===================================================================
@@ -5016,6 +5016,31 @@ const struct altivec_builtin_types altiv
RS6000_BTI_unsigned_V16QI, RS6000_BTI_unsigned_V16QI,
RS6000_BTI_unsigned_V16QI, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRQ_V16QI,
+ RS6000_BTI_unsigned_V16QI, RS6000_BTI_unsigned_V16QI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRQ_V16QI,
+ RS6000_BTI_V16QI, RS6000_BTI_V16QI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRQ_V1TI,
+ RS6000_BTI_unsigned_V1TI, RS6000_BTI_unsigned_V1TI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRQ_V1TI,
+ RS6000_BTI_V1TI, RS6000_BTI_V1TI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRD_V2DI,
+ RS6000_BTI_unsigned_V2DI, RS6000_BTI_unsigned_V2DI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRD_V2DI,
+ RS6000_BTI_V2DI, RS6000_BTI_V2DI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRD_V2DF,
+ RS6000_BTI_V2DF, RS6000_BTI_V2DF, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRW_V4SI,
+ RS6000_BTI_unsigned_V4SI, RS6000_BTI_unsigned_V4SI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRW_V4SI,
+ RS6000_BTI_V4SI, RS6000_BTI_V4SI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRW_V4SF,
+ RS6000_BTI_V4SF, RS6000_BTI_V4SF, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRH_V8HI,
+ RS6000_BTI_unsigned_V8HI, RS6000_BTI_unsigned_V8HI, 0, 0 },
+ { P9V_BUILTIN_VEC_REVB, P9V_BUILTIN_XXBRH_V8HI,
+ RS6000_BTI_V8HI, RS6000_BTI_V8HI, 0, 0 },
+
/* Crypto builtins. */
{ CRYPTO_BUILTIN_VPERMXOR, CRYPTO_BUILTIN_VPERMXOR_V16QI,
RS6000_BTI_unsigned_V16QI, RS6000_BTI_unsigned_V16QI,
===================================================================
@@ -1932,6 +1932,14 @@ BU_P9V_64BIT_VSX_1 (VSESDP, "scalar_extr
BU_P9V_VSX_1 (VSTDCNDP, "scalar_test_neg_dp", CONST, xststdcnegdp)
BU_P9V_VSX_1 (VSTDCNSP, "scalar_test_neg_sp", CONST, xststdcnegsp)
+BU_P9V_VSX_1 (XXBRQ_V16QI, "xxbrq_v16qi", CONST, p9_xxbrq_v16qi)
+BU_P9V_VSX_1 (XXBRQ_V1TI, "xxbrq_v1ti", CONST, p9_xxbrq_v1ti)
+BU_P9V_VSX_1 (XXBRD_V2DI, "xxbrd_v2di", CONST, p9_xxbrd_v2di)
+BU_P9V_VSX_1 (XXBRD_V2DF, "xxbrd_v2df", CONST, p9_xxbrd_v2df)
+BU_P9V_VSX_1 (XXBRW_V4SI, "xxbrw_v4si", CONST, p9_xxbrw_v4si)
+BU_P9V_VSX_1 (XXBRW_V4SF, "xxbrw_v4sf", CONST, p9_xxbrw_v4sf)
+BU_P9V_VSX_1 (XXBRH_V8HI, "xxbrh_v8hi", CONST, p9_xxbrh_v8hi)
+
/* 2 argument vsx scalar functions added in ISA 3.0 (power9). */
BU_P9V_64BIT_VSX_2 (VSIEDP, "scalar_insert_exp", CONST, xsiexpdp)
@@ -1951,6 +1959,8 @@ BU_P9V_OVERLOAD_1 (VSTDCN, "scalar_test_
BU_P9V_OVERLOAD_1 (VSTDCNDP, "scalar_test_neg_dp")
BU_P9V_OVERLOAD_1 (VSTDCNSP, "scalar_test_neg_sp")
+BU_P9V_OVERLOAD_1 (REVB, "revb")
+
/* ISA 3.0 vector scalar overloaded 2 argument functions. */
BU_P9V_OVERLOAD_2 (VSIEDP, "scalar_insert_exp")
===================================================================
@@ -3899,6 +3899,51 @@ (define_insn "*vinsert4b_di_internal"
[(set_attr "type" "vecperm")])
+;; Support for ISA 3.0 vector byte reverse
+
+;; Swap all bytes with in a vector
+(define_insn "p9_xxbrq_v1ti"
+ [(set (match_operand:V1TI 0 "vsx_register_operand" "=wa")
+ (bswap:V1TI (match_operand:V1TI 1 "vsx_register_operand" "wa")))]
+ "TARGET_P9_VECTOR"
+ "xxbrq %x0,%x1"
+ [(set_attr "type" "vecperm")])
+
+(define_expand "p9_xxbrq_v16qi"
+ [(use (match_operand:V16QI 0 "vsx_register_operand" "=wa"))
+ (use (match_operand:V16QI 1 "vsx_register_operand" "=wa"))]
+ "TARGET_P9_VECTOR"
+{
+ rtx op0 = gen_lowpart (V1TImode, operands[0]);
+ rtx op1 = gen_lowpart (V1TImode, operands[1]);
+ emit_insn (gen_p9_xxbrq_v1ti (op0, op1));
+ DONE;
+})
+
+;; Swap all bytes in each 64-bit element
+(define_insn "p9_xxbrd_<mode>"
+ [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
+ (bswap:VSX_D (match_operand:VSX_D 1 "vsx_register_operand" "wa")))]
+ "TARGET_P9_VECTOR"
+ "xxbrd %x0,%x1"
+ [(set_attr "type" "vecperm")])
+
+;; Swap all bytes in each 32-bit element
+(define_insn "p9_xxbrw_<mode>"
+ [(set (match_operand:VSX_W 0 "vsx_register_operand" "=wa")
+ (bswap:VSX_W (match_operand:VSX_W 1 "vsx_register_operand" "wa")))]
+ "TARGET_P9_VECTOR"
+ "xxbrw %x0,%x1"
+ [(set_attr "type" "vecperm")])
+
+;; Swap all bytes in each 16-bit element
+(define_insn "p9_xxbrh_v8hi"
+ [(set (match_operand:V8HI 0 "vsx_register_operand" "=wa")
+ (bswap:V8HI (match_operand:V8HI 1 "vsx_register_operand" "wa")))]
+ "TARGET_P9_VECTOR"
+ "xxbrh %x0,%x1"
+ [(set_attr "type" "vecperm")])
+
;; Operand numbers for the following peephole2
(define_constants
===================================================================
@@ -440,6 +440,8 @@
#define vec_xlx __builtin_vec_vextulx
#define vec_xrx __builtin_vec_vexturx
+
+#define vec_revb __builtin_vec_revb
#endif
/* Predicates.
===================================================================
@@ -18179,6 +18179,34 @@ If any of the enabled test conditions is
in the result vector is -1. Otherwise (all of the enabled test
conditions are false), the corresponding entry of the result vector is 0.
+If the ISA 3.0 instruction set additions (@option{-mcpu=power9})
+are available:
+@smallexample
+vector signed char vec_revb (vector signed char);
+vector unsigned char vec_revb (vector unsigned char);
+vector short vec_revb (vector short);
+vector unsigned short vec_revb (vector unsigned short);
+vector int vec_revb (vector int);
+vector unsigned int vec_revb (vector unsigned int);
+vector float vec_revb (vector float);
+vector long long vec_revb (vector long long);
+vector unsigned long long vec_revb (vector unsigned long long);
+vector double vec_revb (vector double);
+@end smallexample
+
+On 64-bit targets, if the ISA 3.0 additions (@option{-mcpu=power9})
+are available:
+@smallexample
+vector long vec_revb (vector long);
+vector unsigned long vec_revb (vector unsigned long);
+vector __int128_t vec_revb (vector __int128_t);
+vector __uint128_t vec_revb (vector __uint128_t);
+@end smallexample
+
+The @code{vec_revb} built-in function reverses the bytes on an element
+by element basis. A vector of @code{vector unsigned char} or
+@code{vector signed char} reverses the bytes in the whole word.
+
If the cryptographic instructions are enabled (@option{-mcrypto} or
@option{-mcpu=power8}), the following builtins are enabled.
===================================================================
@@ -0,0 +1,67 @@
+/* { dg-do compile { target { powerpc64le-*-* } } } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power9" } } */
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-mcpu=power9 -O3" } */
+
+#include <altivec.h>
+
+/* Verify P9 vec_revb builtin generates the XXBR{Q,D,W,H} instructions. */
+
+vector char
+rev_char (vector char a)
+{
+ return vec_revb (a); /* XXBRQ. */
+}
+
+vector signed char
+rev_schar (vector signed char a)
+{
+ return vec_revb (a); /* XXBRQ. */
+}
+
+vector unsigned char
+rev_uchar (vector unsigned char a)
+{
+ return vec_revb (a); /* XXBRQ. */
+}
+
+vector short
+rev_short (vector short a)
+{
+ return vec_revb (a); /* XXBRH. */
+}
+
+vector unsigned short
+rev_ushort (vector unsigned short a)
+{
+ return vec_revb (a); /* XXBRH. */
+}
+
+vector int
+rev_int (vector int a)
+{
+ return vec_revb (a); /* XXBRW. */
+}
+
+vector unsigned int
+rev_uint (vector unsigned int a)
+{
+ return vec_revb (a); /* XXBRW. */
+}
+
+vector float
+rev_float (vector float a)
+{
+ return vec_revb (a); /* XXBRW. */
+}
+
+vector double
+rev_double (vector double a)
+{
+ return vec_revb (a); /* XXBRD. */
+}
+
+/* { dg-final { scan-assembler-count "xxbrd" 1 } } */
+/* { dg-final { scan-assembler-count "xxbrh" 2 } } */
+/* { dg-final { scan-assembler-count "xxbrq" 3 } } */
+/* { dg-final { scan-assembler-count "xxbrw" 3 } } */
===================================================================
@@ -0,0 +1,36 @@
+/* { dg-do compile { target { powerpc64le-*-* && lp64 } } } */
+/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power9" } } */
+/* { dg-require-effective-target powerpc_p9vector_ok } */
+/* { dg-options "-mcpu=power9 -O3" } */
+
+#include <altivec.h>
+
+/* Verify P9 vec_revb builtin generates the XXBR{Q,D,W,H} instructions. This
+ test only tests the vector types that need a 64-bit environment. */
+
+vector long
+rev_long (vector long a)
+{
+ return vec_revb (a); /* XXBRD. */
+}
+
+vector unsigned long
+rev_ulong (vector unsigned long a)
+{
+ return vec_revb (a); /* XXBRD. */
+}
+
+vector __int128_t
+rev_int128 (vector __int128_t a)
+{
+ return vec_revb (a); /* XXBRQ. */
+}
+
+vector __uint128_t
+rev_uint128 (vector __uint128_t a)
+{
+ return vec_revb (a); /* XXBRQ. */
+}
+
+/* { dg-final { scan-assembler-count "xxbrd" 2 } } */
+/* { dg-final { scan-assembler-count "xxbrq" 2 } } */