xsimd
xsimd copied to clipboard
How to cast xsimd::batch<uint8_t, 16> to xsimd::batch<uint32_t, 4>
Hi @JohanMabille @serge-sans-paille ,
Thank you for your time.
In Arrow, I would like to cast xsimd::batch<uint8_t, 16> to xsimd::batch<uint32_t, 4> for operating some shared data buffer:
using simd_batch_8 = xsimd::batch<uint8_t, 16>;
using simd_batch_32 = xsimd::batch<uint32_t, 4>;
simd_batch_32 rtn;
simd_batch_8 lhs, rhs;
rtn= xsimd::zip_lo(
static_cast<simd_batch_32>(lhs),
static_cast<simd_batch_32>(rhs),);
It failed to compile in Arm Neon, but it works correctly in x86 SSE:
error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
367 | using is_array_initializer_t = typename is_array_initializer<T, N, Args...>::type;
I noted that it would check the variadic arguments of template:
template <class... Args, class Enable = detail::is_array_initializer_t<uint8_t, 16, Args...>>
I didn't find similar checking in xsimd_sse_int8.hpp
, xsimd_sse_int16.hpp
, xsimd_sse_int32.hpp
...
It was found in Neon code branches: https://github.com/xtensor-stack/xsimd/blob/master/include/xsimd/types/xsimd_neon_int8.hpp#L49
https://github.com/xtensor-stack/xsimd/blob/master/include/xsimd/types/xsimd_neon_int16.hpp#L49
May I ask the checking of template arguments is necessary here? How to correctly cast them?
Thanks.
Hi, @serge-sans-paille Maybe I missed something. Could please share the way to cast <uint8_t, 16> to <uint32_t, 4> in xsimd?
Is it correct to cast by static_cast
?
xsimd::batch<uint8_t, 16> batch8;
xsimd::batch<uint32_t, 4> batch32;
//casting by static_cast ?
batch32 = static_cast<xsimd::batch<uint32_t, 4>>(batch8);
Yeah, that's fine, it's the same register underneath, see https://godbolt.org/z/x8Trdb1cz
ok, it's fine on X86 but not on arm, which looks like a bug to me, let me investigate that.
Thanks for your feedback.
ok, it's fine on X86 but not on arm, which looks like a bug to me, let me investigate that.
Yes, static_cast
doesn't work on Arm64.
I'm working on adding these casing operations to xsimd and would like to submit the PR soon.
I'm working on adding these casing operations to xsimd and would like to submit the PR soon.
Great! I'm looking forward to review these
@guyuqi I believe you fixed that one in #487, correct?