[libmath-prime-util-perl] 21/72: Revised mulmod x86_64 asm, work with Wojciech Izykowski
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:49:37 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.32
in repository libmath-prime-util-perl.
commit 83190bf82e83e86e138853c229536781ae7f8f04
Author: Dana Jacobsen <dana at acm.org>
Date: Tue Sep 10 10:35:12 2013 -0700
Revised mulmod x86_64 asm, work with Wojciech Izykowski
---
mulmod.h | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/mulmod.h b/mulmod.h
index 9c08152..7f263a9 100644
--- a/mulmod.h
+++ b/mulmod.h
@@ -25,17 +25,15 @@
#elif defined(__GNUC__) && defined(__x86_64__)
- /* GCC on a 64-bit Intel x86 */
+ /* GCC on a 64-bit Intel x86, help from WraithX and Wojciech Izykowski */
+ /* Beware: if (a*b)/c > 2^64, there will be an FP exception */
static INLINE 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 */
- asm ("mov %1, %%rax;" /* put a into rax */
- "mul %2;" /* mul a*b -> rdx:rax */
- "div %3;" /* (a*b)/c -> quot in rax remainder in rdx */
- "mov %%rdx, %0;" /* store result in d */
- :"=r"(d) /* output */
- :"r"(a), "r"(b), "r"(c) /* input */
- :"%rax", "%rdx" /* clobbered registers */
+ UV d, dummy; /* d will get a*b mod c */
+ asm ("mulq %3\n\t" /* mul a*b -> rdx:rax */
+ "divq %4\n\t" /* (a*b)/c -> quot in rax remainder in rdx */
+ :"=a"(dummy), "=&d"(d) /* output */
+ :"a"(a), "rm"(b), "rm"(c) /* input */
+ :"cc" /* mulq and divq can set conditions */
);
/* A version for _MSC_VER:
*
@@ -56,7 +54,7 @@
asm ("add %2, %1\n\t" /* t := t + b */
"cmovc %1, %0\n\t" /* if (carry) r := t */
:"+r" (r), "+&r" (t)
- :"g" (b)
+ :"rm" (b)
:"cc"
);
return r;
--
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