RISCV:Add builtin for some riscv version function

Message ID CAAerABJtiuqVwHyh6wQX0MQ7T=1yPzYk7h5Bv_-11CppeXYLqQ@mail.gmail.com
State Failed CI
Headers
Series RISCV:Add builtin for some riscv version function |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch fail Patch failed to apply to master at the time it was sent
redhat-pt-bot/TryBot-32bit fail Patch series failed to apply

Commit Message

王博垚 Oct. 18, 2024, 9:48 a.m. UTC
  From: wangboyao

Some functions in glibc, particularly those in the math library, can be
more efficient when using the compiler’s built-in functions, especially in
cases where certain extensions (Zfa) are supported.

Signed-off-by: wangboyao
---
sysdeps/riscv/math-use-builtins-ceil.h | 4 ++++
sysdeps/riscv/math-use-builtins-ffs.h | 2 ++
sysdeps/riscv/math-use-builtins-floor.h | 4 ++++
sysdeps/riscv/math-use-builtins-nearbyint.h | 4 ++++
sysdeps/riscv/math-use-builtins-rint.h | 4 ++++
sysdeps/riscv/math-use-builtins-round.h | 4 ++++
sysdeps/riscv/math-use-builtins-roundeven.h | 4 ++++
sysdeps/riscv/math-use-builtins-trunc.h | 4 ++++
sysdeps/riscv/rv64/rvd/s_ceil.c | 5 +++++
sysdeps/riscv/rv64/rvd/s_floor.c | 5 +++++
sysdeps/riscv/rv64/rvd/s_nearbyint.c | 5 +++++
sysdeps/riscv/rv64/rvd/s_rint.c | 5 +++++
sysdeps/riscv/rv64/rvd/s_round.c | 5 +++++
sysdeps/riscv/rv64/rvd/s_roundeven.c | 5 +++++
sysdeps/riscv/rv64/rvd/s_trunc.c | 5 +++++
sysdeps/riscv/rvf/s_ceilf.c | 5 +++++
sysdeps/riscv/rvf/s_floorf.c | 5 +++++
sysdeps/riscv/rvf/s_nearbyintf.c | 5 +++++
sysdeps/riscv/rvf/s_rintf.c | 5 +++++
sysdeps/riscv/rvf/s_roundevenf.c | 5 +++++
sysdeps/riscv/rvf/s_roundf.c | 5 +++++
sysdeps/riscv/rvf/s_truncf.c | 5 +++++
22 files changed, 100 insertions(+)
create mode 100644 sysdeps/riscv/math-use-builtins-ceil.h
create mode 100644 sysdeps/riscv/math-use-builtins-ffs.h
create mode 100644 sysdeps/riscv/math-use-builtins-floor.h
create mode 100644 sysdeps/riscv/math-use-builtins-nearbyint.h
create mode 100644 sysdeps/riscv/math-use-builtins-rint.h
create mode 100644 sysdeps/riscv/math-use-builtins-round.h
create mode 100644 sysdeps/riscv/math-use-builtins-roundeven.h
create mode 100644 sysdeps/riscv/math-use-builtins-trunc.h
  

Comments

Carlos O'Donell Oct. 21, 2024, 1:18 p.m. UTC | #1
On 10/18/24 5:48 AM, 王博垚 wrote:
> From: wangboyao
> 
> Some functions in glibc, particularly those in the math library, can
> be more efficient when using the compiler’s built-in functions,
> especially in cases where certain extensions (Zfa) are supported.

This fails to apply. Thus it fails pre-commit CI. Please review the patch.

https://patchwork.sourceware.org/project/glibc/patch/CAAerABJtiuqVwHyh6wQX0MQ7T=1yPzYk7h5Bv_-11CppeXYLqQ@mail.gmail.com/
  

Patch

