Skip to content

Instantly share code, notes, and snippets.

@lemire
Last active May 19, 2019 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemire/5212384d74c5f4b6eb762ac238eedc81 to your computer and use it in GitHub Desktop.
Save lemire/5212384d74c5f4b6eb762ac238eedc81 to your computer and use it in GitHub Desktop.
Compile this and run it through valgrind 3.13.0
// gcc -o t2 t2.c -mavx2
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <x86intrin.h>
__attribute__((no_sanitize("memory")))
__attribute__ ((noinline))
bool hash_zero_byte(char *va) {
__m256i v = _mm256_loadu_si256((__m256i *) va);
__m256i vz = _mm256_cmpeq_epi8(v,_mm256_setzero_si256());
return ! _mm256_testz_si256(vz,vz);
}
int main() {
char buffer[32];
buffer[0] = 'a';
buffer[1] = '\0';
printf("%s\n", buffer);
printf("has zero %d \n", hash_zero_byte(buffer));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment