From: chenglulu <chenglulu@loongson.cn>
To: Xi Ruoyao <xry111@xry111.site>, Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, Uros Bizjak <ubizjak@gmail.com>,
i@xen0n.name, xuchenghua@loongson.cn
Subject: Re: [PATCH v3 1/5] LoongArch: Fix usage of LSX and LASX frint/ftint instructions [PR112578]
Date: Fri, 24 Nov 2023 17:46:38 +0800 [thread overview]
Message-ID: <97012389-18f1-97ee-24b3-778c5728aa54@loongson.cn> (raw)
In-Reply-To: <1ab40b49c384517ca38f528fda96e688eae210db.camel@xry111.site>
在 2023/11/24 下午4:42, Xi Ruoyao 写道:
> On Fri, 2023-11-24 at 16:36 +0800, chenglulu wrote:
>> 在 2023/11/24 下午4:26, Xi Ruoyao 写道:
>>> On Fri, 2023-11-24 at 16:01 +0800, chenglulu wrote:
>>>> I only saw lrint llrint in n2310 with this description:
>>>>
>>>> F7.12.9.5
>>>>
>>>> "The lrint and llrint functions round their argument to the nearest
>>>> integer value, rounding
>>>> according to the current rounding direction. If the rounded value is
>>>> outside the range of the return
>>>> type, the numeric result is unspecified and a domain error or range
>>>> error may occur."
>>>>
>>>> I don't know if I'm right?
>>> There's an explanation in the linux man-page for lrint:
>>>
>>> SUSv2 and POSIX.1‐2001 contain text about overflow (which might set er‐
>>> rno to ERANGE, or raise an FE_OVERFLOW exception). In practice, the
>>> result cannot overflow on any current machine, so this error‐handling
>>> stuff is just nonsense. (More precisely, overflow can happen only when
>>> the maximum value of the exponent is smaller than the number of man‐
>>> tissa bits. For the IEEE‐754 standard 32‐bit and 64‐bit floating‐point
>>> numbers the maximum value of the exponent is 127 (respectively, 1023),
>>> and the number of mantissa bits including the implicit bit is 24 (re‐
>>> spectively, 53).)
>>>
>> This is the description of rint rintf rintl in the linux man-page.:-(
> Phew, I misread the message.
>
> Yes, for lrint we assume it may set errno. For example:
>
> long x[4];
> double y[4];
>
> void test()
> {
> for (int i = 0; i < 4; i++)
> x[i] = __builtin_lrint(y[i]);
> }
>
> We produce a loop calling lrint with -O2 -mlasx:
>
> .L2:
> fldx.d $f0,$r26,$r23
> bl %plt(lrint)
> stx.d $r4,$r25,$r23
> addi.d $r23,$r23,8
> bne $r23,$r24,.L2
>
> because using xvftint.l.d may miss an errno from the libc. Only with -
> O2 -mlasx -fno-math-errno xvftint.l.d is emitted.
>
> But for
>
> long x[4];
> double y[4];
>
> void test()
> {
> for (int i = 0; i < 4; i++)
> x[i] = (long) __builtin_rint(y[i]);
> }
>
> we know rint does not set errno, and converting a double to long does
> not set errno, so using xvftint.l.d is correct.
>
> On the contrary, we cannot optimize it to the first example because it
> may cause an errno to be mistakenly set when the libc sets errno for
> lrint. That's why the generic code only transforms (int)rintf -> irintf
> or (long)rint -> lrint when -ffast-math.
>
> But this limitation does not apply for the xvftint.l.d instruction (as
> xvftint.l.d is just an instruction and it does not know errno at all).
>
Yeah, I know what you mean. That is, our handling of errno and exception
flag bits
before and after optimization is unchanged, then the optimization is no
problem.
So I agree with your optimization.
It's just that I'm confused that the description of rint in n2310,
including Joseph's email,
all say that rint will not set errno, but linux-man says "which might
set errno to ERANGE" .
The two aspects about rint lrint's handling of errno are opposite.
next prev parent reply other threads:[~2023-11-24 9:46 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 0:47 [PATCH v3 0/5] LoongArch: SIMD fixes and optimizations Xi Ruoyao
2023-11-20 0:47 ` [PATCH v3 1/5] LoongArch: Fix usage of LSX and LASX frint/ftint instructions [PR112578] Xi Ruoyao
2023-11-23 6:35 ` chenglulu
2023-11-23 7:11 ` Xi Ruoyao
2023-11-23 7:31 ` chenglulu
2023-11-23 8:13 ` chenglulu
2023-11-23 9:02 ` Xi Ruoyao
2023-11-23 9:12 ` chenglulu
2023-11-23 10:12 ` Xi Ruoyao
2023-11-23 12:06 ` Xi Ruoyao
2023-11-23 18:03 ` Joseph Myers
2023-11-24 2:39 ` Xi Ruoyao
2023-11-24 8:01 ` chenglulu
2023-11-24 8:26 ` Xi Ruoyao
2023-11-24 8:36 ` chenglulu
2023-11-24 8:42 ` Xi Ruoyao
2023-11-24 9:46 ` chenglulu [this message]
2023-11-24 10:30 ` Xi Ruoyao
2023-11-24 14:59 ` chenglulu
2023-11-23 8:54 ` Xi Ruoyao
2023-11-20 0:47 ` [PATCH v3 2/5] LoongArch: Use standard pattern name and RTX code for LSX/LASX muh instructions Xi Ruoyao
2023-11-23 12:08 ` chenglulu
2023-11-20 0:47 ` [PATCH v3 3/5] LoongArch: Use standard pattern name and RTX code for LSX/LASX rotate shift Xi Ruoyao
2023-11-23 8:42 ` chenglulu
2023-11-20 0:47 ` [PATCH v3 4/5] LoongArch: Remove lrint_allow_inexact Xi Ruoyao
2023-11-23 8:23 ` chenglulu
2023-11-23 8:58 ` Xi Ruoyao
2023-11-23 9:14 ` chenglulu
2023-11-23 12:24 ` Xi Ruoyao
2023-11-23 14:39 ` chenglulu
2023-11-20 0:47 ` [PATCH v3 5/5] LoongArch: Use LSX for scalar FP rounding with explicit rounding mode Xi Ruoyao
2023-11-29 7:12 ` Pushed: [PATCH v3 0/5] LoongArch: SIMD fixes and optimizations Xi Ruoyao
2023-11-29 7:45 ` chenglulu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=97012389-18f1-97ee-24b3-778c5728aa54@loongson.cn \
--to=chenglulu@loongson.cn \
--cc=gcc-patches@gcc.gnu.org \
--cc=i@xen0n.name \
--cc=joseph@codesourcery.com \
--cc=ubizjak@gmail.com \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).