summaryrefslogtreecommitdiffstats
path: root/mpi-patches
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-06-28 08:53:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-06-28 08:53:45 -0700
commitf69bc0426a3f94318ef89dba18cdad3cbed180e7 (patch)
tree5f5094f936576ac668941774681b3bb58c0b1188 /mpi-patches
parent4e927689cb21336212f1aea7cb61433d5372b87a (diff)
downloadtxr-f69bc0426a3f94318ef89dba18cdad3cbed180e7.tar.gz
txr-f69bc0426a3f94318ef89dba18cdad3cbed180e7.tar.bz2
txr-f69bc0426a3f94318ef89dba18cdad3cbed180e7.zip
* arith.c (bit): New function.
* eval.c (eval_init): Register bit as intrinsic. * lib.h (bit): Declared. * mpi-patches/add-bitops (mp_bit): New function. * txr.1: Documented bit
Diffstat (limited to 'mpi-patches')
-rw-r--r--mpi-patches/add-bitops28
1 files changed, 24 insertions, 4 deletions
diff --git a/mpi-patches/add-bitops b/mpi-patches/add-bitops
index da2cfa3d..81d7de2b 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 2014-06-16 11:22:15.632802821 -0700
-+++ mpi-1.8.6/mpi.c 2014-06-28 07:20:04.364811464 -0700
++++ mpi-1.8.6/mpi.c 2014-06-28 07:42:26.140352649 -0700
@@ -16,6 +16,9 @@
#include <ctype.h>
#include <math.h>
@@ -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);
-@@ -2336,6 +2340,411 @@
+@@ -2336,6 +2340,430 @@
/* }}} */
@@ -429,13 +429,32 @@ Index: mpi-1.8.6/mpi.c
+ return MP_OKAY;
+}
+
++mp_err mp_bit(mp_int *a, mp_digit bit)
++{
++ mp_int tmp;
++ mp_err res;
++ int a_neg = ISNEG(a);
++ int digit = bit / MP_DIGIT_BIT;
++ mp_digit mask = ((mp_digit) 1 << (bit % MP_DIGIT_BIT));
++
++ if (a_neg) {
++ mp_init(&tmp);
++ if ((res = mp_2comp(a, &tmp, bit + 1)) != MP_OKAY)
++ return res;
++ SIGN(&tmp) = MP_ZPOS;
++ a = &tmp;
++ }
++
++ return (DIGITS(a)[digit] & mask) != 0 ? MP_YES : MP_NO;
++}
++
mp_err mp_to_double(mp_int *mp, double *d)
{
int ix;
Index: mpi-1.8.6/mpi.h
===================================================================
--- mpi-1.8.6.orig/mpi.h 2014-06-16 11:22:15.620803044 -0700
-+++ mpi-1.8.6/mpi.h 2014-06-16 11:22:15.648802523 -0700
++++ mpi-1.8.6/mpi.h 2014-06-28 08:46:48.354193482 -0700
@@ -54,6 +54,7 @@
/* Macros for accessing the mp_int internals */
@@ -444,7 +463,7 @@ Index: mpi-1.8.6/mpi.h
#define USED(MP) ((MP)->used)
#define ALLOC(MP) ((MP)->alloc)
#define DIGITS(MP) ((MP)->dp)
-@@ -187,6 +188,17 @@
+@@ -187,6 +188,18 @@
#endif /* end MP_NUMTH */
/*------------------------------------------------------------------------*/
@@ -457,6 +476,7 @@ Index: mpi-1.8.6/mpi.h
+mp_err mp_trunc_comp(mp_int *a, mp_int *b, mp_digit bits);
+mp_err mp_trunc(mp_int *a, mp_int *b, mp_digit bits);
+mp_err mp_shift(mp_int *a, mp_int *b, int bits); /* + left, - right */
++mp_err mp_bit(mp_int *a, mp_digit bit);
+
+/*------------------------------------------------------------------------*/
/* Conversions */