From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 6936E3858D35 for ; Wed, 9 Nov 2022 09:48:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6936E3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1667987337; bh=HV7ylS18/H42br5BI7EPCN5rQ1nzk/jD+VDnktk3OiI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=WZJsgst3IY0lhEkeam94X98rP3s1/Rja3lsIsYTePgoiyLl6d8nDlAHRKb4My0Ki7 EQE4hIUFJfAFyKH6mYQEHZkeOkcGA87d+5MGCU0JMWUnQMVdIVDhB6gzjMxJQarUWX is6e8tWNxAxX8noERZ1yn7MVKyFecHpzDr4ZN+1Q= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 50CD866931; Wed, 9 Nov 2022 04:48:56 -0500 (EST) Message-ID: <969e3de24c8e674ad93854252e77e1906cde420e.camel@xry111.site> Subject: Re: [PATCH v2] RISC-V missing __builtin_lceil and __builtin_lfloor From: Xi Ruoyao To: Kevin Lee , gcc-patches@gcc.gnu.org Cc: palmer@dabbelt.com, kito.cheng@gmail.com, gnu-toolchain@rivosinc.com Date: Wed, 09 Nov 2022 17:48:54 +0800 In-Reply-To: <20221108043657.2064455-1-kevinl@rivosinc.com> References: <20221108043657.2064455-1-kevinl@rivosinc.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,GIT_PATCH_0,KAM_SHORT,LIKELY_SPAM_FROM,PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 2022-11-07 at 20:36 -0800, Kevin Lee wrote: > The patch in=20 > https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599755.html=C2=A0wa= s > corrupted. I am resending the cleaner version as patch v2. Thank you!=20 Hi Kevin, I "shamelessly copied" your idea in https://gcc.gnu.org/pipermail/gcc-patches/2022-November/605456.html.=20 During the review we found an issue. Consider $ cat x.c long x(double d) { return __builtin_ceil(d); } With the patch: $ ./gcc/cc1 x.c -nostdinc -mabi=3Dlp64d -march=3Drv64g -O -fno-fp-int-built= in-inexact $ cat x.s .file "x.c" .option nopic .text .align 2 .globl x .type x, @function x: fcvt.l.d a0,fa0,rup ret .size x, .-x .ident "GCC: (GNU) 13.0.0 20221109 (experimental)" .section .note.GNU-stack,"",@progbits -fno-fp-int-builtin-inexact does not allow __builtin_ceil to raise inexact exception. But fcvt.l.d may raise one. > gcc/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Michael Collison > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* config/riscv/iterators.= md (RINT): Additional iterators. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(rint_pattern): Additiona= l attributes. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(rint_rm): Ditto. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* config/riscv/riscv.md: = New attributes. >=20 > gcc/testsuite/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Kevin Lee > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* gcc.target/riscv/lfloor= -lceil.c: New test. > --- > =C2=A0gcc/config/riscv/iterators.md=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 8 +- > =C2=A0gcc/config/riscv/riscv.md=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0 3 + > =C2=A0gcc/testsuite/gcc.target/riscv/lfloor-lceil.c | 79 > +++++++++++++++++++ > =C2=A03 files changed, 87 insertions(+), 3 deletions(-) > =C2=A0create mode 100644 gcc/testsuite/gcc.target/riscv/lfloor-lceil.c >=20 > diff --git a/gcc/config/riscv/iterators.md > b/gcc/config/riscv/iterators.md > index 50380ecfac9..3dd705eaf81 100644 > --- a/gcc/config/riscv/iterators.md > +++ b/gcc/config/riscv/iterators.md > @@ -233,9 +233,11 @@ (define_code_attr bitmanip_insn [(smin "min") > =C2=A0;; ----------------------------------------------------------------= -- > - > =C2=A0 > =C2=A0;; Iterator and attributes for floating-point rounding instructions= . > -(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND]) > -(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > "round")]) > -(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND > "rmm")]) > +(define_int_iterator RINT [UNSPEC_LRINT UNSPEC_LROUND UNSPEC_LCEIL > UNSPEC_LFLOOR]) > +(define_int_attr rint_pattern [(UNSPEC_LRINT "rint") (UNSPEC_LROUND > "round") > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 (UNSPEC_LCEIL "ceil") (UNSPEC_LFLOOR > "floor")]) > +(define_int_attr rint_rm [(UNSPEC_LRINT "dyn") (UNSPEC_LROUND "rmm") > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (UNSPEC_= LCEIL "rup") (UNSPEC_LFLOOR "rdn")]) > =C2=A0 > =C2=A0;; Iterator and attributes for quiet comparisons. > =C2=A0(define_int_iterator QUIET_COMPARISON [UNSPEC_FLT_QUIET > UNSPEC_FLE_QUIET]) > diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md > index 798f7370a08..07e72af8950 100644 > --- a/gcc/config/riscv/riscv.md > +++ b/gcc/config/riscv/riscv.md > @@ -60,6 +60,9 @@ (define_c_enum "unspec" [ > =C2=A0=C2=A0 UNSPEC_FMIN > =C2=A0=C2=A0 UNSPEC_FMAX > =C2=A0 > +=C2=A0 UNSPEC_LCEIL > +=C2=A0 UNSPEC_LFLOOR > + > =C2=A0=C2=A0 ;; Stack tie > =C2=A0=C2=A0 UNSPEC_TIE > =C2=A0]) > diff --git a/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > new file mode 100644 > index 00000000000..4715de746fb > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/lfloor-lceil.c > @@ -0,0 +1,79 @@ > +/* { dg-do compile } */ > +/* { dg-options "-march=3Drv64gc -mabi=3Dlp64d" } */ > +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ > + > +int > +ceil1(float i) > +{ > +=C2=A0 return __builtin_lceil(i); > +} > + > +long > +ceil2(float i) > +{ > +=C2=A0 return __builtin_lceil(i); > +} > + > +long long > +ceil3(float i) > +{ > +=C2=A0 return __builtin_lceil(i); > +} > + > +int > +ceil4(double i) > +{ > +=C2=A0 return __builtin_lceil(i); > +} > + > +long > +ceil5(double i) > +{ > +=C2=A0 return __builtin_lceil(i); > +} > + > +long long > +ceil6(double i) > +{ > +=C2=A0 return __builtin_lceil(i); > +} > + > +int > +floor1(float i) > +{ > +=C2=A0 return __builtin_lfloor(i); > +} > + > +long > +floor2(float i) > +{ > +=C2=A0 return __builtin_lfloor(i); > +} > + > +long long > +floor3(float i) > +{ > +=C2=A0 return __builtin_lfloor(i); > +} > + > +int > +floor4(double i) > +{ > +=C2=A0 return __builtin_lfloor(i); > +} > + > +long > +floor5(double i) > +{ > +=C2=A0 return __builtin_lfloor(i); > +} > + > +long long > +floor6(double i) > +{ > +=C2=A0 return __builtin_lfloor(i); > +} > + > +/* { dg-final { scan-assembler-times "fcvt.l.s" 6 } } */ > +/* { dg-final { scan-assembler-times "fcvt.l.d" 6 } } */ > +/* { dg-final { scan-assembler-not "call" } } */ --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University