NEON 常用函数及其执行结果

简介: NEON 常用函数及其执行结果

         

令初始数据为:

float d0[4] = {0.f, 1.f, 2.f, 3.f};
float d1[4] = {4.f, 5.f, 6.f, 7.f};
float d2[4] = {8.f, 9.f, 10.f, 11.f};
float d3[4] = {12.f, 13.f, 14.f, 15.f};

一、基本的加载存储操作

1. vld1q_f32

float32x4_t q0 = vld1q_f32(d0); // 加载 d0 地址起始的 4 个 float 数据到 q0

image.png

2.vst1q_f32

vst1q_f32(d1, q0);// 将 q0 中 4 个 float32,赋值给以 d1 为起始地址的 4 个 float32

image.png

3.vld2q_f32

float d4[8]= {1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f};
float32x4x2_t ret = vld2q_f32 (d4);

image.png

注意,此时在寄存器是交错读取的!

4.vst2q_f32

vst2q_f32 (d4, ret);

image.png

注意,由于寄存器是交错存储的,所以内存保持不变!

5.vld3q_f32

float d5[12] = {1.f, 2.f, 3.f, 4.f,
5.f, 6.f, 7.f, 8.f,
9.f, 10.f, 11.f, 12.f};
float32x4x3_t f = vld3q_f32 (d5);

image.png

6.vst3q_f32

vst3q_f32 (d5, f);

image.png

7.vld4q_f32, vst4q_f32

二、特殊操作

1.vdupq_n_f32

float32x4_t res = vdupq_n_f32(0.f); // 存储的四个 float32 都初始化为 0

image.png


2.vzipq_f32

float32x4x2_t q4 = vzipq_f32 (q0, q1);

image.png

3.vuzpq_f32

float32x4x2_t ret = vuzpq_f32 (q0, q1);

image.png

可见,打包 (zip)、拆包(unzip)并不是想当然的可逆的运算

4.vcombine_f32

float32x2_t a = vget_low_f32(q0);
float32x2_t b = vget_high_f32(q0);
float32x4_t ret = vcombine_f32 (a, b);

image.png

5. vget_low_f32

float32x2_t low = vget_low_f32(q0); // 取低2位

image.png

6. vget_high_f32

float32x2_t high = vget_high_f32(q0); // 取高2位

image.png

7. vtrnq_f32

float32x4x2_t ret = vtrnq_f32 (q0, q1)

image.pngimage.png

8. vextq_f32

// 拼接两个寄存器并返回从第 n 位开始的大小为4的寄存器 0<=n<=3 
res = vextq_f32(q0, q1, 2); //取 q1 低2位,拼接到 q0 的高位,保留 q0 的高2位(移到低位)
// q0, q1 实际数据没有变化

image.pngimage.png

  • vext_u8 的例子:
uint8x8_t ret = vext_u8 (p, q, 2); // 取 q 的低两位作为 p 的高位,p 向左移动两位腾出空间

image.png

9.vget_lane_f32

float lane0 = vget_lane_f32(ss0, 0);// get 0th parameter in vector

image.pngimage.png

10. vsetq_lane_f32

float32x4_t res = vsetq_lane_f32(d1[0], q1, 1);//用 d1[0] 的数据替换掉 q1[1](q1 实际数据没有变化)

image.png

11.vtbl1_s8

int8x8_t r = vtbl1_s8 (p, q);

image.png

12.vrev16_s8

int8x8_t s = vrev16_s8 (q);

image.pngimage.png

三、基本数据类型的转换

1.vcvtq_u32_f32

uint32x4_t ui0 = vcvtq_u32_f32 (q0);

image.png

2.vcvtq_s32_f32

int32x4_t i0 = vcvtq_s32_f32 (q1);

image.png

3. vcvtq_f32_s32

float32x4_t f0 = vcvtq_f32_s32 (i0);

image.png

4.vcvtq_f32_u32

float32x4_t uf0 = vcvtq_f32_u32 (ui0)

image.png

四、基本比较运算

1.vceq_f32  

uint32x2_t c = vceq_f32 (a, b); // 等于

