aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-12-26 16:42:04 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-12-27 10:22:29 -0300
commit96af11c2077c95860317169303c3ce25bcc0f43f (patch)
treee448545108dfdb4f79418c22f8bdf835f3268048
parent59eae17fbaa629fb02cc57a8889624d6393b56cf (diff)
downloadglibc-96af11c2077c95860317169303c3ce25bcc0f43f.tar
glibc-96af11c2077c95860317169303c3ce25bcc0f43f.tar.gz
glibc-96af11c2077c95860317169303c3ce25bcc0f43f.tar.bz2
glibc-96af11c2077c95860317169303c3ce25bcc0f43f.zip
mips: Implement ceil with hardware floating-point rounding instruction
-rw-r--r--sysdeps/mips/fpu/round_to_integer.h68
-rw-r--r--sysdeps/mips/fpu/s_ceil.c36
-rw-r--r--sysdeps/mips/mips32/Implies1
-rw-r--r--sysdeps/mips/mips64/Implies1
4 files changed, 106 insertions, 0 deletions
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