Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force clang assembler to emit the `rex.W` prefix?

When writing inline assembly, is there a way to force the use of the rex.W prefix?

So instead of

"psllq $12, %%xmm1\n"

generating 66 0f 73 f1 0c, I want 66 48 0f 73 f1 0c, with the extra 0x48 rex.W prefix.

EDIT: I made a mistake with the initial title, the problem is with clang not GCC.

insn_sse2.c:11794:11: error: unexpected token in argument list
         "rex.W psllq $12, %%xmm1\n"
          ^
<inline asm>:7:13: note: instantiated into assembly here
rex.W psllq $12, %xmm1

like image 254
Paul Floyd Avatar asked Oct 29 '25 10:10

Paul Floyd


1 Answers

You can just add the rex.W prefix:

rex.W psllq $12, %xmm1

This is exactly how GNU binutils will disassemble the opcode bytes you have given. From a file psllq.s with the contents

.byte 0x66, 0x48, 0x0f, 0x73, 0xf1, 0x0c

we can run as psllq.s -o psllq.o && objdump -d psllq.o to obtain:


psllq.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <.text>:
   0:   66 48 0f 73 f1 0c       rex.W psllq $0xc,%xmm1
like image 52
user3840170 Avatar answered Nov 01 '25 13:11

user3840170



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!