unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13
@ 2022-11-23  3:44 Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 01/10] LoongArch: Use __builtin_rint{,f} " Xiaolin Tang
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:44 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111
  Cc: xuchenghua, chenglulu, Xiaolin Tang

Patch 0001-0007:
GCC 13, LoongArch support builtins for {,l,ll}rint, logb,
use these built-ins instead of generic function implementation.

Patch 0008:
GCC 13, LoongArch support ___builtin_scalbn{,f} with -fno-math-errno,
but only "libm" can use -fno-math-errno in GLIBC, and scalbn is in 
libc instead of libm because __printf_fp calls it. So inline assembler
of the scalbn functions is a better choice for LoongArch.

Patch 0009: Add LoongArch support for scalb[f].


From v1 to v2:
Add patch 0010: Add LoongArch support for ilogb[f].


Discuss with Xi Ruoyao<xry111@xry111.site>
Link:
https://sourceware.org/pipermail/libc-alpha/2022-November/143425.html

Xi Ruoyao (1):
  LoongArch: Use __builtin_rint{,f} with GCC >= 13

Xiaolin Tang (9):
  Use GCC builtins for lrint functions if desired.
  LoongArch: Use __builtin_lrint{,f} with GCC >= 13
  Use GCC builtins for llrint functions if desired.
  LoongArch: Use __builtin_llrint{,f} with GCC >= 13
  Use GCC builtins for logb functions if desired.
  LoongArch: Use __builtin_logb{,f} with GCC >= 13
  LoongArch: Add support for scalbn[f]
  LoongArch: Add support for scalb[f]
  LoongArch: Add support for ilogb[f]

 sysdeps/generic/math-use-builtins-llrint.h    |  4 ++
 sysdeps/generic/math-use-builtins-logb.h      |  4 ++
 sysdeps/generic/math-use-builtins-lrint.h     |  4 ++
 sysdeps/generic/math-use-builtins.h           |  3 +
 sysdeps/ieee754/dbl-64/s_llrint.c             | 18 ++++--
 sysdeps/ieee754/dbl-64/s_logb.c               |  5 ++
 sysdeps/ieee754/dbl-64/s_lrint.c              | 18 ++++--
 sysdeps/ieee754/float128/float128_private.h   |  6 ++
 sysdeps/ieee754/flt-32/s_llrintf.c            | 18 ++++--
 sysdeps/ieee754/flt-32/s_logbf.c              |  5 ++
 sysdeps/ieee754/flt-32/s_lrintf.c             | 18 ++++--
 sysdeps/ieee754/ldbl-128/s_llrintl.c          | 17 ++++--
 sysdeps/ieee754/ldbl-128/s_logbl.c            |  6 ++
 sysdeps/ieee754/ldbl-128/s_lrintl.c           | 17 ++++--
 sysdeps/loongarch/fpu/e_ilogb.c               | 39 ++++++++++++
 sysdeps/loongarch/fpu/e_ilogbf.c              | 39 ++++++++++++
 sysdeps/loongarch/fpu/e_scalb.c               | 60 +++++++++++++++++++
 sysdeps/loongarch/fpu/e_scalbf.c              | 60 +++++++++++++++++++
 .../loongarch/fpu/math-use-builtins-llrint.h  | 10 ++++
 .../loongarch/fpu/math-use-builtins-logb.h    | 10 ++++
 .../loongarch/fpu/math-use-builtins-lrint.h   | 10 ++++
 .../loongarch/fpu/math-use-builtins-rint.h    |  9 +++
 sysdeps/loongarch/fpu/s_scalbn.c              | 29 +++++++++
 sysdeps/loongarch/fpu/s_scalbnf.c             | 29 +++++++++
 24 files changed, 404 insertions(+), 34 deletions(-)
 create mode 100644 sysdeps/generic/math-use-builtins-llrint.h
 create mode 100644 sysdeps/generic/math-use-builtins-logb.h
 create mode 100644 sysdeps/generic/math-use-builtins-lrint.h
 create mode 100644 sysdeps/loongarch/fpu/e_ilogb.c
 create mode 100644 sysdeps/loongarch/fpu/e_ilogbf.c
 create mode 100644 sysdeps/loongarch/fpu/e_scalb.c
 create mode 100644 sysdeps/loongarch/fpu/e_scalbf.c
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-llrint.h
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-logb.h
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-lrint.h
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-rint.h
 create mode 100644 sysdeps/loongarch/fpu/s_scalbn.c
 create mode 100644 sysdeps/loongarch/fpu/s_scalbnf.c

