Author Topic: How to set the REX.W=1?  (Read 8720 times)

Offline wanghua131

  • Jr. Member
  • *
  • Posts: 2
How to set the REX.W=1?
« on: September 26, 2018, 01:01:02 AM »
The assembler code is: PCMPESTRI XMM6, XMM13, 0x45, I want to generate  the code which the REX.W =1, but the NASM generate the the code is : 66410F3A61F545, 0x41 is the REX prefix, the REX.W = 0, how to set the REX.W=1 when the NASM generates the code?

Offline vitsoft

  • Jr. Member
  • *
  • Posts: 17
  • Country: cz
    • About me
Re: How to set the REX.W=1?
« Reply #1 on: September 28, 2018, 07:38:44 PM »
Instructions PCMPESTRM and PCMPESTRI expect the length of input strings provided in registers EAX and EDX. When the instruction is encoded with prefix REX.W, RAX and RDX are used instead.
Value in length-registers is saturated to 8 or 16, so the need of REX.W can be bypassed with manual extension of 32bit value to 64 bits:
      XCHG RAX,RDX
    CDQE
    XCHG RDX, RAX
    CDQE
    PCMPESTRI XMM6,XMM13,0x45


But you are right, AMD and Intel do not suggest any specification how to ask for 64bit version of length-registers, so it depends on assembler manufacturers, and it is often overlooked. Thank you for reminding. Possible solutions which occured me:
  • Explicit prefix request:
      REX.W PCMPESTRI XMM6,XMM13,0x45
  • Explicit notation of hardwired length-registers as additional operands:
PCMPESTRI XMM6,XMM13,0x45,RAX,RDX
  • Modification of mnemonic name:
   PCMPESTRI64 XMM6,XMM13,0x45
or PCMPESTRIQ  XMM6,XMM13,0x45
  • Using data modifier:
PCMPESTRI XMM6,XMM13,0x45,DWORD[/li][/list]

Current version of NASM doesn't allow any of this possibilities, AFAIK. I completed €ASM with the fourth variant today, see this test example.[/list]
« Last Edit: September 28, 2018, 07:40:59 PM by vitsoft »

Offline wanghua131

  • Jr. Member
  • *
  • Posts: 2
Re: How to set the REX.W=1?
« Reply #2 on: October 04, 2018, 09:11:44 AM »
Thank you very much!