https://gcc.gnu.org/g:2b340357813089fb211cb2fca80c002f111c18d3

commit 2b340357813089fb211cb2fca80c002f111c18d3
Author: Michael Meissner <meiss...@linux.ibm.com>
Date:   Wed Oct 23 13:26:49 2024 -0400

    Add potential p-future XVRLD and XVRLDI instructions.
    
    2024-10-16  Michael Meissner  <meiss...@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/altivec.md (altivec_vrl<VI_char>): Add support for a
            possible XVRLD instruction in the future.
            (altivec_vrl<VI_char>_immediate): New insns.
            * config/rs6000/predicates.md (vector_shift_immediate): New 
predicate.
            * config/rs6000/rs6000.h (TARGET_XVRLW): New macro.
            * config/rs6000/rs6000.md (isa attribute): Add xvrlw.
            (enabled attribute): Add support for xvrlw.

Diff:
---
 gcc/config/rs6000/altivec.md    | 35 +++++++++++++++++++++++++++++++----
 gcc/config/rs6000/predicates.md | 26 ++++++++++++++++++++++++++
 gcc/config/rs6000/rs6000.h      |  3 +++
 gcc/config/rs6000/rs6000.md     |  6 +++++-
 4 files changed, 65 insertions(+), 5 deletions(-)

diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
index 00dad4b91f1c..d4ee50322ca1 100644
--- a/gcc/config/rs6000/altivec.md
+++ b/gcc/config/rs6000/altivec.md
@@ -1983,12 +1983,39 @@
 }
   [(set_attr "type" "vecperm")])
 
+;; -mcpu=future adds a vector rotate left word variant.  There is no vector
+;; byte/half-word/double-word/quad-word rotate left.  This insn occurs before
+;; altivec_vrl<VI_char> and will match for -mcpu=future, while other cpus will
+;; match the generic insn.
+;; However for testing, allow other xvrl variants.  In particular, XVRLD for
+;; the sha3 tests for multibuf/singlebuf.
 (define_insn "altivec_vrl<VI_char>"
-  [(set (match_operand:VI2 0 "register_operand" "=v")
-        (rotate:VI2 (match_operand:VI2 1 "register_operand" "v")
-                   (match_operand:VI2 2 "register_operand" "v")))]
+  [(set (match_operand:VI2 0 "register_operand" "=v,wa")
+        (rotate:VI2 (match_operand:VI2 1 "register_operand" "v,wa")
+                   (match_operand:VI2 2 "register_operand" "v,wa")))]
   "<VI_unit>"
-  "vrl<VI_char> %0,%1,%2"
+  "@
+   vrl<VI_char> %0,%1,%2
+   xvrl<VI_char> %x0,%x1,%x2"
+  [(set_attr "type" "vecsimple")
+   (set_attr "isa" "*,xvrlw")])
+
+(define_insn "*altivec_vrl<VI_char>_immediate"
+  [(set (match_operand:VI2 0 "register_operand" "=wa,wa,wa,wa")
+       (rotate:VI2 (match_operand:VI2 1 "register_operand" "wa,wa,wa,wa")
+                   (match_operand:VI2 2 "vector_shift_immediate" 
"j,wM,wE,wS")))]
+  "TARGET_XVRLW && <VI_unit>"
+{
+  rtx op2 = operands[2];
+  int value = 256;
+  int num_insns = -1;
+
+  if (!xxspltib_constant_p (op2, <MODE>mode, &num_insns, &value))
+    gcc_unreachable ();
+
+  operands[3] = GEN_INT (value & 0xff);
+  return "xvrl<VI_char>i %x0,%x1,%3";
+}
   [(set_attr "type" "vecsimple")])
 
 (define_insn "altivec_vrlq"
diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md
index 1d95e34557e5..fccfbd7e4904 100644
--- a/gcc/config/rs6000/predicates.md
+++ b/gcc/config/rs6000/predicates.md
@@ -728,6 +728,32 @@
   return num_insns == 1;
 })
 
+;; Return 1 if the operand is a CONST_VECTOR whose elements are all the
+;; same and the elements can be an immediate shift or rotate factor
+(define_predicate "vector_shift_immediate"
+  (match_code "const_vector,vec_duplicate,const_int")
+{
+  int value = 256;
+  int num_insns = -1;
+
+  if (zero_constant (op, mode) || all_ones_constant (op, mode))
+    return true;
+
+  if (!xxspltib_constant_p (op, mode, &num_insns, &value))
+    return false;
+
+  switch (mode)
+    {
+    case V16QImode: return IN_RANGE (value, 0, 7);
+    case V8HImode:  return IN_RANGE (value, 0, 15);
+    case V4SImode:  return IN_RANGE (value, 0, 31);
+    case V2DImode:  return IN_RANGE (value, 0, 63);
+    default:        break;
+    }
+
+  return false;
+})
+  
 ;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
 ;; vector register without using memory.
 (define_predicate "easy_vector_constant"
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 8cfd9faf77dc..1a168c2c9596 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -581,6 +581,9 @@ extern int rs6000_vector_align[];
    below.  */
 #define RS6000_FN_TARGET_INFO_HTM 1
 
+/* Whether we have XVRLW support.  */
+#define TARGET_XVRLW                   TARGET_FUTURE
+
 /* Whether the various reciprocal divide/square root estimate instructions
    exist, and whether we should automatically generate code for the instruction
    by default.  */
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 68fbfec95546..420f20d4524b 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -369,7 +369,7 @@
   (const (symbol_ref "(enum attr_cpu) rs6000_tune")))
 
 ;; The ISA we implement.
-(define_attr "isa" "any,p5,p6,p7,p7v,p8,p8v,p9,p9v,p9kf,p9tf,p10,xxeval"
+(define_attr "isa" "any,p5,p6,p7,p7v,p8,p8v,p9,p9v,p9kf,p9tf,p10,xxeval,xvrlw"
   (const_string "any"))
 
 ;; Is this alternative enabled for the current CPU/ISA/etc.?
@@ -426,6 +426,10 @@
          (match_test "TARGET_PREFIXED && TARGET_XXEVAL"))
      (const_int 1)
 
+     (and (eq_attr "isa" "xvrlw")
+         (match_test "TARGET_XVRLW"))
+     (const_int 1)
+
     ] (const_int 0)))
 
 ;; If this instruction is microcoded on the CELL processor

Reply via email to