如何使用 x86 SIMD 有效地将 8 位位图转换为 0/1 整数数组 [英] How to efficiently convert an 8-bit bitmap to array of 0/1 integers with x86 SIMD

查看:16
本文介绍了如何使用 x86 SIMD 有效地将 8 位位图转换为 0/1 整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 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.

推荐答案

Inverse movemask"用于具有 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