forked from riscv-non-isa/rvv-intrinsic-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rvv_strcpy.c
44 lines (35 loc) · 966 Bytes
/
rvv_strcpy.c
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
#include "common.h"
#include <assert.h>
#include <riscv_vector.h>
#include <string.h>
// reference https://github.com/riscv/riscv-v-spec/blob/master/example/strcpy.s
char *strcpy_vec(char *dst, const char *src) {
char *save = dst;
size_t vlmax = vsetvlmax_e8m8();
long first_set_bit = -1;
size_t vl;
while (first_set_bit < 0) {
vint8m8_t vec_src = vle8ff_v_i8m8(src, &vl, vlmax);
vbool1_t string_terminate = vmseq_vx_i8m8_b1(vec_src, 0, vl);
vbool1_t mask = vmsif_m_b1(string_terminate, vl);
vse8_v_i8m8_m(mask, dst, vec_src, vl);
src += vl;
dst += vl;
first_set_bit = vfirst_m_b1(string_terminate, vl);
}
return save;
}
int main() {
const int N = 100;
const uint32_t seed = 0xdeadbeef;
srand(seed);
// data gen
char s0[N];
gen_string(s0, N);
// compute
char golden[N], actual[N];
strcpy(golden, s0);
strcpy_vec(actual, s0);
// compare
puts(strcmp(golden, actual) == 0 ? "pass" : "fail");
}