public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9
@ 2021-03-01 17:51 Raphael Moreira Zinsly
  2021-03-01 17:51 ` [PATCH v2 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Raphael Moreira Zinsly @ 2021-03-01 17:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: murphyp, tuliom, Raphael Moreira Zinsly

Changes since v1:
	- Move the builtins definitions to powerpc's math_private.h.
	- Check if the correct GCC version is used.

--8<---

The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract
the exponent from a double-precision and quad-precision floating-point
respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128.
---
 sysdeps/powerpc/fpu/math_private.h            | 20 +++++++++++-
 .../powerpc64/le/fpu/w_ilogb_template.c       | 31 +++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c

diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h
index 91b1361749..accc28d091 100644
--- a/sysdeps/powerpc/fpu/math_private.h
+++ b/sysdeps/powerpc/fpu/math_private.h
@@ -25,7 +25,23 @@
 
 #include_next <math_private.h>
 
-#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128
+#ifdef _ARCH_PWR9
+
+#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb
+#define __builtin_ilogbf __builtin_ilogb
+
+#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128
+#define __builtin_ilogbl __builtin_ilogbf128
+
+#define __builtin_test_dc_ilogb(x, y) \
+        __builtin_vsx_scalar_test_data_class_dp(x, y)
+#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff
+
+#define __builtin_test_dc_ilogbf128(x, y) \
+        __builtin_vsx_scalar_test_data_class_qp(x, y)
+#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff
+
+#if __HAVE_DISTINCT_FLOAT128
 extern __always_inline _Float128
 __ieee754_sqrtf128 (_Float128 __x)
 {
@@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x)
 }
 #endif
 
+#endif /* _ARCH_PWR9 */
+
 #endif /* _PPC_MATH_PRIVATE_H_ */
diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
new file mode 100644
index 0000000000..17ac7809e1
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
@@ -0,0 +1,31 @@
+/* The builtins used are only available with GCC 8.0 or newer.  */
+#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0)
+#include <math.h>
+#include <errno.h>
+#include <limits.h>
+#include <math_private.h>
+#include <fenv.h>
+
+int
+M_DECL_FUNC (__ilogb) (FLOAT x)
+{
+  int r;
+  /* Check for exceptional cases.  */
+  if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f))
+    r = M_SUF (__builtin_ilogb) (x);
+  else
+    /* Fallback to the generic ilogb if x is NaN, Inf or subnormal.  */
+    r = M_SUF (__ieee754_ilogb) (x);
+  if (__builtin_expect (r == FP_ILOGB0, 0)
+      || __builtin_expect (r == FP_ILOGBNAN, 0)
+      || __builtin_expect (r == INT_MAX, 0))
+    {
+      __set_errno (EDOM);
+      __feraiseexcept (FE_INVALID);
+    }
+  return r;
+}
+declare_mgen_alias (__ilogb, ilogb)
+#else
+#include <math/w_ilogb_template.c>
+#endif
-- 
2.29.2


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

* [PATCH v2 2/3] powerpc: Add optimized llogb* for POWER9
  2021-03-01 17:51 [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
@ 2021-03-01 17:51 ` Raphael Moreira Zinsly
  2021-03-01 17:51 ` [PATCH v2 3/3] benchtests: Add ilogb* tests Raphael Moreira Zinsly
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Raphael Moreira Zinsly @ 2021-03-01 17:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: murphyp, tuliom, Raphael Moreira Zinsly

Changes since v1:
	- Check if the correct GCC version is used.

--8<---

The POWER9 builtins used to improve the ilogb* functions can be
used in the llogb* functions as well.
---
 .../powerpc64/le/fpu/w_llogb_template.c       | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c

diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
new file mode 100644
index 0000000000..4c1642274f
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
@@ -0,0 +1,40 @@
+/* The builtins used are only available with GCC 8.0 or newer.  */
+#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0)
+#include <math.h>
+#include <errno.h>
+#include <limits.h>
+#include <math_private.h>
+#include <fenv.h>
+
+long int
+M_DECL_FUNC (__llogb) (FLOAT x)
+{
+  int r;
+  /* Check for exceptional cases.  */
+  if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f))
+    r = M_SUF (__builtin_ilogb) (x);
+  else
+    /* Fallback to the generic ilogb if x is NaN, Inf or subnormal.  */
+    r = M_SUF (__ieee754_ilogb) (x);
+  long int lr = r;
+  if (__glibc_unlikely (r == FP_ILOGB0)
+      || __glibc_unlikely (r == FP_ILOGBNAN)
+      || __glibc_unlikely (r == INT_MAX))
+    {
+#if LONG_MAX != INT_MAX
+      if (r == FP_ILOGB0)
+	lr = FP_LLOGB0;
+      else if (r == FP_ILOGBNAN)
+	lr = FP_LLOGBNAN;
+      else
+	lr = LONG_MAX;
+#endif
+      __set_errno (EDOM);
+      __feraiseexcept (FE_INVALID);
+    }
+  return lr;
+}
+declare_mgen_alias (__llogb, llogb)
+#else
+#include <math/w_llogb_template.c>
+#endif
-- 
2.29.2


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

* [PATCH v2 3/3] benchtests: Add ilogb* tests
  2021-03-01 17:51 [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
  2021-03-01 17:51 ` [PATCH v2 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
@ 2021-03-01 17:51 ` Raphael Moreira Zinsly
  2021-03-02  1:27 ` [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Paul A. Clarke
  2021-03-02 17:46 ` Paul E Murphy
  3 siblings, 0 replies; 7+ messages in thread
From: Raphael Moreira Zinsly @ 2021-03-01 17:51 UTC (permalink / raw)
  To: libc-alpha; +Cc: murphyp, tuliom, Raphael Moreira Zinsly

Add a benchtest to ilogb, ilogbf and ilogbf128 based on the logb* benchtests.
---
 benchtests/Makefile         |  4 ++--
 benchtests/ilogb-inputs     | 11 +++++++++++
 benchtests/ilogbf-inputs    | 11 +++++++++++
 benchtests/ilogbf128-inputs | 11 +++++++++++
 4 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 benchtests/ilogb-inputs
 create mode 100644 benchtests/ilogbf-inputs
 create mode 100644 benchtests/ilogbf128-inputs

diff --git a/benchtests/Makefile b/benchtests/Makefile
index 12bd25a57c..0c99547074 100644
--- a/benchtests/Makefile
+++ b/benchtests/Makefile
@@ -25,10 +25,10 @@ bench-math := acos acosh asin asinh atan atanh cos cosh exp exp2 log log2 \
 	      modf pow rint sin sincos sinh sqrt tan tanh fmin fmax fminf \
 	      fmaxf powf trunc truncf roundeven roundevenf expf exp2f logf \
 	      log2f sincosf sinf cosf isnan isinf isfinite hypot logb logbf \
-	      exp10f
+	      exp10f ilogb ilogbf
 
 ifneq (,$(filter yes,$(float128-fcts) $(float128-alias-fcts)))
-bench-math += expf128 powf128 sinf128
+bench-math += expf128 powf128 sinf128 ilogbf128
 endif
 
 bench-pthread := pthread_once thread_create pthread-locks
diff --git a/benchtests/ilogb-inputs b/benchtests/ilogb-inputs
new file mode 100644
index 0000000000..4b3b38bd99
--- /dev/null
+++ b/benchtests/ilogb-inputs
@@ -0,0 +1,11 @@
+## args: double
+## ret: int
+## includes: math.h
+
+## name: subnormal
+0x0.0000000000001p-1022
+0x0.fffffffffffffp-1022
+
+## name: normal
+1.0
+1024.0
diff --git a/benchtests/ilogbf-inputs b/benchtests/ilogbf-inputs
new file mode 100644
index 0000000000..ea391d3b85
--- /dev/null
+++ b/benchtests/ilogbf-inputs
@@ -0,0 +1,11 @@
+## args: float
+## ret: int
+## includes: math.h
+
+## name: subnormal
+0x1p-149
+0x1.fffff8p-128
+
+## name: normal
+1.0
+1024.0
diff --git a/benchtests/ilogbf128-inputs b/benchtests/ilogbf128-inputs
new file mode 100644
index 0000000000..bfbfc93714
--- /dev/null
+++ b/benchtests/ilogbf128-inputs
@@ -0,0 +1,11 @@
+## args: _Float128
+## ret: int
+## includes: math.h
+
+## name: subnormal
+6.47517511943802511092443895822764655e-4966f128
+0x1.fffffffffffffff8p-16383f128
+
+## name: normal
+1.0
+-0x8.2faf442f390a9211f5af128673fp+0L
-- 
2.29.2


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

* Re: [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9
  2021-03-01 17:51 [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
  2021-03-01 17:51 ` [PATCH v2 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
  2021-03-01 17:51 ` [PATCH v2 3/3] benchtests: Add ilogb* tests Raphael Moreira Zinsly
@ 2021-03-02  1:27 ` Paul A. Clarke
  2021-03-03 16:23   ` Raphael M Zinsly
  2021-03-02 17:46 ` Paul E Murphy
  3 siblings, 1 reply; 7+ messages in thread
From: Paul A. Clarke @ 2021-03-02  1:27 UTC (permalink / raw)
  To: Raphael Moreira Zinsly; +Cc: libc-alpha, murphyp, tuliom

On Mon, Mar 01, 2021 at 02:51:38PM -0300, Raphael Moreira Zinsly via Libc-alpha wrote:
> Changes since v1:
> 	- Move the builtins definitions to powerpc's math_private.h.
> 	- Check if the correct GCC version is used.
> 
> --8<---
> 
> The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract
> the exponent from a double-precision and quad-precision floating-point
> respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128.
> ---
>  sysdeps/powerpc/fpu/math_private.h            | 20 +++++++++++-
>  .../powerpc64/le/fpu/w_ilogb_template.c       | 31 +++++++++++++++++++
>  2 files changed, 50 insertions(+), 1 deletion(-)
>  create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> 
> diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h
> index 91b1361749..accc28d091 100644
> --- a/sysdeps/powerpc/fpu/math_private.h
> +++ b/sysdeps/powerpc/fpu/math_private.h
> @@ -25,7 +25,23 @@
> 
>  #include_next <math_private.h>
> 
> -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128
> +#ifdef _ARCH_PWR9
> +
> +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb
> +#define __builtin_ilogbf __builtin_ilogb
> +
> +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128
> +#define __builtin_ilogbl __builtin_ilogbf128
> +
> +#define __builtin_test_dc_ilogb(x, y) \
> +        __builtin_vsx_scalar_test_data_class_dp(x, y)
> +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff
> +
> +#define __builtin_test_dc_ilogbf128(x, y) \
> +        __builtin_vsx_scalar_test_data_class_qp(x, y)
> +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff
> +
> +#if __HAVE_DISTINCT_FLOAT128
>  extern __always_inline _Float128
>  __ieee754_sqrtf128 (_Float128 __x)
>  {
> @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x)
>  }
>  #endif
> 
> +#endif /* _ARCH_PWR9 */
> +
>  #endif /* _PPC_MATH_PRIVATE_H_ */
> diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> new file mode 100644
> index 0000000000..17ac7809e1
> --- /dev/null
> +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> @@ -0,0 +1,31 @@
> +/* The builtins used are only available with GCC 8.0 or newer.  */
> +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0)

I wonder if it would be better to use __glibc_has_builtin () for the
builtins on which you depend, rather than testing for a specific GCC level.

(Same for patch 2/3.)

PC

> +#include <math.h>
> +#include <errno.h>
> +#include <limits.h>
> +#include <math_private.h>
> +#include <fenv.h>
> +
> +int
> +M_DECL_FUNC (__ilogb) (FLOAT x)
> +{
> +  int r;
> +  /* Check for exceptional cases.  */
> +  if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f))
> +    r = M_SUF (__builtin_ilogb) (x);
> +  else
> +    /* Fallback to the generic ilogb if x is NaN, Inf or subnormal.  */
> +    r = M_SUF (__ieee754_ilogb) (x);
> +  if (__builtin_expect (r == FP_ILOGB0, 0)
> +      || __builtin_expect (r == FP_ILOGBNAN, 0)
> +      || __builtin_expect (r == INT_MAX, 0))
> +    {
> +      __set_errno (EDOM);
> +      __feraiseexcept (FE_INVALID);
> +    }
> +  return r;
> +}
> +declare_mgen_alias (__ilogb, ilogb)
> +#else
> +#include <math/w_ilogb_template.c>
> +#endif
> -- 
> 2.29.2
> 

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

