-
Notifications
You must be signed in to change notification settings - Fork 2
/
axpy.cpp
57 lines (44 loc) · 1.31 KB
/
axpy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "riscv_vector.h"
#include <stdlib.h>
extern "C" {
void axpy(uint64_t n, double a, const double *__restrict x,
double *__restrict y) {
#pragma clang loop vectorize(disable)
for (uint64_t i = 0; i < n; i++) {
y[i] += a * x[i];
}
}
void axpy_compiler_vectorize(uint64_t n, double a, const double *__restrict x,
double *__restrict y) {
#pragma clang loop vectorize(enable)
for (uint64_t i = 0; i < n; i++) {
y[i] += a * x[i];
}
}
void axpy_rvv(uint64_t n, double a, const double *__restrict x,
double *__restrict y) {
for (uint64_t i = 0; i < n;) {
uint64_t vl = vsetvl_e64m1(n - i);
vfloat64m1_t x_data = vle64_v_f64m1(&x[i], vl);
vfloat64m1_t y_data = vle64_v_f64m1(&y[i], vl);
y_data = vfmacc(y_data, a, x_data, vl);
vse64_v_f64m1(&y[i], y_data, vl);
i += vl;
}
}
void axpy_rvv2(uint64_t n, double a, const double *__restrict x,
double *__restrict y) {
uint64_t vlmax = vsetvlmax_e64m1();
uint64_t i;
for (i = 0; i + vlmax < n;) {
vfloat64m1_t x_data = vle64_v_f64m1(&x[i], vlmax);
vfloat64m1_t y_data = vle64_v_f64m1(&y[i], vlmax);
y_data = vfmacc(y_data, a, x_data, vlmax);
vse64_v_f64m1(&y[i], y_data, vlmax);
i += vlmax;
}
for (; i < n; i++) {
y[i] += a * x[i];
}
}
}