-- 
2.31.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 01/10] LoongArch: Use __builtin_rint{,f} with GCC >= 13
  2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
@ 2022-11-23  3:44 ` Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 02/10] Use GCC builtins for lrint functions if desired Xiaolin Tang
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:44 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111; +Cc: xuchenghua, chenglulu

From: Xi Ruoyao <xry111@xry111.site>

GCC 13 compiles these built-ins to frint.{d,s} instruction.

Link: https://gcc.gnu.org/r13-3919
---
 sysdeps/loongarch/fpu/math-use-builtins-rint.h | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-rint.h

diff --git a/sysdeps/loongarch/fpu/math-use-builtins-rint.h b/sysdeps/loongarch/fpu/math-use-builtins-rint.h
new file mode 100644
index 0000000000..cd91482f5f
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-rint.h
@@ -0,0 +1,9 @@
+#if __GNUC_PREREQ (13, 0)
+#  define USE_RINT_BUILTIN 1
+#  define USE_RINTF_BUILTIN 1
+#else
+#  define USE_RINT_BUILTIN 0
+#  define USE_RINTF_BUILTIN 0
+#endif
+#define USE_RINTL_BUILTIN 0
+#define USE_RINTF128_BUILTIN 0
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 02/10] Use GCC builtins for lrint functions if desired.
  2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 01/10] LoongArch: Use __builtin_rint{,f} " Xiaolin Tang
@ 2022-11-23  3:44 ` Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 03/10] LoongArch: Use __builtin_lrint{,f} with GCC >= 13 Xiaolin Tang
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:44 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111
  Cc: xuchenghua, chenglulu, Xiaolin Tang

This patch is using the corresponding GCC builtin for lrintf, lrint,
lrintl and lrintf128 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-lrint.h   |  4 ++++
 sysdeps/generic/math-use-builtins.h         |  1 +
 sysdeps/ieee754/dbl-64/s_lrint.c            | 18 ++++++++++++------
 sysdeps/ieee754/float128/float128_private.h |  2 ++
 sysdeps/ieee754/flt-32/s_lrintf.c           | 18 ++++++++++++------
 sysdeps/ieee754/ldbl-128/s_lrintl.c         | 17 ++++++++++++-----
 6 files changed, 43 insertions(+), 17 deletions(-)
 create mode 100644 sysdeps/generic/math-use-builtins-lrint.h

diff --git a/sysdeps/generic/math-use-builtins-lrint.h b/sysdeps/generic/math-use-builtins-lrint.h
new file mode 100644
index 0000000000..e80418be9e
--- /dev/null
+++ b/sysdeps/generic/math-use-builtins-lrint.h
@@ -0,0 +1,4 @@
+#define USE_LRINT_BUILTIN 0
+#define USE_LRINTF_BUILTIN 0
+#define USE_LRINTL_BUILTIN 0
+#define USE_LRINTF128_BUILTIN 0
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 6bd424d900..3acec1d538 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -37,5 +37,6 @@
 #include <math-use-builtins-fmax.h>
 #include <math-use-builtins-fmin.h>
 #include <math-use-builtins-fabs.h>
+#include <math-use-builtins-lrint.h>
 
 #endif /* MATH_USE_BUILTINS_H  */
