summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-03-25 21:50:34 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-03-25 21:50:34 (GMT)
commit6d27f27fe64178257962cf3fa9cab61b03cbcc51 (patch)
treec8909ef172c239ac052863e6cb5f450c68465f4b
parentaaf56c80863b3c12efb020dd21eaa440be153968 (diff)
downloadtcl-6d27f27fe64178257962cf3fa9cab61b03cbcc51.zip
tcl-6d27f27fe64178257962cf3fa9cab61b03cbcc51.tar.gz
tcl-6d27f27fe64178257962cf3fa9cab61b03cbcc51.tar.bz2
Eliminate all usage of mp_iszero/mp_iseven/mp_isodd/mp_isneg from libtommath: In the upcoming new version those will become real functions, causing possible binary incompatibility. This change makes Tcl independant from libtommath's changes.
-rw-r--r--generic/tclBasic.c2
-rw-r--r--generic/tclExecute.c8
-rw-r--r--generic/tclStrToD.c6
-rw-r--r--generic/tclStubInit.c10
-rw-r--r--generic/tclTestObj.c4
-rw-r--r--generic/tclTomMath.decls7
-rw-r--r--generic/tclTomMathDecls.h36
-rw-r--r--unix/Makefile.in14
-rw-r--r--win/Makefile.in2
-rw-r--r--win/makefile.vc2
10 files changed, 78 insertions, 13 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 9429c24..5480835 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -7252,7 +7252,7 @@ ExprIsqrtFunc(
if (Tcl_GetBignumFromObj(interp, objv[1], &big) != TCL_OK) {
return TCL_ERROR;
}
- if (SIGN(&big) == MP_NEG) {
+ if (big.sign) {
mp_clear(&big);
goto negarg;
}
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 77a173e..ca14a55 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -8367,7 +8367,7 @@ ExecuteExtendedBinaryMathOp(
mp_init(&bigResult);
mp_init(&bigRemainder);
mp_div(&big1, &big2, &bigResult, &bigRemainder);
- if (!mp_iszero(&bigRemainder) && (bigRemainder.sign != big2.sign)) {
+ if ((bigRemainder.used) != 0 && (bigRemainder.sign != big2.sign)) {
/*
* Convert to Tcl's integer division rules.
*/
@@ -8768,7 +8768,7 @@ ExecuteExtendedBinaryMathOp(
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
negativeExponent = (mp_cmp_d(&big2, 0) == MP_LT);
mp_mod_2d(&big2, 1, &big2);
- oddExponent = !mp_iszero(&big2);
+ oddExponent = big2.used != 0;
mp_clear(&big2);
break;
}
@@ -9249,7 +9249,7 @@ ExecuteExtendedBinaryMathOp(
mp_mul(&big1, &big2, &bigResult);
break;
case INST_DIV:
- if (mp_iszero(&big2)) {
+ if (big2.used == 0) {
mp_clear(&big1);
mp_clear(&big2);
mp_clear(&bigResult);
@@ -9258,7 +9258,7 @@ ExecuteExtendedBinaryMathOp(
mp_init(&bigRemainder);
mp_div(&big1, &big2, &bigResult, &bigRemainder);
/* TODO: internals intrusion */
- if (!mp_iszero(&bigRemainder)
+ if (bigRemainder.used != 0
&& (bigRemainder.sign != big2.sign)) {
/*
* Convert to Tcl's integer division rules.
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index 5d601e4..6257409 100644
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -3162,7 +3162,7 @@ ShouldBankerRoundUpPowD(
int isodd) /* 1 if the digit is odd, 0 if even. */
{
int i;
- static const mp_digit topbit = 1 << (DIGIT_BIT - 1);
+ static const mp_digit topbit = ((mp_digit)1) << (DIGIT_BIT - 1);
if (b->used < sd || (b->dp[sd-1] & topbit) == 0) {
return 0;
@@ -4631,7 +4631,7 @@ TclBignumToDouble(
*/
mp_div_2d(a, -shift, &b, NULL);
- if (mp_isodd(&b)) {
+ if (mp_get_bit(&b, 0)) {
if (b.sign == MP_ZPOS) {
mp_add_d(&b, 1, &b);
} else {
@@ -4720,7 +4720,7 @@ TclCeil(
mp_int d;
mp_init(&d);
mp_div_2d(a, -shift, &b, &d);
- exact = mp_iszero(&d);
+ exact = d.used == 0;
mp_clear(&d);
} else {
mp_copy(a, &b);
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 3ff686c..1d15715 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -854,6 +854,16 @@ const TclTomMathStubs tclTomMathStubs = {
TclBNInitBignumFromWideInt, /* 65 */
TclBNInitBignumFromWideUInt, /* 66 */
TclBN_mp_expt_d_ex, /* 67 */
+ 0, /* 68 */
+ 0, /* 69 */
+ TclBN_mp_set_long, /* 70 */
+ 0, /* 71 */
+ 0, /* 72 */
+ 0, /* 73 */
+ 0, /* 74 */
+ 0, /* 75 */
+ 0, /* 76 */
+ TclBN_mp_get_bit, /* 77 */
};
static const TclStubHooks tclStubHooks = {
diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c
index f7d2bae..e395435 100644
--- a/generic/tclTestObj.c
+++ b/generic/tclTestObj.c
@@ -290,9 +290,9 @@ TestbignumobjCmd(
return TCL_ERROR;
}
if (!Tcl_IsShared(varPtr[varIndex])) {
- Tcl_SetIntObj(varPtr[varIndex], mp_iseven(&bignumValue));
+ Tcl_SetIntObj(varPtr[varIndex], !mp_get_bit(&bignumValue, 0));
} else {
- SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(mp_iseven(&bignumValue)));
+ SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(!mp_get_bit(&bignumValue, 0)));
}
mp_clear(&bignumValue);
break;
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 065fe09..09bf97d 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -237,6 +237,13 @@ declare 66 {
declare 67 {
int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
}
+declare 70 {
+ int TclBN_mp_set_long(mp_int *a, unsigned long i)
+}
+declare 77 {
+ int TclBN_mp_get_bit(const mp_int *a, int b)
+}
+
# Local Variables:
# mode: tcl
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index 81cd7c9..dc06fc6 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -74,6 +74,7 @@
#define mp_exch TclBN_mp_exch
#define mp_expt_d TclBN_mp_expt_d
#define mp_expt_d_ex TclBN_mp_expt_d_ex
+#define mp_get_bit TclBN_mp_get_bit
#define mp_grow TclBN_mp_grow
#define mp_init TclBN_mp_init
#define mp_init_copy TclBN_mp_init_copy
@@ -97,6 +98,7 @@
#define mp_rshd TclBN_mp_rshd
#define mp_set TclBN_mp_set
#define mp_set_int TclBN_mp_set_int
+#define mp_set_long TclBN_mp_set_long
#define mp_shrink TclBN_mp_shrink
#define mp_sqr TclBN_mp_sqr
#define mp_sqrt TclBN_mp_sqrt
@@ -307,6 +309,18 @@ EXTERN void TclBNInitBignumFromWideUInt(mp_int *bignum,
/* 67 */
EXTERN int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
mp_int *c, int fast);
+/* Slot 68 is reserved */
+/* Slot 69 is reserved */
+/* 70 */
+EXTERN int TclBN_mp_set_long(mp_int *a, unsigned long i);
+/* Slot 71 is reserved */
+/* Slot 72 is reserved */
+/* Slot 73 is reserved */
+/* Slot 74 is reserved */
+/* Slot 75 is reserved */
+/* Slot 76 is reserved */
+/* 77 */
+EXTERN int TclBN_mp_get_bit(const mp_int *a, int b);
typedef struct TclTomMathStubs {
int magic;
@@ -380,6 +394,16 @@ typedef struct TclTomMathStubs {
void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
+ void (*reserved68)(void);
+ void (*reserved69)(void);
+ int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */
+ void (*reserved71)(void);
+ void (*reserved72)(void);
+ void (*reserved73)(void);
+ void (*reserved74)(void);
+ void (*reserved75)(void);
+ void (*reserved76)(void);
+ int (*tclBN_mp_get_bit) (const mp_int *a, int b); /* 77 */
} TclTomMathStubs;
extern const TclTomMathStubs *tclTomMathStubsPtr;
@@ -530,6 +554,18 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBNInitBignumFromWideUInt) /* 66 */
#define TclBN_mp_expt_d_ex \
(tclTomMathStubsPtr->tclBN_mp_expt_d_ex) /* 67 */
+/* Slot 68 is reserved */
+/* Slot 69 is reserved */
+#define TclBN_mp_set_long \
+ (tclTomMathStubsPtr->tclBN_mp_set_long) /* 70 */
+/* Slot 71 is reserved */
+/* Slot 72 is reserved */
+/* Slot 73 is reserved */
+/* Slot 74 is reserved */
+/* Slot 75 is reserved */
+/* Slot 76 is reserved */
+#define TclBN_mp_get_bit \
+ (tclTomMathStubsPtr->tclBN_mp_get_bit) /* 77 */
#endif /* defined(USE_TCL_STUBS) */
diff --git a/unix/Makefile.in b/unix/Makefile.in
index d13c490..1610962 100644
--- a/unix/Makefile.in
+++ b/unix/Makefile.in
@@ -321,8 +321,8 @@ TOMMATH_OBJS = bncore.o bn_reverse.o bn_fast_s_mp_mul_digs.o \
bn_mp_cmp.o bn_mp_cmp_d.o bn_mp_cmp_mag.o \
bn_mp_cnt_lsb.o bn_mp_copy.o \
bn_mp_count_bits.o bn_mp_div.o bn_mp_div_d.o bn_mp_div_2.o \
- bn_mp_div_2d.o bn_mp_div_3.o bn_mp_exch.o \
- bn_mp_expt_d.o bn_mp_expt_d_ex.o bn_mp_grow.o bn_mp_init.o \
+ bn_mp_div_2d.o bn_mp_div_3.o bn_mp_exch.o bn_mp_expt_d.o \
+ bn_mp_expt_d_ex.o bn_mp_get_bit.o bn_mp_grow.o bn_mp_init.o \
bn_mp_init_copy.o bn_mp_init_multi.o bn_mp_init_set.o \
bn_mp_init_set_int.o bn_mp_init_size.o bn_mp_karatsuba_mul.o \
bn_mp_karatsuba_sqr.o \
@@ -330,7 +330,7 @@ TOMMATH_OBJS = bncore.o bn_reverse.o bn_fast_s_mp_mul_digs.o \
bn_mp_mul_2d.o bn_mp_mul_d.o bn_mp_neg.o bn_mp_or.o \
bn_mp_radix_size.o bn_mp_radix_smap.o \
bn_mp_read_radix.o bn_mp_rshd.o bn_mp_set.o bn_mp_set_int.o \
- bn_mp_shrink.o \
+ bn_mp_set_long.o bn_mp_shrink.o \
bn_mp_sqr.o bn_mp_sqrt.o bn_mp_sub.o bn_mp_sub_d.o \
bn_mp_to_unsigned_bin.o bn_mp_to_unsigned_bin_n.o \
bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_toradix_n.o \
@@ -506,6 +506,7 @@ TOMMATH_SRCS = \
$(TOMMATH_DIR)/bn_mp_exch.c \
$(TOMMATH_DIR)/bn_mp_expt_d.c \
$(TOMMATH_DIR)/bn_mp_expt_d_ex.c \
+ $(TOMMATH_DIR)/bn_mp_get_bit.c \
$(TOMMATH_DIR)/bn_mp_grow.c \
$(TOMMATH_DIR)/bn_mp_init.c \
$(TOMMATH_DIR)/bn_mp_init_copy.c \
@@ -530,6 +531,7 @@ TOMMATH_SRCS = \
$(TOMMATH_DIR)/bn_mp_rshd.c \
$(TOMMATH_DIR)/bn_mp_set.c \
$(TOMMATH_DIR)/bn_mp_set_int.c \
+ $(TOMMATH_DIR)/bn_mp_set_long.c \
$(TOMMATH_DIR)/bn_mp_shrink.c \
$(TOMMATH_DIR)/bn_mp_sqr.c \
$(TOMMATH_DIR)/bn_mp_sqrt.c \
@@ -1426,6 +1428,9 @@ bn_mp_expt_d.o: $(TOMMATH_DIR)/bn_mp_expt_d.c $(MATHHDRS)
bn_mp_expt_d_ex.o: $(TOMMATH_DIR)/bn_mp_expt_d_ex.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_expt_d_ex.c
+bn_mp_get_bit.o: $(TOMMATH_DIR)/bn_mp_get_bit.c $(MATHHDRS)
+ $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_get_bit.c
+
bn_mp_grow.o: $(TOMMATH_DIR)/bn_mp_grow.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_grow.c
@@ -1498,6 +1503,9 @@ bn_mp_set.o: $(TOMMATH_DIR)/bn_mp_set.c $(MATHHDRS)
bn_mp_set_int.o: $(TOMMATH_DIR)/bn_mp_set_int.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_set_int.c
+bn_mp_set_long.o: $(TOMMATH_DIR)/bn_mp_set_long.c $(MATHHDRS)
+ $(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_set_long.c
+
bn_mp_shrink.o: $(TOMMATH_DIR)/bn_mp_shrink.c $(MATHHDRS)
$(CC) -c $(CC_SWITCHES) $(TOMMATH_DIR)/bn_mp_shrink.c
diff --git a/win/Makefile.in b/win/Makefile.in
index e6b9801..b983f0a 100644
--- a/win/Makefile.in
+++ b/win/Makefile.in
@@ -335,6 +335,7 @@ TOMMATH_OBJS = \
bn_mp_exch.${OBJEXT} \
bn_mp_expt_d.${OBJEXT} \
bn_mp_expt_d_ex.${OBJEXT} \
+ bn_mp_get_bit.${OBJEXT} \
bn_mp_grow.${OBJEXT} \
bn_mp_init.${OBJEXT} \
bn_mp_init_copy.${OBJEXT} \
@@ -359,6 +360,7 @@ TOMMATH_OBJS = \
bn_mp_rshd.${OBJEXT} \
bn_mp_set.${OBJEXT} \
bn_mp_set_int.${OBJEXT} \
+ bn_mp_set_long.${OBJEXT} \
bn_mp_shrink.${OBJEXT} \
bn_mp_sqr.${OBJEXT} \
bn_mp_sqrt.${OBJEXT} \
diff --git a/win/makefile.vc b/win/makefile.vc
index 647ba89..adfd7c4 100644
--- a/win/makefile.vc
+++ b/win/makefile.vc
@@ -275,6 +275,7 @@ TOMMATHOBJS = \
$(TMP_DIR)\bn_mp_exch.obj \
$(TMP_DIR)\bn_mp_expt_d.obj \
$(TMP_DIR)\bn_mp_expt_d_ex.obj \
+ $(TMP_DIR)\bn_mp_get_bit.obj \
$(TMP_DIR)\bn_mp_grow.obj \
$(TMP_DIR)\bn_mp_init.obj \
$(TMP_DIR)\bn_mp_init_copy.obj \
@@ -299,6 +300,7 @@ TOMMATHOBJS = \
$(TMP_DIR)\bn_mp_rshd.obj \
$(TMP_DIR)\bn_mp_set.obj \
$(TMP_DIR)\bn_mp_set_int.obj \
+ $(TMP_DIR)\bn_mp_set_long.obj \
$(TMP_DIR)\bn_mp_shrink.obj \
$(TMP_DIR)\bn_mp_sqr.obj \
$(TMP_DIR)\bn_mp_sqrt.obj \