Re: [PATCH] libm: Fixing overflow handling issue for scalbnf and scalbn

Keith Packard <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Kito Cheng <[email protected]> writes:

> cc Aldy Hernandez <[email protected]> and Andrew MacLeod <[email protected]>,
> they are author of new VRP analysis for GCC, just to make sure I didn't
> mis-understanding or mis-interpreting anything on GCC site.
>
> GCC 11 have better value range analysis, that give GCC more confidence
> to perform more aggressive optimization, but it cause scalbn/scalbnf get
> wrong result.

C doesn't specify what happens when signed integer values overflow;
compiler developers believe that gives them the license to do this kind
of "optimization". This patch makes the code more compliant with the C
spec.

The only way to get known overflow behavior would be to use unsigned
integers, but as this code depends on signed comparisons, that isn't
practical here.

I've added tests for this case to the picolibc test suite and verified
that your patch corrects this issue on 32-bit ARM using GCC 11.

-- 
-keith
signature.asc (application/pgp-signature, 832 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAmD29fQACgkQ2yIaaQAA
ABE+fBAAtrls+W0JHy/VF3DqU+quoJn0k4uYwE5eyKG3T8OEGFy+nqJVI3q/NUu9
Ezfe1eu0MSJKCeiDvxykNeOQwTGPmzHm0TTMRDmOYMP4gWk0/sBqvVDhGism+fVz
U6cks3uRmox4UyX5nf2DOJKktwHfuEcKLCBPRBlGfMLtEAggaSTI1d6Hp4Iy2MIS
fAjpea2J9/bubNxICHYxjB0xDpaNnOF2hLT9Wnn9Nz55zQNRvCEwUE7M07uqTM/y
wz9b61jdt+xy/qMBhkCMW/T3BNTqG0MuA5hs5gRhsz9T+4y8fxwJIHv3uckHe9ru
UTERYsLMIf7P/HtUyYQKidvf+OxzCup1sIkwwqJqjFgOI9QtG1ZqpdTUzuL2s3vi
jE7PW64vel1eG2ykKxhBogeYr4H4p94cCmATUtuJZARv5ffF8Z4Q3hWiLc9tpZqt
Jt7qORoo62gAyOFOdkcHJ82me4yx4HDb6SdONqIbliq8kulciqCzLQr5s3BHMreE
l8H+W0s+wb809n3c6PIlbkyPwyt8ObhNI2XSEAOCu1bkhdxJPlgdmDSVmp4DOOoN
QryktnMTkqUO/zngH8GndXaPu8cuDvRh0guTqWTCYGuuag/0b+hgi3tTbE2hS1zo
a913rf9zsTYaecMqIh7Sm7NpLWVgTQ4ZEj9TkkIV+8ZVJK3CyZ4=
=I0CJ
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.