Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 5c98efb

Browse files
a4lgouuleilei-bot
authored andcommitted
RISC-V: Initial RV64E and LP64E support
Along with RV32E, RV64E is ratified. Though ILP32E and LP64E ABIs are still draft, it's worth supporting it. This commit should not be merged until two proposals below are going to proceed. LP64E proposal (including suggested changes): <riscv-non-isa/riscv-elf-psabi-doc#299> New "__riscv_64e" proposal by the author of this commit: <riscv-non-isa/riscv-c-api-doc#52> gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_subset_list::parse_std_ext): Allow RV64E. * config.gcc: Parse base ISA RV64E and ABI LP64E. * config/riscv/arch-canonicalize: Parse base ISA 'rv64e'. * config/riscv/riscv-c.cc (riscv_cpu_cpp_builtins): Build different macro per RV32E/RV64E. Add handling for ABI_LP64E. * config/riscv/riscv-d.cc (riscv_d_handle_target_float_abi): Add handling for ABI_LP64E. * config/riscv/riscv-opts.h (enum riscv_abi_type): Add ABI_LP64E. * config/riscv/riscv.cc (riscv_option_override): Enhance error handling to support RV64E and LP64E. (riscv_conditional_register_usage): Change "RV32E" in a comment to "RV32E/RV64E". * config/riscv/riscv.h (UNITS_PER_FP_ARG): Add handling for ABI_LP64E. (STACK_BOUNDARY): Ditto. (ABI_STACK_BOUNDARY): Ditto. (MAX_ARGS_IN_REGISTERS): Ditto. (ABI_SPEC): Add support for "lp64e". * config/riscv/riscv.opt: Parse -mabi=lp64e as ABI_LP64E. * doc/invoke.texi: Add documentation of the LP64E ABI. gcc/testsuite/ChangeLog: * gcc.target/riscv/predef-1.c: Test for __riscv_64e. * gcc.target/riscv/predef-2.c: Ditto. * gcc.target/riscv/predef-3.c: Ditto. * gcc.target/riscv/predef-4.c: Ditto. * gcc.target/riscv/predef-5.c: Ditto. * gcc.target/riscv/predef-6.c: Ditto. * gcc.target/riscv/predef-7.c: Ditto. * gcc.target/riscv/predef-8.c: Ditto. * gcc.target/riscv/predef-9.c: New test for RV32E and LP64E, based on predef-7.c.
1 parent c2d62cd commit 5c98efb

File tree

19 files changed

+134
-21
lines changed

19 files changed

+134
-21
lines changed

gcc/common/config/riscv/riscv-common.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ riscv_subset_list::parse_std_ext (const char *p)
818818

819819
add ("e", major_version, minor_version, explicit_version_p, false);
820820

821-
if (m_xlen > 32)
821+
if (m_xlen > 64)
822822
{
823823
error_at (m_loc, "%<-march=%s%>: rv%de is not a valid base ISA",
824824
m_arch, m_xlen);

gcc/config.gcc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4608,7 +4608,7 @@ case "${target}" in
46084608

46094609
# Infer arch from --with-arch, --target, and --with-abi.
46104610
case "${with_arch}" in
4611-
rv32e* | rv32i* | rv32g* | rv64i* | rv64g*)
4611+
rv32e* | rv32i* | rv32g* | rv64e* | rv64i* | rv64g*)
46124612
# OK.
46134613
;;
46144614
"")
@@ -4617,11 +4617,12 @@ case "${target}" in
46174617
ilp32e) with_arch="rv32e" ;;
46184618
ilp32 | ilp32f | ilp32d) with_arch="rv32gc" ;;
46194619
lp64 | lp64f | lp64d) with_arch="rv64gc" ;;
4620+
lp64e) with_arch="rv64e" ;;
46204621
*) with_arch="rv${xlen}gc" ;;
46214622
esac
46224623
;;
46234624
*)
4624-
echo "--with-arch=${with_arch} is not supported. The argument must begin with rv32e, rv32i, rv32g, rv64i, or rv64g." 1>&2
4625+
echo "--with-arch=${with_arch} is not supported. The argument must begin with rv32e, rv32i, rv32g, rv64e, rv64i, or rv64g." 1>&2
46254626
exit 1
46264627
;;
46274628
esac
@@ -4635,14 +4636,15 @@ case "${target}" in
46354636
# pick a default based on the ISA, preferring soft-float
46364637
# unless the D extension is present.
46374638
case "${with_abi}" in
4638-
ilp32 | ilp32e | ilp32f | ilp32d | lp64 | lp64f | lp64d)
4639+
ilp32 | ilp32e | ilp32f | ilp32d | lp64 | lp64e | lp64f | lp64d)
46394640
;;
46404641
"")
46414642
case "${with_arch}" in
46424643
rv32*d* | rv32g*) with_abi=ilp32d ;;
46434644
rv32e*) with_abi=ilp32e ;;
46444645
rv32*) with_abi=ilp32 ;;
46454646
rv64*d* | rv64g*) with_abi=lp64d ;;
4647+
rv64e*) with_abi=lp64e ;;
46464648
rv64*) with_abi=lp64 ;;
46474649
esac
46484650
;;
@@ -4658,7 +4660,7 @@ case "${target}" in
46584660
ilp32,rv32* | ilp32e,rv32e* \
46594661
| ilp32f,rv32*f* | ilp32f,rv32g* \
46604662
| ilp32d,rv32*d* | ilp32d,rv32g* \
4661-
| lp64,rv64* \
4663+
| lp64,rv64* | lp64e,rv64e* \
46624664
| lp64f,rv64*f* | lp64f,rv64g* \
46634665
| lp64d,rv64*d* | lp64d,rv64g*)
46644666
;;

