views:

283

answers:

2

Is there any faster method to store two x86 32 bit registers in one 128 bit xmm register?

  movd  xmm0, edx
  movd  xmm1, eax
  pshufd xmm0, xmm0, $1
  por   xmm0, xmm1 

So if EAX is 0x12345678 and EDX is 0x87654321 the result in xmm0 must be 0x8765432112345678.

Thanks

A: 

I don't know much about MMX, but perhaps you want the PACKSSDW instruction.

The PACKSSDW instruction takes the two double words in the source operand and the two double words in the destination operand and converts these to four signed words via saturation. The instruction packs these four words together and stores the result in the destination MMX register.

(from http://webster.cs.ucr.edu/AoA/Windows/HTML/TheMMXInstructionSeta2.html)

Edit: I just realized that those were SSE registers. Oh well.

Edit: I'm going to shut up now.

Jens Björnhager
I like xmm registers instead mmx (64bit) because they don't need 'emms' instruction after using it.
GJ
Yes, perhaps nicer with dedicated registers..
Jens Björnhager
+7  A: 

With SSE 4.1 you can use pinsrd and do it in 2 instructions.

For older CPUs you can use 2 x movd and then punpckldq for a total of 3 instructions:

movd xmm0, edx
movd xmm1, eax
punpckldq xmm0, xmm1
Paul R
Thanks. But this is relatively new extension set, since 2007 and the speed and code size is nearly the same.
GJ
OK - have now added a 3 instruction sequence for SSE2/SSE3.
Paul R
Super... That's what I need! Thanks.
GJ