Skip to content

Commit

Permalink
RISC-V: Add stub support for existing extensions (unprivileged)
Browse files Browse the repository at this point in the history
After commit c283c47 ("RISC-V: Throw compilation error for unknown
extensions") changed how do we handle unknown extensions, we have no
guarantee that we can share the same architectural string with Binutils
(specifically, the assembler).

To avoid compilation errors on shared Assembler-C/C++ projects or programs
with inline assembler, GCC should support almost all extensions that
Binutils support, even if the GCC itself does not touch a thing.

This commit adds stub supported standard unprivileged extensions to
riscv_ext_version_table and its implications to riscv_implied_info
(all information is copied from Binutils' bfd/elfxx-riscv.c except not yet
merged 'Zce', 'Zcmp' and 'Zcmt' support).

gcc/ChangeLog:

	* common/config/riscv/riscv-common.cc
	(riscv_implied_info): Add implications from unprivileged extensions.
	(riscv_ext_version_table): Add stub support for all unprivileged
	extensions supported by Binutils as well as 'Zce', 'Zcmp', 'Zcmt'.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/predef-31.c: New test for a stub unprivileged
	extension 'Zcb' with some implications.
  • Loading branch information
a4lg committed Aug 29, 2023
1 parent fea5442 commit f30d6a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions gcc/common/config/riscv/riscv-common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ static const riscv_implied_info_t riscv_implied_info[] =
{"zcb", "zca"},
{"zcmp", "zca"},
{"zcmt", "zca"},
{"zcmt", "zicsr"},

{"smaia", "ssaia"},
{"smstateen", "ssstateen"},
Expand Down
31 changes: 31 additions & 0 deletions gcc/testsuite/gcc.target/riscv/predef-31.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64i_zcb -mabi=lp64 -mcmodel=medlow -misa-spec=20191213" } */

int main () {

#ifndef __riscv_arch_test
#error "__riscv_arch_test"
#endif

#if __riscv_xlen != 64
#error "__riscv_xlen"
#endif

#if !defined(__riscv_i) || (__riscv_i != (2 * 1000 * 1000 + 1 * 1000))
#error "__riscv_i"
#endif

#if defined(__riscv_e)
#error "__riscv_e"
#endif

#if !defined(__riscv_zca)
#error "__riscv_zca"
#endif

#if !defined(__riscv_zcb)
#error "__riscv_zcb"
#endif

return 0;
}

0 comments on commit f30d6a4

Please sign in to comment.