lib/std/mem.ras 919 B raw
1
//! Byte-wide bulk memory stores. Vector state is caller-saved.
2
.text;
3
// a0 is the output address; a1 is its nonzero byte count; a2 is the value.
4
.export @"std::mem::fillBytes";
5
@"std::mem::fillBytes"
6
    vsetvli %t0 %a1 e8 m8 ta ma;
7
    vmv.v.x %v8 %a2;
8
    vse8.v %v8 (%a0);
9
    add %a0 %a0 %t0;
10
    sub %a1 %a1 %t0;
11
    bnez %a1 @"std::mem::fillBytes";
12
    ret;
13
14
// a0 is the output; a1 is the pattern; a2 is the repetition count;
15
// a3 is the pattern width. Count and width must both be nonzero.
16
.export @"std::mem::repeatBytes";
17
@"std::mem::repeatBytes"
18
    vsetvli %t0 %a2 e8 m8 ta ma;
19
    mv %t1 %a0;
20
    mv %t2 %a1;
21
    mv %t3 %a3;
22
@repeatByte
23
    lbu %t4 0(%t2);
24
    vmv.v.x %v8 %t4;
25
    vsse8.v %v8 (%t1) %a3;
26
    addi %t1 %t1 1;
27
    addi %t2 %t2 1;
28
    addi %t3 %t3 -1;
29
    bnez %t3 @repeatByte;
30
    mul %t1 %t0 %a3;
31
    add %a0 %a0 %t1;
32
    sub %a2 %a2 %t0;
33
    bnez %a2 @"std::mem::repeatBytes";
34
    ret;