如何使用x86 SIMD有效地将8位位图转换为0/1整数数组 [英] How to efficiently convert an 8-bit bitmap to array of 0/1 integers with x86 SIMD
问题描述
我想将8位整数转换为大小为8的数组,每个值都包含一个整数的位值.
I want to convert 8 bit integer to an array of size 8 with each value containing the bit value of an integer.
例如:我有int8_t x = 8;
,我想将其转换为int8_t array_x = {0,0,0,0,1,0,0,0};
For example: I have int8_t x = 8;
I want to convert this to int8_t array_x = {0,0,0,0,1,0,0,0};
由于此计算是信号处理模块的一部分,因此必须有效地完成此操作.有没有一种有效的方法可以做到这一点?我确实检查了混合说明.当具有大小为8位的数组元素时,它不符合我的要求.开发平台是AMD Ryzen.
This has to be done efficiently, since this calculation is part of signal processing block. Is there a efficient way to do this? I did check the blend the instruction. It didn't suit my requirement when having array elements of size 8-bit. development platform is AMD Ryzen.
推荐答案
具有0x00:0x01
格式结果的单个字节的逆移动掩码",带有SIMD,但没有BMI2.
"Inverse movemask" for a single byte with 0x00:0x01
formatted results, with SIMD but without BMI2.
__m128i v = _mm_set1_epi8(bitmap);
v = _mm_and_si128(v, _mm_set_epi32(0, 0, 0x80402010, 0x08040201));
v = _mm_min_epu8(v, _mm_set1_epi8(1));
_mm_storel_epi64((__m128i*)&array_x[0], v);
这篇关于如何使用x86 SIMD有效地将8位位图转换为0/1整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!