【问题标题】:How to convert unsigned char to signed integer using Neon SIMD如何使用 Neon SIMD 将无符号字符转换为有符号整数
【发布时间】:2015-08-12 05:56:43
【问题描述】:

如何使用 Neon 将数据类型为 uint8_t 的变量转换为 int32_t?我找不到这样做的任何内在因素。

【问题讨论】:

    标签: c arm simd neon


    【解决方案1】:

    假设您想将一个 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
    

    【讨论】:

    • 不保证 NEON 向量类型可以通过强制转换进行转换,因此对于大多数可移植性,您应该编写 vreinterpretq_s16_u16(vmovl_u8(vget_low_u8(v)))
    • @CharlesBaylis:谢谢 - 我不知道 - gcc 似乎对原始演员表很满意,但我现在根据你的建议更新了答案。
    猜你喜欢
    • 2011-06-14
    • 1970-01-01
    • 2017-07-21
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多