diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-09-03 08:33:33 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-09-03 08:38:42 +0200 |
commit | 7f4d9adf958f00805e60a353d2779434aca36fe2 (patch) | |
tree | 2b92aa777465e63a78fa3cc3365399f2768da6e1 | |
parent | 9ecba820b90c85bd927fbb18fabe0f6fc8f97141 (diff) | |
download | kernel-crypto-7f4d9adf958f00805e60a353d2779434aca36fe2.tar.gz kernel-crypto-7f4d9adf958f00805e60a353d2779434aca36fe2.tar.xz kernel-crypto-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.
-rw-r--r-- | libtommath/bn_mp_div.c | 2 | ||||
-rw-r--r-- | libtommath/bn_mp_div_3.c | 2 | ||||
-rw-r--r-- | libtommath/bn_mp_div_d.c | 2 | ||||
-rw-r--r-- | libtommath/tommath.h | 17 |
4 files changed, 16 insertions, 7 deletions
diff --git a/libtommath/bn_mp_div.c b/libtommath/bn_mp_div.c index aee9c94324d..723c8b503dd 100644 --- a/libtommath/bn_mp_div.c +++ b/libtommath/bn_mp_div.c @@ -195,7 +195,7 @@ int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) mp_word tmp; tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT); tmp |= ((mp_word) x.dp[i - 1]); - tmp /= ((mp_word) y.dp[t]); + tmp = word_div_int(tmp, (int)y.dp[t]); if (tmp > (mp_word) MP_MASK) tmp = MP_MASK; q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK)); diff --git a/libtommath/bn_mp_div_3.c b/libtommath/bn_mp_div_3.c index 3c60269ecea..608e759e366 100644 --- a/libtommath/bn_mp_div_3.c +++ b/libtommath/bn_mp_div_3.c @@ -25,7 +25,7 @@ mp_div_3 (mp_int * a, mp_int *c, mp_digit * d) int res, ix; /* b = 2**DIGIT_BIT / 3 */ - b = (((mp_word)1) << ((mp_word)DIGIT_BIT)) / ((mp_word)3); + b = word_div_int (((mp_word)1) << DIGIT_BIT, 3); if ((res = mp_init_size(&q, a->used)) != MP_OKAY) { return res; diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c index 6a26d4f0cf6..63efc2cfa69 100644 --- a/libtommath/bn_mp_div_d.c +++ b/libtommath/bn_mp_div_d.c @@ -87,7 +87,7 @@ int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d) w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]); if (w >= b) { - t = (mp_digit)(w / b); + t = (mp_digit)(word_div_int(w, b)); w -= ((mp_word)t) * ((mp_word)b); } else { t = 0; diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 6653f5550f5..3fa7ae89853 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) |