public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106743] New: Illegal assembly code with -march=skylake
@ 2022-08-25 19:27 stayprivate at gmail dot com
2022-08-25 19:32 ` [Bug target/106743] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: stayprivate at gmail dot com @ 2022-08-25 19:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106743
Bug ID: 106743
Summary: Illegal assembly code with -march=skylake
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: stayprivate at gmail dot com
Target Milestone: ---
#include <stdint.h>
#include <iostream>
#define swapw(__val)
\
({
\
uint16_t __tmp = __val;
\
__asm__("xchgb %b0, %h0" : "=q"(__tmp) : "0"(__tmp));
\
__tmp;
\
})
int main()
{
int value = rand();
int a = swapw(value);
std::cout << std::hex << "First value is " << value << " " << a << '\n';
}
Compile with gcc (gcc 12 on Ubuntu ), and also with trunk. As shown on
https://godbolt.org/z/oGn9WK6GE the assembler will generate the following
error:
: register type mismatch for `xchg'
This is only when using -march=skylake or above and using -O1 or above.
The code works in gcc-9/10/11.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/106743] Illegal assembly code with -march=skylake
2022-08-25 19:27 [Bug c++/106743] New: Illegal assembly code with -march=skylake stayprivate at gmail dot com
@ 2022-08-25 19:32 ` pinskia at gcc dot gnu.org
2022-08-25 19:35 ` pinskia at gcc dot gnu.org
2022-08-26 12:44 ` marxin at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-25 19:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106743
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
xchgb %bpl, %bp
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/106743] Illegal assembly code with -march=skylake
2022-08-25 19:27 [Bug c++/106743] New: Illegal assembly code with -march=skylake stayprivate at gmail dot com
2022-08-25 19:32 ` [Bug target/106743] " pinskia at gcc dot gnu.org
@ 2022-08-25 19:35 ` pinskia at gcc dot gnu.org
2022-08-26 12:44 ` marxin at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-08-25 19:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106743
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The inline-asm is wrong.
It should be:
__asm__("xchgb %b0, %h0 ## %0 " : "=Q"(__tmp) : "0"(__tmp));
q
Any register accessible as rl. In 32-bit mode, a, b, c, and d; in 64-bit mode,
any integer register.
Q
Any register accessible as rh: a, b, c, and d.
Because you are accessing it as rh so you need to Q rather than q.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug target/106743] Illegal assembly code with -march=skylake
2022-08-25 19:27 [Bug c++/106743] New: Illegal assembly code with -march=skylake stayprivate at gmail dot com
2022-08-25 19:32 ` [Bug target/106743] " pinskia at gcc dot gnu.org
2022-08-25 19:35 ` pinskia at gcc dot gnu.org
@ 2022-08-26 12:44 ` marxin at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-08-26 12:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106743
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Reduced test-case:
cat pr106743.ii
struct basic_ostream {};
template <typename _Traits> void operator<<(_Traits, char);
basic_ostream cout;
int main___tmp;
int main() {
int a = ({
__asm__("xchgb %b0, %h0" : "=q"(main___tmp));
main___tmp;
});
cout << a;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-26 12:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-25 19:27 [Bug c++/106743] New: Illegal assembly code with -march=skylake stayprivate at gmail dot com
2022-08-25 19:32 ` [Bug target/106743] " pinskia at gcc dot gnu.org
2022-08-25 19:35 ` pinskia at gcc dot gnu.org
2022-08-26 12:44 ` marxin 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).