On Tue, 16 Dec 2025, LIU Hao wrote:

This solves a leftover in 19fb46e9e8aaf10bf917266e96362fe2b4414934. Because we cannot pass a segmented memory reference to assembly, the (absolute) address was always passed in a register, preventing optimization when it could be constant,
for example, in `NtCurrentTeb()`:

  # -masm=att
  movl    $48, %eax
  movq %gs:(%eax), %rax

  # -masm=intel
  mov     eax, 48
  mov rax, gs:[eax]

With this commit, a constant address is allowed to be passed as a constant to
inline assembly. There are two cases:

1. In AT&T syntax, there are different ways to say whether a constant is an
  immediate or (part of) an address. For our use, we must write the operand
  in its address form, using the `a` modifier: `mov %%gs:%a1, %0`

2. In Intel syntax, the `a` modifier on a constant would produce a `ds:`
segment prefix, so we must not use that. On the other hand, the address form
  of any kind of operands is actually unified, so we enclose the operand in
  brackets, to indicate an address: `mov %0, gs:[%1]`

`NtCurrentTeb()` now produces:

  # -masm=att
  movq %gs:48, %rax

  # -masm=intel
  mov rax, gs:[48]

Signed-off-by: LIU Hao <[email protected]>
---
mingw-w64-headers/include/psdk_inc/intrin-impl.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

I'm not really familiar enough with x86 to follow the nuance differences here, so I'll just trust you on it. I.e. if you've checked it properly yourself and are confident about it, feel free to go ahead with it.

// Martin



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to