【NEON】vadd_s8

发布于:2025-07-22 ⋅ 阅读:(8) ⋅ 点赞:(0)

code

#include <iostream>
#include <iomanip>
#include <arm_neon.h>

/***********************************************************************************************************************
 * ref: https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics
 *
 * vld1_s8
 * 此指令从内存加载多个单元素结构,并将结果写入SIMD寄存器。
 *
 * vst1_s8
 * 此指令从SIMD寄存器中将元素存储到内存中,不进行交叉存储。每个寄存器的每个元素都会被存储。
 *
 * vadd_s8
 * 相加(向量)。该指令将两个源 SIMD 与浮点寄存器中的对应元素相加,将结果放入一个向量中,并将该向量写入目标 SIMD 与浮点寄存器。
 **********************************************************************************************************************/

void print_int8x8(int8x8_t vec, const std::string& desc) {
  int8_t arr[8];
  vst1_s8(arr, vec);

  std::cout << std::setw(10) << desc << ", int8x8_t: [";
  for (const signed char i : arr) {
    std::cout << std::setw(5) << static_cast<int>(i) << ", ";
  }
  std::cout << "]" << std::endl;
}


int main(int argc, char* argv[]) {
  {
    const int8_t arr_a[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    const int8_t arr_b[8] = {1, 2, 3, 4, 5, 6, 7, 8};
    int8x8_t     a        = vld1_s8(arr_a);
    int8x8_t     b        = vld1_s8(arr_b);
    int8x8_t     c        = vadd_s8(a, b);

    print_int8x8(a, "a");
    print_int8x8(b, "b");
    print_int8x8(c, "c");
  }
}

output

         a, int8x8_t: [    1,     2,     3,     4,     5,     6,     7,     8, ]
         b, int8x8_t: [    1,     2,     3,     4,     5,     6,     7,     8, ]
         c, int8x8_t: [    2,     4,     6,     8,    10,    12,    14,    16, ]

网站公告

今日签到

点亮在社区的每一天
去签到