* [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions.
@ 2022-11-07 14:05 Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ } Xiaolin Tang
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Xiaolin Tang @ 2022-11-07 14:05 UTC (permalink / raw)
To: adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xry111, xuchenghua, chenglulu, Xiaolin Tang
Hi, reviewers.
Those patches 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,
and the performance of those newly implemented functions is good.
Changes from v1 to v2:
1. Delete copysign{f/ } to implement it on compiler.
(https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605071.html)
2. Replace __builtin_expect with __glibc_likely or __glibc_unlikely.
3. Add a brief description on each file header.
4. Split one patch to ten patches for similar functions implementation.
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/ }
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/ }
__finite{f/ }, __isnan{f/ }, isinff{f/ }
Xiaolin Tang (10):
LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ }.
LoongArch: Use __builtin_{fma, fmaf} to implement function {fma,
fmaf}.
LoongArch: Hard Float Support for float-point classification
functions.
LoongArch: Hard Float Support for functions logb{f/ },
__ieee754_ilogb{f/ }.
LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ }.
LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ }.
LoongArch: Hard Float Support for fmaximum_num{f/ }, fminimum_num{f/
}.
LoongArch: Hard Float Support for fmaxmag{f/ }, fminmag{f/ }.
LoongArch: Hard Float Support for fmaximum_mag{f/ }, fminimum_mag{f/
}.
LoongArch: Hard Float Support for fmaximum_mag_num{f/ },
fminimum_mag_num{f/ }.
sysdeps/loongarch/fpu/e_ilogb.c | 39 ++++++++++++
sysdeps/loongarch/fpu/e_ilogbf.c | 39 ++++++++++++
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_finite.c | 30 +++++++++
sysdeps/loongarch/fpu/s_finitef.c | 30 +++++++++
sysdeps/loongarch/fpu/s_fmaximum.c | 40 ++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_mag.c | 40 ++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_mag_num.c | 48 +++++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c | 48 +++++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_magf.c | 40 ++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_num.c | 48 +++++++++++++++
sysdeps/loongarch/fpu/s_fmaximum_numf.c | 49 +++++++++++++++
sysdeps/loongarch/fpu/s_fmaximumf.c | 40 ++++++++++++
sysdeps/loongarch/fpu/s_fmaxmag.c | 29 +++++++++
sysdeps/loongarch/fpu/s_fmaxmagf.c | 29 +++++++++
sysdeps/loongarch/fpu/s_fminimum.c | 40 ++++++++++++
sysdeps/loongarch/fpu/s_fminimum_mag.c | 40 ++++++++++++
sysdeps/loongarch/fpu/s_fminimum_mag_num.c | 48 +++++++++++++++
sysdeps/loongarch/fpu/s_fminimum_mag_numf.c | 48 +++++++++++++++
sysdeps/loongarch/fpu/s_fminimum_magf.c | 40 ++++++++++++
sysdeps/loongarch/fpu/s_fminimum_num.c | 48 +++++++++++++++
sysdeps/loongarch/fpu/s_fminimum_numf.c | 48 +++++++++++++++
sysdeps/loongarch/fpu/s_fminimumf.c | 40 ++++++++++++
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_isinf.c | 30 +++++++++
sysdeps/loongarch/fpu/s_isinff.c | 30 +++++++++
sysdeps/loongarch/fpu/s_isnan.c | 31 ++++++++++
sysdeps/loongarch/fpu/s_isnanf.c | 31 ++++++++++
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 ++++++
46 files changed, 1650 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_finite.c
create mode 100644 sysdeps/loongarch/fpu/s_finitef.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_isinf.c
create mode 100644 sysdeps/loongarch/fpu/s_isinff.c
create mode 100644 sysdeps/loongarch/fpu/s_isnan.c
create mode 100644 sysdeps/loongarch/fpu/s_isnanf.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
--
2.36.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ }.
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
@ 2022-11-07 14:05 ` Xiaolin Tang
2022-11-07 14:38 ` Xi Ruoyao
2022-11-07 14:05 ` [PATCH v2 02/10] LoongArch: Use __builtin_{fma, fmaf} to implement function {fma, fmaf} Xiaolin Tang
` (5 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Xiaolin Tang @ 2022-11-07 14:05 UTC (permalink / raw)
To: adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xry111, xuchenghua, chenglulu, Xiaolin Tang
Use hardware Floating-point instruction frint.{s/d} to implement
functions {ll/l/ }rint{f/ }.
* sysdeps/loongarch/fpu/s_llrint.c: New file.
* sysdeps/loongarch/fpu/s_llrintf.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_llrint.c | 29 +++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_llrintf.c | 29 +++++++++++++++++++++++++++++
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 +++++++++++++++++++++++++++++
6 files changed, 174 insertions(+)
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_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
diff --git a/sysdeps/loongarch/fpu/s_llrint.c b/sysdeps/loongarch/fpu/s_llrint.c
new file mode 100644
index 0000000000..cf787f50ed
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_llrint.c
@@ -0,0 +1,29 @@
+/* llrint(). LoongArch version.
+ 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..a258e635ce
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_llrintf.c
@@ -0,0 +1,29 @@
+/* llrintf(). LoongArch version.
+ 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_lrint.c b/sysdeps/loongarch/fpu/s_lrint.c
new file mode 100644
index 0000000000..10d43218f8
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_lrint.c
@@ -0,0 +1,29 @@
+/* lrint(). LoongArch version.
+ 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..7168eda7cb
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_lrintf.c
@@ -0,0 +1,29 @@
+/* lrintf(). LoongArch version.
+ 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..429d5d1176
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_rint.c
@@ -0,0 +1,29 @@
+/* rint(). LoongArch version.
+ 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..b3faba2027
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_rintf.c
@@ -0,0 +1,29 @@
+/* rintf(). LoongArch version.
+ 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)
--
2.36.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 02/10] LoongArch: Use __builtin_{fma, fmaf} to implement function {fma, fmaf}.
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ } Xiaolin Tang
@ 2022-11-07 14:05 ` Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 03/10] LoongArch: Hard Float Support for float-point classification functions Xiaolin Tang
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Xiaolin Tang @ 2022-11-07 14:05 UTC (permalink / raw)
To: adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xry111, xuchenghua, chenglulu, Xiaolin Tang
Use __builtin_{fma, fmaf} to implement function {fma, fmaf} instead of
the generic implementation.
* sysdeps/loongarch/fpu/math-use-builtins-fma.h: New file.
---
sysdeps/loongarch/fpu/math-use-builtins-fma.h | 4 ++++
1 file changed, 4 insertions(+)
create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-fma.h
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
--
2.36.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 03/10] LoongArch: Hard Float Support for float-point classification functions.
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ } Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 02/10] LoongArch: Use __builtin_{fma, fmaf} to implement function {fma, fmaf} Xiaolin Tang
@ 2022-11-07 14:05 ` Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 04/10] LoongArch: Hard Float Support for functions logb{f/ }, __ieee754_ilogb{f/ } Xiaolin Tang
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Xiaolin Tang @ 2022-11-07 14:05 UTC (permalink / raw)
To: adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xry111, xuchenghua, chenglulu, Xiaolin Tang
Use hardware Floating-point instruction fclass.{s/d} to implement
classification functions, i.e finite{f/ }, fpclassify{f/ }, isnan{f/ },
isinf{f/ }, issignaling{f/ }.
* sysdeps/loongarch/fpu/s_finite.c: New file.
* sysdeps/loongarch/fpu/s_finitef.c: Likewise.
* sysdeps/loongarch/fpu/s_fpclassify.c: Likewise.
* sysdeps/loongarch/fpu/s_fpclassifyf.c: Likewise.
* sysdeps/loongarch/fpu/s_isinf.c: Likewise.
* sysdeps/loongarch/fpu/s_isinff.c: Likewise.
* sysdeps/loongarch/fpu/s_isnan.c: Likewise.
* sysdeps/loongarch/fpu/s_isnanf.c: Likewise.
* sysdeps/loongarch/fpu/s_issignaling.c: Likewise.
* sysdeps/loongarch/fpu/s_issignalingf.c: Likewise.
* sysdeps/loongarch/fpu_control.h: Add _FCLASS_* macro.
---
sysdeps/loongarch/fpu/s_finite.c | 30 ++++++++++++++++++++
sysdeps/loongarch/fpu/s_finitef.c | 30 ++++++++++++++++++++
sysdeps/loongarch/fpu/s_fpclassify.c | 38 ++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_fpclassifyf.c | 38 ++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_isinf.c | 30 ++++++++++++++++++++
sysdeps/loongarch/fpu/s_isinff.c | 30 ++++++++++++++++++++
sysdeps/loongarch/fpu/s_isnan.c | 31 +++++++++++++++++++++
sysdeps/loongarch/fpu/s_isnanf.c | 31 +++++++++++++++++++++
sysdeps/loongarch/fpu/s_issignaling.c | 29 ++++++++++++++++++++
sysdeps/loongarch/fpu/s_issignalingf.c | 29 ++++++++++++++++++++
sysdeps/loongarch/fpu_control.h | 17 ++++++++++++
11 files changed, 333 insertions(+)
create mode 100644 sysdeps/loongarch/fpu/s_finite.c
create mode 100644 sysdeps/loongarch/fpu/s_finitef.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_isinf.c
create mode 100644 sysdeps/loongarch/fpu/s_isinff.c
create mode 100644 sysdeps/loongarch/fpu/s_isnan.c
create mode 100644 sysdeps/loongarch/fpu/s_isnanf.c
create mode 100644 sysdeps/loongarch/fpu/s_issignaling.c
create mode 100644 sysdeps/loongarch/fpu/s_issignalingf.c
diff --git a/sysdeps/loongarch/fpu/s_finite.c b/sysdeps/loongarch/fpu/s_finite.c
new file mode 100644
index 0000000000..a2e98f0b60
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_finite.c
@@ -0,0 +1,30 @@
+/* finite(). LoongArch version.
+ 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
+__finite (double x)
+{
+ int x_cond;
+ asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
+ return x_cond & ~(_FCLASS_INF | _FCLASS_NAN);
+}
+hidden_def (__finite)
+weak_alias (__finite, finite)
diff --git a/sysdeps/loongarch/fpu/s_finitef.c b/sysdeps/loongarch/fpu/s_finitef.c
new file mode 100644
index 0000000000..9ffab38abd
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_finitef.c
@@ -0,0 +1,30 @@
+/* finitef(). LoongArch version.
+ 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
+__finitef (float x)
+{
+ int x_cond;
+ asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
+ return x_cond & ~(_FCLASS_INF | _FCLASS_NAN);
+}
+hidden_def (__finitef)
+weak_alias (__finitef, finitef)
diff --git a/sysdeps/loongarch/fpu/s_fpclassify.c b/sysdeps/loongarch/fpu/s_fpclassify.c
new file mode 100644
index 0000000000..3f4d95da66
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fpclassify.c
@@ -0,0 +1,38 @@
+/* fpclassify(). LoongArch version.
+ Copyright (C) 2017-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 (__glibc_likely (!!(cls & _FCLASS_NORM)))
+ return FP_NORMAL;
+ if (__glibc_likely (!!(cls & _FCLASS_ZERO)))
+ return FP_ZERO;
+ if (__glibc_likely (!!(cls & _FCLASS_SUBNORM)))
+ return FP_SUBNORMAL;
+ if (__glibc_likely (!!(cls & _FCLASS_INF)))
+ return FP_INFINITE;
+ return FP_NAN;
+}
+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..b7c8b25337
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fpclassifyf.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2017-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 (__glibc_likely (!!(cls & _FCLASS_NORM)))
+ return FP_NORMAL;
+ if (__glibc_likely (!!(cls & _FCLASS_ZERO)))
+ return FP_ZERO;
+ if (__glibc_likely (!!(cls & _FCLASS_SUBNORM)))
+ return FP_SUBNORMAL;
+ if (__glibc_likely (!!(cls & _FCLASS_INF)))
+ return FP_INFINITE;
+ return FP_NAN;
+}
+libm_hidden_def (__fpclassifyf)
diff --git a/sysdeps/loongarch/fpu/s_isinf.c b/sysdeps/loongarch/fpu/s_isinf.c
new file mode 100644
index 0000000000..c7a6784185
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_isinf.c
@@ -0,0 +1,30 @@
+/* isinf(). LoongArch version.
+ Copyright (C) 2017-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
+__isinf (double x)
+{
+ int x_cond;
+ asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
+ return -((x_cond & _FCLASS_MINF) ? 1 : 0) | ((x_cond & _FCLASS_PINF) ? 1 : 0);
+}
+hidden_def (__isinf)
+weak_alias (__isinf, isinf)
diff --git a/sysdeps/loongarch/fpu/s_isinff.c b/sysdeps/loongarch/fpu/s_isinff.c
new file mode 100644
index 0000000000..dcb4e04ec8
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_isinff.c
@@ -0,0 +1,30 @@
+/* isinff(). LoongArch version.
+ Copyright (C) 2017-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
+__isinff (float x)
+{
+ int x_cond;
+ asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
+ return -((x_cond & _FCLASS_MINF) ? 1 : 0) | ((x_cond & _FCLASS_PINF) ? 1 : 0);
+}
+hidden_def (__isinff)
+weak_alias (__isinff, isinff)
diff --git a/sysdeps/loongarch/fpu/s_isnan.c b/sysdeps/loongarch/fpu/s_isnan.c
new file mode 100644
index 0000000000..62bb2e2fad
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_isnan.c
@@ -0,0 +1,31 @@
+/* isnan(). LoongArch version.
+ 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
+__isnan (double x)
+{
+ int x_cond;
+ asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x));
+
+ return (x_cond & _FCLASS_NAN) != 0;
+}
+hidden_def (__isnan)
+weak_alias (__isnan, isnan)
diff --git a/sysdeps/loongarch/fpu/s_isnanf.c b/sysdeps/loongarch/fpu/s_isnanf.c
new file mode 100644
index 0000000000..bbdedb8429
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_isnanf.c
@@ -0,0 +1,31 @@
+/* isnanf(). LoongArch version.
+ 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
+__isnanf (float x)
+{
+ int x_cond;
+ asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x));
+
+ return (x_cond & _FCLASS_NAN) != 0;
+}
+hidden_def (__isnanf)
+weak_alias (__isnanf, isnanf)
diff --git a/sysdeps/loongarch/fpu/s_issignaling.c b/sysdeps/loongarch/fpu/s_issignaling.c
new file mode 100644
index 0000000000..4fe0e2b7a9
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_issignaling.c
@@ -0,0 +1,29 @@
+/* issignaling(). LoongArch version.
+ 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..d82abb0e74
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_issignalingf.c
@@ -0,0 +1,29 @@
+/* issignalingf(). LoongArch version.
+ 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_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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 04/10] LoongArch: Hard Float Support for functions logb{f/ }, __ieee754_ilogb{f/ }.
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
` (2 preceding siblings ...)
2022-11-07 14:05 ` [PATCH v2 03/10] LoongArch: Hard Float Support for float-point classification functions Xiaolin Tang
@ 2022-11-07 14:05 ` Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 05/10] LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ } Xiaolin Tang
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Xiaolin Tang @ 2022-11-07 14:05 UTC (permalink / raw)
To: adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xry111, xuchenghua, chenglulu, Xiaolin Tang
Use hardware Floating-point instruction flogb.{s/d}, fclass.{s/d} to
implement functions logb{f/ }, __ieee754_ilogb{f/ }.
* sysdeps/loongarch/fpu/e_ilogb.c: New file.
* sysdeps/loongarch/fpu/e_ilogbf.c: Likewise.
* sysdeps/loongarch/fpu/s_logb.c: Likewise.
* sysdeps/loongarch/fpu/s_logbf.c: Likewise.
---
sysdeps/loongarch/fpu/e_ilogb.c | 39 ++++++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/e_ilogbf.c | 39 ++++++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_logb.c | 30 ++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_logbf.c | 30 ++++++++++++++++++++++++
4 files changed, 138 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/s_logb.c
create mode 100644 sysdeps/loongarch/fpu/s_logbf.c
diff --git a/sysdeps/loongarch/fpu/e_ilogb.c b/sysdeps/loongarch/fpu/e_ilogb.c
new file mode 100644
index 0000000000..f9ada6921a
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_ilogb.c
@@ -0,0 +1,39 @@
+/* __ieee754_ilogb(). LoongArch version.
+ 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 (__glibc_unlikely (x_cond & _FCLASS_ZERO))
+ return FP_ILOGB0;
+ else if (__glibc_unlikely (x_cond & ( _FCLASS_NAN | _FCLASS_INF)))
+ return FP_ILOGBNAN;
+ else
+ {
+ 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..e1da48ecfc
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_ilogbf.c
@@ -0,0 +1,39 @@
+/* __ieee754_ilogbf(). LoongArch version.
+ 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 (__glibc_unlikely (x_cond & _FCLASS_ZERO))
+ return FP_ILOGB0;
+ else if (__glibc_unlikely (x_cond & ( _FCLASS_NAN | _FCLASS_INF)))
+ return FP_ILOGBNAN;
+ else
+ {
+ 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/s_logb.c b/sysdeps/loongarch/fpu/s_logb.c
new file mode 100644
index 0000000000..31bb3be5c9
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_logb.c
@@ -0,0 +1,30 @@
+/* logb(). LoongArch version.
+ 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..f5166bcabd
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_logbf.c
@@ -0,0 +1,30 @@
+/* logbf(). LoongArch version.
+ 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)
--
2.36.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 05/10] LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ }.
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
` (3 preceding siblings ...)
2022-11-07 14:05 ` [PATCH v2 04/10] LoongArch: Hard Float Support for functions logb{f/ }, __ieee754_ilogb{f/ } Xiaolin Tang
@ 2022-11-07 14:05 ` Xiaolin Tang
2022-11-08 3:46 ` Xi Ruoyao
2022-11-07 14:05 ` [PATCH v2 06/10] LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ } Xiaolin Tang
2022-11-11 4:02 ` [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions caiyinyu
6 siblings, 1 reply; 11+ messages in thread
From: Xiaolin Tang @ 2022-11-07 14:05 UTC (permalink / raw)
To: adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xry111, xuchenghua, chenglulu, Xiaolin Tang
Use hardware Floating-point instruction fscaleb.{s/d}, fclass.{s/d} to
implement functions scalb{f/ }, scalbn{f/ }.
* sysdeps/loongarch/fpu/e_scalb.c: New file.
* sysdeps/loongarch/fpu/e_scalbf.c: Likewise.
* sysdeps/loongarch/fpu/s_scalbn.c: Likewise.
* sysdeps/loongarch/fpu/s_scalbnf.c: Likewise.
---
sysdeps/loongarch/fpu/e_scalb.c | 61 +++++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/e_scalbf.c | 61 +++++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_scalbn.c | 29 +++++++++++++++
sysdeps/loongarch/fpu/s_scalbnf.c | 29 +++++++++++++++
4 files changed, 180 insertions(+)
create mode 100644 sysdeps/loongarch/fpu/e_scalb.c
create mode 100644 sysdeps/loongarch/fpu/e_scalbf.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_scalb.c b/sysdeps/loongarch/fpu/e_scalb.c
new file mode 100644
index 0000000000..de01441186
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_scalb.c
@@ -0,0 +1,61 @@
+/* scalb(). LoongArch version.
+ 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 (__glibc_unlikely(( x_cond | fn_cond) & _FCLASS_NAN))
+ return x * fn;
+ else if (__glibc_unlikely(fn_cond & _FCLASS_INF))
+ {
+ if (!(fn_cond & _FCLASS_MINF))
+ return x * fn;
+ else
+ return x / -fn;
+ }
+ else if (__glibc_likely(-DBL_MAX < fn && fn < DBL_MAX))
+ {
+ 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..6b617e8fc1
--- /dev/null
+++ b/sysdeps/loongarch/fpu/e_scalbf.c
@@ -0,0 +1,61 @@
+/* scalbf(). LoongArch version.
+ 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 (__glibc_unlikely(( x_cond | fn_cond) & _FCLASS_NAN))
+ return x * fn;
+ else if (__glibc_unlikely(fn_cond & _FCLASS_INF))
+ {
+ if (!(fn_cond & _FCLASS_MINF))
+ return x * fn;
+ else
+ return x / -fn;
+ }
+ else if (__glibc_likely(-FLT_MAX < fn && fn < FLT_MAX))
+ {
+ 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/s_scalbn.c b/sysdeps/loongarch/fpu/s_scalbn.c
new file mode 100644
index 0000000000..c03e81a31e
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_scalbn.c
@@ -0,0 +1,29 @@
+/* scalbn(). LoongArch version.
+ 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..15e6428044
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_scalbnf.c
@@ -0,0 +1,29 @@
+/* scalbnf(). LoongArch version.
+ 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;
+}
--
2.36.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 06/10] LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ }.
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
` (4 preceding siblings ...)
2022-11-07 14:05 ` [PATCH v2 05/10] LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ } Xiaolin Tang
@ 2022-11-07 14:05 ` Xiaolin Tang
2022-11-11 4:02 ` [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions caiyinyu
6 siblings, 0 replies; 11+ messages in thread
From: Xiaolin Tang @ 2022-11-07 14:05 UTC (permalink / raw)
To: adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xry111, xuchenghua, chenglulu, Xiaolin Tang
Use hardware Floating-point instruction f{max/min}.{s/d}, fclass.{s/d}
to implement fmaximum{f/ }, fminimum{f/ }.
* sysdeps/loongarch/fpu/s_fmaximum.c: New file.
* sysdeps/loongarch/fpu/s_fmaximumf.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimum.c: Likewise.
* sysdeps/loongarch/fpu/s_fminimumf.c: Likewise.
---
sysdeps/loongarch/fpu/s_fmaximum.c | 40 +++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_fmaximumf.c | 40 +++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_fminimum.c | 40 +++++++++++++++++++++++++++++
sysdeps/loongarch/fpu/s_fminimumf.c | 40 +++++++++++++++++++++++++++++
4 files changed, 160 insertions(+)
create mode 100644 sysdeps/loongarch/fpu/s_fmaximum.c
create mode 100644 sysdeps/loongarch/fpu/s_fmaximumf.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimum.c
create mode 100644 sysdeps/loongarch/fpu/s_fminimumf.c
diff --git a/sysdeps/loongarch/fpu/s_fmaximum.c b/sysdeps/loongarch/fpu/s_fmaximum.c
new file mode 100644
index 0000000000..af1c2bf006
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximum.c
@@ -0,0 +1,40 @@
+/* fmaximum(). LoongArch version.
+ 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 (__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)
diff --git a/sysdeps/loongarch/fpu/s_fmaximumf.c b/sysdeps/loongarch/fpu/s_fmaximumf.c
new file mode 100644
index 0000000000..da4dcb6a3b
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fmaximumf.c
@@ -0,0 +1,40 @@
+/* fmaximumf(). LoongArch version.
+ 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 (__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;
+ }
+}
+libm_alias_float (__fmaximum, fmaximum)
diff --git a/sysdeps/loongarch/fpu/s_fminimum.c b/sysdeps/loongarch/fpu/s_fminimum.c
new file mode 100644
index 0000000000..e395ff7e62
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimum.c
@@ -0,0 +1,40 @@
+/* fminimum(). LoongArch version.
+ 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 (__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)
diff --git a/sysdeps/loongarch/fpu/s_fminimumf.c b/sysdeps/loongarch/fpu/s_fminimumf.c
new file mode 100644
index 0000000000..680c5e7e9a
--- /dev/null
+++ b/sysdeps/loongarch/fpu/s_fminimumf.c
@@ -0,0 +1,40 @@
+/* fminimumf(). LoongArch version.
+ 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 (__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;
+ }
+}
+libm_alias_float (__fminimum, fminimum)
--
2.36.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ }.
2022-11-07 14:05 ` [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ } Xiaolin Tang
@ 2022-11-07 14:38 ` Xi Ruoyao
2022-11-07 16:36 ` Adhemerval Zanella Netto
0 siblings, 1 reply; 11+ messages in thread
From: Xi Ruoyao @ 2022-11-07 14:38 UTC (permalink / raw)
To: Xiaolin Tang, adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xuchenghua, chenglulu
On Mon, 2022-11-07 at 22:05 +0800, Xiaolin Tang wrote:
> +long long int
> +__llrint (double x)
> +{
> + asm volatile ("frint.d \t%0, %1" : "=f" (x) : "f" (x));
> + return x;
> +}
GCC trunk generates:
__llrint:
frint.d $f0, $f0
ftintrz.l.d $f0,$f0
movfr2gr.d $r4,$f0
jr $r1
It's not optimal. The optimal way is:
__llrint:
ftint.l.d $f0, $f0
movfr2gr.d $r4,$f0
jr $r1
I have a GCC patch to expand __builtin_llrint to ftint.l.d and
movgr2fr.d (with -fno-math-errno, which is enabled by Glibc building
system).
But I need some time to test my patch correctly: unfortunately I'm now
hitting some "random crashes" running Expect on LoongArch so I can't
complete GCC regression test.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ }.
2022-11-07 14:38 ` Xi Ruoyao
@ 2022-11-07 16:36 ` Adhemerval Zanella Netto
0 siblings, 0 replies; 11+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-07 16:36 UTC (permalink / raw)
To: Xi Ruoyao, Xiaolin Tang, libc-alpha, i.swmail
Cc: caiyinyu, xuchenghua, chenglulu
On 07/11/22 11:38, Xi Ruoyao wrote:
> On Mon, 2022-11-07 at 22:05 +0800, Xiaolin Tang wrote:
>
>> +long long int
>> +__llrint (double x)
>> +{
>> + asm volatile ("frint.d \t%0, %1" : "=f" (x) : "f" (x));
>> + return x;
>> +}
>
> GCC trunk generates:
>
> __llrint:
> frint.d $f0, $f0
> ftintrz.l.d $f0,$f0
> movfr2gr.d $r4,$f0
> jr $r1
>
> It's not optimal. The optimal way is:
>
> __llrint:
> ftint.l.d $f0, $f0
> movfr2gr.d $r4,$f0
> jr $r1
>
> I have a GCC patch to expand __builtin_llrint to ftint.l.d and
> movgr2fr.d (with -fno-math-errno, which is enabled by Glibc building
> system).
>
> But I need some time to test my patch correctly: unfortunately I'm now
> hitting some "random crashes" running Expect on LoongArch so I can't
> complete GCC regression test.
A compiler builtin would indeed more desirable, since it would allows to
move it on generic code and use a math-use-builtins-llrint.h instead of
arch-specific code.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 05/10] LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ }.
2022-11-07 14:05 ` [PATCH v2 05/10] LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ } Xiaolin Tang
@ 2022-11-08 3:46 ` Xi Ruoyao
0 siblings, 0 replies; 11+ messages in thread
From: Xi Ruoyao @ 2022-11-08 3:46 UTC (permalink / raw)
To: Xiaolin Tang, adhemerval.zanella, libc-alpha, i.swmail
Cc: caiyinyu, xuchenghua, chenglulu
On Mon, 2022-11-07 at 22:05 +0800, Xiaolin Tang wrote:
> Use hardware Floating-point instruction fscaleb.{s/d}, fclass.{s/d} to
> implement functions scalb{f/ }, scalbn{f/ }.
>
> * sysdeps/loongarch/fpu/e_scalb.c: New file.
> * sysdeps/loongarch/fpu/e_scalbf.c: Likewise.
> * sysdeps/loongarch/fpu/s_scalbn.c: Likewise.
> * sysdeps/loongarch/fpu/s_scalbnf.c: Likewise.
I plan to add scalbn and scalbnf expands for GCC.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions.
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
` (5 preceding siblings ...)
2022-11-07 14:05 ` [PATCH v2 06/10] LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ } Xiaolin Tang
@ 2022-11-11 4:02 ` caiyinyu
6 siblings, 0 replies; 11+ messages in thread
From: caiyinyu @ 2022-11-11 4:02 UTC (permalink / raw)
To: Xiaolin Tang, adhemerval.zanella, libc-alpha, i.swmail
Cc: xry111, xuchenghua, chenglulu
Considering Xi Ruoyao's new patches of GCC about "LoongArch: Add some
floating-point operations[1]"
, I plan to include the following patches
02, 03, 06-10 temporarily excluding rint{,f} {l/ll}rint{,f} logb{,f} and
scalb{n,ln}{,f} related ones.
Also, I have noticed that there are some new functions added in Patch v2
03: s_isinf{f}.c
and s_isnan{f}.c.
All these patches were tested on LoongArch machine with GCC 12.1.0,
binutils 2.38.50.20220519, and
Linux kernel 5.19 and no new fails were caused.
[1] https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605454.html
在 2022/11/7 下午10:05, Xiaolin Tang 写道:
> Hi, reviewers.
> Those patches 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,
> and the performance of those newly implemented functions is good.
>
> Changes from v1 to v2:
> 1. Delete copysign{f/ } to implement it on compiler.
> (https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605071.html)
> 2. Replace __builtin_expect with __glibc_likely or __glibc_unlikely.
> 3. Add a brief description on each file header.
> 4. Split one patch to ten patches for similar functions implementation.
>
> 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/ }
> 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/ }
> __finite{f/ }, __isnan{f/ }, isinff{f/ }
>
> Xiaolin Tang (10):
> LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ }.
> LoongArch: Use __builtin_{fma, fmaf} to implement function {fma,
> fmaf}.
> LoongArch: Hard Float Support for float-point classification
> functions.
> LoongArch: Hard Float Support for functions logb{f/ },
> __ieee754_ilogb{f/ }.
> LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ }.
> LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ }.
> LoongArch: Hard Float Support for fmaximum_num{f/ }, fminimum_num{f/
> }.
> LoongArch: Hard Float Support for fmaxmag{f/ }, fminmag{f/ }.
> LoongArch: Hard Float Support for fmaximum_mag{f/ }, fminimum_mag{f/
> }.
> LoongArch: Hard Float Support for fmaximum_mag_num{f/ },
> fminimum_mag_num{f/ }.
>
> sysdeps/loongarch/fpu/e_ilogb.c | 39 ++++++++++++
> sysdeps/loongarch/fpu/e_ilogbf.c | 39 ++++++++++++
> 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_finite.c | 30 +++++++++
> sysdeps/loongarch/fpu/s_finitef.c | 30 +++++++++
> sysdeps/loongarch/fpu/s_fmaximum.c | 40 ++++++++++++
> sysdeps/loongarch/fpu/s_fmaximum_mag.c | 40 ++++++++++++
> sysdeps/loongarch/fpu/s_fmaximum_mag_num.c | 48 +++++++++++++++
> sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c | 48 +++++++++++++++
> sysdeps/loongarch/fpu/s_fmaximum_magf.c | 40 ++++++++++++
> sysdeps/loongarch/fpu/s_fmaximum_num.c | 48 +++++++++++++++
> sysdeps/loongarch/fpu/s_fmaximum_numf.c | 49 +++++++++++++++
> sysdeps/loongarch/fpu/s_fmaximumf.c | 40 ++++++++++++
> sysdeps/loongarch/fpu/s_fmaxmag.c | 29 +++++++++
> sysdeps/loongarch/fpu/s_fmaxmagf.c | 29 +++++++++
> sysdeps/loongarch/fpu/s_fminimum.c | 40 ++++++++++++
> sysdeps/loongarch/fpu/s_fminimum_mag.c | 40 ++++++++++++
> sysdeps/loongarch/fpu/s_fminimum_mag_num.c | 48 +++++++++++++++
> sysdeps/loongarch/fpu/s_fminimum_mag_numf.c | 48 +++++++++++++++
> sysdeps/loongarch/fpu/s_fminimum_magf.c | 40 ++++++++++++
> sysdeps/loongarch/fpu/s_fminimum_num.c | 48 +++++++++++++++
> sysdeps/loongarch/fpu/s_fminimum_numf.c | 48 +++++++++++++++
> sysdeps/loongarch/fpu/s_fminimumf.c | 40 ++++++++++++
> 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_isinf.c | 30 +++++++++
> sysdeps/loongarch/fpu/s_isinff.c | 30 +++++++++
> sysdeps/loongarch/fpu/s_isnan.c | 31 ++++++++++
> sysdeps/loongarch/fpu/s_isnanf.c | 31 ++++++++++
> 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 ++++++
> 46 files changed, 1650 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_finite.c
> create mode 100644 sysdeps/loongarch/fpu/s_finitef.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_isinf.c
> create mode 100644 sysdeps/loongarch/fpu/s_isinff.c
> create mode 100644 sysdeps/loongarch/fpu/s_isnan.c
> create mode 100644 sysdeps/loongarch/fpu/s_isnanf.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
>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-11-11 4:02 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 14:05 [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ } Xiaolin Tang
2022-11-07 14:38 ` Xi Ruoyao
2022-11-07 16:36 ` Adhemerval Zanella Netto
2022-11-07 14:05 ` [PATCH v2 02/10] LoongArch: Use __builtin_{fma, fmaf} to implement function {fma, fmaf} Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 03/10] LoongArch: Hard Float Support for float-point classification functions Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 04/10] LoongArch: Hard Float Support for functions logb{f/ }, __ieee754_ilogb{f/ } Xiaolin Tang
2022-11-07 14:05 ` [PATCH v2 05/10] LoongArch: Hard Float Support for functions scalb{f/ }, scalbn{f/ } Xiaolin Tang
2022-11-08 3:46 ` Xi Ruoyao
2022-11-07 14:05 ` [PATCH v2 06/10] LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ } Xiaolin Tang
2022-11-11 4:02 ` [PATCH v2 00/10] LoongArch: Hard Float Support Of Math Functions caiyinyu
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).