From: LIU Hao <lh_mouse@126.com>
To: Hashan Gayasri <hashan.gayasri@gmail.com>, gcc-help@gcc.gnu.org
Subject: Re: pragma GCC optimize prevents inlining
Date: Thu, 4 Jan 2024 17:27:51 +0800 [thread overview]
Message-ID: <38c39ae1-d017-4cf4-a48c-797a273f50a5@126.com> (raw)
In-Reply-To: <CAA6G1fpuHiyDYne5=psCJO0A+gRAbaP65we1UBQjJDcrenDeQw@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 976 bytes --]
在 2024/1/4 17:01, Hashan Gayasri via Gcc-help 写道:
> I wanted the following to be to be optimized:
>
> (... ...)
>
> So that std::lrint uses the vcvtsd2si instruction on X86 with SSE2. It
> does that but prevents the instruction from being inlined. I complied with
> - O3 -march=native -DNDEBUG.
Actually `-ffast-math` is an overkill; `-fno-math-errno` isn't practically bad, and can be enabled
globally:
(https://gcc.godbolt.org/z/hhfP6cYrr)
```
//#pragma GCC push_options
//#pragma GCC optimize ("-ffast-math")
inline int64_t __attribute__ ((const)) RoundToNearestLong (double v)
{
// assert(fegetround() == FE_TONEAREST);
return lrint(v);
}
//#pragma GCC pop_options
void
xgset(int64_t& r, double s)
{
r = RoundToNearestLong(s);
}
```
results in
```
xgset(long&, double):
vcvtsd2si rax, xmm0
mov QWORD PTR [rdi], rax
ret
```
--
Best regards,
LIU Hao
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2024-01-04 9:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-04 9:01 Hashan Gayasri
2024-01-04 9:27 ` LIU Hao [this message]
2024-01-05 0:56 ` Hashan Gayasri
2024-01-04 14:51 ` David Brown
2024-01-04 15:03 ` Segher Boessenkool
2024-01-04 15:24 ` David Brown
2024-01-04 16:37 ` Richard Earnshaw
2024-01-09 13:38 ` Florian Weimer
2024-01-04 16:55 ` Segher Boessenkool
2024-01-05 14:24 ` David Brown
2024-01-05 15:00 ` Segher Boessenkool
2024-01-05 15:53 ` David Brown
2024-01-05 18:19 ` Segher Boessenkool
2024-01-06 17:02 ` David Brown
2024-01-07 17:51 ` Segher Boessenkool
2024-01-07 18:36 ` Gabriel Ravier
2024-01-08 15:53 ` David Brown
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=38c39ae1-d017-4cf4-a48c-797a273f50a5@126.com \
--to=lh_mouse@126.com \
--cc=gcc-help@gcc.gnu.org \
--cc=hashan.gayasri@gmail.com \
/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).