From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 63A7D3858C62; Wed, 27 Dec 2023 13:23:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63A7D3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1703683418; bh=3eqjIgiNAMdaOOzuZi/sJIzXOkIBP1aZeRUTZAxsGq0=; h=From:To:Subject:Date:From; b=UrGibRw/PUU/0K1aXjegVSz3idCKYOvKpwHAMcfoGWajoeXbq6Cb1P66LNMvCsdDu 7eo9aFWp4LlL0taITI6HEoHpxpGvgYwYMU+b1PNPZMTwwnmTRQ0v1Iopk2aoBnvURy 5IYlsCVGhcJ++rEACle6f4K/zHNQzcyYo5esnRzI= 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: 59eae17fbaa629fb02cc57a8889624d6393b56cf X-Git-Newrev: 96af11c2077c95860317169303c3ce25bcc0f43f Message-Id: <20231227132338.63A7D3858C62@sourceware.org> Date: Wed, 27 Dec 2023 13:23:38 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=96af11c2077c95860317169303c3ce25bcc0f43f commit 96af11c2077c95860317169303c3ce25bcc0f43f 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/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 + . */ + +#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/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