-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.cpp
101 lines (85 loc) · 2.25 KB
/
test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "riscv_vector.h"
#include <math.h>
#include <numeric>
#include <stdlib.h>
#include <valarray>
extern "C" {
void test_clampf(uint64_t n, double *__restrict x) {
#pragma clang loop vectorize(enable)
for (int i = 0; i < n; i++) {
if (x[i] > 1.0) {
x[i] = 1.0;
} else if (x[i] < -1.0) {
x[i] = -1.0;
}
}
}
void test_clamp(uint64_t n, int *__restrict x) {
#pragma clang loop vectorize(enable)
for (int i = 0; i < n; i++) {
if (x[i] > 1) {
x[i] = 1;
} else if (x[i] < -1) {
x[i] = -1;
}
}
}
void test_axpy_inner(uint64_t n, double a, const double *__restrict x,
double *__restrict y) {
uint64_t vlmax = vsetvlmax_e64m1();
uint64_t i;
vfloat64m1_t x_data = vle64_v_f64m1(x, vlmax);
vfloat64m1_t y_data = vle64_v_f64m1(y, vlmax);
y_data = vfmacc(y_data, a, x_data, vlmax);
vse64_v_f64m1(&y[i], y_data, vlmax);
}
void test_l1dist(uint64_t n, double *__restrict res, const double *__restrict x,
const double *__restrict y) {
for (int i = 0; i < n; i++) {
res[i] = abs(x[i]) + abs(y[i]);
}
}
void test_l2dist(uint64_t n, double *__restrict res, const double *__restrict x,
const double *__restrict y) {
for (int i = 0; i < n; i++) {
res[i] = sqrt(x[i] * x[i] + y[i] * y[i]);
}
}
void test_sqrt(uint64_t n, double *__restrict x) {
for (int i = 0; i < n; i++) {
x[i] = sqrt(x[i]);
}
}
void test_exp(uint64_t n, double *__restrict x) {
for (int i = 0; i < n; i++) {
x[i] = exp(x[i]);
}
}
void test_round(uint64_t n, double *__restrict x) {
for (int i = 0; i < n; i++) {
x[i] = round(x[i]);
}
}
void test_fpclassify(uint64_t n, int *__restrict c,
const double *__restrict x) {
for (int i = 0; i < n; i++) {
c[i] = fpclassify(x[i]);
}
}
void test_axpy_valarray(double a, const std::valarray<double> &x,
std::valarray<double> &y) {
y += a * x;
}
void test_axpy_valarray2(double a, const std::valarray<double> &x,
std::valarray<double> &y) {
for (size_t i = 0; i < x.size(); i++) {
y[i] += a * x[i];
}
}
void test_diff(size_t n, size_t *res, const size_t *x) {
res[0] = x[0];
for (size_t i = 1;i < n;i++) {
res[i] = x[i] - x[i-1];
}
}
}