Skip to content

Commit 83d58b8

Browse files
sunyuechipablodelara
authored andcommitted
multibinary: Add run-time cpu feature detect for riscv64
Signed-off-by: sunyuechi <[email protected]>
1 parent 726a6f7 commit 83d58b8

File tree

6 files changed

+252
-1
lines changed

6 files changed

+252
-1
lines changed

.clang-format-ignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
include/aarch64_multibinary.h
22
include/aarch64_label.h
33
**/aarch64/*.h
4+
5+
include/riscv64_multibinary.h
6+
**/riscv64/*.h

igzip/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
########################################################################
2929

30+
include igzip/riscv64/Makefile.am
31+
3032
lsrc += igzip/igzip.c \
3133
igzip/hufftables_c.c \
3234
igzip/igzip_base.c \
@@ -39,7 +41,7 @@ lsrc += igzip/igzip.c \
3941
lsrc_base_aliases += igzip/igzip_base_aliases.c igzip/proc_heap_base.c
4042
lsrc_x86_32 += igzip/igzip_base_aliases.c igzip/proc_heap_base.c
4143
lsrc_ppc64le += igzip/igzip_base_aliases.c igzip/proc_heap_base.c
42-
lsrc_riscv64 += igzip/igzip_base_aliases.c igzip/proc_heap_base.c
44+
lsrc_riscv64 += igzip/proc_heap_base.c
4345

4446
lsrc_aarch64 += igzip/aarch64/igzip_inflate_multibinary_arm64.S \
4547
igzip/aarch64/igzip_multibinary_arm64.S \

igzip/riscv64/Makefile.am

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
30+
lsrc_riscv64 += \
31+
igzip/riscv64/igzip_multibinary_riscv64_dispatcher.c \
32+
igzip/riscv64/igzip_multibinary_riscv64.S
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
30+
#include "riscv64_multibinary.h"
31+
32+
mbin_interface_base isal_adler32, adler32_base
33+
mbin_interface_base gen_icf_map_lh1, gen_icf_map_h1_base
34+
mbin_interface_base decode_huffman_code_block_stateless, decode_huffman_code_block_stateless_base
35+
mbin_interface_base isal_deflate_icf_finish_lvl3, isal_deflate_icf_finish_hash_map_base
36+
mbin_interface_base isal_deflate_hash_lvl3, isal_deflate_hash_base
37+
mbin_interface_base isal_deflate_hash_lvl1, isal_deflate_hash_base
38+
mbin_interface_base isal_deflate_icf_body_lvl2, isal_deflate_icf_body_hash_hist_base
39+
mbin_interface_base isal_deflate_icf_finish_lvl1, isal_deflate_icf_finish_hash_hist_base
40+
mbin_interface_base isal_deflate_finish, isal_deflate_finish_base
41+
mbin_interface_base isal_deflate_body, isal_deflate_body_base
42+
mbin_interface_base isal_deflate_hash_lvl2, isal_deflate_hash_base
43+
mbin_interface_base encode_deflate_icf, encode_deflate_icf_base
44+
mbin_interface_base set_long_icf_fg, set_long_icf_fg_base
45+
mbin_interface_base isal_deflate_icf_body_lvl3, icf_body_hash1_fillgreedy_lazy
46+
mbin_interface_base isal_deflate_icf_body_lvl1, isal_deflate_icf_body_hash_hist_base
47+
mbin_interface_base isal_deflate_hash_lvl0, isal_deflate_hash_base
48+
mbin_interface_base isal_deflate_icf_finish_lvl2, isal_deflate_icf_finish_hash_hist_base
49+
mbin_interface_base isal_update_histogram, isal_update_histogram_base
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#include "riscv64_multibinary.h"
30+
31+
DEFINE_INTERFACE_DISPATCHER(isal_adler32)
32+
{
33+
return PROVIDER_BASIC(adler32);
34+
}

include/riscv64_multibinary.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
#ifndef __RISCV_MULTIBINARY_H__
30+
#define __RISCV_MULTIBINARY_H__
31+
#ifndef __riscv
32+
#error "This file is for riscv only"
33+
#endif
34+
35+
#ifdef __ASSEMBLY__
36+
37+
/**
38+
* # mbin_interface : the wrapper layer for isal-l api
39+
*
40+
* ## references:
41+
* * aarch64_multibinary.h
42+
* ## Usage:
43+
*
44+
* 1. Define dispather function
45+
* 2. name must be \name\()_dispatcher
46+
* 3. Prototype should be *"void * \name\()_dispatcher"*
47+
* 4. The dispather should return the right function pointer , revision and a string information .
48+
**/
49+
.macro mbin_interface name:req
50+
.section .data
51+
.align 3
52+
.global \name\()_dispatcher_info
53+
.type \name\()_dispatcher_info, @object
54+
\name\()_dispatcher_info:
55+
.quad \name\()_mbinit
56+
.section .text
57+
.global \name\()_mbinit
58+
\name\()_mbinit:
59+
addi sp, sp, -32
60+
sd ra, 24(sp)
61+
sd a0, 0(sp)
62+
sd a1, 8(sp)
63+
sd a2, 16(sp)
64+
call \name\()_dispatcher
65+
mv t2, a0
66+
la t0, \name\()_dispatcher_info
67+
sd a0, 0(t0)
68+
ld ra, 24(sp)
69+
ld a0, 0(sp)
70+
ld a1, 8(sp)
71+
ld a2, 16(sp)
72+
addi sp, sp, 32
73+
jr t2
74+
.global \name\()
75+
.type \name,%function
76+
\name\():
77+
la t0, \name\()_dispatcher_info
78+
ld t1, 0(t0)
79+
jr t1
80+
.size \name,. - \name
81+
.endm
82+
83+
/**
84+
* mbin_interface_base is used for the interfaces which have only
85+
* noarch implementation
86+
*/
87+
.macro mbin_interface_base name:req, base:req
88+
.extern \base
89+
.data
90+
.align 3
91+
.global \name\()_dispatcher_info
92+
.type \name\()_dispatcher_info, @object
93+
\name\()_dispatcher_info:
94+
.dword \base
95+
.text
96+
.global \name
97+
.type \name, @function
98+
\name:
99+
la t0, \name\()_dispatcher_info
100+
ld t0, (t0)
101+
jr t0
102+
.endm
103+
#else /* __ASSEMBLY__ */
104+
#include <sys/auxv.h>
105+
#define HWCAP_RV(letter) (1ul << ((letter) - 'A'))
106+
107+
#define DEFINE_INTERFACE_DISPATCHER(name) \
108+
void * name##_dispatcher(void)
109+
110+
#define PROVIDER_BASIC(name) \
111+
PROVIDER_INFO(name##_base)
112+
113+
#define DO_DIGNOSTIC(x) _Pragma GCC diagnostic ignored "-W"#x
114+
#define DO_PRAGMA(x) _Pragma (#x)
115+
#define DIGNOSTIC_IGNORE(x) DO_PRAGMA(GCC diagnostic ignored #x)
116+
#define DIGNOSTIC_PUSH() DO_PRAGMA(GCC diagnostic push)
117+
#define DIGNOSTIC_POP() DO_PRAGMA(GCC diagnostic pop)
118+
119+
120+
#define PROVIDER_INFO(_func_entry) \
121+
({ DIGNOSTIC_PUSH() \
122+
DIGNOSTIC_IGNORE(-Wnested-externs) \
123+
extern void _func_entry(void); \
124+
DIGNOSTIC_POP() \
125+
_func_entry; \
126+
})
127+
128+
129+
130+
#endif /* __ASSEMBLY__ */
131+
#endif /* __RISCV_MULTIBINARY_H__ */

0 commit comments

Comments
 (0)