From: Xiaolin Tang <tangxiaolin@loongson.cn>
To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org,
caiyinyu@loongson.cn, i.swmail@xen0n.name
Cc: xuchenghua@loongson.cn, Xiaolin Tang <tangxiaolin@loongson.cn>
Subject: [PATCH 1/1] LoongArch: Hard Float Support Of Math Functions.
Date: Thu, 3 Nov 2022 20:14:33 +0800 [thread overview]
Message-ID: <20221103121433.2909287-2-tangxiaolin@loongson.cn> (raw)
In-Reply-To: <20221103121433.2909287-1-tangxiaolin@loongson.cn>
This patch contains hardware floating-point support of math
fuctions for the LoongArch ISA. LoongArch ISA has many hardware
floating-point instructions that can be used in the corresponding
math functions.
instructions functions
fma.{s/d} __fma{f/ }
f{max/min}.{s/d}, fclass.{s/d} __f{max/min}i{mum/mum_mum}{f/ }
f{maxa/mina}.{s/d} __f{max,min}mag{f/ }
f{maxa/mina}.{s/d}, fclass.{s/d __f{max/min}imum{_mag/_mag_num}{f/ }
fcopysign.{s/d __copysign{f/ }
frint.{s/d} __{ /l/ll}rint{f/ }
fscaleb.{s/d}, fclass.{s/d} __scalbn{f/ }, __ieee754__scalb{f/ }
flogb.{s/d}, fclass.{s/d} __logb{f/ }, __ieee754_ilogb{f/ }
fclass.{s/d} __fpclassify{f/ }, __issignaling{f/ }
* sysdeps/loongarch/fpu/e_ilogb.c: New file.
* sysdeps/loongarch/fpu/e_ilogbf.c: Likewise.
* sysdeps/loongarch/fpu/e_scalb.c: Likewise.
* sysdeps/loongarch/fpu/e_scalbf.c: Likewise.
* sysdeps/loongarch/fpu/math-use-builtins-fma.h: Likewise.
* sysdeps/loongarch/fpu/s_copysign.c: Likewise.
* sysdeps/loongarch/fpu/s_copysignf.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximum.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximum_mag.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximum_mag_num.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximum_magf.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximum_num.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximum_numf.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaximumf.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaxmag.c: Likewise.
* sysdeps/loongarch/fpu/s_fmaxmagf.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum_mag.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum_mag_num.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum_mag_numf.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum_magf.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum_num.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum_numf.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimumf.c: Likewise.
* sysdeps/loongarch/fpu/s_fminmag.c: Likewise.
* sysdeps/loongarch/fpu/s_fminmagf.c: Likewise.
* sysdeps/loongarch/fpu/s_fpclassify.c: Likewise.
* sysdeps/loongarch/fpu/s_fpclassifyf.c: Likewise.
* sysdeps/loongarch/fpu/s_issignaling.c: Likewise.
* sysdeps/loongarch/fpu/s_issignalingf.c: Likewise.
* sysdeps/loongarch/fpu/s_llrint.c: Likewise.
* sysdeps/loongarch/fpu/s_llrintf.c: Likewise.
* sysdeps/loongarch/fpu/s_logb.c: Likewise.
* sysdeps/loongarch/fpu/s_logbf.c: Likewise.
* sysdeps/loongarch/fpu/s_lrint.c: Likewise.
* sysdeps/loongarch/fpu/s_lrintf.c: Likewise.
* sysdeps/loongarch/fpu/s_rint.c: Likewise.
* sysdeps/loongarch/fpu/s_rintf.c: Likewise.
* sysdeps/loongarch/fpu/s_scalbn.c: Likewise.
* sysdeps/loongarch/fpu/s_scalbnf.c: Likewise.
* sysdeps/loongarch/fpu_control.h: Add _FCLASS_* macro.
---
sysdeps/loongarch/fpu/e_ilogb.c | 37 +++++++++++
sysdeps/loongarch/fpu/e_ilogbf.c | 37 +++++++++++
sysdeps/loongarch/fpu/e_scalb.c | 61 +++++++++++++++++++
sysdeps/loongarch/fpu/e_scalbf.c | 61 +++++++++++++++++++
sysdeps/loongarch/fpu/math-use-builtins-fma.h | 4 ++
sysdeps/loongarch/fpu/s_copysign.c | 29 +++++++++
sysdeps/loongarch/fpu/s_copysignf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_fmaximum.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_mag.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_mag_num.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_magf.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_num.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_numf.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fmaximumf.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fmaxmag.c | 29 +++++++++
sysdeps/loongarch/fpu/s_fmaxmagf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_fminimum.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fminimum_mag.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fminimum_mag_num.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fminimum_mag_numf.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fminimum_magf.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fminimum_num.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fminimum_numf.c | 47 ++++++++++++++
sysdeps/loongarch/fpu/s_fminimumf.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fminmag.c | 29 +++++++++
sysdeps/loongarch/fpu/s_fminmagf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_fpclassify.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_fpclassifyf.c | 38 ++++++++++++
sysdeps/loongarch/fpu/s_issignaling.c | 29 +++++++++
sysdeps/loongarch/fpu/s_issignalingf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_llrint.c | 29 +++++++++
sysdeps/loongarch/fpu/s_llrintf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_logb.c | 30 +++++++++
sysdeps/loongarch/fpu/s_logbf.c | 30 +++++++++
sysdeps/loongarch/fpu/s_lrint.c | 29 +++++++++
sysdeps/loongarch/fpu/s_lrintf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_rint.c | 29 +++++++++
sysdeps/loongarch/fpu/s_rintf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_scalbn.c | 29 +++++++++
sysdeps/loongarch/fpu/s_scalbnf.c | 29 +++++++++
sysdeps/loongarch/fpu_control.h | 17 ++++++
42 files changed, 1497 insertions(+)
create mode 100644 sysdeps/loongarch/fpu/e_ilogb.c
create mode 100644 sysdeps/loongarch/fpu/e_ilogbf.c
create mode 100644 sysdeps/loongarch/fpu/e_scalb.c
create mode 100644 sysdeps/loongarch/fpu/e_scalbf.c
create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-fma.h
create mode 100644 sysdeps/loongarch/fpu/s_copysign.c
create mode 100644 sysdeps/loongarch/fpu/s_copysignf.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_mag.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_mag_num.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_magf.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_num.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_numf.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximumf.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaxmag.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaxmagf.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum_mag.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum_mag_num.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum_mag_numf.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum_magf.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum_num.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum_numf.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimumf.c
create mode 100644 sysdeps/loongarch/fpu/s_fminmag.c
create mode 100644 sysdeps/loongarch/fpu/s_fminmagf.c
create mode 100644 sysdeps/loongarch/fpu/s_fpclassify.c
create mode 100644 sysdeps/loongarch/fpu/s_fpclassifyf.c
create mode 100644 sysdeps/loongarch/fpu/s_issignaling.c
create mode 100644 sysdeps/loongarch/fpu/s_issignalingf.c
create mode 100644 sysdeps/loongarch/fpu/s_llrint.c
create mode 100644 sysdeps/loongarch/fpu/s_llrintf.c
create mode 100644 sysdeps/loongarch/fpu/s_logb.c
create mode 100644 sysdeps/loongarch/fpu/s_logbf.c
create mode 100644 sysdeps/loongarch/fpu/s_lrint.c
create mode 100644 sysdeps/loongarch/fpu/s_lrintf.c
create mode 100644 sysdeps/loongarch/fpu/s_rint.c
create mode 100644 sysdeps/loongarch/fpu/s_rintf.c
create mode 100644 sysdeps/loongarch/fpu/s_scalbn.c
create mode 100644 sysdeps/loongarch/fpu/s_scalbnf.c
diff --git a/sysdeps/loongarch/fpu/e_ilogb.c b/sysdeps/loongarch/fpu/e_ilogb.c
new file mode 100644
index 0000000000..27a7dace29
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_ilogb.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <fpu_control.h>
+
+int
+__ieee754_ilogb (double x)
+{
+ int x_cond;
+ asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
+
+ if (x_cond & _FCLASS_ZERO )
+ return FP_ILOGB0;
+ if (x_cond & ( _FCLASS_NAN | _FCLASS_INF))
+ return FP_ILOGBNAN;
+
+ asm volatile("fabs.d \t%0, %1" : "=f" (x) : "f" (x));
+ asm volatile("flogb.d \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
diff --git a/sysdeps/loongarch/fpu/e_ilogbf.c b/sysdeps/loongarch/fpu/e_ilogbf.c
new file mode 100644
index 0000000000..ed5ac99b6b
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_ilogbf.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <fpu_control.h>
+
+int
+__ieee754_ilogbf (float x)
+{
+ int x_cond;
+ asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
+
+ if (x_cond & _FCLASS_ZERO )
+ return FP_ILOGB0;
+ if (x_cond & ( _FCLASS_NAN | _FCLASS_INF))
+ return FP_ILOGBNAN;
+
+ asm volatile("fabs.s \t%0, %1" : "=f" (x) : "f" (x));
+ asm volatile("flogb.s \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
diff --git a/sysdeps/loongarch/fpu/e_scalb.c b/sysdeps/loongarch/fpu/e_scalb.c
new file mode 100644
index 0000000000..e7fcfe86d0
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_scalb.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-finite.h>
+#include <fpu_control.h>
+#include <float.h>
+
+double
+__ieee754_scalb (double x, double fn)
+{
+ int x_cond;
+ int fn_cond;
+ asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
+ asm volatile ("fclass.d \t%0, %1" : "=f" (fn_cond) : "f" (fn));
+
+ if (__builtin_expect(( x_cond | fn_cond) & _FCLASS_NAN, 0))
+ return x * fn;
+ else if (__builtin_expect(fn_cond & _FCLASS_INF, 0))
+ {
+ if (!(fn_cond & _FCLASS_MINF))
+ return x * fn;
+ else
+ return x / -fn;
+ }
+ else if (__builtin_expect(-DBL_MAX < fn && fn < DBL_MAX, 1))
+ {
+ long y1;
+ double y;
+
+ asm volatile("frint.d \t%0, %1" : "=f" (y) : "f" (fn));
+ asm volatile("ftintrz.l.d \t%0, %1" : "=f" (y) : "f" (y));
+ asm volatile("movfr2gr.d \t%0, %1" : "=r" (y1) : "f" (y));
+
+ if (y1 != fn )
+ return (x - x) / (x - x);
+
+ asm volatile("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ }
+ else
+ asm volatile("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (fn));
+
+ return x;
+}
+libm_alias_finite (__ieee754_scalb, __scalb)
diff --git a/sysdeps/loongarch/fpu/e_scalbf.c b/sysdeps/loongarch/fpu/e_scalbf.c
new file mode 100644
index 0000000000..085a5a63bc
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_scalbf.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-finite.h>
+#include <fpu_control.h>
+#include <float.h>
+
+float
+__ieee754_scalbf (float x, float fn)
+{
+ int x_cond;
+ int fn_cond;
+ asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
+ asm volatile ("fclass.s \t%0, %1" : "=f" (fn_cond) : "f" (fn));
+
+ if (__builtin_expect(( x_cond | fn_cond) & _FCLASS_NAN, 0))
+ return x * fn;
+ else if (__builtin_expect(fn_cond & _FCLASS_INF, 0))
+ {
+ if (!(fn_cond & _FCLASS_MINF))
+ return x * fn;
+ else
+ return x / -fn;
+ }
+ else if (__builtin_expect(-FLT_MAX < fn && fn < FLT_MAX, 1))
+ {
+ int y1;
+ float y;
+
+ asm volatile("frint.s \t%0, %1" : "=f" (y) : "f" (fn));
+ asm volatile("ftintrz.w.s \t%0, %1" : "=f" (y) : "f" (y));
+ asm volatile("movfr2gr.s \t%0, %1" : "=r" (y1) : "f" (y));
+
+ if (y1 != fn )
+ return (x - x) / (x - x);
+
+ asm volatile("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ }
+ else
+ asm volatile("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (fn));
+
+ return x;
+}
+libm_alias_finite (__ieee754_scalb, __scalb)
diff --git a/sysdeps/loongarch/fpu/math-use-builtins-fma.h b/sysdeps/loongarch/fpu/math-use-builtins-fma.h
new file mode 100644
index 0000000000..eede75aa41
--- /dev/null
+++ b/sysdeps/loongarch/fpu/math-use-builtins-fma.h
@@ -0,0 +1,4 @@
+#define USE_FMA_BUILTIN 1
+#define USE_FMAF_BUILTIN 1
+#define USE_FMAL_BUILTIN 0
+#define USE_FMAF128_BUILTIN 0
diff --git a/sysdeps/loongarch/fpu/s_copysign.c b/sysdeps/loongarch/fpu/s_copysign.c
new file mode 100644
index 0000000000..e850227549
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_copysign.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__copysign (double x, double y)
+{
+ asm volatile("fcopysign.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__copysign, copysign)
diff --git a/sysdeps/loongarch/fpu/s_copysignf.c b/sysdeps/loongarch/fpu/s_copysignf.c
new file mode 100644
index 0000000000..2047869359
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_copysignf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+
+float
+__copysignf (float x, float y)
+{
+ asm volatile("fcopysign.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__copysign, copysign)
diff --git a/sysdeps/loongarch/fpu/s_fmaximum.c b/sysdeps/loongarch/fpu/s_fmaximum.c
new file mode 100644
index 0000000000..381a2839da
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fmaximum, fmaximum)
diff --git a/sysdeps/loongarch/fpu/s_fmaximum_mag.c b/sysdeps/loongarch/fpu/s_fmaximum_mag.c
new file mode 100644
index 0000000000..e17fc76c25
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum_mag.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+#include <fpu_control.h>
+
+double
+__fmaximum_mag (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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fmaximum_mag, fmaximum_mag)
diff --git a/sysdeps/loongarch/fpu/s_fmaximum_mag_num.c b/sysdeps/loongarch/fpu/s_fmaximum_mag_num.c
new file mode 100644
index 0000000000..b6002aefbd
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum_mag_num.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+#include <fpu_control.h>
+
+double
+__fmaximum_mag_num (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fmaximum_mag_num, fmaximum_mag_num)
diff --git a/sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c b/sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c
new file mode 100644
index 0000000000..7790579555
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fmaximum_mag_numf (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fmaximum_mag_num, fmaximum_mag_num)
diff --git a/sysdeps/loongarch/fpu/s_fmaximum_magf.c b/sysdeps/loongarch/fpu/s_fmaximum_magf.c
new file mode 100644
index 0000000000..54c8b5da47
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum_magf.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fmaximum_magf (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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fmaximum_mag, fmaximum_mag)
diff --git a/sysdeps/loongarch/fpu/s_fmaximum_num.c b/sysdeps/loongarch/fpu/s_fmaximum_num.c
new file mode 100644
index 0000000000..4b36ae800c
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum_num.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+#include <fpu_control.h>
+
+double
+__fmaximum_num (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmax.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fmaximum_num, fmaximum_num)
diff --git a/sysdeps/loongarch/fpu/s_fmaximum_numf.c b/sysdeps/loongarch/fpu/s_fmaximum_numf.c
new file mode 100644
index 0000000000..75c7b9937f
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum_numf.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fmaximum_numf (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmax.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fmaximum_num, fmaximum_num)
diff --git a/sysdeps/loongarch/fpu/s_fmaximumf.c b/sysdeps/loongarch/fpu/s_fmaximumf.c
new file mode 100644
index 0000000000..f6c7e629b6
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximumf.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fmaximumf (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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fmaximum, fmaximum)
diff --git a/sysdeps/loongarch/fpu/s_fmaxmag.c b/sysdeps/loongarch/fpu/s_fmaxmag.c
new file mode 100644
index 0000000000..3757c981de
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaxmag.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__fmaxmag (double x, double y)
+{
+ asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fmaxmag, fmaxmag)
diff --git a/sysdeps/loongarch/fpu/s_fmaxmagf.c b/sysdeps/loongarch/fpu/s_fmaxmagf.c
new file mode 100644
index 0000000000..fd826c03cc
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaxmagf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+
+float
+__fmaxmagf (float x, float y)
+{
+ asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fmaxmag, fmaxmag)
diff --git a/sysdeps/loongarch/fpu/s_fminimum.c b/sysdeps/loongarch/fpu/s_fminimum.c
new file mode 100644
index 0000000000..526dced320
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fminimum, fminimum)
diff --git a/sysdeps/loongarch/fpu/s_fminimum_mag.c b/sysdeps/loongarch/fpu/s_fminimum_mag.c
new file mode 100644
index 0000000000..2de6d4d9d8
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum_mag.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+#include <fpu_control.h>
+
+double
+__fminimum_mag (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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fminimum_mag, fminimum_mag)
diff --git a/sysdeps/loongarch/fpu/s_fminimum_mag_num.c b/sysdeps/loongarch/fpu/s_fminimum_mag_num.c
new file mode 100644
index 0000000000..3f0e6d34b2
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum_mag_num.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+#include <fpu_control.h>
+
+double
+__fminimum_mag_num (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmina.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fminimum_mag_num, fminimum_mag_num)
diff --git a/sysdeps/loongarch/fpu/s_fminimum_mag_numf.c b/sysdeps/loongarch/fpu/s_fminimum_mag_numf.c
new file mode 100644
index 0000000000..f8146b0873
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum_mag_numf.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fminimum_mag_numf (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmina.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fminimum_mag_num, fminimum_mag_num)
diff --git a/sysdeps/loongarch/fpu/s_fminimum_magf.c b/sysdeps/loongarch/fpu/s_fminimum_magf.c
new file mode 100644
index 0000000000..214a6168ad
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum_magf.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fminimum_magf (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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fminimum_mag, fminimum_mag)
diff --git a/sysdeps/loongarch/fpu/s_fminimum_num.c b/sysdeps/loongarch/fpu/s_fminimum_num.c
new file mode 100644
index 0000000000..0091286d12
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum_num.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+#include <fpu_control.h>
+
+double
+__fminimum_num (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmin.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fminimum_num, fminimum_num)
diff --git a/sysdeps/loongarch/fpu/s_fminimum_numf.c b/sysdeps/loongarch/fpu/s_fminimum_numf.c
new file mode 100644
index 0000000000..16f8414293
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum_numf.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fminimum_numf (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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return y;
+ }
+
+ if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))
+ {
+ asm volatile("fmin.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y));
+ return x;
+ }
+
+ asm volatile("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fminimum_num, fminimum_num)
diff --git a/sysdeps/loongarch/fpu/s_fminimumf.c b/sysdeps/loongarch/fpu/s_fminimumf.c
new file mode 100644
index 0000000000..1122db177e
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimumf.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+#include <fpu_control.h>
+
+float
+__fminimumf (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 ((x_cond | y_cond) & _FCLASS_NAN)
+ return x * y;
+
+ asm volatile("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fminimum, fminimum)
diff --git a/sysdeps/loongarch/fpu/s_fminmag.c b/sysdeps/loongarch/fpu/s_fminmag.c
new file mode 100644
index 0000000000..7b6e2915fe
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminmag.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__fminmag (double x, double y)
+{
+ asm volatile("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_double (__fminmag, fminmag)
diff --git a/sysdeps/loongarch/fpu/s_fminmagf.c b/sysdeps/loongarch/fpu/s_fminmagf.c
new file mode 100644
index 0000000000..a93cec2e2b
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminmagf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+
+float
+__fminmagf (float x, float y)
+{
+ asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y));
+ return x;
+}
+libm_alias_float (__fminmag, fminmag)
diff --git a/sysdeps/loongarch/fpu/s_fpclassify.c b/sysdeps/loongarch/fpu/s_fpclassify.c
new file mode 100644
index 0000000000..865436c9a2
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fpclassify.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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>
+
+int
+__fpclassify (double x)
+{
+ int cls;
+ asm volatile ("fclass.d \t%0, %1" : "=f" (cls) : "f" (x));
+
+ if (__builtin_expect (cls & _FCLASS_ZERO, _FCLASS_ZERO))
+ return FP_ZERO;
+ if (__builtin_expect (cls & _FCLASS_SUBNORM, _FCLASS_SUBNORM))
+ return FP_SUBNORMAL;
+ if (__builtin_expect (cls & _FCLASS_NAN, _FCLASS_NAN))
+ return FP_NAN;
+ if (__builtin_expect (cls & _FCLASS_INF, _FCLASS_INF))
+ return FP_INFINITE;
+ return FP_NORMAL;
+}
+libm_hidden_def (__fpclassify)
diff --git a/sysdeps/loongarch/fpu/s_fpclassifyf.c b/sysdeps/loongarch/fpu/s_fpclassifyf.c
new file mode 100644
index 0000000000..ca7b1d6703
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fpclassifyf.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2022 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>
+
+int
+__fpclassifyf (float x)
+{
+ int cls;
+ asm volatile ("fclass.s \t%0, %1" : "=f" (cls) : "f" (x));
+
+ if (__builtin_expect (cls & _FCLASS_NORM, _FCLASS_NORM))
+ return FP_NORMAL;
+ if (__builtin_expect (cls & _FCLASS_ZERO, _FCLASS_ZERO))
+ return FP_ZERO;
+ if (__builtin_expect (cls & _FCLASS_SUBNORM, _FCLASS_SUBNORM))
+ return FP_SUBNORMAL;
+ if (__builtin_expect (cls & _FCLASS_INF, _FCLASS_INF))
+ return FP_INFINITE;
+ return FP_NAN;
+}
+libm_hidden_def (__fpclassifyf)
diff --git a/sysdeps/loongarch/fpu/s_issignaling.c b/sysdeps/loongarch/fpu/s_issignaling.c
new file mode 100644
index 0000000000..d6525516e1
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_issignaling.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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>
+
+int
+__issignaling (double x)
+{
+ int x_cond;
+ asm volatile("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
+ return (x_cond & _FCLASS_SNAN) != 0;
+}
+libm_hidden_def (__issignaling)
diff --git a/sysdeps/loongarch/fpu/s_issignalingf.c b/sysdeps/loongarch/fpu/s_issignalingf.c
new file mode 100644
index 0000000000..48c287c8e7
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_issignalingf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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>
+
+int
+__issignalingf (float x)
+{
+ int x_cond;
+ asm volatile("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
+ return (x_cond & _FCLASS_SNAN) != 0;
+}
+libm_hidden_def (__issignalingf)
diff --git a/sysdeps/loongarch/fpu/s_llrint.c b/sysdeps/loongarch/fpu/s_llrint.c
new file mode 100644
index 0000000000..0adaacf1c1
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_llrint.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+
+long long int
+__llrint (double x)
+{
+ asm volatile("frint.d \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_double (__llrint, llrint)
diff --git a/sysdeps/loongarch/fpu/s_llrintf.c b/sysdeps/loongarch/fpu/s_llrintf.c
new file mode 100644
index 0000000000..c0b0adaf69
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_llrintf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+
+long long int
+__llrintf (float x)
+{
+ asm volatile("frint.s \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_float (__llrint, llrint)
diff --git a/sysdeps/loongarch/fpu/s_logb.c b/sysdeps/loongarch/fpu/s_logb.c
new file mode 100644
index 0000000000..44fd5d7c40
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_logb.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__logb (double x)
+{
+ asm volatile("fabs.d \t%0, %1" : "=f" (x) : "f" (x));
+ asm volatile("flogb.d \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_double (__logb, logb)
diff --git a/sysdeps/loongarch/fpu/s_logbf.c b/sysdeps/loongarch/fpu/s_logbf.c
new file mode 100644
index 0000000000..6c1ab23b5e
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_logbf.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+
+float
+__logbf (float x)
+{
+ asm volatile("fabs.s \t%0, %1" : "=f" (x) : "f" (x));
+ asm volatile("flogb.s \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_float (__logb, logb)
diff --git a/sysdeps/loongarch/fpu/s_lrint.c b/sysdeps/loongarch/fpu/s_lrint.c
new file mode 100644
index 0000000000..f4185f2271
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_lrint.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+
+long int
+__lrint (double x)
+{
+ asm volatile("frint.d \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_double (__lrint, lrint)
diff --git a/sysdeps/loongarch/fpu/s_lrintf.c b/sysdeps/loongarch/fpu/s_lrintf.c
new file mode 100644
index 0000000000..48197b21c4
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_lrintf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+
+long int
+__lrintf (float x)
+{
+ asm volatile("frint.s \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_float (__lrint, lrint)
diff --git a/sysdeps/loongarch/fpu/s_rint.c b/sysdeps/loongarch/fpu/s_rint.c
new file mode 100644
index 0000000000..28638eb9e0
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_rint.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-double.h>
+
+double
+__rint (double x)
+{
+ asm volatile("frint.d \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_double (__rint, rint)
diff --git a/sysdeps/loongarch/fpu/s_rintf.c b/sysdeps/loongarch/fpu/s_rintf.c
new file mode 100644
index 0000000000..ce3815f5e0
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_rintf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <libm-alias-float.h>
+
+float
+__rintf (float x)
+{
+ asm volatile("frint.s \t%0, %1" : "=f" (x) : "f" (x));
+ return x;
+}
+libm_alias_float (__rint, rint)
diff --git a/sysdeps/loongarch/fpu/s_scalbn.c b/sysdeps/loongarch/fpu/s_scalbn.c
new file mode 100644
index 0000000000..4c4bbf8be9
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_scalbn.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+
+double
+__scalbn (double x, int fn)
+{
+ double tmp;
+ asm volatile("movgr2fr.d \t%0, %1" : "=f" (tmp) : "r" (fn));
+ asm volatile("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp));
+ return x;
+}
diff --git a/sysdeps/loongarch/fpu/s_scalbnf.c b/sysdeps/loongarch/fpu/s_scalbnf.c
new file mode 100644
index 0000000000..ff6dc6d3f8
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_scalbnf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2022 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/>. */
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+
+float
+__scalbnf (float x, int fn)
+{
+ float tmp;
+ asm volatile("movgr2fr.w \t%0, %1" : "=f" (tmp) : "r" (fn));
+ asm volatile("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp));
+ return x;
+}
diff --git a/sysdeps/loongarch/fpu_control.h b/sysdeps/loongarch/fpu_control.h
index f482395dba..13436335fe 100644
--- a/sysdeps/loongarch/fpu_control.h
+++ b/sysdeps/loongarch/fpu_control.h
@@ -97,6 +97,23 @@ extern void __loongarch_fpu_setcw (fpu_control_t) __THROW;
/* Default control word set at startup. */
extern fpu_control_t __fpu_control;
+# define _FCLASS_SNAN (1 << 0)
+# define _FCLASS_QNAN (1 << 1)
+# define _FCLASS_MINF (1 << 2)
+# define _FCLASS_MNORM (1 << 3)
+# define _FCLASS_MSUBNORM (1 << 4)
+# define _FCLASS_MZERO (1 << 5)
+# define _FCLASS_PINF (1 << 6)
+# define _FCLASS_PNORM (1 << 7)
+# define _FCLASS_PSUBNORM (1 << 8)
+# define _FCLASS_PZERO (1 << 9)
+
+# define _FCLASS_ZERO (_FCLASS_MZERO | _FCLASS_PZERO)
+# define _FCLASS_SUBNORM (_FCLASS_MSUBNORM | _FCLASS_PSUBNORM)
+# define _FCLASS_NORM (_FCLASS_MNORM | _FCLASS_PNORM)
+# define _FCLASS_INF (_FCLASS_MINF | _FCLASS_PINF)
+# define _FCLASS_NAN (_FCLASS_SNAN | _FCLASS_QNAN)
+
#endif /* __loongarch_soft_float */
#endif /* fpu_control.h */
--
2.36.0
next prev parent reply other threads:[~2022-11-03 12:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 12:14 [PATCH 0/1] " Xiaolin Tang
2022-11-03 12:14 ` Xiaolin Tang [this message]
2022-11-03 12:42 ` [PATCH 1/1] " Adhemerval Zanella Netto
2022-11-03 14:39 ` Xi Ruoyao
2022-11-03 16:14 ` Adhemerval Zanella Netto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221103121433.2909287-2-tangxiaolin@loongson.cn \
--to=tangxiaolin@loongson.cn \
--cc=adhemerval.zanella@linaro.org \
--cc=caiyinyu@loongson.cn \
--cc=i.swmail@xen0n.name \
--cc=libc-alpha@sourceware.org \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).