* [PATCH v4 1/7] RISC-V: Support -mlittle-endian and -mbig-endian
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
@ 2021-03-19 19:49 ` Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 2/7] RISC-V: Add riscv{32,64}be with big endian as default Marcus Comstedt
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marcus Comstedt @ 2021-03-19 19:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Marcus Comstedt
gcc/
* config/riscv/elf.h (LINK_SPEC): Pass linker endianness flag.
* config/riscv/freebsd.h (LINK_SPEC): Likewise.
* config/riscv/linux.h (LINK_SPEC): Likewise.
* config/riscv/riscv.h (ASM_SPEC): Pass -mbig-endian and
-mlittle-endian.
(BYTES_BIG_ENDIAN): Handle big endian.
(WORDS_BIG_ENDIAN): Define to BYTES_BIG_ENDIAN.
* config/riscv/riscv.opt (-mbig-endian, -mlittle-endian): New
options.
* doc/invoke.texi (-mbig-endian, -mlittle-endian): Document.
---
gcc/config/riscv/elf.h | 2 ++
gcc/config/riscv/freebsd.h | 2 ++
gcc/config/riscv/linux.h | 2 ++
gcc/config/riscv/riscv.h | 6 ++++--
gcc/config/riscv/riscv.opt | 8 ++++++++
gcc/doc/invoke.texi | 12 ++++++++++++
6 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h
index d136d46e4fa..973efdaed7b 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see
#define LINK_SPEC "\
-melf" XLEN_SPEC "lriscv \
%{mno-relax:--no-relax} \
+%{mbig-endian:-EB} \
+%{mlittle-endian:-EL} \
%{shared}"
/* Link against Newlib libraries, because the ELF backend assumes Newlib.
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
index a48bf9bffe4..f3aca9f7673 100644
--- a/gcc/config/riscv/freebsd.h
+++ b/gcc/config/riscv/freebsd.h
@@ -44,6 +44,8 @@ along with GCC; see the file COPYING3. If not see
%{p:%nconsider using `-pg' instead of `-p' with gprof (1)} \
%{v:-V} \
%{assert*} %{R*} %{rpath*} %{defsym*} \
+ %{mbig-endian:-EB} \
+ %{mlittle-endian:-EL} \
%{shared:-Bshareable %{h*} %{soname*}} \
%{symbolic:-Bsymbolic} \
%{static:-Bstatic} \
diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index 9238de5bc92..e74f5d3f914 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -60,6 +60,8 @@ along with GCC; see the file COPYING3. If not see
#define LINK_SPEC "\
-melf" XLEN_SPEC "lriscv" LD_EMUL_SUFFIX " \
%{mno-relax:--no-relax} \
+%{mbig-endian:-EB} \
+%{mlittle-endian:-EL} \
%{shared} \
%{!shared: \
%{!static: \
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index c6f8bee07ef..0b667d2e8b9 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -91,6 +91,8 @@ extern const char *riscv_default_mtune (int argc, const char **argv);
%{" FPIE_OR_FPIC_SPEC ":-fpic} \
%{march=*} \
%{mabi=*} \
+%{mbig-endian} \
+%{mlittle-endian} \
%(subtarget_asm_spec)" \
ASM_MISA_SPEC
@@ -126,8 +128,8 @@ ASM_MISA_SPEC
/* Target machine storage layout */
#define BITS_BIG_ENDIAN 0
-#define BYTES_BIG_ENDIAN 0
-#define WORDS_BIG_ENDIAN 0
+#define BYTES_BIG_ENDIAN (TARGET_BIG_ENDIAN != 0)
+#define WORDS_BIG_ENDIAN (BYTES_BIG_ENDIAN)
#define MAX_BITS_PER_WORD 64
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 761a09d18c3..e294e223151 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -21,6 +21,14 @@
HeaderInclude
config/riscv/riscv-opts.h
+mbig-endian
+Target RejectNegative Mask(BIG_ENDIAN)
+Assume target CPU is configured as big endian.
+
+mlittle-endian
+Target RejectNegative InverseMask(BIG_ENDIAN)
+Assume target CPU is configured as little endian.
+
mbranch-cost=
Target RejectNegative Joined UInteger Var(riscv_branch_cost)
-mbranch-cost=N Set the cost of branches to roughly N instructions.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index e8baa545eee..9279a37a832 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1169,6 +1169,7 @@ See RS/6000 and PowerPC Options.
-mrelax -mno-relax @gol
-mriscv-attribute -mmo-riscv-attribute @gol
-malign-data=@var{type} @gol
+-mbig-endian -mlittle-endian @gol
+-mstack-protector-guard=@var{guard} -mstack-protector-guard-reg=@var{reg} @gol
+-mstack-protector-guard-offset=@var{offset}}
@@ -26721,6 +26722,17 @@ types. Supported values for @var{type} are @samp{xlen} which uses x register
width as the alignment value, and @samp{natural} which uses natural alignment.
@samp{xlen} is the default.
+@item -mbig-endian
+@opindex mbig-endian
+Generate big-endian code. This is the default when GCC is configured for a
+@samp{riscv64be-*-*} or @samp{riscv32be-*-*} target.
+
+@item -mlittle-endian
+@opindex mlittle-endian
+Generate little-endian code. This is the default when GCC is configured for a
+@samp{riscv64-*-*} or @samp{riscv32-*-*} but not a @samp{riscv64be-*-*} or
+@samp{riscv32be-*-*} target.
+
@item -mstack-protector-guard=@var{guard}
@itemx -mstack-protector-guard-reg=@var{reg}
@itemx -mstack-protector-guard-offset=@var{offset}
--
2.26.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 2/7] RISC-V: Add riscv{32,64}be with big endian as default
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 1/7] RISC-V: Support -mlittle-endian and -mbig-endian Marcus Comstedt
@ 2021-03-19 19:49 ` Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 3/7] RISC-V: Update soft-fp config for big-endian Marcus Comstedt
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marcus Comstedt @ 2021-03-19 19:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Marcus Comstedt
gcc/
* common/config/riscv/riscv-common.c
(TARGET_DEFAULT_TARGET_FLAGS): Set default endianness.
* config.gcc (riscv32be-*, riscv64be-*): Set
TARGET_BIG_ENDIAN_DEFAULT to 1.
* config/riscv/elf.h (LINK_SPEC): Change -melf* value
depending on default endianness.
* config/riscv/freebsd.h (LINK_SPEC): Likewise.
* config/riscv/linux.h (LINK_SPEC): Likewise.
* config/riscv/riscv.c (TARGET_DEFAULT_TARGET_FLAGS): Set
default endianness.
* config/riscv/riscv.h (DEFAULT_ENDIAN_SPEC): New macro.
---
gcc/common/config/riscv/riscv-common.c | 5 +++++
gcc/config.gcc | 15 +++++++++++++++
gcc/config/riscv/elf.h | 2 +-
gcc/config/riscv/freebsd.h | 2 +-
gcc/config/riscv/linux.h | 2 +-
gcc/config/riscv/riscv.c | 5 +++++
gcc/config/riscv/riscv.h | 6 ++++++
7 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index 6bbe25dba89..34b74e52a2d 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -32,6 +32,11 @@ along with GCC; see the file COPYING3. If not see
#include "config/riscv/riscv-protos.h"
#include "config/riscv/riscv-subset.h"
+#ifdef TARGET_BIG_ENDIAN_DEFAULT
+#undef TARGET_DEFAULT_TARGET_FLAGS
+#define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_ENDIAN)
+#endif
+
/* Type for implied ISA info. */
struct riscv_implied_info_t
{
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 17fea83b2e4..ae47e430062 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2464,6 +2464,11 @@ riscv*-*-linux*)
tmake_file="${tmake_file} riscv/t-riscv riscv/t-linux"
gnu_ld=yes
gas=yes
+ case $target in
+ riscv32be-*|riscv64be-*)
+ tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
+ ;;
+ esac
# Force .init_array support. The configure script cannot always
# automatically detect that GAS supports it, yet we require it.
gcc_cv_initfini_array=yes
@@ -2487,6 +2492,11 @@ riscv*-*-elf* | riscv*-*-rtems*)
tmake_file="${tmake_file} riscv/t-riscv"
gnu_ld=yes
gas=yes
+ case $target in
+ riscv32be-*|riscv64be-*)
+ tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
+ ;;
+ esac
# Force .init_array support. The configure script cannot always
# automatically detect that GAS supports it, yet we require it.
gcc_cv_initfini_array=yes
@@ -2496,6 +2506,11 @@ riscv*-*-freebsd*)
tmake_file="${tmake_file} riscv/t-riscv"
gnu_ld=yes
gas=yes
+ case $target in
+ riscv32be-*|riscv64be-*)
+ tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
+ ;;
+ esac
# Force .init_array support. The configure script cannot always
# automatically detect that GAS supports it, yet we require it.
gcc_cv_initfini_array=yes
diff --git a/gcc/config/riscv/elf.h b/gcc/config/riscv/elf.h
index 973efdaed7b..7e65e499031 100644
--- a/gcc/config/riscv/elf.h
+++ b/gcc/config/riscv/elf.h
@@ -18,7 +18,7 @@ along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#define LINK_SPEC "\
--melf" XLEN_SPEC "lriscv \
+-melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv \
%{mno-relax:--no-relax} \
%{mbig-endian:-EB} \
%{mlittle-endian:-EL} \
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
index f3aca9f7673..6018e7bb764 100644
--- a/gcc/config/riscv/freebsd.h
+++ b/gcc/config/riscv/freebsd.h
@@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see
#undef LINK_SPEC
#define LINK_SPEC " \
- -melf" XLEN_SPEC "lriscv \
+ -melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv \
%{p:%nconsider using `-pg' instead of `-p' with gprof (1)} \
%{v:-V} \
%{assert*} %{R*} %{rpath*} %{defsym*} \
diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index e74f5d3f914..fce5b896e6e 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -58,7 +58,7 @@ along with GCC; see the file COPYING3. If not see
"%{mabi=ilp32:_ilp32}"
#define LINK_SPEC "\
--melf" XLEN_SPEC "lriscv" LD_EMUL_SUFFIX " \
+-melf" XLEN_SPEC DEFAULT_ENDIAN_SPEC "riscv" LD_EMUL_SUFFIX " \
%{mno-relax:--no-relax} \
%{mbig-endian:-EB} \
%{mlittle-endian:-EL} \
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index fffd0814eee..eab14602355 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -5524,6 +5524,11 @@ riscv_asan_shadow_offset (void)
#undef TARGET_ASAN_SHADOW_OFFSET
#define TARGET_ASAN_SHADOW_OFFSET riscv_asan_shadow_offset
+#ifdef TARGET_BIG_ENDIAN_DEFAULT
+#undef TARGET_DEFAULT_TARGET_FLAGS
+#define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_ENDIAN)
+#endif
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-riscv.h"
diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
index 0b667d2e8b9..3cc3e864a3e 100644
--- a/gcc/config/riscv/riscv.h
+++ b/gcc/config/riscv/riscv.h
@@ -30,6 +30,12 @@ along with GCC; see the file COPYING3. If not see
/* Target CPU versions for D. */
#define TARGET_D_CPU_VERSIONS riscv_d_target_versions
+#ifdef TARGET_BIG_ENDIAN_DEFAULT
+#define DEFAULT_ENDIAN_SPEC "b"
+#else
+#define DEFAULT_ENDIAN_SPEC "l"
+#endif
+
/* Default target_flags if no switches are specified */
#ifndef TARGET_DEFAULT
--
2.26.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 3/7] RISC-V: Update soft-fp config for big-endian
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 1/7] RISC-V: Support -mlittle-endian and -mbig-endian Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 2/7] RISC-V: Add riscv{32,64}be with big endian as default Marcus Comstedt
@ 2021-03-19 19:49 ` Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 4/7] RISC-V: Fix trampoline generation on big endian Marcus Comstedt
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marcus Comstedt @ 2021-03-19 19:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Marcus Comstedt
libgcc/
* config/riscv/sfp-machine.h (__BYTE_ORDER): Set according
to __BYTE_ORDER__.
---
libgcc/config/riscv/sfp-machine.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libgcc/config/riscv/sfp-machine.h b/libgcc/config/riscv/sfp-machine.h
index db2697157ce..8adbf4b8b2e 100644
--- a/libgcc/config/riscv/sfp-machine.h
+++ b/libgcc/config/riscv/sfp-machine.h
@@ -128,7 +128,11 @@ do { \
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define __BYTE_ORDER __BIG_ENDIAN
+#else
#define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
/* Define ALIASNAME as a strong alias for NAME. */
--
2.26.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 4/7] RISC-V: Fix trampoline generation on big endian
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
` (2 preceding siblings ...)
2021-03-19 19:49 ` [PATCH v4 3/7] RISC-V: Update soft-fp config for big-endian Marcus Comstedt
@ 2021-03-19 19:49 ` Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 5/7] RISC-V: Update shift-shift-5.c testcase for " Marcus Comstedt
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marcus Comstedt @ 2021-03-19 19:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Marcus Comstedt
gcc/
* config/riscv/riscv.c (riscv_swap_instruction): New function
to byteswap an SImode rtx containing an instruction.
(riscv_trampoline_init): Byteswap the generated instructions
when needed.
---
gcc/config/riscv/riscv.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index eab14602355..1cd795bd19c 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -1073,6 +1073,15 @@ riscv_force_binary (machine_mode mode, enum rtx_code code, rtx x, rtx y)
return riscv_emit_binary (code, gen_reg_rtx (mode), x, y);
}
+static rtx
+riscv_swap_instruction (rtx inst)
+{
+ gcc_assert (GET_MODE (inst) == SImode);
+ if (BYTES_BIG_ENDIAN)
+ inst = expand_unop (SImode, bswap_optab, inst, gen_reg_rtx (SImode), 1);
+ return inst;
+}
+
/* Copy VALUE to a register and return that register. If new pseudos
are allowed, copy it into a new register, otherwise use DEST. */
@@ -4953,7 +4962,7 @@ riscv_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
gen_int_mode (lui_hi_chain_code, SImode));
mem = adjust_address (m_tramp, SImode, 0);
- riscv_emit_move (mem, lui_hi_chain);
+ riscv_emit_move (mem, riscv_swap_instruction (lui_hi_chain));
/* Gen lui t0, hi(func). */
rtx hi_func = riscv_force_binary (SImode, PLUS, target_function,
@@ -4965,7 +4974,7 @@ riscv_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
gen_int_mode (lui_hi_func_code, SImode));
mem = adjust_address (m_tramp, SImode, 1 * GET_MODE_SIZE (SImode));
- riscv_emit_move (mem, lui_hi_func);
+ riscv_emit_move (mem, riscv_swap_instruction (lui_hi_func));
/* Gen addi t2, t2, lo(chain). */
rtx lo_chain = riscv_force_binary (SImode, AND, chain_value,
@@ -4980,7 +4989,7 @@ riscv_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
force_reg (SImode, GEN_INT (lo_chain_code)));
mem = adjust_address (m_tramp, SImode, 2 * GET_MODE_SIZE (SImode));
- riscv_emit_move (mem, addi_lo_chain);
+ riscv_emit_move (mem, riscv_swap_instruction (addi_lo_chain));
/* Gen jr t0, lo(func). */
rtx lo_func = riscv_force_binary (SImode, AND, target_function,
@@ -4993,7 +5002,7 @@ riscv_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
force_reg (SImode, GEN_INT (lo_func_code)));
mem = adjust_address (m_tramp, SImode, 3 * GET_MODE_SIZE (SImode));
- riscv_emit_move (mem, jr_lo_func);
+ riscv_emit_move (mem, riscv_swap_instruction (jr_lo_func));
}
else
{
@@ -5019,6 +5028,8 @@ riscv_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
/* Copy the trampoline code. */
for (i = 0; i < ARRAY_SIZE (trampoline); i++)
{
+ if (BYTES_BIG_ENDIAN)
+ trampoline[i] = __builtin_bswap32(trampoline[i]);
mem = adjust_address (m_tramp, SImode, i * GET_MODE_SIZE (SImode));
riscv_emit_move (mem, gen_int_mode (trampoline[i], SImode));
}
--
2.26.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 5/7] RISC-V: Update shift-shift-5.c testcase for big endian
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
` (3 preceding siblings ...)
2021-03-19 19:49 ` [PATCH v4 4/7] RISC-V: Fix trampoline generation on big endian Marcus Comstedt
@ 2021-03-19 19:49 ` Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 6/7] RISC-V: Fix matches against subreg with a bytenum of 0 in riscv.md Marcus Comstedt
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Marcus Comstedt @ 2021-03-19 19:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Marcus Comstedt
gcc/
* testsuite/gcc.target/riscv/shift-shift-5.c (sub): Change
order of struct fields depending on byteorder.
---
gcc/testsuite/gcc.target/riscv/shift-shift-5.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/gcc/testsuite/gcc.target/riscv/shift-shift-5.c b/gcc/testsuite/gcc.target/riscv/shift-shift-5.c
index 5b2ae89a471..0ecab9723c9 100644
--- a/gcc/testsuite/gcc.target/riscv/shift-shift-5.c
+++ b/gcc/testsuite/gcc.target/riscv/shift-shift-5.c
@@ -7,7 +7,11 @@ unsigned long
sub (long l)
{
union u {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
struct s { int a : 19; unsigned int b : 13; int x; } s;
+#else
+ struct s { int x; unsigned int b : 13; int a : 19; } s;
+#endif
long l;
} u;
u.l = l;
--
2.26.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 6/7] RISC-V: Fix matches against subreg with a bytenum of 0 in riscv.md
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
` (4 preceding siblings ...)
2021-03-19 19:49 ` [PATCH v4 5/7] RISC-V: Update shift-shift-5.c testcase for " Marcus Comstedt
@ 2021-03-19 19:49 ` Marcus Comstedt
2021-03-19 19:49 ` [PATCH v4 7/7] RISC-V: Fix riscv_subword() for big endian Marcus Comstedt
2021-03-23 9:30 ` [PATCH v4 0/7] RISC-V big endian support Kito Cheng
7 siblings, 0 replies; 9+ messages in thread
From: Marcus Comstedt @ 2021-03-19 19:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Marcus Comstedt
These all intend the least significant subpart of the register.
Use the same endian-neutral "subreg_lowpart_operator" predicate that
ARM does instead.
gcc/
* config/riscv/predicates.md (subreg_lowpart_operator): New predicate
* config/riscv/riscv.md (*addsi3_extended2, *subsi3_extended2)
(*negsi2_extended2, *mulsi3_extended2, *<optab>si3_mask)
(*<optab>si3_mask_1, *<optab>di3_mask, *<optab>di3_mask_1)
(*<optab>si3_extend_mask, *<optab>si3_extend_mask_1): Use
new predicate "subreg_lowpart_operator"
---
gcc/config/riscv/predicates.md | 5 +++
gcc/config/riscv/riscv.md | 70 +++++++++++++++++-----------------
2 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md
index ef821add663..23211513554 100644
--- a/gcc/config/riscv/predicates.md
+++ b/gcc/config/riscv/predicates.md
@@ -198,6 +198,11 @@
(define_predicate "signed_order_operator"
(match_code "eq,ne,lt,le,ge,gt"))
+(define_predicate "subreg_lowpart_operator"
+ (ior (match_code "truncate")
+ (and (match_code "subreg")
+ (match_test "subreg_lowpart_p (op)"))))
+
(define_predicate "fp_native_comparison"
(match_code "eq,lt,le,gt,ge"))
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index fcdcc3abaa0..c3687d57047 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -480,9 +480,9 @@
(define_insn "*addsi3_extended2"
[(set (match_operand:DI 0 "register_operand" "=r,r")
(sign_extend:DI
- (subreg:SI (plus:DI (match_operand:DI 1 "register_operand" " r,r")
- (match_operand:DI 2 "arith_operand" " r,I"))
- 0)))]
+ (match_operator:SI 3 "subreg_lowpart_operator"
+ [(plus:DI (match_operand:DI 1 "register_operand" " r,r")
+ (match_operand:DI 2 "arith_operand" " r,I"))])))]
"TARGET_64BIT"
"add%i2w\t%0,%1,%2"
[(set_attr "type" "arith")
@@ -536,9 +536,9 @@
(define_insn "*subsi3_extended2"
[(set (match_operand:DI 0 "register_operand" "= r")
(sign_extend:DI
- (subreg:SI (minus:DI (match_operand:DI 1 "reg_or_0_operand" " rJ")
- (match_operand:DI 2 "register_operand" " r"))
- 0)))]
+ (match_operator:SI 3 "subreg_lowpart_operator"
+ [(minus:DI (match_operand:DI 1 "reg_or_0_operand" " rJ")
+ (match_operand:DI 2 "register_operand" " r"))])))]
"TARGET_64BIT"
"subw\t%0,%z1,%2"
[(set_attr "type" "arith")
@@ -572,8 +572,8 @@
(define_insn "*negsi2_extended2"
[(set (match_operand:DI 0 "register_operand" "=r")
(sign_extend:DI
- (subreg:SI (neg:DI (match_operand:DI 1 "register_operand" " r"))
- 0)))]
+ (match_operator:SI 2 "subreg_lowpart_operator"
+ [(neg:DI (match_operand:DI 1 "register_operand" " r"))])))]
"TARGET_64BIT"
"negw\t%0,%1"
[(set_attr "type" "arith")
@@ -627,9 +627,9 @@
(define_insn "*mulsi3_extended2"
[(set (match_operand:DI 0 "register_operand" "=r")
(sign_extend:DI
- (subreg:SI (mult:DI (match_operand:DI 1 "register_operand" " r")
- (match_operand:DI 2 "register_operand" " r"))
- 0)))]
+ (match_operator:SI 3 "subreg_lowpart_operator"
+ [(mult:DI (match_operand:DI 1 "register_operand" " r")
+ (match_operand:DI 2 "register_operand" " r"))])))]
"TARGET_MUL && TARGET_64BIT"
"mulw\t%0,%1,%2"
[(set_attr "type" "imul")
@@ -1591,10 +1591,10 @@
[(set (match_operand:SI 0 "register_operand" "= r")
(any_shift:SI
(match_operand:SI 1 "register_operand" " r")
- (subreg:QI
- (and:SI
- (match_operand:SI 2 "register_operand" "r")
- (match_operand 3 "const_int_operand")) 0)))]
+ (match_operator 4 "subreg_lowpart_operator"
+ [(and:SI
+ (match_operand:SI 2 "register_operand" "r")
+ (match_operand 3 "const_int_operand"))])))]
"(INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1))
== GET_MODE_BITSIZE (SImode)-1"
"#"
@@ -1610,10 +1610,10 @@
[(set (match_operand:SI 0 "register_operand" "= r")
(any_shift:SI
(match_operand:SI 1 "register_operand" " r")
- (subreg:QI
- (and:DI
- (match_operand:DI 2 "register_operand" "r")
- (match_operand 3 "const_int_operand")) 0)))]
+ (match_operator 4 "subreg_lowpart_operator"
+ [(and:DI
+ (match_operand:DI 2 "register_operand" "r")
+ (match_operand 3 "const_int_operand"))])))]
"TARGET_64BIT
&& (INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1))
== GET_MODE_BITSIZE (SImode)-1"
@@ -1646,10 +1646,10 @@
[(set (match_operand:DI 0 "register_operand" "= r")
(any_shift:DI
(match_operand:DI 1 "register_operand" " r")
- (subreg:QI
- (and:SI
- (match_operand:SI 2 "register_operand" "r")
- (match_operand 3 "const_int_operand")) 0)))]
+ (match_operator 4 "subreg_lowpart_operator"
+ [(and:SI
+ (match_operand:SI 2 "register_operand" "r")
+ (match_operand 3 "const_int_operand"))])))]
"TARGET_64BIT
&& (INTVAL (operands[3]) & (GET_MODE_BITSIZE (DImode)-1))
== GET_MODE_BITSIZE (DImode)-1"
@@ -1666,10 +1666,10 @@
[(set (match_operand:DI 0 "register_operand" "= r")
(any_shift:DI
(match_operand:DI 1 "register_operand" " r")
- (subreg:QI
- (and:DI
- (match_operand:DI 2 "register_operand" "r")
- (match_operand 3 "const_int_operand")) 0)))]
+ (match_operator 4 "subreg_lowpart_operator"
+ [(and:DI
+ (match_operand:DI 2 "register_operand" "r")
+ (match_operand 3 "const_int_operand"))])))]
"TARGET_64BIT
&& (INTVAL (operands[3]) & (GET_MODE_BITSIZE (DImode)-1))
== GET_MODE_BITSIZE (DImode)-1"
@@ -1702,10 +1702,10 @@
(sign_extend:DI
(any_shift:SI
(match_operand:SI 1 "register_operand" " r")
- (subreg:QI
- (and:SI
- (match_operand:SI 2 "register_operand" " r")
- (match_operand 3 "const_int_operand")) 0))))]
+ (match_operator 4 "subreg_lowpart_operator"
+ [(and:SI
+ (match_operand:SI 2 "register_operand" " r")
+ (match_operand 3 "const_int_operand"))]))))]
"TARGET_64BIT
&& (INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1))
== GET_MODE_BITSIZE (SImode)-1"
@@ -1724,10 +1724,10 @@
(sign_extend:DI
(any_shift:SI
(match_operand:SI 1 "register_operand" " r")
- (subreg:QI
- (and:DI
- (match_operand:DI 2 "register_operand" " r")
- (match_operand 3 "const_int_operand")) 0))))]
+ (match_operator 4 "subreg_lowpart_operator"
+ [(and:DI
+ (match_operand:DI 2 "register_operand" " r")
+ (match_operand 3 "const_int_operand"))]))))]
"TARGET_64BIT
&& (INTVAL (operands[3]) & (GET_MODE_BITSIZE (SImode)-1))
== GET_MODE_BITSIZE (SImode)-1"
--
2.26.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v4 7/7] RISC-V: Fix riscv_subword() for big endian
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
` (5 preceding siblings ...)
2021-03-19 19:49 ` [PATCH v4 6/7] RISC-V: Fix matches against subreg with a bytenum of 0 in riscv.md Marcus Comstedt
@ 2021-03-19 19:49 ` Marcus Comstedt
2021-03-23 9:30 ` [PATCH v4 0/7] RISC-V big endian support Kito Cheng
7 siblings, 0 replies; 9+ messages in thread
From: Marcus Comstedt @ 2021-03-19 19:49 UTC (permalink / raw)
To: gcc-patches; +Cc: Marcus Comstedt
gcc/
* config/riscv/riscv.c (riscv_subword): Take endianness into
account when calculating the byte offset.
---
gcc/config/riscv/riscv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 1cd795bd19c..2f624e2123d 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -1966,7 +1966,7 @@ riscv_address_cost (rtx addr, machine_mode mode,
rtx
riscv_subword (rtx op, bool high_p)
{
- unsigned int byte = high_p ? UNITS_PER_WORD : 0;
+ unsigned int byte = (high_p != BYTES_BIG_ENDIAN) ? UNITS_PER_WORD : 0;
machine_mode mode = GET_MODE (op);
if (mode == VOIDmode)
--
2.26.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v4 0/7] RISC-V big endian support
2021-03-19 19:49 [PATCH v4 0/7] RISC-V big endian support Marcus Comstedt
` (6 preceding siblings ...)
2021-03-19 19:49 ` [PATCH v4 7/7] RISC-V: Fix riscv_subword() for big endian Marcus Comstedt
@ 2021-03-23 9:30 ` Kito Cheng
7 siblings, 0 replies; 9+ messages in thread
From: Kito Cheng @ 2021-03-23 9:30 UTC (permalink / raw)
To: Marcus Comstedt; +Cc: GCC Patches
Hi Marcus:
Verified with spike for rv32be and rv64be.
Committed to trunk, appreciate your work on this, RISC-V big-endian
support just reached a great milestone today!
On Sat, Mar 20, 2021 at 3:50 AM Marcus Comstedt <marcus@mc.pp.se> wrote:
>
> New update of the RISC-V big endian support.
>
> Changes since v3:
>
> * Changed riscv_subword to take endianness into account. This
> fixed multiple issues with long long on 32-bit.
>
> Testsuite results are now on par with little endian also on 32 bit.
> The only exception is gcc.c-torture/compile/pr35318.c, which has an
> internal compiler error (test fail) on 32 bit big endian, but not
> on 32 bit little endian (test pass, even though the generated code
> looks suspicious).
>
>
> // Marcus
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread