simdjson  3.1.5
Ridiculously Fast JSON
bitmask.h
1 #ifndef SIMDJSON_WESTMERE_BITMASK_H
2 #define SIMDJSON_WESTMERE_BITMASK_H
3 
4 namespace simdjson {
5 namespace SIMDJSON_IMPLEMENTATION {
6 namespace {
7 
8 //
9 // Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered.
10 //
11 // For example, prefix_xor(00100100) == 00011100
12 //
13 simdjson_inline uint64_t prefix_xor(const uint64_t bitmask) {
14  // There should be no such thing with a processing supporting avx2
15  // but not clmul.
16  __m128i all_ones = _mm_set1_epi8('\xFF');
17  __m128i result = _mm_clmulepi64_si128(_mm_set_epi64x(0ULL, bitmask), all_ones, 0);
18  return _mm_cvtsi128_si64(result);
19 }
20 
21 } // unnamed namespace
22 } // namespace SIMDJSON_IMPLEMENTATION
23 } // namespace simdjson
24 
25 #endif // SIMDJSON_WESTMERE_BITMASK_H
We want to support argument-dependent lookup (ADL).