libgmp deimos library

Andrew Hall via Digitalmars-d digitalmars-d at puremagic.com
Sat Jan 14 19:04:30 PST 2017


On Thursday, 12 January 2017 at 16:55:10 UTC, Nordlöw wrote:
> On Thursday, 12 January 2017 at 09:19:26 UTC, Russel Winder 
> wrote:
>> Is the intention for this to stand with or replace std.bigint ?
>
> I have no plan yet. I'm just gonna work on it for fun until it 
> covers most of GNU MP. Pull requests are very welcome.

What would be cool would be a way for D to generate 'optimal' gmp 
code. So a template function that takes in an expression, and 
output's D / GMP code that uses minimal allocation.

ulong a = 27, b = 84, c = 110, d = 133;
compileGMP!"Integer res = a ^^ 5 + b ^^ 5 + c ^^ 5 + d ^^ 5"();

might generate the code:
Integer res, r2; //r2 used as a register of sorts (minimise 
allocation of Integers)
mpz_init(res); mpz_init(r2);

mpz_ui_pow_ui(res, a, 5);
mpz_ui_pow_ui(r2, b, 5);
mpz_add(res, res, r2);

mpz_ui_pow_ui(res, c 5);
mpz_add(res, res, r2);

mpz_ui_pow_ui(r2, d, 5);
mpz_add(res, res, r2);

Obviously the compileGMP function would need to know a bit about 
the types, but that can be arranged. Just something to think 
about ;)



More information about the Digitalmars-d mailing list