public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/2] RISC-V: __builtin_riscv_pause for all environment
@ 2023-08-09  6:11 Tsukasa OI
  2023-08-09  6:11 ` [RFC PATCH 1/2] " Tsukasa OI
                   ` (4 more replies)
  0 siblings, 5 replies; 28+ messages in thread
From: Tsukasa OI @ 2023-08-09  6:11 UTC (permalink / raw)
  To: Tsukasa OI, Kito Cheng, Palmer Dabbelt, Andrew Waterman, Jim Wilson
  Cc: gcc-patches

Hello,

I found that a built-in function "__builtin_riscv_pause" is not usable
unless we enable the 'Zihintpause' extension explicitly (still, this
built-in exists EVEN IF the 'Zihintpause' extension is disabled).

Contents of a.c:

> void sample(void)
> {
>     __builtin_riscv_pause();
> }


Compiling with the 'Zihintpause' extension is fine.

> $ riscv64-unknown-elf-gcc -O2 -march=rv64i_zihintpause -mabi=lp64 -c a.c


However, compiling without the 'Zihintpause' causes an assembler error
(tested with GNU Binutils 2.41):

> $ riscv64-unknown-elf-gcc -O2 -march=rv64i -mabi=lp64 -c a.c
> /tmp/ccFjacAz.s: Assembler messages:
> /tmp/ccFjacAz.s:11: Error: unrecognized opcode `pause', extension `zihintpause' required


This is because:

1.  GCC does not handle the 'Zihintpause' extension and
2.  "riscv_pause" (insn) unconditionally emits "pause" even if the
    assembler does not accept it (when the extension is disabled).


This patch set (PATCH 1/2) resolves this issue by:

1.  Handling the 'Zihintpause' extension and
2.  Splitting the "__builtin_riscv_pause" implementation
    depending on the existence of the 'Zihintpause' extension.

Because a released version of GCC defines "__builtin_riscv_pause"
unconditionally, I chose to define no-'Zihintpause' version.

There is another option to unconditionally emit ".insn 0x0100000f"
(the machine code of "pause") but I didn't because I wanted to improve the
diagnostics (e.g. *.s output).

I also fixed the description of this built-in function (in PATCH 2/2).


I'm not sure whether this is a good method to split the implementation
depending on the 'Zihintpause' extension.  Other than that, I believe that
this is okay and approval is appreciated.

Note that because I assigned copyright of GCC contribution to FSF, I didn't
attach "Signed-off-by" tag.  Tell me if I need it.

Thanks,
Tsukasa




Tsukasa OI (2):
  RISC-V: __builtin_riscv_pause for all environment
  RISC-V: Fix documentation of __builtin_riscv_pause

 gcc/common/config/riscv/riscv-common.cc             |  2 ++
 gcc/config/riscv/riscv-builtins.cc                  |  6 ++++--
 gcc/config/riscv/riscv-opts.h                       |  2 ++
 gcc/config/riscv/riscv.md                           |  7 ++++++-
 gcc/doc/extend.texi                                 |  6 +++---
 gcc/testsuite/gcc.target/riscv/builtin_pause.c      | 10 ----------
 gcc/testsuite/gcc.target/riscv/zihintpause-noarch.c | 11 +++++++++++
 gcc/testsuite/gcc.target/riscv/zihintpause.c        | 11 +++++++++++
 8 files changed, 39 insertions(+), 16 deletions(-)
 delete mode 100644 gcc/testsuite/gcc.target/riscv/builtin_pause.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zihintpause-noarch.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/zihintpause.c


base-commit: c8b396243ec5bfa9b541555131df597ebc84b9d0
-- 
2.41.0


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2023-08-29  9:26 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-09  6:11 [RFC PATCH 0/2] RISC-V: __builtin_riscv_pause for all environment Tsukasa OI
2023-08-09  6:11 ` [RFC PATCH 1/2] " Tsukasa OI
2023-08-28 21:12   ` Jeff Law
2023-08-29  2:02     ` Tsukasa OI
2023-08-09  6:11 ` [RFC PATCH 2/2] RISC-V: Fix documentation of __builtin_riscv_pause Tsukasa OI
2023-08-28 21:14   ` Jeff Law
2023-08-28 23:09     ` Hans-Peter Nilsson
2023-08-28 23:15       ` Jeff Law
2023-08-29  2:15       ` Tsukasa OI
2023-08-29  9:26         ` Hans-Peter Nilsson
2023-08-09 20:05 ` [RFC PATCH 0/2] RISC-V: __builtin_riscv_pause for all environment Jeff Law
2023-08-09 22:39   ` Tsukasa OI
2023-08-11 23:30     ` Jeff Law
2023-08-11 23:34       ` Palmer Dabbelt
2023-08-12  0:20       ` Tsukasa OI
2023-08-15 13:49         ` Jeff Law
2023-08-13 19:52       ` Philipp Tomsich
2023-08-13 20:17         ` Andrew Waterman
2023-08-15 13:52         ` Jeff Law
2023-08-10  2:25 ` [RFC PATCH v2 " Tsukasa OI
2023-08-10  2:25   ` [RFC PATCH v2 1/2] " Tsukasa OI
2023-08-16  1:26     ` Jeff Law
2023-08-16  8:33       ` Philipp Tomsich
2023-08-21 14:02         ` Jeff Law
2023-08-10  2:25   ` [RFC PATCH v2 2/2] RISC-V: Fix documentation of __builtin_riscv_pause Tsukasa OI
2023-08-10  2:26 ` [RFC PATCH 0/2] RISC-V: Make __builtin_riscv_pause 'Zihintpause' only Tsukasa OI
2023-08-10  2:26   ` [RFC PATCH 1/2] " Tsukasa OI
2023-08-10  2:26   ` [RFC PATCH 2/2] RISC-V: Fix documentation of __builtin_riscv_pause Tsukasa OI

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).