From 7fc1f141cef7caf7967835abd178292b8fb72987 Mon Sep 17 00:00:00 2001 From: pjc97uv2f <1291955673@qq.com> Date: Sat, 23 Nov 2024 11:18:03 +0800 Subject: [PATCH] Add 2 --- 2 | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 2 diff --git a/2 b/2 new file mode 100644 index 0000000..22b7534 --- /dev/null +++ b/2 @@ -0,0 +1,58 @@ +#include +#include +#include + +#include + + +#define SIZE 1024 + + +void vector_add_optimized(float* A, float* B, float* C, int size) { + int i; + for (i = 0; i < size - 3; i += 4) { + + float32x4_t a_vec = vld1q_f32(&A[i]); + float32x4_t b_vec = vld1q_f32(&B[i]); + + + float32x4_t result_vec = vaddq_f32(a_vec, b_vec); + + + vst1q_f32(&C[i], result_vec); + } + + + for (; i < size; i++) { + C[i] = A[i] + B[i]; + } +} + +int main() { + + float A[SIZE]; + float B[SIZE]; + float C[SIZE]; + + + for (int i = 0; i < SIZE; i++) { + A[i] = (float)(rand() % 100); + B[i] = (float)(rand() % 100); + } + + clock_t start_time, end_time; + + start_time = clock(); + + + vector_add_optimized(A, B, C, SIZE); + + + end_time = clock(); + + + double elapsed_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; + printf("NEON优化向量加法的运行时间:%f 秒\n", elapsed_time); + + return 0; +} \ No newline at end of file