diff --git a/sysdeps/ieee754/dbl-64/s_lrint.c b/sysdeps/ieee754/dbl-64/s_lrint.c
index d4272916cd..24385038ef 100644
--- a/sysdeps/ieee754/dbl-64/s_lrint.c
+++ b/sysdeps/ieee754/dbl-64/s_lrint.c
@@ -25,17 +25,22 @@
 #include <math_private.h>
 #include <libm-alias-double.h>
 #include <fix-fp-int-convert-overflow.h>
-
-static const double two52[2] =
-{
-  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
- -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
-};
+#include <math-use-builtins.h>
 
 
 long int
 __lrint (double x)
 {
+#if USE_LRINT_BUILTIN
+  return __builtin_lrint (x);
+#else
+  /* Use generic implementation.  */
+  static const double two52[2] =
+  {
+    4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
+   -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
+  };
+
   int32_t j0;
   uint32_t i0, i1;
   double w;
@@ -119,6 +124,7 @@ __lrint (double x)
     }
 
   return sx ? -result : result;
+#endif /* ! USE_LRINT_BUILTIN  */
 }
 
 libm_alias_double (__lrint, lrint)
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
index f9655df0df..a452ced89a 100644
--- a/sysdeps/ieee754/float128/float128_private.h
+++ b/sysdeps/ieee754/float128/float128_private.h
@@ -161,6 +161,8 @@
 #define USE_COPYSIGNL_BUILTIN USE_COPYSIGNF128_BUILTIN
 #undef USE_FMAL_BUILTIN
 #define USE_FMAL_BUILTIN USE_FMAF128_BUILTIN
+#undef USE_LRINTL_BUILTIN
+#define USE_LRINTL_BUILTIN USE_LRINTF128_BUILTIN
 
 /* IEEE function renames.  */
 #define __ieee754_acoshl __ieee754_acoshf128
diff --git a/sysdeps/ieee754/flt-32/s_lrintf.c b/sysdeps/ieee754/flt-32/s_lrintf.c
index 7438b272b2..50d044dd8d 100644
--- a/sysdeps/ieee754/flt-32/s_lrintf.c
+++ b/sysdeps/ieee754/flt-32/s_lrintf.c
@@ -25,17 +25,22 @@
 #include <math_private.h>
 #include <libm-alias-float.h>
 #include <fix-fp-int-convert-overflow.h>
-
-static const float two23[2] =
-{
-  8.3886080000e+06, /* 0x4B000000 */
- -8.3886080000e+06, /* 0xCB000000 */
-};
+#include <math-use-builtins.h>
 
 
 long int
 __lrintf (float x)
 {
+#if USE_LRINTF_BUILTIN
+  return __builtin_lrintf (x);
+#else
+  /* Use generic implementation.  */
+  static const float two23[2] =
+  {
+    8.3886080000e+06, /* 0x4B000000 */
+   -8.3886080000e+06, /* 0xCB000000 */
+  };
+
   int32_t j0;
   uint32_t i0;
   float w;
@@ -82,6 +87,7 @@ __lrintf (float x)
     }
 
   return sx ? -result : result;
+#endif /* ! USE_LRINTF_BUILTIN  */
 }
 
 libm_alias_float (__lrint, lrint)
diff --git a/sysdeps/ieee754/ldbl-128/s_lrintl.c b/sysdeps/ieee754/ldbl-128/s_lrintl.c
index e8ec02dc6f..ecb604a650 100644
--- a/sysdeps/ieee754/ldbl-128/s_lrintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_lrintl.c
@@ -24,16 +24,22 @@
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
 #include <fix-fp-int-convert-overflow.h>
+#include <math-use-builtins.h>
 
-static const _Float128 two112[2] =
-{
-  L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
- L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
-};
 
 long int
 __lrintl (_Float128 x)
 {
+#if USE_LRINTL_BUILTIN
+  return __builtin_lrintl (x);
+#else
+  /* Use generic implementation. */
+  static const _Float128 two112[2] =
+  {
+    L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
+   L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
+  };
+
   int32_t j0;
   uint64_t i0,i1;
   _Float128 w;
@@ -131,6 +137,7 @@ __lrintl (_Float128 x)
     }
 
   return sx ? -result : result;
