1#ifndef SIMDJSON_WESTMERE_BITMASK_H
2#define SIMDJSON_WESTMERE_BITMASK_H
3
4#include "simdjson/portability.h"
5
6#ifdef IS_X86_64
7
8#include "simdjson/common_defs.h"
9#include "westmere/intrinsics.h"
10
11TARGET_WESTMERE
12namespace simdjson::westmere {
13
14//
15// Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered.
16//
17// For example, prefix_xor(00100100) == 00011100
18//
19really_inline uint64_t prefix_xor(const uint64_t bitmask) {
20 // There should be no such thing with a processing supporting avx2
21 // but not clmul.
22 __m128i all_ones = _mm_set1_epi8('\xFF');
23 __m128i result = _mm_clmulepi64_si128(_mm_set_epi64x(0ULL, bitmask), all_ones, 0);
24 return _mm_cvtsi128_si64(result);
25}
26
27} // namespace simdjson::westmere
28UNTARGET_REGION
29
30#endif // IS_X86_64
31#endif
32