forked from pi7mcrg2k/operator_optimization
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
751 B
31 lines
751 B
#include <arm_neon.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#define SIZE 1024
|
|
|
|
void vector_add_optimized(float* A, float* B, float* C, int size);
|
|
int main() {
|
|
float A[SIZE], B[SIZE], C[SIZE];
|
|
int i;
|
|
srand(time(0));
|
|
for(i=0; i<SIZE; i++) {
|
|
A[i] = rand() % 100;
|
|
B[i] = rand() % 100;
|
|
}
|
|
|
|
clock_t start = clock();
|
|
vector_add_optimized(A, B, C, SIZE);
|
|
clock_t end = clock();
|
|
printf("使用NEON 优化向量加法时间:%lf\n", (double)(end-start) / CLOCKS_PER_SEC);
|
|
}
|
|
|
|
void vector_add_optimized(float* A, float* B, float* C, int size) {
|
|
int i;
|
|
for(i=0; i<size; i+=4) {
|
|
float32x4_t vecA = vld1q_f32(&A[i]);
|
|
float32x4_t vecB = vld1q_f32(&B[i]);
|
|
float32x4_t vecC = vaddq_f32(vecA, vecB);
|
|
vst1q_f32(&C[i], vecC);
|
|
}
|
|
} |