From: LIU Hao <lh_mouse@126.com>
To: David Brown <david@westcontrol.com>, gcc-help@gcc.gnu.org
Subject: Re: Odd error with the "X" inline assembly constraint
Date: Sat, 6 Jan 2024 01:53:52 +0800 [thread overview]
Message-ID: <b3d36e48-7ffb-4e1d-a2d5-ef2ee5948660@126.com> (raw)
In-Reply-To: <un9arr$leo$1@ciao.gmane.io>
[-- Attachment #1.1: Type: text/plain, Size: 1469 bytes --]
在 2024/1/6 0:30, David Brown via Gcc-help 写道:
> I'd imagine that the "X" operand doesn't see much use in real inline assembly - on x86 and ARM the
> assembly instruction template would usually depend on where the data is put. But if anyone can
> explain this behaviour to me, I am very curious to know what is going on.
I haven't used it at all and know nothing about its original intention. From GCC documentation, it
looks like `X` specifies that the argument is allowed to be passed via either a register or memory,
so it should be eligible for overloaded mnemonics, such as the MOV, FLD and ADDPD instructions on x86.
For example, given
(https://gcc.godbolt.org/z/vxb1aTe9c)
```
static int value;
int
test_X(void)
{
int a;
__asm__("mov %0, %1" : "=&r"(a), "+X"(value));
return a;
}
```
GCC passes `value` directly via memory
```
test_X:
mov eax, DWORD PTR value[rip]
ret
```
and Clang passes it via the ECX register
```
test_X:
mov ecx, dword ptr [rip + value]
mov eax, ecx
mov dword ptr [rip + value], ecx
ret
```
If `static int value;` is changed to `extern int value;` then GCC will reject it, as the operand no
longer fits into a single operand; but the clang approach still works, with `value` replaced with
`value@GOTPCREL`.
It doesn't seem very useful for RISC machines.
--
Best regards,
LIU Hao
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2024-01-05 17:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-05 16:30 David Brown
2024-01-05 17:53 ` LIU Hao [this message]
2024-01-05 18:46 ` Segher Boessenkool
2024-01-07 10:04 ` LIU Hao
2024-01-07 15:26 ` David Brown
2024-01-07 18:32 ` Segher Boessenkool
2024-01-08 18:39 ` David Brown
2024-01-07 15:10 ` David Brown
2024-01-07 18:24 ` Segher Boessenkool
2024-01-08 18:48 ` David Brown
2024-01-07 23:18 ` Marc Glisse
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=b3d36e48-7ffb-4e1d-a2d5-ef2ee5948660@126.com \
--to=lh_mouse@126.com \
--cc=david@westcontrol.com \
--cc=gcc-help@gcc.gnu.org \
/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).