* Re: [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9
  2021-03-01 17:51 [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
                   ` (2 preceding siblings ...)
  2021-03-02  1:27 ` [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Paul A. Clarke
@ 2021-03-02 17:46 ` Paul E Murphy
  3 siblings, 0 replies; 7+ messages in thread
From: Paul E Murphy @ 2021-03-02 17:46 UTC (permalink / raw)
  To: Raphael Moreira Zinsly, libc-alpha; +Cc: tuliom



On 3/1/21 11:51 AM, Raphael Moreira Zinsly wrote:
> Changes since v1:
> 	- Move the builtins definitions to powerpc's math_private.h.
> 	- Check if the correct GCC version is used.
> 
> --8<---
> 
> The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract
> the exponent from a double-precision and quad-precision floating-point
> respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128.
> ---
>   sysdeps/powerpc/fpu/math_private.h            | 20 +++++++++++-
>   .../powerpc64/le/fpu/w_ilogb_template.c       | 31 +++++++++++++++++++
>   2 files changed, 50 insertions(+), 1 deletion(-)
>   create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> 
> diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h
> index 91b1361749..accc28d091 100644
> --- a/sysdeps/powerpc/fpu/math_private.h
> +++ b/sysdeps/powerpc/fpu/math_private.h
> @@ -25,7 +25,23 @@
>   
>   #include_next <math_private.h>
>   
> -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128
> +#ifdef _ARCH_PWR9
> +
> +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb
> +#define __builtin_ilogbf __builtin_ilogb
> +
> +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128
> +#define __builtin_ilogbl __builtin_ilogbf128

I suspect this converting an ibm128 value to float128.  Can you verify 
whether this is the case, and if so, exclude ibm long doubles from this 
optimization? (Note, libm should be building long double == ibm128)

Otherwise, LGTM.

> +
> +#define __builtin_test_dc_ilogb(x, y) \
> +        __builtin_vsx_scalar_test_data_class_dp(x, y)
> +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff
> +
> +#define __builtin_test_dc_ilogbf128(x, y) \
> +        __builtin_vsx_scalar_test_data_class_qp(x, y)
> +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff
> +
> +#if __HAVE_DISTINCT_FLOAT128
>   extern __always_inline _Float128
>   __ieee754_sqrtf128 (_Float128 __x)
>   {
> @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x)
>   }
>   #endif
>   
> +#endif /* _ARCH_PWR9 */
> +
>   #endif /* _PPC_MATH_PRIVATE_H_ */
> diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> new file mode 100644
> index 0000000000..17ac7809e1
> --- /dev/null
> +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> @@ -0,0 +1,31 @@
> +/* The builtins used are only available with GCC 8.0 or newer.  */
> +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0)
> +#include <math.h>
> +#include <errno.h>
> +#include <limits.h>
> +#include <math_private.h>
> +#include <fenv.h>
> +
> +int
> +M_DECL_FUNC (__ilogb) (FLOAT x)
> +{
> +  int r;
> +  /* Check for exceptional cases.  */
> +  if (! M_SUF(__builtin_test_dc_ilogb) (x, 0x7f))
> +    r = M_SUF (__builtin_ilogb) (x);
> +  else
> +    /* Fallback to the generic ilogb if x is NaN, Inf or subnormal.  */
> +    r = M_SUF (__ieee754_ilogb) (x);
> +  if (__builtin_expect (r == FP_ILOGB0, 0)
> +      || __builtin_expect (r == FP_ILOGBNAN, 0)
> +      || __builtin_expect (r == INT_MAX, 0))
> +    {
> +      __set_errno (EDOM);
> +      __feraiseexcept (FE_INVALID);
> +    }
> +  return r;
> +}
> +declare_mgen_alias (__ilogb, ilogb)
> +#else
> +#include <math/w_ilogb_template.c>
> +#endif
> 

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

* Re: [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9
  2021-03-02  1:27 ` [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Paul A. Clarke
@ 2021-03-03 16:23   ` Raphael M Zinsly
  2021-03-03 17:20     ` Paul A. Clarke
  0 siblings, 1 reply; 7+ messages in thread
From: Raphael M Zinsly @ 2021-03-03 16:23 UTC (permalink / raw)
  To: Paul A. Clarke; +Cc: libc-alpha

On 01/03/2021 22:27, Paul A. Clarke wrote:
> On Mon, Mar 01, 2021 at 02:51:38PM -0300, Raphael Moreira Zinsly via Libc-alpha wrote:
>> Changes since v1:
>> 	- Move the builtins definitions to powerpc's math_private.h.
>> 	- Check if the correct GCC version is used.
>>
>> --8<---
>>
>> The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract
>> the exponent from a double-precision and quad-precision floating-point
>> respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128.
>> ---
>>   sysdeps/powerpc/fpu/math_private.h            | 20 +++++++++++-
>>   .../powerpc64/le/fpu/w_ilogb_template.c       | 31 +++++++++++++++++++
>>   2 files changed, 50 insertions(+), 1 deletion(-)
>>   create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
>>
>> diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h
>> index 91b1361749..accc28d091 100644
>> --- a/sysdeps/powerpc/fpu/math_private.h
>> +++ b/sysdeps/powerpc/fpu/math_private.h
>> @@ -25,7 +25,23 @@
>>
>>   #include_next <math_private.h>
>>
>> -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128
>> +#ifdef _ARCH_PWR9
>> +
>> +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb
>> +#define __builtin_ilogbf __builtin_ilogb
>> +
>> +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128
>> +#define __builtin_ilogbl __builtin_ilogbf128
>> +
>> +#define __builtin_test_dc_ilogb(x, y) \
>> +        __builtin_vsx_scalar_test_data_class_dp(x, y)
>> +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff
>> +
>> +#define __builtin_test_dc_ilogbf128(x, y) \
>> +        __builtin_vsx_scalar_test_data_class_qp(x, y)
>> +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff
>> +
>> +#if __HAVE_DISTINCT_FLOAT128
>>   extern __always_inline _Float128
>>   __ieee754_sqrtf128 (_Float128 __x)
>>   {
>> @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x)
>>   }
>>   #endif
>>
>> +#endif /* _ARCH_PWR9 */
>> +
>>   #endif /* _PPC_MATH_PRIVATE_H_ */
>> diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
>> new file mode 100644
>> index 0000000000..17ac7809e1
>> --- /dev/null
>> +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
>> @@ -0,0 +1,31 @@
>> +/* The builtins used are only available with GCC 8.0 or newer.  */
>> +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0)
> 
> I wonder if it would be better to use __glibc_has_builtin () for the
> builtins on which you depend, rather than testing for a specific GCC level.
>

I didn't find a __glibc_has_builtin definition, do you mean the 
preprocessor's __has_builtin()? I believe it's not available on GCC 8.0.

> (Same for patch 2/3.)
> 
> PC
-- 
Raphael Moreira Zinsly
IBM
Linux on Power Toolchain

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

* Re: [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9
  2021-03-03 16:23   ` Raphael M Zinsly
@ 2021-03-03 17:20     ` Paul A. Clarke
  0 siblings, 0 replies; 7+ messages in thread
From: Paul A. Clarke @ 2021-03-03 17:20 UTC (permalink / raw)
  To: Raphael M Zinsly; +Cc: libc-alpha

On Wed, Mar 03, 2021 at 01:23:43PM -0300, Raphael M Zinsly via Libc-alpha wrote:
> On 01/03/2021 22:27, Paul A. Clarke wrote:
> > On Mon, Mar 01, 2021 at 02:51:38PM -0300, Raphael Moreira Zinsly via Libc-alpha wrote:
> > > Changes since v1:
> > > 	- Move the builtins definitions to powerpc's math_private.h.
> > > 	- Check if the correct GCC version is used.
> > > 
> > > --8<---
> > > 
> > > The instructions xsxexpdp and xsxexpqp introduced on POWER9 extract
> > > the exponent from a double-precision and quad-precision floating-point
> > > respectively, thus they can be used to improve ilogb, ilogbf and ilogbf128.
> > > ---
> > >   sysdeps/powerpc/fpu/math_private.h            | 20 +++++++++++-
> > >   .../powerpc64/le/fpu/w_ilogb_template.c       | 31 +++++++++++++++++++
> > >   2 files changed, 50 insertions(+), 1 deletion(-)
> > >   create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> > > 
> > > diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h
> > > index 91b1361749..accc28d091 100644
> > > --- a/sysdeps/powerpc/fpu/math_private.h
> > > +++ b/sysdeps/powerpc/fpu/math_private.h
> > > @@ -25,7 +25,23 @@
> > > 
> > >   #include_next <math_private.h>
> > > 
> > > -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128
> > > +#ifdef _ARCH_PWR9
> > > +
> > > +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb
> > > +#define __builtin_ilogbf __builtin_ilogb
> > > +
> > > +#define __builtin_test_dc_ilogbl __builtin_test_dc_ilogbf128
> > > +#define __builtin_ilogbl __builtin_ilogbf128
> > > +
> > > +#define __builtin_test_dc_ilogb(x, y) \
> > > +        __builtin_vsx_scalar_test_data_class_dp(x, y)
> > > +#define __builtin_ilogb(x) __builtin_vsx_scalar_extract_exp(x) - 0x3ff
> > > +
> > > +#define __builtin_test_dc_ilogbf128(x, y) \
> > > +        __builtin_vsx_scalar_test_data_class_qp(x, y)
> > > +#define __builtin_ilogbf128(x) __builtin_vsx_scalar_extract_expq(x) - 0x3fff
> > > +
> > > +#if __HAVE_DISTINCT_FLOAT128
> > >   extern __always_inline _Float128
> > >   __ieee754_sqrtf128 (_Float128 __x)
> > >   {
> > > @@ -35,4 +51,6 @@ __ieee754_sqrtf128 (_Float128 __x)
> > >   }
> > >   #endif
> > > 
> > > +#endif /* _ARCH_PWR9 */
> > > +
> > >   #endif /* _PPC_MATH_PRIVATE_H_ */
> > > diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> > > new file mode 100644
> > > index 0000000000..17ac7809e1
> > > --- /dev/null
> > > +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> > > @@ -0,0 +1,31 @@
> > > +/* The builtins used are only available with GCC 8.0 or newer.  */
> > > +#if defined _ARCH_PWR9 && __GNUC_PREREQ (8, 0)
> > 
> > I wonder if it would be better to use __glibc_has_builtin () for the
> > builtins on which you depend, rather than testing for a specific GCC level.
> > 
> 
> I didn't find a __glibc_has_builtin definition, do you mean the
> preprocessor's __has_builtin()? I believe it's not available on GCC 8.0.

misc/sys/cdefs.h:
--
/* Compilers that lack __has_attribute may object to
       #if defined __has_attribute && __has_attribute (...)
   even though they do not need to evaluate the right-hand side of the &&.
   Similarly for __has_builtin, etc.  */
[...]
#ifdef __has_builtin
# define __glibc_has_builtin(name) __has_builtin (name)
#else
# define __glibc_has_builtin(name) 0
#endif
--

... so, it covers pre-GCC8 by always saying "nope".

PC

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

end of thread, other threads:[~2021-03-03 17:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 17:51 [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
2021-03-01 17:51 ` [PATCH v2 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
2021-03-01 17:51 ` [PATCH v2 3/3] benchtests: Add ilogb* tests Raphael Moreira Zinsly
2021-03-02  1:27 ` [PATCH v2 1/3] powerpc: Add optimized ilogb* for POWER9 Paul A. Clarke
2021-03-03 16:23   ` Raphael M Zinsly
2021-03-03 17:20     ` Paul A. Clarke
2021-03-02 17:46 ` Paul E Murphy

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).