首页 > 解决方案 > uint32x2x2_t 和 int32x4_t 之间的 arm-neon 转换

问题描述

我正在尝试为使用sse2neon_mm_mul_epu32的某些代码实现一个等效的霓虹灯下降,因为它是代码使用的唯一调用,而sse2neon没有等效的代码。_mm_mul_epu32

FORCE_INLINE __m128i _mm_mul_epu32(__m128i a, __m128i b)
{
    // shuffle: 0, 1, 2, 3 -> 0, 2, 1, 3 */
    __m128i const a_shuf = (int32x4_t)(vzip_u32(vget_low_u32(vreinterpretq_u32_m128i(a)), vget_high_u32(vreinterpretq_u32_m128i(a))));
    __m128i const b_shuf = (int32x4_t)(vzip_u32(vget_low_u32(vreinterpretq_u32_m128i(b)), vget_high_u32(vreinterpretq_u32_m128i(b))));

    // Multiply low word (32 bit) against low word (24 bit) and high word (32 bit) against high word (32 bit).
    // Pack both results (64 bit) into 128 bit register and return result.
    return vreinterpretq_m128i_u64(vmull_u32(vget_low_u32(vreinterpretq_u32_m128i(a_shuf)), vget_low_u32(vreinterpretq_u32_m128i(b_shuf))));
}

我有一些似乎基本上是等价的 - 但是我不确定将vzip_u32(which is uint32x2x2_t) 的结果转换为其他函数期望的正确方法是什么int32x4_t

对于大多数其他霓虹灯转换,有转换功能,例如vreinterpretq_u32_s32,但我找不到这个。

我可以强制强制转换编译,如果我这样做结果是正确的(通过我的测试向量),但是我不喜欢这样,并且想知道是否有更正确的方法来处理事情。

在这些类型之间转换的正确方法是什么,有吗?或者有没有更好的方法来进行洗牌,这样我就可以完全避免转换?

带有一些强制转换的 Godbolt 示例: https ://godbolt.org/z/gRDpRs https://godbolt.org/z/H-3fOt

标签: assemblyarmintrinsicsneon

解决方案


推荐阅读