blob: a6ab49aa85a7b720f2a5d184e4a5075a0fe139c9 [file] [log] [blame]
Scott Michel8b6b4202007-12-04 22:35:58 +00001//==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michel8b6b4202007-12-04 22:35:58 +00007//
8//===----------------------------------------------------------------------===//
9// Cell SPU Instructions:
10//===----------------------------------------------------------------------===//
11
12//===----------------------------------------------------------------------===//
13// TODO Items (not urgent today, but would be nice, low priority)
14//
15// ANDBI, ORBI: SPU constructs a 4-byte constant for these instructions by
16// concatenating the byte argument b as "bbbb". Could recognize this bit pattern
17// in 16-bit and 32-bit constants and reduce instruction count.
18//===----------------------------------------------------------------------===//
19
20//===----------------------------------------------------------------------===//
21// Pseudo instructions:
22//===----------------------------------------------------------------------===//
23
24let hasCtrlDep = 1, Defs = [R1], Uses = [R1] in {
Scott Michelbc5fbc12008-04-30 00:30:08 +000025 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000026 "${:comment} ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000027 [(callseq_start timm:$amt)]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +000028 def ADJCALLSTACKUP : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000029 "${:comment} ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000030 [(callseq_end timm:$amt)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +000031}
32
33//===----------------------------------------------------------------------===//
34// DWARF debugging Pseudo Instructions
35//===----------------------------------------------------------------------===//
36
37def DWARF_LOC : Pseudo<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
38 "${:comment} .loc $file, $line, $col",
39 [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
40 (i32 imm:$file))]>;
41
42//===----------------------------------------------------------------------===//
43// Loads:
44// NB: The ordering is actually important, since the instruction selection
45// will try each of the instructions in sequence, i.e., the D-form first with
46// the 10-bit displacement, then the A-form with the 16 bit displacement, and
47// finally the X-form with the register-register.
48//===----------------------------------------------------------------------===//
49
Chris Lattner1a1932c2008-01-06 23:38:27 +000050let isSimpleLoad = 1 in {
Scott Michelf9f42e62008-01-29 02:16:57 +000051 class LoadDFormVec<ValueType vectype>
52 : RI10Form<0b00101100, (outs VECREG:$rT), (ins memri10:$src),
53 "lqd\t$rT, $src",
54 LoadStore,
55 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
56 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000057
Scott Michelf9f42e62008-01-29 02:16:57 +000058 class LoadDForm<RegisterClass rclass>
59 : RI10Form<0b00101100, (outs rclass:$rT), (ins memri10:$src),
60 "lqd\t$rT, $src",
61 LoadStore,
62 [(set rclass:$rT, (load dform_addr:$src))]>
63 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000064
Scott Michelf9f42e62008-01-29 02:16:57 +000065 multiclass LoadDForms
66 {
67 def v16i8: LoadDFormVec<v16i8>;
68 def v8i16: LoadDFormVec<v8i16>;
69 def v4i32: LoadDFormVec<v4i32>;
70 def v2i64: LoadDFormVec<v2i64>;
71 def v4f32: LoadDFormVec<v4f32>;
72 def v2f64: LoadDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000073
Scott Michelf9f42e62008-01-29 02:16:57 +000074 def r128: LoadDForm<GPRC>;
75 def r64: LoadDForm<R64C>;
76 def r32: LoadDForm<R32C>;
77 def f32: LoadDForm<R32FP>;
78 def f64: LoadDForm<R64FP>;
79 def r16: LoadDForm<R16C>;
80 def r8: LoadDForm<R8C>;
81 }
Scott Michel8b6b4202007-12-04 22:35:58 +000082
Scott Michelf9f42e62008-01-29 02:16:57 +000083 class LoadAFormVec<ValueType vectype>
84 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
85 "lqa\t$rT, $src",
86 LoadStore,
87 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
88 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000089
Scott Michelf9f42e62008-01-29 02:16:57 +000090 class LoadAForm<RegisterClass rclass>
91 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
92 "lqa\t$rT, $src",
93 LoadStore,
94 [(set rclass:$rT, (load aform_addr:$src))]>
95 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000096
Scott Michelf9f42e62008-01-29 02:16:57 +000097 multiclass LoadAForms
98 {
99 def v16i8: LoadAFormVec<v16i8>;
100 def v8i16: LoadAFormVec<v8i16>;
101 def v4i32: LoadAFormVec<v4i32>;
102 def v2i64: LoadAFormVec<v2i64>;
103 def v4f32: LoadAFormVec<v4f32>;
104 def v2f64: LoadAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000105
Scott Michelf9f42e62008-01-29 02:16:57 +0000106 def r128: LoadAForm<GPRC>;
107 def r64: LoadAForm<R64C>;
108 def r32: LoadAForm<R32C>;
109 def f32: LoadAForm<R32FP>;
110 def f64: LoadAForm<R64FP>;
111 def r16: LoadAForm<R16C>;
112 def r8: LoadAForm<R8C>;
113 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000114
Scott Michelf9f42e62008-01-29 02:16:57 +0000115 class LoadXFormVec<ValueType vectype>
116 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
117 "lqx\t$rT, $src",
118 LoadStore,
119 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
120 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000121
Scott Michelf9f42e62008-01-29 02:16:57 +0000122 class LoadXForm<RegisterClass rclass>
123 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
124 "lqx\t$rT, $src",
125 LoadStore,
126 [(set rclass:$rT, (load xform_addr:$src))]>
127 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000128
Scott Michelf9f42e62008-01-29 02:16:57 +0000129 multiclass LoadXForms
130 {
131 def v16i8: LoadXFormVec<v16i8>;
132 def v8i16: LoadXFormVec<v8i16>;
133 def v4i32: LoadXFormVec<v4i32>;
134 def v2i64: LoadXFormVec<v2i64>;
135 def v4f32: LoadXFormVec<v4f32>;
136 def v2f64: LoadXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000137
Scott Michelf9f42e62008-01-29 02:16:57 +0000138 def r128: LoadXForm<GPRC>;
139 def r64: LoadXForm<R64C>;
140 def r32: LoadXForm<R32C>;
141 def f32: LoadXForm<R32FP>;
142 def f64: LoadXForm<R64FP>;
143 def r16: LoadXForm<R16C>;
144 def r8: LoadXForm<R8C>;
145 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000146
Scott Michelf9f42e62008-01-29 02:16:57 +0000147 defm LQA : LoadAForms;
148 defm LQD : LoadDForms;
149 defm LQX : LoadXForms;
Scott Michel438be252007-12-17 22:32:34 +0000150
Scott Michel8b6b4202007-12-04 22:35:58 +0000151/* Load quadword, PC relative: Not much use at this point in time.
Scott Michelf9f42e62008-01-29 02:16:57 +0000152 Might be of use later for relocatable code. It's effectively the
153 same as LQA, but uses PC-relative addressing.
Scott Michel8b6b4202007-12-04 22:35:58 +0000154 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
155 "lqr\t$rT, $disp", LoadStore,
156 [(set VECREG:$rT, (load iaddr:$disp))]>;
157 */
Scott Michel8b6b4202007-12-04 22:35:58 +0000158}
159
160//===----------------------------------------------------------------------===//
161// Stores:
162//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +0000163class StoreDFormVec<ValueType vectype>
164 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, memri10:$src),
165 "stqd\t$rT, $src",
166 LoadStore,
167 [(store (vectype VECREG:$rT), dform_addr:$src)]>
168{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000169
Scott Michelf9f42e62008-01-29 02:16:57 +0000170class StoreDForm<RegisterClass rclass>
171 : RI10Form<0b00100100, (outs), (ins rclass:$rT, memri10:$src),
172 "stqd\t$rT, $src",
173 LoadStore,
174 [(store rclass:$rT, dform_addr:$src)]>
175{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000176
Scott Michelf9f42e62008-01-29 02:16:57 +0000177multiclass StoreDForms
178{
179 def v16i8: StoreDFormVec<v16i8>;
180 def v8i16: StoreDFormVec<v8i16>;
181 def v4i32: StoreDFormVec<v4i32>;
182 def v2i64: StoreDFormVec<v2i64>;
183 def v4f32: StoreDFormVec<v4f32>;
184 def v2f64: StoreDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000185
Scott Michelf9f42e62008-01-29 02:16:57 +0000186 def r128: StoreDForm<GPRC>;
187 def r64: StoreDForm<R64C>;
188 def r32: StoreDForm<R32C>;
189 def f32: StoreDForm<R32FP>;
190 def f64: StoreDForm<R64FP>;
191 def r16: StoreDForm<R16C>;
192 def r8: StoreDForm<R8C>;
193}
Scott Michel8b6b4202007-12-04 22:35:58 +0000194
Scott Michelf9f42e62008-01-29 02:16:57 +0000195class StoreAFormVec<ValueType vectype>
196 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000197 "stqa\t$rT, $src",
198 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000199 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000200
Scott Michelf9f42e62008-01-29 02:16:57 +0000201class StoreAForm<RegisterClass rclass>
202 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000203 "stqa\t$rT, $src",
204 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000205 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000206
Scott Michelf9f42e62008-01-29 02:16:57 +0000207multiclass StoreAForms
208{
209 def v16i8: StoreAFormVec<v16i8>;
210 def v8i16: StoreAFormVec<v8i16>;
211 def v4i32: StoreAFormVec<v4i32>;
212 def v2i64: StoreAFormVec<v2i64>;
213 def v4f32: StoreAFormVec<v4f32>;
214 def v2f64: StoreAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000215
Scott Michelf9f42e62008-01-29 02:16:57 +0000216 def r128: StoreAForm<GPRC>;
217 def r64: StoreAForm<R64C>;
218 def r32: StoreAForm<R32C>;
219 def f32: StoreAForm<R32FP>;
220 def f64: StoreAForm<R64FP>;
221 def r16: StoreAForm<R16C>;
222 def r8: StoreAForm<R8C>;
223}
Scott Michel8b6b4202007-12-04 22:35:58 +0000224
Scott Michelf9f42e62008-01-29 02:16:57 +0000225class StoreXFormVec<ValueType vectype>
226 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000227 "stqx\t$rT, $src",
228 LoadStore,
229 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000230{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000231
Scott Michelf9f42e62008-01-29 02:16:57 +0000232class StoreXForm<RegisterClass rclass>
233 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000234 "stqx\t$rT, $src",
235 LoadStore,
236 [(store rclass:$rT, xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000237{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000238
Scott Michelf9f42e62008-01-29 02:16:57 +0000239multiclass StoreXForms
240{
241 def v16i8: StoreXFormVec<v16i8>;
242 def v8i16: StoreXFormVec<v8i16>;
243 def v4i32: StoreXFormVec<v4i32>;
244 def v2i64: StoreXFormVec<v2i64>;
245 def v4f32: StoreXFormVec<v4f32>;
246 def v2f64: StoreXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000247
Scott Michelf9f42e62008-01-29 02:16:57 +0000248 def r128: StoreXForm<GPRC>;
249 def r64: StoreXForm<R64C>;
250 def r32: StoreXForm<R32C>;
251 def f32: StoreXForm<R32FP>;
252 def f64: StoreXForm<R64FP>;
253 def r16: StoreXForm<R16C>;
254 def r8: StoreXForm<R8C>;
255}
Scott Michel8b6b4202007-12-04 22:35:58 +0000256
Scott Michelf9f42e62008-01-29 02:16:57 +0000257defm STQD : StoreDForms;
258defm STQA : StoreAForms;
259defm STQX : StoreXForms;
Scott Michel8b6b4202007-12-04 22:35:58 +0000260
261/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michelf9f42e62008-01-29 02:16:57 +0000262 be useful for relocatable code.
Chris Lattneref8d6082008-01-06 06:44:58 +0000263def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
264 "stqr\t$rT, $disp", LoadStore,
265 [(store VECREG:$rT, iaddr:$disp)]>;
266*/
Scott Michel8b6b4202007-12-04 22:35:58 +0000267
268//===----------------------------------------------------------------------===//
269// Generate Controls for Insertion:
270//===----------------------------------------------------------------------===//
271
272def CBD :
273 RI7Form<0b10101111100, (outs VECREG:$rT), (ins memri7:$src),
274 "cbd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000275 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000276
277def CBX : RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
278 "cbx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000279 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000280
281def CHD : RI7Form<0b10101111100, (outs VECREG:$rT), (ins memri7:$src),
282 "chd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000283 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000284
285def CHX : RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
286 "chx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000287 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000288
289def CWD : RI7Form<0b01101111100, (outs VECREG:$rT), (ins memri7:$src),
290 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000291 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000292
Scott Michelbc5fbc12008-04-30 00:30:08 +0000293def CWDf32 : RI7Form<0b01101111100, (outs VECREG:$rT), (ins memri7:$src),
294 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000295 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000296
Scott Michel8b6b4202007-12-04 22:35:58 +0000297def CWX : RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
298 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000299 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000300
Scott Michelbc5fbc12008-04-30 00:30:08 +0000301def CWXf32 : RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
302 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000303 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000304
Scott Michel8b6b4202007-12-04 22:35:58 +0000305def CDD : RI7Form<0b11101111100, (outs VECREG:$rT), (ins memri7:$src),
306 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000307 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000308
Scott Michelbc5fbc12008-04-30 00:30:08 +0000309def CDDf64 : RI7Form<0b11101111100, (outs VECREG:$rT), (ins memri7:$src),
310 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000311 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000312
Scott Michel8b6b4202007-12-04 22:35:58 +0000313def CDX : RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
314 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000315 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000316
Scott Michelbc5fbc12008-04-30 00:30:08 +0000317def CDXf64 : RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
318 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000319 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000320
Scott Michel8b6b4202007-12-04 22:35:58 +0000321//===----------------------------------------------------------------------===//
322// Constant formation:
323//===----------------------------------------------------------------------===//
324
325def ILHv8i16:
326 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
327 "ilh\t$rT, $val", ImmLoad,
328 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
329
330def ILHr16:
331 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
332 "ilh\t$rT, $val", ImmLoad,
333 [(set R16C:$rT, immSExt16:$val)]>;
334
Scott Michel438be252007-12-17 22:32:34 +0000335// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
336// the right constant")
337def ILHr8:
338 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
339 "ilh\t$rT, $val", ImmLoad,
340 [(set R8C:$rT, immSExt8:$val)]>;
341
Scott Michel8b6b4202007-12-04 22:35:58 +0000342// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000343
Scott Michel6baba072008-03-05 23:02:02 +0000344class ILInst<dag OOL, dag IOL, list<dag> pattern>:
345 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
346 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000347
Scott Michel6baba072008-03-05 23:02:02 +0000348class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
349 ILInst<(outs VECREG:$rT), (ins immtype:$val),
350 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000351
Scott Michel6baba072008-03-05 23:02:02 +0000352class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
353 ILInst<(outs rclass:$rT), (ins immtype:$val),
354 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000355
Scott Michel6baba072008-03-05 23:02:02 +0000356multiclass ImmediateLoad
357{
358 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
359 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000360
Scott Michel6baba072008-03-05 23:02:02 +0000361 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000362
Scott Michel6baba072008-03-05 23:02:02 +0000363 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
364 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
365 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
366 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
367}
Scott Michel8b6b4202007-12-04 22:35:58 +0000368
Scott Michel6baba072008-03-05 23:02:02 +0000369defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000370
Scott Michel6baba072008-03-05 23:02:02 +0000371class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
372 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
373 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000374
Scott Michel6baba072008-03-05 23:02:02 +0000375class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
376 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
377 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
378
379class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
380 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
381 [(set rclass:$rT, xform:$val)]>;
382
383multiclass ImmLoadHalfwordUpper
384{
385 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000386 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000387
388 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000389 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000390
391 // Loads the high portion of an address
392 def hi: ILHURegInst<R32C, symbolHi, hi16>;
393
394 // Used in custom lowering constant SFP loads:
395 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
396}
397
398defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000399
400// Immediate load address (can also be used to load 18-bit unsigned constants,
401// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000402
Scott Michel97872d32008-02-23 18:41:37 +0000403class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
404 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
405 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000406
Scott Michel6baba072008-03-05 23:02:02 +0000407class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
408 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
409 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
410
411class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
412 ILAInst<(outs rclass:$rT), (ins immtype:$val),
413 [(set rclass:$rT, xform:$val)]>;
414
Scott Michel97872d32008-02-23 18:41:37 +0000415multiclass ImmLoadAddress
416{
Scott Michel6baba072008-03-05 23:02:02 +0000417 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
418 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000419
Scott Michel6baba072008-03-05 23:02:02 +0000420 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
421 def r32: ILARegInst<R32C, u18imm, imm18>;
422 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
423 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000424
Scott Michel6baba072008-03-05 23:02:02 +0000425 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000426
Scott Michel97872d32008-02-23 18:41:37 +0000427 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
428 [/* no pattern */]>;
429}
430
431defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000432
433// Immediate OR, Halfword Lower: The "other" part of loading large constants
434// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
435// Note that these are really two operand instructions, but they're encoded
436// as three operands with the first two arguments tied-to each other.
437
Scott Michel6baba072008-03-05 23:02:02 +0000438class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
439 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
440 ImmLoad, pattern>,
441 RegConstraint<"$rS = $rT">,
442 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000443
Scott Michel6baba072008-03-05 23:02:02 +0000444class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
445 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
446 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000447
Scott Michel6baba072008-03-05 23:02:02 +0000448class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
449 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
450 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000451
Scott Michel6baba072008-03-05 23:02:02 +0000452multiclass ImmOrHalfwordLower
453{
454 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000455 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000456
457 def r32: IOHLRegInst<R32C, i32imm>;
458 def f32: IOHLRegInst<R32FP, f32imm>;
459
460 def lo: IOHLRegInst<R32C, symbolLo>;
461}
462
463defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000464
Scott Michel8b6b4202007-12-04 22:35:58 +0000465// Form select mask for bytes using immediate, used in conjunction with the
466// SELB instruction:
467
Scott Michel6baba072008-03-05 23:02:02 +0000468class FSMBIVec<ValueType vectype>:
469 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
470 "fsmbi\t$rT, $val",
471 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000472 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000473
Scott Michel97872d32008-02-23 18:41:37 +0000474multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000475{
476 def v16i8: FSMBIVec<v16i8>;
477 def v8i16: FSMBIVec<v8i16>;
478 def v4i32: FSMBIVec<v4i32>;
479 def v2i64: FSMBIVec<v2i64>;
480}
Scott Michel8b6b4202007-12-04 22:35:58 +0000481
Scott Michel97872d32008-02-23 18:41:37 +0000482defm FSMBI : FormSelectMaskBytesImm;
483
484// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
485def FSMB:
486 RRForm_1<0b01101101100, (outs VECREG:$rT), (ins R16C:$rA),
Scott Michel6baba072008-03-05 23:02:02 +0000487 "fsmb\t$rT, $rA", SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000488 [(set (v16i8 VECREG:$rT), (SPUselmask R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000489
490// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
491// only 8-bits wide (even though it's input as 16-bits here)
492def FSMH:
493 RRForm_1<0b10101101100, (outs VECREG:$rT), (ins R16C:$rA),
494 "fsmh\t$rT, $rA", SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000495 [(set (v8i16 VECREG:$rT), (SPUselmask R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000496
497// fsm: Form select mask for words. Like the other fsm* instructions,
498// only the lower 4 bits of $rA are significant.
Scott Michel67224b22008-06-02 22:18:03 +0000499class FSMInst<ValueType vectype, RegisterClass rclass>:
500 RRForm_1<0b00101101100, (outs VECREG:$rT), (ins rclass:$rA),
501 "fsm\t$rT, $rA",
502 SelectOp,
503 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
504
505multiclass FormSelectMaskWord {
506 def r32 : FSMInst<v4i32, R32C>;
507 def r16 : FSMInst<v4i32, R16C>;
508}
509
510defm FSM : FormSelectMaskWord;
511
512// Special case when used for i64 math operations
513multiclass FormSelectMaskWord64 {
514 def r32 : FSMInst<v2i64, R32C>;
515 def r16 : FSMInst<v2i64, R16C>;
516}
517
518defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000519
520//===----------------------------------------------------------------------===//
521// Integer and Logical Operations:
522//===----------------------------------------------------------------------===//
523
524def AHv8i16:
525 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
526 "ah\t$rT, $rA, $rB", IntegerOp,
527 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
528
529def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
530 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
531
Scott Michel8b6b4202007-12-04 22:35:58 +0000532def AHr16:
533 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
534 "ah\t$rT, $rA, $rB", IntegerOp,
535 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
536
537def AHIvec:
538 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
539 "ahi\t$rT, $rA, $val", IntegerOp,
540 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
541 v8i16SExt10Imm:$val))]>;
542
Scott Michel97872d32008-02-23 18:41:37 +0000543def AHIr16:
544 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
545 "ahi\t$rT, $rA, $val", IntegerOp,
546 [(set R16C:$rT, (add R16C:$rA, v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000547
Scott Michel97872d32008-02-23 18:41:37 +0000548def Avec:
549 RRForm<0b00000011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
550 "a\t$rT, $rA, $rB", IntegerOp,
551 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000552
553def : Pat<(add (v16i8 VECREG:$rA), (v16i8 VECREG:$rB)),
554 (Avec VECREG:$rA, VECREG:$rB)>;
555
Scott Michel97872d32008-02-23 18:41:37 +0000556def Ar32:
557 RRForm<0b00000011000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
558 "a\t$rT, $rA, $rB", IntegerOp,
559 [(set R32C:$rT, (add R32C:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000560
Scott Michel438be252007-12-17 22:32:34 +0000561def Ar8:
562 RRForm<0b00000011000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
563 "a\t$rT, $rA, $rB", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000564 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +0000565
Scott Michel8b6b4202007-12-04 22:35:58 +0000566def AIvec:
567 RI10Form<0b00111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
568 "ai\t$rT, $rA, $val", IntegerOp,
569 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA),
570 v4i32SExt10Imm:$val))]>;
571
Scott Michel438be252007-12-17 22:32:34 +0000572def AIr32:
573 RI10Form<0b00111000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
574 "ai\t$rT, $rA, $val", IntegerOp,
575 [(set R32C:$rT, (add R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000576
Scott Michel438be252007-12-17 22:32:34 +0000577def SFHvec:
578 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
579 "sfh\t$rT, $rA, $rB", IntegerOp,
580 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
581 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000582
Scott Michel438be252007-12-17 22:32:34 +0000583def SFHr16:
584 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
585 "sfh\t$rT, $rA, $rB", IntegerOp,
586 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000587
588def SFHIvec:
589 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
590 "sfhi\t$rT, $rA, $val", IntegerOp,
591 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
592 (v8i16 VECREG:$rA)))]>;
593
594def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
595 "sfhi\t$rT, $rA, $val", IntegerOp,
596 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
597
598def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
599 (ins VECREG:$rA, VECREG:$rB),
600 "sf\t$rT, $rA, $rB", IntegerOp,
601 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
602
603def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
604 "sf\t$rT, $rA, $rB", IntegerOp,
605 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
606
607def SFIvec:
608 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
609 "sfi\t$rT, $rA, $val", IntegerOp,
610 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
611 (v4i32 VECREG:$rA)))]>;
612
613def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
614 (ins R32C:$rA, s10imm_i32:$val),
615 "sfi\t$rT, $rA, $val", IntegerOp,
616 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
617
618// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000619class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
620 RRForm<0b00000010110, OOL, IOL,
621 "addx\t$rT, $rA, $rB",
622 IntegerOp, pattern>;
623
624class ADDXVecInst<ValueType vectype>:
625 ADDXInst<(outs VECREG:$rT),
626 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
627 [(set (vectype VECREG:$rT),
628 (SPUaddx (vectype VECREG:$rA), (vectype VECREG:$rB),
629 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000630 RegConstraint<"$rCarry = $rT">,
631 NoEncode<"$rCarry">;
632
Scott Michel67224b22008-06-02 22:18:03 +0000633class ADDXRegInst<RegisterClass rclass>:
634 ADDXInst<(outs rclass:$rT),
635 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
636 [(set rclass:$rT,
637 (SPUaddx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000638 RegConstraint<"$rCarry = $rT">,
639 NoEncode<"$rCarry">;
640
Scott Michel67224b22008-06-02 22:18:03 +0000641multiclass AddExtended {
642 def v2i64 : ADDXVecInst<v2i64>;
643 def v4i32 : ADDXVecInst<v4i32>;
644 def r64 : ADDXRegInst<R64C>;
645 def r32 : ADDXRegInst<R32C>;
646}
647
648defm ADDX : AddExtended;
649
650// CG: Generate carry for add
651class CGInst<dag OOL, dag IOL, list<dag> pattern>:
652 RRForm<0b01000011000, OOL, IOL,
653 "cg\t$rT, $rA, $rB",
654 IntegerOp, pattern>;
655
656class CGVecInst<ValueType vectype>:
657 CGInst<(outs VECREG:$rT),
658 (ins VECREG:$rA, VECREG:$rB),
659 [(set (vectype VECREG:$rT),
660 (SPUcarry_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
661
662class CGRegInst<RegisterClass rclass>:
663 CGInst<(outs rclass:$rT),
664 (ins rclass:$rA, rclass:$rB),
665 [(set rclass:$rT,
666 (SPUcarry_gen rclass:$rA, rclass:$rB))]>;
667
668multiclass CarryGenerate {
669 def v2i64 : CGVecInst<v2i64>;
670 def v4i32 : CGVecInst<v4i32>;
671 def r64 : CGRegInst<R64C>;
672 def r32 : CGRegInst<R32C>;
673}
674
675defm CG : CarryGenerate;
676
677// SFX: Subract from, extended. This is used in conjunction with BG to subtract
678// with carry (borrow, in this case)
679class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
680 RRForm<0b10000010110, OOL, IOL,
681 "sfx\t$rT, $rA, $rB",
682 IntegerOp, pattern>;
683
684class SFXVecInst<ValueType vectype>:
685 SFXInst<(outs VECREG:$rT),
686 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
687 [(set (vectype VECREG:$rT),
688 (SPUsubx (vectype VECREG:$rA), (vectype VECREG:$rB),
689 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000690 RegConstraint<"$rCarry = $rT">,
691 NoEncode<"$rCarry">;
692
Scott Michel67224b22008-06-02 22:18:03 +0000693class SFXRegInst<RegisterClass rclass>:
694 SFXInst<(outs rclass:$rT),
695 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
696 [(set rclass:$rT,
697 (SPUsubx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
698 RegConstraint<"$rCarry = $rT">,
699 NoEncode<"$rCarry">;
700
701multiclass SubtractExtended {
702 def v2i64 : SFXVecInst<v2i64>;
703 def v4i32 : SFXVecInst<v4i32>;
704 def r64 : SFXRegInst<R64C>;
705 def r32 : SFXRegInst<R32C>;
706}
707
708defm SFX : SubtractExtended;
709
Scott Michel8b6b4202007-12-04 22:35:58 +0000710// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000711class BGInst<dag OOL, dag IOL, list<dag> pattern>:
712 RRForm<0b01000010000, OOL, IOL,
713 "bg\t$rT, $rA, $rB",
714 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000715
Scott Michel67224b22008-06-02 22:18:03 +0000716class BGVecInst<ValueType vectype>:
717 BGInst<(outs VECREG:$rT),
718 (ins VECREG:$rA, VECREG:$rB),
719 [(set (vectype VECREG:$rT),
720 (SPUborrow_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
721
722class BGRegInst<RegisterClass rclass>:
723 BGInst<(outs rclass:$rT),
724 (ins rclass:$rA, rclass:$rB),
725 [(set rclass:$rT,
726 (SPUborrow_gen rclass:$rA, rclass:$rB))]>;
727
728multiclass BorrowGenerate {
729 def v4i32 : BGVecInst<v4i32>;
730 def v2i64 : BGVecInst<v2i64>;
731 def r64 : BGRegInst<R64C>;
732 def r32 : BGRegInst<R32C>;
733}
734
735defm BG : BorrowGenerate;
736
737// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000738def BGXvec:
739 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
740 VECREG:$rCarry),
741 "bgx\t$rT, $rA, $rB", IntegerOp,
742 []>,
743 RegConstraint<"$rCarry = $rT">,
744 NoEncode<"$rCarry">;
745
746// Halfword multiply variants:
747// N.B: These can be used to build up larger quantities (16x16 -> 32)
748
749def MPYv8i16:
750 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
751 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
752 [(set (v8i16 VECREG:$rT), (SPUmpy_v8i16 (v8i16 VECREG:$rA),
753 (v8i16 VECREG:$rB)))]>;
754
755def MPYr16:
756 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
757 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
758 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
759
760def MPYUv4i32:
761 RRForm<0b00110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
762 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
763 [(set (v4i32 VECREG:$rT),
764 (SPUmpyu_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
765
766def MPYUr16:
767 RRForm<0b00110011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
768 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
769 [(set R32C:$rT, (mul (zext R16C:$rA),
770 (zext R16C:$rB)))]>;
771
772def MPYUr32:
773 RRForm<0b00110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
774 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
775 [(set R32C:$rT, (SPUmpyu_i32 R32C:$rA, R32C:$rB))]>;
776
777// mpyi: multiply 16 x s10imm -> 32 result (custom lowering for 32 bit result,
778// this only produces the lower 16 bits)
779def MPYIvec:
780 RI10Form<0b00101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
781 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
782 [(set (v8i16 VECREG:$rT), (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
783
784def MPYIr16:
785 RI10Form<0b00101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
786 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
787 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
788
789// mpyui: same issues as other multiplies, plus, this doesn't match a
790// pattern... but may be used during target DAG selection or lowering
791def MPYUIvec:
792 RI10Form<0b10101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
793 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
794 []>;
795
796def MPYUIr16:
797 RI10Form<0b10101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
798 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
799 []>;
800
801// mpya: 16 x 16 + 16 -> 32 bit result
802def MPYAvec:
803 RRRForm<0b0011, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
804 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
805 [(set (v4i32 VECREG:$rT), (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
806 (v8i16 VECREG:$rB)))),
807 (v4i32 VECREG:$rC)))]>;
808
809def MPYAr32:
810 RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
811 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
812 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
813 R32C:$rC))]>;
814
815def : Pat<(add (mul (sext R16C:$rA), (sext R16C:$rB)), R32C:$rC),
816 (MPYAr32 R16C:$rA, R16C:$rB, R32C:$rC)>;
817
818def MPYAr32_sextinreg:
819 RRRForm<0b0011, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
820 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
821 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
822 (sext_inreg R32C:$rB, i16)),
823 R32C:$rC))]>;
824
825//def MPYAr32:
826// RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
827// "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
828// [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
829// R32C:$rC))]>;
830
831// mpyh: multiply high, used to synthesize 32-bit multiplies
832def MPYHv4i32:
833 RRForm<0b10100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
834 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
835 [(set (v4i32 VECREG:$rT),
836 (SPUmpyh_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
837
838def MPYHr32:
839 RRForm<0b10100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
840 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
841 [(set R32C:$rT, (SPUmpyh_i32 R32C:$rA, R32C:$rB))]>;
842
843// mpys: multiply high and shift right (returns the top half of
844// a 16-bit multiply, sign extended to 32 bits.)
845def MPYSvec:
846 RRForm<0b11100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
847 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
848 []>;
849
850def MPYSr16:
851 RRForm<0b11100011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
852 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
853 []>;
854
855// mpyhh: multiply high-high (returns the 32-bit result from multiplying
856// the top 16 bits of the $rA, $rB)
857def MPYHHv8i16:
858 RRForm<0b01100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
859 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
860 [(set (v8i16 VECREG:$rT),
861 (SPUmpyhh_v8i16 (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)))]>;
862
863def MPYHHr32:
864 RRForm<0b01100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
865 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
866 []>;
867
868// mpyhha: Multiply high-high, add to $rT:
869def MPYHHAvec:
870 RRForm<0b01100010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
871 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
872 []>;
873
874def MPYHHAr32:
875 RRForm<0b01100010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
876 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
877 []>;
878
879// mpyhhu: Multiply high-high, unsigned
880def MPYHHUvec:
881 RRForm<0b01110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
882 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
883 []>;
884
885def MPYHHUr32:
886 RRForm<0b01110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
887 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
888 []>;
889
890// mpyhhau: Multiply high-high, unsigned
891def MPYHHAUvec:
892 RRForm<0b01110010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
893 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
894 []>;
895
896def MPYHHAUr32:
897 RRForm<0b01110010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
898 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
899 []>;
900
901// clz: Count leading zeroes
902def CLZv4i32:
903 RRForm_1<0b10100101010, (outs VECREG:$rT), (ins VECREG:$rA),
904 "clz\t$rT, $rA", IntegerOp,
905 [/* intrinsic */]>;
906
907def CLZr32:
908 RRForm_1<0b10100101010, (outs R32C:$rT), (ins R32C:$rA),
909 "clz\t$rT, $rA", IntegerOp,
910 [(set R32C:$rT, (ctlz R32C:$rA))]>;
911
912// cntb: Count ones in bytes (aka "population count")
913// NOTE: This instruction is really a vector instruction, but the custom
914// lowering code uses it in unorthodox ways to support CTPOP for other
915// data types!
916def CNTBv16i8:
917 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
918 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000919 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000920
921def CNTBv8i16 :
922 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
923 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000924 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000925
926def CNTBv4i32 :
927 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
928 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000929 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000930
Scott Michel8b6b4202007-12-04 22:35:58 +0000931// gbb: Gather all low order bits from each byte in $rA into a single 16-bit
932// quantity stored into $rT
933def GBB:
934 RRForm_1<0b01001101100, (outs R16C:$rT), (ins VECREG:$rA),
935 "gbb\t$rT, $rA", GatherOp,
936 []>;
937
938// gbh: Gather all low order bits from each halfword in $rA into a single
939// 8-bit quantity stored in $rT
940def GBH:
941 RRForm_1<0b10001101100, (outs R16C:$rT), (ins VECREG:$rA),
942 "gbh\t$rT, $rA", GatherOp,
943 []>;
944
945// gb: Gather all low order bits from each word in $rA into a single
946// 4-bit quantity stored in $rT
947def GB:
948 RRForm_1<0b00001101100, (outs R16C:$rT), (ins VECREG:$rA),
949 "gb\t$rT, $rA", GatherOp,
950 []>;
951
952// avgb: average bytes
953def AVGB:
954 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
955 "avgb\t$rT, $rA, $rB", ByteOp,
956 []>;
957
958// absdb: absolute difference of bytes
959def ABSDB:
960 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
961 "absdb\t$rT, $rA, $rB", ByteOp,
962 []>;
963
964// sumb: sum bytes into halfwords
965def SUMB:
966 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
967 "sumb\t$rT, $rA, $rB", ByteOp,
968 []>;
969
970// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +0000971class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
972 RRForm_1<0b01101101010, OOL, IOL,
973 "xsbh\t$rDst, $rSrc",
974 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000975
Scott Michel67224b22008-06-02 22:18:03 +0000976class XSBHVecInst<ValueType vectype>:
977 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
978 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000979
Scott Michel67224b22008-06-02 22:18:03 +0000980class XSBHRegInst<RegisterClass rclass>:
981 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
982 [(set rclass:$rDst, (sext_inreg rclass:$rSrc, i8))]>;
983
984multiclass ExtendByteHalfword {
985 def v16i8: XSBHVecInst<v8i16>;
986 def r16: XSBHRegInst<R16C>;
987
988 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
989 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
990 // pattern below). Intentionally doesn't match a pattern because we want the
991 // sext 8->32 pattern to do the work for us, namely because we need the extra
992 // XSHWr32.
993 def r32: XSBHRegInst<R32C>;
994}
995
996defm XSBH : ExtendByteHalfword;
997
998// Sign-extend, but take an 8-bit register to a 16-bit register (not done as
999// sext_inreg)
Scott Michel438be252007-12-17 22:32:34 +00001000def XSBHr8:
Scott Michel67224b22008-06-02 22:18:03 +00001001 XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1002 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001003
1004// Sign extend halfwords to words:
1005def XSHWvec:
1006 RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
1007 "xshw\t$rDest, $rSrc", IntegerOp,
1008 [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
1009
1010def XSHWr32:
1011 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
1012 "xshw\t$rDst, $rSrc", IntegerOp,
1013 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
1014
1015def XSHWr16:
1016 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
1017 "xshw\t$rDst, $rSrc", IntegerOp,
1018 [(set R32C:$rDst, (sext R16C:$rSrc))]>;
1019
1020def XSWDvec:
1021 RRForm_1<0b01100101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
1022 "xswd\t$rDst, $rSrc", IntegerOp,
1023 [(set (v2i64 VECREG:$rDst), (sext (v4i32 VECREG:$rSrc)))]>;
1024
1025def XSWDr64:
1026 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R64C:$rSrc),
1027 "xswd\t$rDst, $rSrc", IntegerOp,
1028 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1029
1030def XSWDr32:
1031 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R32C:$rSrc),
1032 "xswd\t$rDst, $rSrc", IntegerOp,
1033 [(set R64C:$rDst, (SPUsext32_to_64 R32C:$rSrc))]>;
1034
1035def : Pat<(sext R32C:$inp),
1036 (XSWDr32 R32C:$inp)>;
1037
1038// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001039
Scott Michel97872d32008-02-23 18:41:37 +00001040class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1041 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1042 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001043
Scott Michel97872d32008-02-23 18:41:37 +00001044class ANDVecInst<ValueType vectype>:
1045 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1046 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1047 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001048
Scott Michel6baba072008-03-05 23:02:02 +00001049class ANDRegInst<RegisterClass rclass>:
1050 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1051 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1052
Scott Michel97872d32008-02-23 18:41:37 +00001053multiclass BitwiseAnd
1054{
1055 def v16i8: ANDVecInst<v16i8>;
1056 def v8i16: ANDVecInst<v8i16>;
1057 def v4i32: ANDVecInst<v4i32>;
1058 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001059
Scott Michel6baba072008-03-05 23:02:02 +00001060 def r128: ANDRegInst<GPRC>;
1061 def r64: ANDRegInst<R64C>;
1062 def r32: ANDRegInst<R32C>;
1063 def r16: ANDRegInst<R16C>;
1064 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001065
Scott Michel97872d32008-02-23 18:41:37 +00001066 //===---------------------------------------------
1067 // Special instructions to perform the fabs instruction
1068 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1069 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001070
Scott Michel97872d32008-02-23 18:41:37 +00001071 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1072 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001073
Scott Michel97872d32008-02-23 18:41:37 +00001074 // Could use v4i32, but won't for clarity
1075 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1076 [/* Intentionally does not match a pattern */]>;
1077
1078 //===---------------------------------------------
1079
1080 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1081 // quantities -- see 16->32 zext pattern.
1082 //
1083 // This pattern is somewhat artificial, since it might match some
1084 // compiler generated pattern but it is unlikely to do so.
1085
1086 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1087 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1088}
1089
1090defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001091
1092// N.B.: vnot_conv is one of those special target selection pattern fragments,
1093// in which we expect there to be a bit_convert on the constant. Bear in mind
1094// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1095// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001096
Scott Michel97872d32008-02-23 18:41:37 +00001097class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1098 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1099 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001100
Scott Michel97872d32008-02-23 18:41:37 +00001101class ANDCVecInst<ValueType vectype>:
1102 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1103 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1104 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001105
Scott Michel97872d32008-02-23 18:41:37 +00001106class ANDCRegInst<RegisterClass rclass>:
1107 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1108 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001109
Scott Michel97872d32008-02-23 18:41:37 +00001110multiclass AndComplement
1111{
1112 def v16i8: ANDCVecInst<v16i8>;
1113 def v8i16: ANDCVecInst<v8i16>;
1114 def v4i32: ANDCVecInst<v4i32>;
1115 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001116
Scott Michel97872d32008-02-23 18:41:37 +00001117 def r128: ANDCRegInst<GPRC>;
1118 def r64: ANDCRegInst<R64C>;
1119 def r32: ANDCRegInst<R32C>;
1120 def r16: ANDCRegInst<R16C>;
1121 def r8: ANDCRegInst<R8C>;
1122}
Scott Michel438be252007-12-17 22:32:34 +00001123
Scott Michel97872d32008-02-23 18:41:37 +00001124defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001125
Scott Michel97872d32008-02-23 18:41:37 +00001126class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1127 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
1128 IntegerOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001129
Scott Michel97872d32008-02-23 18:41:37 +00001130multiclass AndByteImm
1131{
1132 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1133 [(set (v16i8 VECREG:$rT),
1134 (and (v16i8 VECREG:$rA),
1135 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001136
Scott Michel97872d32008-02-23 18:41:37 +00001137 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1138 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1139}
Scott Michel438be252007-12-17 22:32:34 +00001140
Scott Michel97872d32008-02-23 18:41:37 +00001141defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001142
Scott Michel97872d32008-02-23 18:41:37 +00001143class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1144 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
1145 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001146
Scott Michel97872d32008-02-23 18:41:37 +00001147multiclass AndHalfwordImm
1148{
1149 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1150 [(set (v8i16 VECREG:$rT),
1151 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001152
Scott Michel97872d32008-02-23 18:41:37 +00001153 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1154 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001155
Scott Michel97872d32008-02-23 18:41:37 +00001156 // Zero-extend i8 to i16:
1157 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1158 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1159}
Scott Michel8b6b4202007-12-04 22:35:58 +00001160
Scott Michel97872d32008-02-23 18:41:37 +00001161defm ANDHI : AndHalfwordImm;
1162
1163class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1164 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1165 IntegerOp, pattern>;
1166
1167multiclass AndWordImm
1168{
1169 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1170 [(set (v4i32 VECREG:$rT),
1171 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1172
1173 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1174 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1175
1176 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1177 // pattern below.
1178 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1179 [(set R32C:$rT,
1180 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1181
1182 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1183 // zext 16->32 pattern below.
1184 //
1185 // Note that this pattern is somewhat artificial, since it might match
1186 // something the compiler generates but is unlikely to occur in practice.
1187 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1188 [(set R32C:$rT,
1189 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1190}
1191
1192defm ANDI : AndWordImm;
1193
1194//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001195// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001196//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1197
Scott Michel8b6b4202007-12-04 22:35:58 +00001198// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001199class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1200 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1201 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001202
Scott Michel97872d32008-02-23 18:41:37 +00001203class ORVecInst<ValueType vectype>:
1204 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1205 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1206 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001207
Scott Michel97872d32008-02-23 18:41:37 +00001208class ORRegInst<RegisterClass rclass>:
1209 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1210 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001211
Scott Michel97872d32008-02-23 18:41:37 +00001212class ORPromoteScalar<RegisterClass rclass>:
1213 ORInst<(outs VECREG:$rT), (ins rclass:$rA, rclass:$rB),
1214 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001215
Scott Michel97872d32008-02-23 18:41:37 +00001216class ORExtractElt<RegisterClass rclass>:
1217 ORInst<(outs rclass:$rT), (ins VECREG:$rA, VECREG:$rB),
1218 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001219
Scott Michel97872d32008-02-23 18:41:37 +00001220multiclass BitwiseOr
1221{
1222 def v16i8: ORVecInst<v16i8>;
1223 def v8i16: ORVecInst<v8i16>;
1224 def v4i32: ORVecInst<v4i32>;
1225 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001226
Scott Michel97872d32008-02-23 18:41:37 +00001227 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1228 [(set (v4f32 VECREG:$rT),
1229 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1230 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001231
Scott Michel97872d32008-02-23 18:41:37 +00001232 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1233 [(set (v2f64 VECREG:$rT),
1234 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1235 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001236
Scott Michel97872d32008-02-23 18:41:37 +00001237 def r64: ORRegInst<R64C>;
1238 def r32: ORRegInst<R32C>;
1239 def r16: ORRegInst<R16C>;
1240 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001241
Scott Michel97872d32008-02-23 18:41:37 +00001242 // OR instructions used to copy f32 and f64 registers.
1243 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1244 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001245
Scott Michel97872d32008-02-23 18:41:37 +00001246 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1247 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001248
Scott Michel97872d32008-02-23 18:41:37 +00001249 // scalar->vector promotion:
1250 def v16i8_i8: ORPromoteScalar<R8C>;
1251 def v8i16_i16: ORPromoteScalar<R16C>;
1252 def v4i32_i32: ORPromoteScalar<R32C>;
1253 def v2i64_i64: ORPromoteScalar<R64C>;
1254 def v4f32_f32: ORPromoteScalar<R32FP>;
1255 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001256
Scott Michel97872d32008-02-23 18:41:37 +00001257 // extract element 0:
1258 def i8_v16i8: ORExtractElt<R8C>;
1259 def i16_v8i16: ORExtractElt<R16C>;
1260 def i32_v4i32: ORExtractElt<R32C>;
1261 def i64_v2i64: ORExtractElt<R64C>;
1262 def f32_v4f32: ORExtractElt<R32FP>;
1263 def f64_v2f64: ORExtractElt<R64FP>;
1264}
Scott Michel438be252007-12-17 22:32:34 +00001265
Scott Michel97872d32008-02-23 18:41:37 +00001266defm OR : BitwiseOr;
1267
1268// scalar->vector promotion patterns:
Scott Michel438be252007-12-17 22:32:34 +00001269def : Pat<(v16i8 (SPUpromote_scalar R8C:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001270 (ORv16i8_i8 R8C:$rA, R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001271
Scott Michel8b6b4202007-12-04 22:35:58 +00001272def : Pat<(v8i16 (SPUpromote_scalar R16C:$rA)),
1273 (ORv8i16_i16 R16C:$rA, R16C:$rA)>;
1274
Scott Michel8b6b4202007-12-04 22:35:58 +00001275def : Pat<(v4i32 (SPUpromote_scalar R32C:$rA)),
1276 (ORv4i32_i32 R32C:$rA, R32C:$rA)>;
1277
Scott Michel8b6b4202007-12-04 22:35:58 +00001278def : Pat<(v2i64 (SPUpromote_scalar R64C:$rA)),
1279 (ORv2i64_i64 R64C:$rA, R64C:$rA)>;
1280
Scott Michel8b6b4202007-12-04 22:35:58 +00001281def : Pat<(v4f32 (SPUpromote_scalar R32FP:$rA)),
1282 (ORv4f32_f32 R32FP:$rA, R32FP:$rA)>;
1283
Scott Michel8b6b4202007-12-04 22:35:58 +00001284def : Pat<(v2f64 (SPUpromote_scalar R64FP:$rA)),
1285 (ORv2f64_f64 R64FP:$rA, R64FP:$rA)>;
1286
1287// ORi*_v*: Used to extract vector element 0 (the preferred slot)
Scott Michel438be252007-12-17 22:32:34 +00001288
1289def : Pat<(SPUextract_elt0 (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001290 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001291
Scott Michel394e26d2008-01-17 20:38:41 +00001292def : Pat<(SPUextract_elt0_chained (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001293 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel394e26d2008-01-17 20:38:41 +00001294
Scott Michel8b6b4202007-12-04 22:35:58 +00001295def : Pat<(SPUextract_elt0 (v8i16 VECREG:$rA)),
1296 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1297
1298def : Pat<(SPUextract_elt0_chained (v8i16 VECREG:$rA)),
1299 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1300
Scott Michel8b6b4202007-12-04 22:35:58 +00001301def : Pat<(SPUextract_elt0 (v4i32 VECREG:$rA)),
1302 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1303
1304def : Pat<(SPUextract_elt0_chained (v4i32 VECREG:$rA)),
1305 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1306
Scott Michel8b6b4202007-12-04 22:35:58 +00001307def : Pat<(SPUextract_elt0 (v2i64 VECREG:$rA)),
1308 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1309
1310def : Pat<(SPUextract_elt0_chained (v2i64 VECREG:$rA)),
1311 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1312
Scott Michel8b6b4202007-12-04 22:35:58 +00001313def : Pat<(SPUextract_elt0 (v4f32 VECREG:$rA)),
1314 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1315
1316def : Pat<(SPUextract_elt0_chained (v4f32 VECREG:$rA)),
1317 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1318
Scott Michel8b6b4202007-12-04 22:35:58 +00001319def : Pat<(SPUextract_elt0 (v2f64 VECREG:$rA)),
1320 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1321
1322def : Pat<(SPUextract_elt0_chained (v2f64 VECREG:$rA)),
1323 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1324
Scott Michel97872d32008-02-23 18:41:37 +00001325// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001326
Scott Michel97872d32008-02-23 18:41:37 +00001327class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1328 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1329 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001330
Scott Michel97872d32008-02-23 18:41:37 +00001331class ORCVecInst<ValueType vectype>:
1332 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1333 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1334 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001335
Scott Michel97872d32008-02-23 18:41:37 +00001336class ORCRegInst<RegisterClass rclass>:
1337 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1338 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001339
Scott Michel97872d32008-02-23 18:41:37 +00001340multiclass BitwiseOrComplement
1341{
1342 def v16i8: ORCVecInst<v16i8>;
1343 def v8i16: ORCVecInst<v8i16>;
1344 def v4i32: ORCVecInst<v4i32>;
1345 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001346
Scott Michel97872d32008-02-23 18:41:37 +00001347 def r64: ORCRegInst<R64C>;
1348 def r32: ORCRegInst<R32C>;
1349 def r16: ORCRegInst<R16C>;
1350 def r8: ORCRegInst<R8C>;
1351}
1352
1353defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001354
Scott Michel8b6b4202007-12-04 22:35:58 +00001355// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001356class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1357 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1358 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001359
Scott Michel97872d32008-02-23 18:41:37 +00001360class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1361 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1362 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1363 (vectype immpred:$val)))]>;
1364
1365multiclass BitwiseOrByteImm
1366{
1367 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1368
1369 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1370 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1371}
1372
1373defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001374
Scott Michel6e2d68b2008-11-10 23:43:06 +00001375// Truncate i16 -> i8
1376def ORBItrunc : ORBIInst<(outs R8C:$rT), (ins R16C:$rA, u10imm:$val),
1377 [/* empty */]>;
1378
1379def : Pat<(trunc R16C:$rSrc),
1380 (ORBItrunc R16C:$rSrc, 0)>;
1381
Scott Michel8b6b4202007-12-04 22:35:58 +00001382// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001383class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1384 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1385 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001386
Scott Michel97872d32008-02-23 18:41:37 +00001387class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1388 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1389 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1390 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001391
Scott Michel97872d32008-02-23 18:41:37 +00001392multiclass BitwiseOrHalfwordImm
1393{
1394 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1395
1396 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1397 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1398
1399 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1400 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1401 [(set R16C:$rT, (or (anyext R8C:$rA),
1402 i16ImmSExt10:$val))]>;
1403}
1404
1405defm ORHI : BitwiseOrHalfwordImm;
1406
Scott Michel6e2d68b2008-11-10 23:43:06 +00001407// Truncate i32 -> i16
1408def ORHItrunc : ORHIInst<(outs R16C:$rT), (ins R32C:$rA, u10imm:$val),
1409 [/* empty */]>;
1410
1411def : Pat<(trunc R32C:$rSrc),
1412 (ORHItrunc R32C:$rSrc, 0)>;
1413
Scott Michel97872d32008-02-23 18:41:37 +00001414class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1415 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1416 IntegerOp, pattern>;
1417
1418class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1419 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1420 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1421 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001422
1423// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001424multiclass BitwiseOrImm
1425{
1426 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001427
Scott Michel97872d32008-02-23 18:41:37 +00001428 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1429 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001430
Scott Michel97872d32008-02-23 18:41:37 +00001431 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1432 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1433 // infra "anyext 16->32" pattern.)
1434 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1435 [(set R32C:$rT, (or (anyext R16C:$rA),
1436 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001437
Scott Michel97872d32008-02-23 18:41:37 +00001438 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1439 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1440 // infra "anyext 16->32" pattern.)
1441 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1442 [(set R32C:$rT, (or (anyext R8C:$rA),
1443 i32ImmSExt10:$val))]>;
1444}
Scott Michel8b6b4202007-12-04 22:35:58 +00001445
Scott Michel97872d32008-02-23 18:41:37 +00001446defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001447
Scott Michel6e2d68b2008-11-10 23:43:06 +00001448// Truncate i64 -> i32
1449def ORItrunc : ORIInst<(outs R32C:$rT), (ins R64C:$rA, u10imm_i32:$val),
1450 [/* empty */]>;
1451
1452def : Pat<(trunc R64C:$rSrc),
1453 (ORItrunc R64C:$rSrc, 0)>;
1454
Scott Michel8b6b4202007-12-04 22:35:58 +00001455// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1456// $rT[0], slots 1-3 are zeroed.
1457//
Scott Michel438be252007-12-17 22:32:34 +00001458// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001459def ORXv4i32:
1460 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1461 "orx\t$rT, $rA, $rB", IntegerOp,
1462 []>;
1463
Scott Michel438be252007-12-17 22:32:34 +00001464// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001465
Scott Michel6baba072008-03-05 23:02:02 +00001466class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1467 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1468 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001469
Scott Michel6baba072008-03-05 23:02:02 +00001470class XORVecInst<ValueType vectype>:
1471 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1472 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1473 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001474
Scott Michel6baba072008-03-05 23:02:02 +00001475class XORRegInst<RegisterClass rclass>:
1476 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1477 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1478
1479multiclass BitwiseExclusiveOr
1480{
1481 def v16i8: XORVecInst<v16i8>;
1482 def v8i16: XORVecInst<v8i16>;
1483 def v4i32: XORVecInst<v4i32>;
1484 def v2i64: XORVecInst<v2i64>;
1485
1486 def r128: XORRegInst<GPRC>;
1487 def r64: XORRegInst<R64C>;
1488 def r32: XORRegInst<R32C>;
1489 def r16: XORRegInst<R16C>;
1490 def r8: XORRegInst<R8C>;
1491
1492 // Special forms for floating point instructions.
1493 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1494
1495 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1496 [/* no pattern */]>;
1497
1498 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1499 [/* no pattern */]>;
1500
1501 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1502 [/* no pattern, see fneg{32,64} */]>;
1503}
1504
1505defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001506
1507//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001508
Scott Michel97872d32008-02-23 18:41:37 +00001509class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1510 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1511 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001512
Scott Michel97872d32008-02-23 18:41:37 +00001513multiclass XorByteImm
1514{
1515 def v16i8:
1516 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1517 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1518
1519 def r8:
1520 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1521 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1522}
1523
1524defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001525
Scott Michel8b6b4202007-12-04 22:35:58 +00001526def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001527 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001528 "xorhi\t$rT, $rA, $val", IntegerOp,
1529 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1530 v8i16SExt10Imm:$val))]>;
1531
1532def XORHIr16:
1533 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1534 "xorhi\t$rT, $rA, $val", IntegerOp,
1535 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1536
1537def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001538 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001539 "xori\t$rT, $rA, $val", IntegerOp,
1540 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1541 v4i32SExt10Imm:$val))]>;
1542
1543def XORIr32:
1544 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1545 "xori\t$rT, $rA, $val", IntegerOp,
1546 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1547
1548// NAND:
1549def NANDv16i8:
1550 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1551 "nand\t$rT, $rA, $rB", IntegerOp,
1552 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1553 (v16i8 VECREG:$rB))))]>;
1554
1555def NANDv8i16:
1556 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1557 "nand\t$rT, $rA, $rB", IntegerOp,
1558 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1559 (v8i16 VECREG:$rB))))]>;
1560
1561def NANDv4i32:
1562 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1563 "nand\t$rT, $rA, $rB", IntegerOp,
1564 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1565 (v4i32 VECREG:$rB))))]>;
1566
1567def NANDr32:
1568 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1569 "nand\t$rT, $rA, $rB", IntegerOp,
1570 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1571
1572def NANDr16:
1573 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1574 "nand\t$rT, $rA, $rB", IntegerOp,
1575 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1576
Scott Michel438be252007-12-17 22:32:34 +00001577def NANDr8:
1578 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1579 "nand\t$rT, $rA, $rB", IntegerOp,
1580 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1581
Scott Michel8b6b4202007-12-04 22:35:58 +00001582// NOR:
1583def NORv16i8:
1584 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1585 "nor\t$rT, $rA, $rB", IntegerOp,
1586 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1587 (v16i8 VECREG:$rB))))]>;
1588
1589def NORv8i16:
1590 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1591 "nor\t$rT, $rA, $rB", IntegerOp,
1592 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1593 (v8i16 VECREG:$rB))))]>;
1594
1595def NORv4i32:
1596 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1597 "nor\t$rT, $rA, $rB", IntegerOp,
1598 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1599 (v4i32 VECREG:$rB))))]>;
1600
1601def NORr32:
1602 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1603 "nor\t$rT, $rA, $rB", IntegerOp,
1604 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1605
1606def NORr16:
1607 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1608 "nor\t$rT, $rA, $rB", IntegerOp,
1609 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1610
Scott Michel438be252007-12-17 22:32:34 +00001611def NORr8:
1612 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1613 "nor\t$rT, $rA, $rB", IntegerOp,
1614 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1615
Scott Michel8b6b4202007-12-04 22:35:58 +00001616// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001617class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1618 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1619 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001620
Scott Michel6baba072008-03-05 23:02:02 +00001621class SELBVecInst<ValueType vectype>:
1622 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1623 [(set (vectype VECREG:$rT),
1624 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1625 (and (vnot (vectype VECREG:$rC)),
1626 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001627
Scott Michel6baba072008-03-05 23:02:02 +00001628class SELBRegInst<RegisterClass rclass>:
1629 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1630 [(set rclass:$rT,
1631 (or (and rclass:$rA, rclass:$rC),
1632 (and rclass:$rB, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001633
Scott Michel6baba072008-03-05 23:02:02 +00001634multiclass SelectBits
1635{
1636 def v16i8: SELBVecInst<v16i8>;
1637 def v8i16: SELBVecInst<v8i16>;
1638 def v4i32: SELBVecInst<v4i32>;
1639 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001640
Scott Michel6baba072008-03-05 23:02:02 +00001641 def r128: SELBRegInst<GPRC>;
1642 def r64: SELBRegInst<R64C>;
1643 def r32: SELBRegInst<R32C>;
1644 def r16: SELBRegInst<R16C>;
1645 def r8: SELBRegInst<R8C>;
1646}
Scott Michel8b6b4202007-12-04 22:35:58 +00001647
Scott Michel6baba072008-03-05 23:02:02 +00001648defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001649
Scott Michel56a125e2008-11-22 23:50:42 +00001650class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001651 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1652 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001653
Scott Michel56a125e2008-11-22 23:50:42 +00001654def : SPUselbPatVec<v16i8, SELBv16i8>;
1655def : SPUselbPatVec<v8i16, SELBv8i16>;
1656def : SPUselbPatVec<v4i32, SELBv4i32>;
1657def : SPUselbPatVec<v2i64, SELBv2i64>;
1658
1659class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1660 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1661 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1662
1663def : SPUselbPatReg<R8C, SELBr8>;
1664def : SPUselbPatReg<R16C, SELBr16>;
1665def : SPUselbPatReg<R32C, SELBr32>;
1666def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001667
Scott Michel6baba072008-03-05 23:02:02 +00001668class SelectConditional<RegisterClass rclass, SPUInstr inst>:
1669 Pat<(select rclass:$rCond, rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00001670 (inst rclass:$rFalse, rclass:$rTrue, rclass:$rCond)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001671
Scott Michel6baba072008-03-05 23:02:02 +00001672def : SelectConditional<R32C, SELBr32>;
1673def : SelectConditional<R16C, SELBr16>;
1674def : SelectConditional<R8C, SELBr8>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001675
Scott Michel6baba072008-03-05 23:02:02 +00001676// EQV: Equivalence (1 for each same bit, otherwise 0)
1677//
1678// Note: There are a lot of ways to match this bit operator and these patterns
1679// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001680
Scott Michel6baba072008-03-05 23:02:02 +00001681class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1682 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1683 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001684
Scott Michel6baba072008-03-05 23:02:02 +00001685class EQVVecInst<ValueType vectype>:
1686 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1687 [(set (vectype VECREG:$rT),
1688 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1689 (and (vnot (vectype VECREG:$rA)),
1690 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001691
Scott Michel6baba072008-03-05 23:02:02 +00001692class EQVRegInst<RegisterClass rclass>:
1693 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1694 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1695 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001696
Scott Michel6baba072008-03-05 23:02:02 +00001697class EQVVecPattern1<ValueType vectype>:
1698 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1699 [(set (vectype VECREG:$rT),
1700 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001701
Scott Michel6baba072008-03-05 23:02:02 +00001702class EQVRegPattern1<RegisterClass rclass>:
1703 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1704 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001705
Scott Michel6baba072008-03-05 23:02:02 +00001706class EQVVecPattern2<ValueType vectype>:
1707 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1708 [(set (vectype VECREG:$rT),
1709 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1710 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001711
Scott Michel6baba072008-03-05 23:02:02 +00001712class EQVRegPattern2<RegisterClass rclass>:
1713 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1714 [(set rclass:$rT,
1715 (or (and rclass:$rA, rclass:$rB),
1716 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001717
Scott Michel6baba072008-03-05 23:02:02 +00001718class EQVVecPattern3<ValueType vectype>:
1719 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1720 [(set (vectype VECREG:$rT),
1721 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001722
Scott Michel6baba072008-03-05 23:02:02 +00001723class EQVRegPattern3<RegisterClass rclass>:
1724 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1725 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001726
Scott Michel6baba072008-03-05 23:02:02 +00001727multiclass BitEquivalence
1728{
1729 def v16i8: EQVVecInst<v16i8>;
1730 def v8i16: EQVVecInst<v8i16>;
1731 def v4i32: EQVVecInst<v4i32>;
1732 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001733
Scott Michel6baba072008-03-05 23:02:02 +00001734 def v16i8_1: EQVVecPattern1<v16i8>;
1735 def v8i16_1: EQVVecPattern1<v8i16>;
1736 def v4i32_1: EQVVecPattern1<v4i32>;
1737 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001738
Scott Michel6baba072008-03-05 23:02:02 +00001739 def v16i8_2: EQVVecPattern2<v16i8>;
1740 def v8i16_2: EQVVecPattern2<v8i16>;
1741 def v4i32_2: EQVVecPattern2<v4i32>;
1742 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001743
Scott Michel6baba072008-03-05 23:02:02 +00001744 def v16i8_3: EQVVecPattern3<v16i8>;
1745 def v8i16_3: EQVVecPattern3<v8i16>;
1746 def v4i32_3: EQVVecPattern3<v4i32>;
1747 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001748
Scott Michel6baba072008-03-05 23:02:02 +00001749 def r128: EQVRegInst<GPRC>;
1750 def r64: EQVRegInst<R64C>;
1751 def r32: EQVRegInst<R32C>;
1752 def r16: EQVRegInst<R16C>;
1753 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001754
Scott Michel6baba072008-03-05 23:02:02 +00001755 def r128_1: EQVRegPattern1<GPRC>;
1756 def r64_1: EQVRegPattern1<R64C>;
1757 def r32_1: EQVRegPattern1<R32C>;
1758 def r16_1: EQVRegPattern1<R16C>;
1759 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001760
Scott Michel6baba072008-03-05 23:02:02 +00001761 def r128_2: EQVRegPattern2<GPRC>;
1762 def r64_2: EQVRegPattern2<R64C>;
1763 def r32_2: EQVRegPattern2<R32C>;
1764 def r16_2: EQVRegPattern2<R16C>;
1765 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001766
Scott Michel6baba072008-03-05 23:02:02 +00001767 def r128_3: EQVRegPattern3<GPRC>;
1768 def r64_3: EQVRegPattern3<R64C>;
1769 def r32_3: EQVRegPattern3<R32C>;
1770 def r16_3: EQVRegPattern3<R16C>;
1771 def r8_3: EQVRegPattern3<R8C>;
1772}
Scott Michel438be252007-12-17 22:32:34 +00001773
Scott Michel6baba072008-03-05 23:02:02 +00001774defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00001775
1776//===----------------------------------------------------------------------===//
1777// Vector shuffle...
1778//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001779// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
1780// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
1781// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
1782// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00001783//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001784
Scott Michel97872d32008-02-23 18:41:37 +00001785class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
1786 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
1787 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001788
Scott Michel97872d32008-02-23 18:41:37 +00001789class SHUFBVecInst<ValueType vectype>:
1790 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1791 [(set (vectype VECREG:$rT), (SPUshuffle (vectype VECREG:$rA),
1792 (vectype VECREG:$rB),
1793 (vectype VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001794
Scott Michel97872d32008-02-23 18:41:37 +00001795// It's this pattern that's probably the most useful, since SPUISelLowering
1796// methods create a v16i8 vector for $rC:
Scott Michel67224b22008-06-02 22:18:03 +00001797class SHUFBVecPat1<ValueType vectype, ValueType masktype, SPUInstr inst>:
Scott Michel97872d32008-02-23 18:41:37 +00001798 Pat<(SPUshuffle (vectype VECREG:$rA), (vectype VECREG:$rB),
Scott Michel67224b22008-06-02 22:18:03 +00001799 (masktype VECREG:$rC)),
Scott Michel97872d32008-02-23 18:41:37 +00001800 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel754d8662007-12-20 00:44:13 +00001801
Scott Michel97872d32008-02-23 18:41:37 +00001802multiclass ShuffleBytes
1803{
1804 def v16i8 : SHUFBVecInst<v16i8>;
1805 def v8i16 : SHUFBVecInst<v8i16>;
1806 def v4i32 : SHUFBVecInst<v4i32>;
1807 def v2i64 : SHUFBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001808
Scott Michel97872d32008-02-23 18:41:37 +00001809 def v4f32 : SHUFBVecInst<v4f32>;
1810 def v2f64 : SHUFBVecInst<v2f64>;
1811}
1812
1813defm SHUFB : ShuffleBytes;
1814
Scott Michel67224b22008-06-02 22:18:03 +00001815// Shuffle mask is a v16i8 vector
1816def : SHUFBVecPat1<v8i16, v16i8, SHUFBv16i8>;
1817def : SHUFBVecPat1<v4i32, v16i8, SHUFBv16i8>;
1818def : SHUFBVecPat1<v2i64, v16i8, SHUFBv16i8>;
1819def : SHUFBVecPat1<v4f32, v16i8, SHUFBv16i8>;
1820def : SHUFBVecPat1<v2f64, v16i8, SHUFBv16i8>;
1821
1822// Shuffle mask is a v4i32 vector:
Scott Michel56a125e2008-11-22 23:50:42 +00001823def : SHUFBVecPat1<v16i8, v4i32, SHUFBv4i32>;
Scott Michel67224b22008-06-02 22:18:03 +00001824def : SHUFBVecPat1<v8i16, v4i32, SHUFBv4i32>;
Scott Michel67224b22008-06-02 22:18:03 +00001825def : SHUFBVecPat1<v2i64, v4i32, SHUFBv4i32>;
1826def : SHUFBVecPat1<v4f32, v4i32, SHUFBv4i32>;
1827def : SHUFBVecPat1<v2f64, v4i32, SHUFBv4i32>;
Scott Michel754d8662007-12-20 00:44:13 +00001828
Scott Michel8b6b4202007-12-04 22:35:58 +00001829//===----------------------------------------------------------------------===//
1830// Shift and rotate group:
1831//===----------------------------------------------------------------------===//
1832
Scott Michel97872d32008-02-23 18:41:37 +00001833class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
1834 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
1835 RotateShift, pattern>;
1836
1837class SHLHVecInst<ValueType vectype>:
1838 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1839 [(set (vectype VECREG:$rT),
1840 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001841
1842// $rB gets promoted to 32-bit register type when confronted with
1843// this llvm assembly code:
1844//
1845// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
1846// %A = shl i16 %arg1, %arg2
1847// ret i16 %A
1848// }
Scott Michel8b6b4202007-12-04 22:35:58 +00001849
Scott Michel97872d32008-02-23 18:41:37 +00001850multiclass ShiftLeftHalfword
1851{
1852 def v8i16: SHLHVecInst<v8i16>;
1853 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1854 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
1855 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
1856 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
1857}
Scott Michel8b6b4202007-12-04 22:35:58 +00001858
Scott Michel97872d32008-02-23 18:41:37 +00001859defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001860
Scott Michel97872d32008-02-23 18:41:37 +00001861//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00001862
Scott Michel97872d32008-02-23 18:41:37 +00001863class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
1864 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
1865 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001866
Scott Michel97872d32008-02-23 18:41:37 +00001867class SHLHIVecInst<ValueType vectype>:
1868 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
1869 [(set (vectype VECREG:$rT),
1870 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001871
Scott Michel97872d32008-02-23 18:41:37 +00001872multiclass ShiftLeftHalfwordImm
1873{
1874 def v8i16: SHLHIVecInst<v8i16>;
1875 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
1876 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
1877}
1878
1879defm SHLHI : ShiftLeftHalfwordImm;
1880
1881def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
1882 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
1883
1884def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00001885 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001886
Scott Michel97872d32008-02-23 18:41:37 +00001887//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001888
Scott Michel97872d32008-02-23 18:41:37 +00001889class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
1890 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
1891 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001892
Scott Michel97872d32008-02-23 18:41:37 +00001893multiclass ShiftLeftWord
1894{
1895 def v4i32:
1896 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1897 [(set (v4i32 VECREG:$rT),
1898 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
1899 def r32:
1900 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1901 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
1902}
Scott Michel8b6b4202007-12-04 22:35:58 +00001903
Scott Michel97872d32008-02-23 18:41:37 +00001904defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00001905
Scott Michel97872d32008-02-23 18:41:37 +00001906//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001907
Scott Michel97872d32008-02-23 18:41:37 +00001908class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
1909 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
1910 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001911
Scott Michel97872d32008-02-23 18:41:37 +00001912multiclass ShiftLeftWordImm
1913{
1914 def v4i32:
1915 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1916 [(set (v4i32 VECREG:$rT),
1917 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001918
Scott Michel97872d32008-02-23 18:41:37 +00001919 def r32:
1920 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
1921 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
1922}
Scott Michel8b6b4202007-12-04 22:35:58 +00001923
Scott Michel97872d32008-02-23 18:41:37 +00001924defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00001925
Scott Michel97872d32008-02-23 18:41:37 +00001926//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001927// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
1928// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00001929//
1930// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
1931// of 7 bits is actually possible.
1932//
1933// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
1934// to shift i64 and i128. SHLQBI is the residual left over after shifting by
1935// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00001936
Scott Michel97872d32008-02-23 18:41:37 +00001937class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
1938 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
1939 RotateShift, pattern>;
1940
1941class SHLQBIVecInst<ValueType vectype>:
1942 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1943 [(set (vectype VECREG:$rT),
1944 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
1945
1946multiclass ShiftLeftQuadByBits
1947{
1948 def v16i8: SHLQBIVecInst<v16i8>;
1949 def v8i16: SHLQBIVecInst<v8i16>;
1950 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00001951 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00001952 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00001953 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00001954}
1955
1956defm SHLQBI : ShiftLeftQuadByBits;
1957
1958// See note above on SHLQBI. In this case, the predicate actually does then
1959// enforcement, whereas with SHLQBI, we have to "take it on faith."
1960class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
1961 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
1962 RotateShift, pattern>;
1963
1964class SHLQBIIVecInst<ValueType vectype>:
1965 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1966 [(set (vectype VECREG:$rT),
1967 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
1968
1969multiclass ShiftLeftQuadByBitsImm
1970{
1971 def v16i8 : SHLQBIIVecInst<v16i8>;
1972 def v8i16 : SHLQBIIVecInst<v8i16>;
1973 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00001974 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00001975 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00001976 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00001977}
1978
1979defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001980
1981// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00001982// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00001983
Scott Michel97872d32008-02-23 18:41:37 +00001984class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
1985 RI7Form<0b11111011100, OOL, IOL, "shlqbyi\t$rT, $rA, $rB",
1986 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001987
Scott Michel97872d32008-02-23 18:41:37 +00001988class SHLQBYVecInst<ValueType vectype>:
1989 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1990 [(set (vectype VECREG:$rT),
1991 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001992
Scott Michel97872d32008-02-23 18:41:37 +00001993multiclass ShiftLeftQuadBytes
1994{
1995 def v16i8: SHLQBYVecInst<v16i8>;
1996 def v8i16: SHLQBYVecInst<v8i16>;
1997 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00001998 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00001999 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002000 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002001 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2002 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2003}
Scott Michel8b6b4202007-12-04 22:35:58 +00002004
Scott Michel97872d32008-02-23 18:41:37 +00002005defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002006
Scott Michel97872d32008-02-23 18:41:37 +00002007class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2008 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2009 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002010
Scott Michel97872d32008-02-23 18:41:37 +00002011class SHLQBYIVecInst<ValueType vectype>:
2012 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2013 [(set (vectype VECREG:$rT),
2014 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002015
Scott Michel97872d32008-02-23 18:41:37 +00002016multiclass ShiftLeftQuadBytesImm
2017{
2018 def v16i8: SHLQBYIVecInst<v16i8>;
2019 def v8i16: SHLQBYIVecInst<v8i16>;
2020 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002021 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002022 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002023 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002024 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2025 [(set GPRC:$rT,
2026 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2027}
Scott Michel438be252007-12-17 22:32:34 +00002028
Scott Michel97872d32008-02-23 18:41:37 +00002029defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002030
Scott Michel97872d32008-02-23 18:41:37 +00002031// Special form for truncating i64 to i32:
2032def SHLQBYItrunc64: SHLQBYIInst<(outs R32C:$rT), (ins R64C:$rA, u7imm_i32:$val),
2033 [/* no pattern, see below */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002034
Scott Michel97872d32008-02-23 18:41:37 +00002035def : Pat<(trunc R64C:$rSrc),
2036 (SHLQBYItrunc64 R64C:$rSrc, 4)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002037
Scott Michel97872d32008-02-23 18:41:37 +00002038//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2039// Rotate halfword:
2040//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2041class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2042 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2043 RotateShift, pattern>;
2044
2045class ROTHVecInst<ValueType vectype>:
2046 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2047 [(set (vectype VECREG:$rT),
2048 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2049
2050class ROTHRegInst<RegisterClass rclass>:
2051 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2052 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2053
2054multiclass RotateLeftHalfword
2055{
2056 def v8i16: ROTHVecInst<v8i16>;
2057 def r16: ROTHRegInst<R16C>;
2058}
2059
2060defm ROTH: RotateLeftHalfword;
2061
2062def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2063 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2064
2065//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2066// Rotate halfword, immediate:
2067//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2068class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2069 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2070 RotateShift, pattern>;
2071
2072class ROTHIVecInst<ValueType vectype>:
2073 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2074 [(set (vectype VECREG:$rT),
2075 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2076
2077multiclass RotateLeftHalfwordImm
2078{
2079 def v8i16: ROTHIVecInst<v8i16>;
2080 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2081 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2082 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2083 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2084}
2085
2086defm ROTHI: RotateLeftHalfwordImm;
2087
2088def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002089 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
2090
Scott Michel97872d32008-02-23 18:41:37 +00002091//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2092// Rotate word:
2093//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002094
Scott Michel97872d32008-02-23 18:41:37 +00002095class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2096 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2097 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002098
Scott Michel97872d32008-02-23 18:41:37 +00002099class ROTVecInst<ValueType vectype>:
2100 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2101 [(set (vectype VECREG:$rT),
2102 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002103
Scott Michel97872d32008-02-23 18:41:37 +00002104class ROTRegInst<RegisterClass rclass>:
2105 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2106 [(set rclass:$rT,
2107 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002108
Scott Michel97872d32008-02-23 18:41:37 +00002109multiclass RotateLeftWord
2110{
2111 def v4i32: ROTVecInst<v4i32>;
2112 def r32: ROTRegInst<R32C>;
2113}
2114
2115defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002116
Scott Michel438be252007-12-17 22:32:34 +00002117// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2118// 32-bit register
2119def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002120 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2121 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002122
2123def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2124 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2125
2126def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2127 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2128
2129def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002130 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2131 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002132
2133def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2134 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2135
2136def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2137 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2138
Scott Michel97872d32008-02-23 18:41:37 +00002139//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2140// Rotate word, immediate
2141//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002142
Scott Michel97872d32008-02-23 18:41:37 +00002143class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2144 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2145 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002146
Scott Michel97872d32008-02-23 18:41:37 +00002147class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2148 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2149 [(set (vectype VECREG:$rT),
2150 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002151
Scott Michel97872d32008-02-23 18:41:37 +00002152class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2153 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2154 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002155
Scott Michel97872d32008-02-23 18:41:37 +00002156multiclass RotateLeftWordImm
2157{
2158 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2159 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2160 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002161
Scott Michel97872d32008-02-23 18:41:37 +00002162 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2163 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2164 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2165}
Scott Michel438be252007-12-17 22:32:34 +00002166
Scott Michel97872d32008-02-23 18:41:37 +00002167defm ROTI : RotateLeftWordImm;
2168
2169//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2170// Rotate quad by byte (count)
2171//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2172
2173class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2174 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2175 RotateShift, pattern>;
2176
2177class ROTQBYVecInst<ValueType vectype>:
2178 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2179 [(set (vectype VECREG:$rT),
2180 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2181
2182multiclass RotateQuadLeftByBytes
2183{
2184 def v16i8: ROTQBYVecInst<v16i8>;
2185 def v8i16: ROTQBYVecInst<v8i16>;
2186 def v4i32: ROTQBYVecInst<v4i32>;
2187 def v2i64: ROTQBYVecInst<v2i64>;
2188}
2189
2190defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002191
Scott Micheldbac4cf2008-01-11 02:53:15 +00002192def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002193 (ROTQBYv16i8 VECREG:$rA, R32C:$rB)>;
2194def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), R32C:$rB),
2195 (ROTQBYv8i16 VECREG:$rA, R32C:$rB)>;
2196def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), R32C:$rB),
2197 (ROTQBYv4i32 VECREG:$rA, R32C:$rB)>;
2198def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), R32C:$rB),
2199 (ROTQBYv2i64 VECREG:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002200
Scott Michel97872d32008-02-23 18:41:37 +00002201//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2202// Rotate quad by byte (count), immediate
2203//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2204
2205class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2206 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2207 RotateShift, pattern>;
2208
2209class ROTQBYIVecInst<ValueType vectype>:
2210 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2211 [(set (vectype VECREG:$rT),
2212 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2213
2214multiclass RotateQuadByBytesImm
2215{
2216 def v16i8: ROTQBYIVecInst<v16i8>;
2217 def v8i16: ROTQBYIVecInst<v8i16>;
2218 def v4i32: ROTQBYIVecInst<v4i32>;
2219 def v2i64: ROTQBYIVecInst<v2i64>;
2220}
2221
2222defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002223
2224def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel97872d32008-02-23 18:41:37 +00002225 (ROTQBYIv16i8 VECREG:$rA, uimm7:$val)>;
2226def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), (i16 uimm7:$val)),
2227 (ROTQBYIv8i16 VECREG:$rA, uimm7:$val)>;
2228def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2229 (ROTQBYIv4i32 VECREG:$rA, uimm7:$val)>;
2230def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), (i16 uimm7:$val)),
2231 (ROTQBYIv2i64 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002232
2233// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002234class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2235 RI7Form<0b00110011100, OOL, IOL,
2236 "rotqbybi\t$rT, $rA, $shift",
2237 RotateShift, pattern>;
2238
2239class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2240 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2241 [(set (vectype VECREG:$rT),
2242 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2243
2244multiclass RotateQuadByBytesByBitshift {
2245 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2246 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2247 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2248 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2249}
2250
2251defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002252
Scott Michel97872d32008-02-23 18:41:37 +00002253//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002254// See ROTQBY note above.
2255//
2256// Assume that the user of this instruction knows to shift the rotate count
2257// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002258//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002259
Scott Michel97872d32008-02-23 18:41:37 +00002260class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2261 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2262 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002263
Scott Michel97872d32008-02-23 18:41:37 +00002264class ROTQBIVecInst<ValueType vectype>:
2265 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2266 [/* no pattern yet */]>;
2267
2268class ROTQBIRegInst<RegisterClass rclass>:
2269 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2270 [/* no pattern yet */]>;
2271
2272multiclass RotateQuadByBitCount
2273{
2274 def v16i8: ROTQBIVecInst<v16i8>;
2275 def v8i16: ROTQBIVecInst<v8i16>;
2276 def v4i32: ROTQBIVecInst<v4i32>;
2277 def v2i64: ROTQBIVecInst<v2i64>;
2278
2279 def r128: ROTQBIRegInst<GPRC>;
2280 def r64: ROTQBIRegInst<R64C>;
2281}
2282
2283defm ROTQBI: RotateQuadByBitCount;
2284
2285class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2286 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2287 RotateShift, pattern>;
2288
2289class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2290 PatLeaf pred>:
2291 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2292 [/* no pattern yet */]>;
2293
2294class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2295 PatLeaf pred>:
2296 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2297 [/* no pattern yet */]>;
2298
2299multiclass RotateQuadByBitCountImm
2300{
2301 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2302 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2303 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2304 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2305
2306 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2307 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2308}
2309
2310defm ROTQBII : RotateQuadByBitCountImm;
2311
2312//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002313// ROTHM v8i16 form:
2314// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2315// so this only matches a synthetically generated/lowered code
2316// fragment.
2317// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002318//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002319
Scott Michel97872d32008-02-23 18:41:37 +00002320class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2321 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2322 RotateShift, pattern>;
2323
2324def ROTHMv8i16:
2325 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2326 [/* see patterns below - $rB must be negated */]>;
2327
2328def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002329 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2330
Scott Michel97872d32008-02-23 18:41:37 +00002331def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002332 (ROTHMv8i16 VECREG:$rA,
2333 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2334
Scott Michel97872d32008-02-23 18:41:37 +00002335def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002336 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002337 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002338
2339// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2340// Note: This instruction doesn't match a pattern because rB must be negated
2341// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002342
Scott Michel8b6b4202007-12-04 22:35:58 +00002343def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002344 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2345 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002346
2347def : Pat<(srl R16C:$rA, R32C:$rB),
2348 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2349
2350def : Pat<(srl R16C:$rA, R16C:$rB),
2351 (ROTHMr16 R16C:$rA,
2352 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2353
Scott Michel438be252007-12-17 22:32:34 +00002354def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002355 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002356 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002357
2358// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2359// that the immediate can be complemented, so that the user doesn't have to
2360// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002361
Scott Michel97872d32008-02-23 18:41:37 +00002362class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2363 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2364 RotateShift, pattern>;
2365
2366def ROTHMIv8i16:
2367 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2368 [/* no pattern */]>;
2369
2370def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2371 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2372
2373def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002374 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002375
Scott Michel97872d32008-02-23 18:41:37 +00002376def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002377 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002378
2379def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002380 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2381 [/* no pattern */]>;
2382
2383def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2384 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002385
2386def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2387 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2388
Scott Michel438be252007-12-17 22:32:34 +00002389def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2390 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2391
Scott Michel8b6b4202007-12-04 22:35:58 +00002392// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002393class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2394 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2395 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002396
Scott Michel97872d32008-02-23 18:41:37 +00002397def ROTMv4i32:
2398 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2399 [/* see patterns below - $rB must be negated */]>;
2400
2401def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002402 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2403
Scott Michel97872d32008-02-23 18:41:37 +00002404def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002405 (ROTMv4i32 VECREG:$rA,
2406 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2407
Scott Michel97872d32008-02-23 18:41:37 +00002408def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002409 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002410 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002411
2412def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002413 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2414 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002415
2416def : Pat<(srl R32C:$rA, R32C:$rB),
2417 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2418
2419def : Pat<(srl R32C:$rA, R16C:$rB),
2420 (ROTMr32 R32C:$rA,
2421 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2422
Scott Michel438be252007-12-17 22:32:34 +00002423def : Pat<(srl R32C:$rA, R8C:$rB),
2424 (ROTMr32 R32C:$rA,
2425 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2426
Scott Michel8b6b4202007-12-04 22:35:58 +00002427// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2428def ROTMIv4i32:
2429 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2430 "rotmi\t$rT, $rA, $val", RotateShift,
2431 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002432 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002433
Scott Michel97872d32008-02-23 18:41:37 +00002434def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002435 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002436
Scott Michel97872d32008-02-23 18:41:37 +00002437def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002438 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002439
2440// ROTMI r32 form: know how to complement the immediate value.
2441def ROTMIr32:
2442 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2443 "rotmi\t$rT, $rA, $val", RotateShift,
2444 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2445
2446def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2447 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2448
Scott Michel438be252007-12-17 22:32:34 +00002449def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2450 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2451
Scott Michel97872d32008-02-23 18:41:37 +00002452//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002453// ROTQMBYvec: This is a vector form merely so that when used in an
2454// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002455// that the user knew to negate $rB.
2456//
2457// Using the SPUrotquad_rz_bytes target-specific DAG node, the patterns
2458// ensure that $rB is negated.
2459//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002460
Scott Michel97872d32008-02-23 18:41:37 +00002461class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2462 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2463 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002464
Scott Michel97872d32008-02-23 18:41:37 +00002465class ROTQMBYVecInst<ValueType vectype>:
2466 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2467 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002468
Scott Michel97872d32008-02-23 18:41:37 +00002469class ROTQMBYRegInst<RegisterClass rclass>:
2470 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2471 [(set rclass:$rT,
2472 (SPUrotquad_rz_bytes rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002473
Scott Michel97872d32008-02-23 18:41:37 +00002474multiclass RotateQuadBytes
2475{
2476 def v16i8: ROTQMBYVecInst<v16i8>;
2477 def v8i16: ROTQMBYVecInst<v8i16>;
2478 def v4i32: ROTQMBYVecInst<v4i32>;
2479 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002480
Scott Michel97872d32008-02-23 18:41:37 +00002481 def r128: ROTQMBYRegInst<GPRC>;
2482 def r64: ROTQMBYRegInst<R64C>;
2483}
2484
2485defm ROTQMBY : RotateQuadBytes;
2486
2487def : Pat<(SPUrotquad_rz_bytes (v16i8 VECREG:$rA), R32C:$rB),
2488 (ROTQMBYv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2489def : Pat<(SPUrotquad_rz_bytes (v8i16 VECREG:$rA), R32C:$rB),
2490 (ROTQMBYv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2491def : Pat<(SPUrotquad_rz_bytes (v4i32 VECREG:$rA), R32C:$rB),
2492 (ROTQMBYv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2493def : Pat<(SPUrotquad_rz_bytes (v2i64 VECREG:$rA), R32C:$rB),
2494 (ROTQMBYv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2495def : Pat<(SPUrotquad_rz_bytes GPRC:$rA, R32C:$rB),
2496 (ROTQMBYr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2497def : Pat<(SPUrotquad_rz_bytes R64C:$rA, R32C:$rB),
2498 (ROTQMBYr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2499
2500class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2501 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2502 RotateShift, pattern>;
2503
2504class ROTQMBYIVecInst<ValueType vectype>:
2505 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2506 [(set (vectype VECREG:$rT),
2507 (SPUrotquad_rz_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2508
2509class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2510 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2511 [(set rclass:$rT,
2512 (SPUrotquad_rz_bytes rclass:$rA, (inttype pred:$val)))]>;
2513
2514multiclass RotateQuadBytesImm
2515{
2516 def v16i8: ROTQMBYIVecInst<v16i8>;
2517 def v8i16: ROTQMBYIVecInst<v8i16>;
2518 def v4i32: ROTQMBYIVecInst<v4i32>;
2519 def v2i64: ROTQMBYIVecInst<v2i64>;
2520
2521 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2522 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2523}
2524
2525defm ROTQMBYI : RotateQuadBytesImm;
2526
Scott Michel97872d32008-02-23 18:41:37 +00002527//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2528// Rotate right and mask by bit count
2529//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2530
2531class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2532 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2533 RotateShift, pattern>;
2534
2535class ROTQMBYBIVecInst<ValueType vectype>:
2536 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2537 [/* no pattern, intrinsic? */]>;
2538
2539multiclass RotateMaskQuadByBitCount
2540{
2541 def v16i8: ROTQMBYBIVecInst<v16i8>;
2542 def v8i16: ROTQMBYBIVecInst<v8i16>;
2543 def v4i32: ROTQMBYBIVecInst<v4i32>;
2544 def v2i64: ROTQMBYBIVecInst<v2i64>;
2545}
2546
2547defm ROTQMBYBI: RotateMaskQuadByBitCount;
2548
2549//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2550// Rotate quad and mask by bits
2551// Note that the rotate amount has to be negated
2552//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2553
2554class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2555 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2556 RotateShift, pattern>;
2557
2558class ROTQMBIVecInst<ValueType vectype>:
2559 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2560 [/* no pattern */]>;
2561
2562class ROTQMBIRegInst<RegisterClass rclass>:
2563 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2564 [/* no pattern */]>;
2565
2566multiclass RotateMaskQuadByBits
2567{
2568 def v16i8: ROTQMBIVecInst<v16i8>;
2569 def v8i16: ROTQMBIVecInst<v8i16>;
2570 def v4i32: ROTQMBIVecInst<v4i32>;
2571 def v2i64: ROTQMBIVecInst<v2i64>;
2572
2573 def r128: ROTQMBIRegInst<GPRC>;
2574 def r64: ROTQMBIRegInst<R64C>;
2575}
2576
2577defm ROTQMBI: RotateMaskQuadByBits;
2578
2579def : Pat<(SPUrotquad_rz_bits (v16i8 VECREG:$rA), R32C:$rB),
2580 (ROTQMBIv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2581def : Pat<(SPUrotquad_rz_bits (v8i16 VECREG:$rA), R32C:$rB),
2582 (ROTQMBIv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2583def : Pat<(SPUrotquad_rz_bits (v4i32 VECREG:$rA), R32C:$rB),
2584 (ROTQMBIv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2585def : Pat<(SPUrotquad_rz_bits (v2i64 VECREG:$rA), R32C:$rB),
2586 (ROTQMBIv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2587def : Pat<(SPUrotquad_rz_bits GPRC:$rA, R32C:$rB),
2588 (ROTQMBIr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2589def : Pat<(SPUrotquad_rz_bits R64C:$rA, R32C:$rB),
2590 (ROTQMBIr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2591
2592//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2593// Rotate quad and mask by bits, immediate
2594//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2595
2596class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2597 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2598 RotateShift, pattern>;
2599
2600class ROTQMBIIVecInst<ValueType vectype>:
2601 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2602 [(set (vectype VECREG:$rT),
2603 (SPUrotquad_rz_bits (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2604
2605class ROTQMBIIRegInst<RegisterClass rclass>:
2606 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2607 [(set rclass:$rT,
2608 (SPUrotquad_rz_bits rclass:$rA, (i32 uimm7:$val)))]>;
2609
2610multiclass RotateMaskQuadByBitsImm
2611{
2612 def v16i8: ROTQMBIIVecInst<v16i8>;
2613 def v8i16: ROTQMBIIVecInst<v8i16>;
2614 def v4i32: ROTQMBIIVecInst<v4i32>;
2615 def v2i64: ROTQMBIIVecInst<v2i64>;
2616
2617 def r128: ROTQMBIIRegInst<GPRC>;
2618 def r64: ROTQMBIIRegInst<R64C>;
2619}
2620
2621defm ROTQMBII: RotateMaskQuadByBitsImm;
2622
2623//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2624//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002625
2626def ROTMAHv8i16:
2627 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2628 "rotmah\t$rT, $rA, $rB", RotateShift,
2629 [/* see patterns below - $rB must be negated */]>;
2630
Scott Michel97872d32008-02-23 18:41:37 +00002631def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002632 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2633
Scott Michel97872d32008-02-23 18:41:37 +00002634def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002635 (ROTMAHv8i16 VECREG:$rA,
2636 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2637
Scott Michel97872d32008-02-23 18:41:37 +00002638def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002639 (ROTMAHv8i16 VECREG:$rA,
2640 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2641
Scott Michel8b6b4202007-12-04 22:35:58 +00002642def ROTMAHr16:
2643 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2644 "rotmah\t$rT, $rA, $rB", RotateShift,
2645 [/* see patterns below - $rB must be negated */]>;
2646
2647def : Pat<(sra R16C:$rA, R32C:$rB),
2648 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2649
2650def : Pat<(sra R16C:$rA, R16C:$rB),
2651 (ROTMAHr16 R16C:$rA,
2652 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2653
Scott Michel438be252007-12-17 22:32:34 +00002654def : Pat<(sra R16C:$rA, R8C:$rB),
2655 (ROTMAHr16 R16C:$rA,
2656 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2657
Scott Michel8b6b4202007-12-04 22:35:58 +00002658def ROTMAHIv8i16:
2659 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2660 "rotmahi\t$rT, $rA, $val", RotateShift,
2661 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002662 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002663
Scott Michel97872d32008-02-23 18:41:37 +00002664def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002665 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2666
Scott Michel97872d32008-02-23 18:41:37 +00002667def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002668 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2669
Scott Michel8b6b4202007-12-04 22:35:58 +00002670def ROTMAHIr16:
2671 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2672 "rotmahi\t$rT, $rA, $val", RotateShift,
2673 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2674
2675def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2676 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2677
Scott Michel438be252007-12-17 22:32:34 +00002678def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2679 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2680
Scott Michel8b6b4202007-12-04 22:35:58 +00002681def ROTMAv4i32:
2682 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2683 "rotma\t$rT, $rA, $rB", RotateShift,
2684 [/* see patterns below - $rB must be negated */]>;
2685
Scott Michel97872d32008-02-23 18:41:37 +00002686def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002687 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2688
Scott Michel97872d32008-02-23 18:41:37 +00002689def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002690 (ROTMAv4i32 (v4i32 VECREG:$rA),
2691 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2692
Scott Michel97872d32008-02-23 18:41:37 +00002693def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002694 (ROTMAv4i32 (v4i32 VECREG:$rA),
2695 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2696
Scott Michel8b6b4202007-12-04 22:35:58 +00002697def ROTMAr32:
2698 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2699 "rotma\t$rT, $rA, $rB", RotateShift,
2700 [/* see patterns below - $rB must be negated */]>;
2701
2702def : Pat<(sra R32C:$rA, R32C:$rB),
2703 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2704
2705def : Pat<(sra R32C:$rA, R16C:$rB),
2706 (ROTMAr32 R32C:$rA,
2707 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2708
Scott Michel438be252007-12-17 22:32:34 +00002709def : Pat<(sra R32C:$rA, R8C:$rB),
2710 (ROTMAr32 R32C:$rA,
2711 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2712
Scott Michel67224b22008-06-02 22:18:03 +00002713class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2714 RRForm<0b01011110000, OOL, IOL,
2715 "rotmai\t$rT, $rA, $val",
2716 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002717
Scott Michel67224b22008-06-02 22:18:03 +00002718class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2719 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2720 [(set (vectype VECREG:$rT),
2721 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002722
Scott Michel67224b22008-06-02 22:18:03 +00002723class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2724 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2725 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002726
Scott Michel67224b22008-06-02 22:18:03 +00002727multiclass RotateMaskAlgebraicImm {
2728 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2729 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2730 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2731 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2732}
Scott Michel8b6b4202007-12-04 22:35:58 +00002733
Scott Michel67224b22008-06-02 22:18:03 +00002734defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00002735
Scott Michel8b6b4202007-12-04 22:35:58 +00002736//===----------------------------------------------------------------------===//
2737// Branch and conditionals:
2738//===----------------------------------------------------------------------===//
2739
2740let isTerminator = 1, isBarrier = 1 in {
2741 // Halt If Equal (r32 preferred slot only, no vector form)
2742 def HEQr32:
2743 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2744 "heq\t$rA, $rB", BranchResolv,
2745 [/* no pattern to match */]>;
2746
2747 def HEQIr32 :
2748 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2749 "heqi\t$rA, $val", BranchResolv,
2750 [/* no pattern to match */]>;
2751
2752 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2753 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2754 def HGTr32:
2755 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2756 "hgt\t$rA, $rB", BranchResolv,
2757 [/* no pattern to match */]>;
2758
2759 def HGTIr32:
2760 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2761 "hgti\t$rA, $val", BranchResolv,
2762 [/* no pattern to match */]>;
2763
2764 def HLGTr32:
2765 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2766 "hlgt\t$rA, $rB", BranchResolv,
2767 [/* no pattern to match */]>;
2768
2769 def HLGTIr32:
2770 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2771 "hlgti\t$rA, $val", BranchResolv,
2772 [/* no pattern to match */]>;
2773}
2774
Scott Michel97872d32008-02-23 18:41:37 +00002775//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002776// Comparison operators:
Scott Michel97872d32008-02-23 18:41:37 +00002777//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002778
Scott Michel97872d32008-02-23 18:41:37 +00002779class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2780 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2781 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002782
Scott Michel97872d32008-02-23 18:41:37 +00002783multiclass CmpEqualByte
2784{
2785 def v16i8 :
2786 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2787 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2788 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002789
Scott Michel97872d32008-02-23 18:41:37 +00002790 def r8 :
2791 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2792 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2793}
Scott Michel8b6b4202007-12-04 22:35:58 +00002794
Scott Michel97872d32008-02-23 18:41:37 +00002795class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2796 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2797 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002798
Scott Michel97872d32008-02-23 18:41:37 +00002799multiclass CmpEqualByteImm
2800{
2801 def v16i8 :
2802 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2803 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2804 v16i8SExt8Imm:$val))]>;
2805 def r8:
2806 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2807 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
2808}
Scott Michel8b6b4202007-12-04 22:35:58 +00002809
Scott Michel97872d32008-02-23 18:41:37 +00002810class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
2811 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
2812 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002813
Scott Michel97872d32008-02-23 18:41:37 +00002814multiclass CmpEqualHalfword
2815{
2816 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2817 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2818 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002819
Scott Michel97872d32008-02-23 18:41:37 +00002820 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2821 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
2822}
Scott Michel8b6b4202007-12-04 22:35:58 +00002823
Scott Michel97872d32008-02-23 18:41:37 +00002824class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
2825 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
2826 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002827
Scott Michel97872d32008-02-23 18:41:37 +00002828multiclass CmpEqualHalfwordImm
2829{
2830 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2831 [(set (v8i16 VECREG:$rT),
2832 (seteq (v8i16 VECREG:$rA),
2833 (v8i16 v8i16SExt10Imm:$val)))]>;
2834 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2835 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
2836}
Scott Michel8b6b4202007-12-04 22:35:58 +00002837
Scott Michel97872d32008-02-23 18:41:37 +00002838class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
2839 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
2840 ByteOp, pattern>;
2841
2842multiclass CmpEqualWord
2843{
2844 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2845 [(set (v4i32 VECREG:$rT),
2846 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2847
2848 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2849 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
2850}
2851
2852class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
2853 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
2854 ByteOp, pattern>;
2855
2856multiclass CmpEqualWordImm
2857{
2858 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2859 [(set (v4i32 VECREG:$rT),
2860 (seteq (v4i32 VECREG:$rA),
2861 (v4i32 v4i32SExt16Imm:$val)))]>;
2862
2863 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2864 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
2865}
2866
2867class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
2868 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
2869 ByteOp, pattern>;
2870
2871multiclass CmpGtrByte
2872{
2873 def v16i8 :
2874 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2875 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2876 (v8i16 VECREG:$rB)))]>;
2877
2878 def r8 :
2879 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2880 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
2881}
2882
2883class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
2884 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
2885 ByteOp, pattern>;
2886
2887multiclass CmpGtrByteImm
2888{
2889 def v16i8 :
2890 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2891 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
2892 v16i8SExt8Imm:$val))]>;
2893 def r8:
2894 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00002895 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002896}
2897
2898class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
2899 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
2900 ByteOp, pattern>;
2901
2902multiclass CmpGtrHalfword
2903{
2904 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2905 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2906 (v8i16 VECREG:$rB)))]>;
2907
2908 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2909 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
2910}
2911
2912class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
2913 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
2914 ByteOp, pattern>;
2915
2916multiclass CmpGtrHalfwordImm
2917{
2918 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2919 [(set (v8i16 VECREG:$rT),
2920 (setgt (v8i16 VECREG:$rA),
2921 (v8i16 v8i16SExt10Imm:$val)))]>;
2922 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2923 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
2924}
2925
2926class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
2927 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
2928 ByteOp, pattern>;
2929
2930multiclass CmpGtrWord
2931{
2932 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2933 [(set (v4i32 VECREG:$rT),
2934 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2935
2936 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2937 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
2938}
2939
2940class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
2941 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
2942 ByteOp, pattern>;
2943
2944multiclass CmpGtrWordImm
2945{
2946 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2947 [(set (v4i32 VECREG:$rT),
2948 (setgt (v4i32 VECREG:$rA),
2949 (v4i32 v4i32SExt16Imm:$val)))]>;
2950
2951 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2952 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
2953}
2954
2955class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002956 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002957 ByteOp, pattern>;
2958
2959multiclass CmpLGtrByte
2960{
2961 def v16i8 :
2962 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2963 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2964 (v8i16 VECREG:$rB)))]>;
2965
2966 def r8 :
2967 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2968 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
2969}
2970
2971class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002972 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002973 ByteOp, pattern>;
2974
2975multiclass CmpLGtrByteImm
2976{
2977 def v16i8 :
2978 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2979 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
2980 v16i8SExt8Imm:$val))]>;
2981 def r8:
2982 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2983 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
2984}
2985
2986class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002987 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002988 ByteOp, pattern>;
2989
2990multiclass CmpLGtrHalfword
2991{
2992 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2993 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2994 (v8i16 VECREG:$rB)))]>;
2995
2996 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2997 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
2998}
2999
3000class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003001 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003002 ByteOp, pattern>;
3003
3004multiclass CmpLGtrHalfwordImm
3005{
3006 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3007 [(set (v8i16 VECREG:$rT),
3008 (setugt (v8i16 VECREG:$rA),
3009 (v8i16 v8i16SExt10Imm:$val)))]>;
3010 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3011 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3012}
3013
3014class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003015 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003016 ByteOp, pattern>;
3017
3018multiclass CmpLGtrWord
3019{
3020 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3021 [(set (v4i32 VECREG:$rT),
3022 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3023
3024 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3025 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3026}
3027
3028class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003029 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003030 ByteOp, pattern>;
3031
3032multiclass CmpLGtrWordImm
3033{
3034 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3035 [(set (v4i32 VECREG:$rT),
3036 (setugt (v4i32 VECREG:$rA),
3037 (v4i32 v4i32SExt16Imm:$val)))]>;
3038
3039 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003040 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003041}
3042
3043defm CEQB : CmpEqualByte;
3044defm CEQBI : CmpEqualByteImm;
3045defm CEQH : CmpEqualHalfword;
3046defm CEQHI : CmpEqualHalfwordImm;
3047defm CEQ : CmpEqualWord;
3048defm CEQI : CmpEqualWordImm;
3049defm CGTB : CmpGtrByte;
3050defm CGTBI : CmpGtrByteImm;
3051defm CGTH : CmpGtrHalfword;
3052defm CGTHI : CmpGtrHalfwordImm;
3053defm CGT : CmpGtrWord;
3054defm CGTI : CmpGtrWordImm;
3055defm CLGTB : CmpLGtrByte;
3056defm CLGTBI : CmpLGtrByteImm;
3057defm CLGTH : CmpLGtrHalfword;
3058defm CLGTHI : CmpLGtrHalfwordImm;
3059defm CLGT : CmpLGtrWord;
3060defm CLGTI : CmpLGtrWordImm;
3061
Scott Michel53ab7792008-03-10 16:58:52 +00003062//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003063// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3064// define a pattern to generate the right code, as a binary operator
3065// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003066//
3067// N.B.: This only matches the setcc set of conditionals. Special pattern
3068// matching is used for select conditionals.
3069//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003070
Scott Michel53ab7792008-03-10 16:58:52 +00003071class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3072 SPUInstr xorinst, SPUInstr cmpare>:
3073 Pat<(cond rclass:$rA, rclass:$rB),
3074 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3075
3076class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3077 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3078 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3079 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3080
3081def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
3082def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3083
3084def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
3085def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3086
3087def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3088def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003089
3090class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3091 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3092 Pat<(cond rclass:$rA, rclass:$rB),
3093 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3094 (cmpOp2 rclass:$rA, rclass:$rB))>;
3095
3096class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3097 ValueType immtype,
3098 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3099 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3100 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3101 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3102
Scott Michel53ab7792008-03-10 16:58:52 +00003103def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3104def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3105def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3106def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3107def : Pat<(setle R8C:$rA, R8C:$rB),
3108 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3109def : Pat<(setle R8C:$rA, immU8:$imm),
3110 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003111
Scott Michel53ab7792008-03-10 16:58:52 +00003112def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3113def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3114 ORr16, CGTHIr16, CEQHIr16>;
3115def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3116def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3117def : Pat<(setle R16C:$rA, R16C:$rB),
3118 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3119def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3120 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003121
Scott Michel53ab7792008-03-10 16:58:52 +00003122def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3123def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3124 ORr32, CGTIr32, CEQIr32>;
3125def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3126def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3127def : Pat<(setle R32C:$rA, R32C:$rB),
3128 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3129def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3130 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003131
Scott Michel53ab7792008-03-10 16:58:52 +00003132def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3133def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3134def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3135def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3136def : Pat<(setule R8C:$rA, R8C:$rB),
3137 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3138def : Pat<(setule R8C:$rA, immU8:$imm),
3139 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003140
Scott Michel53ab7792008-03-10 16:58:52 +00003141def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3142def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3143 ORr16, CLGTHIr16, CEQHIr16>;
3144def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3145def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3146 CLGTHIr16, CEQHIr16>;
3147def : Pat<(setule R16C:$rA, R16C:$rB),
3148 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003149def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003150 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003151
Scott Michel53ab7792008-03-10 16:58:52 +00003152def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003153def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003154 ORr32, CLGTIr32, CEQIr32>;
3155def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003156def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003157def : Pat<(setule R32C:$rA, R32C:$rB),
3158 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3159def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3160 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003161
Scott Michel53ab7792008-03-10 16:58:52 +00003162//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3163// select conditional patterns:
3164//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3165
3166class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3167 SPUInstr selinstr, SPUInstr cmpare>:
3168 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3169 rclass:$rTrue, rclass:$rFalse),
3170 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003171 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003172
3173class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3174 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3175 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003176 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003177 (selinstr rclass:$rTrue, rclass:$rFalse,
3178 (cmpare rclass:$rA, immpred:$imm))>;
3179
3180def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3181def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3182def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3183def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3184def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3185def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3186
3187def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3188def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3189def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3190def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3191def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3192def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3193
3194def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3195def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3196def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3197def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3198def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3199def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3200
3201class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3202 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3203 SPUInstr cmpOp2>:
3204 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3205 rclass:$rFalse, rclass:$rTrue),
3206 (selinstr rclass:$rTrue, rclass:$rFalse,
3207 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3208 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3209
3210class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3211 ValueType inttype,
3212 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3213 SPUInstr cmpOp2>:
3214 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003215 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003216 (selinstr rclass:$rFalse, rclass:$rTrue,
3217 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3218 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3219
3220def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3221def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3222 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3223
3224def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3225def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3226 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3227
3228def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3229def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3230 SELBr32, ORr32, CGTIr32, CEQIr32>;
3231
3232def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3233def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3234 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3235
3236def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3237def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3238 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3239
3240def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3241def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3242 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003243
3244//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003245
3246let isCall = 1,
3247 // All calls clobber the non-callee-saved registers:
3248 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3249 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3250 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3251 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3252 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3253 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3254 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3255 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3256 // All of these instructions use $lr (aka $0)
3257 Uses = [R0] in {
3258 // Branch relative and set link: Used if we actually know that the target
3259 // is within [-32768, 32767] bytes of the target
3260 def BRSL:
3261 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3262 "brsl\t$$lr, $func",
3263 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3264
3265 // Branch absolute and set link: Used if we actually know that the target
3266 // is an absolute address
3267 def BRASL:
3268 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3269 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003270 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003271
3272 // Branch indirect and set link if external data. These instructions are not
3273 // actually generated, matched by an intrinsic:
3274 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3275 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3276 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3277 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3278
3279 // Branch indirect and set link. This is the "X-form" address version of a
3280 // function call
3281 def BISL:
3282 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3283}
3284
3285// Unconditional branches:
3286let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3287 def BR :
3288 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3289 "br\t$dest",
3290 [(br bb:$dest)]>;
3291
3292 // Unconditional, absolute address branch
3293 def BRA:
3294 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3295 "bra\t$dest",
3296 [/* no pattern */]>;
3297
3298 // Indirect branch
3299 def BI:
3300 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3301
3302 // Various branches:
3303 def BRNZ:
3304 RI16Form<0b010000100, (outs), (ins R32C:$rCond, brtarget:$dest),
3305 "brnz\t$rCond,$dest",
3306 BranchResolv,
3307 [(brcond R32C:$rCond, bb:$dest)]>;
3308
3309 def BRZ:
3310 RI16Form<0b000000100, (outs), (ins R32C:$rT, brtarget:$dest),
3311 "brz\t$rT,$dest",
3312 BranchResolv,
3313 [/* no pattern */]>;
3314
3315 def BRHNZ:
3316 RI16Form<0b011000100, (outs), (ins R16C:$rCond, brtarget:$dest),
3317 "brhnz\t$rCond,$dest",
3318 BranchResolv,
3319 [(brcond R16C:$rCond, bb:$dest)]>;
3320
3321 def BRHZ:
3322 RI16Form<0b001000100, (outs), (ins R16C:$rT, brtarget:$dest),
3323 "brhz\t$rT,$dest",
3324 BranchResolv,
3325 [/* no pattern */]>;
3326
3327/*
3328 def BINZ:
3329 BICondForm<0b10010100100, "binz\t$rA, $func",
3330 [(SPUbinz R32C:$rA, R32C:$func)]>;
3331
3332 def BIZ:
3333 BICondForm<0b00010100100, "biz\t$rA, $func",
3334 [(SPUbiz R32C:$rA, R32C:$func)]>;
3335*/
3336}
3337
Scott Michel394e26d2008-01-17 20:38:41 +00003338//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003339// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003340//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003341
Scott Michel8b6b4202007-12-04 22:35:58 +00003342def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3343 (BRHZ R16C:$rA, bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003344def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3345 (BRHNZ R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003346
3347def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3348 (BRZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003349def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
Scott Michel394e26d2008-01-17 20:38:41 +00003350 (BRNZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003351
Scott Michel97872d32008-02-23 18:41:37 +00003352multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3353{
3354 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3355 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003356
Scott Michel97872d32008-02-23 18:41:37 +00003357 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3358 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3359
3360 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3361 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3362
3363 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3364 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3365}
3366
3367defm BRCONDeq : BranchCondEQ<seteq, BRHZ, BRZ>;
3368defm BRCONDne : BranchCondEQ<setne, BRHNZ, BRNZ>;
3369
3370multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3371{
3372 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3373 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3374
3375 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3376 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3377
3378 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3379 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3380
3381 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3382 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3383}
3384
3385defm BRCONDugt : BranchCondLGT<setugt, BRHNZ, BRNZ>;
3386defm BRCONDule : BranchCondLGT<setule, BRHZ, BRZ>;
3387
3388multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3389 SPUInstr orinst32, SPUInstr brinst32>
3390{
3391 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3392 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3393 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3394 bb:$dest)>;
3395
3396 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3397 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3398 (CEQHr16 R16C:$rA, R16:$rB)),
3399 bb:$dest)>;
3400
3401 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3402 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3403 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3404 bb:$dest)>;
3405
3406 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3407 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3408 (CEQr32 R32C:$rA, R32C:$rB)),
3409 bb:$dest)>;
3410}
3411
3412defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZ, ORr32, BRNZ>;
3413defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZ, ORr32, BRZ>;
3414
3415multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3416{
3417 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3418 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3419
3420 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3421 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3422
3423 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3424 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3425
3426 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3427 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3428}
3429
3430defm BRCONDgt : BranchCondGT<setgt, BRHNZ, BRNZ>;
3431defm BRCONDle : BranchCondGT<setle, BRHZ, BRZ>;
3432
3433multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3434 SPUInstr orinst32, SPUInstr brinst32>
3435{
3436 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3437 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3438 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3439 bb:$dest)>;
3440
3441 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3442 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3443 (CEQHr16 R16C:$rA, R16:$rB)),
3444 bb:$dest)>;
3445
3446 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3447 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3448 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3449 bb:$dest)>;
3450
3451 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3452 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3453 (CEQr32 R32C:$rA, R32C:$rB)),
3454 bb:$dest)>;
3455}
3456
3457defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZ, ORr32, BRNZ>;
3458defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZ, ORr32, BRZ>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003459
Scott Michel8b6b4202007-12-04 22:35:58 +00003460let isTerminator = 1, isBarrier = 1 in {
3461 let isReturn = 1 in {
3462 def RET:
3463 RETForm<"bi\t$$lr", [(retflag)]>;
3464 }
3465}
3466
3467//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003468// Single precision floating point instructions
3469//===----------------------------------------------------------------------===//
3470
3471def FAv4f32:
3472 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3473 "fa\t$rT, $rA, $rB", SPrecFP,
3474 [(set (v4f32 VECREG:$rT), (fadd (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3475
3476def FAf32 :
3477 RRForm<0b00100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3478 "fa\t$rT, $rA, $rB", SPrecFP,
3479 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3480
3481def FSv4f32:
3482 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3483 "fs\t$rT, $rA, $rB", SPrecFP,
3484 [(set (v4f32 VECREG:$rT), (fsub (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3485
3486def FSf32 :
3487 RRForm<0b10100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3488 "fs\t$rT, $rA, $rB", SPrecFP,
3489 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3490
3491// Floating point reciprocal estimate
3492def FREv4f32 :
3493 RRForm_1<0b00011101100, (outs VECREG:$rT), (ins VECREG:$rA),
3494 "frest\t$rT, $rA", SPrecFP,
3495 [(set (v4f32 VECREG:$rT), (SPUreciprocalEst (v4f32 VECREG:$rA)))]>;
3496
3497def FREf32 :
3498 RRForm_1<0b00011101100, (outs R32FP:$rT), (ins R32FP:$rA),
3499 "frest\t$rT, $rA", SPrecFP,
3500 [(set R32FP:$rT, (SPUreciprocalEst R32FP:$rA))]>;
3501
3502// Floating point interpolate (used in conjunction with reciprocal estimate)
3503def FIv4f32 :
3504 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3505 "fi\t$rT, $rA, $rB", SPrecFP,
3506 [(set (v4f32 VECREG:$rT), (SPUinterpolate (v4f32 VECREG:$rA),
3507 (v4f32 VECREG:$rB)))]>;
3508
3509def FIf32 :
3510 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3511 "fi\t$rT, $rA, $rB", SPrecFP,
3512 [(set R32FP:$rT, (SPUinterpolate R32FP:$rA, R32FP:$rB))]>;
3513
Scott Michel33d73eb2008-11-21 02:56:16 +00003514//--------------------------------------------------------------------------
3515// Basic single precision floating point comparisons:
3516//
3517// Note: There is no support on SPU for single precision NaN. Consequently,
3518// ordered and unordered comparisons are the same.
3519//--------------------------------------------------------------------------
3520
Scott Michel8b6b4202007-12-04 22:35:58 +00003521def FCEQf32 :
3522 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3523 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003524 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3525
3526def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3527 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003528
3529def FCMEQf32 :
3530 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3531 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003532 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3533
3534def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3535 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003536
3537def FCGTf32 :
3538 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3539 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003540 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3541
3542def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3543 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003544
3545def FCMGTf32 :
3546 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3547 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003548 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3549
3550def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3551 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3552
3553//--------------------------------------------------------------------------
3554// Single precision floating point comparisons and SETCC equivalents:
3555//--------------------------------------------------------------------------
3556
3557def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3558def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3559
3560def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3561def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3562
3563def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3564def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3565
3566def : Pat<(setule R32FP:$rA, R32FP:$rB),
3567 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3568def : Pat<(setole R32FP:$rA, R32FP:$rB),
3569 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003570
3571// FP Status and Control Register Write
3572// Why isn't rT a don't care in the ISA?
3573// Should we create a special RRForm_3 for this guy and zero out the rT?
3574def FSCRWf32 :
3575 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3576 "fscrwr\t$rA", SPrecFP,
3577 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3578
3579// FP Status and Control Register Read
3580def FSCRRf32 :
3581 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3582 "fscrrd\t$rT", SPrecFP,
3583 [/* This instruction requires an intrinsic */]>;
3584
3585// llvm instruction space
3586// How do these map onto cell instructions?
3587// fdiv rA rB
3588// frest rC rB # c = 1/b (both lines)
3589// fi rC rB rC
3590// fm rD rA rC # d = a * 1/b
3591// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3592// fma rB rB rC rD # b = b * c + d
3593// = -(d *b -a) * c + d
3594// = a * c - c ( a *b *c - a)
3595
3596// fcopysign (???)
3597
3598// Library calls:
3599// These llvm instructions will actually map to library calls.
3600// All that's needed, then, is to check that the appropriate library is
3601// imported and do a brsl to the proper function name.
3602// frem # fmod(x, y): x - (x/y) * y
3603// (Note: fmod(double, double), fmodf(float,float)
3604// fsqrt?
3605// fsin?
3606// fcos?
3607// Unimplemented SPU instruction space
3608// floating reciprocal absolute square root estimate (frsqest)
3609
3610// The following are probably just intrinsics
3611// status and control register write
3612// status and control register read
3613
3614//--------------------------------------
3615// Floating point multiply instructions
3616//--------------------------------------
3617
3618def FMv4f32:
3619 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3620 "fm\t$rT, $rA, $rB", SPrecFP,
3621 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3622 (v4f32 VECREG:$rB)))]>;
3623
3624def FMf32 :
3625 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3626 "fm\t$rT, $rA, $rB", SPrecFP,
3627 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3628
3629// Floating point multiply and add
3630// e.g. d = c + (a * b)
3631def FMAv4f32:
3632 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3633 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3634 [(set (v4f32 VECREG:$rT),
3635 (fadd (v4f32 VECREG:$rC),
3636 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3637
3638def FMAf32:
3639 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3640 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3641 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3642
3643// FP multiply and subtract
3644// Subtracts value in rC from product
3645// res = a * b - c
3646def FMSv4f32 :
3647 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3648 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3649 [(set (v4f32 VECREG:$rT),
3650 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3651 (v4f32 VECREG:$rC)))]>;
3652
3653def FMSf32 :
3654 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3655 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3656 [(set R32FP:$rT,
3657 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3658
3659// Floating Negative Mulitply and Subtract
3660// Subtracts product from value in rC
3661// res = fneg(fms a b c)
3662// = - (a * b - c)
3663// = c - a * b
3664// NOTE: subtraction order
3665// fsub a b = a - b
3666// fs a b = b - a?
3667def FNMSf32 :
3668 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3669 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3670 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3671
3672def FNMSv4f32 :
3673 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3674 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3675 [(set (v4f32 VECREG:$rT),
3676 (fsub (v4f32 VECREG:$rC),
3677 (fmul (v4f32 VECREG:$rA),
3678 (v4f32 VECREG:$rB))))]>;
3679
3680//--------------------------------------
3681// Floating Point Conversions
3682// Signed conversions:
3683def CSiFv4f32:
3684 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3685 "csflt\t$rT, $rA, 0", SPrecFP,
3686 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3687
3688// Convert signed integer to floating point
3689def CSiFf32 :
3690 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3691 "csflt\t$rT, $rA, 0", SPrecFP,
3692 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3693
3694// Convert unsigned into to float
3695def CUiFv4f32 :
3696 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3697 "cuflt\t$rT, $rA, 0", SPrecFP,
3698 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3699
3700def CUiFf32 :
3701 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3702 "cuflt\t$rT, $rA, 0", SPrecFP,
3703 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
3704
3705// Convert float to unsigned int
3706// Assume that scale = 0
3707
3708def CFUiv4f32 :
3709 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3710 "cfltu\t$rT, $rA, 0", SPrecFP,
3711 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
3712
3713def CFUif32 :
3714 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3715 "cfltu\t$rT, $rA, 0", SPrecFP,
3716 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
3717
3718// Convert float to signed int
3719// Assume that scale = 0
3720
3721def CFSiv4f32 :
3722 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3723 "cflts\t$rT, $rA, 0", SPrecFP,
3724 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
3725
3726def CFSif32 :
3727 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3728 "cflts\t$rT, $rA, 0", SPrecFP,
3729 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
3730
3731//===----------------------------------------------------------------------==//
3732// Single<->Double precision conversions
3733//===----------------------------------------------------------------------==//
3734
3735// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
3736// v4f32, output is v2f64--which goes in the name?)
3737
3738// Floating point extend single to double
3739// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
3740// operates on two double-word slots (i.e. 1st and 3rd fp numbers
3741// are ignored).
3742def FESDvec :
3743 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3744 "fesd\t$rT, $rA", SPrecFP,
3745 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
3746
3747def FESDf32 :
3748 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
3749 "fesd\t$rT, $rA", SPrecFP,
3750 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
3751
3752// Floating point round double to single
3753//def FRDSvec :
3754// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3755// "frds\t$rT, $rA,", SPrecFP,
3756// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
3757
3758def FRDSf64 :
3759 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
3760 "frds\t$rT, $rA", SPrecFP,
3761 [(set R32FP:$rT, (fround R64FP:$rA))]>;
3762
3763//ToDo include anyextend?
3764
3765//===----------------------------------------------------------------------==//
3766// Double precision floating point instructions
3767//===----------------------------------------------------------------------==//
3768def FAf64 :
3769 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3770 "dfa\t$rT, $rA, $rB", DPrecFP,
3771 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
3772
3773def FAv2f64 :
3774 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3775 "dfa\t$rT, $rA, $rB", DPrecFP,
3776 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3777
3778def FSf64 :
3779 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3780 "dfs\t$rT, $rA, $rB", DPrecFP,
3781 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
3782
3783def FSv2f64 :
3784 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3785 "dfs\t$rT, $rA, $rB", DPrecFP,
3786 [(set (v2f64 VECREG:$rT),
3787 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3788
3789def FMf64 :
3790 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3791 "dfm\t$rT, $rA, $rB", DPrecFP,
3792 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
3793
3794def FMv2f64:
3795 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3796 "dfm\t$rT, $rA, $rB", DPrecFP,
3797 [(set (v2f64 VECREG:$rT),
3798 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3799
3800def FMAf64:
3801 RRForm<0b00111010110, (outs R64FP:$rT),
3802 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3803 "dfma\t$rT, $rA, $rB", DPrecFP,
3804 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3805 RegConstraint<"$rC = $rT">,
3806 NoEncode<"$rC">;
3807
3808def FMAv2f64:
3809 RRForm<0b00111010110, (outs VECREG:$rT),
3810 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3811 "dfma\t$rT, $rA, $rB", DPrecFP,
3812 [(set (v2f64 VECREG:$rT),
3813 (fadd (v2f64 VECREG:$rC),
3814 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
3815 RegConstraint<"$rC = $rT">,
3816 NoEncode<"$rC">;
3817
3818def FMSf64 :
3819 RRForm<0b10111010110, (outs R64FP:$rT),
3820 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3821 "dfms\t$rT, $rA, $rB", DPrecFP,
3822 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
3823 RegConstraint<"$rC = $rT">,
3824 NoEncode<"$rC">;
3825
3826def FMSv2f64 :
3827 RRForm<0b10111010110, (outs VECREG:$rT),
3828 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3829 "dfms\t$rT, $rA, $rB", DPrecFP,
3830 [(set (v2f64 VECREG:$rT),
3831 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3832 (v2f64 VECREG:$rC)))]>;
3833
3834// FNMS: - (a * b - c)
3835// - (a * b) + c => c - (a * b)
3836def FNMSf64 :
3837 RRForm<0b01111010110, (outs R64FP:$rT),
3838 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3839 "dfnms\t$rT, $rA, $rB", DPrecFP,
3840 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3841 RegConstraint<"$rC = $rT">,
3842 NoEncode<"$rC">;
3843
3844def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
3845 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
3846
3847def FNMSv2f64 :
3848 RRForm<0b01111010110, (outs VECREG:$rT),
3849 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3850 "dfnms\t$rT, $rA, $rB", DPrecFP,
3851 [(set (v2f64 VECREG:$rT),
3852 (fsub (v2f64 VECREG:$rC),
3853 (fmul (v2f64 VECREG:$rA),
3854 (v2f64 VECREG:$rB))))]>,
3855 RegConstraint<"$rC = $rT">,
3856 NoEncode<"$rC">;
3857
3858def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3859 (v2f64 VECREG:$rC))),
3860 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
3861
3862// - (a * b + c)
3863// - (a * b) - c
3864def FNMAf64 :
3865 RRForm<0b11111010110, (outs R64FP:$rT),
3866 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3867 "dfnma\t$rT, $rA, $rB", DPrecFP,
3868 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
3869 RegConstraint<"$rC = $rT">,
3870 NoEncode<"$rC">;
3871
3872def FNMAv2f64 :
3873 RRForm<0b11111010110, (outs VECREG:$rT),
3874 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3875 "dfnma\t$rT, $rA, $rB", DPrecFP,
3876 [(set (v2f64 VECREG:$rT),
3877 (fneg (fadd (v2f64 VECREG:$rC),
3878 (fmul (v2f64 VECREG:$rA),
3879 (v2f64 VECREG:$rB)))))]>,
3880 RegConstraint<"$rC = $rT">,
3881 NoEncode<"$rC">;
3882
3883//===----------------------------------------------------------------------==//
3884// Floating point negation and absolute value
3885//===----------------------------------------------------------------------==//
3886
3887def : Pat<(fneg (v4f32 VECREG:$rA)),
3888 (XORfnegvec (v4f32 VECREG:$rA),
3889 (v4f32 (ILHUv4i32 0x8000)))>;
3890
3891def : Pat<(fneg R32FP:$rA),
3892 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
3893
3894def : Pat<(fneg (v2f64 VECREG:$rA)),
3895 (XORfnegvec (v2f64 VECREG:$rA),
3896 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
3897
3898def : Pat<(fneg R64FP:$rA),
3899 (XORfneg64 R64FP:$rA,
3900 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
3901
3902// Floating point absolute value
3903
3904def : Pat<(fabs R32FP:$rA),
3905 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
3906
3907def : Pat<(fabs (v4f32 VECREG:$rA)),
3908 (ANDfabsvec (v4f32 VECREG:$rA),
3909 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3910
3911def : Pat<(fabs R64FP:$rA),
3912 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
3913
3914def : Pat<(fabs (v2f64 VECREG:$rA)),
3915 (ANDfabsvec (v2f64 VECREG:$rA),
3916 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3917
3918//===----------------------------------------------------------------------===//
3919// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
3920// in the odd pipeline)
3921//===----------------------------------------------------------------------===//
3922
Scott Michel97872d32008-02-23 18:41:37 +00003923def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003924 let Pattern = [];
3925
3926 let Inst{0-10} = 0b10000000010;
3927 let Inst{11-17} = 0;
3928 let Inst{18-24} = 0;
3929 let Inst{25-31} = 0;
3930}
3931
Scott Michel97872d32008-02-23 18:41:37 +00003932def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003933 let Pattern = [];
3934
3935 let Inst{0-10} = 0b10000000000;
3936 let Inst{11-17} = 0;
3937 let Inst{18-24} = 0;
3938 let Inst{25-31} = 0;
3939}
3940
3941//===----------------------------------------------------------------------===//
3942// Bit conversions (type conversions between vector/packed types)
3943// NOTE: Promotions are handled using the XS* instructions. Truncation
3944// is not handled.
3945//===----------------------------------------------------------------------===//
3946def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
3947def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
3948def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
3949def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
3950def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
3951
3952def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
3953def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
3954def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
3955def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
3956def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
3957
3958def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
3959def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
3960def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
3961def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
3962def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
3963
3964def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
3965def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
3966def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
3967def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
3968def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
3969
3970def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
3971def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
3972def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
3973def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
3974def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
3975
3976def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
3977def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
3978def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
3979def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
3980def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
3981
3982def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00003983def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003984
3985//===----------------------------------------------------------------------===//
3986// Instruction patterns:
3987//===----------------------------------------------------------------------===//
3988
3989// General 32-bit constants:
3990def : Pat<(i32 imm:$imm),
3991 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
3992
3993// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00003994def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00003995 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
3996
3997// General constant 32-bit vectors
3998def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00003999 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4000 (LO16_vec v4i32Imm:$imm))>;
Scott Michel438be252007-12-17 22:32:34 +00004001
4002// 8-bit constants
4003def : Pat<(i8 imm:$imm),
4004 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004005
4006//===----------------------------------------------------------------------===//
4007// Call instruction patterns:
4008//===----------------------------------------------------------------------===//
4009// Return void
4010def : Pat<(ret),
4011 (RET)>;
4012
4013//===----------------------------------------------------------------------===//
4014// Zero/Any/Sign extensions
4015//===----------------------------------------------------------------------===//
4016
4017// zext 1->32: Zero extend i1 to i32
4018def : Pat<(SPUextract_i1_zext R32C:$rSrc),
4019 (ANDIr32 R32C:$rSrc, 0x1)>;
4020
4021// sext 8->32: Sign extend bytes to words
4022def : Pat<(sext_inreg R32C:$rSrc, i8),
4023 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4024
Scott Michel438be252007-12-17 22:32:34 +00004025def : Pat<(i32 (sext R8C:$rSrc)),
4026 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4027
Scott Michel8b6b4202007-12-04 22:35:58 +00004028def : Pat<(SPUextract_i8_sext VECREG:$rSrc),
4029 (XSHWr32 (XSBHr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc),
4030 (v4i32 VECREG:$rSrc))))>;
4031
Scott Michel438be252007-12-17 22:32:34 +00004032// zext 8->16: Zero extend bytes to halfwords
4033def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004034 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004035
4036// zext 8->32 from preferred slot in load/store
Scott Michel8b6b4202007-12-04 22:35:58 +00004037def : Pat<(SPUextract_i8_zext VECREG:$rSrc),
4038 (ANDIr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc), (v4i32 VECREG:$rSrc)),
4039 0xff)>;
4040
Scott Michel438be252007-12-17 22:32:34 +00004041// zext 8->32: Zero extend bytes to words
4042def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004043 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004044
4045// anyext 8->16: Extend 8->16 bits, irrespective of sign
4046def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004047 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004048
4049// anyext 8->32: Extend 8->32 bits, irrespective of sign
4050def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004051 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004052
Scott Michel97872d32008-02-23 18:41:37 +00004053// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004054def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004055 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004056
4057def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004058 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004059
4060def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004061 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004062
4063def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004064 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004065
4066// anyext 16->32: Extend 16->32 bits, irrespective of sign
4067def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004068 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004069
4070//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004071// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004072// low parts in order to load them into a register.
4073//===----------------------------------------------------------------------===//
4074
Scott Michelf9f42e62008-01-29 02:16:57 +00004075def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4076def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4077def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4078def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4079
4080def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4081 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004082 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004083
Scott Michelf9f42e62008-01-29 02:16:57 +00004084def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4085 (SPUlo texternalsym:$in, 0)),
4086 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4087
4088def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4089 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004090 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004091
Scott Michelf9f42e62008-01-29 02:16:57 +00004092def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4093 (SPUlo tconstpool:$in, 0)),
4094 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4095
Scott Michelbc5fbc12008-04-30 00:30:08 +00004096def : Pat<(SPUindirect R32C:$sp, i32ImmSExt10:$imm),
4097 (AIr32 R32C:$sp, i32ImmSExt10:$imm)>;
4098
4099def : Pat<(SPUindirect R32C:$sp, imm:$imm),
4100 (Ar32 R32C:$sp,
4101 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm)))>;
4102
Scott Michelf9f42e62008-01-29 02:16:57 +00004103def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4104 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4105
4106def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4107 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4108
4109def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4110 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4111
4112def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4113 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004114
Scott Michel8b6b4202007-12-04 22:35:58 +00004115// Instrinsics:
4116include "CellSDKIntrinsics.td"