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