diff mbox series

[v2] ARC:fpu: add extra capability check before use of sqrt and fma builtins

Message ID 20230117121223.2635-1-kozlov@synopsys.com
State New
Headers show
Series [v2] ARC:fpu: add extra capability check before use of sqrt and fma builtins | expand

Commit Message

develop--- via Libc-alpha Jan. 17, 2023, 12:12 p.m. UTC
From: Pavel Kozlov <pavel.kozlov@synopsys.com>

Add extra check for compiler definitions to ensure that compiler provides
sqrt and fma hw fpu instructions else use software implementation.

As divide/sqrt and FMA hw support from CPU side is optional,
the compiler can be configured by options to generate hw FPU instructions,
but without use of FDDIV, FDSQRT, FSDIV, FSSQRT, FDMADD and FSMADD
instructions. In this case __builtin_sqrt and __builtin_sqrtf provided by
compiler can't be used inside the glibc code, as these builtins are used
in implementations of sqrt() and sqrtf() functions but at the same time
these builtins unfold to sqrt() and sqrtf(). So it is possible to receive
code like that:

0001c4b4 <__ieee754_sqrtf>:
   1c4b4:    0001 0000      b     0         ;1c4b4 <__ieee754_sqrtf>

The same is also true for __builtin_fma and __builtin_fmaf.

---
Changes in v2:
 - Fixed macros definitions for FMA

 sysdeps/arc/fpu/math-use-builtins-fma.h  | 14 ++++++++++++--
 sysdeps/arc/fpu/math-use-builtins-sqrt.h | 14 ++++++++++++--
 2 files changed, 24 insertions(+), 4 deletions(-)

Comments

Adhemerval Zanella Netto Jan. 17, 2023, 2:31 p.m. UTC | #1
On 17/01/23 09:12, Pavel.Kozlov--- via Libc-alpha wrote:
> From: Pavel Kozlov <pavel.kozlov@synopsys.com>
> 
> Add extra check for compiler definitions to ensure that compiler provides
> sqrt and fma hw fpu instructions else use software implementation.
> 
> As divide/sqrt and FMA hw support from CPU side is optional,
> the compiler can be configured by options to generate hw FPU instructions,
> but without use of FDDIV, FDSQRT, FSDIV, FSSQRT, FDMADD and FSMADD
> instructions. In this case __builtin_sqrt and __builtin_sqrtf provided by
> compiler can't be used inside the glibc code, as these builtins are used
> in implementations of sqrt() and sqrtf() functions but at the same time
> these builtins unfold to sqrt() and sqrtf(). So it is possible to receive
> code like that:
> 
> 0001c4b4 <__ieee754_sqrtf>:
>    1c4b4:    0001 0000      b     0         ;1c4b4 <__ieee754_sqrtf>
> 
> The same is also true for __builtin_fma and __builtin_fmaf.

LGTM, thanks.  You might need to check with Carlos O'Donnel to see it you
could install this for 2.36.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> 
> ---
> Changes in v2:
>  - Fixed macros definitions for FMA
> 
>  sysdeps/arc/fpu/math-use-builtins-fma.h  | 14 ++++++++++++--
>  sysdeps/arc/fpu/math-use-builtins-sqrt.h | 14 ++++++++++++--
>  2 files changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/sysdeps/arc/fpu/math-use-builtins-fma.h b/sysdeps/arc/fpu/math-use-builtins-fma.h
> index eede75aa41be..2acd8113ce2c 100644
> --- a/sysdeps/arc/fpu/math-use-builtins-fma.h
> +++ b/sysdeps/arc/fpu/math-use-builtins-fma.h
> @@ -1,4 +1,14 @@
> -#define USE_FMA_BUILTIN 1
> -#define USE_FMAF_BUILTIN 1
> +#if defined __ARC_FPU_DP_FMA__
> +# define USE_FMA_BUILTIN 1
> +#else
> +# define USE_FMA_BUILTIN 0
> +#endif
> +
> +#if defined __ARC_FPU_SP_FMA__
> +# define USE_FMAF_BUILTIN 1
> +#else
> +# define USE_FMAF_BUILTIN 0
> +#endif
> +
>  #define USE_FMAL_BUILTIN 0
>  #define USE_FMAF128_BUILTIN 0
> diff --git a/sysdeps/arc/fpu/math-use-builtins-sqrt.h b/sysdeps/arc/fpu/math-use-builtins-sqrt.h
> index e94c915ba66a..a449bc609295 100644
> --- a/sysdeps/arc/fpu/math-use-builtins-sqrt.h
> +++ b/sysdeps/arc/fpu/math-use-builtins-sqrt.h
> @@ -1,4 +1,14 @@
> -#define USE_SQRT_BUILTIN 1
> -#define USE_SQRTF_BUILTIN 1
> +#if defined __ARC_FPU_DP_DIV__
> +# define USE_SQRT_BUILTIN 1
> +#else
> +# define USE_SQRT_BUILTIN 0
> +#endif
> +
> +#if defined __ARC_FPU_SP_DIV__
> +# define USE_SQRTF_BUILTIN 1
> +#else
> +# define USE_SQRTF_BUILTIN 0
> +#endif
> +
>  #define USE_SQRTL_BUILTIN 0
>  #define USE_SQRTF128_BUILTIN 0
diff mbox series

Patch

diff --git a/sysdeps/arc/fpu/math-use-builtins-fma.h b/sysdeps/arc/fpu/math-use-builtins-fma.h
index eede75aa41be..2acd8113ce2c 100644
--- a/sysdeps/arc/fpu/math-use-builtins-fma.h
+++ b/sysdeps/arc/fpu/math-use-builtins-fma.h
@@ -1,4 +1,14 @@ 
-#define USE_FMA_BUILTIN 1
-#define USE_FMAF_BUILTIN 1
+#if defined __ARC_FPU_DP_FMA__
+# define USE_FMA_BUILTIN 1
+#else
+# define USE_FMA_BUILTIN 0
+#endif
+
+#if defined __ARC_FPU_SP_FMA__
+# define USE_FMAF_BUILTIN 1
+#else
+# define USE_FMAF_BUILTIN 0
+#endif
+
 #define USE_FMAL_BUILTIN 0
 #define USE_FMAF128_BUILTIN 0
diff --git a/sysdeps/arc/fpu/math-use-builtins-sqrt.h b/sysdeps/arc/fpu/math-use-builtins-sqrt.h
index e94c915ba66a..a449bc609295 100644
--- a/sysdeps/arc/fpu/math-use-builtins-sqrt.h
+++ b/sysdeps/arc/fpu/math-use-builtins-sqrt.h
@@ -1,4 +1,14 @@ 
-#define USE_SQRT_BUILTIN 1
-#define USE_SQRTF_BUILTIN 1
+#if defined __ARC_FPU_DP_DIV__
+# define USE_SQRT_BUILTIN 1
+#else
+# define USE_SQRT_BUILTIN 0
+#endif
+
+#if defined __ARC_FPU_SP_DIV__
+# define USE_SQRTF_BUILTIN 1
+#else
+# define USE_SQRTF_BUILTIN 0
+#endif
+
 #define USE_SQRTL_BUILTIN 0
 #define USE_SQRTF128_BUILTIN 0