如何使用Neon SIMD将unsigned char转换为有符号整数

use*_*225 3 c arm simd neon

如何将数据类型的变量转换uint8_tint32_t使用Neon?这样做我找不到任何内在的东西.

Pau*_*l R 6

假设您要将16 x 8位整数的向量转换为4 x 32位整数的四个向量,您可以先将数据包解压缩到16位然后再转换为32位:

// load 8 bit vector
uint8x16_t v = vld1q_u8(p);   // load vector of 16 x 8 bits ints from p

// unpack to 16 bits
int16x8_t vl =  vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(v)));   // 0..7
int16x8_t vh =  vreinterpretq_s16_u16(vmovl_u8(vget_high_u8(v)));  // 8..15

// unpack to 32 bits
int32x4_t vll = vmovl_s16(vget_low_s16(vl));           // 0..3
int32x4_t vlh = vmovl_s16(vget_high_s16(vl));          // 4..7
int32x4_t vhl = vmovl_s16(vget_low_s16(vh));           // 8..11
int32x4_t vhh = vmovl_s16(vget_high_s16(vh));          // 12..15
Run Code Online (Sandbox Code Playgroud)

  • NEON向量类型不能保证可以通过强制转换来转换,因此对于大多数可移植性,您应该编写`vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(v)))` (4认同)