3 ms·
The usual way to do this in SIMD is via vpermb(lut, str) == str, or potentially slightly faster vpshufb(str>>1, lut) == str. str|0x32 if you want case-insensit
by camel-cdr 1y ago
The usual way to do this in SIMD is via vpermb(lut, str) == str, or potentially slightly faster vpshufb(str>>1, lut) == str.
str|0x32 if you want case-insensitive.
This works because the lowest five bits, more specifically bits two to five, of the vowels are distinct.
The lut is zeroed except for the indices corresponding to the vowels, which contain it self: lut[vowel&31]=vowel or lut[(vowel&31)>>1]=vowel
- teo_zero 1y ago> The lut is zeroed except for the indices corresponding to the vowels, which contain it self So in the comparison vs. the original str, vowels get a true and consonants get a false. Doesn't the "==" then returns true if all the chars are vowels?
- camel-cdr 1y agoI used the C operators as short cuts to denote SIMD operations. So the == would be element wise and return a mask of the vowels in the input vector.