sgemv.c (832B)
1 #include <stdlib.h> 2 3 void sgemv_noalias(const float *A, 4 const float *x, 5 float *__restrict__ y, 6 const int *n) 7 { 8 const int N = *n; 9 for (int j = 0; j < N; ++j) { 10 for (int i = 0; i < N; ++i) { 11 y[j] += A[j * N + i] * x[i]; 12 } 13 } 14 } 15 16 void sgemv_alias(const float *A, const float *x, float *y, const int *n) 17 { 18 const int N = *n; 19 for (int j = 0; j < N; ++j) { 20 for (int i = 0; i < N; ++i) { 21 y[j] += A[j * N + i] * x[i]; 22 } 23 } 24 } 25 26 void sgemv_temporary(const float *A, const float *x, float *y, const int *n) 27 { 28 const int N = *n; 29 for (int j = 0; j < N; ++j) { 30 float temp = 0.0f; 31 for (int i = 0; i < N; ++i) { 32 temp += A[j * N + i] * x[i]; 33 } 34 y[j] += temp; 35 } 36 }