rs6000: Add support for the vec_sbox_be, vec_cipher_be etc. builtins.
authorXiong Hu Luo <luoxhu@linux.vnet.ibm.com>
Wed, 13 Feb 2019 06:31:01 +0000 (06:31 +0000)
committerXiong Hu Luo <luoxhu@gcc.gnu.org>
Wed, 13 Feb 2019 06:31:01 +0000 (06:31 +0000)
The 5 new builtins vec_sbox_be, vec_cipher_be, vec_cipherlast_be, vec_ncipher_be
and vec_ncipherlast_be only support vector unsigned char type parameters.
Add new instruction crypto_vsbox_<mode> and crypto_<CR_insn>_<mode> to handle
them accordingly, where the new mode CR_vqdi can be expanded to vector unsigned
long long for none _be postfix builtins or vector unsigned char for _be postfix
builtins.

gcc/ChangeLog

2019-02-13  Xiong Hu Luo  <luoxhu@linux.vnet.ibm.com>

* config/rs6000/altivec.h (vec_sbox_be, vec_cipher_be,
vec_cipherlast_be, vec_ncipher_be, vec_ncipherlast_be): New #defines.
* config/rs6000/crypto.md (CR_vqdi): New define_mode_iterator.
(crypto_vsbox_<mode>, crypto_<CR_insn>_<mode>): New define_insns.
* config/rs6000/rs6000-builtin.def (VSBOX_BE): New BU_CRYPTO_1.
(VCIPHER_BE, VCIPHERLAST_BE, VNCIPHER_BE, VNCIPHERLAST_BE):
New BU_CRYPTO_2.
* config/rs6000/rs6000.c (builtin_function_type)
<CRYPTO_BUILTIN_VSBOX_BE, CRYPTO_BUILTIN_VCIPHER_BE,
CRYPTO_BUILTIN_VCIPHERLAST_BE, CRYPTO_BUILTIN_VNCIPHER_BE,
CRYPTO_BUILTIN_VNCIPHERLAST_BE>: New switch options.
* doc/extend.texi (vec_sbox_be, vec_cipher_be, vec_cipherlast_be,
vec_ncipher_be, vec_ncipherlast_be): New builtin functions.

gcc/testsuite/ChangeLog

2019-02-13  Xiong Hu Luo  <luoxhu@linux.vnet.ibm.com>

* gcc.target/powerpc/crypto-builtin-1.c
(crypto1_be, crypto2_be, crypto3_be, crypto4_be, crypto5_be):
New testcases.

From-SVN: r268834

gcc/ChangeLog
gcc/config/rs6000/altivec.h
gcc/config/rs6000/crypto.md
gcc/config/rs6000/rs6000-builtin.def
gcc/config/rs6000/rs6000.c
gcc/doc/extend.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/powerpc/crypto-builtin-1.c

index 5225f636cdd9fd19ea8745f0b5b0a3a97f26fc7c..c866e2d6dc93a2adea766dfffd1aa1b979840e17 100644 (file)
@@ -1,3 +1,19 @@
+2019-02-13  Xiong Hu Luo  <luoxhu@linux.vnet.ibm.com>
+
+       * config/rs6000/altivec.h (vec_sbox_be, vec_cipher_be,
+       vec_cipherlast_be, vec_ncipher_be, vec_ncipherlast_be): New #defines.
+       * config/rs6000/crypto.md (CR_vqdi): New define_mode_iterator.
+       (crypto_vsbox_<mode>, crypto_<CR_insn>_<mode>): New define_insns.
+       * config/rs6000/rs6000-builtin.def (VSBOX_BE): New BU_CRYPTO_1.
+       (VCIPHER_BE, VCIPHERLAST_BE, VNCIPHER_BE, VNCIPHERLAST_BE):
+       New BU_CRYPTO_2.
+       * config/rs6000/rs6000.c (builtin_function_type)
+       <CRYPTO_BUILTIN_VSBOX_BE, CRYPTO_BUILTIN_VCIPHER_BE,
+       CRYPTO_BUILTIN_VCIPHERLAST_BE, CRYPTO_BUILTIN_VNCIPHER_BE,
+       CRYPTO_BUILTIN_VNCIPHERLAST_BE>: New switch options.
+       * doc/extend.texi (vec_sbox_be, vec_cipher_be, vec_cipherlast_be,
+       vec_ncipher_be, vec_ncipherlast_be): New builtin functions.
+
 2019-02-12  Pat Haugen  <pthaugen@us.ibm.com>
 
        * doc/invoke.texi (RS/6000 and PowerPC Options): Remove duplicate
