diff options
-rw-r--r-- | include/mp_asm.h | 29 | ||||
-rw-r--r-- | include/mp_asmi.h | 28 | ||||
-rw-r--r-- | src/mp_comba.cpp | 2 |
3 files changed, 32 insertions, 27 deletions
diff --git a/include/mp_asm.h b/include/mp_asm.h index 5f0747d88..a450ac47a 100644 --- a/include/mp_asm.h +++ b/include/mp_asm.h @@ -20,6 +20,9 @@ #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64 #endif +#include <stdio.h> +#include <assert.h> + namespace Botan { extern "C" { @@ -44,32 +47,6 @@ inline word word_madd3(word a, word b, word c, word d, word* carry) return (word)z; } -/************************************************* -* Multiply-Add Accumulator * -*************************************************/ -inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b) - { - *w0 = word_madd2(a, b, *w0, &b); - *w1 += b; - *w2 += (*w1 < b) ? 1 : 0; - } - -/************************************************* -* Multiply-Add Accumulator * -*************************************************/ -inline void word3_muladd_2(word* w2, word* w1, word* w0, word a, word b) - { - a = word_madd2(a, b, 0, &b); - - *w0 += a; - *w1 += b + ((*w0 < a) ? 1 : 0); - *w2 += (*w1 < b) ? 1 : 0; - - *w0 += a; - *w1 += b + ((*w0 < a) ? 1 : 0); - *w2 += (*w1 < b) ? 1 : 0; - } - } } diff --git a/include/mp_asmi.h b/include/mp_asmi.h index b05199d0a..46a0696de 100644 --- a/include/mp_asmi.h +++ b/include/mp_asmi.h @@ -150,6 +150,34 @@ inline word word8_madd3(word z[8], const word x[8], word y, word carry) return carry; } +/************************************************* +* Multiply-Add Accumulator * +*************************************************/ +inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b) + { + *w0 = word_madd2(a, b, *w0, &b); + *w1 += b; + *w2 += (*w1 < b) ? 1 : 0; + } + +/************************************************* +* Multiply-Add Accumulator * +*************************************************/ +inline void word3_muladd_2(word* w2, word* w1, word* w0, word a, word b) + { + a = word_madd2(a, b, 0, &b); + + word top = (b >> (BOTAN_MP_WORD_BITS-1)); + b <<= 1; + b |= (a >> (BOTAN_MP_WORD_BITS-1)); + a <<= 1; + + word carry = 0; + *w0 = word_add(*w0, a, &carry); + *w1 = word_add(*w1, b, &carry); + *w2 = word_add(*w2, top, &carry); + } + } } diff --git a/src/mp_comba.cpp b/src/mp_comba.cpp index 450d955a7..0e6dbd259 100644 --- a/src/mp_comba.cpp +++ b/src/mp_comba.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/mp_core.h> -#include <botan/mp_asm.h> +#include <botan/mp_asmi.h> namespace Botan { |