[libmath-prime-util-perl] 78/181: Merge XS changes from bulk88

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:51:08 UTC 2015


This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.36
in repository libmath-prime-util-perl.

commit 25e10313fedf929850634b4ef625c27d63ef3605
Merge: 91f7c61 9ed115d
Author: Dana Jacobsen <dana at acm.org>
Date:   Tue Dec 31 04:07:25 2013 -0800

    Merge XS changes from bulk88

 XS.xs    | 118 ++++++++++++++++++++++++++++++++++++++-------------------------
 ptypes.h |  24 +++++++++++++
 2 files changed, 95 insertions(+), 47 deletions(-)

diff --cc XS.xs
index 2d8e507,3072b6f..66ba2ad
--- a/XS.xs
+++ b/XS.xs
@@@ -38,7 -38,7 +38,7 @@@
   #define my_svuv(sv)  PSTRTOULL(SvPV_nolen(sv), NULL, 10)
   #define my_sviv(sv)  PSTRTOLL(SvPV_nolen(sv), NULL, 10)
  #else
-- #define my_svuv(sv)  ((!SvROK(sv)) ? SvUV(sv) : PSTRTOULL(SvPV_nolen(sv), NULL, 10))
++  #define my_svuv(sv)  ((!SvROK(sv)) ? SvUV(sv) : PSTRTOULL(SvPV_nolen(sv), NULL, 10))
   #define my_sviv(sv)  ((!SvROK(sv)) ? SvIV(sv) : PSTRTOLL(SvPV_nolen(sv), NULL, 10))
  #endif
  
