1;; Cryptographic instructions added in ISA 2.07
2;; Copyright (C) 2012-2022 Free Software Foundation, Inc.
3;; Contributed by Michael Meissner (meissner@linux.vnet.ibm.com)
4
5;; This file is part of GCC.
6
7;; GCC is free software; you can redistribute it and/or modify it
8;; under the terms of the GNU General Public License as published
9;; by the Free Software Foundation; either version 3, or (at your
10;; option) any later version.
11
12;; GCC is distributed in the hope that it will be useful, but WITHOUT
13;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15;; License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GCC; see the file COPYING3.  If not see
19;; <http://www.gnu.org/licenses/>.
20
21;; NOTE: Although this file contains all the instructions from
22;; section 5.11 of ISA 2.07, only those in sections 5.11.1 and
23;; 5.11.2 are in Category:Vector.Crypto.  Those are the only
24;; ones controlled by -m[no-]crypto.
25
26;; FIXME: The builtin names for the instructions in this file
27;; are likely to be deprecated in favor of other names to be
28;; agreed upon with the XL compilers and LLVM.
29
30(define_c_enum "unspec"
31  [UNSPEC_VCIPHER
32   UNSPEC_VNCIPHER
33   UNSPEC_VCIPHERLAST
34   UNSPEC_VNCIPHERLAST
35   UNSPEC_VSBOX
36   UNSPEC_VSHASIGMA
37   UNSPEC_VPERMXOR
38   UNSPEC_VPMSUM])
39
40;; Iterator for VPMSUM/VPERMXOR
41(define_mode_iterator CR_mode [V16QI V8HI V4SI V2DI])
42
43(define_mode_attr CR_char [(V16QI "b")
44			   (V8HI  "h")
45			   (V4SI  "w")
46			   (V2DI  "d")])
47
48;; Iterator for VSHASIGMAD/VSHASIGMAW
49(define_mode_iterator CR_hash [V4SI V2DI])
50
51;; Iterator for VSBOX/VCIPHER/VNCIPHER/VCIPHERLAST/VNCIPHERLAST
52(define_mode_iterator CR_vqdi [V16QI V2DI])
53
54;; Iterator for the other crypto functions
55(define_int_iterator CR_code   [UNSPEC_VCIPHER
56				UNSPEC_VNCIPHER
57				UNSPEC_VCIPHERLAST
58				UNSPEC_VNCIPHERLAST])
59
60(define_int_attr CR_insn [(UNSPEC_VCIPHER      "vcipher")
61			  (UNSPEC_VNCIPHER     "vncipher")
62			  (UNSPEC_VCIPHERLAST  "vcipherlast")
63			  (UNSPEC_VNCIPHERLAST "vncipherlast")])
64
65;; 2 operand crypto instructions
66(define_insn "crypto_<CR_insn>_<mode>"
67  [(set (match_operand:CR_vqdi 0 "register_operand" "=v")
68	(unspec:CR_vqdi [(match_operand:CR_vqdi 1 "register_operand" "v")
69		      (match_operand:CR_vqdi 2 "register_operand" "v")]
70		     CR_code))]
71  "TARGET_CRYPTO"
72  "<CR_insn> %0,%1,%2"
73  [(set_attr "type" "crypto")])
74
75(define_insn "crypto_vpmsum<CR_char>"
76  [(set (match_operand:CR_mode 0 "register_operand" "=v")
77	(unspec:CR_mode [(match_operand:CR_mode 1 "register_operand" "v")
78			 (match_operand:CR_mode 2 "register_operand" "v")]
79			UNSPEC_VPMSUM))]
80  "TARGET_P8_VECTOR"
81  "vpmsum<CR_char> %0,%1,%2"
82  [(set_attr "type" "crypto")])
83
84;; 3 operand crypto instructions
85(define_insn "crypto_vpermxor_<mode>"
86  [(set (match_operand:CR_mode 0 "register_operand" "=v")
87	(unspec:CR_mode [(match_operand:CR_mode 1 "register_operand" "v")
88			 (match_operand:CR_mode 2 "register_operand" "v")
89			 (match_operand:CR_mode 3 "register_operand" "v")]
90			UNSPEC_VPERMXOR))]
91  "TARGET_P8_VECTOR"
92  "vpermxor %0,%1,%2,%3"
93  [(set_attr "type" "vecperm")])
94
95;; 1 operand crypto instruction
96(define_insn "crypto_vsbox_<mode>"
97  [(set (match_operand:CR_vqdi 0 "register_operand" "=v")
98	(unspec:CR_vqdi [(match_operand:CR_vqdi 1 "register_operand" "v")]
99		     UNSPEC_VSBOX))]
100  "TARGET_CRYPTO"
101  "vsbox %0,%1"
102  [(set_attr "type" "crypto")])
103
104;; Hash crypto instructions
105(define_insn "crypto_vshasigma<CR_char>"
106  [(set (match_operand:CR_hash 0 "register_operand" "=v")
107	(unspec:CR_hash [(match_operand:CR_hash 1 "register_operand" "v")
108			 (match_operand:SI 2 "const_0_to_1_operand" "n")
109			 (match_operand:SI 3 "const_0_to_15_operand" "n")]
110			UNSPEC_VSHASIGMA))]
111  "TARGET_CRYPTO"
112  "vshasigma<CR_char> %0,%1,%2,%3"
113  [(set_attr "type" "vecsimple")])
114