Skip to content

Commit 58a6a69

Browse files
stephanosionashif
authored andcommitted
arch: riscv: Add Zc* compressed instruction extension support
This commit adds the support for the following new Zc* series compressed instruction extensions: Zca - Subset of the C extension without FP loads and stores Zcb - "Simple" instructions Zcd - Double-precision floating-point instructions Zcf - Single-precision floating-point instructions Zcmp - "Complex" instructions for embedded CPUs Zcmt - Table jump instructions for embedded CPUs With the introduction of the Zc* extensions, the C extension now implies the following Zc* extensions: * Zca, always * Zcf if F is specified (RV32 only) * Zcd if D is specified The Zc* extensions that are implied by the C extension are not specified in the GCC `-march` flag because they are redundant and can interfere with the resolution of the correct multi-lib for the selected architecture unless the the alternate mappings for the redundant forms are manually specified. All the implementation details in this commit are based on the Zc* v1.0.0 specification, which is the ratified version. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
1 parent ff82bb8 commit 58a6a69

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

‎arch/riscv/Kconfig.isa‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ config RISCV_ISA_EXT_Q
8989

9090
config RISCV_ISA_EXT_C
9191
bool
92+
select RISCV_ISA_EXT_ZCA
93+
select RISCV_ISA_EXT_ZCD if RISCV_ISA_EXT_D
94+
select RISCV_ISA_EXT_ZCF if RISCV_ISA_EXT_F && (RISCV_ISA_RV32I || RISCV_ISA_RV32E)
9295
help
9396
(C) - Standard Extension for Compressed Instructions
9497

@@ -127,6 +130,65 @@ config RISCV_ISA_EXT_ZALRSC
127130

128131
The Zalrsc extension enables support for LR.W/D and SC.W/D-style instructions.
129132

133+
config RISCV_ISA_EXT_ZCA
134+
bool
135+
help
136+
(Zca) - Zba Extension for Compressed Instructions
137+
138+
The Zca extension is a subset of the C extension that does not include
139+
the floating-point load and store instructions.
140+
141+
config RISCV_ISA_EXT_ZCB
142+
bool
143+
depends on RISCV_ISA_EXT_ZCA
144+
help
145+
(Zcb) - Zcb Extension for Simple Compressed Instructions
146+
147+
The Zcb extension is a set of simple code-size saving instructions
148+
which are easy to implement on all CPUs.
149+
150+
config RISCV_ISA_EXT_ZCD
151+
bool
152+
depends on RISCV_ISA_EXT_D
153+
depends on RISCV_ISA_EXT_ZCA
154+
help
155+
(Zcd) - Zcd Extension for Double-Precision FP Compressed Instructions
156+
157+
The Zcd extension consists of compressed double-precision
158+
floating-point load and store instructions.
159+
160+
config RISCV_ISA_EXT_ZCF
161+
bool
162+
depends on RISCV_ISA_RV32I || RISCV_ISA_RV32E
163+
depends on RISCV_ISA_EXT_F
164+
depends on RISCV_ISA_EXT_ZCA
165+
help
166+
(Zcf) - Zcf Extension for Single-Precision FP Compressed Instructions
167+
168+
The Zcf extension consists of compressed single-precision
169+
floating-point load and store instructions.
170+
171+
config RISCV_ISA_EXT_ZCMP
172+
bool
173+
depends on RISCV_ISA_EXT_ZCA
174+
depends on !RISCV_ISA_EXT_ZCD
175+
help
176+
(Zcmp) - Zcmp Extension for Complex Compressed Instructions
177+
178+
The Zcmp extension consists of complex operations intended for
179+
embedded CPUs.
180+
181+
config RISCV_ISA_EXT_ZCMT
182+
bool
183+
depends on RISCV_ISA_EXT_ZICSR
184+
depends on RISCV_ISA_EXT_ZCA
185+
depends on !RISCV_ISA_EXT_ZCD
186+
help
187+
(Zcmt) - Zcmt Extension for Compressed Table Jump Instructions
188+
189+
The Zcmt extension consists of compressed table jump instructions for
190+
embedded CPUs.
191+
130192
config RISCV_ISA_EXT_ZBA
131193
bool
132194
help

‎cmake/compiler/gcc/target_riscv.cmake‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,36 @@ if(NOT CONFIG_RISCV_ISA_EXT_A)
6666
endif()
6767
endif()
6868

69+
# Zca is implied by C
70+
if(CONFIG_RISCV_ISA_EXT_ZCA AND
71+
NOT CONFIG_RISCV_ISA_EXT_C)
72+
string(CONCAT riscv_march ${riscv_march} "_zca")
73+
endif()
74+
75+
if(CONFIG_RISCV_ISA_EXT_ZCB)
76+
string(CONCAT riscv_march ${riscv_march} "_zcb")
77+
endif()
78+
79+
# Zcd is implied by C+D
80+
if(CONFIG_RISCV_ISA_EXT_ZCD AND
81+
NOT (CONFIG_RISCV_ISA_EXT_C AND CONFIG_RISCV_ISA_EXT_D))
82+
string(CONCAT riscv_march ${riscv_march} "_zcd")
83+
endif()
84+
85+
# Zcf is implied by C+F
86+
if(CONFIG_RISCV_ISA_EXT_ZCF AND
87+
NOT (CONFIG_RISCV_ISA_EXT_C AND CONFIG_RISCV_ISA_EXT_F))
88+
string(CONCAT riscv_march ${riscv_march} "_zcf")
89+
endif()
90+
91+
if(CONFIG_RISCV_ISA_EXT_ZCMP)
92+
string(CONCAT riscv_march ${riscv_march} "_zcmp")
93+
endif()
94+
95+
if(CONFIG_RISCV_ISA_EXT_ZCMT)
96+
string(CONCAT riscv_march ${riscv_march} "_zcmt")
97+
endif()
98+
6999
if(CONFIG_RISCV_ISA_EXT_ZBA)
70100
string(CONCAT riscv_march ${riscv_march} "_zba")
71101
endif()

0 commit comments

Comments
 (0)