NEON函数详解-----vld1_u16、vadd_u16、vst1_u16、vcombine_s32、vget_high_s32、vget_low_s32

来源:互联网 发布:矩阵音响的连接 编辑:程序博客网 时间:2024/06/06 09:10
#include <stdio.h>
#include <arm_neon.h>


unsigned short int A[] = {1,2,3,4}; // array with 4 elements


int main(void)

{

  uint16x4_t v; // declare a vector of four 16-bit lanes


   v = vld1_u16(A); // load the array from memory into a vector


   v = vadd_u16(v,v); // double each element in the vector


  vst1_u16(A, v); // store the vector back to memory


   return 0;

}


函数功能:

               vld1_u16():     函数的功能是将内存中的数据映射到寄存器上面。这样就可以直接通过寄存器来操作数据了

   

                vadd_u16():   函数的功能是数据的加法  ,上面的数据1\2\3\4   经过函数变成 2\4\6\8

  

                vst1_u16():  函数的功能是将寄存器中的数据映射回内存中,这样就可以通过打印来看到结果了。

 

#include <arm_neon.h>
#include "stdio.h"

int data[5]={99,10,4,5,6};

int main(void)
{
    int A,B;
    int32x2_t a,b;
    int32x4_t c;
    //int32x4_t vdupq_n_s32 (int32_t __a);
    a=vdup_n_s32(data[0]);
    b=vdup_n_s32(data[1]);

    //int32x4_t vcombine_s32 (int32x2_t __a, int32x2_t __b);
    c=vcombine_s32(a,b);
    c=vqaddq_s32(c,c);
    c=vqaddq_s32(c,c);
    c=vmulq_s32(c,c);

    a=vget_high_s32(c);
    b=vget_low_s32(c);

    vst1_s32(&A,a);
    vst1_s32(&B,b);

    printf("A:%d\nB:%d \n",A,B);
    return 0;
}





0 0
原创粉丝点击