public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Takayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH 3/4] xtensa: Make use of BALL/BNALL instructions
Date: Sun, 12 Jun 2022 15:38:23 +0900	[thread overview]
Message-ID: <a7dfdbbc-0c72-730c-9843-6ec9db72f070@yahoo.co.jp> (raw)

In Xtensa ISA, there is no single machine instruction that calculates unary
bitwise negation, but a few similar fused instructions are exist:

   "BALL  Ax, Ay, label"  // if ((~Ax & Ay) == 0) goto label;
   "BNALL Ax, Ay, label"  // if ((~Ax & Ay) != 0) goto label;

These instructions have never been emitted before, but it seems no 
reason not
to make use of them.

gcc/ChangeLog:

	* config/xtensa/xtensa.md (*masktrue_bitcmpl): New insn pattern.

gcc/testsuite/ChangeLog:

	* gcc.target/xtensa/BALL-BNALL.c: New.
---
  gcc/config/xtensa/xtensa.md                  | 21 +++++++++++++
  gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c | 33 ++++++++++++++++++++
  2 files changed, 54 insertions(+)
  create mode 100644 gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c

diff --git a/gcc/config/xtensa/xtensa.md b/gcc/config/xtensa/xtensa.md
index 25b8d2fb3c9..090a2939684 100644
--- a/gcc/config/xtensa/xtensa.md
+++ b/gcc/config/xtensa/xtensa.md
@@ -1627,6 +1627,27 @@
     (set_attr "mode"	"none")
     (set_attr "length"	"3")])

+(define_insn "*masktrue_bitcmpl"
+  [(set (pc)
+	(if_then_else (match_operator 3 "boolean_operator"
+			[(and:SI (not:SI (match_operand:SI 0 "register_operand" "r"))
+				 (match_operand:SI 1 "register_operand" "r"))
+			 (const_int 0)])
+		      (label_ref (match_operand 2 "" ""))
+		      (pc)))]
+  ""
+{
+  switch (GET_CODE (operands[3]))
+    {
+    case EQ:	return "ball\t%0, %1, %2";
+    case NE:	return "bnall\t%0, %1, %2";
+    default:	gcc_unreachable ();
+    }
+}
+  [(set_attr "type"	"jump")
+   (set_attr "mode"	"none")
+   (set_attr "length"	"3")])
+

  ;; Zero-overhead looping support.

diff --git a/gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c 
b/gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c
new file mode 100644
index 00000000000..ba61c6f371b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+extern void foo(void);
+
+void BNONE_test(int a, int b)
+{
+  if (a & b)
+    foo();
+}
+
+void BANY_test(int a, int b)
+{
+  if (!(a & b))
+    foo();
+}
+
+void BALL_test(int a, int b)
+{
+  if (~a & b)
+    foo();
+}
+
+void BNALL_test(int a, int b)
+{
+  if (!(~a & b))
+    foo();
+}
+
+/* { dg-final { scan-assembler-times "bnone" 1 } } */
+/* { dg-final { scan-assembler-times "bany" 1 } } */
+/* { dg-final { scan-assembler-times "ball" 1 } } */
+/* { dg-final { scan-assembler-times "bnall" 1 } } */
-- 
2.20.1

             reply	other threads:[~2022-06-12  6:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-12  6:38 Takayuki 'January June' Suwa [this message]
2022-06-14  0:33 ` Max Filippov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a7dfdbbc-0c72-730c-9843-6ec9db72f070@yahoo.co.jp \
    --to=jjsuwa_sys3175@yahoo.co.jp \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).