0

Example:

__asm__ __volatile__("rdrand %%rax\nrdrand %%rbx\nrdrand %%rcx\nrdrand %%rdx\n"
                    : "=a" (varr[0]), "=b" (varr[1]), "=c" (varr[2]), "=d" (varr[3])

in this example, I can reference rax using "=a" rbx using "=b" and so on for c and d

How can I reference r8,r9,r10,r11,r12,r13,r14,r15??

It's hours I am searching but I don't find an answer.

__asm__ __volatile__("rdrand %%r8\nrdrand %%r9\nrdrand %%r10\nrdrand %%r11\n"
                    : "=?" (varr[0]), "=?" (varr[1]), "=?" (varr[2]), "=?" (varr[3])
Community
  • 1
  • 1
Zibri
  • 9,096
  • 3
  • 52
  • 44
  • 2
    1) Don't do that. 2) You can use [local register variables](https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables) with `r` constraint. – Jester Mar 20 '19 at 16:17
  • the high registers need REX prefix, so always prefer the lower ones when possible – phuclv Mar 20 '19 at 16:19
  • @Jester: you can't say "don't do that".. I am just asking HOW to reference the 64 bit registers r8-r15. – Zibri Mar 20 '19 at 16:21
  • 1
    I told you how to do that. It's in the manual. But it's not recommended. – Jester Mar 20 '19 at 16:22
  • you can use "h" (when in thumb state) – ensc Mar 20 '19 at 16:25
  • 1
  • @ensc: x86-64 and ARM32 both have registers r8-r15. But this is an x86-64 question. There's a [`"R"` constraint](https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Constraints) for a legacy register accessible without a REX prefix, but no constraint that limits the selection to only the high regs. – Peter Cordes Mar 20 '19 at 17:12
  • 1
    @Zibri: In this specific use-case, why don't you just use `"=r"` for all 4 constraints like a normal person? It's usually best to let the compiler do register allocation, so it can avoid saving/restoring call-clobbered registers like RBX for no reason. It's also generally not helpful to force it to put 4x rdrand back to back, instead of mixing it with stores or whatever else it wants to do, unless there's some reason for it. – Peter Cordes Mar 20 '19 at 17:14
  • Wouldn't a normal person just use the [builtins](https://stackoverflow.com/a/31216938/2189500)? – David Wohlferd Mar 21 '19 at 01:49
  • @DavidWohlferd Wouldn't a normal person just answer "I don't know" or "Here is the answer:" ?!? – Zibri Mar 22 '19 at 09:13
  • @PeterCordes I didn't ask "how to solve a problem" (which I already solved using builins). I asked a precise question to see if there is a way or not. For pure knowledge. – Zibri Mar 22 '19 at 09:14
  • Oh good, glad this was just a made-up example to demonstrate the question. One real use-case is for a `syscall` wrapper function with 4 or more args; in the x86-64 System V ABI, `syscall` args go in RDI, RSI, RDX, R10 (not RCX), R8, R9. – Peter Cordes Mar 22 '19 at 16:36

0 Answers0