diff options
-rw-r--r-- | include/mp_asm.h | 23 | ||||
-rw-r--r-- | include/mp_asmi.h | 48 | ||||
-rw-r--r-- | src/mp_asm.cpp | 8 | ||||
-rw-r--r-- | src/mp_misc.cpp | 8 |
4 files changed, 40 insertions, 47 deletions
diff --git a/include/mp_asm.h b/include/mp_asm.h index 1166d9c8d..5f0747d88 100644 --- a/include/mp_asm.h +++ b/include/mp_asm.h @@ -27,20 +27,20 @@ extern "C" { /************************************************* * Word Multiply/Add * *************************************************/ -inline word word_madd2(word a, word b, word* c) +inline word word_madd2(word a, word b, word c, word* carry) { - dword z = (dword)a * b + *c; - *c = (word)(z >> BOTAN_MP_WORD_BITS); + dword z = (dword)a * b + c; + *carry = (word)(z >> BOTAN_MP_WORD_BITS); return (word)z; } /************************************************* * Word Multiply/Add * *************************************************/ -inline word word_madd3(word a, word b, word c, word *d) +inline word word_madd3(word a, word b, word c, word d, word* carry) { - dword z = (dword)a * b + c + *d; - *d = (word)(z >> BOTAN_MP_WORD_BITS); + dword z = (dword)a * b + c + d; + *carry = (word)(z >> BOTAN_MP_WORD_BITS); return (word)z; } @@ -49,11 +49,7 @@ inline word word_madd3(word a, word b, word c, word *d) *************************************************/ inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b) { - dword z = (dword)a * b + *w0; - - b = (word)(z >> BOTAN_MP_WORD_BITS); - *w0 = (word)z; - + *w0 = word_madd2(a, b, *w0, &b); *w1 += b; *w2 += (*w1 < b) ? 1 : 0; } @@ -63,10 +59,7 @@ inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b) *************************************************/ inline void word3_muladd_2(word* w2, word* w1, word* w0, word a, word b) { - dword z = (dword)a * b; - - b = (word)(z >> BOTAN_MP_WORD_BITS); - a = (word)z; + a = word_madd2(a, b, 0, &b); *w0 += a; *w1 += b + ((*w0 < a) ? 1 : 0); diff --git a/include/mp_asmi.h b/include/mp_asmi.h index 70e25d07b..b05199d0a 100644 --- a/include/mp_asmi.h +++ b/include/mp_asmi.h @@ -107,14 +107,14 @@ inline word word8_sub3(word z[8], const word x[8], *************************************************/ inline word word8_linmul2(word x[4], word y, word carry) { - x[0] = word_madd2(x[0], y, &carry); - x[1] = word_madd2(x[1], y, &carry); - x[2] = word_madd2(x[2], y, &carry); - x[3] = word_madd2(x[3], y, &carry); - x[4] = word_madd2(x[4], y, &carry); - x[5] = word_madd2(x[5], y, &carry); - x[6] = word_madd2(x[6], y, &carry); - x[7] = word_madd2(x[7], y, &carry); + x[0] = word_madd2(x[0], y, carry, &carry); + x[1] = word_madd2(x[1], y, carry, &carry); + x[2] = word_madd2(x[2], y, carry, &carry); + x[3] = word_madd2(x[3], y, carry, &carry); + x[4] = word_madd2(x[4], y, carry, &carry); + x[5] = word_madd2(x[5], y, carry, &carry); + x[6] = word_madd2(x[6], y, carry, &carry); + x[7] = word_madd2(x[7], y, carry, &carry); return carry; } @@ -123,14 +123,14 @@ inline word word8_linmul2(word x[4], word y, word carry) *************************************************/ inline word word8_linmul3(word z[8], const word x[8], word y, word carry) { - z[0] = word_madd2(x[0], y, &carry); - z[1] = word_madd2(x[1], y, &carry); - z[2] = word_madd2(x[2], y, &carry); - z[3] = word_madd2(x[3], y, &carry); - z[4] = word_madd2(x[4], y, &carry); - z[5] = word_madd2(x[5], y, &carry); - z[6] = word_madd2(x[6], y, &carry); - z[7] = word_madd2(x[7], y, &carry); + z[0] = word_madd2(x[0], y, carry, &carry); + z[1] = word_madd2(x[1], y, carry, &carry); + z[2] = word_madd2(x[2], y, carry, &carry); + z[3] = word_madd2(x[3], y, carry, &carry); + z[4] = word_madd2(x[4], y, carry, &carry); + z[5] = word_madd2(x[5], y, carry, &carry); + z[6] = word_madd2(x[6], y, carry, &carry); + z[7] = word_madd2(x[7], y, carry, &carry); return carry; } @@ -139,14 +139,14 @@ inline word word8_linmul3(word z[8], const word x[8], word y, word carry) *************************************************/ inline word word8_madd3(word z[8], const word x[8], word y, word carry) { - z[0] = word_madd3(x[0], y, z[0], &carry); - z[1] = word_madd3(x[1], y, z[1], &carry); - z[2] = word_madd3(x[2], y, z[2], &carry); - z[3] = word_madd3(x[3], y, z[3], &carry); - z[4] = word_madd3(x[4], y, z[4], &carry); - z[5] = word_madd3(x[5], y, z[5], &carry); - z[6] = word_madd3(x[6], y, z[6], &carry); - z[7] = word_madd3(x[7], y, z[7], &carry); + z[0] = word_madd3(x[0], y, z[0], carry, &carry); + z[1] = word_madd3(x[1], y, z[1], carry, &carry); + z[2] = word_madd3(x[2], y, z[2], carry, &carry); + z[3] = word_madd3(x[3], y, z[3], carry, &carry); + z[4] = word_madd3(x[4], y, z[4], carry, &carry); + z[5] = word_madd3(x[5], y, z[5], carry, &carry); + z[6] = word_madd3(x[6], y, z[6], carry, &carry); + z[7] = word_madd3(x[7], y, z[7], carry, &carry); return carry; } diff --git a/src/mp_asm.cpp b/src/mp_asm.cpp index ef8292083..ec2e31011 100644 --- a/src/mp_asm.cpp +++ b/src/mp_asm.cpp @@ -148,7 +148,7 @@ void bigint_linmul2(word x[], u32bit x_size, word y) carry = word8_linmul2(x + j, y, carry); for(u32bit j = blocks; j != x_size; ++j) - x[j] = word_madd2(x[j], y, &carry); + x[j] = word_madd2(x[j], y, carry, &carry); x[x_size] = carry; } @@ -166,7 +166,7 @@ void bigint_linmul3(word z[], const word x[], u32bit x_size, word y) carry = word8_linmul3(z + j, x + j, y, carry); for(u32bit j = blocks; j != x_size; ++j) - z[j] = word_madd2(x[j], y, &carry); + z[j] = word_madd2(x[j], y, carry, &carry); z[x_size] = carry; } @@ -190,7 +190,7 @@ void bigint_simple_mul(word z[], const word x[], u32bit x_size, carry = word8_madd3(z + j + k, y + k, x_j, carry); for(u32bit k = blocks; k != y_size; ++k) - z[j+k] = word_madd3(x_j, y[k], z[j+k], &carry); + z[j+k] = word_madd3(x_j, y[k], z[j+k], carry, &carry); z[j+y_size] = carry; } @@ -215,7 +215,7 @@ void montgomery_reduce(word z[], u32bit z_size, carry = word8_madd3(z_j + k, x + k, y, carry); for(u32bit k = blocks; k != x_size; ++k) - z_j[k] = word_madd3(x[k], y, z_j[k], &carry); + z_j[k] = word_madd3(x[k], y, z_j[k], carry, &carry); word carry2 = 0; z_j[x_size] = word_add(z_j[x_size], carry, &carry2); diff --git a/src/mp_misc.cpp b/src/mp_misc.cpp index 782ad9d15..f551948b7 100644 --- a/src/mp_misc.cpp +++ b/src/mp_misc.cpp @@ -17,8 +17,8 @@ u32bit bigint_divcore(word q, word y1, word y2, word x1, word x2, word x3) { word y0 = 0; - y2 = word_madd2(q, y2, &y0); - y1 = word_madd2(q, y1, &y0); + y2 = word_madd2(q, y2, y0, &y0); + y1 = word_madd2(q, y1, y0, &y0); if(y0 > x1) return 1; if(y0 < x1) return 0; @@ -80,8 +80,8 @@ word bigint_divop(word n1, word n0, word d) word bigint_modop(word n1, word n0, word d) { word z = bigint_divop(n1, n0, d); - word carry = 0; - z = word_madd2(z, d, &carry); + word dummy = 0; + z = word_madd2(z, d, dummy, &dummy); return (n0-z); } |