| 164 | /// 2015. http://arxiv.org/abs/1209.2137 |
| 165 | template <typename Arch, typename Int, Int... kShifts> |
| 166 | ARROW_FORCE_INLINE auto right_shift_by_excess( |
| 167 | const xsimd::batch<Int, Arch>& batch, |
| 168 | xsimd::batch_constant<Int, Arch, kShifts...> shifts) { |
| 169 | constexpr bool kIsSse2 = IsSse2<Arch>; |
| 170 | constexpr bool kIsAvx2 = IsAvx2<Arch>; |
| 171 | static_assert( |
| 172 | !(kIsSse2 && kIsAvx2), |
| 173 | "In xsimd, an x86 arch is either part of the SSE family or of the AVX family," |
| 174 | "not both. If this check fails, it means the assumptions made here to detect SSE " |
| 175 | "and AVX are out of date."); |
| 176 | |
| 177 | constexpr auto IntSize = sizeof(Int); |
| 178 | |
| 179 | // Architectures for which there is no variable right shift but a larger fallback |
| 180 | // exists. |
| 181 | if constexpr (kIsAvx2 && (IntSize == sizeof(uint8_t) || IntSize == sizeof(uint16_t))) { |
| 182 | using twice_uint = SizedUint<2 * IntSize>; |
| 183 | |
| 184 | const auto batch2 = xsimd::bitwise_cast<twice_uint>(batch); |
| 185 | |
| 186 | constexpr auto kShifts0 = select_stride<twice_uint, 0>(shifts); |
| 187 | constexpr auto kMask0 = bit_util::LeastSignificantBitMask<twice_uint>(8 * IntSize); |
| 188 | const auto shifted0 = right_shift_by_excess(batch2 & kMask0, kShifts0); |
| 189 | |
| 190 | constexpr auto kShifts1 = select_stride<twice_uint, 1>(shifts); |
| 191 | constexpr auto kMask1 = static_cast<twice_uint>(kMask0 << (8 * IntSize)); |
| 192 | const auto shifted1 = right_shift_by_excess(batch2, kShifts1) & kMask1; |
| 193 | |
| 194 | return xsimd::bitwise_cast<Int>(shifted0 | shifted1); |
| 195 | } |
| 196 | |
| 197 | // Architectures for which there is no variable right shift but a left shift exists |
| 198 | // (possibly using the multiply trick inside of xsimd). |
| 199 | // We use a variable left shift and fixed right shift. |
| 200 | if constexpr (kIsSse2 && (IntSize != sizeof(uint64_t))) { |
| 201 | constexpr Int kMaxRShift = max_value(std::array{kShifts...}); |
| 202 | |
| 203 | constexpr auto kLShifts = |
| 204 | xsimd::make_batch_constant<Int, kMaxRShift, Arch>() - shifts; |
| 205 | |
| 206 | return xsimd::bitwise_rshift<kMaxRShift>(batch << kLShifts); |
| 207 | } |
| 208 | |
| 209 | return batch >> shifts; |
| 210 | } |
| 211 | |
| 212 | /**************************** |
| 213 | * Properties of a kernel * |
no test coverage detected