Use GCC builtins for logb functions if desired.
authorXiaolin Tang <tangxiaolin@loongson.cn>
Wed, 23 Nov 2022 03:45:00 +0000 (11:45 +0800)
committercaiyinyu <caiyinyu@loongson.cn>
Tue, 29 Nov 2022 08:00:28 +0000 (16:00 +0800)
This patch is using the corresponding GCC builtin for logbf, logb,
logbl and logbf128 if the USE_FUNCTION_BUILTIN macros are defined to one
in math-use-builtins-function.h.

Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
sysdeps/generic/math-use-builtins-logb.h [new file with mode: 0644]
sysdeps/generic/math-use-builtins.h
sysdeps/ieee754/dbl-64/s_logb.c
sysdeps/ieee754/float128/float128_private.h
sysdeps/ieee754/flt-32/s_logbf.c
sysdeps/ieee754/ldbl-128/s_logbl.c

diff --git a/sysdeps/generic/math-use-builtins-logb.h b/sysdeps/generic/math-use-builtins-logb.h
new file mode 100644 (file)
index 0000000..e816a7e
--- /dev/null
@@ -0,0 +1,4 @@
+#define USE_LOGB_BUILTIN 0
+#define USE_LOGBF_BUILTIN 0
+#define USE_LOGBL_BUILTIN 0
+#define USE_LOGBF128_BUILTIN 0
index dddeaa4ea888cc571da2daaca9df3820439c637c..c59612a8781513982eae01fdc34425050128353a 100644 (file)
@@ -39,5 +39,6 @@
 #include <math-use-builtins-fabs.h>
 #include <math-use-builtins-lrint.h>
 #include <math-use-builtins-llrint.h>
+#include <math-use-builtins-logb.h>
 
 #endif /* MATH_USE_BUILTINS_H  */
index 82cabd206a7b224bb646317be7c0a183daa30e22..dd74d5f08c40a4765ec3197a3838b5cf396540a8 100644 (file)
 #include <math_private.h>
 #include <libm-alias-double.h>
 #include <fix-int-fp-convert-zero.h>
+#include <math-use-builtins.h>
 
 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 /* !USE_LOGB_BUILTIN  */
 }
 #ifndef __logb
 libm_alias_double (__logb, logb)
index 3bb5fffa7441de6f3ea6b349dcdd4aa5614c09d7..78107b15252b2d2f1dc038f10b659315e0e548d1 100644 (file)
 #define USE_LRINTL_BUILTIN USE_LRINTF128_BUILTIN
 #undef USE_LLRINTL_BUILTIN
 #define USE_LLRINTL_BUILTIN USE_LLRINTF128_BUILTIN
+#undef USE_LOGBL_BUILTIN
+#define USE_LOGBL_BUILTIN USE_LOGBF128_BUILTIN
 
 /* IEEE function renames.  */
 #define __ieee754_acoshl __ieee754_acoshf128
index a06f97579780f318b1894c4df4ef10fea5dbc619..b027e7b9c24eae95bebd0958555572ccdbcb1092 100644 (file)
 #include <math_private.h>
 #include <libm-alias-float.h>
 #include <fix-int-fp-convert-zero.h>
+#include <math-use-builtins.h>
 
 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 /* ! USE_LOGBF_BUILTIN */
 }
 libm_alias_float (__logb, logb)
index 1c56eda49958f4bf0c505652311fa4f06c35c36a..59b08aa29555849bad75afd928963891c147504a 100644 (file)
@@ -25,10 +25,15 @@ static char rcsid[] = "$NetBSD: $";
 #include <math.h>
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
+#include <math-use-builtins.h>
 
 _Float128
 __logbl (_Float128 x)
 {
+#if USE_LOGBL_BUILTIN
+  return __builtin_logbl (x);
+#else
+  /* Use generic implementation.  */
   int64_t lx, hx, ex;
 
   GET_LDOUBLE_WORDS64 (hx, lx, x);
@@ -49,6 +54,7 @@ __logbl (_Float128 x)
       ex -= ma - 16;
     }
   return (_Float128) (ex - 16383);
+#endif /* ! USE_LOGBL_BUILTIN  */
 }
 
 libm_alias_ldouble (__logb, logb)