public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hashan Gayasri <hashan.gayasri@gmail.com>
To: LIU Hao <lh_mouse@126.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: pragma GCC optimize prevents inlining
Date: Fri, 5 Jan 2024 11:56:04 +1100	[thread overview]
Message-ID: <CAA6G1fpvJMv+PB1=0L5-Y0Gu9EwcZykZ-oi3ywvMtrDiGzSfXg@mail.gmail.com> (raw)
In-Reply-To: <38c39ae1-d017-4cf4-a48c-797a273f50a5@126.com>

[-- Attachment #1: Type: text/plain, Size: 2026 bytes --]

Hi Hao,

Thanks for the suggestion! Yes, - fno-math-errno is definitely more
suitable for enabling globally than -ffast-math.

While I don't particularly remember using errno for math functions in
particularm it's used in non-math functions. So eventhough it seems
reasonable to be enabled globally, still a bit tricky to validate that it
doesn't cause any unintentional side effects with a large codebase with 3rd
parety libs.

Another weird side effect I noticed is GCC still doesn't inline the
function when the function is within a `pragma GCC optimize
("-fno-math-errno") ` region and -ffast-math is enabled globally eventhough
-fno-math-errno is a subset. If you enable both -ffast-math and
-fno-math-errno, globally, the function gets inlined.

I'm not sure if improving that should be considered as a bug-fix or a
feature/enhancement.

Best Regards,
Hashan Gayasri

On Thu, 4 Jan 2024, 8:28 pm LIU Hao, <lh_mouse@126.com> wrote:

> 在 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
>
>

  reply	other threads:[~2024-01-05  0:56 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
2024-01-05  0:56   ` Hashan Gayasri [this message]
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='CAA6G1fpvJMv+PB1=0L5-Y0Gu9EwcZykZ-oi3ywvMtrDiGzSfXg@mail.gmail.com' \
    --to=hashan.gayasri@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=lh_mouse@126.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).