new file mode 100644
@@ -0,0 +1,36 @@
+/* Return maximum of X and Y. RISC-V version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <fenv_private.h>
+#include <libm-alias-double.h>
+
+double
+__fmaximum (double x, double y)
+{
+ double res;
+
+ if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN))
+ return x * y;
+ else
+ {
+ asm volatile ("fmax.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_double (__fmaximum, fmaximum)
new file mode 100644
@@ -0,0 +1,36 @@
+/* Return minimum of X and Y. RISC-V version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <fenv_private.h>
+#include <libm-alias-double.h>
+
+double
+__fminimum (double x, double y)
+{
+ double res;
+
+ if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN))
+ return x * y;
+ else
+ {
+ asm volatile ("fmin.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_double (__fminimum, fminimum)
new file mode 100644
@@ -0,0 +1,36 @@
+/* Return maximum of X and Y. RISC-V version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <fenv_private.h>
+#include <libm-alias-float.h>
+
+float
+__fmaximumf (float x, float y)
+{
+ float res;
+
+ if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN))
+ return x * y;
+ else
+ {
+ asm volatile ("fmax.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_float (__fmaximum, fmaximum)
new file mode 100644
@@ -0,0 +1,36 @@
+/* Return minimum of X and Y. RISC-V version.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <math.h>
+#include <fenv_private.h>
+#include <libm-alias-float.h>
+
+float
+__fminimumf (float x, float y)
+{
+ float res;
+
+ if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN))
+ return x * y;
+ else
+ {
+ asm volatile ("fmin.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_float (__fminimum, fminimum)
Implemented `fmaximum{f}` and `fminimum{f}` using hard-float `fclass.fmt` and `f{max,min}.fmt` instructions to generate more simplified code. Signed-off-by: Julian Zhu <jz531210@gmail.com> --- sysdeps/riscv/rvd/s_fmaximum.c | 36 +++++++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_fminimum.c | 36 +++++++++++++++++++++++++++++++++ sysdeps/riscv/rvf/s_fmaximumf.c | 36 +++++++++++++++++++++++++++++++++ sysdeps/riscv/rvf/s_fminimumf.c | 36 +++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 sysdeps/riscv/rvd/s_fmaximum.c create mode 100644 sysdeps/riscv/rvd/s_fminimum.c create mode 100644 sysdeps/riscv/rvf/s_fmaximumf.c create mode 100644 sysdeps/riscv/rvf/s_fminimumf.c