image.png

2.vceqq_f32

uint32x4_t q = vceqq_f32 (q1, q2); // 等于

image.pngimage.png

3. vmaxq_f32

float32x4_t ret = vmaxq_f32 (q2, q1);

image.pngimage.png

4. vminq_f32

float32x4_t ret0 = vminq_f32 (q2, q1);

image.pngimage.png

5.vpmax_s8

int8x8_t r = vpmax_s8 (p, q);

image.pngimage.png

6.vpmin_s8

int8x8_t s = vpmin_s8 (p, q);

image.pngimage.png

五、基本的位运算

1.vclsq_s32

int32x4_t q1 = vclsq_s32 (q0); // 统计和符号位相同的 bit 数(不包括符号位)

image.png

2.vclzq_s32 2.vclzq_s32

int32x4_t q2 = vclzq_s32 (q0); // 统计前缀 0 的个数

image.pngimage.png

3.vcnt_s8

int8_t d0[8] = {0, 1, 2, 3, 4, 5, 6, 7};
int8x8_t q = vld1_s8(d0);
int8x8_t p = vcnt_s8 (q); // 二进制形式的 1 的个数

image.png

4.vmvn_s8

int8x8_t q = vmvn_s8 (p); // 按位取反

image.png

5.vqneg_s8

int8x8_t r = vqneg_s8 (p);

image.pngimage.png

6. vqshl_s8

int8_t d0[8] = {0, 1, 2, 3, 4, 5, 6, 7};
int8_t d1[8] = {1, 1, 2, 2, 3, 3, 4, 4};
int8x8_t p = vld1_s8(d0);
int8x8_t q = vld1_s8(d1);
int8x8_t pq = vqshl_s8 (p, q); // 左移对应的位数

image.png

如果移位是负数 ,则变成截断的右移

int8_t d0[8] = {0, 1, 2, 3, 4, 5, 6, 7};
int8_t d1[8] = {-1, -1, -2, -2, -3, -3, -4, -4};
int8x8_t p = vld1_s8(d0);
int8x8_t q = vld1_s8(d1);
int8x8_t pq = vqshl_s8 (p, q);

image.png

六、基本的逻辑运算

七、基本的算术运算

1.vadd_f32

float32x2_t ss0 = vadd_f32(vget_low_f32(q2), vget_high_f32(q2));//对应元素相加

image.png

2.vaddq_f32

float32x4_t q4 = vaddq_f32 (q1, q2);

image.pngimage.png

3.vpadd_f32

float32x2_t ss1 = vpadd_f32(vget_low_f32(q2), vget_high_f32(q2));//相邻元素相加

image.png

3.vmulq_f32

float32x4_t res0 = vmulq_f32(q0, q1); //点乘

image.pngimage.png

4. vmlaq_f32

float32x4_t res1 = vmlaq_f32(q0, q1, q2);// q0 + q1*q2

image.pngimage.png

5.vmlaq_lane_f32

//  ri = ai + bi * c[d];
float32x4_t res = vmlaq_lane_f32(q0, q1, vget_low_f32(q2), 0);//取 q2 的第0个数,分别与 q1 中的 4 个数相乘,得到 4 个结果与 q0 累加

image.pngimage.png

6.vmaxq_f3

float32x4_t max = vmaxq_f32(q1, q2);//对应元素比较,取最大

image.pngimage.png

7.vrecpeq_f32

float32x4_t q5 = vrecpeq_f32 (q1); // 倒数

image.png

8.vrsqrteq_f32

float32x4_t q6 = vrsqrteq_f32 (q1); // 倒数平方根

image.png

待续

目录
相关文章
|
1月前
|
Perl
|
1月前
|
Perl
|
1月前
|
自然语言处理 Perl
|
1月前
|
Perl
|
1月前
|
Perl
|
1月前
|
Perl
|
1月前
|
自然语言处理 Perl
|
1月前
|
Perl
|
1月前
|
Perl
|
11月前
|
Python
Python built-in module time 内建时间库常用函数
Python built-in module time 内建时间库常用函数
86 0