minor noises made by gcc and -std=iso9899:1999 with -Wall -pedantic -Wextra -pedantic-errors
vincent at vinc17.net
Mon Jul 1 14:41:29 UTC 2019
On 2019-07-01 14:40:24 +0200, Torbjorn Granlund wrote:
> Vincent Lefevre <vincent at vinc17.net> writes:
> However the GMP code is poorly written.
> mp_size_t n = 1 + (2 * an >= 3 * bn ? (an - 1) / (size_t) 3 : (bn - 1) >> 1);
> What's the point of the cast to size_t?
> It is a slight performance optimisation.
Could you explain? I would say that, on the contrary, it may make
the code slower, e.g. on platforms where size_t > mp_size_t: the
compiler does not know that an > 0, thus it could not reduce the
size of the division to the one of mp_size_t in order to support
negative arguments implicitly converted to size_t.
> Moreover, GMP favors signed arithmetic with a signed type mp_size_t,
> thus artificially switching to unsigned arithmetic with this cast is
> a bad idea.
> Why? We have full control of the ranges of the involved variables.
You do, but the compiler does not know the ranges. And if the compiler
knew the ranges, the presence of the cast would not change anything
for the compiler.
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the gmp-discuss