[PATCH v2 1/4] riscv: Use builtins for the fmaximum and fminimum

Julian Zhu <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
Enable the fmax and fmin builtins for the fmaximum{_num} and fminimum{_num}.
The generic fmaximum{_num} and fminimum{_num} use them for ordered operands,
on rv64gc the double-precision functions drop from 21, 26, 23 and
29 instructions to 8, 8, 14 and 14.

fmax and fmin keep their own implementations, which need a signaling NaN
check because the instruction returns the number where C requires a
quiet NaN.  The headers live in rvd because without floating-point
registers GCC lowers the builtins to a call, which would recurse.

Signed-off-by: Julian Zhu <[email protected]>
---
 sysdeps/riscv/rvd/math-use-builtins-fmax.h | 15 +++++++++++++++
 sysdeps/riscv/rvd/math-use-builtins-fmin.h | 15 +++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 sysdeps/riscv/rvd/math-use-builtins-fmax.h
 create mode 100644 sysdeps/riscv/rvd/math-use-builtins-fmin.h

diff --git a/sysdeps/riscv/rvd/math-use-builtins-fmax.h b/sysdeps/riscv/rvd/math-use-builtins-fmax.h
new file mode 100644
index 0000000000..8865377475
--- /dev/null
+++ b/sysdeps/riscv/rvd/math-use-builtins-fmax.h
@@ -0,0 +1,15 @@
+/* This does not affect fmax and fmaxf, which have their own
+   implementations in rvd and rvf: the instruction returns the number for
+   a signaling NaN operand where C requires a quiet NaN, so they need an
+   explicit check.  Only the fmaximum and fminimum families and hypot use
+   these builtins.  */
+#if __GNUC_PREREQ (13, 0)
+# define USE_FMAX_BUILTIN 1
+# define USE_FMAXF_BUILTIN 1
+#else
+# define USE_FMAX_BUILTIN 0
+# define USE_FMAXF_BUILTIN 0
+#endif
+
+#define USE_FMAXL_BUILTIN 0
+#define USE_FMAXF128_BUILTIN 0
diff --git a/sysdeps/riscv/rvd/math-use-builtins-fmin.h b/sysdeps/riscv/rvd/math-use-builtins-fmin.h
new file mode 100644
index 0000000000..06e46bf7dd
--- /dev/null
+++ b/sysdeps/riscv/rvd/math-use-builtins-fmin.h
@@ -0,0 +1,15 @@
+/* This does not affect fmin and fminf, which have their own
+   implementations in rvd and rvf: the instruction returns the number for
+   a signaling NaN operand where C requires a quiet NaN, so they need an
+   explicit check.  Only the fmaximum and fminimum families and hypot use
+   these builtins.  */
+#if __GNUC_PREREQ (13, 0)
+# define USE_FMIN_BUILTIN 1
+# define USE_FMINF_BUILTIN 1
+#else
+# define USE_FMIN_BUILTIN 0
+# define USE_FMINF_BUILTIN 0
+#endif
+
+#define USE_FMINL_BUILTIN 0
+#define USE_FMINF128_BUILTIN 0
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.