0

Is there an alternate way to put a qword in an mmx register?

For example, in this code snippet:

db random 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
run:
    movq mm2, [rel random]

I can now work with that as a qword 0xaaaaaaaaaaaaaaaa and do pxor etc with it. Is there some other way I could put that data in the register? Maybe by pushing/popping to it?

user2059300
  • 361
  • 1
  • 5
  • 17

1 Answers1

3

No idea why you want to do this, but you can avoid movq if you zero the register and then bring in the value using some operation, such as:

pxor mm2, mm2
pxor mm2, [rel random]

Alternatively, you can load the words using pinsrw:

pinsrw mm2, [rel random], 0
pinsrw mm2, [rel random + 2], 1
pinsrw mm2, [rel random + 4], 2
pinsrw mm2, [rel random + 6], 3

This approach also works in reverse using pextrw but have to go through a general purpose register:

pextrw eax, mm2, 0
mov [rel random], ax
pextrw eax, mm2, 1
mov [rel random + 2], ax
pextrw eax, mm2, 2
mov [rel random + 4], ax
pextrw eax, mm2, 3
mov [rel random + 6], ax

If only movq must be avoided but maskmovq can be used then you can do:

pcmpeqb mm1, mm1
lea rdi, [rel random]
maskmovq mm2, mm1
Jester
  • 56,577
  • 4
  • 81
  • 125
  • 1
    @user2059300: there are really two separate instructions, both called `movq`. One is `movq mm, mm/m64` (so it has an `mm,mm` form, and an `mm, [memory]` form. It's under `MOVQ` in Intel's x86 insn ref). The other is for moving data between integer and vector registers, and is under `MOVD/MOVQ` in the insn ref. So you could `mov r64, imm64` / `movq mm, r64`. This insn also has a `mm, [memory]` form, but only works in 64bit mode. – Peter Cordes Dec 29 '15 at 18:59