+#endif /* ! USE_LRINTL_BUILTIN  */
 }
 
 libm_alias_ldouble (__lrint, lrint)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 03/10] LoongArch: Use __builtin_lrint{,f} with GCC >= 13
  2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 01/10] LoongArch: Use __builtin_rint{,f} " Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 02/10] Use GCC builtins for lrint functions if desired Xiaolin Tang
@ 2022-11-23  3:44 ` Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 04/10] Use GCC builtins for llrint functions if desired Xiaolin Tang
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:44 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111
  Cc: xuchenghua, chenglulu, Xiaolin Tang

GCC 13 compiles these built-ins instead of generic
implementation for function lrint.

Link: https://gcc.gnu.org/r13-3920
Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
---
 sysdeps/loongarch/fpu/math-use-builtins-lrint.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-lrint.h

diff --git a/sysdeps/loongarch/fpu/math-use-builtins-lrint.h b/sysdeps/loongarch/fpu/math-use-builtins-lrint.h
new file mode 100644
index 0000000000..7df8aac81f
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-lrint.h
@@ -0,0 +1,10 @@
+#if __GNUC_PREREQ (13, 0)
+# define USE_LRINT_BUILTIN 1
+# define USE_LRINTF_BUILTIN 1
+#else
+# define USE_LRINT_BUILTIN 0
+# define USE_LRINTF_BUILTIN 0
+#endif
+
+#define USE_LRINTL_BUILTIN 0
+#define USE_LRINTF128_BUILTIN 0
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 04/10] Use GCC builtins for llrint functions if desired.
  2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
                   ` (2 preceding siblings ...)
  2022-11-23  3:44 ` [PATCH v2 03/10] LoongArch: Use __builtin_lrint{,f} with GCC >= 13 Xiaolin Tang
@ 2022-11-23  3:44 ` Xiaolin Tang
  2022-11-23  3:44 ` [PATCH v2 05/10] LoongArch: Use __builtin_llrint{,f} with GCC >= 13 Xiaolin Tang
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:44 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111
  Cc: xuchenghua, chenglulu, Xiaolin Tang

This patch is using the corresponding GCC builtin for llrintf, llrint,
llrintl and llrintf128 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-llrint.h  |  4 ++++
 sysdeps/generic/math-use-builtins.h         |  1 +
 sysdeps/ieee754/dbl-64/s_llrint.c           | 18 ++++++++++++------
 sysdeps/ieee754/float128/float128_private.h |  2 ++
 sysdeps/ieee754/flt-32/s_llrintf.c          | 18 ++++++++++++------
 sysdeps/ieee754/ldbl-128/s_llrintl.c        | 17 ++++++++++++-----
 6 files changed, 43 insertions(+), 17 deletions(-)
 create mode 100644 sysdeps/generic/math-use-builtins-llrint.h

diff --git a/sysdeps/generic/math-use-builtins-llrint.h b/sysdeps/generic/math-use-builtins-llrint.h
new file mode 100644
index 0000000000..ced6a327a1
--- /dev/null
+++ b/sysdeps/generic/math-use-builtins-llrint.h
@@ -0,0 +1,4 @@
+#define USE_LLRINT_BUILTIN 0
+#define USE_LLRINTF_BUILTIN 0
+#define USE_LLRINTL_BUILTIN 0
+#define USE_LLRINTF128_BUILTIN 0
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index 3acec1d538..dddeaa4ea8 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -38,5 +38,6 @@
 #include <math-use-builtins-fmin.h>
 #include <math-use-builtins-fabs.h>
 #include <math-use-builtins-lrint.h>
+#include <math-use-builtins-llrint.h>
 
 #endif /* MATH_USE_BUILTINS_H  */
diff --git a/sysdeps/ieee754/dbl-64/s_llrint.c b/sysdeps/ieee754/dbl-64/s_llrint.c
index dc8d9948df..88c8ec3624 100644
--- a/sysdeps/ieee754/dbl-64/s_llrint.c
+++ b/sysdeps/ieee754/dbl-64/s_llrint.c
@@ -25,17 +25,22 @@
 #include <math_private.h>
 #include <libm-alias-double.h>
 #include <fix-fp-int-convert-overflow.h>
-
-static const double two52[2] =
-{
-  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
- -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
-};
+#include <math-use-builtins.h>
 
 
 long long int
 __llrint (double x)
 {
+#if USE_LLRINT_BUILTIN
+  return __builtin_llrint (x);
+#else
+  /* Use generic implementation.  */
+  static const double two52[2] =
+  {
+    4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
+   -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
+  };
+
   int32_t j0;
   uint32_t i1, i0;
   long long int result;
@@ -95,6 +100,7 @@ __llrint (double x)
     }
 
   return sx ? -result : result;
+#endif /* ! USE_LLRINT_BUILTIN  */
 }
 
 libm_alias_double (__llrint, llrint)
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
index a452ced89a..3bb5fffa74 100644
--- a/sysdeps/ieee754/float128/float128_private.h
+++ b/sysdeps/ieee754/float128/float128_private.h
@@ -163,6 +163,8 @@
 #define USE_FMAL_BUILTIN USE_FMAF128_BUILTIN
 #undef USE_LRINTL_BUILTIN
 #define USE_LRINTL_BUILTIN USE_LRINTF128_BUILTIN
+#undef USE_LLRINTL_BUILTIN
+#define USE_LLRINTL_BUILTIN USE_LLRINTF128_BUILTIN
 
 /* IEEE function renames.  */
 #define __ieee754_acoshl __ieee754_acoshf128
diff --git a/sysdeps/ieee754/flt-32/s_llrintf.c b/sysdeps/ieee754/flt-32/s_llrintf.c
index 226b8261d3..79e3c385d1 100644
--- a/sysdeps/ieee754/flt-32/s_llrintf.c
+++ b/sysdeps/ieee754/flt-32/s_llrintf.c
@@ -25,17 +25,22 @@
 #include <math_private.h>
 #include <libm-alias-float.h>
 #include <fix-fp-int-convert-overflow.h>
-
-static const float two23[2] =
-{
-  8.3886080000e+06, /* 0x4B000000 */
- -8.3886080000e+06, /* 0xCB000000 */
-};
+#include <math-use-builtins.h>
 
 
 long long int
 __llrintf (float x)
 {
+#if USE_LLRINTF_BUILTIN
+  return __builtin_llrintf (x);
+#else
+  /* Use generic implementation.  */
+  static const float two23[2] =
+  {
+    8.3886080000e+06, /* 0x4B000000 */
+   -8.3886080000e+06, /* 0xCB000000 */
+  };
+
   int32_t j0;
   uint32_t i0;
   float w;
@@ -82,6 +87,7 @@ __llrintf (float x)
     }
 
   return sx ? -result : result;
+#endif /* ! USE_LLRINTF_BUILTIN  */
 }
 
 libm_alias_float (__llrint, llrint)
diff --git a/sysdeps/ieee754/ldbl-128/s_llrintl.c b/sysdeps/ieee754/ldbl-128/s_llrintl.c
index 79d3937cc9..3a5635d509 100644
--- a/sysdeps/ieee754/ldbl-128/s_llrintl.c
+++ b/sysdeps/ieee754/ldbl-128/s_llrintl.c
@@ -24,16 +24,22 @@
 #include <math_private.h>
 #include <libm-alias-ldouble.h>
 #include <fix-fp-int-convert-overflow.h>
+#include <math-use-builtins.h>
 
-static const _Float128 two112[2] =
-{
-  L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
- L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
-};
 
 long long int
 __llrintl (_Float128 x)
 {
+#if USE_LLRINTL_BUILTIN
+  return __builtin_round (x);
+#else
+  /* Use generic implementation.  */
+  static const _Float128 two112[2] =
+  {
+    L(5.19229685853482762853049632922009600E+33), /* 0x406F000000000000, 0 */
+   L(-5.19229685853482762853049632922009600E+33)  /* 0xC06F000000000000, 0 */
+  };
+
   int32_t j0;
   uint64_t i0,i1;
   _Float128 w;
@@ -102,6 +108,7 @@ __llrintl (_Float128 x)
     }
 
   return sx ? -result : result;
+#endif /* ! USE_LLRINTL_BUILTIN  */
 }
 
 libm_alias_ldouble (__llrint, llrint)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 05/10] LoongArch: Use __builtin_llrint{,f} with GCC >= 13
  2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
                   ` (3 preceding siblings ...)
  2022-11-23  3:44 ` [PATCH v2 04/10] Use GCC builtins for llrint functions if desired Xiaolin Tang
@ 2022-11-23  3:44 ` Xiaolin Tang
  2022-11-23  3:45 ` [PATCH v2 06/10] Use GCC builtins for logb functions if desired Xiaolin Tang
  2022-11-23  3:45 ` [PATCH v2 07/10] LoongArch: Use __builtin_logb{,f} with GCC >= 13 Xiaolin Tang
  6 siblings, 0 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:44 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111
  Cc: xuchenghua, chenglulu, Xiaolin Tang

