public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers
@ 2024-03-21 16:05 lee.imple at gmail dot com
  2024-03-21 16:09 ` [Bug target/114417] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: lee.imple at gmail dot com @ 2024-03-21 16:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114417
           Summary: simd parameters are passed by memory on x64 , not
                    using the available sse registers
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lee.imple at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/3GYnadqc1

In current implementation, SIMD parameters are passed by memory, while the
equivalent vector parameters are passed by SSE registers. If the equivalent
vector parameters can be passed by SSE registers, can we use SSE registers for
SIMD parameters?

Maybe the performance difference is not so significant, but I just want to keep
everything in registers.

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

* [Bug target/114417] simd parameters are passed by memory on x64 , not using the available sse registers
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
@ 2024-03-21 16:09 ` pinskia at gcc dot gnu.org
  2024-03-21 16:16 ` lee.imple at gmail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-21 16:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |target
           Keywords|                            |ABI

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I doubt this can change since this is the abi gcc decided on a long time ago.

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

* [Bug target/114417] simd parameters are passed by memory on x64 , not using the available sse registers
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
  2024-03-21 16:09 ` [Bug target/114417] " pinskia at gcc dot gnu.org
@ 2024-03-21 16:16 ` lee.imple at gmail dot com
  2024-03-21 16:17 ` lee.imple at gmail dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: lee.imple at gmail dot com @ 2024-03-21 16:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Imple Lee <lee.imple at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> I doubt this can change since this is the abi gcc decided on a long time ago.

If we implement the simd class as a wrapper around a vector, the parameter can
still be passed by sse registers, so I think there may be an implementation
issue in libstdc++'s implementation of stdx::simd.

https://godbolt.org/z/a6s67zzc7

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

* [Bug target/114417] simd parameters are passed by memory on x64 , not using the available sse registers
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
  2024-03-21 16:09 ` [Bug target/114417] " pinskia at gcc dot gnu.org
  2024-03-21 16:16 ` lee.imple at gmail dot com
@ 2024-03-21 16:17 ` lee.imple at gmail dot com
  2024-03-21 16:26 ` [Bug target/114417] std::experimental::simd " pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: lee.imple at gmail dot com @ 2024-03-21 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Imple Lee <lee.imple at gmail dot com> ---
Oh, I didn't make it clear. I am describing libstdc++'s std::experimental::simd
class.

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

* [Bug target/114417] std::experimental::simd parameters are passed by memory on x64 , not using the available sse registers
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (2 preceding siblings ...)
  2024-03-21 16:17 ` lee.imple at gmail dot com
@ 2024-03-21 16:26 ` pinskia at gcc dot gnu.org
  2024-03-21 16:28 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-21 16:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 57759
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57759&action=edit
testcase

Note please attach the testcase (or put it inline) instead of just linking to
godbolt next time.

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

* [Bug target/114417] std::experimental::simd parameters are passed by memory on x64 , not using the available sse registers
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (3 preceding siblings ...)
  2024-03-21 16:26 ` [Bug target/114417] std::experimental::simd " pinskia at gcc dot gnu.org
@ 2024-03-21 16:28 ` pinskia at gcc dot gnu.org
  2024-03-21 16:34 ` [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-21 16:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
uint64_t f2 (struct type2 & x)

It is definitely passed by reference because of ABI requirements of C++.

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

* [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (4 preceding siblings ...)
  2024-03-21 16:28 ` pinskia at gcc dot gnu.org
