[Openmcl-devel] Bignums using GMP.
Waldek Hebisch
hebisch at math.uni.wroc.pl
Fri Feb 12 23:22:12 UTC 2010
Attached are two files which together cause Closure CL to use GMP
for bignum arithmetic. The routines are specific to 64-bit Amd
(and Intel) architecture. For relatively small bignums current
Closure CL multiplication is quite competitive and the routines
use it, however for really large bignums GMP is faster. For
division (truncate), gcd and integer square root GMP is faster
even for smallest bignums so the routines just use GMP. In fact,
fixnum isqrt is slower than isqrt for small bignums via GMP.
I use GMP "mpn" routines. Because the "mpn" interface is quite
restrictive I use two helper C routines. On Lisp side there
are LAP routines to do reasonably fact copy and replacements
for Closuse CL bignums routines. Like originals the replacements
are careful to stack allocate temporaries.
To try the routines compile the C file to get shared library
(as indicated at the top of the file), then compile the lisp
file. After starting Closure CL load GMP library, then the
helper library and the fasl. After that Closure CL will use
new routines.
To give you some idea of speed, on 2.4 GHz Core 2 Quadro,
gcd of 90949470177292823791503906250000000 and
7178979876918525887702490000000 takes 11us using current
version and 1us using GMP (I used GMP 5.0, GMP 4.2
is slower).
Comments welcame. In particular what is best method to
make sure that multiplication works OK after starting
from saved image. For my purpose I modified Closure CL
kernel makefile to link in my C routines and GMP. But
without linking GMP to Lisp kernel there is risk that
replacement bignum routines will try to use GMP before
it is loaded (IIUC saved core image will contain
replacement bignum routines, but have no access to GMP
before it is explicitely loaded).
I wonder if there is interst to include such routines in
Closure CL (possibly as optional feature, if depending on
GMP is considered undesirable).
--
Waldek Hebisch
hebisch at math.uni.wroc.pl
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: num.lisp
Url: http://clozure.com/pipermail/openmcl-devel/attachments/20100213/54b39272/attachment.txt
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mulp.c
Url: http://clozure.com/pipermail/openmcl-devel/attachments/20100213/54b39272/attachment-0001.txt
More information about the Openmcl-devel
mailing list