Skip to content

Commit 18d7351

Browse files
committed
Back to using array_to_batch_constant
1 parent 474dc03 commit 18d7351

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

cpp/src/arrow/util/bpacking_simd_kernel_internal.h

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ ARROW_FORCE_INLINE constexpr T max_value(const std::array<T, N>& arr) {
7373
return out;
7474
}
7575

76+
template <std::array kArr, typename Arch, std::size_t... Is>
77+
ARROW_FORCE_INLINE constexpr auto array_to_batch_constant_impl(
78+
std::index_sequence<Is...>) {
79+
using Array = std::decay_t<decltype(kArr)>;
80+
using value_type = typename Array::value_type;
81+
82+
return xsimd::batch_constant<value_type, Arch, kArr[Is]...>{};
83+
}
84+
85+
/// Make a ``xsimd::batch_constant`` from a static constexpr array.
86+
template <std::array kArr, typename Arch>
87+
ARROW_FORCE_INLINE constexpr auto array_to_batch_constant() {
88+
return array_to_batch_constant_impl<kArr, Arch>(
89+
std::make_index_sequence<kArr.size()>());
90+
}
91+
7692
template <typename Uint, typename Arch>
7793
ARROW_FORCE_INLINE xsimd::batch<uint8_t, Arch> load_val_as(const uint8_t* in) {
7894
const Uint val = util::SafeLoadAs<Uint>(in);
@@ -123,7 +139,7 @@ ARROW_FORCE_INLINE constexpr auto select_stride(
123139
constexpr auto kStridesArr =
124140
select_stride_impl<ToInt, kOffset, sizeof(ToInt) / sizeof(Int)>(
125141
std::array{kShifts...});
126-
return xsimd::make_batch_constant<kStridesArr, Arch>();
142+
return array_to_batch_constant<kStridesArr, Arch>();
127143
}
128144

129145
/// Whether we are compiling for the SSE2 or above in the SSE family (not AVX).
@@ -634,8 +650,7 @@ struct MediumKernel {
634650
unpacked_type* out) {
635651
constexpr auto kRightShiftsArr =
636652
kPlan.shifts.at(kReadIdx).at(kSwizzleIdx).at(kShiftIdx);
637-
constexpr auto kRightShifts =
638-
xsimd::make_batch_constant<kRightShiftsArr, arch_type>();
653+
constexpr auto kRightShifts = array_to_batch_constant<kRightShiftsArr, arch_type>();
639654
constexpr auto kMask = kPlan.mask;
640655
constexpr auto kOutOffset = (kReadIdx * kPlan.unpacked_per_read() +
641656
kSwizzleIdx * kPlan.unpacked_per_swizzle() +
@@ -659,7 +674,7 @@ struct MediumKernel {
659674
const simd_bytes& bytes, unpacked_type* out,
660675
std::integer_sequence<int, kShiftIds...>) {
661676
constexpr auto kSwizzlesArr = kPlan.swizzles.at(kReadIdx).at(kSwizzleIdx);
662-
constexpr auto kSwizzles = xsimd::make_batch_constant<kSwizzlesArr, arch_type>();
677+
constexpr auto kSwizzles = array_to_batch_constant<kSwizzlesArr, arch_type>();
663678

664679
const auto swizzled = xsimd::swizzle(bytes, kSwizzles);
665680
const auto words = xsimd::bitwise_cast<uint_type>(swizzled);
@@ -923,13 +938,13 @@ struct LargeKernel {
923938
ARROW_FORCE_INLINE static void unpack_one_read_impl(const uint8_t* in,
924939
unpacked_type* out) {
925940
constexpr auto kLowSwizzles =
926-
xsimd::make_batch_constant<kPlan.low_swizzles.at(kReadIdx), arch_type>();
941+
array_to_batch_constant<kPlan.low_swizzles.at(kReadIdx), arch_type>();
927942
constexpr auto kLowRShifts =
928-
xsimd::make_batch_constant<kPlan.low_rshifts.at(kReadIdx), arch_type>();
943+
array_to_batch_constant<kPlan.low_rshifts.at(kReadIdx), arch_type>();
929944
constexpr auto kHighSwizzles =
930-
xsimd::make_batch_constant<kPlan.high_swizzles.at(kReadIdx), arch_type>();
945+
array_to_batch_constant<kPlan.high_swizzles.at(kReadIdx), arch_type>();
931946
constexpr auto kHighLShifts =
932-
xsimd::make_batch_constant<kPlan.high_lshifts.at(kReadIdx), arch_type>();
947+
array_to_batch_constant<kPlan.high_lshifts.at(kReadIdx), arch_type>();
933948

934949
const auto bytes =
935950
safe_load_bytes<kPlan.bytes_per_read(), arch_type>(in + kPlan.reads.at(kReadIdx));

0 commit comments

Comments
 (0)