summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_div_d.c
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 /libtommath/bn_mp_div_d.c
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.
Diffstat (limited to 'libtommath/bn_mp_div_d.c')
-rw-r--r--libtommath/bn_mp_div_d.c22
1 files changed, 6 insertions, 16 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);
}