From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 5D82F395B06A for ; Wed, 16 Nov 2022 14:39:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D82F395B06A 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=1668609562; bh=EixAKw1EiRs+6i0wOHthtx8RD54JG7ZfUfWan4X1VXw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=H4qn6evDVPbyyhfVCT6qUU/ilRJy7DAMC2v3hVv/QRALgwNt1ScBWAn6pDf2z++hI jqnqL1aNdi3PXQhiz5WBFOd16iLbi7GDVctIIXcZuLxwWJlXzN7uenSebMluApYtHb Gt38wbnP5GYx83zW2YohSCXrRcUexX8X6ga+n884= Received: from [IPv6:240e:358:116a:f400:dc73:854d:832e:2] (unknown [IPv6:240e:358:116a:f400:dc73:854d:832e:2]) (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 3B3DC66848; Wed, 16 Nov 2022 09:39:16 -0500 (EST) Message-ID: Subject: Re: [PATCH v2 0/4] LoongArch: Add some floating-point operations From: Xi Ruoyao To: tangxiaolin , libc-alpha@sourceware.org Cc: Lulu Cheng , Wang Xuerui , Chenghua Xu , caiyinyu@loongson.cn Date: Wed, 16 Nov 2022 22:39:06 +0800 In-Reply-To: <040b20f8-c94c-859e-34c5-fe4e0eef4da5@loongson.cn> References: <20221109135329.952128-1-xry111@xry111.site> <1a465d2a0bea2a47aadaa727c0689ac48d5982c5.camel@xry111.site> <235d9f8e-040c-2917-8444-654b33aa124e@loongson.cn> <3520c6e178315f94e38ce334e66432e4b0ccab2a.camel@xry111.site> <040b20f8-c94c-859e-34c5-fe4e0eef4da5@loongson.cn> 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=0.9 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD,KAM_SHORT,LIKELY_SPAM_FROM,PDS_OTHER_BAD_TLD,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no 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 Wed, 2022-11-16 at 21:00 +0800, tangxiaolin wrote: > I notice that use __builtin_lrint to expand __lrint to: > =C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 ftint.l.d=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 $fa0, $fa0 > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0 movfr2gr.d=C2=A0 =C2=A0=C2=A0=C2= =A0 $a0, $fa0 > =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0 jirl=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 $zero, $ra, 0 >=20 > Operations of 'ftint.l.d'=C2=A0 is convertToIntegerExactTiesToEven(x)/= =20 > convertToIntegerExactTowardZero(x)/convertToIntegerExactTowardPositive > (x)/convertToIntegerExactTowardNegative(x) according to FCSR > RM(LoongArch Manual). >=20 > However, the operation of function rint, lrint, llrint is > roundToIntegralExact according to=C2=A0 ISO/IEC TS 18661-1: 2014 and The > GNU C Library Reference Manual. It's a little bit difference between > those two operations, but we still can pass all testcases so far. I'm > a little worried about it. (As we know that operations of=C2=A0 > 'frint.{d,s}' is exactly roundToIntegralExact, however we=20 > discard it.) TS 18661 says: =E2=80=94 The lrint and llrint functions in provide the IEC 605= 59 conversions, which honor the directed rounding mode, from floating point to the long int an= d long long int integer formats. The lrint and llrint functions can be used to implement= IEC 60559 conversions from floating to other integer formats. Note that it mentions "conversions" explicitly. In IEC 60559 convertToInteger* are called "conversions", but roundToIntegral* are just called "rounding operations". And the plural form of "conversions" also suggests that we need to pick a proper conversion operation according to the rounding mode. So I think the semantics of lrint aligns with ftint.{s/d}. >=20 >=20 >=20 > =E5=9C=A8 2022/11/14 =E4=B8=8B=E5=8D=884:05, Xi Ruoyao =E5=86=99=E9=81=93= : > > On Mon, 2022-11-14 at 10:41 +0800, tangxiaolin wrote: > > > How about I do this work on Glibc? > > [Moving the discussion to libc-alpha.] > >=20 > > Go for it.=C2=A0 I'm attaching my draft patches and you can use them as= a > > starting point. > >=20 > > rint change is trivial.=C2=A0 for lrint and llrint I'm not sure if we > > should > > add USE_LRINTL_BUILTIN and USE_LRINTF128_BUILTIN (with zero value) > > as > > well.=C2=A0 Likewise for logb. > >=20 > > scalbn is a little complicated: I'd prefer to expand M_SCALBN to > > __builtin_scalbn directly instead of calling __scalbn (to avoid the > > overhead calling a function with only two instructions) but it seems > > not > > easy: some files calling M_SCALBN are compiled with -fmath-errno, > > with > > which the compiler will refuse to expand __builtin_scalbn. > >=20 > > > =E5=9C=A8 2022/11/12 =E4=B8=8B=E5=8D=883:08, Xi Ruoyao =E5=86=99=E9= =81=93: > > > > On Wed, 2022-11-09 at 21:53 +0800, Xi Ruoyao wrote: > > > > > These patches allow to expand the following builtins to > > > > > floating > > > > > point > > > > > instructions for LoongArch: > > > > >=20 > > > > > - __builtin_rint{,f} > > > > > - __builtin_{l,ll}rint{,f} > > > > > - __builtin_{l,ll}floor{,f} > > > > > - __builtin_{l,ll}ceil{,f} > > > > > - __builtin_scalb{n,ln}{,f} > > > > > - __builtin_logb{,f} > > > > >=20 > > > > > Bootstrapped and regtested on loongarch64-linux-gnu.=C2=A0 And a > > > > > modified > > > > > Glibc using the builtins for rint{,f}, {l,ll}rint{,f}, and > > > > > logb{,f} > > > > > also survived Glibc test suite. > > > > >=20 > > > > > Please review ASAP because GCC 13 stage 1 will end on Nov. > > > > > 13th. > > > > >=20 > > > > > v1 -> v2: Only use ftint{rm,rp} instructions if floor and ceil > > > > > are > > > > > allowed to raise inexact exception. > > > > >=20 > > > > > Xi Ruoyao (4): > > > > > =C2=A0=C2=A0=C2=A0 LoongArch: Rename frint_ to rint2 > > > > > =C2=A0=C2=A0=C2=A0 LoongArch: Add ftint{,rm,rp}.{w,l}.{s,d} instr= uctions > > > > > =C2=A0=C2=A0=C2=A0 LoongArch: Add fscaleb.{s,d} instructions as l= dexp{sf,df}3 > > > > > =C2=A0=C2=A0=C2=A0 LoongArch: Add flogb.{s,d} instructions and ex= pand > > > > > logb{sf,df}2 > > > > >=20 > > > > > =C2=A0=C2=A0=C2=A0gcc/config/loongarch/loongarch.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 | 95 > > > > > ++++++++++++++++++- > > > > > =C2=A0=C2=A0=C2=A0gcc/testsuite/gcc.target/loongarch/flogb.c=C2= =A0=C2=A0=C2=A0 | 18 ++++ > > > > > =C2=A0=C2=A0=C2=A0gcc/testsuite/gcc.target/loongarch/frint.c=C2= =A0=C2=A0=C2=A0 | 16 ++++ > > > > > =C2=A0=C2=A0=C2=A0gcc/testsuite/gcc.target/loongarch/fscaleb.c=C2= =A0 | 48 > > > > > ++++++++++ > > > > > =C2=A0=C2=A0=C2=A0.../gcc.target/loongarch/ftint-no-inexact.c=C2= =A0=C2=A0 | 44 > > > > > +++++++++ > > > > > =C2=A0=C2=A0=C2=A0gcc/testsuite/gcc.target/loongarch/ftint.c=C2= =A0=C2=A0=C2=A0 | 44 > > > > > +++++++++ > > > > > =C2=A0=C2=A0=C2=A06 files changed, 261 insertions(+), 4 deletions= (-) > > > > > =C2=A0=C2=A0=C2=A0create mode 100644 > > > > > gcc/testsuite/gcc.target/loongarch/flogb.c > > > > > =C2=A0=C2=A0=C2=A0create mode 100644 > > > > > gcc/testsuite/gcc.target/loongarch/frint.c > > > > > =C2=A0=C2=A0=C2=A0create mode 100644 > > > > > gcc/testsuite/gcc.target/loongarch/fscaleb.c > > > > > =C2=A0=C2=A0=C2=A0create mode 100644 > > > > > gcc/testsuite/gcc.target/loongarch/ftint-no- > > > > > inexact.c > > > > > =C2=A0=C2=A0=C2=A0create mode 100644 > > > > > gcc/testsuite/gcc.target/loongarch/ftint.c > > > > >=20 > > > > Pushed r13-3922. > > > >=20 > > > > I'll be busy in the following week.=C2=A0 Will do the work on Glibc > > > > side > > > > after Nov. 20. > > > >=20 >=20 --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University