minor noises made by gcc and -std=iso9899:1999 with -Wall -pedantic -Wextra -pedantic-errors
tg at gmplib.org
Wed Jul 3 12:40:14 UTC 2019
> The code for division by constants is shorter for unsigned than for
> signed dividends.
This could be enabled by providing range information to the compiler:
ASSUME (an >= 1);
ASSUME (bn >= 1);
It makes the source code longer, but IMHO, much easier to understand.
And the compiler has more information (this might make the code even
shorter on some processors).
This seems to be OK with GCC (without the cast): the generated code
is the same for both:
#define ASSUME(x) \
(! __builtin_constant_p (!!(x) || !(x)) || (x) ? \
(void) 0 : __builtin_unreachable())
long sdiv (long i)
ASSUME (i >= 0);
return i / 3;
unsigned long udiv (unsigned long i)
return i / 3;
Cool, this might be a useful GNU extension!
But I shrudder to see that you Vincent of all people seem to suggest
that we stray away from the Holy Standard! :-D
The disputed current GMP code does not get executed for values where
undefined behaviour is triggered, and it gives consistently great code
for old and new gcc as well as clang. While I, a practically oriented
developer, think the __builtin_blah operators are cool and useful, I
don't think using them here in lieu of the size_t cast would be an
Please encrypt, key id 0xC8601622
More information about the gmp-discuss