NEON Intrinsics

  • 本篇博客将对NEON Intrinsic进行介绍,同时末尾会给出几个example。如有谬误,烦请指出,谢谢。

Introduction

  • NEON Intrinsics是一种比汇编更高级的API,可以直接在C/C++中进行调用。使用汇编,我们可以对更多的硬件执行细节进行控制,但是汇编相对来说维护代价较高。相比之下,NEON Intrinsic易于维护,同时也可以对硬件执行细节进行一定程度的控制。编译器会将NEON Intrinsic调用替换成对应的NEON指令。NEON Intrinsic定义在arm_neon.h中,包含一些函数和数据类型。

Data Type

  • NEON vector数据类型的命名规则如下:

    x_t

    例如:int16x4_t 定义一个包含4个元素的short类型vector
  • NEON 支持vector数组,规则如下:

    xx_t

    例如:int16x4x2_t指由两个int16x4_t类型组成的数组。

NEON Intrinsics

  • NEON Intrinsic明明规则如下:

    _

    例如:
    • vmul_s16,两个s16类型的vector相乘
    • vadd_u8, add two 64-bit vectors containing unsigned 8-bit and return 64-bit vectors, doubleword registers
    • vaddq_u8, add two 128-bit vectors containing unsigned 8-bit and return 128-bit vectors, quadword registers
    • vaddl_u8, vector add long unsigned 8-bit, add two 64-bit vectors containing unsigned 8-bit and return 128-bit vectors containing unsigned 16-bit

Variabls and constants

uint32x2_t vec64a, vec64b;              // create two D-register variables
uint8x8_t start_value = vdup_n_u8(0);   // create D-register with initial value 0
result = vget_lane_u32(vec64a, 0);      // extract lane 0
vec64a = vget_low_u32(vec128);          // split 128-bit vector into 2x 64-bit vectors
vec64b = vget_high_u32(vec128);

Load and Store

unsigned short int A[] = {1,2,3,4};
uint16x4_t v;           // declare a vector of four 16-bit lanes
v = vld1_u16(A);        // vector load 1-way unsigned 16-bit
vst1_u16(A, v);         // vector store 1-way unsigned 16-bit

uint8x8x3_t v;          // This represents 3 vectors, each vector has eight lanes of 8-bit data
unsigned char A[24];    // This array represents a 24-bit RGB image
v = vld3_u8(A);         // vector load 3-way unsigned 8-bit
vst3_u8(A, v);          // vector store 3-way unsigned 8-bit

Example

  1. neon_intrinsics.c
  2. neon_load.c
  3. neon_interleave.c

你可能感兴趣的:(计算机,NEON)