@@@ -175,6 -180,9 +182,8 @@@ prime_precalc(IN UV n
      _XS_set_verbose = 1
      _XS_set_callgmp = 2
    PPCODE:
 -    PUTBACK; /* SP is never used again, the 3 next func calls are
 -    tailcall friendly since this XSUB has nothing to do after the 3 calls
 -    return */
++    PUTBACK; /* SP is never used again, the 3 next func calls are tailcall
++    friendly since this XSUB has nothing to do after the 3 calls return */
      switch (ix) {
        case 0:  prime_precalc(n);    break;
        case 1:  _XS_set_verbose(n);  break;
@@@ -357,29 -381,33 +367,30 @@@ trial_factor(IN UV n, ...
      }
  
  int
 -_XS_is_pseudoprime(IN UV n, IN UV a)
 -
 -int
  _XS_miller_rabin(IN UV n, ...)
--  PREINIT:
--    UV bases[64];
--    int prob_prime = 1;
--    int c = 1;
    CODE:
      if (items < 2)
        croak("No bases given to miller_rabin");
-     if ( (n == 0) || (n == 1) ) XSRETURN_IV(0);   /* 0 and 1 are composite */
-     if ( (n == 2) || (n == 3) ) XSRETURN_IV(1);   /* 2 and 3 are prime */
-     if (( n % 2 ) == 0)  XSRETURN_IV(0);          /* MR works with odd n */
 -    if ( (n == 0) || (n == 1) ) {RETVAL = 0; goto return_iv;}   /* 0 and 1 are composite */
 -    if ( (n == 2) || (n == 3) ) {RETVAL = 1; goto return_iv;}   /* 2 and 3 are prime */
 -    if (( n % 2 ) == 0) {RETVAL = 0; goto return_iv;}          /* MR works with odd n */
--    while (c < items) {
--      int b = 0;
++    if      ( (n == 0) || (n == 1) ) { RETVAL = 0; }  /* 0 and 1 composite */
++    else if ( (n == 2) || (n == 3) ) { RETVAL = 1; }  /* 2 and 3 prime */
++    else if ( (n % 2) == 0 )         { RETVAL = 0; }  /* MR works on odds */
++    else {
++      UV bases[64];
++      int prob_prime = 1;
++      int c = 1;
        while (c < items) {
--        bases[b++] = SvUV(ST(c));
--        c++;
--        if (b == 64) break;
++        int b = 0;
++        while (c < items) {
++          bases[b++] = SvUV(ST(c));
++          c++;
++          if (b == 64) break;
++        }
++        prob_prime = _XS_miller_rabin(n, bases, b);
++        if (prob_prime != 1)
++          break;
        }
--      prob_prime = _XS_miller_rabin(n, bases, b);
--      if (prob_prime != 1)
--        break;
++      RETVAL = prob_prime;
      }
--    RETVAL = prob_prime;
 -    return_iv:
    OUTPUT:
      RETVAL
  
@@@ -389,12 -417,12 +400,12 @@@ _XS_lucas_sequence(IN UV n, IN IV P, I
      UV U, V, Qk;
    PPCODE:
      lucas_seq(&U, &V, &Qk,  n, P, Q, k);
-     XPUSHs(sv_2mortal(newSVuv( U )));
-     XPUSHs(sv_2mortal(newSVuv( V )));
-     XPUSHs(sv_2mortal(newSVuv( Qk )));
 -    PUSHs(sv_2mortal(newSVuv( U )));
++    PUSHs(sv_2mortal(newSVuv( U )));    /* 4 args in, 3 out, no EXTEND needed */
+     PUSHs(sv_2mortal(newSVuv( V )));
+     PUSHs(sv_2mortal(newSVuv( Qk )));
  
  int
 -_XS_is_prime(IN UV n)
 +_XS_is_prime(IN UV n, ...)
    ALIAS:
      _XS_is_prob_prime = 1
      _XS_is_lucas_pseudoprime = 2
@@@ -486,7 -516,7 +498,7 @@@ factor(IN SV* svn
          }
        }
      } else {
-       _vcallsubn(aTHX_ GIMME_V, "_generic_factor", 1);
 -      _vcallsubn(aTHX_ gimme_v, "Math::Prime::Util::_generic_factor", 1);
++      _vcallsubn(aTHX_ gimme_v, "_generic_factor", 1);
        return; /* skip implicit PUTBACK */
      }
  
@@@ -565,13 -595,22 +577,22 @@@ _XS_ExponentialIntegral(IN SV* x
    PREINIT:
      double ret;
    CODE:
-     switch (ix) {
-       case 0: ret = _XS_ExponentialIntegral(SvNV(x)); break;
-       case 1: ret = _XS_LogarithmicIntegral(SvNV(x)); break;
-       case 2: ret = (double) ld_riemann_zeta(SvNV(x)); break;
-       case 3: ret = _XS_RiemannR(SvNV(x)); break;
-       case 4: ret = _XS_chebyshev_theta(SvUV(x)); break;
-       default:ret = _XS_chebyshev_psi(SvUV(x)); break;
 -    if(ix < 4 ) {
++    if (ix < 4) {
+       NV nv = SvNV(x);
+       switch (ix) {
+         case 0: ret = _XS_ExponentialIntegral(nv); break;
+         case 1: ret = _XS_LogarithmicIntegral(nv); break;
+         case 2: ret = (double) ld_riemann_zeta(nv); break;
 -        case 3: ret = _XS_RiemannR(nv); break;
 -        default: MPUNOT_REACHED; break; /* CC thinks ix is negative */
++        case 3:
++        default:ret = _XS_RiemannR(nv); break;
+       }
+     } else {
+       UV uv = SvUV(x);
+       switch (ix) {
+         case 4: ret = _XS_chebyshev_theta(uv); break;
+         case 5:
 -        default: ret = _XS_chebyshev_psi(uv); break;
++        default:ret = _XS_chebyshev_psi(uv); break;
+       }
      }
      RETVAL = ret;
    OUTPUT:
diff --cc ptypes.h
index 1259198,6c51e4d..860977c
--- a/ptypes.h
+++ b/ptypes.h
@@@ -102,4 -102,23 +102,28 @@@ typedef __int8 int8_t
  
  #define MPUassert(c,text) if (!(c)) { croak("Math::Prime::Util internal error: " text); }
  
++/* The ASSUME bits are from perl 5.19.6 perl.h */
++
++#ifndef __has_builtin
++#  define __has_builtin(x) 0 /* not a clang style compiler */
++#endif
++
+ #ifndef DEBUGGING
 -#  if __has_builtin(__builtin_unreachable) \
 -     || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5 || __GNUC__ > 5) /* 4.5 -> */
++#  if (__GNUC__ == 4 && __GNUC_MINOR__ >= 5 || __GNUC__ > 5) || __has_builtin(__builtin_unreachable)
+ #    define MPUASSUME(x) ((x) ? (void) 0 : __builtin_unreachable())
+ #  elif defined(_MSC_VER)
+ #    define MPUASSUME(x) __assume(x)
+ #  elif defined(__ARMCC_VERSION) /* untested */
+ #    define MPUASSUME(x) __promise(x)
+ #  else
+ /* a random compiler might define assert to its own special optimization token
+    so pass it through to C lib as a last resort */
+ #    define MPUASSUME(x) assert(x)
+ #  endif
+ #else
+ #  define MPUASSUME(x) assert(x)
+ #endif
+ 
+ #define MPUNOT_REACHED MPUASSUME(0)
+ 
  #endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git



More information about the Pkg-perl-cvs-commits mailing list