aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xconfigure.py16
-rw-r--r--src/math/mp/info.txt2
-rw-r--r--src/math/mp/mp_generic/mp_asm.h57
-rw-r--r--src/math/mp/mp_types.h13
-rw-r--r--src/math/mp/mp_word64/info.txt18
-rw-r--r--src/math/mp/mp_word64/mp_asm.h57
-rw-r--r--src/utils/info.txt2
-rw-r--r--src/utils/mul128.h2
8 files changed, 61 insertions, 106 deletions
diff --git a/configure.py b/configure.py
index 87ec8aa4a..011f16c06 100755
--- a/configure.py
+++ b/configure.py
@@ -646,15 +646,14 @@ class ArchInfo(object):
{ 'endian': None,
'family': None,
'unaligned': 'no',
- 'wordsize': None
+ 'wordsize': 32
})
self.submodel_aliases = force_to_dict(self.submodel_aliases)
self.unaligned_ok = (1 if self.unaligned == 'ok' else 0)
- if self.wordsize is not None:
- self.wordsize = int(self.wordsize)
+ self.wordsize = int(self.wordsize)
"""
Return a list of all submodels for this arch, ordered longest
@@ -701,11 +700,10 @@ class ArchInfo(object):
if self.family is not None:
macros.append('TARGET_CPU_IS_%s_FAMILY' % (self.family.upper()))
- if self.wordsize is not None:
- macros.append('TARGET_CPU_NATIVE_WORD_SIZE %d' % (self.wordsize))
+ macros.append('TARGET_CPU_NATIVE_WORD_SIZE %d' % (self.wordsize))
- if self.wordsize == 64:
- macros.append('TARGET_CPU_HAS_NATIVE_64BIT')
+ if self.wordsize == 64:
+ macros.append('TARGET_CPU_HAS_NATIVE_64BIT')
macros.append('TARGET_UNALIGNED_MEMORY_ACCESS_OK %d' % (unaligned_ok))
@@ -1000,13 +998,15 @@ def create_template_vars(build_config, options, modules, cc, arch, osinfo):
mp_bits = [mod.mp_bits for mod in modules if mod.mp_bits != 0]
if mp_bits == []:
- return 32 # default
+ logging.debug('Using arch default MP bits %d' % (arch.wordsize))
+ return arch.wordsize
# Check that settings are consistent across modules
for mp_bit in mp_bits[1:]:
if mp_bit != mp_bits[0]:
raise Exception('Incompatible mp_bits settings found')
+ logging.debug('Using MP bits %d' % (mp_bits[0]))
return mp_bits[0]
def isa_specific_flags(cc, src):
diff --git a/src/math/mp/info.txt b/src/math/mp/info.txt
index 531eee4e4..8dcaa7481 100644
--- a/src/math/mp/info.txt
+++ b/src/math/mp/info.txt
@@ -19,5 +19,5 @@ mp_core.h
</header:internal>
<requires>
-mp_x86_64|mp_word64|mp_x86_32|mp_x86_32_msvc|mp_generic
+mp_x86_64|mp_x86_32|mp_x86_32_msvc|mp_generic
</requires>
diff --git a/src/math/mp/mp_generic/mp_asm.h b/src/math/mp/mp_generic/mp_asm.h
index 08f40aa67..ff00cc24b 100644
--- a/src/math/mp/mp_generic/mp_asm.h
+++ b/src/math/mp/mp_generic/mp_asm.h
@@ -1,6 +1,6 @@
/*
* Lowest Level MPI Algorithms
-* (C) 1999-2008 Jack Lloyd
+* (C) 1999-2008,2013 Jack Lloyd
* 2006 Luca Piccarreta
*
* Distributed under the terms of the Botan license
@@ -13,18 +13,6 @@
namespace Botan {
-#if (BOTAN_MP_WORD_BITS == 8)
- typedef u16bit dword;
-#elif (BOTAN_MP_WORD_BITS == 16)
- typedef u32bit dword;
-#elif (BOTAN_MP_WORD_BITS == 32)
- typedef u64bit dword;
-#elif (BOTAN_MP_WORD_BITS == 64)
- #error BOTAN_MP_WORD_BITS can be 64 only with assembly support
-#else
- #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64
-#endif
-
extern "C" {
/*
@@ -32,9 +20,23 @@ extern "C" {
*/
inline word word_madd2(word a, word b, word* c)
{
- dword z = (dword)a * b + *c;
- *c = (word)(z >> BOTAN_MP_WORD_BITS);
- return (word)z;
+#if defined(BOTAN_HAS_MP_DWORD)
+ const dword s = static_cast<dword>(a) * b + *c;
+ *c = static_cast<word>(s >> BOTAN_MP_WORD_BITS);
+ return static_cast<word>(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
}
/*
@@ -42,9 +44,26 @@ inline word word_madd2(word a, word b, word* c)
*/
inline word word_madd3(word a, word b, word c, word* d)
{
- dword z = (dword)a * b + c + *d;
- *d = (word)(z >> BOTAN_MP_WORD_BITS);
- return (word)z;
+#if defined(BOTAN_HAS_MP_DWORD)
+ const dword s = static_cast<dword>(a) * b + c + *d;
+ *d = static_cast<word>(s >> BOTAN_MP_WORD_BITS);
+ return static_cast<word>(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
}
}
diff --git a/src/math/mp/mp_types.h b/src/math/mp/mp_types.h
index 1648713ed..60282fb83 100644
--- a/src/math/mp/mp_types.h
+++ b/src/math/mp/mp_types.h
@@ -9,17 +9,30 @@
#define BOTAN_MPI_TYPES_H__
#include <botan/types.h>
+#include <botan/mul128.h>
namespace Botan {
#if (BOTAN_MP_WORD_BITS == 8)
typedef byte word;
+ typedef u16bit dword;
+ #define BOTAN_HAS_MP_DWORD
#elif (BOTAN_MP_WORD_BITS == 16)
typedef u16bit word;
+ typedef u32bit dword;
+ #define BOTAN_HAS_MP_DWORD
#elif (BOTAN_MP_WORD_BITS == 32)
typedef u32bit word;
+ typedef u64bit dword;
+ #define BOTAN_HAS_MP_DWORD
#elif (BOTAN_MP_WORD_BITS == 64)
typedef u64bit word;
+
+ #if defined(BOTAN_TARGET_HAS_NATIVE_UINT128)
+ typedef uint128_t dword;
+ #define BOTAN_HAS_MP_DWORD
+ #endif
+
#else
#error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64
#endif
diff --git a/src/math/mp/mp_word64/info.txt b/src/math/mp/mp_word64/info.txt
deleted file mode 100644
index a12221f4e..000000000
--- a/src/math/mp/mp_word64/info.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-mp_bits 64
-
-load_on dep
-
-<header:internal>
-mp_asm.h
-mp_generic:mp_asmi.h
-</header:internal>
-
-<arch>
-alpha
-ia64
-mips64
-ppc64
-s390x
-sparc64
-x86_64
-</arch>
diff --git a/src/math/mp/mp_word64/mp_asm.h b/src/math/mp/mp_word64/mp_asm.h
deleted file mode 100644
index 76d2bb918..000000000
--- a/src/math/mp/mp_word64/mp_asm.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-* MPI Multiply-Add Core
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_MP_MADD_H__
-#define BOTAN_MP_MADD_H__
-
-#include <botan/mp_types.h>
-#include <botan/internal/mul128.h>
-
-namespace Botan {
-
-#if (BOTAN_MP_WORD_BITS != 64)
- #error The mp_word64 module requires that BOTAN_MP_WORD_BITS == 64
-#endif
-
-/*
-* Word Multiply/Add
-*/
-inline word word_madd2(word a, word b, word* c)
- {
- word z0 = 0, z1 = 0;
-
- mul64x64_128(a, b, &z1, &z0);
-
- z1 += *c;
- z0 += (z1 < *c);
-
- *c = z0;
- return z1;
- }
-
-/*
-* Word Multiply/Add
-*/
-inline word word_madd3(word a, word b, word c, word* d)
- {
- word z0 = 0, z1 = 0;
-
- mul64x64_128(a, b, &z1, &z0);
-
- z1 += c;
- z0 += (z1 < c);
-
- z1 += *d;
- z0 += (z1 < *d);
-
- *d = z0;
- return z1;
- }
-
-}
-
-#endif
diff --git a/src/utils/info.txt b/src/utils/info.txt
index 1d77b87a7..59dffa4ae 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -15,7 +15,6 @@ zero_mem.cpp
<header:internal>
bit_ops.h
-mul128.h
prefetch.h
rounding.h
semaphore.h
@@ -33,6 +32,7 @@ exceptn.h
get_byte.h
loadstor.h
mem_ops.h
+mul128.h
parsing.h
rotate.h
types.h
diff --git a/src/utils/mul128.h b/src/utils/mul128.h
index 83d6f5aa6..7927e5d08 100644
--- a/src/utils/mul128.h
+++ b/src/utils/mul128.h
@@ -118,6 +118,4 @@ inline void mul64x64_128(u64bit a, u64bit b, u64bit* lo, u64bit* hi)
}
-}
-
#endif