This is an automated email from the git hooks/post-receive script. ppm-guest pushed a commit to annotated tag v0.06 in repository libmath-prime-util-perl.
commit e0ab486cf9bbb4e2f7a153c97d8bb7eabe5ea44e Author: Dana Jacobsen <d...@acm.org> Date: Fri Jun 8 14:13:11 2012 -0600 Tweak to mulmod use --- Changes | 3 +++ factor.c | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 9277d67..980499a 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension Math::Prime::Util. +0.05 8 June 2012 + - Use assembler for mulmod if 64-bit and gcc and x86 + 0.04 7 June 2012 - Didn't do tests on 32-bit machine before release. Test suite caught problem with next_prime overflow. diff --git a/factor.c b/factor.c index b02ff1a..1b06519 100644 --- a/factor.c +++ b/factor.c @@ -100,9 +100,11 @@ int trial_factor(UV n, UV *factors, UV maxtrial) /* UV is the largest integral type available (that we know of). */ + /* if n is smaller than this, you can multiply without overflow */ + #define HALF_WORD (UVCONST(1) << (BITS_PER_WORD/2)) + #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) /* Inline assembly -- basically as fast as a regular (a*b)%m */ - /* Arguably we don't need all the ifs to avoid it */ static UV _mulmod(UV a, UV b, UV c) { UV d; /* to hold the result of a*b mod c */ /* calculates a*b mod c, stores result in d */ @@ -116,6 +118,8 @@ int trial_factor(UV n, UV *factors, UV maxtrial) ); return d; } + #define mulmod(a,b,m) _mulmod(a,b,m) + #define sqrmod(n,m) _mulmod(n,n,m) #else /* Do it by hand */ static UV _mulmod(UV a, UV b, UV m) { @@ -134,14 +138,11 @@ int trial_factor(UV n, UV *factors, UV maxtrial) } return r; } + #define mulmod(a,b,m) (((a)|(b)) < HALF_WORD) ? ((a)*(b))%(m):_mulmod(a,b,m) + #define sqrmod(n,m) ((n) < HALF_WORD) ? ((n)*(n))%(m):_mulmod(n,n,m) #endif - /* if n is smaller than this, you can multiply without overflow */ - #define HALF_WORD (UVCONST(1) << (BITS_PER_WORD/2)) - #define addmod(n,a,m) ((((m)-(n)) > (a)) ? ((n)+(a)) : ((n)+(a)-(m))) - #define mulmod(a,b,m) (((a)|(b)) < HALF_WORD) ? ((a)*(b))%(m) : _mulmod(a,b,m) - #define sqrmod(n,m) ((n) < HALF_WORD) ? ((n)*(n))%(m) : _mulmod(n,n,m) /* n^power mod m */ static UV powmod(UV n, UV power, UV m) { -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits