Re: pragma GCC optimize prevents inlining

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



在 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: OpenPGP_signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux