Esa Ilari Vuokko wrote:

I have been planning to work on GMP-issue [1] 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.

Esa, this is great stuff!

My current modifications (darcs patches) are available over
http [2].  I managed to get stage 2 ghc compiled with them,
but it didn't work for anything much, probably because of
serialisation issues.

Which bignum library should be used?
 * Choices I know of: OpenSSL [3] bignum and libtommath [4].
   (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.

I'm quite happy with libtommath. From a license point of view, PD is good enough for me. (but perhaps it would be possible to extract a more explicit license from the author?)

Plan and action
 * Configuration time option. (Rts-way seems overkill and is hard
   to do because base lib needs modifications.)

I'm not keen on keeping two versions of the arbitrary precision integer support around - we either switch or we don't. There are already too many ways to build GHC, we don't want yet another variable. So, no configure options.

 * 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.

     Wierd:
       * ghc/rts/linker.c has symbol tables for some (direct) GMP
         symbols, wierd, are they for something important?

You should test GHCi with your changes, you'll soon find out if any symbols are missing.

     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.

     Not done:
       * 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.

 * libraries/base
   - 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.

I think Show should work as-is, unless I'm missing something.

I suggest you run your new code against the benchmark in nofib/spectral/integer, which should give the integer arithmetic a good work out, and will be able to tell us where your version is performance-wise compared to GMP.

Cheers,
        Simon
_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to