Providing alternative to GMP
Esa Ilari Vuokko
eivuokko at gmail.com
Sat Jan 21 19:37:42 EST 2006
I have been planning to work on GMP-issue  for a while, and
I finally got started :-) Before I continue committing
myself to certain choices, I'd like some optinions how I should
have done it ;-) Any feedback is appreciated.
My current modifications (darcs patches) are available over
http . I managed to get stage 2 ghc compiled with them,
but it didn't work for anything much, probably because of
Which bignum library should be used?
* Choices I know of: OpenSSL  bignum and libtommath .
(I used libtommath up to now, but just because it is easier
to read and modify) Either license works for me, and
both are probably manageable.
Plan and action
* Configuration time option. (Rts-way seems overkill and is hard
to do because base lib needs modifications.)
* Add autotools/Makefile machinery for --enable-tommath
Causes UseTomMath to have value YES in Makefiles and
WANT_TOMMATH defined to 1 in headers.
* Primops and rts functionality
- Simple primops haven been replaced, but haven't been tested.
I am not familiar with C--, so all of my code is just copying
from other places in ghc sources.
* ghc/rts/linker.c has symbol tables for some (direct) GMP
symbols, wierd, are they for something important?
Compatibility notes (libtommath vs GMP):
* In GHC heap, tommath has similar presentation as before,
int with digits and sign bit, and bytearray containing digits.
* There's a lot of boring sign converting going as tommath's
mp_int keeps sign in separate int, no big deal tho.
* Tommath doesn't use all of one digit to present value, for
speed or simplicity reasons it leaves 4 bits space around, and
this breaks just about all existing binary conversions.
* I didn't convert double and float stuff yet as I couldn't
understand it quick. (StgPrimFloat.c)
* Most of Int/Word <-> Integer conversions aren't working yet,
but they are probably mostly trivial.
* Memory handling is a bit ad-hoc right now, I modified both
rts and tommath.
* If it seems a good idea, all function names in bignum library
could be changed to something less clashy.
- Given that all of primops are correct, numerical typeclasses work
as-is. But it would be much better to provide only
library-provided primops, and change definitions in base.
- Show etc serialisation (probably) needs to be done.
License comments are my layman interpretations, so you should consult
real lawyer etc :-)
 http://hackage.haskell.org/trac/ghc/ticket/601 - Replace GMP
 http://tamelambda.net/1-tommath.tar.gz (212 kb)
 http://www.openssl.org/ as part of ssl distribution comes bignum
library. License is BSD-style, requires acknowledgement.
 http://math.libtomcrypt.org/ License is public domain, which might
not be perfect in all countries.
More information about the Cvs-ghc