diff options
author | lloyd <[email protected]> | 2008-03-09 02:53:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-03-09 02:53:59 +0000 |
commit | 9f63fc79701df7e6b659908f5f8ae7efba7c7720 (patch) | |
tree | 79e75981643e1a2aa7e1985820e3b45c47693bb0 | |
parent | c6629040068af67dbd9648eb64cc47b1923287cd (diff) |
Alter bigint_madd2 and bigint_madd3 to take only 3 (4, resp) arguments,
with the last one being both one of the input values and the output carry
register, since almost always they were in fact the same variable.
Also update the x86 and x86-64 modules.
-rw-r--r-- | include/mp_asm.h | 12 | ||||
-rw-r--r-- | include/mp_asmi.h | 61 | ||||
-rw-r--r-- | modules/mp_amd64/mp_asm.h | 12 | ||||
-rw-r--r-- | modules/mp_ia32/mp_asm.h | 12 | ||||
-rw-r--r-- | src/mp_asm.cpp | 4 | ||||
-rw-r--r-- | src/mp_misc.cpp | 6 | ||||
-rw-r--r-- | src/mp_mulop.cpp | 2 |
7 files changed, 56 insertions, 53 deletions
diff --git a/include/mp_asm.h b/include/mp_asm.h index 88229b386..64694492a 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, word* carry) +inline word word_madd2(word a, word b, word* c) { - dword z = (dword)a * b + c; - *carry = (word)(z >> BOTAN_MP_WORD_BITS); + dword z = (dword)a * b + *c; + *c = (word)(z >> BOTAN_MP_WORD_BITS); return (word)z; } /************************************************* * Word Multiply/Add * *************************************************/ -inline word word_madd3(word a, word b, word c, word d, word* carry) +inline word word_madd3(word a, word b, word c, word* d) { - dword z = (dword)a * b + c + d; - *carry = (word)(z >> BOTAN_MP_WORD_BITS); + dword z = (dword)a * b + c + *d; + *d = (word)(z >> BOTAN_MP_WORD_BITS); return (word)z; } diff --git a/include/mp_asmi.h b/include/mp_asmi.h index ded60d51f..c2e539be8 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, &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); + 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); 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, &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); + 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); 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, &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); + 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); return carry; } @@ -155,9 +155,10 @@ inline word word8_madd3(word z[8], const word x[8], word y, word carry) *************************************************/ 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; + word carry = *w0; + *w0 = word_madd2(a, b, &carry); + *w1 += carry; + *w2 += (*w1 < carry) ? 1 : 0; } /************************************************* @@ -165,14 +166,16 @@ 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) { - a = word_madd2(a, b, 0, &b); + word carry = 0; + a = word_madd2(a, b, &carry); + b = carry; word top = (b >> (BOTAN_MP_WORD_BITS-1)); b <<= 1; b |= (a >> (BOTAN_MP_WORD_BITS-1)); a <<= 1; - word carry = 0; + carry = 0; *w0 = word_add(*w0, a, &carry); *w1 = word_add(*w1, b, &carry); *w2 = word_add(*w2, top, &carry); diff --git a/modules/mp_amd64/mp_asm.h b/modules/mp_amd64/mp_asm.h index 745f62fdb..f24f030bd 100644 --- a/modules/mp_amd64/mp_asm.h +++ b/modules/mp_amd64/mp_asm.h @@ -24,15 +24,15 @@ extern "C" { /************************************************* * Word Multiply * *************************************************/ -inline word word_madd2(word a, word b, word c, word* carry) +inline word word_madd2(word a, word b, word* c) { asm( ASM("mulq %[b]") ASM("addq %[c],%[a]") ASM("adcq $0,%[carry]") - : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*carry) - : "0"(a), "1"(b), [c]"g"(c) : "cc"); + : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*c) + : "0"(a), "1"(b), [c]"g"(*c) : "cc"); return a; } @@ -40,7 +40,7 @@ inline word word_madd2(word a, word b, word c, word* carry) /************************************************* * Word Multiply/Add * *************************************************/ -inline word word_madd3(word a, word b, word c, word d, word* carry) +inline word word_madd3(word a, word b, word c, word* d) { asm( ASM("mulq %[b]") @@ -51,8 +51,8 @@ inline word word_madd3(word a, word b, word c, word d, word* carry) ASM("addq %[d],%[a]") ASM("adcq $0,%[carry]") - : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*carry) - : "0"(a), "1"(b), [c]"g"(c), [d]"g"(d) : "cc"); + : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d) + : "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc"); return a; } diff --git a/modules/mp_ia32/mp_asm.h b/modules/mp_ia32/mp_asm.h index 937aee598..873b88f46 100644 --- a/modules/mp_ia32/mp_asm.h +++ b/modules/mp_ia32/mp_asm.h @@ -24,15 +24,15 @@ extern "C" { /************************************************* * Word Multiply * *************************************************/ -inline word word_madd2(word a, word b, word c, word* carry) +inline word word_madd2(word a, word b, word* c) { asm( ASM("mull %[b]") ASM("addl %[c],%[a]") ASM("adcl $0,%[carry]") - : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*carry) - : "0"(a), "1"(b), [c]"g"(c) : "cc"); + : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*c) + : "0"(a), "1"(b), [c]"g"(*c) : "cc"); return a; } @@ -40,7 +40,7 @@ inline word word_madd2(word a, word b, word c, word* carry) /************************************************* * Word Multiply/Add * *************************************************/ -inline word word_madd3(word a, word b, word c, word d, word* carry) +inline word word_madd3(word a, word b, word c, word* d) { asm( ASM("mull %[b]") @@ -51,8 +51,8 @@ inline word word_madd3(word a, word b, word c, word d, word* carry) ASM("addl %[d],%[a]") ASM("adcl $0,%[carry]") - : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*carry) - : "0"(a), "1"(b), [c]"g"(c), [d]"g"(d) : "cc"); + : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d) + : "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc"); return a; } diff --git a/src/mp_asm.cpp b/src/mp_asm.cpp index 2b921f15d..8065bd186 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, &carry); + x[j] = word_madd2(x[j], y, &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, &carry); + z[j] = word_madd2(x[j], y, &carry); z[x_size] = carry; } diff --git a/src/mp_misc.cpp b/src/mp_misc.cpp index 2c6c35d30..24dbb6bfd 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, &y0); - y1 = word_madd2(q, y1, y0, &y0); + y2 = word_madd2(q, y2, &y0); + y1 = word_madd2(q, y1, &y0); if(y0 > x1) return 1; if(y0 < x1) return 0; @@ -83,7 +83,7 @@ word bigint_modop(word n1, word n0, word d) { word z = bigint_divop(n1, n0, d); word dummy = 0; - z = word_madd2(z, d, dummy, &dummy); + z = word_madd2(z, d, &dummy); return (n0-z); } diff --git a/src/mp_mulop.cpp b/src/mp_mulop.cpp index 9bbd4cee2..9b6ddca8c 100644 --- a/src/mp_mulop.cpp +++ b/src/mp_mulop.cpp @@ -24,7 +24,7 @@ word bigint_mul_add_words(word z[], const word x[], u32bit x_size, word y) carry = word8_madd3(z + j, x + j, y, carry); for(u32bit j = blocks; j != x_size; ++j) - z[j] = word_madd3(x[j], y, z[j], carry, &carry); + z[j] = word_madd3(x[j], y, z[j], &carry); return carry; } |