public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/mips-hw-fp-round] mips: Implement ceil with hardware floating-point rounding instruction
@ 2023-12-26 20:06 Adhemerval Zanella
0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2023-12-26 20:06 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=aa380931b0f1a6888dec548532a5b15d36631ac3
commit aa380931b0f1a6888dec548532a5b15d36631ac3
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Dec 26 16:42:04 2023 -0300
mips: Implement ceil with hardware floating-point rounding instruction
Diff:
---
sysdeps/mips/fpu/round_to_integer.h | 68 +++++++++++++++++++++++++++++++++++++
sysdeps/mips/fpu/s_ceil.c | 36 ++++++++++++++++++++
sysdeps/mips/mips64/Implies | 1 +
3 files changed, 105 insertions(+)
diff --git a/sysdeps/mips/fpu/round_to_integer.h b/sysdeps/mips/fpu/round_to_integer.h
new file mode 100644
index 0000000000..7ac6783e54
--- /dev/null
+++ b/sysdeps/mips/fpu/round_to_integer.h
@@ -0,0 +1,68 @@
+/* Round to integer generic implementation.
+ Copyright (C) 2023 Free Software .
+ 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/>. */
+
+#ifndef _ROUND_TO_INTEGER_H
+#define _ROUND_TO_INTEGER_H
+
+#include <fenv_private.h>
+#include <sysdeps/ieee754/dbl-64/math_config.h>
+
+enum round_mode
+{
+ CEIL,
+};
+
+static inline double
+round_to_integer_double (enum round_mode mode, double x)
+{
+ uint64_t hx = asuint64 (x);
+ int ex = (hx & ~SIGN_MASK) >> MANTISSA_WIDTH;
+
+ double r = x;
+
+ fenv_t fe;
+ libc_feholdexcept (&fe);
+ switch (mode)
+ {
+ case CEIL:
+ asm ("ceil.l.d %0, %0" : "+f" (r));
+ break;
+ }
+ libc_fesetenv (&fe);
+
+ /* Inf or NaN. */
+ if (__glibc_unlikely (ex == 0x7ff))
+ return x + x;
+
+ /* Number input and no fraction, return the number itself. */
+ if (ex >= 1024 + 53)
+ return x;
+
+ asm ("cvt.d.l %0, %1\n" : "+f" (r));
+ /* The copysign seems to generate better code. */
+#if 1
+ return copysign (r, x);
+#else
+ bool sign = hx & SIGN_MASK;
+ if (ex >= 1023)
+ return r;
+ return sign ? -r : r;
+#endif
+}
+
+#endif
diff --git a/sysdeps/mips/fpu/s_ceil.c b/sysdeps/mips/fpu/s_ceil.c
new file mode 100644
index 0000000000..ed79cb6dd9
--- /dev/null
+++ b/sysdeps/mips/fpu/s_ceil.c
@@ -0,0 +1,36 @@
+/* Round to nearest integer, away from zero. MIPS version.
+ Copyright (C) 2023 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/>. */
+
+#if ((__mips_fpr == 64) \
+ && (__mips_hard_float == 1) \
+ && ((__mips == 32 && __mips_isa_rev > 1) || __mips == 64))
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <round_to_integer.h>
+#include <libm-alias-double.h>
+
+double
+__ceil (double x)
+{
+ return round_to_integer_double (CEIL, x);
+}
+libm_alias_double (__ceil, ceil)
+#else
+# include <sysdeps/ieee754/dbl-64/s_ceil.c>
+#endif
diff --git a/sysdeps/mips/mips64/Implies b/sysdeps/mips/mips64/Implies
index 826ff1541f..8885ebd564 100644
--- a/sysdeps/mips/mips64/Implies
+++ b/sysdeps/mips/mips64/Implies
@@ -1,4 +1,5 @@
# MIPS uses IEEE 754 floating point.
+mips/fpu
mips/ieee754
ieee754/flt-32
ieee754/dbl-64
^ permalink raw reply [flat|nested] 2+ messages in thread
* [glibc/azanella/mips-hw-fp-round] mips: Implement ceil with hardware floating-point rounding instruction
@ 2023-12-27 13:23 Adhemerval Zanella
0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2023-12-27 13:23 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=96af11c2077c95860317169303c3ce25bcc0f43f
commit 96af11c2077c95860317169303c3ce25bcc0f43f
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Tue Dec 26 16:42:04 2023 -0300
mips: Implement ceil with hardware floating-point rounding instruction
Diff:
---
sysdeps/mips/fpu/round_to_integer.h | 68 +++++++++++++++++++++++++++++++++++++
sysdeps/mips/fpu/s_ceil.c | 36 ++++++++++++++++++++
sysdeps/mips/mips32/Implies | 1 +
sysdeps/mips/mips64/Implies | 1 +
4 files changed, 106 insertions(+)
diff --git a/sysdeps/mips/fpu/round_to_integer.h b/sysdeps/mips/fpu/round_to_integer.h
new file mode 100644
index 0000000000..7ac6783e54
--- /dev/null
+++ b/sysdeps/mips/fpu/round_to_integer.h
@@ -0,0 +1,68 @@
+/* Round to integer generic implementation.
+ Copyright (C) 2023 Free Software .
+ 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/>. */
+
+#ifndef _ROUND_TO_INTEGER_H
+#define _ROUND_TO_INTEGER_H
+
+#include <fenv_private.h>
+#include <sysdeps/ieee754/dbl-64/math_config.h>
+
+enum round_mode
+{
+ CEIL,
+};
+
+static inline double
+round_to_integer_double (enum round_mode mode, double x)
+{
+ uint64_t hx = asuint64 (x);
+ int ex = (hx & ~SIGN_MASK) >> MANTISSA_WIDTH;
+
+ double r = x;
+
+ fenv_t fe;
+ libc_feholdexcept (&fe);
+ switch (mode)
+ {
+ case CEIL:
+ asm ("ceil.l.d %0, %0" : "+f" (r));
+ break;
+ }
+ libc_fesetenv (&fe);
+
+ /* Inf or NaN. */
+ if (__glibc_unlikely (ex == 0x7ff))
+ return x + x;
+
+ /* Number input and no fraction, return the number itself. */
+ if (ex >= 1024 + 53)
+ return x;
+
+ asm ("cvt.d.l %0, %1\n" : "+f" (r));
+ /* The copysign seems to generate better code. */
+#if 1
+ return copysign (r, x);
+#else
+ bool sign = hx & SIGN_MASK;
+ if (ex >= 1023)
+ return r;
+ return sign ? -r : r;
+#endif
+}
+
+#endif
diff --git a/sysdeps/mips/fpu/s_ceil.c b/sysdeps/mips/fpu/s_ceil.c
new file mode 100644
index 0000000000..ed79cb6dd9
--- /dev/null
+++ b/sysdeps/mips/fpu/s_ceil.c
@@ -0,0 +1,36 @@
+/* Round to nearest integer, away from zero. MIPS version.
+ Copyright (C) 2023 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/>. */
+
+#if ((__mips_fpr == 64) \
+ && (__mips_hard_float == 1) \
+ && ((__mips == 32 && __mips_isa_rev > 1) || __mips == 64))
+
+#define NO_MATH_REDIRECT
+#include <math.h>
+#include <round_to_integer.h>
+#include <libm-alias-double.h>
+
+double
+__ceil (double x)
+{
+ return round_to_integer_double (CEIL, x);
+}
+libm_alias_double (__ceil, ceil)
+#else
+# include <sysdeps/ieee754/dbl-64/s_ceil.c>
+#endif
diff --git a/sysdeps/mips/mips32/Implies b/sysdeps/mips/mips32/Implies
index 6473f2517c..71b3678c6c 100644
--- a/sysdeps/mips/mips32/Implies
+++ b/sysdeps/mips/mips32/Implies
@@ -1,3 +1,4 @@
+mips/fpu
mips/ieee754
mips
wordsize-32
diff --git a/sysdeps/mips/mips64/Implies b/sysdeps/mips/mips64/Implies
index 826ff1541f..8885ebd564 100644
--- a/sysdeps/mips/mips64/Implies
+++ b/sysdeps/mips/mips64/Implies
@@ -1,4 +1,5 @@
# MIPS uses IEEE 754 floating point.
+mips/fpu
mips/ieee754
ieee754/flt-32
ieee754/dbl-64
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-27 13:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 20:06 [glibc/azanella/mips-hw-fp-round] mips: Implement ceil with hardware floating-point rounding instruction Adhemerval Zanella
2023-12-27 13:23 Adhemerval Zanella
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).