1 #ifndef SIMDJSON_ARM64_BITMANIPULATION_H
2 #define SIMDJSON_ARM64_BITMANIPULATION_H
4 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
5 #include "simdjson/arm64/base.h"
6 #include "simdjson/arm64/intrinsics.h"
16 SIMDJSON_NO_SANITIZE_UNDEFINED
20 SIMDJSON_NO_SANITIZE_MEMORY
21 simdjson_inline
int trailing_zeroes(uint64_t input_num) {
22 #if SIMDJSON_REGULAR_VISUAL_STUDIO
26 _BitScanForward64(&ret, input_num);
29 return __builtin_ctzll(input_num);
34 simdjson_inline uint64_t clear_lowest_bit(uint64_t input_num) {
35 return input_num & (input_num-1);
43 SIMDJSON_NO_SANITIZE_UNDEFINED
45 simdjson_inline
int leading_zeroes(uint64_t input_num) {
46 #if SIMDJSON_REGULAR_VISUAL_STUDIO
47 unsigned long leading_zero = 0;
50 if (_BitScanReverse64(&leading_zero, input_num))
51 return (
int)(63 - leading_zero);
55 return __builtin_clzll(input_num);
60 simdjson_inline
int count_ones(uint64_t input_num) {
61 return vaddv_u8(vcnt_u8(vcreate_u8(input_num)));
76 #define SIMDJSON_PREFER_REVERSE_BITS 1
79 simdjson_inline uint64_t reverse_bits(uint64_t input_num) {
81 __asm(
"rbit %0, %1" :
"=r"(rev_bits) :
"r"(input_num));
91 SIMDJSON_NO_SANITIZE_UNDEFINED
92 simdjson_inline uint64_t zero_leading_bit(uint64_t rev_bits,
int leading_zeroes) {
93 return rev_bits ^ (uint64_t(0x8000000000000000) >> leading_zeroes);
98 simdjson_inline
bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) {
99 #if SIMDJSON_REGULAR_VISUAL_STUDIO
100 *result = value1 + value2;
101 return *result < value1;
103 return __builtin_uaddll_overflow(value1, value2,
104 reinterpret_cast<unsigned long long *
>(result));
The top level simdjson namespace, containing everything the library provides.