[v2,01/10] LoongArch: Hard Float Support for functions {ll/l/ }rint{f/ }.
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
Commit Message
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
Comments
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.
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.
new file mode 100644
@@ -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)
new file mode 100644
@@ -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)
new file mode 100644
@@ -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)
new file mode 100644
@@ -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)
new file mode 100644
@@ -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)
new file mode 100644
@@ -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)