]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
xtensa: Make use of BALL/BNALL instructions
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Thu, 27 May 2021 10:04:12 +0000 (19:04 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Tue, 14 Jun 2022 00:25:48 +0000 (17:25 -0700)
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
gcc/testsuite/gcc.target/xtensa/BALL-BNALL.c [new file with mode: 0644]

index 449e4b242622146b873767e474f34cebde9ea6ae..a4477e2207ec10e8eff4f9f71df39e305faee7dd 100644 (file)
    (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 (file)
index 0000000..ba61c6f
--- /dev/null
@@ -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 } } */