@@ -2331,8 +2331,8 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
return false;
case AND:
- /* czero.eqz/nez */
- if ((TARGET_ZICOND)
+ /* czero.eqz/nez or vt.maskc/vt.maskcn */
+ if ((TARGET_ZICOND || TARGET_XVENTANACONDOPS)
&& mode == word_mode
&& GET_CODE (XEXP (x, 0)) == NEG)
{
@@ -2673,7 +2673,7 @@ (define_split
(match_operator:GPR 1 "anyle_operator"
[(match_operand:X 2 "register_operand")
(match_operand:X 3 "register_operand")]))]
- "TARGET_ZICOND"
+ "TARGET_ZICOND || TARGET_XVENTANACONDOPS"
[(set (match_dup 0) (match_dup 4))
(set (match_dup 0) (eq:GPR (match_dup 0) (const_int 0)))]
{
@@ -2707,7 +2707,7 @@ (define_split
(match_operator:GPR 1 "anyge_operator"
[(match_operand:X 2 "register_operand")
(match_operand:X 3 "register_operand")]))]
- "TARGET_ZICOND"
+ "TARGET_ZICOND || TARGET_XVENTANACONDOPS"
[(set (match_dup 0) (match_dup 4))
(set (match_dup 0) (eq:GPR (match_dup 0) (const_int 0)))]
{
@@ -3255,3 +3255,4 @@ (define_insn "riscv_prefetchi_<mode>"
(include "sifive-7.md")
(include "vector.md")
(include "zicond.md")
+(include "xventanacondops.md")
new file mode 100644
@@ -0,0 +1,29 @@
+;; Machine description for X-Ventana-CondOps
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; This file is part of GCC.
+
+;; GCC is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; GCC is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GCC; see the file COPYING3. If not see
+;; <http://www.gnu.org/licenses/>.
+
+(define_code_attr vt_n [(eq "n") (ne "")])
+
+(define_insn "*vt.maskc<vt_n>"
+ [(set (match_operand:DI 0 "register_operand" "=r")
+ (and:DI (neg:DI (eq_or_ne:DI
+ (match_operand:DI 1 "register_operand" "r")
+ (const_int 0)))
+ (match_operand:DI 2 "register_operand" "r")))]
+ "TARGET_XVENTANACONDOPS"
+ "vt.maskc<vt_n>\t%0,%2,%1")
@@ -39,7 +39,7 @@ (define_split
(const_int 0)]))
(match_operand:DI 3 "immediate_operand")))
(clobber (match_operand:DI 4 "register_operand"))]
- "TARGET_ZICOND"
+ "TARGET_ZICOND || TARGET_XVENTANACONDOPS"
[(set (match_dup 4) (match_dup 3))
(set (match_dup 0) (and:DI (neg:DI (match_dup 1))
(match_dup 4)))]
@@ -60,7 +60,7 @@ (define_split
(match_operand:X 3 "arith_operand")]))
(match_operand:X 4 "register_operand")))
(clobber (match_operand:X 5 "register_operand"))]
- "TARGET_ZICOND"
+ "TARGET_ZICOND || TARGET_XVENTANACONDOPS"
[(set (match_dup 5) (match_dup 6))
(set (match_dup 0) (and:X (neg:X (eq:X (match_dup 5) (const_int 0)))
(match_dup 4)))]
@@ -77,7 +77,7 @@ (define_split
(match_operand:X 3 "arith_operand")]))
(match_operand:X 4 "register_operand")))
(clobber (match_operand:X 5 "register_operand"))]
- "TARGET_ZICOND"
+ "TARGET_ZICOND || TARGET_XVENTANACONDOPS"
[(set (match_dup 5) (match_dup 1))
(set (match_dup 0) (and:X (neg:X (ne:X (match_dup 5) (const_int 0)))
(match_dup 4)))])
@@ -90,7 +90,7 @@ (define_split
(match_operand:X 3 "arith_operand")]))
(match_operand:X 4 "register_operand")))
(clobber (match_operand:X 5 "register_operand"))]
- "TARGET_ZICOND"
+ "TARGET_ZICOND || TARGET_XVENTANACONDOPS"
[(set (match_dup 5) (match_dup 6))
(set (match_dup 0) (and:X (neg:X (eq:X (match_dup 5) (const_int 0)))
(match_dup 4)))]
@@ -123,7 +123,7 @@ (define_split
(match_operand 2 "immediate_operand"))
(match_operand:X 3 "register_operand")))
(clobber (match_operand:X 4 "register_operand"))]
- "TARGET_ZICOND && TARGET_ZBS"
+ "(TARGET_ZICOND || TARGET_XVENTANACONDOPS) && TARGET_ZBS"
[(set (match_dup 4) (zero_extract:X (match_dup 1) (const_int 1) (match_dup 2)))
(set (match_dup 0) (and:X (neg:X (ne:X (match_dup 4) (const_int 0)))
(match_dup 3)))])
@@ -136,7 +136,8 @@ (define_split
(match_operand 2 "immediate_operand"))
(match_operand:X 3 "register_operand")))
(clobber (match_operand:X 4 "register_operand"))]
- "TARGET_ZICOND && !TARGET_ZBS && (UINTVAL (operands[2]) < 11)"
+ "(TARGET_ZICOND || TARGET_XVENTANACONDOPS)
+ && !TARGET_ZBS && (UINTVAL (operands[2]) < 11)"
[(set (match_dup 4) (and:X (match_dup 1) (match_dup 2)))
(set (match_dup 0) (and:X (neg:X (ne:X (match_dup 4) (const_int 0)))
(match_dup 3)))]
@@ -150,6 +151,6 @@ (define_split
(const_int 1)
(match_operand 2 "immediate_operand"))
(const_int 0))))]
- "!TARGET_ZICOND && TARGET_ZBS"
+ "!(TARGET_ZICOND || TARGET_XVENTANACONDOPS) && TARGET_ZBS"
[(set (match_dup 0) (zero_extract:X (match_dup 1) (const_int 1) (match_dup 2)))
(set (match_dup 0) (plus:X (match_dup 0) (const_int -1)))])
new file mode 100644
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
+
+long and1(long a, long b, long c, long d)
+{
+ if (c < d)
+ a &= b;
+
+ return a;
+}
+
+/* { dg-final { scan-assembler-times "and\t" 1 } } */
+/* { dg-final { scan-assembler-times "slt" 1 } } */
+/* { dg-final { scan-assembler-times "vt.maskcn" 1 } } */
+/* { dg-final { scan-assembler-times "or\t" 1 } } */
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
+
+int and2(int a, int b, long c)
+{
+ if (c)
+ a &= b;
+
+ return a;
+}
+
+/* { dg-final { scan-assembler-times "and\t" 1 } } */
+/* { dg-final { scan-assembler-times "vt.maskcn" 1 } } */
+/* { dg-final { scan-assembler-times "or\t" 1 } } */
new file mode 100644
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+long
+eq1 (long a, long b)
+{
+ return (a == 0) ? b : 0;
+}
+
+/* { dg-final { scan-assembler-times "vt.maskcn" 1 } } */
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+long
+eq2 (long a, long b)
+{
+ if (a == 0)
+ return b;
+
+ return 0;
+}
+
+/* { dg-final { scan-assembler-times "vt.maskcn" 1 } } */
new file mode 100644
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
+
+/* Each function below should emit a vt.maskcn instruction */
+
+long
+foo0 (long a, long b, long c)
+{
+ if (c)
+ a = 0;
+ else
+ a = 5;
+ return a;
+}
+
+/* { dg-final { scan-assembler-times "vt.maskcn\t" 1 } } */
+/* { dg-final { scan-assembler-not "beqz\t" } } */
+/* { dg-final { scan-assembler-not "bnez\t" } } */
new file mode 100644
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb_zbs_xventanacondops -mabi=lp64 -mbranch-cost=4" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" "-Os" "-Oz" } } */
+
+long long sink (long long);
+
+long long le1 (long long a, long long b)
+{
+ if (a <= b)
+ b = 0;
+
+ return sink(b);
+}
+
+/* { dg-final { scan-assembler-times "sgt\t" 1 } } */
+/* { dg-final { scan-assembler-times "vt.maskc\t" 1 } } */
new file mode 100644
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb_zbs_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" "-Os" "-Oz" } } */
+
+long long le2 (long long a, long long b, long long c)
+{
+ return (a <= c) ? b : 0;
+}
+
+/* { dg-final { scan-assembler-times "sgt\t" 1 } } */
+/* { dg-final { scan-assembler-times "vt.maskcn\t" 1 } } */
new file mode 100644
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
+
+long long sink (long long);
+
+long long lt3 (long long a, long long b)
+{
+ if (a < b)
+ b = 0;
+
+ return sink(b);
+}
+
+/* { dg-final { scan-assembler-times "vt.maskcn\t" 1 } } */
+/* { dg-final { scan-assembler-times "slt\t" 1 } } */
new file mode 100644
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba_zbb_zbs_xventanacondops -mabi=lp64 -mbranch-cost=4" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" "-Os" "-Oz" } } */
+
+long long sink (long long);
+
+long long lt3 (long long a, long long b)
+{
+ if (a < b)
+ b = 0;
+
+ return sink(b);
+}
+
+/* { dg-final { scan-assembler-times "slt\t" 1 } } */
+/* { dg-final { scan-assembler-times "vt.maskcn\t" 1 } } */
new file mode 100644
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */
+
+long long ne1(long long a, long long b)
+{
+ return (a != 0) ? b : 0;
+}
+
+/* { dg-final { scan-assembler-times "vt.maskc" 1 } } */
new file mode 100644
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64 -mtune=thead-c906" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-O1" "-Os" "-Oz" } } */
+
+long long ne3(long long a, long long b)
+{
+ if (a != 0)
+ return b;
+
+ return 0;
+}
+
+/* { dg-final { scan-assembler-times "vt.maskc" 1 } } */
new file mode 100644
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64 -mtune=thead-c906" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
+
+long long ne4(long long a, long long b)
+{
+ if (a != 0)
+ return 0;
+
+ return b;
+}
+
+/* { dg-final { scan-assembler-times "vt.maskcn" 1 } } */
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_xventanacondops -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
+
+long xor1(long crc, long poly)
+{
+ if (crc & 1)
+ crc ^= poly;
+
+ return crc;
+}
+
+/* { dg-final { scan-assembler-times "vt.maskc" 1 } } */
+/* { dg-final { scan-assembler-times "xor\t" 1 } } */