1414
1515#include < algorithm>
1616#include < array>
17+ #include < cassert>
1718#include < complex>
1819#include < tuple>
1920#include < type_traits>
@@ -2372,6 +2373,17 @@ namespace xsimd
23722373 return bitwise_lshift (lhs, n, ::xsimd::detail::int_sequence<Is...>());
23732374 }
23742375 }
2376+
2377+ template <class A , class T >
2378+ XSIMD_INLINE bool all_positive (batch<T, A> const & b) noexcept
2379+ {
2380+ for (std::size_t k = 0 ; k < b.size ; ++k)
2381+ {
2382+ if (b.get (k) < 0 )
2383+ return false ;
2384+ }
2385+ return true ;
2386+ }
23752387 }
23762388
23772389 template <class A , class T >
@@ -2386,6 +2398,7 @@ namespace xsimd
23862398 XSIMD_INLINE batch<T, A> bitwise_lshift (batch<T, A> const & lhs, batch<T, A> const & rhs, requires_arch<neon>) noexcept
23872399 {
23882400 // Blindly converting to signed since out of bounds shifts are UB anyways
2401+ assert (detail::all_positive (rhs));
23892402 return vshlq_u8 (lhs, vreinterpretq_s8_u8 (rhs));
23902403 }
23912404
@@ -2399,6 +2412,7 @@ namespace xsimd
23992412 XSIMD_INLINE batch<T, A> bitwise_lshift (batch<T, A> const & lhs, batch<T, A> const & rhs, requires_arch<neon>) noexcept
24002413 {
24012414 // Blindly converting to signed since out of bounds shifts are UB anyways
2415+ assert (detail::all_positive (rhs));
24022416 return vshlq_u16 (lhs, vreinterpretq_s16_u16 (rhs));
24032417 }
24042418
@@ -2412,6 +2426,7 @@ namespace xsimd
24122426 XSIMD_INLINE batch<T, A> bitwise_lshift (batch<T, A> const & lhs, batch<T, A> const & rhs, requires_arch<neon>) noexcept
24132427 {
24142428 // Blindly converting to signed since out of bounds shifts are UB anyways
2429+ assert (detail::all_positive (rhs));
24152430 return vshlq_u32 (lhs, vreinterpretq_s32_u32 (rhs));
24162431 }
24172432
@@ -2425,6 +2440,7 @@ namespace xsimd
24252440 XSIMD_INLINE batch<T, A> bitwise_lshift (batch<T, A> const & lhs, batch<T, A> const & rhs, requires_arch<neon>) noexcept
24262441 {
24272442 // Blindly converting to signed since out of bounds shifts are UB
2443+ assert (detail::all_positive (rhs));
24282444 return vshlq_u64 (lhs, vreinterpretq_s64_u64 (rhs));
24292445 }
24302446
@@ -2626,6 +2642,7 @@ namespace xsimd
26262642 XSIMD_INLINE batch<T, A> bitwise_rshift (batch<T, A> const & lhs, batch<T, A> const & rhs, requires_arch<neon>) noexcept
26272643 {
26282644 // Blindly converting to signed since out of bounds shifts are UB anyways
2645+ assert (detail::all_positive (rhs));
26292646 return vshlq_u8 (lhs, vnegq_s8 (vreinterpretq_s8_u8 (rhs)));
26302647 }
26312648
@@ -2639,6 +2656,7 @@ namespace xsimd
26392656 XSIMD_INLINE batch<T, A> bitwise_rshift (batch<T, A> const & lhs, batch<T, A> const & rhs, requires_arch<neon>) noexcept
26402657 {
26412658 // Blindly converting to signed since out of bounds shifts are UB anyways
2659+ assert (detail::all_positive (rhs));
26422660 return vshlq_u16 (lhs, vnegq_s16 (vreinterpretq_s16_u16 (rhs)));
26432661 }
26442662
@@ -2652,6 +2670,7 @@ namespace xsimd
26522670 XSIMD_INLINE batch<T, A> bitwise_rshift (batch<T, A> const & lhs, batch<T, A> const & rhs, requires_arch<neon>) noexcept
26532671 {
26542672 // Blindly converting to signed since out of bounds shifts are UB anyways
2673+ assert (detail::all_positive (rhs));
26552674 return vshlq_u32 (lhs, vnegq_s32 (vreinterpretq_s32_u32 (rhs)));
26562675 }
26572676
0 commit comments