summaryrefslogtreecommitdiffstats
path: root/mpi-patches/add-mp-set-intptr
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-12-09 22:25:51 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-12-09 22:25:51 -0800
commit236a20e92316535bc75dde63d51431875e253bfb (patch)
tree6ec4fb84a27cb311027495db9d3c34b791fe207e /mpi-patches/add-mp-set-intptr
parentb1088a2502cba1a61b862f708489c8d4baa722fe (diff)
downloadtxr-236a20e92316535bc75dde63d51431875e253bfb.tar.gz
txr-236a20e92316535bc75dde63d51431875e253bfb.tar.bz2
txr-236a20e92316535bc75dde63d51431875e253bfb.zip
Bignum support, here we go!
Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s.
Diffstat (limited to 'mpi-patches/add-mp-set-intptr')
-rw-r--r--mpi-patches/add-mp-set-intptr77
1 files changed, 77 insertions, 0 deletions
diff --git a/mpi-patches/add-mp-set-intptr b/mpi-patches/add-mp-set-intptr
new file mode 100644
index 00000000..a5d50a33
--- /dev/null
+++ b/mpi-patches/add-mp-set-intptr
@@ -0,0 +1,77 @@
+Index: mpi-1.8.6/mpi.c
+===================================================================
+--- mpi-1.8.6.orig/mpi.c 2011-12-09 13:52:26.000000000 -0800
++++ mpi-1.8.6/mpi.c 2011-12-09 13:56:19.000000000 -0800
+@@ -528,6 +528,59 @@
+
+ /* }}} */
+
++mp_err mp_set_intptr(mp_int *mp, int_ptr_t z)
++{
++ if (sizeof z > sizeof (mp_digit)) {
++ int ix, shift;
++ unsigned long v = z > 0 ? z : -z;
++ const int nd = (sizeof v + sizeof (mp_digit) - 1) / sizeof (mp_digit);
++
++ ARGCHK(mp != NULL, MP_BADARG);
++
++ mp_zero(mp);
++
++ if(z == 0)
++ return MP_OKAY; /* shortcut for zero */
++
++ s_mp_grow(mp, nd);
++
++ USED(mp) = nd;
++
++ for (ix = 0, shift = 0; ix < nd; ix++, shift += MP_DIGIT_BIT)
++ {
++ DIGIT(mp, ix) = (v >> shift) & MP_DIGIT_MAX;
++ }
++
++ if(z < 0)
++ SIGN(mp) = MP_NEG;
++
++ return MP_OKAY;
++ }
++
++ mp_set(mp, z);
++ return MP_OKAY;
++}
++
++/*
++ * No checks here: assumes that the mp is in range!
++ */
++mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z)
++{
++ int_ptr_t out = 0;
++
++#if MP_DIGIT_SIZE < SIZEOF_PTR
++ int ix;
++ int nd = USED(mp);
++ for (ix = 0; ix < nd; ix++, out <<= MP_DIGIT_BIT)
++ out = DIGIT(mp, ix);
++#else
++ out = DIGIT(mp, 0);
++#endif
++
++ *z = (SIGN(mp) == MP_NEG) ? -out : out;
++ return MP_OKAY;
++}
++
+ /*------------------------------------------------------------------------*/
+ /* {{{ Digit arithmetic */
+
+Index: mpi-1.8.6/mpi.h
+===================================================================
+--- mpi-1.8.6.orig/mpi.h 2011-12-09 13:49:20.000000000 -0800
++++ mpi-1.8.6/mpi.h 2011-12-09 13:56:19.000000000 -0800
+@@ -94,6 +94,8 @@
+ void mp_zero(mp_int *mp);
+ void mp_set(mp_int *mp, mp_digit d);
+ mp_err mp_set_int(mp_int *mp, long z);
++mp_err mp_set_intptr(mp_int *mp, int_ptr_t z);
++mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z);
+
+ /*------------------------------------------------------------------------*/
+ /* Single digit arithmetic */