[m-users.] Too Slow
Matthias Guedemann
matthias.guedemann at googlemail.com
Fri May 1 03:54:29 AEST 2015
Hi,
> If anyone wanted to contribute a binding to libgmp that we can place
> in the extras directory that would be okay with me *hint hint*.
I started a binding to libtommath[1], a public domain multiprecision
integer library written in portable ISO C.
This binding is a very early stage, there is no error code checks etc.,
but basic operators work without problems. Robert's Miller-Rabin code
can easily be adapted by changing the type from 'integer' to
'mp_int'. Once it is more complete and tested, I'll provide a PL for the
extras directory.
For the larger example in PL #22, this drops the time from 37:06 to
1:03.
> Some smart people have already done the hard work and written libgmp,
> it'd be great to use it when we want big integers fast. And if it
> were in extras then it wouldn't become a dependency of Mercury itself
> or Mercury programs that don't use the gmp binding.
I'd be happy to learn more on using FFI. In particular, I think my
approach is heavy on memory leaks. Every time a new mp_int is created,
memory is allocated which is never(?) freed. How does one handle this in
Mercury normally when using FFI?
To use 'mp_int', copy 'mp_int.m' in your folder, replace 'integer' with
'mp_int' and follow rougly this:
,----
| > cd $SOMEWHERE
| > git clone https://github.com/libtom/libtommath.git
| > cd libtommath
| > make
| > cp libtommath.a *.h $YOUR_PROGRAM_FOLDER
| > cd $YOUR_PROGRAM_FOLDER
| > mmc --link-object libtommath.a --make $YOUR_PROGRAM
`----
Best regards,
Matthias
Footnotes:
[1] https://github.com/libtom/libtommath
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp_int.m
Type: application/octet-stream
Size: 7403 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/users/attachments/20150430/25261e50/attachment.obj>
More information about the users
mailing list