3 ms·
Thank you for sharing this. How would you emulate this kind of operation on avx2?
by ozgrakkurt 2mo ago
Thank you for sharing this. How would you emulate this kind of operation on avx2?
- variadix 2mo agoOnce you have a mask of the positions you want to compress, you can generate a shuffle index vector from that mask to place the desired elements in the low part of the vector. You can expand the mask into nibble-sized indices using pext/pdep and some magic constants, then expand those nibble-sized indices into a vector of indices to use as the shuffle indices.
- anematode 2mo agoYes, that's one approach. Another reasonable approach is to get out a mask from the comparison using `vmovmskpd` and use that to look up a shuffle constant, since there are only 16 possibilities. This also works well on NEON, although I wonder there whether it'd make more sense to find the shuffle dynamically rather than loading it.