aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-17 23:26:21 +0000
committerlloyd <[email protected]>2008-09-17 23:26:21 +0000
commitb1341696de81ddb9c6ce15f8a1c03e4285a51311 (patch)
tree1fd00152f485d002c39c253a592ea73bbe6a3ba8
parent119cba52f4e96e18fbad846d1fc8dfe682f38974 (diff)
Move biging_wordmul inlined into the only place where it is used,
the mp_asm64 module. It is called only on systems like UltraSPARC which have 64 bit registers/ALU but no native 64x64->128 bit multiplication operation.
-rw-r--r--modules/mp_asm64/mp_asm.h34
-rw-r--r--src/mp_misc.cpp27
2 files changed, 29 insertions, 32 deletions
diff --git a/modules/mp_asm64/mp_asm.h b/modules/mp_asm64/mp_asm.h
index 2ceb9fd56..e455b3616 100644
--- a/modules/mp_asm64/mp_asm.h
+++ b/modules/mp_asm64/mp_asm.h
@@ -8,6 +8,8 @@
#include <botan/mp_types.h>
+namespace Botan {
+
#if (BOTAN_MP_WORD_BITS != 64)
#error The mp_asm64 module requires that BOTAN_MP_WORD_BITS == 64
#endif
@@ -41,15 +43,37 @@
#else
-#include <botan/mp_core.h>
+// Do a 64x64->128 multiply using four 64x64->64 multiplies
+// plus some adds and shifts. Last resort for CPUs like UltraSPARC,
+// with 64-bit registers/ALU, but no 64x64->128 multiply.
+inline void bigint_2word_mul(word a, word b, word* z1, word* z0)
+ {
+ const u32bit MP_HWORD_BITS = MP_WORD_BITS / 2;
+ const word MP_HWORD_MASK = ((word)1 << MP_HWORD_BITS) - 1;
+
+ const word a_hi = (a >> MP_HWORD_BITS);
+ const word a_lo = (a & MP_HWORD_MASK);
+ const word b_hi = (b >> MP_HWORD_BITS);
+ const word b_lo = (b & MP_HWORD_MASK);
+
+ word x0 = a_hi * b_hi;
+ word x1 = a_lo * b_hi;
+ word x2 = a_hi * b_lo;
+ word x3 = a_lo * b_lo;
+
+ x2 += x3 >> (MP_HWORD_BITS);
+ x2 += x1;
+ if(x2 < x1)
+ x0 += ((word)1 << MP_HWORD_BITS);
+
+ *z0 = x0 + (x2 >> MP_HWORD_BITS);
+ *z1 = ((x2 & MP_HWORD_MASK) << MP_HWORD_BITS) + (x3 & MP_HWORD_MASK);
+ }
-#define BOTAN_WORD_MUL(a,b,z1,z0) \
- do { bigint_wordmul(a, b, &z1, &z0); } while(0);
+#define BOTAN_WORD_MUL(a,b,z1,z0) bigint_2word_mul(a, b, &z1, &z0)
#endif
-namespace Botan {
-
/*************************************************
* Word Multiply/Add *
*************************************************/
diff --git a/src/mp_misc.cpp b/src/mp_misc.cpp
index 632808151..db9c8cda0 100644
--- a/src/mp_misc.cpp
+++ b/src/mp_misc.cpp
@@ -87,33 +87,6 @@ word bigint_modop(word n1, word n0, word d)
return (n0-z);
}
-/*************************************************
-* Do a word*word->2-word Multiply *
-*************************************************/
-void bigint_wordmul(word a, word b, word* out_low, word* out_high)
- {
- const u32bit MP_HWORD_BITS = MP_WORD_BITS / 2;
- const word MP_HWORD_MASK = ((word)1 << MP_HWORD_BITS) - 1;
-
- const word a_hi = (a >> MP_HWORD_BITS);
- const word a_lo = (a & MP_HWORD_MASK);
- const word b_hi = (b >> MP_HWORD_BITS);
- const word b_lo = (b & MP_HWORD_MASK);
-
- word x0 = a_hi * b_hi;
- word x1 = a_lo * b_hi;
- word x2 = a_hi * b_lo;
- word x3 = a_lo * b_lo;
-
- x2 += x3 >> (MP_HWORD_BITS);
- x2 += x1;
- if(x2 < x1)
- x0 += ((word)1 << MP_HWORD_BITS);
-
- *out_high = x0 + (x2 >> MP_HWORD_BITS);
- *out_low = ((x2 & MP_HWORD_MASK) << MP_HWORD_BITS) + (x3 & MP_HWORD_MASK);
- }
-
}
}