GCC 13 compiles these built-ins instead of generic
implementation for function llrint.

Link: https://gcc.gnu.org/r13-3920
Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
---
 sysdeps/loongarch/fpu/math-use-builtins-llrint.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-llrint.h

diff --git a/sysdeps/loongarch/fpu/math-use-builtins-llrint.h b/sysdeps/loongarch/fpu/math-use-builtins-llrint.h
new file mode 100644
index 0000000000..bee5910b09
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-llrint.h
@@ -0,0 +1,10 @@
+#if __GNUC_PREREQ (13, 0)
+# define USE_LLRINT_BUILTIN 1
+# define USE_LLRINTF_BUILTIN 1
+#else
+# define USE_LLRINT_BUILTIN 0
+# define USE_LLRINTF_BUILTIN 0
+#endif
+
+#define USE_LLRINTL_BUILTIN 0
+#define USE_LLRINTF128_BUILTIN 0
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 06/10] Use GCC builtins for logb functions if desired.
  2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
                   ` (4 preceding siblings ...)
  2022-11-23  3:44 ` [PATCH v2 05/10] LoongArch: Use __builtin_llrint{,f} with GCC >= 13 Xiaolin Tang
@ 2022-11-23  3:45 ` Xiaolin Tang
  2022-11-23  3:45 ` [PATCH v2 07/10] LoongArch: Use __builtin_logb{,f} with GCC >= 13 Xiaolin Tang
  6 siblings, 0 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:45 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111
  Cc: xuchenghua, chenglulu, Xiaolin Tang

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    | 4 ++++
 sysdeps/generic/math-use-builtins.h         | 1 +
 sysdeps/ieee754/dbl-64/s_logb.c             | 5 +++++
 sysdeps/ieee754/float128/float128_private.h | 2 ++
 sysdeps/ieee754/flt-32/s_logbf.c            | 5 +++++
 sysdeps/ieee754/ldbl-128/s_logbl.c          | 6 ++++++
 6 files changed, 23 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..e816a7e0a1
