summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-22 08:48:23 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-09-22 08:48:23 (GMT)
commitdecba31378095b56c8854968f0c9595761c68ed9 (patch)
treed44e6a9c46969ff4b3b0fb466a351b9c90ed765d
parent67831aeaaa04f492749313df68cea14d6732d875 (diff)
downloadtcl-decba31378095b56c8854968f0c9595761c68ed9.zip
tcl-decba31378095b56c8854968f0c9595761c68ed9.tar.gz
tcl-decba31378095b56c8854968f0c9595761c68ed9.tar.bz2
Make libtommath's "make" work in Tcl environment (for testing). Eliminate internal s_is_power_of_two(), which can better be done inline. Fix tommath.h for _MSC_VER.
-rw-r--r--libtommath/bn_mp_div_d.c22
-rw-r--r--libtommath/tommath.h4
2 files changed, 9 insertions, 17 deletions
diff --git a/libtommath/bn_mp_div_d.c b/libtommath/bn_mp_div_d.c
index d0131c3..c408602 100644
--- a/libtommath/bn_mp_div_d.c
+++ b/libtommath/bn_mp_div_d.c
@@ -15,21 +15,6 @@
* Tom St Denis, tstdenis82@gmail.com, http://libtom.org
*/
-static int s_is_power_of_two(mp_digit b, int *p)
-{
- int x;
-
- /* Gives the wrong result for b==1, but this function
- * is never called for this value anyway. */
- for (x = 1; x < DIGIT_BIT; x++) {
- if (b == (((mp_digit)1)<<x)) {
- *p = x;
- return 1;
- }
- }
- return 0;
-}
-
/* single digit division (based on routine from MPI) */
int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
{
@@ -55,7 +40,12 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
}
/* power of two ? */
- if (((b & (b-1)) == 0) && s_is_power_of_two(b, &ix)) {
+ if (((b & (b-1)) == 0)) {
+ for (ix = 1; ix < DIGIT_BIT; ix++) {
+ if (b == (((mp_digit)1)<<ix)) {
+ break;
+ }
+ }
if (d != NULL) {
*d = a->dp[0] & ((((mp_digit)1)<<ix) - 1);
}
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index dee7ab5..e067cb4 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -33,11 +33,13 @@ extern "C" {
defined(__sparcv9) || defined(__sparc_v9__) || defined(__sparc64__) || \
defined(__ia64) || defined(__ia64__) || defined(__itanium__) || defined(_M_IA64) || \
defined(__LP64__) || defined(_LP64) || defined(__64BIT__)
-# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
+# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT) || defined(_MSC_VER))
# define MP_64BIT
# endif
#endif
+typedef unsigned long long Tcl_WideUInt;
+
/* some default configurations.
*
* A "mp_digit" must be able to hold DIGIT_BIT + 1 bits