diff --git a/sysdeps/riscv/math-use-builtins-ceil.h
b/sysdeps/riscv/math-use-builtins-ceil.h
new file mode 100644
index 0000000000..17d6452e51
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-ceil.h
@@ -0,0 +1,4 @@ 
+#define USE_CEIL_BUILTIN 1
+#define USE_CEILF_BUILTIN 1
+#define USE_CEILL_BUILTIN 0
+#define USE_CEILF128_BUILTIN 0
diff --git a/sysdeps/riscv/math-use-builtins-ffs.h
b/sysdeps/riscv/math-use-builtins-ffs.h
new file mode 100644
index 0000000000..a83bb15414
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-ffs.h
@@ -0,0 +1,2 @@ 
+#define USE_FFS_BUILTIN 1
+#define USE_FFSLL_BUILTIN 1
diff --git a/sysdeps/riscv/math-use-builtins-floor.h
b/sysdeps/riscv/math-use-builtins-floor.h
new file mode 100644
index 0000000000..553c0674af
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-floor.h
@@ -0,0 +1,4 @@ 
+#define USE_FLOOR_BUILTIN 1
+#define USE_FLOORF_BUILTIN 1
+#define USE_FLOORL_BUILTIN 0
+#define USE_FLOORF128_BUILTIN 0
diff --git a/sysdeps/riscv/math-use-builtins-nearbyint.h
b/sysdeps/riscv/math-use-builtins-nearbyint.h
new file mode 100644
index 0000000000..a2590c920f
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-nearbyint.h
@@ -0,0 +1,4 @@ 
+#define USE_NEARBYINT_BUILTIN 1
+#define USE_NEARBYINTF_BUILTIN 1
+#define USE_NEARBYINTL_BUILTIN 0
+#define USE_NEARBYINTF128_BUILTIN 0
diff --git a/sysdeps/riscv/math-use-builtins-rint.h
b/sysdeps/riscv/math-use-builtins-rint.h
new file mode 100644
index 0000000000..45c3307692
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-rint.h
@@ -0,0 +1,4 @@ 
+#define USE_RINT_BUILTIN 1
+#define USE_RINTF_BUILTIN 1
+#define USE_RINTL_BUILTIN 0
+#define USE_RINTF128_BUILTIN 0
diff --git a/sysdeps/riscv/math-use-builtins-round.h
b/sysdeps/riscv/math-use-builtins-round.h
new file mode 100644
index 0000000000..f6083d7d0a
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-round.h
@@ -0,0 +1,4 @@ 
+#define USE_ROUND_BUILTIN 1
+#define USE_ROUNDF_BUILTIN 1
+#define USE_ROUNDL_BUILTIN 0
+#define USE_ROUNDF128_BUILTIN 0
diff --git a/sysdeps/riscv/math-use-builtins-roundeven.h
b/sysdeps/riscv/math-use-builtins-roundeven.h
new file mode 100644
index 0000000000..b7f51730d6
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-roundeven.h
@@ -0,0 +1,4 @@ 
+#define USE_ROUNDEVEN_BUILTIN 1
+#define USE_ROUNDEVENF_BUILTIN 1
+#define USE_ROUNDEVENL_BUILTIN 0
+#define USE_ROUNDEVENF128_BUILTIN 0
diff --git a/sysdeps/riscv/math-use-builtins-trunc.h
b/sysdeps/riscv/math-use-builtins-trunc.h
new file mode 100644
index 0000000000..4fc6da42b6
--- /dev/null
+++ b/sysdeps/riscv/math-use-builtins-trunc.h
@@ -0,0 +1,4 @@ 
+#define USE_TRUNC_BUILTIN 1
+#define USE_TRUNCF_BUILTIN 1
+#define USE_TRUNCL_BUILTIN 0
+#define USE_TRUNCF128_BUILTIN 0
diff --git a/sysdeps/riscv/rv64/rvd/s_ceil.c
b/sysdeps/riscv/rv64/rvd/s_ceil.c
index dfa853f7fc..8651739959 100644
--- a/sysdeps/riscv/rv64/rvd/s_ceil.c
+++ b/sysdeps/riscv/rv64/rvd/s_ceil.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

double
__ceil (double x)
{
+#if USE_CEIL_BUILTIN
+ return __builtin_ceil (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +52,7 @@  __ceil (double x)
}

return x;
+#endif /* ! USE_CEIL_BUILTIN */
}

libm_alias_double (__ceil, ceil)
diff --git a/sysdeps/riscv/rv64/rvd/s_floor.c
b/sysdeps/riscv/rv64/rvd/s_floor.c
index f294651147..957d4792ff 100644
--- a/sysdeps/riscv/rv64/rvd/s_floor.c
+++ b/sysdeps/riscv/rv64/rvd/s_floor.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

