Is there a way to cast integers to bytes, knowing these ints are in range of bytes. Using SSE?
The easiest way is probably to use pshufb
to permute the bytes, followed by movd
to store the datum:
; convert dwords in xmm0 into bytes and store into dest
pshufb xmm0, xmmword ptr mask
movd dword ptr dest, xmm0
...
align 16
mask db 0, 4, 8, 12, 12 dup (-1)
This stores 4 bytes instead of 3, so make sure your code can handle that. Storing only 3 bytes is also possible, but requires more work:
; convert dwords in xmm0 into bytes and store into dest
pshufb xmm0, xmmword ptr mask
movd eax, xmm0
mov word ptr dest, ax
bswap eax
mov byte ptr dest+2, ah
...
align 16
mask db 0, 4, 8, 12, 12 dup (-1)
If this happens more than once, you can load the mask ahead of time to avoid the penalty of repeatedly loading it.