index bf29d4694b2c23a1eebe0439e95daaf0e2e15982..d66ae7ca2c73ea4a6ef44914828661d362e31464 100644 (file)
 #define vec_vupkhsw __builtin_vec_vupkhsw
 #define vec_vupklsw __builtin_vec_vupklsw
 #define vec_revb __builtin_vec_revb
+#define vec_sbox_be __builtin_crypto_vsbox_be
+#define vec_cipher_be __builtin_crypto_vcipher_be
+#define vec_cipherlast_be __builtin_crypto_vcipherlast_be
+#define vec_ncipher_be __builtin_crypto_vncipher_be
+#define vec_ncipherlast_be __builtin_crypto_vncipherlast_be
 #endif
 
 #ifdef __POWER9_VECTOR__
index 2ee3e3ae9860d148ced4fa7f8a41db3d95ec3dae..b9917b08d984574424398c2be3ee71e685260e62 100644 (file)
@@ -48,6 +48,9 @@
 ;; Iterator for VSHASIGMAD/VSHASIGMAW
 (define_mode_iterator CR_hash [V4SI V2DI])
 
+;; Iterator for VSBOX/VCIPHER/VNCIPHER/VCIPHERLAST/VNCIPHERLAST
+(define_mode_iterator CR_vqdi [V16QI V2DI])
+
 ;; Iterator for the other crypto functions
 (define_int_iterator CR_code   [UNSPEC_VCIPHER
                                UNSPEC_VNCIPHER
                          (UNSPEC_VNCIPHERLAST "vncipherlast")])
 
 ;; 2 operand crypto instructions