gcc/config/riscv/arch-canonicalize

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def arch_canonicalize(arch, isa_spec):
7676
new_arch = ""
7777
extra_long_ext = []
7878
std_exts = []
79-
if arch[:5] in ['rv32e', 'rv32i', 'rv32g', 'rv64i', 'rv64g']:
79+
if arch[:5] in ['rv32e', 'rv32i', 'rv32g', 'rv64e', 'rv64i', 'rv64g']:
8080
new_arch = arch[:5].replace("g", "i")
8181
if arch[:5] in ['rv32g', 'rv64g']:
8282
std_exts = ['m', 'a', 'f', 'd']

gcc/config/riscv/riscv-c.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile)
5151
builtin_define ("__riscv_compressed");
5252

5353
if (TARGET_RVE)
54-
builtin_define ("__riscv_32e");
54+
builtin_define (TARGET_64BIT ? "__riscv_64e" : "__riscv_32e");
5555

5656
if (TARGET_ATOMIC)
5757
builtin_define ("__riscv_atomic");
@@ -76,6 +76,7 @@ riscv_cpu_cpp_builtins (cpp_reader *pfile)
7676
switch (riscv_abi)
7777
{
7878
case ABI_ILP32E:
79+
case ABI_LP64E:
7980
builtin_define ("__riscv_abi_rve");
8081
gcc_fallthrough ();
8182

gcc/config/riscv/riscv-d.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ riscv_d_handle_target_float_abi (void)
5252
{
5353
case ABI_ILP32E:
5454
case ABI_ILP32:
55+
case ABI_LP64E:
5556
case ABI_LP64:
5657
abi = "soft";
5758
break;

gcc/config/riscv/riscv-opts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum riscv_abi_type {
2727
ABI_ILP32F,
2828
ABI_ILP32D,
2929
ABI_LP64,
30+
ABI_LP64E,
3031
ABI_LP64F,
3132
ABI_LP64D
3233
};

gcc/config/riscv/riscv.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6460,13 +6460,18 @@ riscv_option_override (void)
64606460
error ("requested ABI requires %<-march%> to subsume the %qc extension",
64616461
UNITS_PER_FP_ARG > 8 ? 'Q' : (UNITS_PER_FP_ARG > 4 ? 'D' : 'F'));
64626462

6463-
if (TARGET_RVE && riscv_abi != ABI_ILP32E)
6464-
error ("rv32e requires ilp32e ABI");
6463+
/* RVE requires specific ABI. */
6464+
if (TARGET_RVE)
6465+
if (!TARGET_64BIT && riscv_abi != ABI_ILP32E)
6466+
error ("rv32e requires ilp32e ABI");
6467+
else if (TARGET_64BIT && riscv_abi != ABI_LP64E)
6468+
error ("rv64e requires lp64e ABI");
64656469

6466-
// Zfinx require abi ilp32,ilp32e or lp64.
6467-
if (TARGET_ZFINX && riscv_abi != ABI_ILP32
6468-
&& riscv_abi != ABI_LP64 && riscv_abi != ABI_ILP32E)
6469-
error ("z*inx requires ABI ilp32, ilp32e or lp64");
6470+
/* Zfinx require abi ilp32, ilp32e, lp64 or lp64e. */
6471+
if (TARGET_ZFINX
6472+
&& riscv_abi != ABI_ILP32 && riscv_abi != ABI_LP64
6473+
&& riscv_abi != ABI_ILP32E && riscv_abi != ABI_LP64E)
6474+
error ("z*inx requires ABI ilp32, ilp32e, lp64 or lp64e");
64706475

64716476
/* We do not yet support ILP32 on RV64. */
64726477
if (BITS_PER_WORD != POINTER_SIZE)
@@ -6553,7 +6558,7 @@ riscv_option_override (void)
65536558
static void
65546559
riscv_conditional_register_usage (void)
65556560
{
6556-
/* We have only x0~x15 on RV32E. */
6561+
/* We have only x0~x15 on RV32E/RV64E. */
65576562
if (TARGET_RVE)
65586563
{
65596564
for (int r = 16; r <= 31; r++)

gcc/config/riscv/riscv.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ ASM_MISA_SPEC
164164
/* The largest type that can be passed in floating-point registers. */
165165
#define UNITS_PER_FP_ARG \
166166
((riscv_abi == ABI_ILP32 || riscv_abi == ABI_ILP32E \
167-
|| riscv_abi == ABI_LP64) \
167+
|| riscv_abi == ABI_LP64 || riscv_abi == ABI_LP64E) \
168168
? 0 \
169169
: ((riscv_abi == ABI_ILP32F || riscv_abi == ABI_LP64F) ? 4 : 8))
170170

@@ -187,10 +187,15 @@ ASM_MISA_SPEC
187187

188188
/* The smallest supported stack boundary the calling convention supports. */
189189
#define STACK_BOUNDARY \
190-
(riscv_abi == ABI_ILP32E ? BITS_PER_WORD : 2 * BITS_PER_WORD)
190+
(riscv_abi == ABI_ILP32E || riscv_abi == ABI_LP64E \
191+
? BITS_PER_WORD \
192+
: 2 * BITS_PER_WORD)
191193

192194
/* The ABI stack alignment. */
193-
#define ABI_STACK_BOUNDARY (riscv_abi == ABI_ILP32E ? BITS_PER_WORD : 128)
195+
#define ABI_STACK_BOUNDARY \
196+
(riscv_abi == ABI_ILP32E || riscv_abi == ABI_LP64E \
197+
? BITS_PER_WORD \
198+
: 128)
194199

195200
/* There is no point aligning anything to a rounder boundary than this. */
196201
#define BIGGEST_ALIGNMENT 128
@@ -634,7 +639,10 @@ enum reg_class
634639
#define GP_RETURN GP_ARG_FIRST
635640
#define FP_RETURN (UNITS_PER_FP_ARG == 0 ? GP_RETURN : FP_ARG_FIRST)
636641

637-
#define MAX_ARGS_IN_REGISTERS (riscv_abi == ABI_ILP32E ? 6 : 8)
642+
#define MAX_ARGS_IN_REGISTERS \
643+
(riscv_abi == ABI_ILP32E || riscv_abi == ABI_LP64E \
644+
? 6 \
645+
: 8)
638646

639647
/* Symbolic macros for the first/last argument registers. */
640648

@@ -1044,6 +1052,7 @@ extern poly_int64 riscv_v_adjust_bytesize (enum machine_mode, int);
10441052
"%{mabi=ilp32f:ilp32f}" \
10451053
"%{mabi=ilp32d:ilp32d}" \
10461054
"%{mabi=lp64:lp64}" \
1055+
"%{mabi=lp64e:lp64e}" \
10471056
"%{mabi=lp64f:lp64f}" \
10481057
"%{mabi=lp64d:lp64d}" \
10491058

gcc/config/riscv/riscv.opt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Enum(abi_type) String(ilp32d) Value(ABI_ILP32D)
6464
EnumValue
6565
Enum(abi_type) String(lp64) Value(ABI_LP64)
6666

67+
EnumValue
68+
Enum(abi_type) String(lp64e) Value(ABI_LP64E)
69+
6770
EnumValue
6871
Enum(abi_type) String(lp64f) Value(ABI_LP64F)
6972

gcc/doc/invoke.texi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28936,9 +28936,10 @@ conventions are: @samp{ilp32}, @samp{ilp32f}, @samp{ilp32d}, @samp{lp64},
2893628936
@samp{lp64f}, and @samp{lp64d}. Some calling conventions are impossible to
2893728937
implement on some ISAs: for example, @samp{-march=rv32if -mabi=ilp32d} is
2893828938
invalid because the ABI requires 64-bit values be passed in F registers, but F
28939-
registers are only 32 bits wide. There is also the @samp{ilp32e} ABI that can
28940-
only be used with the @samp{rv32e} architecture. This ABI is not well
28941-
specified at present, and is subject to change.
28939+
registers are only 32 bits wide. There are also the @samp{ilp32e} ABI that can
28940+
only be used with the @samp{rv32e} architecture and @samp{lp64e} ABI that can
28941+
only be used with the @samp{rv64e}. Those ABI are not well specified at
28942+
present, and is subject to change.
2894228943

2894328944
@opindex mfdiv
2894428945
@item -mfdiv

0 commit comments

Comments
 (0)