@ 2024-03-21 16:34 ` pinskia at gcc dot gnu.org
  2024-03-21 16:37 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-21 16:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|std::experimental::simd     |std::experimental::simd is
                   |parameters are passed by    |not a POD (by ABI
                   |memory on x64 , not using   |definitions) and is always
                   |the available sse registers |passed by reference instead
                   |                            |of by value
          Component|target                      |libstdc++

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Most likely because stdx::fixed_size_simd is not a POD type.

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

* [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (5 preceding siblings ...)
  2024-03-21 16:34 ` [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value pinskia at gcc dot gnu.org
@ 2024-03-21 16:37 ` pinskia at gcc dot gnu.org
  2024-03-21 18:01 ` lee.imple at gmail dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-21 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

* [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (6 preceding siblings ...)
  2024-03-21 16:37 ` pinskia at gcc dot gnu.org
@ 2024-03-21 18:01 ` lee.imple at gmail dot com
  2024-03-22  1:37 ` de34 at live dot cn
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: lee.imple at gmail dot com @ 2024-03-21 18:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Imple Lee <lee.imple at gmail dot com> ---
I tried to dig into the source code and it seems like it was designed to be
"passed via the stack". Not sure whether this was specified by the
specification (did not find relevant requirements, but I am not quite familiar
with that) or just an implementation choice.

In GCC git tree [libstdc++-v3/include/experimental/bits/simd_fixed_size.h, line
27](https://gcc.gnu.org/git?p=gcc.git;a=blob;f=libstdc%2B%2B-v3/include/experimental/bits/simd_fixed_size.h;h=408855212979cc32699db0805079ac74f495a8fa;hb=HEAD#l27):

...
  * The fixed_size ABI gives the following guarantees:
  *  - simd objects are passed via the stack
...

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

* [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (7 preceding siblings ...)
  2024-03-21 18:01 ` lee.imple at gmail dot com
@ 2024-03-22  1:37 ` de34 at live dot cn
  2024-04-22 12:46 ` mkretz at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: de34 at live dot cn @ 2024-03-22  1:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #8 from Jiang An <de34 at live dot cn> ---
There're comments saying:

> // The following ensures, function arguments are passed via the stack.
> // This is important for ABI compatibility across TU boundaries

I have no idea about why this was considered outweighting trivial copyability.

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

* [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (8 preceding siblings ...)
  2024-03-22  1:37 ` de34 at live dot cn
@ 2024-04-22 12:46 ` mkretz at gcc dot gnu.org
  2024-04-22 12:48 ` mkretz at gcc dot gnu.org
  2024-04-22 17:18 ` lee.imple at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: mkretz at gcc dot gnu.org @ 2024-04-22 12:46 UTC (permalink / raw)
  To: gcc-bugs

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

Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mkretz at gcc dot gnu.org

--- Comment #9 from Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> ---
Sorry for not noticing this PR earlier. Yes, this specific behavior of
fixed_size follows a request from the C++ committee for the TS. It is not
mandated by the TS wording, because the C++ spec has no means to require
passing arguments via the stack or registers. That's beyond the abstract
machine. It still asks for that behavior non-normatively, though.

What you want to use instead is std::experimental::simd_abi::deduce_t<T, N>.
That'll give you a not-fixed_size ABI if one exists. And those will likely be
passed via registers (as long as the psABI allows).

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

* [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (9 preceding siblings ...)
  2024-04-22 12:46 ` mkretz at gcc dot gnu.org
@ 2024-04-22 12:48 ` mkretz at gcc dot gnu.org
  2024-04-22 17:18 ` lee.imple at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: mkretz at gcc dot gnu.org @ 2024-04-22 12:48 UTC (permalink / raw)
  To: gcc-bugs

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

Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> changed:

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

--- Comment #10 from Matthias Kretz (Vir) <mkretz at gcc dot gnu.org> ---
Here's your example with the simd_abi::compatible ABI tag:
https://godbolt.org/z/WbWr75EGW

This is all working as intended. Note that no such ABI-stable ABI tag is
currently planned for the TS merge to C++26. So I guess that will make you
happy? :)

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

* [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value
  2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
                   ` (10 preceding siblings ...)
  2024-04-22 12:48 ` mkretz at gcc dot gnu.org
@ 2024-04-22 17:18 ` lee.imple at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: lee.imple at gmail dot com @ 2024-04-22 17:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Imple Lee <lee.imple at gmail dot com> ---
> What you want to use instead is std::experimental::simd_abi::deduce_t<T, N>. That'll give you a not-fixed_size ABI if one exists. And those will likely be passed via registers (as long as the psABI allows).

Great! It does work as intended. Thank you for telling me that.
Maybe all I need is just to read the docs on cppref more carefully :|

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

end of thread, other threads:[~2024-04-22 17:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-21 16:05 [Bug libstdc++/114417] New: simd parameters are passed by memory on x64 , not using the available sse registers lee.imple at gmail dot com
2024-03-21 16:09 ` [Bug target/114417] " pinskia at gcc dot gnu.org
2024-03-21 16:16 ` lee.imple at gmail dot com
2024-03-21 16:17 ` lee.imple at gmail dot com
2024-03-21 16:26 ` [Bug target/114417] std::experimental::simd " pinskia at gcc dot gnu.org
2024-03-21 16:28 ` pinskia at gcc dot gnu.org
2024-03-21 16:34 ` [Bug libstdc++/114417] std::experimental::simd is not a POD (by ABI definitions) and is always passed by reference instead of by value pinskia at gcc dot gnu.org
2024-03-21 16:37 ` pinskia at gcc dot gnu.org
2024-03-21 18:01 ` lee.imple at gmail dot com
2024-03-22  1:37 ` de34 at live dot cn
2024-04-22 12:46 ` mkretz at gcc dot gnu.org
2024-04-22 12:48 ` mkretz at gcc dot gnu.org
2024-04-22 17:18 ` lee.imple at gmail dot com

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