I have some code that performs (nearly) the opposite function of a pmovmskb.
It takes as input a 16-bit bitfield and expands it into 2 xmm registers.
(I'm limited to working with AVX1 code).
The code I've come up with is:
const SliverToSliceMask = 0x0001-0002-0004-0008-0010-0020-0040-0080 movdqu xmm14,[rip+SliverToSliceMask] ;xmm14 = mask to isolate bits 0..7 movdqa xmm15,xmm14 ;xmm15 = mask pslldq xmm15,1 ;convert mask from bit 0..7 to bit 8..15 and edx,r8d ;combine the two slivers //Now expand the sliver into a slice movd xmm0, edx ;xmm0 = sliver pshuflw xmm0,xmm0,$00 ;Paste the sliver 4 times (expanding it to 8 bytes). pshufd xmm0, xmm0, $50 ;Paste the sliver 2 more times (expanding it to 16 bytes) movdqa xmm1,xmm0 ;make a copy,expanding it to 32 bytes (in 2 regs) //now xmm0 and xmm1 are filled with 16 copies of the input sliver, mask out the bit //that is intended per word pand xmm0,xmm14 ;mask off the words for bit 0..7 pand xmm1,xmm15 ;mask off the words for bit 8..15 pcmpeqw xmm0,xmm14 ;set 1's to $FFFF and 0's to 0 pcmpeqw xmm1,xmm15 ;Thus expanding the sliver (1 bit per outer sliver) ;to a slice (16 bits per sliver)
Is there a way to optimize this code. I would esp. like to get rid of the memory access to fetch the mask.