-/* fmaximum(). LoongArch version.
- Copyright (C) 2022-2025 Free Software Foundation, Inc.
+/* Helper macros for double variants of type generic functions of libm,
+ LoongArch version.
+ Copyright (C) 2025 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
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#define NO_MATH_REDIRECT
-#include <math.h>
-#include <libm-alias-double.h>
-#include <fpu_control.h>
-
-double
-__fmaximum (double x, double y)
-{
- int x_cond;
- int y_cond;
- asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
- asm volatile ("fclass.d \t%0, %1" : "=f" (y_cond) : "f" (y));
-
- if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN))
- return x * y;
- else
- {
- asm volatile ("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
- }
-}
-libm_alias_double (__fmaximum, fmaximum)
+#include_next <math-type-macros-double.h>
+#define INSN_FMT "d"
-/* fminimum(). LoongArch version.
- Copyright (C) 2022-2025 Free Software Foundation, Inc.
+/* Helper macros for float variants of type generic functions of libm,
+ LoongArch version.
+ Copyright (C) 2025 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
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#define NO_MATH_REDIRECT
-#include <math.h>
-#include <libm-alias-double.h>
-#include <fpu_control.h>
-
-double
-__fminimum (double x, double y)
-{
- int x_cond;
- int y_cond;
- asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
- asm volatile ("fclass.d \t%0, %1" : "=f" (y_cond) : "f" (y));
-
- if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN))
- return x * y;
- else
- {
- asm volatile ("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
- }
-}
-libm_alias_double (__fminimum, fminimum)
+#include_next <math-type-macros-float.h>
+#define INSN_FMT "s"
-/* fmaximumf(). LoongArch version.
- Copyright (C) 2022-2025 Free Software Foundation, Inc.
+/* Return maximum of X and Y. LoongArch version.
+ Copyright (C) 2025 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
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#define NO_MATH_REDIRECT
+#ifndef INSN_FMT
+#include_next <s_fmaximum_template.c>
+#else
+
#include <math.h>
-#include <libm-alias-float.h>
-#include <fpu_control.h>
-float
-__fmaximumf (float x, float y)
+FLOAT
+M_DECL_FUNC (__fmaximum) (FLOAT x, FLOAT y)
{
- int x_cond;
- int y_cond;
- asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
- asm volatile ("fclass.s \t%0, %1" : "=f" (y_cond) : "f" (y));
-
- if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN))
- return x * y;
- else
- {
- asm volatile ("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
- }
+ FLOAT a, b;
+ asm("fcmp.cor." INSN_FMT "\t$fcc0, %2, %2\n\t"
+ "fcmp.cor." INSN_FMT "\t$fcc1, %3, %3\n\t"
+ "fsel" "\t%0, %2, %3, $fcc0\n\t"
+ "fsel" "\t%1, %3, %2, $fcc1\n\t"
+ "fmax." INSN_FMT "\t%1, %0, %1"
+ : "=&f" (a), "=f" (b) : "f" (x), "f" (y) : "fcc0", "fcc1");
+ return b;
}
-libm_alias_float (__fmaximum, fmaximum)
+declare_mgen_alias (__fmaximum, fmaximum);
+
+#endif
-/* fminimumf(). LoongArch version.
- Copyright (C) 2022-2025 Free Software Foundation, Inc.
+/* Return minimum of X and Y. LoongArch version.
+ Copyright (C) 2025 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
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#define NO_MATH_REDIRECT
+#ifndef INSN_FMT
+#include_next <s_fminimum_template.c>
+#else
+
#include <math.h>
-#include <libm-alias-float.h>
-#include <fpu_control.h>
-float
-__fminimumf (float x, float y)
+FLOAT
+M_DECL_FUNC (__fminimum) (FLOAT x, FLOAT y)
{
- int x_cond;
- int y_cond;
- asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
- asm volatile ("fclass.s \t%0, %1" : "=f" (y_cond) : "f" (y));
-
- if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN))
- return x * y;
- else
- {
- asm volatile ("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
- return x;
- }
+ FLOAT a, b;
+ asm("fcmp.cor." INSN_FMT "\t$fcc0, %2, %2\n\t"
+ "fcmp.cor." INSN_FMT "\t$fcc1, %3, %3\n\t"
+ "fsel" "\t%0, %2, %3, $fcc0\n\t"
+ "fsel" "\t%1, %3, %2, $fcc1\n\t"
+ "fmin." INSN_FMT "\t%1, %0, %1"
+ : "=&f" (a), "=f" (b) : "f" (x), "f" (y) : "fcc0", "fcc1");
+ return b;
}
-libm_alias_float (__fminimum, fminimum)
+declare_mgen_alias (__fminimum, fminimum);
+
+#endif