[PATCH v2 0/4] Remove UB and optimize ilogbf/ilogb
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Mon Apr 28 17:35:58 GMT 2025
On 28/04/25 14:03, Adhemerval Zanella wrote:
> From a recent experiment to build glibc with -fsanitize=undefined [1],
> I found that both the float and double ilogb triggered UB due to the
> use of shift with a signed integer.
>
> This patchset fixes the UB issues on both implementations by
> reimplementing with a slightly better code.
>
> [1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/ubsan-undef
This version triggers some issues on loongarch and fails to build
on m68k. Both architecture will need to some adjustment, I will
send a v3.
>
> Adhemerval Zanella (4):
> math: Remove UB and optimize double ilogb
> math: Optimize double ilogb/llogb
> math: Remove UB and optimize double ilogbf
> math: Optimize float ilogb/llogb
>
> sysdeps/i386/fpu/math_err.c | 1 -
> sysdeps/ieee754/dbl-64/e_ilogb.c | 64 +--------------------------
> sysdeps/ieee754/dbl-64/math_config.h | 2 +
> sysdeps/ieee754/dbl-64/math_err.c | 32 ++++++++++++++
> sysdeps/ieee754/dbl-64/w_ilogb.c | 63 ++++++++++++++++++++++++++
> sysdeps/ieee754/dbl-64/w_llogb.c | 2 +
> sysdeps/ieee754/flt-32/e_ilogbf.c | 44 +------------------
> sysdeps/ieee754/flt-32/math_config.h | 2 +
> sysdeps/ieee754/flt-32/math_errf.c | 33 ++++++++++++++
> sysdeps/ieee754/flt-32/w_ilogbf.c | 66 ++++++++++++++++++++++++++++
> sysdeps/ieee754/flt-32/w_llogbf.c | 2 +
> 11 files changed, 204 insertions(+), 107 deletions(-)
> delete mode 100644 sysdeps/i386/fpu/math_err.c
> create mode 100644 sysdeps/ieee754/dbl-64/w_ilogb.c
> create mode 100644 sysdeps/ieee754/dbl-64/w_llogb.c
> create mode 100644 sysdeps/ieee754/flt-32/w_ilogbf.c
> create mode 100644 sysdeps/ieee754/flt-32/w_llogbf.c
>
More information about the Libc-alpha
mailing list