double
__floor (double x)
{
+#if USE_FLOOR_BUILTIN
+ return __builtin_floor (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +52,7 @@  __floor (double x)
}

return x;
+#endif /* ! USE_FLOOR_BUILTIN */
}

libm_alias_double (__floor, floor)
diff --git a/sysdeps/riscv/rv64/rvd/s_nearbyint.c
b/sysdeps/riscv/rv64/rvd/s_nearbyint.c
index ddc512d460..b55d3d0f2f 100644
--- a/sysdeps/riscv/rv64/rvd/s_nearbyint.c
+++ b/sysdeps/riscv/rv64/rvd/s_nearbyint.c
@@ -20,10 +20,14 @@ 
#include
#include
#include
+#include

double
__nearbyint (double x)
{
+#if USE_NEARBYINT_BUILTIN
+ return __builtin_nearbyint (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -47,6 +51,7 @@  __nearbyint (double x)
}

return x;
+#endif /* ! USE_NEARBYINT_BUILTIN */
}

libm_alias_double (__nearbyint, nearbyint)
diff --git a/sysdeps/riscv/rv64/rvd/s_rint.c
b/sysdeps/riscv/rv64/rvd/s_rint.c
index 45bea32671..7c4d23f32c 100644
--- a/sysdeps/riscv/rv64/rvd/s_rint.c
+++ b/sysdeps/riscv/rv64/rvd/s_rint.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

double
__rint (double x)
{
+#if USE_RINT_BUILTIN
+ return __builtin_rint (x);
+#else
bool nan;
double mag;

@@ -48,6 +52,7 @@  __rint (double x)
}

return x;
+#endif /* ! USE_RINT_BUILTIN */
}

libm_alias_double (__rint, rint)
diff --git a/sysdeps/riscv/rv64/rvd/s_round.c
b/sysdeps/riscv/rv64/rvd/s_round.c
index bd01fcc8c9..0964f94de6 100644
--- a/sysdeps/riscv/rv64/rvd/s_round.c
+++ b/sysdeps/riscv/rv64/rvd/s_round.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

double
__round (double x)
{
+#if USE_ROUND_BUILTIN
+ return __builtin_round (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +52,7 @@  __round (double x)
}

return x;
+#endif /* ! USE_ROUND_BUILTIN */
}

libm_alias_double (__round, round)
diff --git a/sysdeps/riscv/rv64/rvd/s_roundeven.c
b/sysdeps/riscv/rv64/rvd/s_roundeven.c
index 108c7dc970..ea888d7555 100644
--- a/sysdeps/riscv/rv64/rvd/s_roundeven.c
+++ b/sysdeps/riscv/rv64/rvd/s_roundeven.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

double
__roundeven (double x)
{
+#if USE_ROUNDEVEN_BUILTIN
+ return __builtin_roundeven (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +52,7 @@  __roundeven (double x)
}

return x;
+#endif /* ! USE_ROUNDEVEN_BUILTIN */
}

libm_alias_double (__roundeven, roundeven)
diff --git a/sysdeps/riscv/rv64/rvd/s_trunc.c
b/sysdeps/riscv/rv64/rvd/s_trunc.c
index 779c7d26b3..82c6196ef0 100644
--- a/sysdeps/riscv/rv64/rvd/s_trunc.c
+++ b/sysdeps/riscv/rv64/rvd/s_trunc.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

double
__trunc (double x)
{
+ #if USE_TRUNC_BUILTIN
+ return __builtin_trunc (x);
+ #else
int flags = riscv_getflags ();
bool nan = isnan (x);
double mag = fabs (x);
@@ -48,6 +52,7 @@  __trunc (double x)
}

return x;
+ #endif /* ! USE_TRUNC_BUILTIN */
}

libm_alias_double (__trunc, trunc)
diff --git a/sysdeps/riscv/rvf/s_ceilf.c b/sysdeps/riscv/rvf/s_ceilf.c
index d19f17e16b..ab49a8dfbd 100644
--- a/sysdeps/riscv/rvf/s_ceilf.c
+++ b/sysdeps/riscv/rvf/s_ceilf.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

float
__ceilf (float x)
{
+#if USE_CEILF_BUILTIN
+ return __builtin_ceilf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +52,7 @@  __ceilf (float x)
}

