freebsd-src/lib/msun
Karl Tomlinson e75a1bbc23 pow,powf(3),__ieee754_rem_pio2(f): Avoid negative integer left shift UB
A compiler clever enough to know that z is positive with a non-zero
biased exponent could, for example, optimize away the scalbnf(z,n) in
pow() because behavior for left shift of negative values is undefined.
`n` is negative when y*log2(|x|) < -0.5.  i.e. |x^y| < sqrt(0.5)

The intended behavior for operator<< in this code is to shift the two's
complement representation of the first operand.

In the pow() functions, the result is added to the IEEE 754 exponent of
z = 2^y'.  n may be negative enough to underflow the biased IEEE 754
exponent below zero, which is manifested in the sign bit of j
(which would correspond to the IEEE 754 sign bit).

The conversion from uint32_t to int32_t for out-of-int32_t-range values
is implementation defined.  The assumed behavior of interpreting the
uint32_t value as a two's complement representation of a signed value
is already assumed in many parts of the code, such as uses of
GET_FLOAT_WORD() with signed integers.

This code passes all the current tests, and makes some out of tree
fuzzing tests pass again rather than hit UB (detailed in the commentary
of the pull request).

Signed-off-by: Karl Tomlinson <karlt+@karlt.net>
Reviewed by: imp, steve kargl, dim
Pull Request: https://github.com/freebsd/freebsd-src/pull/1137
2024-04-23 14:04:07 -06:00
..
aarch64 Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
amd64 lib: Automated cleanup of cdefs and other formatting 2023-11-26 22:23:59 -07:00
arm Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
bsdsrc lib/msun: Cleanup after $FreeBSD$ removal 2024-01-28 17:00:23 +02:00
i387 lib/msun: Cleanup after $FreeBSD$ removal 2024-01-28 17:00:23 +02:00
ld80 lib/msun: Cleanup after $FreeBSD$ removal 2024-01-28 17:00:23 +02:00
ld128 lib/msun: Fix tgammal(3) on IEEE 128-bit platforms 2024-03-18 09:48:43 +00:00
man Now that D44168 has been merged to stable/14, update the manpage 2024-04-12 16:33:54 +01:00
powerpc Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:55:03 -06:00
riscv riscv: remove more riscv64sf support 2024-03-21 23:48:37 +00:00
src pow,powf(3),__ieee754_rem_pio2(f): Avoid negative integer left shift UB 2024-04-23 14:04:07 -06:00
tests lib/msun: Cleanup after $FreeBSD$ removal 2024-01-28 17:00:23 +02:00
x86 Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:16 -06:00
Makefile lib/msun: Fix tgammal(3) on IEEE 128-bit platforms 2024-03-18 09:48:43 +00:00
Makefile.depend dirdeps: Update/fix Makefile.depend* for toolchain 2023-11-26 20:50:13 -05:00
Symbol.map msun: remove fabs from Symbol.map, and adjust comment 2024-01-27 22:24:38 +01:00