-(define_insn "crypto_<CR_insn>"
-  [(set (match_operand:V2DI 0 "register_operand" "=v")
-       (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "v")
-                     (match_operand:V2DI 2 "register_operand" "v")]
+(define_insn "crypto_<CR_insn>_<mode>"
+  [(set (match_operand:CR_vqdi 0 "register_operand" "=v")
+       (unspec:CR_vqdi [(match_operand:CR_vqdi 1 "register_operand" "v")
+                     (match_operand:CR_vqdi 2 "register_operand" "v")]
                     CR_code))]
   "TARGET_CRYPTO"
   "<CR_insn> %0,%1,%2"
@@ -90,9 +93,9 @@
   [(set_attr "type" "vecperm")])
 
 ;; 1 operand crypto instruction
-(define_insn "crypto_vsbox"
-  [(set (match_operand:V2DI 0 "register_operand" "=v")
-       (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "v")]
+(define_insn "crypto_vsbox_<mode>"
+  [(set (match_operand:CR_vqdi 0 "register_operand" "=v")
+       (unspec:CR_vqdi [(match_operand:CR_vqdi 1 "register_operand" "v")]
                     UNSPEC_VSBOX))]
   "TARGET_CRYPTO"
   "vsbox %0,%1"
index 60b3bd0db931917d33fd162bb26580562aee4155..0a2bdb79e15c638b4cd9cef3c9632eb0f2a76cf3 100644 (file)
@@ -2418,13 +2418,22 @@ BU_P9_OVERLOAD_2 (CMPRB2,       "byte_in_either_range")
 BU_P9_OVERLOAD_2 (CMPEQB,      "byte_in_set")
 \f
 /* 1 argument crypto functions.  */
-BU_CRYPTO_1 (VSBOX,            "vsbox",          CONST, crypto_vsbox)
+BU_CRYPTO_1 (VSBOX,            "vsbox",          CONST, crypto_vsbox_v2di)
+BU_CRYPTO_1 (VSBOX_BE,         "vsbox_be",       CONST, crypto_vsbox_v16qi)
 
 /* 2 argument crypto functions.  */
-BU_CRYPTO_2 (VCIPHER,          "vcipher",        CONST, crypto_vcipher)
-BU_CRYPTO_2 (VCIPHERLAST,      "vcipherlast",    CONST, crypto_vcipherlast)
-BU_CRYPTO_2 (VNCIPHER,         "vncipher",       CONST, crypto_vncipher)
-BU_CRYPTO_2 (VNCIPHERLAST,     "vncipherlast",   CONST, crypto_vncipherlast)
+BU_CRYPTO_2 (VCIPHER,          "vcipher",        CONST, crypto_vcipher_v2di)
+BU_CRYPTO_2 (VCIPHER_BE,       "vcipher_be",     CONST, crypto_vcipher_v16qi)
+BU_CRYPTO_2 (VCIPHERLAST,      "vcipherlast",
+            CONST, crypto_vcipherlast_v2di)
+BU_CRYPTO_2 (VCIPHERLAST_BE,   "vcipherlast_be",
+            CONST, crypto_vcipherlast_v16qi)
+BU_CRYPTO_2 (VNCIPHER,         "vncipher",       CONST, crypto_vncipher_v2di)
+BU_CRYPTO_2 (VNCIPHER_BE,      "vncipher_be",    CONST, crypto_vncipher_v16qi)
+BU_CRYPTO_2 (VNCIPHERLAST,     "vncipherlast",
+            CONST, crypto_vncipherlast_v2di)
+BU_CRYPTO_2 (VNCIPHERLAST_BE,  "vncipherlast_be",
+            CONST, crypto_vncipherlast_v16qi)
 BU_CRYPTO_2A (VPMSUMB,         "vpmsumb",        CONST, crypto_vpmsumb)
 BU_CRYPTO_2A (VPMSUMH,         "vpmsumh",        CONST, crypto_vpmsumh)
 BU_CRYPTO_2A (VPMSUMW,         "vpmsumw",        CONST, crypto_vpmsumw)
index ff51e48eae46bac1a4ef738d1ba0c7025936f13a..aea7925d4cfab670e978e79673a19c7ce1880d7b 100644 (file)
@@ -17687,6 +17687,7 @@ builtin_function_type (machine_mode mode_ret, machine_mode mode_arg0,
     {
     /* unsigned 1 argument functions.  */
     case CRYPTO_BUILTIN_VSBOX:
+    case CRYPTO_BUILTIN_VSBOX_BE:
     case P8V_BUILTIN_VGBBD:
     case MISC_BUILTIN_CDTBCD:
     case MISC_BUILTIN_CBCDTD:
@@ -17702,9 +17703,13 @@ builtin_function_type (machine_mode mode_ret, machine_mode mode_arg0,
     case ALTIVEC_BUILTIN_VMULOUH:
     case P8V_BUILTIN_VMULOUW:
     case CRYPTO_BUILTIN_VCIPHER:
+    case CRYPTO_BUILTIN_VCIPHER_BE:
     case CRYPTO_BUILTIN_VCIPHERLAST:
+    case CRYPTO_BUILTIN_VCIPHERLAST_BE:
     case CRYPTO_BUILTIN_VNCIPHER:
+    case CRYPTO_BUILTIN_VNCIPHER_BE:
     case CRYPTO_BUILTIN_VNCIPHERLAST:
+    case CRYPTO_BUILTIN_VNCIPHERLAST_BE:
     case CRYPTO_BUILTIN_VPMSUMB:
     case CRYPTO_BUILTIN_VPMSUMH:
     case CRYPTO_BUILTIN_VPMSUMW:
index 815788c40abe1c142331bc7dc545000c09ca0365..e7af5a6aa53a88924c6a157973d41ae6aa68247f 100644 (file)
@@ -20136,19 +20136,32 @@ If the cryptographic instructions are enabled (@option{-mcrypto} or
 @smallexample
 vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long);
 
+vector unsigned char vec_sbox_be (vector unsigned char);
+
 vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long,
                                                     vector unsigned long long);
 
+vector unsigned char vec_cipher_be (vector unsigned char, vector unsigned char);
+
 vector unsigned long long __builtin_crypto_vcipherlast
                                      (vector unsigned long long,
                                       vector unsigned long long);
 
+vector unsigned char vec_cipherlast_be (vector unsigned char,
+                                        vector unsigned char);
+
 vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long,
                                                      vector unsigned long long);
 
+vector unsigned char vec_ncipher_be (vector unsigned char,
+                                     vector unsigned char);
+
 vector unsigned long long __builtin_crypto_vncipherlast (vector unsigned long long,
                                                          vector unsigned long long);
 
+vector unsigned char vec_ncipherlast_be (vector unsigned char,
+                                         vector unsigned char);
+
 vector unsigned char __builtin_crypto_vpermxor (vector unsigned char,
                                                 vector unsigned char,
                                                 vector unsigned char);
index d8549f0fb3ef286336916fa58e6ae3bafd6660e3..43d84f68b49ed3084d2f3663feb9a6f14be600f6 100644 (file)
@@ -1,3 +1,9 @@
+2019-01-23  Xiong Hu Luo  <luoxhu@linux.vnet.ibm.com>
+
+       * gcc.target/powerpc/crypto-builtin-1.c
+       (crypto1_be, crypto2_be, crypto3_be, crypto4_be, crypto5_be):
+       New testcases.
+
 2019-02-12  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/89229
index 234041d5c358da7cd05035417c4a59c9177ab444..38245ffc3702cc089bfbd484d87ec4710034c5a4 100644 (file)
@@ -4,37 +4,63 @@
 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
 /* { dg-options "-mcpu=power8 -O2 -ftree-vectorize -fvect-cost-model=dynamic -fno-unroll-loops -fno-unroll-all-loops" } */
 
+#include <altivec.h>
 typedef vector unsigned long long      crypto_t;
 typedef vector unsigned long long      v2di_t;
 typedef vector unsigned int            v4si_t;
 typedef vector unsigned short          v8hi_t;
 typedef vector unsigned char           v16qi_t;
 
-crypto_t crpyto1 (crypto_t a)
+crypto_t crypto1 (crypto_t a)
 {
   return __builtin_crypto_vsbox (a);
 }
 
+v16qi_t crypto1_be (v16qi_t a)
+{
+  return vec_sbox_be (a);
+}
+
 crypto_t crypto2 (crypto_t a, crypto_t b)
 {
   return __builtin_crypto_vcipher (a, b);
 }
 
+v16qi_t crypto2_be (v16qi_t a, v16qi_t b)
+{
+  return vec_cipher_be (a, b);
+}
+
 crypto_t crypto3 (crypto_t a, crypto_t b)
 {
   return __builtin_crypto_vcipherlast (a, b);
 }
 
+v16qi_t crypto3_be (v16qi_t a, v16qi_t b)
+{
+  return vec_cipherlast_be (a, b);
+}
+
 crypto_t crypto4 (crypto_t a, crypto_t b)
 {
   return __builtin_crypto_vncipher (a, b);
 }
 
+v16qi_t crypto4_be (v16qi_t a, v16qi_t b)
+{
+  return vec_ncipher_be (a, b);
+}
+
 crypto_t crypto5 (crypto_t a, crypto_t b)
 {
   return __builtin_crypto_vncipherlast (a, b);
 }
 
+v16qi_t crypto5_be (v16qi_t a, v16qi_t b)
+{
+  return vec_ncipherlast_be (a, b);
+}
+
 v16qi_t crypto6a (v16qi_t a, v16qi_t b, v16qi_t c)
 {
   return __builtin_crypto_vpermxor (a, b, c);
@@ -117,15 +143,15 @@ v4si_t crypto8d (v4si_t a)
 
 /* Note space is used after the instruction so that vcipherlast does not match
    vcipher.  */
-/* { dg-final { scan-assembler-times "vcipher "      1 } } */
-/* { dg-final { scan-assembler-times "vcipherlast "  1 } } */
-/* { dg-final { scan-assembler-times "vncipher "     1 } } */
-/* { dg-final { scan-assembler-times "vncipherlast " 1 } } */
+/* { dg-final { scan-assembler-times "vcipher "      2 } } */
+/* { dg-final { scan-assembler-times "vcipherlast "  2 } } */
+/* { dg-final { scan-assembler-times "vncipher "     2 } } */
+/* { dg-final { scan-assembler-times "vncipherlast " 2 } } */
 /* { dg-final { scan-assembler-times "vpermxor "     4 } } */
 /* { dg-final { scan-assembler-times "vpmsumb "      2 } } */
 /* { dg-final { scan-assembler-times "vpmsumd "      2 } } */
 /* { dg-final { scan-assembler-times "vpmsumh "      2 } } */
 /* { dg-final { scan-assembler-times "vpmsumw "      2 } } */
-/* { dg-final { scan-assembler-times "vsbox "        1 } } */
+/* { dg-final { scan-assembler-times "vsbox "        2 } } */
 /* { dg-final { scan-assembler-times "vshasigmad "   2 } } */
 /* { dg-final { scan-assembler-times "vshasigmaw "   2 } } */