From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 5DCAF385840A; Tue, 26 Dec 2023 20:06:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DCAF385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1703621183; bh=+SxaNpNqO1u2OL6wqD3dj+kNLwCSbRKq6j3hi8NmhSQ=; h=From:To:Subject:Date:From; b=nv2OS85ojRIsgUBtec/bgXen+GFnJeaJwk6ekNH7W/FGA+69QnCxZ596sZJyfrY8J Ei3YFPGsb8TozbwHltUwbJc2rqI3qop8eNaOFIQr5vh7ME4Cq9pXlIRhHBOVGvKlVj i04eStTNIEtd0QgOG4jGxcfKyjHRGY4bB+c+2OBo= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/mips-hw-fp-round] mips: Implement ceil with hardware floating-point rounding instruction X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/mips-hw-fp-round X-Git-Oldrev: bd62e3fe20f2693342f861dfcceee61ed917d3a4 X-Git-Newrev: aa380931b0f1a6888dec548532a5b15d36631ac3 Message-Id: <20231226200623.5DCAF385840A@sourceware.org> Date: Tue, 26 Dec 2023 20:06:23 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=aa380931b0f1a6888dec548532a5b15d36631ac3 commit aa380931b0f1a6888dec548532a5b15d36631ac3 Author: Adhemerval Zanella 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 + . */ + +#ifndef _ROUND_TO_INTEGER_H +#define _ROUND_TO_INTEGER_H + +#include +#include + +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 + . */ + +#if ((__mips_fpr == 64) \ + && (__mips_hard_float == 1) \ + && ((__mips == 32 && __mips_isa_rev > 1) || __mips == 64)) + +#define NO_MATH_REDIRECT +#include +#include +#include + +double +__ceil (double x) +{ + return round_to_integer_double (CEIL, x); +} +libm_alias_double (__ceil, ceil) +#else +# include +#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