Re: mpz_get_si: possible undefined behaviour? [Was: Micro-GMP]

2018-12-03 Thread Torbjörn Granlund
Marco Bodrato writes: But, what about the LONG_MIN == -LONG_MAX case? The result is undefined, isn't it? Does anybody (apart from Vincent) have access to such a machine? :-) -- Torbjörn Please encrypt, key id 0xC8601622 ___ gmp-devel mailing list

Re: mpz_get_si: possible undefined behaviour? [Was: Micro-GMP]

2018-12-03 Thread Vincent Lefevre
On 2018-12-03 23:47:00 +0100, Marco Bodrato wrote: > If LONG_MIN == -LONG_MAX-1, this step is correct. > But, what about the LONG_MIN == -LONG_MAX case? > The result is undefined, isn't it? Yes. > Which value we should actually return when the given mpz does not > fit in the target type is not so

mpz_get_si: possible undefined behaviour? [Was: Micro-GMP]

2018-12-03 Thread Marco Bodrato
Ciao, Il 2018-12-03 13:43 Vincent Lefevre ha scritto: On 2018-12-03 13:04:11 +0100, Torbjorn Granlund wrote: 2. For signed source types, the + 1 - 1 trickery might help for MIN_INT with the type of x. In such a case, the + 1 - 1 trickery is harmless, It is wonderful to count how many messa

Re: mpn_sec_div_r

2018-12-03 Thread Niels Möller
t...@gmplib.org (Torbjörn Granlund) writes: > For invert_limb, we should write some leak-free C code for generating a > suitable table, I suppose. You mean leak-free code replacing the table lookup? For 64-bits, the table used in x86_64/invert_limb is floor(0x7fd00 / x) for 0x100 <= x < 0x200, 8

Re: Micro-GMP

2018-12-03 Thread Torbjörn Granlund
Editing gmp-impl.h to include it early is a good start. And of course one needs a C++ compiler. (GMP is valid C++.) ftp://ftp.gmplib.org/pub/archive/ Well, as Vincent pointed out, ftp is obsolete. His link is better. -- Torbjörn Please encrypt, key id 0xC8601622 _

Re: Micro-GMP

2018-12-03 Thread Torbjörn Granlund
paul zimmermann writes: quite interesting! Is there any documentation how to use it? I cannot find any. :-( Editing gmp-impl.h to include it early is a good start. I have a checkout somewhere which makes the GMP testsuite run almost to completion. Lots of edits are needed, as we (ab)use mp

Re: Micro-GMP

2018-12-03 Thread Vincent Lefevre
On 2018-12-03 15:06:02 +0100, paul zimmermann wrote: > indeed, in several places I opted for simplicity, since speed was not > (at first) a goal. But when running "make check" of MPFR with micro-gmp-8, > I now realize speed is also important! Yes, in particular if we want to do exhaustive tests (t

Re: Micro-GMP

2018-12-03 Thread paul zimmermann
Dear Marco, > Date: Fri, 30 Nov 2018 07:43:40 +0100 > From: Marco Bodrato > > Ciao Paul! > > Il 2018-11-23 13:38 paul zimmermann ha scritto: > > I presented some work in progress on "Micro-GMP", a modified > > version of Mini-GMP which works with 16-bit or even 8-bit limbs: > > Great! >

Re: Micro-GMP

2018-12-03 Thread Vincent Lefevre
On 2018-12-03 13:57:32 +0100, paul zimmermann wrote: > > First public GMP releaae wasn't 1.3.2 (sic) in 1993 but 1.1 in 1991. > > my source was ftp://ftp.gnu.org/gnu/gmp/, where the first version is 1.3.2. Isn't ftp obsolete? Look at https://gmplib.org/download/gmp/archive/ instead. gmp-1.1.tar

Re: Micro-GMP

2018-12-03 Thread paul zimmermann
Dear Torbjörn, > From: t...@gmplib.org (Torbjörn Granlund) > Date: Fri, 23 Nov 2018 18:03:31 +0100 > > You might be interested in GMP's asl.h, it implements artificially small > limbs ("asl"), down to 4 bits IIRC. The repo GMP doesn't complete its > tests with it currently. (A student of

Re: Micro-GMP

2018-12-03 Thread Vincent Lefevre
On 2018-12-03 13:04:11 +0100, Torbjorn Granlund wrote: > > What is the purpose of GMP_NEG_CAST > > > > #define GMP_NEG_CAST(T,x) (-((T)((x) + 1) - 1)) > > > > instead of just a cast followed by a negation? i.e. > > > > mpz_set_ui (r, - (unsigned long int) x); > > This is confusing.

Re: Micro-GMP

2018-12-03 Thread Torbjörn Granlund
> What is the purpose of GMP_NEG_CAST > > #define GMP_NEG_CAST(T,x) (-((T)((x) + 1) - 1)) > > instead of just a cast followed by a negation? i.e. > > mpz_set_ui (r, - (unsigned long int) x); This is confusing. 1. We can never use this for signed types with negative values if T is