Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broadcast a byte value to all 16 XMM slots in Delphi ASM

This is easy in AVX with the VBROADCASTS command, or in SSE if the value were doubles or floats.

How do I broadcast a single 8-bit value to every slot in an XMM register in Delphi ASM?

like image 381
IamIC Avatar asked Jan 05 '15 13:01

IamIC


2 Answers

Michael's answer will work. As an alternative, if you can assume the SSSE3 instruction set, then using Packed Shuffle Bytes pshufb would also work.

Assuming (1) an 8-bit value in AL (for example) and (2) the desired broadcast destination to be XMM1, and (3) that another register, say XMM0, is available, this will do the trick:

movd   xmm1, eax  ;// move value in AL (part of EAX) into XMM1
pxor   xmm0, xmm0 ;// clear xmm0 to create the appropriate mask for pshufb
pshufb xmm1, xmm0 ;// broadcast lowest value into all slots of xmm1

And yes, Delphi's BASM understands SSSE3.

like image 195
PhiS Avatar answered Oct 11 '22 17:10

PhiS


You mean you have a byte in the LSB of an XMM register and want to duplicate it across all lanes of that register? I don't know Delphi's inline assembly syntax, but in Intel/MASM syntax it could be done something like this:

punpcklbw xmm0,xmm0    ; xxxxxxxxABCDEFGH -> xxxxxxxxEEFFGGHH
punpcklwd xmm0,xmm0    ; xxxxxxxxEEFFGGHH -> xxxxxxxxGGGGHHHH
punpckldq xmm0,xmm0    ; xxxxxxxxGGGGHHHH -> xxxxxxxxHHHHHHHH
punpcklqdq xmm0,xmm0   ; xxxxxxxxHHHHHHHH -> HHHHHHHHHHHHHHHH
like image 42
Michael Avatar answered Oct 11 '22 18:10

Michael