* [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9
@ 2021-03-04 15:00 Raphael Moreira Zinsly
2021-03-04 15:00 ` [PATCH v3 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Raphael Moreira Zinsly @ 2021-03-04 15:00 UTC (permalink / raw)
To: libc-alpha; +Cc: murphyp, pc, tuliom, Raphael Moreira Zinsly
Changes since v2:
- Moved the GCC version test to math_private.h and start using
__has_builtin().
- Removed the optimization from long double as it was converting
ibm128 to float128.
---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 | 26 +++++++++++++++-
.../powerpc64/le/fpu/w_ilogb_template.c | 30 +++++++++++++++++++
sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c | 3 ++
3 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h
index 91b1361749..21628f3bda 100644
--- a/sysdeps/powerpc/fpu/math_private.h
+++ b/sysdeps/powerpc/fpu/math_private.h
@@ -25,7 +25,28 @@
#include_next <math_private.h>
-#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128
+#ifdef _ARCH_PWR9
+
+#if __GNUC_PREREQ (8, 0)
+# define _GL_HAS_BUILTIN_ILOGB 1
+#elif defined __has_builtin
+# define _GL_HAS_BUILTIN_ILOGB __has_builtin (__builtin_vsx_scalar_extract_exp)
+#else
+# define _GL_HAS_BUILTIN_ILOGB 0
+#endif
+
+#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb
+#define __builtin_ilogbf __builtin_ilogb
+
+#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)
{
@@ -34,5 +55,8 @@ __ieee754_sqrtf128 (_Float128 __x)
return __z;
}
#endif
+#else /* !_ARCH_PWR9 */
+#define _GL_HAS_BUILTIN_ILOGB 0
+#endif
#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..b5c1c0aa9d
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
@@ -0,0 +1,30 @@
+#include <math.h>
+#include <errno.h>
+#include <limits.h>
+#include <math_private.h>
+#include <fenv.h>
+
+#if _GL_HAS_BUILTIN_ILOGB
+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
diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
new file mode 100644
index 0000000000..215a00141d
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
@@ -0,0 +1,3 @@
+/* Skip the optimization for long double as it uses ibm128. */
+#include <math-type-macros-ldouble.h>
+#include <math/w_ilogb_template.c>
--
2.29.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 2/3] powerpc: Add optimized llogb* for POWER9
2021-03-04 15:00 [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
@ 2021-03-04 15:00 ` Raphael Moreira Zinsly
2021-03-18 16:51 ` Paul E Murphy
2021-03-04 15:00 ` [PATCH v3 3/3] benchtests: Add ilogb* tests Raphael Moreira Zinsly
2021-03-04 15:30 ` [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Paul E Murphy
2 siblings, 1 reply; 6+ messages in thread
From: Raphael Moreira Zinsly @ 2021-03-04 15:00 UTC (permalink / raw)
To: libc-alpha; +Cc: murphyp, pc, tuliom, Raphael Moreira Zinsly
Changes since v2:
- Removed the GCC version test and used the _GL_HAS_BUILTIN_ILOGB.
- Removed the optimization from long double as it was converting
ibm128 to float128.
---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 | 39 +++++++++++++++++++
sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c | 3 ++
2 files changed, 42 insertions(+)
create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.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..d00b71d2a3
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_llogb_template.c
@@ -0,0 +1,39 @@
+#include <math.h>
+#include <errno.h>
+#include <limits.h>
+#include <math_private.h>
+#include <fenv.h>
+
+#if _GL_HAS_BUILTIN_ILOGB
+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
diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c b/sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c
new file mode 100644
index 0000000000..b7e132a1de
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/le/fpu/w_llogbl.c
@@ -0,0 +1,3 @@
+/* Skip the optimization for long double as it uses ibm128. */
+#include <math-type-macros-ldouble.h>
+#include <math/w_llogb_template.c>
--
2.29.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 3/3] benchtests: Add ilogb* tests
2021-03-04 15:00 [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
2021-03-04 15:00 ` [PATCH v3 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
@ 2021-03-04 15:00 ` Raphael Moreira Zinsly
2021-03-04 15:30 ` [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Paul E Murphy
2 siblings, 0 replies; 6+ messages in thread
From: Raphael Moreira Zinsly @ 2021-03-04 15:00 UTC (permalink / raw)
To: libc-alpha; +Cc: murphyp, pc, 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] 6+ messages in thread
* Re: [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9
2021-03-04 15:00 [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
2021-03-04 15:00 ` [PATCH v3 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
2021-03-04 15:00 ` [PATCH v3 3/3] benchtests: Add ilogb* tests Raphael Moreira Zinsly
@ 2021-03-04 15:30 ` Paul E Murphy
2021-03-16 16:20 ` Raphael M Zinsly
2 siblings, 1 reply; 6+ messages in thread
From: Paul E Murphy @ 2021-03-04 15:30 UTC (permalink / raw)
To: Raphael Moreira Zinsly, libc-alpha; +Cc: pc, tuliom
On 3/4/21 9:00 AM, Raphael Moreira Zinsly wrote:
> Changes since v2:
> - Moved the GCC version test to math_private.h and start using
> __has_builtin().
> - Removed the optimization from long double as it was converting
> ibm128 to float128.
>
> ---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 | 26 +++++++++++++++-
> .../powerpc64/le/fpu/w_ilogb_template.c | 30 +++++++++++++++++++
> sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c | 3 ++
> 3 files changed, 58 insertions(+), 1 deletion(-)
> create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> create mode 100644 sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
>
> diff --git a/sysdeps/powerpc/fpu/math_private.h b/sysdeps/powerpc/fpu/math_private.h
> index 91b1361749..21628f3bda 100644
> --- a/sysdeps/powerpc/fpu/math_private.h
> +++ b/sysdeps/powerpc/fpu/math_private.h
> @@ -25,7 +25,28 @@
>
> #include_next <math_private.h>
>
> -#if defined _ARCH_PWR9 && __HAVE_DISTINCT_FLOAT128
> +#ifdef _ARCH_PWR9
> +
> +#if __GNUC_PREREQ (8, 0)
> +# define _GL_HAS_BUILTIN_ILOGB 1
> +#elif defined __has_builtin
> +# define _GL_HAS_BUILTIN_ILOGB __has_builtin (__builtin_vsx_scalar_extract_exp)
> +#else
> +# define _GL_HAS_BUILTIN_ILOGB 0
> +#endif
> +
> +#define __builtin_test_dc_ilogbf __builtin_test_dc_ilogb
> +#define __builtin_ilogbf __builtin_ilogb
> +
> +#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)
> {
> @@ -34,5 +55,8 @@ __ieee754_sqrtf128 (_Float128 __x)
> return __z;
> }
> #endif
> +#else /* !_ARCH_PWR9 */
> +#define _GL_HAS_BUILTIN_ILOGB 0
> +#endif
>
> #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..b5c1c0aa9d
> --- /dev/null
> +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogb_template.c
> @@ -0,0 +1,30 @@
> +#include <math.h>
> +#include <errno.h>
> +#include <limits.h>
> +#include <math_private.h>
> +#include <fenv.h>
> +
> +#if _GL_HAS_BUILTIN_ILOGB
> +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
> diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
> new file mode 100644
> index 0000000000..215a00141d
> --- /dev/null
> +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
> @@ -0,0 +1,3 @@
> +/* Skip the optimization for long double as it uses ibm128. */
I would recommend rewording this as "... as ibm128 does not provide an
optimized builtin".
Though, I suspect you could use the double version of these built-ins by
extracting the significant double of the ibm128, and testing/extracting
it in a similar manner.
Anyhow, this patch is OK with a minor rewording of this comment.
> +#include <math-type-macros-ldouble.h>
> +#include <math/w_ilogb_template.c>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9
2021-03-04 15:30 ` [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Paul E Murphy
@ 2021-03-16 16:20 ` Raphael M Zinsly
0 siblings, 0 replies; 6+ messages in thread
From: Raphael M Zinsly @ 2021-03-16 16:20 UTC (permalink / raw)
To: Paul E Murphy, libc-alpha; +Cc: pc, tuliom
On 04/03/2021 12:30, Paul E Murphy wrote:
>
>> diff --git a/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
>> b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
>> new file mode 100644
>> index 0000000000..215a00141d
>> --- /dev/null
>> +++ b/sysdeps/powerpc/powerpc64/le/fpu/w_ilogbl.c
>> @@ -0,0 +1,3 @@
>> +/* Skip the optimization for long double as it uses ibm128. */
>
> I would recommend rewording this as "... as ibm128 does not provide an
> optimized builtin".
>
> Though, I suspect you could use the double version of these built-ins by
> extracting the significant double of the ibm128, and testing/extracting
> it in a similar manner.
>
> Anyhow, this patch is OK with a minor rewording of this comment.
>
I fixed that and pushed as 56c81132ccc6f468fa4fc29c536db060e18e9d87, thanks!
Best Regards,
--
Raphael Moreira Zinsly
IBM
Linux on Power Toolchain
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 2/3] powerpc: Add optimized llogb* for POWER9
2021-03-04 15:00 ` [PATCH v3 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
@ 2021-03-18 16:51 ` Paul E Murphy
0 siblings, 0 replies; 6+ messages in thread
From: Paul E Murphy @ 2021-03-18 16:51 UTC (permalink / raw)
To: Raphael Moreira Zinsly, libc-alpha; +Cc: pc, tuliom
On 3/4/21 9:00 AM, Raphael Moreira Zinsly wrote:
> Changes since v2:
> - Removed the GCC version test and used the _GL_HAS_BUILTIN_ILOGB.
> - Removed the optimization from long double as it was converting
> ibm128 to float128.
>
> ---8<---
>
> The POWER9 builtins used to improve the ilogb* functions can be
> used in the llogb* functions as well.
> ---
This patch looks OK.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-18 16:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 15:00 [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Raphael Moreira Zinsly
2021-03-04 15:00 ` [PATCH v3 2/3] powerpc: Add optimized llogb* " Raphael Moreira Zinsly
2021-03-18 16:51 ` Paul E Murphy
2021-03-04 15:00 ` [PATCH v3 3/3] benchtests: Add ilogb* tests Raphael Moreira Zinsly
2021-03-04 15:30 ` [PATCH v3 1/3] powerpc: Add optimized ilogb* for POWER9 Paul E Murphy
2021-03-16 16:20 ` Raphael M Zinsly
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).