new file mode 100644
@@ -0,0 +1,44 @@
+/* Return maximum number 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_num (double x, double y)
+{
+ double res;
+
+ if (__glibc_unlikely((_FCLASS (x) & _FCLASS_NAN) && !(_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmax.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else if (__glibc_unlikely(!(_FCLASS (x) & _FCLASS_NAN) && (_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmax.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else
+ {
+ asm volatile ("fmax.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_double (__fmaximum_num, fmaximum_num)
new file mode 100644
@@ -0,0 +1,44 @@
+/* Return minimum number 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_num (double x, double y)
+{
+ double res;
+
+ if (__glibc_unlikely((_FCLASS (x) & _FCLASS_NAN) && !(_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmin.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else if (__glibc_unlikely(!(_FCLASS (x) & _FCLASS_NAN) && (_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmin.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else
+ {
+ asm volatile ("fmin.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_double (__fminimum_num, fminimum_num)
new file mode 100644
@@ -0,0 +1,44 @@
+/* Return maximum number 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
+__fmaximum_numf (float x, float y)
+{
+ float res;
+
+ if (__glibc_unlikely((_FCLASS (x) & _FCLASS_NAN) && !(_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmax.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else if (__glibc_unlikely(!(_FCLASS (x) & _FCLASS_NAN) && (_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmax.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else
+ {
+ asm volatile ("fmax.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_float (__fmaximum_num, fmaximum_num)
new file mode 100644
@@ -0,0 +1,44 @@
+/* Return minimum number 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
+__fminimum_numf (float x, float y)
+{
+ float res;
+
+ if (__glibc_unlikely((_FCLASS (x) & _FCLASS_NAN) && !(_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmin.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else if (__glibc_unlikely(!(_FCLASS (x) & _FCLASS_NAN) && (_FCLASS (y) & _FCLASS_NAN)))
+ {
+ asm volatile ("fmin.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+ else
+ {
+ asm volatile ("fmin.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y));
+ return res;
+ }
+}
+libm_alias_float (__fminimum_num, fminimum_num)
Implemented `fmaximum_num{f}` and `fminimum_num{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_num.c | 44 +++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_fminimum_num.c | 44 +++++++++++++++++++++++++++++ sysdeps/riscv/rvf/s_fmaximum_numf.c | 44 +++++++++++++++++++++++++++++ sysdeps/riscv/rvf/s_fminimum_numf.c | 44 +++++++++++++++++++++++++++++ 4 files changed, 176 insertions(+) create mode 100644 sysdeps/riscv/rvd/s_fmaximum_num.c create mode 100644 sysdeps/riscv/rvd/s_fminimum_num.c create mode 100644 sysdeps/riscv/rvf/s_fmaximum_numf.c create mode 100644 sysdeps/riscv/rvf/s_fminimum_numf.c