public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: Zihintpause: add __builtin_riscv_pause
@ 2022-11-15 14:02 Philipp Tomsich
0 siblings, 0 replies; 2+ messages in thread
From: Philipp Tomsich @ 2022-11-15 14:02 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:78df89a90553391570ebf96bcb89e250077aa396
commit 78df89a90553391570ebf96bcb89e250077aa396
Author: Philipp Tomsich <philipp.tomsich@vrull.eu>
Date: Thu Dec 17 00:44:11 2020 +0100
RISC-V: Zihintpause: add __builtin_riscv_pause
The Zihintpause extension uses an opcode from the 'fence' opcode range
to add a true hint instruction (i.e. if it is not supported on any
given platform, the 'fence' that is encoded will not enforce any
specific ordering on memory accesses) for entering a low-power state
(e.g. in an idle thread). We expose this new instruction through a
machine-dependent builtin to allow generating it without a requirement
for any inline assembly.
Given that the encoding of 'pause' is valid (as a 'fence' encoding)
even for processors that do not (yet) support Zihintpause, we make
this builtin available without any further TARGET_* constraints.
gcc/ChangeLog:
* config/riscv/riscv-builtins.cc (struct riscv_builtin_description):
add the pause machine-dependent builtin with no result and no
arguments; mark it as always present (pause is a true hint
that encodes into a fence-insn, if not supported with the new
pause semantics).
* config/riscv/riscv-ftypes.def: Add type for void -> void.
* config/riscv/riscv.md (riscv_pause): Add risc_pause and UNSPECV_PAUSE
* doc/gcc/extensions-to-the-c-language-family/target-builtins/risc-v-built-in-functions.rst:
Document.
* optabs.cc (maybe_gen_insn): Allow nops == 0 (void -> void).
gcc/testsuite/ChangeLog:
* gcc.target/riscv/builtin_pause.c: New test.
Series-to: gcc-patches@gcc.gnu.org
Series-cc: Palmer Dabbelt <palmer@rivosinc.com>
Series-cc: Vineet Gupta <vineetg@rivosinc.com>
Series-cc: Christoph Muellner <christoph.muellner@vrull.eu>
Series-cc: Kito Cheng <kito.cheng@gmail.com>
Series-cc: Jeff Law <jlaw@ventanamicro.com>
Diff:
---
gcc/config/riscv/riscv-builtins.cc | 6 +++---
gcc/config/riscv/riscv-ftypes.def | 1 +
gcc/config/riscv/riscv.md | 8 ++++++++
gcc/doc/extend.texi | 4 ++++
gcc/optabs.cc | 2 ++
gcc/testsuite/gcc.target/riscv/builtin_pause.c | 10 ++++++++++
6 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/gcc/config/riscv/riscv-builtins.cc b/gcc/config/riscv/riscv-builtins.cc
index 021f6c6b69a..24ae22c99cd 100644
--- a/gcc/config/riscv/riscv-builtins.cc
+++ b/gcc/config/riscv/riscv-builtins.cc
@@ -88,8 +88,6 @@ struct riscv_builtin_description {
};
AVAIL (hard_float, TARGET_HARD_FLOAT || TARGET_ZFINX)
-
-
AVAIL (clean32, TARGET_ZICBOM && !TARGET_64BIT)
AVAIL (clean64, TARGET_ZICBOM && TARGET_64BIT)
AVAIL (flush32, TARGET_ZICBOM && !TARGET_64BIT)
@@ -100,6 +98,7 @@ AVAIL (zero32, TARGET_ZICBOZ && !TARGET_64BIT)
AVAIL (zero64, TARGET_ZICBOZ && TARGET_64BIT)
AVAIL (prefetchi32, TARGET_ZICBOP && !TARGET_64BIT)
AVAIL (prefetchi64, TARGET_ZICBOP && TARGET_64BIT)
+AVAIL (always, (!0))
/* Construct a riscv_builtin_description from the given arguments.
@@ -148,7 +147,8 @@ static const struct riscv_builtin_description riscv_builtins[] = {
#include "riscv-cmo.def"
DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE, hard_float),
- DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float)
+ DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float),
+ DIRECT_NO_TARGET_BUILTIN (pause, RISCV_VOID_FTYPE, always),
};
/* Index I is the function declaration for riscv_builtins[I], or null if the
diff --git a/gcc/config/riscv/riscv-ftypes.def b/gcc/config/riscv/riscv-ftypes.def
index c2b45c63ea1..bf2d30782d9 100644
--- a/gcc/config/riscv/riscv-ftypes.def
+++ b/gcc/config/riscv/riscv-ftypes.def
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see
argument type. */
DEF_RISCV_FTYPE (0, (USI))
+DEF_RISCV_FTYPE (0, (VOID))
DEF_RISCV_FTYPE (1, (VOID, USI))
DEF_RISCV_FTYPE (1, (VOID, VOID_PTR))
DEF_RISCV_FTYPE (1, (SI, SI))
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 88183cea87d..7d2fd12d58f 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -97,6 +97,9 @@
UNSPECV_INVAL
UNSPECV_ZERO
UNSPECV_PREI
+
+ ;; Zihintpause unspec
+ UNSPECV_PAUSE
])
(define_constants
@@ -1985,6 +1988,11 @@
"TARGET_ZIFENCEI"
"fence.i")
+(define_insn "riscv_pause"
+ [(unspec_volatile [(const_int 0)] UNSPECV_PAUSE)]
+ ""
+ "pause")
+
;;
;; ....................
;;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 608bbe1699c..b1dd39e64b8 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -21102,6 +21102,10 @@ processors.
Returns the value that is currently set in the @samp{tp} register.
@end deftypefn
+@deftypefn {Built-in Function} void __builtin_riscv_pause (void)
+Generates the @code{pause} (hint) machine instruction.
+@end deftypefn
+
@node RX Built-in Functions
@subsection RX Built-in Functions
GCC supports some of the RX instructions which cannot be expressed in
diff --git a/gcc/optabs.cc b/gcc/optabs.cc
index 2d9ca4e56ab..bbe3bd79ca1 100644
--- a/gcc/optabs.cc
+++ b/gcc/optabs.cc
@@ -7962,6 +7962,8 @@ maybe_gen_insn (enum insn_code icode, unsigned int nops,
switch (nops)
{
+ case 0:
+ return GEN_FCN (icode) ();
case 1:
return GEN_FCN (icode) (ops[0].value);
case 2:
diff --git a/gcc/testsuite/gcc.target/riscv/builtin_pause.c b/gcc/testsuite/gcc.target/riscv/builtin_pause.c
new file mode 100644
index 00000000000..9250937cabb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/builtin_pause.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void test_pause()
+{
+ __builtin_riscv_pause ();
+}
+
+/* { dg-final { scan-assembler "pause" } } */
+
^ permalink raw reply [flat|nested] 2+ messages in thread
* [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: Zihintpause: add __builtin_riscv_pause
@ 2022-11-15 15:00 Philipp Tomsich
0 siblings, 0 replies; 2+ messages in thread
From: Philipp Tomsich @ 2022-11-15 15:00 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:11a36c1747d267a114553f55b5d43f4f8f28ec90
commit 11a36c1747d267a114553f55b5d43f4f8f28ec90
Author: Philipp Tomsich <philipp.tomsich@vrull.eu>
Date: Thu Dec 17 00:44:11 2020 +0100
RISC-V: Zihintpause: add __builtin_riscv_pause
The Zihintpause extension uses an opcode from the 'fence' opcode range
to add a true hint instruction (i.e. if it is not supported on any
given platform, the 'fence' that is encoded will not enforce any
specific ordering on memory accesses) for entering a low-power state
(e.g. in an idle thread). We expose this new instruction through a
machine-dependent builtin to allow generating it without a requirement
for any inline assembly.
Given that the encoding of 'pause' is valid (as a 'fence' encoding)
even for processors that do not (yet) support Zihintpause, we make
this builtin available without any further TARGET_* constraints.
gcc/ChangeLog:
* config/riscv/riscv-builtins.cc (struct riscv_builtin_description):
add the pause machine-dependent builtin with no result and no
arguments; mark it as always present (pause is a true hint
that encodes into a fence-insn, if not supported with the new
pause semantics).
* config/riscv/riscv-ftypes.def: Add type for void -> void.
* config/riscv/riscv.md (riscv_pause): Add risc_pause and UNSPECV_PAUSE
* doc/gcc/extensions-to-the-c-language-family/target-builtins/risc-v-built-in-functions.rst:
Document.
* optabs.cc (maybe_gen_insn): Allow nops == 0 (void -> void).
gcc/testsuite/ChangeLog:
* gcc.target/riscv/builtin_pause.c: New test.
Series-to: gcc-patches@gcc.gnu.org
Series-cc: Palmer Dabbelt <palmer@rivosinc.com>
Series-cc: Vineet Gupta <vineetg@rivosinc.com>
Series-cc: Christoph Muellner <christoph.muellner@vrull.eu>
Series-cc: Kito Cheng <kito.cheng@gmail.com>
Series-cc: Jeff Law <jlaw@ventanamicro.com>
Diff:
---
gcc/config/riscv/riscv-builtins.cc | 6 +++---
gcc/config/riscv/riscv-ftypes.def | 1 +
gcc/config/riscv/riscv.md | 8 ++++++++
gcc/doc/extend.texi | 4 ++++
gcc/optabs.cc | 2 ++
gcc/testsuite/gcc.target/riscv/builtin_pause.c | 10 ++++++++++
6 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/gcc/config/riscv/riscv-builtins.cc b/gcc/config/riscv/riscv-builtins.cc
index 021f6c6b69a6..24ae22c99cd4 100644
--- a/gcc/config/riscv/riscv-builtins.cc
+++ b/gcc/config/riscv/riscv-builtins.cc
@@ -88,8 +88,6 @@ struct riscv_builtin_description {
};
AVAIL (hard_float, TARGET_HARD_FLOAT || TARGET_ZFINX)
-
-
AVAIL (clean32, TARGET_ZICBOM && !TARGET_64BIT)
AVAIL (clean64, TARGET_ZICBOM && TARGET_64BIT)
AVAIL (flush32, TARGET_ZICBOM && !TARGET_64BIT)
@@ -100,6 +98,7 @@ AVAIL (zero32, TARGET_ZICBOZ && !TARGET_64BIT)
AVAIL (zero64, TARGET_ZICBOZ && TARGET_64BIT)
AVAIL (prefetchi32, TARGET_ZICBOP && !TARGET_64BIT)
AVAIL (prefetchi64, TARGET_ZICBOP && TARGET_64BIT)
+AVAIL (always, (!0))
/* Construct a riscv_builtin_description from the given arguments.
@@ -148,7 +147,8 @@ static const struct riscv_builtin_description riscv_builtins[] = {
#include "riscv-cmo.def"
DIRECT_BUILTIN (frflags, RISCV_USI_FTYPE, hard_float),
- DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float)
+ DIRECT_NO_TARGET_BUILTIN (fsflags, RISCV_VOID_FTYPE_USI, hard_float),
+ DIRECT_NO_TARGET_BUILTIN (pause, RISCV_VOID_FTYPE, always),
};
/* Index I is the function declaration for riscv_builtins[I], or null if the
diff --git a/gcc/config/riscv/riscv-ftypes.def b/gcc/config/riscv/riscv-ftypes.def
index c2b45c63ea17..bf2d30782d9e 100644
--- a/gcc/config/riscv/riscv-ftypes.def
+++ b/gcc/config/riscv/riscv-ftypes.def
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see
argument type. */
DEF_RISCV_FTYPE (0, (USI))
+DEF_RISCV_FTYPE (0, (VOID))
DEF_RISCV_FTYPE (1, (VOID, USI))
DEF_RISCV_FTYPE (1, (VOID, VOID_PTR))
DEF_RISCV_FTYPE (1, (SI, SI))
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index 88183cea87d8..7d2fd12d58fb 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -97,6 +97,9 @@
UNSPECV_INVAL
UNSPECV_ZERO
UNSPECV_PREI
+
+ ;; Zihintpause unspec
+ UNSPECV_PAUSE
])
(define_constants
@@ -1985,6 +1988,11 @@
"TARGET_ZIFENCEI"
"fence.i")
+(define_insn "riscv_pause"
+ [(unspec_volatile [(const_int 0)] UNSPECV_PAUSE)]
+ ""
+ "pause")
+
;;
;; ....................
;;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 608bbe1699c7..b1dd39e64b84 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -21102,6 +21102,10 @@ processors.
Returns the value that is currently set in the @samp{tp} register.
@end deftypefn
+@deftypefn {Built-in Function} void __builtin_riscv_pause (void)
+Generates the @code{pause} (hint) machine instruction.
+@end deftypefn
+
@node RX Built-in Functions
@subsection RX Built-in Functions
GCC supports some of the RX instructions which cannot be expressed in
diff --git a/gcc/optabs.cc b/gcc/optabs.cc
index 2d9ca4e56ab5..bbe3bd79ca10 100644
--- a/gcc/optabs.cc
+++ b/gcc/optabs.cc
@@ -7962,6 +7962,8 @@ maybe_gen_insn (enum insn_code icode, unsigned int nops,
switch (nops)
{
+ case 0:
+ return GEN_FCN (icode) ();
case 1:
return GEN_FCN (icode) (ops[0].value);
case 2:
diff --git a/gcc/testsuite/gcc.target/riscv/builtin_pause.c b/gcc/testsuite/gcc.target/riscv/builtin_pause.c
new file mode 100644
index 000000000000..9250937cabb9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/builtin_pause.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void test_pause()
+{
+ __builtin_riscv_pause ();
+}
+
+/* { dg-final { scan-assembler "pause" } } */
+
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-15 15:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 14:02 [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: Zihintpause: add __builtin_riscv_pause Philipp Tomsich
2022-11-15 15:00 Philipp Tomsich
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).