summaryrefslogtreecommitdiffstats
path: root/libtommath/tommath.h
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2010-09-03 08:33:33 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-09-03 08:38:42 +0200
commit7f4d9adf958f00805e60a353d2779434aca36fe2 (patch)
tree2b92aa777465e63a78fa3cc3365399f2768da6e1 /libtommath/tommath.h
parent9ecba820b90c85bd927fbb18fabe0f6fc8f97141 (diff)
downloadcryptodev-linux-7f4d9adf958f00805e60a353d2779434aca36fe2.tar.gz
cryptodev-linux-7f4d9adf958f00805e60a353d2779434aca36fe2.tar.xz
cryptodev-linux-7f4d9adf958f00805e60a353d2779434aca36fe2.zip
Optimizations for 32bit machines by using a 64bit word type and 32bit digit.
Unfortunately we cannot do the same for 64bit since we don't have an 128bit type in kernel.
Diffstat (limited to 'libtommath/tommath.h')
-rw-r--r--libtommath/tommath.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index 6653f55..3fa7ae8 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -20,6 +20,7 @@
#include <linux/slab.h>
#include <linux/random.h>
#include <linux/ctype.h>
+#include <linux/math64.h>
#define CHAR_BIT sizeof(uint8_t)*8
@@ -65,19 +66,22 @@ extern "C" {
* [any size beyond that is ok provided it doesn't overflow the data type]
*/
-/* FIXME: This can be improved, but might require to use a 64bit division
- * on 32bit machines and an 128bit on 64.
+/* FIXME: This can be improved, but requires to use 128bit division
+ * on 64bit machines, which is not available in kernel now.
*/
-#if BITS_PER_LONG <= 32
+#if BITS_PER_LONG < 32
typedef uint16_t mp_digit;
typedef uint32_t mp_word;
# define DIGIT_BIT 15
-#elif BITS_PER_LONG == 64
+#elif BITS_PER_LONG <= 64
typedef uint32_t mp_digit;
typedef uint64_t mp_word;
+
+# define word_div_int(x,y) div_u64((x),(y))
+
# define DIGIT_BIT 31
#endif
@@ -92,6 +96,11 @@ extern "C" {
#endif
+#ifndef word_div_int
+# define word_div_int(x,y) ((x)/(y))
+#endif
+
+
/* define heap macros */
#ifndef XMALLOC
# define XMALLOC(x) kmalloc(x, GFP_KERNEL)