Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpp/src/arrow/acero/aggregate_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "benchmark/benchmark.h"

#include <bit>
#include <cassert>
#include <cmath>
#include <iostream>
Expand Down Expand Up @@ -269,7 +270,7 @@ struct SumBitmapVectorizeUnroll : public Summer<T> {
local.total += SUM_SHIFT(5);
local.total += SUM_SHIFT(6);
local.total += SUM_SHIFT(7);
local.valid_count += bit_util::kBytePopcount[valid_byte];
local.valid_count += std::popcount(valid_byte);
} else {
// No nulls
local.total += values[i + 0] + values[i + 1] + values[i + 2] + values[i + 3] +
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/acero/bloom_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <gmock/gmock-matchers.h>

#include <algorithm>
#include <bit>
#include <chrono>
#include <condition_variable>
#include <thread>
Expand Down Expand Up @@ -407,14 +408,14 @@ void TestBloomLarge(BloomFilterBuildStrategy strategy, int64_t num_build,
uint64_t num_negatives = 0ULL;
for (int iword = 0; iword < next_batch_size / 64; ++iword) {
uint64_t word = reinterpret_cast<const uint64_t*>(result_bit_vector.data())[iword];
num_negatives += ARROW_POPCOUNT64(~word);
num_negatives += std::popcount(~word);
}
if (next_batch_size % 64 > 0) {
uint64_t word = reinterpret_cast<const uint64_t*>(
result_bit_vector.data())[next_batch_size / 64];
uint64_t mask = (1ULL << (next_batch_size % 64)) - 1;
word |= ~mask;
num_negatives += ARROW_POPCOUNT64(~word);
num_negatives += std::popcount(~word);
}
if (i < num_build) {
num_negatives_build += num_negatives;
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/acero/swiss_join.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <sys/stat.h>
#include <algorithm> // std::upper_bound
#include <bit>
#include <cstdio>
#include <cstdlib>
#include <mutex>
Expand Down Expand Up @@ -666,7 +667,7 @@ void SwissTableMerge::MergePartition(SwissTable* target, const SwissTable* sourc
// For each non-empty source slot...
constexpr uint64_t kHighBitOfEachByte = 0x8080808080808080ULL;
int num_full_slots = SwissTable::kSlotsPerBlock -
static_cast<int>(ARROW_POPCOUNT64(block & kHighBitOfEachByte));
static_cast<int>(std::popcount(block & kHighBitOfEachByte));
for (int local_slot_id = 0; local_slot_id < num_full_slots; ++local_slot_id) {
// Read group id and hash for this slot.
//
Expand Down Expand Up @@ -722,7 +723,7 @@ inline bool SwissTableMerge::InsertNewGroup(SwissTable* target, uint32_t group_i
return false;
}
int local_slot_id = SwissTable::kSlotsPerBlock -
static_cast<int>(ARROW_POPCOUNT64(block & kHighBitOfEachByte));
static_cast<int>(std::popcount(block & kHighBitOfEachByte));
uint32_t global_slot_id = SwissTable::global_slot_id(block_id, local_slot_id);
target->insert_into_empty_slot(global_slot_id, hash, group_id);
return true;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/compute/kernels/base_arithmetic_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include <bit>
#include <limits>
#include "arrow/compute/api_scalar.h"
#include "arrow/compute/kernels/common_internal.h"
Expand Down Expand Up @@ -594,8 +595,7 @@ struct PowerChecked {
}
// left to right O(logn) power with overflow checks
bool overflow = false;
uint64_t bitmask =
1ULL << (63 - bit_util::CountLeadingZeros(static_cast<uint64_t>(exp)));
uint64_t bitmask = 1ULL << (63 - std::countl_zero(static_cast<uint64_t>(exp)));
T pow = 1;
while (bitmask) {
overflow |= MultiplyWithOverflow(pow, pow, &pow);
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/compute/key_hash_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <memory.h>

#include <algorithm>
#include <bit>
#include <cstdint>

#include "arrow/compute/light_array_internal.h"
Expand Down Expand Up @@ -357,7 +358,7 @@ void Hashing32::HashInt(bool combine_hashes, uint32_t num_keys, uint64_t key_len
void Hashing32::HashFixed(int64_t hardware_flags, bool combine_hashes, uint32_t num_keys,
uint64_t key_length, const uint8_t* keys, uint32_t* hashes,
uint32_t* temp_hashes_for_combine) {
if (ARROW_POPCOUNT64(key_length) == 1 && key_length <= sizeof(uint64_t)) {
if (std::popcount(key_length) == 1 && key_length <= sizeof(uint64_t)) {
HashInt(combine_hashes, num_keys, key_length, keys, hashes);
return;
}
Expand Down Expand Up @@ -809,7 +810,7 @@ void Hashing64::HashInt(bool combine_hashes, uint32_t num_keys, uint64_t key_len

void Hashing64::HashFixed(bool combine_hashes, uint32_t num_keys, uint64_t key_length,
const uint8_t* keys, uint64_t* hashes) {
if (ARROW_POPCOUNT64(key_length) == 1 && key_length <= sizeof(uint64_t)) {
if (std::popcount(key_length) == 1 && key_length <= sizeof(uint64_t)) {
HashInt(combine_hashes, num_keys, key_length, keys, hashes);
return;
}
Expand Down
18 changes: 9 additions & 9 deletions cpp/src/arrow/compute/key_map_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "arrow/compute/key_map_internal.h"

#include <algorithm>
#include <bit>
#include <cstdint>

#include "arrow/util/bit_util.h"
Expand All @@ -27,7 +28,6 @@

namespace arrow {

using bit_util::CountLeadingZeros;
using internal::CpuInfo;

namespace compute {
Expand Down Expand Up @@ -91,7 +91,7 @@ inline void SwissTable::search_block(uint64_t block, int stamp, int start_slot,
// Now if we or with the highest bits of the block and scan zero bits in reverse, we get
// 8x slot index that we were looking for. This formula works in all three cases a), b)
// and c).
*out_slot = static_cast<int>(CountLeadingZeros(matches | block_high_bits) >> 3);
*out_slot = static_cast<int>(std::countl_zero(matches | block_high_bits) >> 3);
}

template <typename T, bool use_selection>
Expand Down Expand Up @@ -204,8 +204,8 @@ void SwissTable::init_slot_ids_for_new_keys(uint32_t num_ids, const uint16_t* id
int num_block_bytes = num_block_bytes_from_num_groupid_bits(num_groupid_bits);
if (log_blocks_ == 0) {
uint64_t block = *reinterpret_cast<const uint64_t*>(blocks_->mutable_data());
uint32_t empty_slot = static_cast<uint32_t>(
kSlotsPerBlock - ARROW_POPCOUNT64(block & kHighBitOfEachByte));
uint32_t empty_slot =
static_cast<uint32_t>(kSlotsPerBlock - std::popcount(block & kHighBitOfEachByte));
for (uint32_t i = 0; i < num_ids; ++i) {
int id = ids[i];
slot_ids[id] = empty_slot;
Expand All @@ -224,7 +224,7 @@ void SwissTable::init_slot_ids_for_new_keys(uint32_t num_ids, const uint16_t* id
}
iblock = (iblock + 1) & ((1 << log_blocks_) - 1);
}
uint32_t empty_slot = static_cast<int>(kSlotsPerBlock - ARROW_POPCOUNT64(block));
uint32_t empty_slot = static_cast<int>(kSlotsPerBlock - std::popcount(block));
slot_ids[id] = global_slot_id(iblock, empty_slot);
}
}
Expand Down Expand Up @@ -684,7 +684,7 @@ Status SwissTable::grow_double() {
mutable_block_data(blocks_new->mutable_data(), 2 * i, block_size_after);
uint64_t block = *reinterpret_cast<const uint64_t*>(block_base);

uint32_t full_slots = CountLeadingZeros(block & kHighBitOfEachByte) >> 3;
uint32_t full_slots = std::countl_zero(block & kHighBitOfEachByte) >> 3;
uint32_t full_slots_new[2];
full_slots_new[0] = full_slots_new[1] = 0;
util::SafeStore(double_block_base_new, kHighBitOfEachByte);
Expand Down Expand Up @@ -722,7 +722,7 @@ Status SwissTable::grow_double() {
// How many full slots in this block
const uint8_t* block_base = block_data(i, block_size_before);
uint64_t block = util::SafeLoadAs<uint64_t>(block_base);
uint32_t full_slots = CountLeadingZeros(block & kHighBitOfEachByte) >> 3;
uint32_t full_slots = std::countl_zero(block & kHighBitOfEachByte) >> 3;

for (uint32_t j = 0; j < full_slots; ++j) {
uint32_t slot_id = global_slot_id(i, j);
Expand All @@ -741,13 +741,13 @@ Status SwissTable::grow_double() {
mutable_block_data(blocks_new->mutable_data(), block_id_new, block_size_after);
uint64_t block_new = util::SafeLoadAs<uint64_t>(block_base_new);
int full_slots_new =
static_cast<int>(CountLeadingZeros(block_new & kHighBitOfEachByte) >> 3);
static_cast<int>(std::countl_zero(block_new & kHighBitOfEachByte) >> 3);
while (full_slots_new == kSlotsPerBlock) {
block_id_new = (block_id_new + 1) & ((1 << log_blocks_after) - 1);
block_base_new = blocks_new->mutable_data() + block_id_new * block_size_after;
block_new = util::SafeLoadAs<uint64_t>(block_base_new);
full_slots_new =
static_cast<int>(CountLeadingZeros(block_new & kHighBitOfEachByte) >> 3);
static_cast<int>(std::countl_zero(block_new & kHighBitOfEachByte) >> 3);
}

hashes_new[block_id_new * kSlotsPerBlock + full_slots_new] = hash;
Expand Down
10 changes: 6 additions & 4 deletions cpp/src/arrow/compute/row/row_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include "arrow/compute/row/row_internal.h"

#include <bit>

#include "arrow/compute/util.h"
#include "arrow/util/logging_internal.h"

Expand Down Expand Up @@ -89,9 +91,9 @@ void RowTableMetadata::FromColumnMetadataVector(
std::sort(
column_order.begin(), column_order.end(), [&cols](uint32_t left, uint32_t right) {
bool is_left_pow2 =
!cols[left].is_fixed_length || ARROW_POPCOUNT64(cols[left].fixed_length) <= 1;
bool is_right_pow2 = !cols[right].is_fixed_length ||
ARROW_POPCOUNT64(cols[right].fixed_length) <= 1;
!cols[left].is_fixed_length || std::popcount(cols[left].fixed_length) <= 1;
bool is_right_pow2 =
!cols[right].is_fixed_length || std::popcount(cols[right].fixed_length) <= 1;
bool is_left_fixedlen = cols[left].is_fixed_length;
bool is_right_fixedlen = cols[right].is_fixed_length;
uint32_t width_left =
Expand Down Expand Up @@ -127,7 +129,7 @@ void RowTableMetadata::FromColumnMetadataVector(
for (uint32_t i = 0; i < num_cols; ++i) {
const KeyColumnMetadata& col = cols[column_order[i]];
if (col.is_fixed_length && col.fixed_length != 0 &&
ARROW_POPCOUNT64(col.fixed_length) != 1) {
std::popcount(col.fixed_length) != 1) {
offset_within_row += RowTableMetadata::padding_for_alignment_within_row(
offset_within_row, string_alignment, col);
}
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/arrow/compute/row/row_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.
#pragma once

#include <bit>
#include <cstdint>
#include <vector>

Expand Down Expand Up @@ -85,7 +86,7 @@ struct ARROW_COMPUTE_EXPORT RowTableMetadata {
/// Alignment must be a power of 2.
static inline uint32_t padding_for_alignment_within_row(uint32_t offset,
int required_alignment) {
ARROW_DCHECK(ARROW_POPCOUNT64(required_alignment) == 1);
ARROW_DCHECK(std::popcount(static_cast<uint64_t>(required_alignment)) == 1);
return static_cast<uint32_t>((-static_cast<int32_t>(offset)) &
(required_alignment - 1));
}
Expand All @@ -94,8 +95,7 @@ struct ARROW_COMPUTE_EXPORT RowTableMetadata {
/// choosing required alignment based on the data type of that column.
static inline uint32_t padding_for_alignment_within_row(
uint32_t offset, int string_alignment, const KeyColumnMetadata& col_metadata) {
if (!col_metadata.is_fixed_length ||
ARROW_POPCOUNT64(col_metadata.fixed_length) <= 1) {
if (!col_metadata.is_fixed_length || std::popcount(col_metadata.fixed_length) <= 1) {
return 0;
} else {
return padding_for_alignment_within_row(offset, string_alignment);
Expand All @@ -106,7 +106,7 @@ struct ARROW_COMPUTE_EXPORT RowTableMetadata {
/// Alignment must be a power of 2.
static inline offset_type padding_for_alignment_row(offset_type row_offset,
int required_alignment) {
ARROW_DCHECK(ARROW_POPCOUNT64(required_alignment) == 1);
ARROW_DCHECK(std::popcount(static_cast<uint64_t>(required_alignment)) == 1);
return (-row_offset) & (required_alignment - 1);
}

Expand Down
7 changes: 4 additions & 3 deletions cpp/src/arrow/compute/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

#include "arrow/compute/util.h"

#include <bit>

#include "arrow/util/logging.h"
#include "arrow/util/ubsan.h"

namespace arrow {

using bit_util::CountTrailingZeros;
using internal::CpuInfo;

namespace util {
Expand Down Expand Up @@ -65,7 +66,7 @@ inline void bits_to_indexes_helper(uint64_t word, uint16_t base_index, int* num_
uint16_t* indexes) {
int n = *num_indexes;
while (word) {
indexes[n++] = base_index + static_cast<uint16_t>(CountTrailingZeros(word));
indexes[n++] = base_index + static_cast<uint16_t>(std::countr_zero(word));
word &= word - 1;
}
*num_indexes = n;
Expand All @@ -75,7 +76,7 @@ inline void bits_filter_indexes_helper(uint64_t word, const uint16_t* input_inde
int* num_indexes, uint16_t* indexes) {
int n = *num_indexes;
while (word) {
indexes[n++] = input_indexes[CountTrailingZeros(word)];
indexes[n++] = input_indexes[std::countr_zero(word)];
word &= word - 1;
}
*num_indexes = n;
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/compute/util_avx2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

#include <bit>
#include <cstring>

#include "arrow/compute/util.h"
Expand Down Expand Up @@ -54,7 +55,7 @@ void bits_to_indexes_imp_avx2(const int num_bits, const uint8_t* bits, int* num_
_pext_u64(mask, _pdep_u64(word, kEachByteIs1) * 0xff) + base;
*reinterpret_cast<uint64_t*>(byte_indexes + num_indexes_loop) = byte_indexes_next;
base += incr;
num_indexes_loop += static_cast<int>(arrow::bit_util::PopCount(word & 0xff));
num_indexes_loop += static_cast<int>(std::popcount(word & 0xff));
word >>= 8;
}
// Unpack indexes to 16-bits and either add the base of i * 64 or shuffle input
Expand Down Expand Up @@ -144,7 +145,7 @@ void bits_filter_indexes_imp_avx2(const int num_bits, const uint8_t* bits,
kByteSequence_0_8_1_9_2_10_3_11,
kByteSequence_4_12_5_13_6_14_7_15));
_mm256_storeu_si256((__m256i*)(indexes + num_indexes), output);
num_indexes += static_cast<int>(arrow::bit_util::PopCount(word & 0xffff));
num_indexes += static_cast<int>(std::popcount(word & 0xffff));
word >>= 16;
++loop_id;
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/src/arrow/testing/uniform_real.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include <bit>
#include <limits>

#include <arrow/util/bit_util.h>
Expand All @@ -39,8 +40,8 @@ namespace detail {
template <typename RealType, typename Rng>
RealType generate_canonical(Rng& rng) {
const size_t b = std::numeric_limits<RealType>::digits;
const size_t log2R = 63 - ::arrow::bit_util::CountLeadingZeros(
static_cast<uint64_t>(Rng::max() - Rng::min()) + 1);
const size_t log2R =
63 - std::countl_zero(static_cast<uint64_t>(Rng::max() - Rng::min()) + 1);
const size_t k = b / log2R + (b % log2R != 0) + (b == 0);
const RealType r = static_cast<RealType>(Rng::max() - Rng::min()) + 1;
RealType base = r;
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/util/align_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <algorithm>
#include <bit>

#include "arrow/memory_pool.h"
#include "arrow/type_fwd.h"
Expand All @@ -43,7 +44,7 @@ struct BitmapWordAlignParams {
template <uint64_t ALIGN_IN_BYTES>
inline BitmapWordAlignParams BitmapWordAlign(const uint8_t* data, int64_t bit_offset,
int64_t length) {
static_assert(bit_util::IsPowerOf2(ALIGN_IN_BYTES),
static_assert(std::has_single_bit(ALIGN_IN_BYTES),
"ALIGN_IN_BYTES should be a positive power of two");
constexpr uint64_t ALIGN_IN_BITS = ALIGN_IN_BYTES * 8;

Expand Down
9 changes: 5 additions & 4 deletions cpp/src/arrow/util/basic_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <algorithm>
#include <array>
#include <bit>
#include <climits>
#include <cstdint>
#include <cstdlib>
Expand Down Expand Up @@ -388,7 +389,7 @@ BasicDecimal64 operator%(const BasicDecimal64& left, const BasicDecimal64& right

template <typename BaseType>
int32_t SmallBasicDecimal<BaseType>::CountLeadingBinaryZeros() const {
return bit_util::CountLeadingZeros(static_cast<std::make_unsigned_t<BaseType>>(value_));
return std::countl_zero(static_cast<std::make_unsigned_t<BaseType>>(value_));
}

// same as kDecimal128PowersOfTen[38] - 1
Expand Down Expand Up @@ -892,7 +893,7 @@ static inline DecimalStatus DecimalDivide(const DecimalClass& dividend,
// Normalize by shifting both by a multiple of 2 so that
// the digit guessing is better. The requirement is that
// divisor_array[0] is greater than 2**31.
int64_t normalize_bits = bit_util::CountLeadingZeros(divisor_array[0]);
int64_t normalize_bits = std::countl_zero(divisor_array[0]);
ShiftArrayLeft(divisor_array, divisor_length, normalize_bits);
ShiftArrayLeft(dividend_array, dividend_length, normalize_bits);

Expand Down Expand Up @@ -1155,9 +1156,9 @@ int32_t BasicDecimal128::CountLeadingBinaryZeros() const {
DCHECK_GE(*this, BasicDecimal128(0));

if (high_bits() == 0) {
return bit_util::CountLeadingZeros(low_bits()) + 64;
return std::countl_zero(low_bits()) + 64;
} else {
return bit_util::CountLeadingZeros(static_cast<uint64_t>(high_bits()));
return std::countl_zero(static_cast<uint64_t>(high_bits()));
}
}

Expand Down
Loading
Loading