--- /dev/null
+++ b/sysdeps/generic/math-use-builtins-logb.h
@@ -0,0 +1,4 @@
+#define USE_LOGB_BUILTIN 0
+#define USE_LOGBF_BUILTIN 0
+#define USE_LOGBL_BUILTIN 0
+#define USE_LOGBF128_BUILTIN 0
diff --git a/sysdeps/generic/math-use-builtins.h b/sysdeps/generic/math-use-builtins.h
index dddeaa4ea8..c59612a878 100644
--- a/sysdeps/generic/math-use-builtins.h
+++ b/sysdeps/generic/math-use-builtins.h
@@ -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  */
diff --git a/sysdeps/ieee754/dbl-64/s_logb.c b/sysdeps/ieee754/dbl-64/s_logb.c
index 82cabd206a..dd74d5f08c 100644
--- a/sysdeps/ieee754/dbl-64/s_logb.c
+++ b/sysdeps/ieee754/dbl-64/s_logb.c
@@ -21,10 +21,14 @@
 #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)
diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h
index 3bb5fffa74..78107b1525 100644
--- a/sysdeps/ieee754/float128/float128_private.h
+++ b/sysdeps/ieee754/float128/float128_private.h
@@ -165,6 +165,8 @@
 #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
diff --git a/sysdeps/ieee754/flt-32/s_logbf.c b/sysdeps/ieee754/flt-32/s_logbf.c
index a06f975797..b027e7b9c2 100644
--- a/sysdeps/ieee754/flt-32/s_logbf.c
+++ b/sysdeps/ieee754/flt-32/s_logbf.c
@@ -16,10 +16,14 @@
 #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)
