Skip to content

arch: riscv: Add Zc* compressed instruction extension support #92276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions arch/riscv/Kconfig.isa
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ config RISCV_ISA_EXT_Q

config RISCV_ISA_EXT_C
bool
select RISCV_ISA_EXT_ZCA
select RISCV_ISA_EXT_ZCD if RISCV_ISA_EXT_D
select RISCV_ISA_EXT_ZCF if RISCV_ISA_EXT_F && (RISCV_ISA_RV32I || RISCV_ISA_RV32E)
help
(C) - Standard Extension for Compressed Instructions

Expand Down Expand Up @@ -127,6 +130,65 @@ config RISCV_ISA_EXT_ZALRSC

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

config RISCV_ISA_EXT_ZCA
bool
help
(Zca) - Zba Extension for Compressed Instructions

The Zca extension is a subset of the C extension that does not include
the floating-point load and store instructions.

config RISCV_ISA_EXT_ZCB
bool
depends on RISCV_ISA_EXT_ZCA
help
(Zcb) - Zcb Extension for Simple Compressed Instructions

The Zcb extension is a set of simple code-size saving instructions
which are easy to implement on all CPUs.

config RISCV_ISA_EXT_ZCD
bool
depends on RISCV_ISA_EXT_D
depends on RISCV_ISA_EXT_ZCA
help
(Zcd) - Zcd Extension for Double-Precision FP Compressed Instructions

The Zcd extension consists of compressed double-precision
floating-point load and store instructions.

config RISCV_ISA_EXT_ZCF
bool
depends on RISCV_ISA_RV32I || RISCV_ISA_RV32E
depends on RISCV_ISA_EXT_F
depends on RISCV_ISA_EXT_ZCA
help
(Zcf) - Zcf Extension for Single-Precision FP Compressed Instructions

The Zcf extension consists of compressed single-precision
floating-point load and store instructions.

config RISCV_ISA_EXT_ZCMP
bool
depends on RISCV_ISA_EXT_ZCA
depends on !RISCV_ISA_EXT_ZCD
help
(Zcmp) - Zcmp Extension for Complex Compressed Instructions

The Zcmp extension consists of complex operations intended for
embedded CPUs.

config RISCV_ISA_EXT_ZCMT
bool
depends on RISCV_ISA_EXT_ZICSR
depends on RISCV_ISA_EXT_ZCA
depends on !RISCV_ISA_EXT_ZCD
help
(Zcmt) - Zcmt Extension for Compressed Table Jump Instructions

The Zcmt extension consists of compressed table jump instructions for
embedded CPUs.

config RISCV_ISA_EXT_ZBA
bool
help
Expand Down
30 changes: 30 additions & 0 deletions cmake/compiler/gcc/target_riscv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ if(NOT CONFIG_RISCV_ISA_EXT_A)
endif()
endif()

# Zca is implied by C
if(CONFIG_RISCV_ISA_EXT_ZCA AND
NOT CONFIG_RISCV_ISA_EXT_C)
string(CONCAT riscv_march ${riscv_march} "_zca")
endif()

if(CONFIG_RISCV_ISA_EXT_ZCB)
string(CONCAT riscv_march ${riscv_march} "_zcb")
endif()

# Zcd is implied by C+D
if(CONFIG_RISCV_ISA_EXT_ZCD AND
NOT (CONFIG_RISCV_ISA_EXT_C AND CONFIG_RISCV_ISA_EXT_D))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking EXT_D is redundant since zcd depends on EXT_D in Kconfig?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes; but, we have nothing to lose by being verbose here.

string(CONCAT riscv_march ${riscv_march} "_zcd")
endif()

# Zcf is implied by C+F
if(CONFIG_RISCV_ISA_EXT_ZCF AND
NOT (CONFIG_RISCV_ISA_EXT_C AND CONFIG_RISCV_ISA_EXT_F))
string(CONCAT riscv_march ${riscv_march} "_zcf")
endif()

if(CONFIG_RISCV_ISA_EXT_ZCMP)
string(CONCAT riscv_march ${riscv_march} "_zcmp")
endif()

if(CONFIG_RISCV_ISA_EXT_ZCMT)
string(CONCAT riscv_march ${riscv_march} "_zcmt")
endif()

if(CONFIG_RISCV_ISA_EXT_ZBA)
string(CONCAT riscv_march ${riscv_march} "_zba")
endif()
Expand Down