From c9a2d46d4a67168c8aece9e2f5a45454fe68ede9 Mon Sep 17 00:00:00 2001 From: lloyd Date: Thu, 8 Jun 2006 04:54:04 +0000 Subject: Move the word3_muladd routines from mp_asm.h to mp_asmi.h, so they can make use of word_add Update mp_comba.cpp to include the needed header. --- include/mp_asm.h | 29 +++-------------------------- include/mp_asmi.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 26 deletions(-) (limited to 'include') 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 +#include + 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); + } + } } -- cgit v1.2.3