diff --git a/sysdeps/ieee754/ldbl-128/s_logbl.c b/sysdeps/ieee754/ldbl-128/s_logbl.c
index 1c56eda499..59b08aa295 100644
--- a/sysdeps/ieee754/ldbl-128/s_logbl.c
+++ b/sysdeps/ieee754/ldbl-128/s_logbl.c
@@ -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)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 07/10] LoongArch: Use __builtin_logb{,f} with GCC >= 13
  2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
                   ` (5 preceding siblings ...)
  2022-11-23  3:45 ` [PATCH v2 06/10] Use GCC builtins for logb functions if desired Xiaolin Tang
@ 2022-11-23  3:45 ` Xiaolin Tang
  6 siblings, 0 replies; 8+ messages in thread
From: Xiaolin Tang @ 2022-11-23  3:45 UTC (permalink / raw)
  To: adhemerval.zanella, libc-alpha, caiyinyu, xry111
  Cc: xuchenghua, chenglulu, Xiaolin Tang

GCC 13 compiles these built-ins instead of generic
implementation for function logb.

Link: https://gcc.gnu.org/r13-3922
Co-Authored-By: Xi Ruoyao <xry111@xry111.site>
---
 sysdeps/loongarch/fpu/math-use-builtins-logb.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-logb.h

diff --git a/sysdeps/loongarch/fpu/math-use-builtins-logb.h b/sysdeps/loongarch/fpu/math-use-builtins-logb.h
new file mode 100644
index 0000000000..b1c3f30dc4
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-logb.h
@@ -0,0 +1,10 @@
+#if __GNUC_PREREQ (13, 0)
+# define USE_LOGB_BUILTIN 1
+# define USE_LOGBF_BUILTIN 1
+#else
+# define USE_LOGB_BUILTIN 0
+# define USE_LOGBF_BUILTIN 0
+#endif
+
+#define USE_LOGBL_BUILTIN 0
+#define USE_LOGBF128_BUILTIN 0
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-23  3:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23  3:44 [PATCH v2 00/10] LoongArch: Use builtins with GCC >= 13 Xiaolin Tang
2022-11-23  3:44 ` [PATCH v2 01/10] LoongArch: Use __builtin_rint{,f} " Xiaolin Tang
2022-11-23  3:44 ` [PATCH v2 02/10] Use GCC builtins for lrint functions if desired Xiaolin Tang
2022-11-23  3:44 ` [PATCH v2 03/10] LoongArch: Use __builtin_lrint{,f} with GCC >= 13 Xiaolin Tang
2022-11-23  3:44 ` [PATCH v2 04/10] Use GCC builtins for llrint functions if desired Xiaolin Tang
2022-11-23  3:44 ` [PATCH v2 05/10] LoongArch: Use __builtin_llrint{,f} with GCC >= 13 Xiaolin Tang
2022-11-23  3:45 ` [PATCH v2 06/10] Use GCC builtins for logb functions if desired Xiaolin Tang
2022-11-23  3:45 ` [PATCH v2 07/10] LoongArch: Use __builtin_logb{,f} with GCC >= 13 Xiaolin Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).