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 1C8FB3858C5F for ; Tue, 26 Dec 2023 08:29:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C8FB3858C5F Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1C8FB3858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703579395; cv=none; b=RnUWEGaVvTrtMXAEn5zpH61YhMAQbhCoT9iruYiZhHGIUyMopM4bi89DO8nCDpsYDyTIqWCdWlwTLzhYvfofTPQTMUMo7QT+Vpdpwh09s9h4JIk+ata7f9b5HXyX98PGeFf0rp9UWJSqe2wosKSbZbrSYMgBugKl857JvZZnp9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703579395; c=relaxed/simple; bh=bZKgS1n65G2tWcvmfhoCi6eypEIFCIQ+j/b806s8gOw=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=ZVG1lc/OPPCoL0JRXaYRyt9b6WhdjYqgvXx+hDfcFL3dE/A0vXm3JHEoisxgWZhhpzDJSCejm4BfK4BFG1KGSN8BSp7SQnWMeuuB+uhLtfzu11zSf1bL3qffhmTWkG4z36hUxr7SdQxUOhzRUvoxhYCNKD1sSHYiOPt/InN/W7I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1703579390; bh=bZKgS1n65G2tWcvmfhoCi6eypEIFCIQ+j/b806s8gOw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=X6/Cmrp+jB1Z7s7t5xT0LWnQ+uQsRFIANdnrb+lOXKcSVtxg+cTvvVPCunGBFV3Mj ZCKXK+OXxFhqLHA9NrM49a7t/CSSTKkIx8zXecN4BmsQJVWeRdb5UzG15E/jDYLW8s Q05Yeampb2gF6NDdl1rj/HLwJC7luInepeCev8/k= Received: from [IPv6:240e:358:113a:1b00:dc73:854d:832e:2] (unknown [IPv6:240e:358:113a:1b00: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 69B4E66E1B; Tue, 26 Dec 2023 03:29:45 -0500 (EST) Message-ID: Subject: Re: [PATCH 2/2] MIPS: Hard-float rounding instructions support From: Xi Ruoyao To: Junxian Zhu Cc: libc-alpha@sourceware.org Date: Tue, 26 Dec 2023 16:29:35 +0800 In-Reply-To: References: <20231225103548.1615-2-zhujunxian@oss.cipunited.com> <20231225103548.1615-4-zhujunxian@oss.cipunited.com> Autocrypt: addr=xry111@xry111.site; prefer-encrypt=mutual; keydata=mDMEYnkdPhYJKwYBBAHaRw8BAQdAsY+HvJs3EVKpwIu2gN89cQT/pnrbQtlvd6Yfq7egugi0HlhpIFJ1b3lhbyA8eHJ5MTExQHhyeTExMS5zaXRlPoiTBBMWCgA7FiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQrKrSDhnnEOPHFgD8D9vUToTd1MF5bng9uPJq5y3DfpcxDp+LD3joA3U2TmwA/jZtN9xLH7CGDHeClKZK/ZYELotWfJsqRcthOIGjsdAPuDgEYnkdPhIKKwYBBAGXVQEFAQEHQG+HnNiPZseiBkzYBHwq/nN638o0NPwgYwH70wlKMZhRAwEIB4h4BBgWCgAgFiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwwACgkQrKrSDhnnEOPjXgD/euD64cxwqDIqckUaisT3VCst11RcnO5iRHm6meNIwj0BALLmWplyi7beKrOlqKfuZtCLbiAPywGfCNg8LOTt4iMD Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LIKELY_SPAM_FROM,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 Tue, 2023-12-26 at 10:37 +0800, Junxian Zhu wrote: > =E5=9C=A8 2023/12/25 18:51, Xi Ruoyao =E5=86=99=E9=81=93: > > On Mon, 2023-12-25 at 18:35 +0800, Junxian Zhu wrote: > >=20 > > /* snip */ > >=20 > > > +/* > > > + * ceil(x) > > > + * Return x rounded toward -inf to integral value > > > + * Method: > > > + * Bit twiddling. > > > + */ > > > + > > > +#if ((__mips_fpr =3D=3D 64) && (__mips_hard_float =3D=3D 1) && ((__m= ips =3D=3D 32 && __mips_isa_rev > 1) || __mips =3D=3D 64)) > > > +#include > > > +#include > > > +#include > > > + > > > +ENTRY(__ceil) > > > + .set push > > > + .set noreorder > > > + .set noat > > > +# $f0=3Dret, $f12=3Ddouble, a0=3Dint64/int32_h, a1=3Dint32_l, a2=3Ds= ign, a3=3Dexp > > > +#if __mips =3D=3D 64 > > > + dmfc1=C2=A0=C2=A0 a0, $f12 # assign int64 > > > +#else > > > + mfhc1=C2=A0=C2=A0 a0, $f12 # assign int64 > > > +#endif > > > + cfc1=C2=A0=C2=A0=C2=A0 t0, $f26 > > > + ceil.l.d=C2=A0=C2=A0=C2=A0 $f0, $f12 > > No, C23 does not allow this function to raise an INEXACT exception, but > > ceil.l.d will do so. > >=20 > > Such optimizations should be performed in GCC which can be controlled b= y > > the programmer with -std=3Dc23 and/or -f[no-]fp-int-builtin-inexact, no= t > > in Glibc where we cannot know if the programmer wants to deviate from > > C23. >=20 > The cfc1 instruction will backup float point exception status before=20 > running ceil.l.d, and the following ctc1 will restore float point=20 > exception status to avoid INEXACT exception raised by ceil.l.d. It's the= =20 > same way like what have been done in s_ceil.S for i386. Still incorrect because when the Enable field of FCSR contains INEXACT a SIGFPE will be immediately delivered and there is no way to recover. A demonstration: #define _GNU_SOURCE #include #include int main() { printf("%d\n", feenableexcept(FE_INEXACT)); double data =3D 114.514; long control; asm("cfc1\t%1,$f26\n\t" "ceil.l.d\t%0,%0\n\t" "cvt.d.l\t%0,%0\n\t" "ctc1\t%1,$f26": "+f"(data), "=3Dr"(control)); printf("%.15f\n", data); return 0; } On i386 the fnstenv instruction also masks out all the FP exceptions so this is not a problem. See commit 26b0bf96000a. --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University