#ifndef SIMDJSON_RVV_VLS_BITMANIPULATION_H #define SIMDJSON_RVV_VLS_BITMANIPULATION_H #ifndef SIMDJSON_CONDITIONAL_INCLUDE #include "simdjson/rvv-vls/base.h" #endif // SIMDJSON_CONDITIONAL_INCLUDE namespace simdjson { namespace rvv_vls { namespace { // We sometimes call trailing_zero on inputs that are zero, // but the algorithms do not end up using the returned value. // Sadly, sanitizers are not smart enough to figure it out. SIMDJSON_NO_SANITIZE_UNDEFINED // This function can be used safely even if not all bytes have been // initialized. // See issue https://github.com/simdjson/simdjson/issues/1965 SIMDJSON_NO_SANITIZE_MEMORY simdjson_inline int trailing_zeroes(uint64_t input_num) { return __builtin_ctzll(input_num); } /* result might be undefined when input_num is zero */ simdjson_inline uint64_t clear_lowest_bit(uint64_t input_num) { return input_num & (input_num-1); } /* result might be undefined when input_num is zero */ simdjson_inline int leading_zeroes(uint64_t input_num) { return __builtin_clzll(input_num); } simdjson_inline long long int count_ones(uint64_t input_num) { return __builtin_popcountll(input_num); } simdjson_inline bool add_overflow(uint64_t value1, uint64_t value2, uint64_t *result) { return __builtin_uaddll_overflow(value1, value2, reinterpret_cast(result)); } } // unnamed namespace } // namespace rvv_vls } // namespace simdjson #endif // SIMDJSON_RVV_VLS_BITMANIPULATION_H