diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /modules/mp_amd64/mp_asm.h |
Initial checkin1.5.6
Diffstat (limited to 'modules/mp_amd64/mp_asm.h')
-rw-r--r-- | modules/mp_amd64/mp_asm.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/modules/mp_amd64/mp_asm.h b/modules/mp_amd64/mp_asm.h new file mode 100644 index 000000000..17f33224c --- /dev/null +++ b/modules/mp_amd64/mp_asm.h @@ -0,0 +1,84 @@ +/************************************************* +* Lowest Level MPI Algorithms Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_MP_ASM_H__ +#define BOTAN_MP_ASM_H__ + +#include <botan/mp_types.h> + +#if (BOTAN_MP_WORD_BITS != 64) + #error The mp_amd64 module requires that BOTAN_MP_WORD_BITS == 64 +#endif + +namespace Botan { + +extern "C" { + +/************************************************* +* Word Multiply * +*************************************************/ +inline word word_madd2(word a, word b, word c, word* carry) + { + asm( + "mulq %1\n\t" // a(in eax) * b(wherever) -> edx:eax + "addq %5,%0\n\t" // add c to low word (eax) + "adcq $0,%2" // add carry from previous to high word (edx) + : "=a"(a), "=rm"(b), "=&d"(*carry) + : "0"(a), "1"(b), "g"(c) : "cc"); + return a; + } + +/************************************************* +* Word Multiply/Add * +*************************************************/ +inline word word_madd3(word a, word b, word c, word d, word* carry) + { + asm( + "mulq %1\n\t" // a(in eax) * b(wherever) -> edx:eax + "addq %5,%0\n\t" // add c to low word (eax) + "adcq $0,%2\n\t" // add carry from previous to high word (edx) + "addq %6,%0\n\t" // add d to low word (eax) + "adcq $0,%2" // add carry from previous to high word (edx) + : "=a"(a), "=rm"(b), "=&d"(*carry) + : "0"(a), "1"(b), "g"(c), "g"(d) : "cc"); + return a; + } + +/************************************************* +* Multiply-Add Accumulator * +*************************************************/ +inline void word3_muladd(word* w2, word* w1, word* w0, word a, word b) + { + asm("mulq %[b]\n\t" // a(in eax) * b(wherever) -> edx:eax + "addq %3,%[w0]\n\t" // add c to low word (eax) + "adcq %4,%[w1]\n\t" // add carry from previous to high word (edx) + "adcq $0,%[w2]\n\t" // add carry from previous to high word (edx) + : [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2) + : "a"(a), [b]"d"(b), "0"(*w0), "1"(*w1), "2"(*w2) + : "cc"); + } + +/************************************************* +* Multiply-Add Accumulator * +*************************************************/ +inline void word3_muladd_2(word* w2, word* w1, word* w0, word a, word b) + { + asm("mulq %[b]\n\t" // a(in eax) * b(wherever) -> edx:eax + "addq %3,%[w0]\n\t" // add c to low word (eax) + "adcq %4,%[w1]\n\t" // add carry from previous to high word (edx) + "adcq $0,%[w2]\n\t" // add carry from previous to high word (edx) + "addq %3,%[w0]\n\t" // add c to low word (eax) + "adcq %4,%[w1]\n\t" // add carry from previous to high word (edx) + "adcq $0,%[w2]\n\t" // add carry from previous to high word (edx) + : [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2) + : "a"(a), [b]"d"(b), "0"(*w0), "1"(*w1), "2"(*w2) + : "cc"); + } + +} + +} + +#endif |