On Sat, Sep 12, 2026 at 08:34:29PM +0800, Yuao Ma wrote:
> Thanks for the quick review! On second thought, I agree that the
> initial implementation wasn't fully vectorized. The current <simd>
> actually provides support similar to your generic vector approach.
> Instead of the shl/shr operations in the current patch, we could do
> the following:

Yeah, with whatever details Matthias/Jonathan want in there.

>   template<__simd_integral _VX, __simd_integral _VS>
>     requires (_VX::size() == _VS::size())
>       && (sizeof(typename _VX::value_type) == sizeof(typename 
> _VS::value_type))
>     [[__gnu__::__always_inline__]]
>     constexpr _VX
>     shl(const _VX& __v, const _VS& __s0) noexcept
>     {
>       using _Tp = typename _VX::value_type;
>       using _Sp = typename _VS::value_type;
>       constexpr int _Nd = sizeof(_Tp) * __CHAR_BIT__;
>       const rebind_t<_Sp, _VX> __s(__s0);
>       const _VX __sl(__s & _Sp(_Nd - 1));
>       _VX __r = select(__s < _Sp(_Nd), __v << __sl, _VX());
>       if constexpr (is_signed_v<_Sp>)
>       {
>         const _VX __sr = -__sl & _Tp(_Nd - 1);
>         if constexpr (is_signed_v<_Tp>)
>           __r = select(__s < _Sp(0),
>                        select(__s > _Sp(-_Nd), __v >> __sr, __v >> (_Nd - 
> 1)), __r);
>         else
>           __r = select(__s < _Sp(0), select(__s > _Sp(-_Nd), __v >> __sr, 
> _VX()), __r);

Just note these lines are too long.  And for the first case, it might be
better then to
          __r = select(__s < _Sp(0),
                       __v >> select(__s > _Sp(-Nd), __sr, _Sp(_Nd - 1)),
                       __r);
or
          __r = select(__s < _Sp(0), __v >> min(-__s, _Sp(_Nd - 1)), __r);

        Jakub

Reply via email to