Search code examples
delphiassemblydelphi-7ssebasm

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?


Solution

  • 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