Skip to content

Commit 5cf2106

Browse files
committed
raid: R-V V xor_gen
banana_f3: new: xor_gen_warm: runtime = 3006459 usecs, bandwidth 10685 MB in 3.0065 sec = 3554.17 MB/s old: xor_gen_warm: runtime = 3060970 usecs, bandwidth 514 MB in 3.0610 sec = 168.21 MB/s Signed-off-by: sunyuechi <sunyuechi@iscas.ac.cn>
1 parent 0593430 commit 5cf2106

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

raid/riscv64/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030
lsrc_riscv64 += \
3131
raid/riscv64/raid_multibinary_riscv64_dispatcher.c \
3232
raid/riscv64/raid_multibinary_riscv64.S \
33-
raid/riscv64/raid_pq_gen_rvv.S
33+
raid/riscv64/raid_pq_gen_rvv.S \
34+
raid/riscv64/raid_xor_gen_rvv.S

raid/riscv64/raid_multibinary_riscv64.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131

3232
#if HAVE_RVV
3333
mbin_interface pq_gen
34+
mbin_interface xor_gen
3435
#else
3536
mbin_interface_base pq_gen pq_gen_base
37+
mbin_interface_base xor_gen xor_gen_base
3638
#endif
3739

3840
mbin_interface_base pq_check pq_check_base
39-
mbin_interface_base xor_gen xor_gen_base
4041
mbin_interface_base xor_check xor_check_base

raid/riscv64/raid_multibinary_riscv64_dispatcher.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ DEFINE_INTERFACE_DISPATCHER(pq_gen)
3838
#endif
3939
return PROVIDER_BASIC(pq_gen);
4040
}
41+
42+
DEFINE_INTERFACE_DISPATCHER(xor_gen)
43+
{
44+
#if HAVE_RVV
45+
const unsigned long hwcap = getauxval(AT_HWCAP);
46+
if (hwcap & HWCAP_RV('V'))
47+
return PROVIDER_INFO(xor_gen_rvv);
48+
else
49+
#endif
50+
return PROVIDER_BASIC(xor_gen);
51+
}

raid/riscv64/raid_xor_gen_rvv.S

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**********************************************************************
2+
Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS).
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in
11+
the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of ISCAS Corporation nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
**********************************************************************/
29+
#if HAVE_RVV
30+
.option arch, +v
31+
.global xor_gen_rvv
32+
.type xor_gen_rvv, %function
33+
xor_gen_rvv:
34+
beqz a1, ret0 # len <= 0, return 0
35+
addi t1, a0, -2 # vects - 3
36+
blez t1, ret1 # vects < 3, return 1
37+
38+
slli t0, a0, 3 # t0 = vects * 8
39+
add t0, a2, t0 # array + vects * 8
40+
ld a4, 0(a2) # src[0]
41+
ld a3, -8(t0) # dest = array[vects - 1]
42+
mv t5, a3 # save dest
43+
mv t6, a1 # save len
44+
45+
init_dest:
46+
vsetvli t4, t6, e8, m8, ta, ma
47+
vle8.v v0, (a4) # load src[0]
48+
vse8.v v0, (a3) # dest
49+
sub t6, t6, t4
50+
add a4, a4, t4
51+
add a3, a3, t4
52+
bnez t6, init_dest
53+
54+
outer_j:
55+
mv a3, t5 # restore dest
56+
mv t6, a1 # restore length
57+
ld a4, -16(t0)
58+
59+
inner_len:
60+
vsetvli t4, t6, e8, m8, ta, ma
61+
vle8.v v0, (a4) # src[j]
62+
vle8.v v8, (a3) # dest
63+
vxor.vv v8, v8, v0 # dest ^= src[j]
64+
vse8.v v8, (a3)
65+
sub t6, t6, t4
66+
add a4, a4, t4
67+
add a3, a3, t4
68+
bnez t6, inner_len
69+
70+
addi t1, t1, -1
71+
addi t0, t0, -8
72+
bnez t1, outer_j
73+
74+
ret0:
75+
li a0, 0
76+
ret
77+
78+
ret1:
79+
li a0, 1
80+
ret
81+
82+
#endif

0 commit comments

Comments
 (0)