Skip to content

Instantly share code, notes, and snippets.

@treed
Created September 26, 2011 09:59
Show Gist options
  • Save treed/1241961 to your computer and use it in GitHub Desktop.
Save treed/1241961 to your computer and use it in GitHub Desktop.
Using packed string compare from SSE4.2 to search for certain characters
#include <smmintrin.h>
typedef union __attribute__((aligned(16))) {
unsigned char bytes[16];
__m128i vec;
} vec_bytes_128;
int main() {
int length = 3;
vec_bytes_128 in = { 'a', 'e', 'e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
vec_bytes_128 test = { '\t', '\n', '\\', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int skippable = _mm_cmpistri(test.vec, in.vec, 0);
if (skippable > length)
skippable = length;
exit(skippable);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment