From 124e7dd6977a0853d7a8399921e31fd1ccde2dcb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 19 Feb 2014 20:45:22 -0800 Subject: * mpi-patches/faster-square-root (mp_sqrt): Bugfix: was computing square roots that were incorrect in the last digit/bit, because it was not generating the guess mask all the way down to bit zero. Also, added an early test to bail the loop when an the guess at the root happens to be right. * mpi-patches/add-bitops: Refreshed. * mpi-patches/fix-ctype-warnings: Likewise. * mpi-patches/mpi-to-double: Likewise. --- ChangeLog | 14 ++++++++++++++ mpi-patches/add-bitops | 10 +++++----- mpi-patches/faster-square-root | 20 +++++++++++++------- mpi-patches/fix-ctype-warnings | 8 ++++---- mpi-patches/mpi-to-double | 10 +++++----- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80823cbe..fef5ab1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2014-02-19 Kaz Kylheku + + * mpi-patches/faster-square-root (mp_sqrt): Bugfix: was computing square + roots that were incorrect in the last digit/bit, because it was not + generating the guess mask all the way down to bit zero. Also, added + an early test to bail the loop when an the guess at the root happens + to be right. + + * mpi-patches/add-bitops: Refreshed. + + * mpi-patches/fix-ctype-warnings: Likewise. + + * mpi-patches/mpi-to-double: Likewise. + 2014-02-19 Kaz Kylheku Fixing a long-running issue in the TXR pattern language: premature diff --git a/mpi-patches/add-bitops b/mpi-patches/add-bitops index 7eae01cb..2019aa50 100644 --- a/mpi-patches/add-bitops +++ b/mpi-patches/add-bitops @@ -1,7 +1,7 @@ Index: mpi-1.8.6/mpi.c =================================================================== ---- mpi-1.8.6.orig/mpi.c 2012-09-16 10:50:08.270639006 -0700 -+++ mpi-1.8.6/mpi.c 2012-09-17 07:33:38.563334756 -0700 +--- mpi-1.8.6.orig/mpi.c 2014-02-19 19:01:39.562347737 -0800 ++++ mpi-1.8.6/mpi.c 2014-02-19 19:01:43.174297255 -0800 @@ -16,6 +16,9 @@ #include #include @@ -20,7 +20,7 @@ Index: mpi-1.8.6/mpi.c int s_highest_bit_mp(mp_int *a); mp_err s_mp_set_bit(mp_int *a, int bit); -@@ -2330,6 +2334,414 @@ +@@ -2336,6 +2340,414 @@ /* }}} */ @@ -437,8 +437,8 @@ Index: mpi-1.8.6/mpi.c int ix; Index: mpi-1.8.6/mpi.h =================================================================== ---- mpi-1.8.6.orig/mpi.h 2012-09-16 10:50:08.046513006 -0700 -+++ mpi-1.8.6/mpi.h 2012-09-17 07:32:54.738697256 -0700 +--- mpi-1.8.6.orig/mpi.h 2014-02-19 19:01:29.302491325 -0800 ++++ mpi-1.8.6/mpi.h 2014-02-19 19:01:43.178297199 -0800 @@ -54,6 +54,7 @@ /* Macros for accessing the mp_int internals */ diff --git a/mpi-patches/faster-square-root b/mpi-patches/faster-square-root index 30f3da91..36fa4993 100644 --- a/mpi-patches/faster-square-root +++ b/mpi-patches/faster-square-root @@ -1,7 +1,7 @@ Index: mpi-1.8.6/mpi.c =================================================================== ---- mpi-1.8.6.orig/mpi.c 2012-03-04 11:45:43.071884757 -0800 -+++ mpi-1.8.6/mpi.c 2012-03-04 11:45:43.556157007 -0800 +--- mpi-1.8.6.orig/mpi.c 2014-02-17 22:25:46.042680203 -0800 ++++ mpi-1.8.6/mpi.c 2014-02-19 19:00:21.279452088 -0800 @@ -158,6 +158,9 @@ mp_err s_mp_grow(mp_int *mp, mp_size min); /* increase allocated size */ mp_err s_mp_pad(mp_int *mp, mp_size min); /* left pad with zeroes */ @@ -12,7 +12,7 @@ Index: mpi-1.8.6/mpi.c void s_mp_clamp(mp_int *mp); /* clip leading zeroes */ void s_mp_exch(mp_int *a, mp_int *b); /* swap a and b in place */ -@@ -1535,77 +1538,55 @@ +@@ -1535,77 +1538,61 @@ /* {{{ mp_sqrt(a, b) */ @@ -85,8 +85,9 @@ Index: mpi-1.8.6/mpi.c + if ((err = mp_init(&guess_sqr))) + goto cleanup_guess; + -+ for (mask_shift = s_highest_bit_mp(a) / 2; mask_shift > 0; mask_shift--) { ++ for (mask_shift = s_highest_bit_mp(a) / 2; mask_shift >= 0; mask_shift--) { + mp_int *temp; ++ int cmp; + + if ((err = mp_copy(proot, pguess))) + goto cleanup; @@ -97,10 +98,15 @@ Index: mpi-1.8.6/mpi.c + if ((err = s_mp_sqr(&guess_sqr))) + goto cleanup; + -+ if (s_mp_cmp(&guess_sqr, a) <= 0) { ++ cmp = s_mp_cmp(&guess_sqr, a); ++ ++ if (cmp < 0) { + temp = proot; + proot = pguess; + pguess = temp; ++ } else if (cmp == 0) { ++ proot = pguess; ++ break; + } } @@ -130,7 +136,7 @@ Index: mpi-1.8.6/mpi.c /* }}} */ -@@ -2554,21 +2535,9 @@ +@@ -2554,21 +2541,9 @@ int mp_count_bits(mp_int *mp) { @@ -153,7 +159,7 @@ Index: mpi-1.8.6/mpi.c } /* end mp_count_bits() */ /* }}} */ -@@ -3132,6 +3101,27 @@ +@@ -3132,6 +3107,27 @@ abort(); } diff --git a/mpi-patches/fix-ctype-warnings b/mpi-patches/fix-ctype-warnings index 17aeeb9c..aa84542d 100644 --- a/mpi-patches/fix-ctype-warnings +++ b/mpi-patches/fix-ctype-warnings @@ -1,7 +1,7 @@ Index: mpi-1.8.6/mpi.c =================================================================== ---- mpi-1.8.6.orig/mpi.c 2012-04-10 20:44:54.109795757 -0700 -+++ mpi-1.8.6/mpi.c 2012-04-10 20:45:57.857633757 -0700 +--- mpi-1.8.6.orig/mpi.c 2014-02-19 19:01:29.294491437 -0800 ++++ mpi-1.8.6/mpi.c 2014-02-19 19:01:39.562347737 -0800 @@ -200,7 +200,7 @@ int s_mp_ispow2(mp_int *v); /* is v a power of 2? */ int s_mp_ispow2d(mp_digit d); /* is d a power of 2? */ @@ -11,7 +11,7 @@ Index: mpi-1.8.6/mpi.c char s_mp_todigit(int val, int r, int low); /* convert val to digit */ int s_mp_outlen(int bits, int r); /* output length in bytes */ -@@ -4258,7 +4258,7 @@ +@@ -4264,7 +4264,7 @@ The results will be odd if you use a radix < 2 or > 62, you are expected to know what you're up to. */ @@ -20,7 +20,7 @@ Index: mpi-1.8.6/mpi.c { int val, xch; -@@ -4302,7 +4302,7 @@ +@@ -4308,7 +4308,7 @@ char s_mp_todigit(int val, int r, int low) { diff --git a/mpi-patches/mpi-to-double b/mpi-patches/mpi-to-double index 608e9dc3..dae195b2 100644 --- a/mpi-patches/mpi-to-double +++ b/mpi-patches/mpi-to-double @@ -1,7 +1,7 @@ Index: mpi-1.8.6/mpi.c =================================================================== ---- mpi-1.8.6.orig/mpi.c 2012-03-20 22:20:10.242815758 -0700 -+++ mpi-1.8.6/mpi.c 2012-03-21 06:48:36.401050757 -0700 +--- mpi-1.8.6.orig/mpi.c 2014-02-19 19:00:21.279452088 -0800 ++++ mpi-1.8.6/mpi.c 2014-02-19 19:01:29.294491437 -0800 @@ -14,6 +14,7 @@ #include #include @@ -10,7 +10,7 @@ Index: mpi-1.8.6/mpi.c typedef unsigned char mem_t; extern mem_t *chk_malloc(size_t size); -@@ -2329,6 +2330,29 @@ +@@ -2335,6 +2336,29 @@ /* }}} */ @@ -42,8 +42,8 @@ Index: mpi-1.8.6/mpi.c Index: mpi-1.8.6/mpi.h =================================================================== ---- mpi-1.8.6.orig/mpi.h 2012-03-20 22:20:09.994676258 -0700 -+++ mpi-1.8.6/mpi.h 2012-03-20 22:20:10.498959758 -0700 +--- mpi-1.8.6.orig/mpi.h 2014-02-19 18:59:53.335849528 -0800 ++++ mpi-1.8.6/mpi.h 2014-02-19 19:01:29.302491325 -0800 @@ -187,6 +187,11 @@ #endif /* end MP_NUMTH */ -- cgit v1.2.3