gpt4 book ai didi

arm - ARM NEON 的 SSE _mm_movemask_epi8 等效方法

转载 作者:行者123 更新时间:2023-12-02 21:04:41 25 4
gpt4 key购买 nike

我决定继续快速拐角优化并停留在_mm_movemask_epi8 SSE指令。如何使用 uint8x16_t 输入为 ARM Neon 重写它?

最佳答案

我知道这篇文章已经过时了,但我发现提供我的(经过验证的)解决方案很有用。它假定输入参数的每个 channel 中全为 1/全 0。

const uint8_t __attribute__ ((aligned (16))) _Powers[16]= 
{ 1, 2, 4, 8, 16, 32, 64, 128, 1, 2, 4, 8, 16, 32, 64, 128 };

// Set the powers of 2 (do it once for all, if applicable)
uint8x16_t Powers= vld1q_u8(_Powers);

// Compute the mask from the input
uint64x2_t Mask= vpaddlq_u32(vpaddlq_u16(vpaddlq_u8(vandq_u8(Input, Powers))));

// Get the resulting bytes
uint16_t Output;
vst1q_lane_u8((uint8_t*)&Output + 0, (uint8x16_t)Mask, 0);
vst1q_lane_u8((uint8_t*)&Output + 1, (uint8x16_t)Mask, 8);

(无论如何,请记住 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47553 。)

与 Michael 类似,技巧是形成非空条目索引的幂,并将它们两两求和 3 次。这必须通过增加数据大小来完成,以使每次添加的步幅加倍。您可以将 2 x 8 8 位条目减少到 2 x 4 16 位,然后减少到 2 x 2 32 位和 2 x 1 64 位。这两个数字的低字节给出了解决方案。我认为没有一种简单的方法可以使用 NEON 将它们打包在一起形成单个短值。

如果输入的形式合适并且可以预加载功率,则需要 6 个 NEON 指令。

关于arm - ARM NEON 的 SSE _mm_movemask_epi8 等效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11870910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com