summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-05-31 11:28:39 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-05-31 11:28:39 (GMT)
commitbe861c2430ca13fd13b81ff3bcdc6fc0cb4ec8f4 (patch)
tree1c7b9ff79fe0e418ec7f713b79f04fe0f846369b /generic
parent984c717026e7de57c6dab8db6f99bea6fcf08308 (diff)
downloadtcl-be861c2430ca13fd13b81ff3bcdc6fc0cb4ec8f4.zip
tcl-be861c2430ca13fd13b81ff3bcdc6fc0cb4ec8f4.tar.gz
tcl-be861c2430ca13fd13b81ff3bcdc6fc0cb4ec8f4.tar.bz2
Rename mp_get_bit to s_mp_get_bit, rename mp_tc_div_2d to mp_signed_rsh, remove mp_tc_(add|or|xor) functions in favor of mp_(add|or|xor) which can now handle twos-complement. Following ongoing changes in libtommath development.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclExecute.c2
-rw-r--r--generic/tclStrToD.c2
-rw-r--r--generic/tclStubInit.c8
-rw-r--r--generic/tclTestObj.c4
-rw-r--r--generic/tclTomMath.decls2
-rw-r--r--generic/tclTomMath.h35
-rw-r--r--generic/tclTomMathDecls.h19
7 files changed, 34 insertions, 38 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 812ee84..bf2d7bc 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -8642,7 +8642,7 @@ ExecuteExtendedBinaryMathOp(
if (opcode == INST_LSHIFT) {
mp_mul_2d(&big1, shift, &bigResult);
} else {
- mp_tc_div_2d(&big1, shift, &bigResult);
+ mp_signed_rsh(&big1, shift, &bigResult);
}
mp_clear(&big1);
BIG_RESULT(&bigResult);
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index 6e1b131..4826d1c 100644
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -4631,7 +4631,7 @@ TclBignumToDouble(
*/
mp_div_2d(a, -shift, &b, NULL);
- if (mp_get_bit(&b, 0)) {
+ if (mp_isodd(&b)) {
if (b.sign == MP_ZPOS) {
mp_add_d(&b, 1, &b);
} else {
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 6290aa0..bf05158 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -51,6 +51,12 @@
#undef TclWinGetServByName
#undef TclWinGetSockOpt
#undef TclWinSetSockOpt
+#undef TclBN_mp_tc_and
+#undef TclBN_mp_tc_or
+#undef TclBN_mp_tc_xor
+#define TclBN_mp_tc_and TclBN_mp_and
+#define TclBN_mp_tc_or TclBN_mp_or
+#define TclBN_mp_tc_xor TclBN_mp_xor
/* See bug 510001: TclSockMinimumBuffers needs plat imp */
#ifdef _WIN64
@@ -862,7 +868,7 @@ const TclTomMathStubs tclTomMathStubs = {
TclBN_mp_tc_and, /* 73 */
TclBN_mp_tc_or, /* 74 */
TclBN_mp_tc_xor, /* 75 */
- TclBN_mp_tc_div_2d, /* 76 */
+ TclBN_mp_signed_rsh, /* 76 */
TclBN_mp_get_bit, /* 77 */
};
diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c
index e395435..7f9b561 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_get_bit(&bignumValue, 0));
+ Tcl_SetIntObj(varPtr[varIndex], !mp_isodd(&bignumValue));
} else {
- SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(!mp_get_bit(&bignumValue, 0)));
+ SetVarToObj(varPtr, varIndex, Tcl_NewIntObj(!mp_isodd(&bignumValue)));
}
mp_clear(&bignumValue);
break;
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 6f4b4c3..8703082 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -252,7 +252,7 @@ declare 75 {
int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 76 {
- int TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
+ int TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c)
}
declare 77 {
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index cc9f286..bbcb4bc 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -203,12 +203,14 @@ typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
/* error code to char* string */
-const char *mp_error_to_string(int code);
+/*
+const char *mp_error_to_string(mp_err code);
+*/
/* ---> init and deinit bignum functions <--- */
/* init a bignum */
/*
-int mp_init(mp_int *a);
+mp_err mp_init(mp_int *a);
*/
/* free a bignum */
@@ -218,7 +220,7 @@ void mp_clear(mp_int *a);
/* init a null terminated series of arguments */
/*
-int mp_init_multi(mp_int *mp, ...);
+mp_err mp_init_multi(mp_int *mp, ...);
*/
/* clear a null terminated series of arguments */
@@ -233,23 +235,23 @@ void mp_exch(mp_int *a, mp_int *b);
/* shrink ram required for a bignum */
/*
-int mp_shrink(mp_int *a);
+mp_err mp_shrink(mp_int *a);
*/
/* grow an int to a given size */
/*
-int mp_grow(mp_int *a, int size);
+mp_err mp_grow(mp_int *a, int size);
*/
/* init to a given number of digits */
/*
-int mp_init_size(mp_int *a, int size);
+mp_err mp_init_size(mp_int *a, int size);
*/
/* ---> Basic Manipulations <--- */
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
-#define mp_iseven(a) (!mp_get_bit((a),0))
-#define mp_isodd(a) mp_get_bit((a),0)
+#define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
+#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
#define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
/* set to zero */
@@ -410,24 +412,9 @@ int mp_or(const mp_int *a, const mp_int *b, mp_int *c);
int mp_and(const mp_int *a, const mp_int *b, mp_int *c);
*/
-/* c = a XOR b (two complement) */
-/*
-int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c);
-*/
-
-/* c = a OR b (two complement) */
-/*
-int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c);
-*/
-
-/* c = a AND b (two complement) */
-/*
-int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c);
-*/
-
/* right shift (two complement) */
/*
-int mp_tc_div_2d(const mp_int *a, int b, mp_int *c);
+int mp_signed_rsh(const mp_int *a, int b, mp_int *c);
*/
/* ---> Basic arithmetic <--- */
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index beb34ef..214a131 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -71,6 +71,7 @@
#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 s_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
@@ -102,10 +103,11 @@
#define mp_sqrt TclBN_mp_sqrt
#define mp_sub TclBN_mp_sub
#define mp_sub_d TclBN_mp_sub_d
-#define mp_tc_and TclBN_mp_tc_and
-#define mp_tc_div_2d TclBN_mp_tc_div_2d
-#define mp_tc_or TclBN_mp_tc_or
-#define mp_tc_xor TclBN_mp_tc_xor
+#define mp_signed_rsh TclBN_mp_signed_rsh
+#define mp_tc_and TclBN_mp_and
+#define mp_tc_div_2d TclBN_mp_signed_rsh
+#define mp_tc_or TclBN_mp_or
+#define mp_tc_xor TclBN_mp_xor
#define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin
#define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n
#define mp_toom_mul TclBN_mp_toom_mul
@@ -329,7 +331,8 @@ EXTERN int TclBN_mp_tc_or(const mp_int *a, const mp_int *b,
EXTERN int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
mp_int *c);
/* 76 */
-EXTERN int TclBN_mp_tc_div_2d(const mp_int *a, int b, mp_int *c);
+EXTERN int TclBN_mp_signed_rsh(const mp_int *a, int b,
+ mp_int *c);
/* 77 */
EXTERN int TclBN_mp_get_bit(const mp_int *a, int b);
@@ -413,7 +416,7 @@ typedef struct TclTomMathStubs {
int (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */
int (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
int (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
- int (*tclBN_mp_tc_div_2d) (const mp_int *a, int b, mp_int *c); /* 76 */
+ int (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */
int (*tclBN_mp_get_bit) (const mp_int *a, int b); /* 77 */
} TclTomMathStubs;
@@ -577,8 +580,8 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBN_mp_tc_or) /* 74 */
#define TclBN_mp_tc_xor \
(tclTomMathStubsPtr->tclBN_mp_tc_xor) /* 75 */
-#define TclBN_mp_tc_div_2d \
- (tclTomMathStubsPtr->tclBN_mp_tc_div_2d) /* 76 */
+#define TclBN_mp_signed_rsh \
+ (tclTomMathStubsPtr->tclBN_mp_signed_rsh) /* 76 */
#define TclBN_mp_get_bit \
(tclTomMathStubsPtr->tclBN_mp_get_bit) /* 77 */