public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107458] New: std::fma generates slow scalar-call
@ 2022-10-29 23:33 g.peterhoff@t-online.de
  2022-10-30  0:00 ` [Bug c++/107458] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: g.peterhoff@t-online.de @ 2022-10-29 23:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107458

            Bug ID: 107458
           Summary: std::fma generates slow scalar-call
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: g.peterhoff@t-online.de
  Target Milestone: ---

Please see https://godbolt.org/z/bxxc9ezeM

thx
Gero

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107458] std::fma generates slow scalar-call
  2022-10-29 23:33 [Bug c++/107458] New: std::fma generates slow scalar-call g.peterhoff@t-online.de
@ 2022-10-30  0:00 ` pinskia at gcc dot gnu.org
  2022-10-30  0:02 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30  0:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107458

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 53790
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53790&action=edit
testcase -march=x86-64-v2 -O3 -std=c++20 -Wall -mno-vzeroupper

Please attach the testcase next time instead of just linking to godbolt.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107458] std::fma generates slow scalar-call
  2022-10-29 23:33 [Bug c++/107458] New: std::fma generates slow scalar-call g.peterhoff@t-online.de
  2022-10-30  0:00 ` [Bug c++/107458] " pinskia at gcc dot gnu.org
@ 2022-10-30  0:02 ` pinskia at gcc dot gnu.org
  2022-10-30  0:11 ` pinskia at gcc dot gnu.org
  2022-10-30  0:13 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30  0:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107458

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
fmaf80_manually, fmaf64_manually, and fmaf32_manually are not exactly fma.

at least for x86-64-v2 due not doing the add before the rounding of the
multiply.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107458] std::fma generates slow scalar-call
  2022-10-29 23:33 [Bug c++/107458] New: std::fma generates slow scalar-call g.peterhoff@t-online.de
  2022-10-30  0:00 ` [Bug c++/107458] " pinskia at gcc dot gnu.org
  2022-10-30  0:02 ` pinskia at gcc dot gnu.org
@ 2022-10-30  0:11 ` pinskia at gcc dot gnu.org
  2022-10-30  0:13 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30  0:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107458

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Your definition of fma_manually is broken really.

The following is closer to being correct though there is still an extra
rounding step so it is still not 100%.

inline constexpr float fma_manually(const float a, const float b, const float
c)  noexcept
{
    double
        res = a;

    res *= b;
    res += c;
    return res;
}
inline constexpr double fma_manually(const double a, const double b, const
double 
 c)  noexcept
{
    long double
        res = a;

    res *= b;
    res += c;
    return res;
}

But GCC does the correct thing for fma and fmaf with x86-64-v3 and use the fma
instruction.

So closing as invalid.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107458] std::fma generates slow scalar-call
  2022-10-29 23:33 [Bug c++/107458] New: std::fma generates slow scalar-call g.peterhoff@t-online.de
                   ` (2 preceding siblings ...)
  2022-10-30  0:11 ` pinskia at gcc dot gnu.org
@ 2022-10-30  0:13 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-10-30  0:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107458

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The C++ standard defines fma as doing (a*b) + c in infinite precision (and then
round), this is why GCC cannot inline if your target does not have a FMA
instruction.

There is still no bug here.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-30  0:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-29 23:33 [Bug c++/107458] New: std::fma generates slow scalar-call g.peterhoff@t-online.de
2022-10-30  0:00 ` [Bug c++/107458] " pinskia at gcc dot gnu.org
2022-10-30  0:02 ` pinskia at gcc dot gnu.org
2022-10-30  0:11 ` pinskia at gcc dot gnu.org
2022-10-30  0:13 ` pinskia at gcc dot gnu.org

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).