From a5b8dff144d01ecc5eb76a8e27f7a207a7200807 Mon Sep 17 00:00:00 2001 From: Xi Ruoyao Date: Wed, 9 Nov 2022 02:01:32 +0800 Subject: [PATCH 4/5] math: Allow using compiler builtins for logb{,f} --- sysdeps/generic/math-use-builtins-logb.h | 2 ++ sysdeps/generic/math-use-builtins.h | 1 + sysdeps/ieee754/dbl-64/s_logb.c | 5 +++++ sysdeps/ieee754/flt-32/s_logbf.c | 5 +++++ 4 files changed, 13 insertions(+) create mode 100644 sysdeps/generic/math-use-builtins-logb.h diff --git a/sysdeps/generic/math-use-builtins-logb.h b/sysdeps/generic/math-use-builtins-logb.h new file mode 100644 index 0000000000..f8fc9ae7cb --- /dev/null +++ b/sysdeps/generic/math-use-builtins-logb.h @@ -0,0 +1,2 @@ +#define USE_LOGB_BUILTIN 0 +#define USE_LOGBF_BUILTIN 0 diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h index 3acec1d538..a9cd510c2a 100644 --- a/sysdeps/generic/math-use-builtins.h +++ b/sysdeps/generic/math-use-builtins.h @@ -38,5 +38,6 @@ #include #include #include +#include #endif /* MATH_USE_BUILTINS_H */ diff --git a/sysdeps/ieee754/dbl-64/s_logb.c b/sysdeps/ieee754/dbl-64/s_logb.c index 82cabd206a..a9b18bf97b 100644 --- a/sysdeps/ieee754/dbl-64/s_logb.c +++ b/sysdeps/ieee754/dbl-64/s_logb.c @@ -21,10 +21,14 @@ #include #include #include +#include double __logb (double x) { +#if USE_LOGB_BUILTIN + return __builtin_logb (x); +#else int64_t ix, ex; EXTRACT_WORDS64 (ix, x); @@ -42,6 +46,7 @@ __logb (double x) if (FIX_INT_FP_CONVERT_ZERO && ex == 1023) return 0.0; return (double) (ex - 1023); +#endif } #ifndef __logb libm_alias_double (__logb, logb) diff --git a/sysdeps/ieee754/flt-32/s_logbf.c b/sysdeps/ieee754/flt-32/s_logbf.c index a06f975797..cf58596c8f 100644 --- a/sysdeps/ieee754/flt-32/s_logbf.c +++ b/sysdeps/ieee754/flt-32/s_logbf.c @@ -16,10 +16,14 @@ #include #include #include +#include float __logbf (float x) { +#if USE_LOGBF_BUILTIN + return __builtin_logbf (x); +#else int32_t ix, rix; GET_FLOAT_WORD (ix, x); @@ -37,5 +41,6 @@ __logbf (float x) if (FIX_INT_FP_CONVERT_ZERO && rix == 127) return 0.0f; return (float) (rix - 127); +#endif } libm_alias_float (__logb, logb) -- 2.37.0