Skip to content

Instantly share code, notes, and snippets.

@fsaintjacques
Last active January 14, 2016 14:50
Show Gist options
  • Save fsaintjacques/94a81ad147ae7ad5b8f6 to your computer and use it in GitHub Desktop.
Save fsaintjacques/94a81ad147ae7ad5b8f6 to your computer and use it in GitHub Desktop.
typedef simd_t __m256i;
// specialized for every container type
simd_t container_to_chunk(const container_t * array, size_t chunk_position);
// intersecting any 2 types of containers
container_intersection(const container *a, const container *b, bitset *dst) {
// promote dst to bitset
for (i = 0; i < N_CHUNKS; ++i) {
simd_t chunk_a = container_to_chunk(a, i);
simd_t chunk_b = container_to_chunk(b, i);
simd_t *addr = &((simd_t*) dst->array)[i]
_mm_save(addr, _mm_intersection(a, b));
// dst->cardinality += popcount(addr)
}
// optionnally promote dst to best suited container
return dst;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment