[libmath-prime-util-perl] 40/40: Add x86_64 asm for addmod from Kruppa

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


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

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

commit 4ba8d5976e14a711af901537ad98b0fc4e84afb4
Author: Dana Jacobsen <dana at acm.org>
Date:   Tue Aug 6 04:19:26 2013 -0700

    Add x86_64 asm for addmod from Kruppa
---
 mulmod.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/mulmod.h b/mulmod.h
index a4a960c..3e072a6 100644
--- a/mulmod.h
+++ b/mulmod.h
@@ -49,6 +49,20 @@
   #define mulmod(a,b,m) _mulmod(a,b,m)
   #define sqrmod(n,m)   _mulmod(n,n,m)
 
+  /* addmod from Kruppa 2010 page 67 */
+  static INLINE UV _addmod(UV a, UV b, UV m) {
+    UV r = a+b;
+    UV t = a-m;
+    asm ("add %2, %1\n\t"    /* t := t + b */
+         "cmovc %1, %0\n\t"  /* if (carry) r := t */
+         :"+r" (r), "+&r" (t)
+         :"g" (b)
+         :"cc"
+        );
+    return r;
+  }
+  #define addmod(a,b,n) _addmod(a,b,n)
+
 #elif BITS_PER_WORD == 64 && __GNUC__ == 4 && __GNUC_MINOR__ >= 4 && (defined(__LP64__) || defined(__x86_64__) || defined(__powerpc64__) || defined(_M_X64) || defined(_M_IX86))
 
   /* We're 64-bit, using a modern gcc, and the target has some 128-bit type */
@@ -86,7 +100,7 @@
 #endif
 
 #ifndef addmod
-  #define addmod(n,a,m) ((((m)-(n)) > (a))  ?  ((n)+(a))  :  ((n)+(a)-(m)))
+  #define addmod(a,b,m) ((((m)-(a)) > (b))  ?  ((a)+(b))  :  ((a)+(b)-(m)))
 #endif
 
 /* We need to make sure a and b get evaluated into UVs, then do the

-- 
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