Skip to content
Merged
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
26 changes: 16 additions & 10 deletions cpp/src/arrow/util/bpacking_simd_kernel_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,15 @@ template <typename Arch>
constexpr bool IsNeon = std::is_base_of_v<xsimd::neon, Arch>;

/// Wrapper around ``xsimd::bitwise_lshift`` with optimizations for non implemented sizes.
//
// We replace the variable left shift by a variable multiply with a power of two.
//
// This trick is borrowed from Daniel Lemire and Leonid Boytsov, Decoding billions of
// integers per second through vectorization, Software Practice & Experience 45 (1), 2015.
// http://arxiv.org/abs/1209.2137
//
///
/// We replace the variable left shift by a variable multiply with a power of two.
///
/// This trick is borrowed from Daniel Lemire and Leonid Boytsov, Decoding billions of
/// integers per second through vectorization, Software Practice & Experience 45 (1),
/// 2015. http://arxiv.org/abs/1209.2137
///
/// TODO(xsimd) Tracking in https://github.com/xtensor-stack/xsimd/pull/1220
/// When migrating, be sure to use batch_constant overload, and not the batch one.
template <typename Arch, typename Int, Int... kShifts>
auto left_shift(const xsimd::batch<Int, Arch>& batch,
xsimd::batch_constant<Int, Arch, kShifts...> shifts)
Expand Down Expand Up @@ -200,14 +201,16 @@ auto left_shift(const xsimd::batch<Int, Arch>& batch,
return xsimd::bitwise_cast<Int>(shifted0 | shifted1);
}

// TODO(xsimd) bug fixed likely in xsimd>14.0.0
// TODO(xsimd) bug fixed in xsimd 14.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove TODO because the bug was fixed?

Suggested change
// TODO(xsimd) bug fixed in xsimd 14.1.0
// For a bug fixed in xsimd 14.1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave the TODO as this points to code to remove in the future.

// https://github.com/xtensor-stack/xsimd/pull/1266
#if XSIMD_VERSION_MAJOR < 14 || ((XSIMD_VERSION_MAJOR == 14) && XSIMD_VERSION_MINOR == 0)
if constexpr (IsNeon<Arch>) {
using SInt = std::make_signed_t<Int>;
constexpr auto signed_shifts =
xsimd::batch_constant<SInt, Arch, static_cast<SInt>(kShifts)...>();
return xsimd::kernel::bitwise_lshift(batch, signed_shifts.as_batch(), Arch{});
}
#endif

return batch << shifts;
}
Expand Down Expand Up @@ -237,7 +240,8 @@ auto right_shift_by_excess(const xsimd::batch<Int, Arch>& batch,
constexpr auto IntSize = sizeof(Int);

// Architecture for which there is no variable right shift but a larger fallback exists.
/// TODO(xsimd) Tracking for Avx2 in https://github.com/xtensor-stack/xsimd/pull/1220
// TODO(xsimd) Tracking for Avx2 in https://github.com/xtensor-stack/xsimd/pull/1220
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the PR is also merged. Do we need #if ... for this too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to keep it because some builds use a version of xsimd that does not yet have the fix.

Do we need #if ... for this too?

Contrary to the fix in this PR, in this case the back-ported fix also works with newer xsimd versions, so we don't really need to.

// When migrating, be sure to use batch_constant overload, and not the batch one.
if constexpr (kIsAvx2 && (IntSize == sizeof(uint8_t) || IntSize == sizeof(uint16_t))) {
using twice_uint = SizedUint<2 * IntSize>;

Expand Down Expand Up @@ -265,14 +269,16 @@ auto right_shift_by_excess(const xsimd::batch<Int, Arch>& batch,
return xsimd::bitwise_rshift<kMaxRShift>(left_shift(batch, kLShifts));
}

// TODO(xsimd) bug fixed likely in xsimd>14.0.0
// TODO(xsimd) bug fixed in xsimd 14.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove TODO because the bug was fixed?

Suggested change
// TODO(xsimd) bug fixed in xsimd 14.1.0
// Fox a bug fixed in xsimd 14.1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we keep the TODO until (hopefully sooner rather than later) we bump again the minimum version of xsimd and delete that piece of code.

// https://github.com/xtensor-stack/xsimd/pull/1266
#if XSIMD_VERSION_MAJOR < 14 || ((XSIMD_VERSION_MAJOR == 14) && XSIMD_VERSION_MINOR == 0)
if constexpr (IsNeon<Arch>) {
using SInt = std::make_signed_t<Int>;
constexpr auto signed_shifts =
xsimd::batch_constant<SInt, Arch, static_cast<SInt>(kShifts)...>();
return xsimd::kernel::bitwise_rshift(batch, signed_shifts.as_batch(), Arch{});
}
#endif

return batch >> shifts;
}
Expand Down
Loading