Skip to content

Commit e0687d4

Browse files
sunyuechipablodelara
authored andcommitted
igzip: R-V V isal_adler32
banana_f3: new: adler32_warm: runtime = 3062612 usecs, bandwidth 3861 MB in 3.0626 sec = 1261.01 MB/s old: adler32_warm: runtime = 3062505 usecs, bandwidth 1027 MB in 3.0625 sec = 335.64 MB/s Signed-off-by: sunyuechi <[email protected]>
1 parent 83d58b8 commit e0687d4

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

igzip/riscv64/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929

3030
lsrc_riscv64 += \
3131
igzip/riscv64/igzip_multibinary_riscv64_dispatcher.c \
32-
igzip/riscv64/igzip_multibinary_riscv64.S
32+
igzip/riscv64/igzip_multibinary_riscv64.S \
33+
igzip/riscv64/igzip_isal_adler32_rvv.S
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
.option arch, +v
30+
.global adler32_rvv
31+
.type adler32_rvv, %function
32+
adler32_rvv:
33+
slli t2, a0, 48
34+
srli t2, t2, 48 // t2: A = adler32 & 0xffff;
35+
srliw t3, a0, 16 // t3: B = adler32 >> 16;
36+
beqz a2, 2f
37+
38+
vsetvli zero, a2, e64, m8, tu, ma
39+
vmv.v.i v8, 0
40+
vmv.v.i v16, 0
41+
vmv.s.x v24, zero
42+
mv t6, a2 // t6 = length
43+
vsetvli zero, zero, e32, m4, tu, ma
44+
vmv.s.x v8, t2 // v8 = adler32 & 0xffff
45+
46+
1:
47+
vsetvli t1, a2, e8, m1, tu, ma
48+
vle8.v v0, (a1)
49+
vsetvli zero, zero, e32, m4, tu, ma
50+
vzext.vf4 v4, v0
51+
vid.v v12 // 0, 1, 2, .. vl-1
52+
vadd.vv v8, v8, v4
53+
vrsub.vx v12, v12, a2 // len, len-1, len-2
54+
vwmaccu.vv v16, v12, v4 // v16: B += weight * next
55+
sub a2, a2, t1
56+
add a1, a1, t1
57+
bnez a2, 1b
58+
59+
vsetvli zero, t6, e32, m4, tu, ma
60+
vwredsumu.vs v24, v8, v24
61+
mul a7, t6, t2 // B += A(init) * len
62+
vsetvli zero, t6, e64, m8, tu, ma
63+
vmv.s.x v0, a7
64+
vredsum.vs v0, v16, v0
65+
vmv.x.s t4, v0 // B = t4
66+
vmv.x.s t2, v24 // A = t2
67+
add t3, t4, t3
68+
69+
2:
70+
li t0, 65521
71+
remu t2, t2, t0 // A = A % ADLER_MOD
72+
remu t3, t3, t0 // B = B % ADLER_MOD
73+
slli t3, t3, 16 // B << 16
74+
add a0, t2, t3 // a0 = A + B
75+
76+
ret

igzip/riscv64/igzip_multibinary_riscv64.S

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
#include "riscv64_multibinary.h"
3131

32-
mbin_interface_base isal_adler32, adler32_base
32+
mbin_interface isal_adler32
33+
3334
mbin_interface_base gen_icf_map_lh1, gen_icf_map_h1_base
3435
mbin_interface_base decode_huffman_code_block_stateless, decode_huffman_code_block_stateless_base
3536
mbin_interface_base isal_deflate_icf_finish_lvl3, isal_deflate_icf_finish_hash_map_base

igzip/riscv64/igzip_multibinary_riscv64_dispatcher.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@
3030

3131
DEFINE_INTERFACE_DISPATCHER(isal_adler32)
3232
{
33-
return PROVIDER_BASIC(adler32);
33+
const unsigned long hwcap = getauxval(AT_HWCAP);
34+
if (hwcap & HWCAP_RV('V'))
35+
return PROVIDER_INFO(adler32_rvv);
36+
else
37+
return PROVIDER_BASIC(adler32);
3438
}

0 commit comments

Comments
 (0)