public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Xiaolin Tang <tangxiaolin@loongson.cn>
To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org,
	caiyinyu@loongson.cn, xry111@xry111.site
Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn,
	Xiaolin Tang <tangxiaolin@loongson.cn>
Subject: [PATCH v2 06/10] Use GCC builtins for logb functions if desired.
Date: Wed, 23 Nov 2022 11:45:00 +0800	[thread overview]
Message-ID: <20221123034504.1249579-7-tangxiaolin@loongson.cn> (raw)
In-Reply-To: <20221123034504.1249579-1-tangxiaolin@loongson.cn>

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


  parent reply	other threads:[~2022-11-23  3:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Xiaolin Tang [this message]
2022-11-23  3:45 ` [PATCH v2 07/10] LoongArch: Use __builtin_logb{,f} " Xiaolin Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221123034504.1249579-7-tangxiaolin@loongson.cn \
    --to=tangxiaolin@loongson.cn \
    --cc=adhemerval.zanella@linaro.org \
    --cc=caiyinyu@loongson.cn \
    --cc=chenglulu@loongson.cn \
    --cc=libc-alpha@sourceware.org \
    --cc=xry111@xry111.site \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).