aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/mp/mp_asm64/mp_asm.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-10-12 15:00:33 +0000
committerlloyd <[email protected]>2010-10-12 15:00:33 +0000
commit5d86eaf95f62dd414f6267fbb2f688489718d99e (patch)
tree145a2a3548fb67330fedb97a5f76bf325fc6fe0f /src/math/mp/mp_asm64/mp_asm.h
parentd1740672b8f9e0b5be1cd3d9f5da9ffd76c7c300 (diff)
Change ifs to compares to make it easier for a compiler to figure out
it should use add with carry or conditional moves if available. Also remove the amd64 asm; the mp_amd64 code should be used for this case.
Diffstat (limited to 'src/math/mp/mp_asm64/mp_asm.h')
-rw-r--r--src/math/mp/mp_asm64/mp_asm.h20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/math/mp/mp_asm64/mp_asm.h b/src/math/mp/mp_asm64/mp_asm.h
index b0906095d..d9135ace2 100644
--- a/src/math/mp/mp_asm64/mp_asm.h
+++ b/src/math/mp/mp_asm64/mp_asm.h
@@ -23,13 +23,6 @@ namespace Botan {
z1 = a * b; \
} while(0);
-#elif defined(BOTAN_TARGET_ARCH_IS_AMD64)
-
-#define BOTAN_WORD_MUL(a,b,z1,z0) do { \
- asm("mulq %3" : "=d" (z0), "=a" (z1) : \
- "a" (a), "rm" (b) : "cc"); \
-} while(0);
-
#elif defined(BOTAN_TARGET_ARCH_IS_IA64)
#define BOTAN_WORD_MUL(a,b,z1,z0) do { \
@@ -75,7 +68,8 @@ inline void bigint_2word_mul(word a, word b, word* z1, word* z0)
x2 += x3 >> (MP_HWORD_BITS);
x2 += x1;
- if(x2 < x1)
+
+ if(x2 < x1) // timing channel
x0 += ((word)1 << MP_HWORD_BITS);
*z0 = x0 + (x2 >> MP_HWORD_BITS);
@@ -95,7 +89,8 @@ inline word word_madd2(word a, word b, word* c)
BOTAN_WORD_MUL(a, b, z1, z0);
- z1 += *c; if(z1 < *c) z0++;
+ z1 += *c;
+ z0 += (z1 < *c);
*c = z0;
return z1;
@@ -110,8 +105,11 @@ inline word word_madd3(word a, word b, word c, word* d)
BOTAN_WORD_MUL(a, b, z1, z0);
- z1 += c; if(z1 < c) z0++;
- z1 += *d; if(z1 < *d) z0++;
+ z1 += c;
+ z0 += (z1 < c);
+
+ z1 += *d;
+ z0 += (z1 < *d);
*d = z0;
return z1;