mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
31 lines
845 B
C++
31 lines
845 B
C++
#ifndef SIMDJSON_ICELAKE_BITMASK_H
|
|
#define SIMDJSON_ICELAKE_BITMASK_H
|
|
|
|
#ifndef SIMDJSON_CONDITIONAL_INCLUDE
|
|
#include "simdjson/icelake/base.h"
|
|
#include "simdjson/icelake/intrinsics.h"
|
|
#endif // SIMDJSON_CONDITIONAL_INCLUDE
|
|
|
|
namespace simdjson {
|
|
namespace icelake {
|
|
namespace {
|
|
|
|
//
|
|
// Perform a "cumulative bitwise xor," flipping bits each time a 1 is encountered.
|
|
//
|
|
// For example, prefix_xor(00100100) == 00011100
|
|
//
|
|
simdjson_inline uint64_t prefix_xor(const uint64_t bitmask) {
|
|
// There should be no such thing with a processor supporting avx2
|
|
// but not clmul.
|
|
__m128i all_ones = _mm_set1_epi8('\xFF');
|
|
__m128i result = _mm_clmulepi64_si128(_mm_set_epi64x(0ULL, bitmask), all_ones, 0);
|
|
return _mm_cvtsi128_si64(result);
|
|
}
|
|
|
|
} // unnamed namespace
|
|
} // namespace icelake
|
|
} // namespace simdjson
|
|
|
|
#endif // SIMDJSON_ICELAKE_BITMASK_H
|