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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With