I use SSE and I want to duplicate the last byte of each double word 4 times of XMM0 but I don't know how to do! (maybe with (un)packs?)
To illustrate, I'd like to do this.
Thanks for your help!
I use SSE and I want to duplicate the last byte of each double word 4 times of XMM0 but I don't know how to do! (maybe with (un)packs?)
To illustrate, I'd like to do this.
Thanks for your help!
You can do this with the SSSE3 command PSHUFB
like this (MASM 32-bit assembly)
.data
align 16
mask db 0,0,0,0, 4,4,4,4, 8,8,8,8, 12,12,12,12
.code
; value in XMM0 ; 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
pshufb xmm0, xmmword ptr [mask] ; 12 12 12 12 08 08 08 08 04 04 04 04 00 00 00 00
That the output seems to match the mask is a coincident.
I couldn't test this at the moment, the order of the mask bytes may be reversed. But you should get the idea.
Anyways: take care of alignment, because
When the source operand is a 128-bit memory operand, the operand must be aligned on a 16-byte boundary or a general-protection exception (#GP) will be generated.