From 0abddf092a646168b0cb5648b940e7baf6188bf4 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 30 Jul 2013 19:14:19 +0000 Subject: Rename mp_asm.h to mp_madd.h --- src/math/bigint/divide.cpp | 2 +- src/math/mp/mp_asm.cpp | 18 --------- src/math/mp/mp_core.h | 5 ++- src/math/mp/mp_generic/info.txt | 2 +- src/math/mp/mp_generic/mp_asm.h | 73 ------------------------------------ src/math/mp/mp_generic/mp_asmi.h | 2 +- src/math/mp/mp_generic/mp_madd.h | 73 ++++++++++++++++++++++++++++++++++++ src/math/mp/mp_misc.cpp | 2 +- src/math/mp/mp_monty.cpp | 2 +- src/math/mp/mp_mulop.cpp | 2 +- src/math/mp/mp_x86_32/info.txt | 2 +- src/math/mp/mp_x86_32/mp_asm.h | 67 --------------------------------- src/math/mp/mp_x86_32/mp_asmi.h | 2 +- src/math/mp/mp_x86_32/mp_madd.h | 67 +++++++++++++++++++++++++++++++++ src/math/mp/mp_x86_32_msvc/info.txt | 2 +- src/math/mp/mp_x86_32_msvc/mp_asmi.h | 2 +- src/math/mp/mp_x86_64/info.txt | 2 +- src/math/mp/mp_x86_64/mp_asm.h | 69 ---------------------------------- src/math/mp/mp_x86_64/mp_asmi.h | 2 +- src/math/mp/mp_x86_64/mp_madd.h | 69 ++++++++++++++++++++++++++++++++++ 20 files changed, 224 insertions(+), 241 deletions(-) delete mode 100644 src/math/mp/mp_generic/mp_asm.h create mode 100644 src/math/mp/mp_generic/mp_madd.h delete mode 100644 src/math/mp/mp_x86_32/mp_asm.h create mode 100644 src/math/mp/mp_x86_32/mp_madd.h delete mode 100644 src/math/mp/mp_x86_64/mp_asm.h create mode 100644 src/math/mp/mp_x86_64/mp_madd.h (limited to 'src/math') diff --git a/src/math/bigint/divide.cpp b/src/math/bigint/divide.cpp index c8b82422a..8b21bce13 100644 --- a/src/math/bigint/divide.cpp +++ b/src/math/bigint/divide.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace Botan { diff --git a/src/math/mp/mp_asm.cpp b/src/math/mp/mp_asm.cpp index 3ba52c4b1..7f98b47cb 100644 --- a/src/math/mp/mp_asm.cpp +++ b/src/math/mp/mp_asm.cpp @@ -6,11 +6,7 @@ * Distributed under the terms of the Botan license */ -#include -#include #include -#include -#include namespace Botan { @@ -21,20 +17,6 @@ extern "C" { */ word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size) { - word carry = 0; - - const size_t blocks = y_size - (y_size % 8); - - for(size_t i = 0; i != blocks; i += 8) - carry = word8_add2(x + i, y + i, carry); - - for(size_t i = blocks; i != y_size; ++i) - x[i] = word_add(x[i], y[i], &carry); - - for(size_t i = y_size; i != x_size; ++i) - x[i] = word_add(x[i], 0, &carry); - - return carry; } /* diff --git a/src/math/mp/mp_core.h b/src/math/mp/mp_core.h index a84b38cdd..c25cb994f 100644 --- a/src/math/mp/mp_core.h +++ b/src/math/mp/mp_core.h @@ -1,12 +1,13 @@ /* * MPI Algorithms * (C) 1999-2010 Jack Lloyd +* 2006 Luca Piccarreta * * Distributed under the terms of the Botan license */ -#ifndef BOTAN_MP_CORE_H__ -#define BOTAN_MP_CORE_H__ +#ifndef BOTAN_MP_CORE_OPS_H__ +#define BOTAN_MP_CORE_OPS_H__ #include diff --git a/src/math/mp/mp_generic/info.txt b/src/math/mp/mp_generic/info.txt index ab4d7406a..c87dd00ca 100644 --- a/src/math/mp/mp_generic/info.txt +++ b/src/math/mp/mp_generic/info.txt @@ -1,6 +1,6 @@ load_on dep -mp_asm.h +mp_madd.h mp_asmi.h diff --git a/src/math/mp/mp_generic/mp_asm.h b/src/math/mp/mp_generic/mp_asm.h deleted file mode 100644 index ff00cc24b..000000000 --- a/src/math/mp/mp_generic/mp_asm.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -* Lowest Level MPI Algorithms -* (C) 1999-2008,2013 Jack Lloyd -* 2006 Luca Piccarreta -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MP_ASM_H__ -#define BOTAN_MP_ASM_H__ - -#include - -namespace Botan { - -extern "C" { - -/* -* Word Multiply/Add -*/ -inline word word_madd2(word a, word b, word* c) - { -#if defined(BOTAN_HAS_MP_DWORD) - const dword s = static_cast(a) * b + *c; - *c = static_cast(s >> BOTAN_MP_WORD_BITS); - return static_cast(s); -#else - static_assert(BOTAN_MP_WORD_BITS == 64, "Unexpected word size"); - - word hi = 0, lo = 0; - - mul64x64_128(a, b, &lo, &hi); - - lo += *c; - hi += (lo < *c); // carry? - - *c = hi; - return lo; -#endif - } - -/* -* Word Multiply/Add -*/ -inline word word_madd3(word a, word b, word c, word* d) - { -#if defined(BOTAN_HAS_MP_DWORD) - const dword s = static_cast(a) * b + c + *d; - *d = static_cast(s >> BOTAN_MP_WORD_BITS); - return static_cast(s); -#else - static_assert(BOTAN_MP_WORD_BITS == 64, "Unexpected word size"); - - word hi = 0, lo = 0; - - mul64x64_128(a, b, &lo, &hi); - - lo += c; - hi += (lo < c); // carry? - - lo += *d; - hi += (lo < *d); // carry? - - *d = hi; - return lo; -#endif - } - -} - -} - -#endif diff --git a/src/math/mp/mp_generic/mp_asmi.h b/src/math/mp/mp_generic/mp_asmi.h index 8225f372d..018055696 100644 --- a/src/math/mp/mp_generic/mp_asmi.h +++ b/src/math/mp/mp_generic/mp_asmi.h @@ -9,7 +9,7 @@ #ifndef BOTAN_MP_ASM_INTERNAL_H__ #define BOTAN_MP_ASM_INTERNAL_H__ -#include +#include namespace Botan { diff --git a/src/math/mp/mp_generic/mp_madd.h b/src/math/mp/mp_generic/mp_madd.h new file mode 100644 index 000000000..17713f55f --- /dev/null +++ b/src/math/mp/mp_generic/mp_madd.h @@ -0,0 +1,73 @@ +/* +* Lowest Level MPI Algorithms +* (C) 1999-2008,2013 Jack Lloyd +* 2006 Luca Piccarreta +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MP_WORD_MULADD_H__ +#define BOTAN_MP_WORD_MULADD_H__ + +#include + +namespace Botan { + +extern "C" { + +/* +* Word Multiply/Add +*/ +inline word word_madd2(word a, word b, word* c) + { +#if defined(BOTAN_HAS_MP_DWORD) + const dword s = static_cast(a) * b + *c; + *c = static_cast(s >> BOTAN_MP_WORD_BITS); + return static_cast(s); +#else + static_assert(BOTAN_MP_WORD_BITS == 64, "Unexpected word size"); + + word hi = 0, lo = 0; + + mul64x64_128(a, b, &lo, &hi); + + lo += *c; + hi += (lo < *c); // carry? + + *c = hi; + return lo; +#endif + } + +/* +* Word Multiply/Add +*/ +inline word word_madd3(word a, word b, word c, word* d) + { +#if defined(BOTAN_HAS_MP_DWORD) + const dword s = static_cast(a) * b + c + *d; + *d = static_cast(s >> BOTAN_MP_WORD_BITS); + return static_cast(s); +#else + static_assert(BOTAN_MP_WORD_BITS == 64, "Unexpected word size"); + + word hi = 0, lo = 0; + + mul64x64_128(a, b, &lo, &hi); + + lo += c; + hi += (lo < c); // carry? + + lo += *d; + hi += (lo < *d); // carry? + + *d = hi; + return lo; +#endif + } + +} + +} + +#endif diff --git a/src/math/mp/mp_misc.cpp b/src/math/mp/mp_misc.cpp index 2aff00592..0efd5fd19 100644 --- a/src/math/mp/mp_misc.cpp +++ b/src/math/mp/mp_misc.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include namespace Botan { diff --git a/src/math/mp/mp_monty.cpp b/src/math/mp/mp_monty.cpp index 57a2b51a6..095457dbe 100644 --- a/src/math/mp/mp_monty.cpp +++ b/src/math/mp/mp_monty.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include diff --git a/src/math/mp/mp_mulop.cpp b/src/math/mp/mp_mulop.cpp index e6a8ba891..0c79cc2ef 100644 --- a/src/math/mp/mp_mulop.cpp +++ b/src/math/mp/mp_mulop.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include diff --git a/src/math/mp/mp_x86_32/info.txt b/src/math/mp/mp_x86_32/info.txt index 432f909f8..f36abaf62 100644 --- a/src/math/mp/mp_x86_32/info.txt +++ b/src/math/mp/mp_x86_32/info.txt @@ -3,7 +3,7 @@ load_on dep mp_bits 32 -mp_asm.h +mp_madd.h mp_asmi.h diff --git a/src/math/mp/mp_x86_32/mp_asm.h b/src/math/mp/mp_x86_32/mp_asm.h deleted file mode 100644 index 9be5680f8..000000000 --- a/src/math/mp/mp_x86_32/mp_asm.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -* Lowest Level MPI Algorithms -* (C) 1999-2008 Jack Lloyd -* 2006 Luca Piccarreta -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MP_ASM_H__ -#define BOTAN_MP_ASM_H__ - -#include - -#if (BOTAN_MP_WORD_BITS != 32) - #error The mp_x86_32 module requires that BOTAN_MP_WORD_BITS == 32 -#endif - -namespace Botan { - -extern "C" { - -/* -* Helper Macros for x86 Assembly -*/ -#define ASM(x) x "\n\t" - -/* -* Word Multiply -*/ -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"(*c) - : "0"(a), "1"(b), [c]"g"(*c) : "cc"); - - return a; - } - -/* -* Word Multiply/Add -*/ -inline word word_madd3(word a, word b, word c, word* d) - { - asm( - ASM("mull %[b]") - - ASM("addl %[c],%[a]") - ASM("adcl $0,%[carry]") - - ASM("addl %[d],%[a]") - ASM("adcl $0,%[carry]") - - : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d) - : "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc"); - - return a; - } - -} - -} - -#endif diff --git a/src/math/mp/mp_x86_32/mp_asmi.h b/src/math/mp/mp_x86_32/mp_asmi.h index c7b679e80..9b858c8d5 100644 --- a/src/math/mp/mp_x86_32/mp_asmi.h +++ b/src/math/mp/mp_x86_32/mp_asmi.h @@ -9,7 +9,7 @@ #ifndef BOTAN_MP_ASM_INTERNAL_H__ #define BOTAN_MP_ASM_INTERNAL_H__ -#include +#include namespace Botan { diff --git a/src/math/mp/mp_x86_32/mp_madd.h b/src/math/mp/mp_x86_32/mp_madd.h new file mode 100644 index 000000000..9d60c721d --- /dev/null +++ b/src/math/mp/mp_x86_32/mp_madd.h @@ -0,0 +1,67 @@ +/* +* Lowest Level MPI Algorithms +* (C) 1999-2008 Jack Lloyd +* 2006 Luca Piccarreta +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MP_WORD_MULADD_H__ +#define BOTAN_MP_WORD_MULADD_H__ + +#include + +#if (BOTAN_MP_WORD_BITS != 32) + #error The mp_x86_32 module requires that BOTAN_MP_WORD_BITS == 32 +#endif + +namespace Botan { + +extern "C" { + +/* +* Helper Macros for x86 Assembly +*/ +#define ASM(x) x "\n\t" + +/* +* Word Multiply +*/ +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"(*c) + : "0"(a), "1"(b), [c]"g"(*c) : "cc"); + + return a; + } + +/* +* Word Multiply/Add +*/ +inline word word_madd3(word a, word b, word c, word* d) + { + asm( + ASM("mull %[b]") + + ASM("addl %[c],%[a]") + ASM("adcl $0,%[carry]") + + ASM("addl %[d],%[a]") + ASM("adcl $0,%[carry]") + + : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d) + : "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc"); + + return a; + } + +} + +} + +#endif diff --git a/src/math/mp/mp_x86_32_msvc/info.txt b/src/math/mp/mp_x86_32_msvc/info.txt index 8d35c02e7..3029d6a61 100644 --- a/src/math/mp/mp_x86_32_msvc/info.txt +++ b/src/math/mp/mp_x86_32_msvc/info.txt @@ -3,7 +3,7 @@ mp_bits 32 load_on dep -mp_generic:mp_asm.h +mp_generic:mp_madd.h mp_asmi.h diff --git a/src/math/mp/mp_x86_32_msvc/mp_asmi.h b/src/math/mp/mp_x86_32_msvc/mp_asmi.h index aee457d65..ef149c920 100644 --- a/src/math/mp/mp_x86_32_msvc/mp_asmi.h +++ b/src/math/mp/mp_x86_32_msvc/mp_asmi.h @@ -9,7 +9,7 @@ #ifndef BOTAN_MP_ASM_INTERNAL_H__ #define BOTAN_MP_ASM_INTERNAL_H__ -#include +#include namespace Botan { diff --git a/src/math/mp/mp_x86_64/info.txt b/src/math/mp/mp_x86_64/info.txt index fdcc05dd6..75c42ddc1 100644 --- a/src/math/mp/mp_x86_64/info.txt +++ b/src/math/mp/mp_x86_64/info.txt @@ -3,7 +3,7 @@ load_on dep mp_bits 64 -mp_asm.h +mp_madd.h mp_asmi.h diff --git a/src/math/mp/mp_x86_64/mp_asm.h b/src/math/mp/mp_x86_64/mp_asm.h deleted file mode 100644 index edfaf6352..000000000 --- a/src/math/mp/mp_x86_64/mp_asm.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -* Lowest Level MPI Algorithms -* (C) 1999-2008 Jack Lloyd -* 2006 Luca Piccarreta -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MP_ASM_H__ -#define BOTAN_MP_ASM_H__ - -#include - -#if (BOTAN_MP_WORD_BITS != 64) - #error The mp_x86_64 module requires that BOTAN_MP_WORD_BITS == 64 -#endif - -namespace Botan { - -extern "C" { - -/* -* Helper Macros for x86-64 Assembly -*/ -#define ASM(x) x "\n\t" - -/* -* Word Multiply -*/ -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"(*c) - : "0"(a), "1"(b), [c]"g"(*c) : "cc"); - - return a; - } - -/* -* Word Multiply/Add -*/ -inline word word_madd3(word a, word b, word c, word* d) - { - asm( - ASM("mulq %[b]") - - ASM("addq %[c],%[a]") - ASM("adcq $0,%[carry]") - - ASM("addq %[d],%[a]") - ASM("adcq $0,%[carry]") - - : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d) - : "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc"); - - return a; - } - -#undef ASM - -} - -} - -#endif diff --git a/src/math/mp/mp_x86_64/mp_asmi.h b/src/math/mp/mp_x86_64/mp_asmi.h index f14df0e89..b2f1202e3 100644 --- a/src/math/mp/mp_x86_64/mp_asmi.h +++ b/src/math/mp/mp_x86_64/mp_asmi.h @@ -9,7 +9,7 @@ #ifndef BOTAN_MP_ASM_INTERNAL_H__ #define BOTAN_MP_ASM_INTERNAL_H__ -#include +#include namespace Botan { diff --git a/src/math/mp/mp_x86_64/mp_madd.h b/src/math/mp/mp_x86_64/mp_madd.h new file mode 100644 index 000000000..4c0d79931 --- /dev/null +++ b/src/math/mp/mp_x86_64/mp_madd.h @@ -0,0 +1,69 @@ +/* +* Lowest Level MPI Algorithms +* (C) 1999-2008 Jack Lloyd +* 2006 Luca Piccarreta +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MP_WORD_MULADD_H__ +#define BOTAN_MP_WORD_MULADD_H__ + +#include + +#if (BOTAN_MP_WORD_BITS != 64) + #error The mp_x86_64 module requires that BOTAN_MP_WORD_BITS == 64 +#endif + +namespace Botan { + +extern "C" { + +/* +* Helper Macros for x86-64 Assembly +*/ +#define ASM(x) x "\n\t" + +/* +* Word Multiply +*/ +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"(*c) + : "0"(a), "1"(b), [c]"g"(*c) : "cc"); + + return a; + } + +/* +* Word Multiply/Add +*/ +inline word word_madd3(word a, word b, word c, word* d) + { + asm( + ASM("mulq %[b]") + + ASM("addq %[c],%[a]") + ASM("adcq $0,%[carry]") + + ASM("addq %[d],%[a]") + ASM("adcq $0,%[carry]") + + : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d) + : "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc"); + + return a; + } + +#undef ASM + +} + +} + +#endif -- cgit v1.2.3