return x;
+#endif /* ! USE_CEILF_BUILTIN */
}

libm_alias_float (__ceil, ceil)
diff --git a/sysdeps/riscv/rvf/s_floorf.c b/sysdeps/riscv/rvf/s_floorf.c
index efe104c7e0..daf708fe56 100644
--- a/sysdeps/riscv/rvf/s_floorf.c
+++ b/sysdeps/riscv/rvf/s_floorf.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

float
__floorf (float x)
{
+#if USE_FLOORF_BUILTIN
+ return __builtin_floorf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +52,7 @@  __floorf (float x)
}

return x;
+#endif /* ! USE_FLOORF_BUILTIN */
}

libm_alias_float (__floor, floor)
diff --git a/sysdeps/riscv/rvf/s_nearbyintf.c
b/sysdeps/riscv/rvf/s_nearbyintf.c
index 4abaaa2551..487ca659da 100644
--- a/sysdeps/riscv/rvf/s_nearbyintf.c
+++ b/sysdeps/riscv/rvf/s_nearbyintf.c
@@ -20,10 +20,14 @@ 
#include
#include
#include
+#include

float
__nearbyintf (float x)
{
+#if USE_NEARBYINTF_BUILTIN
+ return __builtin_nearbyintf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -47,6 +51,7 @@  __nearbyintf (float x)
}

return x;
+#endif /* ! USE_NEARBYINT_BUILTIN */
}

libm_alias_float (__nearbyint, nearbyint)
diff --git a/sysdeps/riscv/rvf/s_rintf.c b/sysdeps/riscv/rvf/s_rintf.c
index f70d1b3db3..a82629a015 100644
--- a/sysdeps/riscv/rvf/s_rintf.c
+++ b/sysdeps/riscv/rvf/s_rintf.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

float
__rintf (float x)
{
+#if USE_RINTF_BUILTIN
+ return __builtin_rintf (x);
+#else
bool nan;
float mag;

@@ -48,6 +52,7 @@  __rintf (float x)
}

return x;
+#endif /* ! USE_RINTF_BUILTIN */
}

libm_alias_float (__rint, rint)
diff --git a/sysdeps/riscv/rvf/s_roundevenf.c
b/sysdeps/riscv/rvf/s_roundevenf.c
index 99018c050e..813d11f92d 100644
--- a/sysdeps/riscv/rvf/s_roundevenf.c
+++ b/sysdeps/riscv/rvf/s_roundevenf.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

float
__roundevenf (float x)
{
+#if USE_ROUNDEVENF_BUILTIN
+ return __builtin_roundevenf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +52,7 @@  __roundevenf (float x)
}

return x;
+#endif /* ! USE_ROUNDEVENF_BUILTIN */
}

libm_alias_float (__roundeven, roundeven)
diff --git a/sysdeps/riscv/rvf/s_roundf.c b/sysdeps/riscv/rvf/s_roundf.c
index 735e7e9de9..db299e0a41 100644
--- a/sysdeps/riscv/rvf/s_roundf.c
+++ b/sysdeps/riscv/rvf/s_roundf.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

float
__roundf (float x)
{
+#if USE_ROUNDF_BUILTIN
+ return __builtin_roundf (x);
+#else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +52,7 @@  __roundf (float x)
}

return x;
+#endif /* ! USE_ROUNDF_BUILTIN */
}

libm_alias_float (__round, round)
diff --git a/sysdeps/riscv/rvf/s_truncf.c b/sysdeps/riscv/rvf/s_truncf.c
index 0774f7cbd6..e2d99b20a8 100644
--- a/sysdeps/riscv/rvf/s_truncf.c
+++ b/sysdeps/riscv/rvf/s_truncf.c
@@ -21,10 +21,14 @@ 
#include
#include
#include
+#include

float
__truncf (float x)
{
+ #if USE_TRUNCF_BUILTIN
+ return __builtin_truncf (x);
+ #else
int flags = riscv_getflags ();
bool nan = isnan (x);
float mag = fabsf (x);
@@ -48,6 +52,7 @@  __truncf (float x)
}

return x;
+ #endif /* ! USE_TRUNCF_BUILTIN */
}

libm_alias_float (__trunc, trunc)