blob: 5d6d8af0cee6848a91ef9eaeeaf546cdcf113195 [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
Dan Gohman5574cc72008-12-03 18:15:48 +000050let canFoldAsLoad = 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
Scott Michel0718cd82008-12-01 17:56:02 +0000272def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins memri7:$src),
273 "cbd\t$rT, $src", ShuffleOp,
274 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000275
Scott Michel0718cd82008-12-01 17:56:02 +0000276def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000277 "cbx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000278 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000279
Scott Michel0718cd82008-12-01 17:56:02 +0000280def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins memri7:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000281 "chd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000282 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000283
Scott Michel0718cd82008-12-01 17:56:02 +0000284def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000285 "chx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000286 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000287
Scott Michel0718cd82008-12-01 17:56:02 +0000288def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins memri7:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000289 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000290 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000291
Scott Michel0718cd82008-12-01 17:56:02 +0000292def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000293 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000294 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000295
Scott Michel0718cd82008-12-01 17:56:02 +0000296def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins memri7:$src),
297 "cwd\t$rT, $src", ShuffleOp,
298 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
299
300def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000301 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000302 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000303
Scott Michel0718cd82008-12-01 17:56:02 +0000304def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins memri7:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000305 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000306 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000307
Scott Michel0718cd82008-12-01 17:56:02 +0000308def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000309 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000310 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000311
Scott Michel0718cd82008-12-01 17:56:02 +0000312def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins memri7:$src),
313 "cdd\t$rT, $src", ShuffleOp,
314 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
315
316def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000317 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000318 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000319
Scott Michel8b6b4202007-12-04 22:35:58 +0000320//===----------------------------------------------------------------------===//
321// Constant formation:
322//===----------------------------------------------------------------------===//
323
324def ILHv8i16:
325 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
326 "ilh\t$rT, $val", ImmLoad,
327 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
328
329def ILHr16:
330 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
331 "ilh\t$rT, $val", ImmLoad,
332 [(set R16C:$rT, immSExt16:$val)]>;
333
Scott Michel438be252007-12-17 22:32:34 +0000334// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
335// the right constant")
336def ILHr8:
337 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
338 "ilh\t$rT, $val", ImmLoad,
339 [(set R8C:$rT, immSExt8:$val)]>;
340
Scott Michel8b6b4202007-12-04 22:35:58 +0000341// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000342
Scott Michel6baba072008-03-05 23:02:02 +0000343class ILInst<dag OOL, dag IOL, list<dag> pattern>:
344 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
345 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000346
Scott Michel6baba072008-03-05 23:02:02 +0000347class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
348 ILInst<(outs VECREG:$rT), (ins immtype:$val),
349 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000350
Scott Michel6baba072008-03-05 23:02:02 +0000351class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
352 ILInst<(outs rclass:$rT), (ins immtype:$val),
353 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000354
Scott Michel6baba072008-03-05 23:02:02 +0000355multiclass ImmediateLoad
356{
357 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
358 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000359
Scott Michel6baba072008-03-05 23:02:02 +0000360 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000361
Scott Michel6baba072008-03-05 23:02:02 +0000362 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
363 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
364 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
365 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
366}
Scott Michel8b6b4202007-12-04 22:35:58 +0000367
Scott Michel6baba072008-03-05 23:02:02 +0000368defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000369
Scott Michel6baba072008-03-05 23:02:02 +0000370class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
371 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
372 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000373
Scott Michel6baba072008-03-05 23:02:02 +0000374class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
375 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
376 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
377
378class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
379 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
380 [(set rclass:$rT, xform:$val)]>;
381
382multiclass ImmLoadHalfwordUpper
383{
384 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000385 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000386
387 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000388 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000389
390 // Loads the high portion of an address
391 def hi: ILHURegInst<R32C, symbolHi, hi16>;
392
393 // Used in custom lowering constant SFP loads:
394 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
395}
396
397defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000398
399// Immediate load address (can also be used to load 18-bit unsigned constants,
400// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000401
Scott Michel97872d32008-02-23 18:41:37 +0000402class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
403 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
404 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000405
Scott Michel6baba072008-03-05 23:02:02 +0000406class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
407 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
408 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
409
410class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
411 ILAInst<(outs rclass:$rT), (ins immtype:$val),
412 [(set rclass:$rT, xform:$val)]>;
413
Scott Michel97872d32008-02-23 18:41:37 +0000414multiclass ImmLoadAddress
415{
Scott Michel6baba072008-03-05 23:02:02 +0000416 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
417 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000418
Scott Michel6baba072008-03-05 23:02:02 +0000419 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
420 def r32: ILARegInst<R32C, u18imm, imm18>;
421 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
422 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000423
Scott Michel6baba072008-03-05 23:02:02 +0000424 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000425
Scott Michel97872d32008-02-23 18:41:37 +0000426 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
427 [/* no pattern */]>;
428}
429
430defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000431
432// Immediate OR, Halfword Lower: The "other" part of loading large constants
433// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
434// Note that these are really two operand instructions, but they're encoded
435// as three operands with the first two arguments tied-to each other.
436
Scott Michel6baba072008-03-05 23:02:02 +0000437class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
438 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
439 ImmLoad, pattern>,
440 RegConstraint<"$rS = $rT">,
441 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000442
Scott Michel6baba072008-03-05 23:02:02 +0000443class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
444 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
445 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000446
Scott Michel6baba072008-03-05 23:02:02 +0000447class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
448 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
449 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000450
Scott Michel6baba072008-03-05 23:02:02 +0000451multiclass ImmOrHalfwordLower
452{
453 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000454 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000455
456 def r32: IOHLRegInst<R32C, i32imm>;
457 def f32: IOHLRegInst<R32FP, f32imm>;
458
459 def lo: IOHLRegInst<R32C, symbolLo>;
460}
461
462defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000463
Scott Michel8b6b4202007-12-04 22:35:58 +0000464// Form select mask for bytes using immediate, used in conjunction with the
465// SELB instruction:
466
Scott Michel6baba072008-03-05 23:02:02 +0000467class FSMBIVec<ValueType vectype>:
468 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
469 "fsmbi\t$rT, $val",
470 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000471 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000472
Scott Michel97872d32008-02-23 18:41:37 +0000473multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000474{
475 def v16i8: FSMBIVec<v16i8>;
476 def v8i16: FSMBIVec<v8i16>;
477 def v4i32: FSMBIVec<v4i32>;
478 def v2i64: FSMBIVec<v2i64>;
479}
Scott Michel8b6b4202007-12-04 22:35:58 +0000480
Scott Michel97872d32008-02-23 18:41:37 +0000481defm FSMBI : FormSelectMaskBytesImm;
482
483// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
484def FSMB:
485 RRForm_1<0b01101101100, (outs VECREG:$rT), (ins R16C:$rA),
Scott Michel6baba072008-03-05 23:02:02 +0000486 "fsmb\t$rT, $rA", SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000487 [(set (v16i8 VECREG:$rT), (SPUselmask R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000488
489// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
490// only 8-bits wide (even though it's input as 16-bits here)
491def FSMH:
492 RRForm_1<0b10101101100, (outs VECREG:$rT), (ins R16C:$rA),
493 "fsmh\t$rT, $rA", SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000494 [(set (v8i16 VECREG:$rT), (SPUselmask R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000495
496// fsm: Form select mask for words. Like the other fsm* instructions,
497// only the lower 4 bits of $rA are significant.
Scott Michel67224b22008-06-02 22:18:03 +0000498class FSMInst<ValueType vectype, RegisterClass rclass>:
499 RRForm_1<0b00101101100, (outs VECREG:$rT), (ins rclass:$rA),
500 "fsm\t$rT, $rA",
501 SelectOp,
502 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
503
504multiclass FormSelectMaskWord {
505 def r32 : FSMInst<v4i32, R32C>;
506 def r16 : FSMInst<v4i32, R16C>;
507}
508
509defm FSM : FormSelectMaskWord;
510
511// Special case when used for i64 math operations
512multiclass FormSelectMaskWord64 {
513 def r32 : FSMInst<v2i64, R32C>;
514 def r16 : FSMInst<v2i64, R16C>;
515}
516
517defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000518
519//===----------------------------------------------------------------------===//
520// Integer and Logical Operations:
521//===----------------------------------------------------------------------===//
522
523def AHv8i16:
524 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
525 "ah\t$rT, $rA, $rB", IntegerOp,
526 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
527
528def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
529 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
530
Scott Michel8b6b4202007-12-04 22:35:58 +0000531def AHr16:
532 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
533 "ah\t$rT, $rA, $rB", IntegerOp,
534 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
535
536def AHIvec:
537 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
538 "ahi\t$rT, $rA, $val", IntegerOp,
539 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
540 v8i16SExt10Imm:$val))]>;
541
Scott Michel97872d32008-02-23 18:41:37 +0000542def AHIr16:
543 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
544 "ahi\t$rT, $rA, $val", IntegerOp,
545 [(set R16C:$rT, (add R16C:$rA, v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000546
Scott Michel97872d32008-02-23 18:41:37 +0000547def Avec:
548 RRForm<0b00000011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
549 "a\t$rT, $rA, $rB", IntegerOp,
550 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000551
552def : Pat<(add (v16i8 VECREG:$rA), (v16i8 VECREG:$rB)),
553 (Avec VECREG:$rA, VECREG:$rB)>;
554
Scott Michel97872d32008-02-23 18:41:37 +0000555def Ar32:
556 RRForm<0b00000011000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
557 "a\t$rT, $rA, $rB", IntegerOp,
558 [(set R32C:$rT, (add R32C:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000559
Scott Michel438be252007-12-17 22:32:34 +0000560def Ar8:
561 RRForm<0b00000011000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
562 "a\t$rT, $rA, $rB", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000563 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +0000564
Scott Michel8b6b4202007-12-04 22:35:58 +0000565def AIvec:
566 RI10Form<0b00111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
567 "ai\t$rT, $rA, $val", IntegerOp,
568 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA),
569 v4i32SExt10Imm:$val))]>;
570
Scott Michel438be252007-12-17 22:32:34 +0000571def AIr32:
572 RI10Form<0b00111000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
573 "ai\t$rT, $rA, $val", IntegerOp,
574 [(set R32C:$rT, (add R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000575
Scott Michel438be252007-12-17 22:32:34 +0000576def SFHvec:
577 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
578 "sfh\t$rT, $rA, $rB", IntegerOp,
579 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
580 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000581
Scott Michel438be252007-12-17 22:32:34 +0000582def SFHr16:
583 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
584 "sfh\t$rT, $rA, $rB", IntegerOp,
585 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000586
587def SFHIvec:
588 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
589 "sfhi\t$rT, $rA, $val", IntegerOp,
590 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
591 (v8i16 VECREG:$rA)))]>;
592
593def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
594 "sfhi\t$rT, $rA, $val", IntegerOp,
595 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
596
597def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
598 (ins VECREG:$rA, VECREG:$rB),
599 "sf\t$rT, $rA, $rB", IntegerOp,
600 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
601
602def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
603 "sf\t$rT, $rA, $rB", IntegerOp,
604 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
605
606def SFIvec:
607 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
608 "sfi\t$rT, $rA, $val", IntegerOp,
609 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
610 (v4i32 VECREG:$rA)))]>;
611
612def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
613 (ins R32C:$rA, s10imm_i32:$val),
614 "sfi\t$rT, $rA, $val", IntegerOp,
615 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
616
617// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000618class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
619 RRForm<0b00000010110, OOL, IOL,
620 "addx\t$rT, $rA, $rB",
621 IntegerOp, pattern>;
622
623class ADDXVecInst<ValueType vectype>:
624 ADDXInst<(outs VECREG:$rT),
625 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
626 [(set (vectype VECREG:$rT),
627 (SPUaddx (vectype VECREG:$rA), (vectype VECREG:$rB),
628 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000629 RegConstraint<"$rCarry = $rT">,
630 NoEncode<"$rCarry">;
631
Scott Michel67224b22008-06-02 22:18:03 +0000632class ADDXRegInst<RegisterClass rclass>:
633 ADDXInst<(outs rclass:$rT),
634 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
635 [(set rclass:$rT,
636 (SPUaddx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000637 RegConstraint<"$rCarry = $rT">,
638 NoEncode<"$rCarry">;
639
Scott Michel67224b22008-06-02 22:18:03 +0000640multiclass AddExtended {
641 def v2i64 : ADDXVecInst<v2i64>;
642 def v4i32 : ADDXVecInst<v4i32>;
643 def r64 : ADDXRegInst<R64C>;
644 def r32 : ADDXRegInst<R32C>;
645}
646
647defm ADDX : AddExtended;
648
649// CG: Generate carry for add
650class CGInst<dag OOL, dag IOL, list<dag> pattern>:
651 RRForm<0b01000011000, OOL, IOL,
652 "cg\t$rT, $rA, $rB",
653 IntegerOp, pattern>;
654
655class CGVecInst<ValueType vectype>:
656 CGInst<(outs VECREG:$rT),
657 (ins VECREG:$rA, VECREG:$rB),
658 [(set (vectype VECREG:$rT),
659 (SPUcarry_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
660
661class CGRegInst<RegisterClass rclass>:
662 CGInst<(outs rclass:$rT),
663 (ins rclass:$rA, rclass:$rB),
664 [(set rclass:$rT,
665 (SPUcarry_gen rclass:$rA, rclass:$rB))]>;
666
667multiclass CarryGenerate {
668 def v2i64 : CGVecInst<v2i64>;
669 def v4i32 : CGVecInst<v4i32>;
670 def r64 : CGRegInst<R64C>;
671 def r32 : CGRegInst<R32C>;
672}
673
674defm CG : CarryGenerate;
675
676// SFX: Subract from, extended. This is used in conjunction with BG to subtract
677// with carry (borrow, in this case)
678class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
679 RRForm<0b10000010110, OOL, IOL,
680 "sfx\t$rT, $rA, $rB",
681 IntegerOp, pattern>;
682
683class SFXVecInst<ValueType vectype>:
684 SFXInst<(outs VECREG:$rT),
685 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
686 [(set (vectype VECREG:$rT),
687 (SPUsubx (vectype VECREG:$rA), (vectype VECREG:$rB),
688 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000689 RegConstraint<"$rCarry = $rT">,
690 NoEncode<"$rCarry">;
691
Scott Michel67224b22008-06-02 22:18:03 +0000692class SFXRegInst<RegisterClass rclass>:
693 SFXInst<(outs rclass:$rT),
694 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
695 [(set rclass:$rT,
696 (SPUsubx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
697 RegConstraint<"$rCarry = $rT">,
698 NoEncode<"$rCarry">;
699
700multiclass SubtractExtended {
701 def v2i64 : SFXVecInst<v2i64>;
702 def v4i32 : SFXVecInst<v4i32>;
703 def r64 : SFXRegInst<R64C>;
704 def r32 : SFXRegInst<R32C>;
705}
706
707defm SFX : SubtractExtended;
708
Scott Michel8b6b4202007-12-04 22:35:58 +0000709// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000710class BGInst<dag OOL, dag IOL, list<dag> pattern>:
711 RRForm<0b01000010000, OOL, IOL,
712 "bg\t$rT, $rA, $rB",
713 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000714
Scott Michel67224b22008-06-02 22:18:03 +0000715class BGVecInst<ValueType vectype>:
716 BGInst<(outs VECREG:$rT),
717 (ins VECREG:$rA, VECREG:$rB),
718 [(set (vectype VECREG:$rT),
719 (SPUborrow_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
720
721class BGRegInst<RegisterClass rclass>:
722 BGInst<(outs rclass:$rT),
723 (ins rclass:$rA, rclass:$rB),
724 [(set rclass:$rT,
725 (SPUborrow_gen rclass:$rA, rclass:$rB))]>;
726
727multiclass BorrowGenerate {
728 def v4i32 : BGVecInst<v4i32>;
729 def v2i64 : BGVecInst<v2i64>;
730 def r64 : BGRegInst<R64C>;
731 def r32 : BGRegInst<R32C>;
732}
733
734defm BG : BorrowGenerate;
735
736// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000737def BGXvec:
738 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
739 VECREG:$rCarry),
740 "bgx\t$rT, $rA, $rB", IntegerOp,
741 []>,
742 RegConstraint<"$rCarry = $rT">,
743 NoEncode<"$rCarry">;
744
745// Halfword multiply variants:
746// N.B: These can be used to build up larger quantities (16x16 -> 32)
747
748def MPYv8i16:
749 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
750 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
751 [(set (v8i16 VECREG:$rT), (SPUmpy_v8i16 (v8i16 VECREG:$rA),
752 (v8i16 VECREG:$rB)))]>;
753
754def MPYr16:
755 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
756 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
757 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
758
759def MPYUv4i32:
760 RRForm<0b00110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
761 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
762 [(set (v4i32 VECREG:$rT),
763 (SPUmpyu_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
764
765def MPYUr16:
766 RRForm<0b00110011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
767 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
768 [(set R32C:$rT, (mul (zext R16C:$rA),
769 (zext R16C:$rB)))]>;
770
771def MPYUr32:
772 RRForm<0b00110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
773 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
774 [(set R32C:$rT, (SPUmpyu_i32 R32C:$rA, R32C:$rB))]>;
775
776// mpyi: multiply 16 x s10imm -> 32 result (custom lowering for 32 bit result,
777// this only produces the lower 16 bits)
778def MPYIvec:
779 RI10Form<0b00101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
780 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
781 [(set (v8i16 VECREG:$rT), (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
782
783def MPYIr16:
784 RI10Form<0b00101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
785 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
786 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
787
788// mpyui: same issues as other multiplies, plus, this doesn't match a
789// pattern... but may be used during target DAG selection or lowering
790def MPYUIvec:
791 RI10Form<0b10101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
792 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
793 []>;
794
795def MPYUIr16:
796 RI10Form<0b10101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
797 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
798 []>;
799
800// mpya: 16 x 16 + 16 -> 32 bit result
801def MPYAvec:
802 RRRForm<0b0011, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
803 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
804 [(set (v4i32 VECREG:$rT), (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
805 (v8i16 VECREG:$rB)))),
806 (v4i32 VECREG:$rC)))]>;
807
808def MPYAr32:
809 RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
810 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
811 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
812 R32C:$rC))]>;
813
814def : Pat<(add (mul (sext R16C:$rA), (sext R16C:$rB)), R32C:$rC),
815 (MPYAr32 R16C:$rA, R16C:$rB, R32C:$rC)>;
816
817def MPYAr32_sextinreg:
818 RRRForm<0b0011, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
819 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
820 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
821 (sext_inreg R32C:$rB, i16)),
822 R32C:$rC))]>;
823
824//def MPYAr32:
825// RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
826// "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
827// [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
828// R32C:$rC))]>;
829
830// mpyh: multiply high, used to synthesize 32-bit multiplies
831def MPYHv4i32:
832 RRForm<0b10100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
833 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
834 [(set (v4i32 VECREG:$rT),
835 (SPUmpyh_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
836
837def MPYHr32:
838 RRForm<0b10100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
839 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
840 [(set R32C:$rT, (SPUmpyh_i32 R32C:$rA, R32C:$rB))]>;
841
842// mpys: multiply high and shift right (returns the top half of
843// a 16-bit multiply, sign extended to 32 bits.)
844def MPYSvec:
845 RRForm<0b11100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
846 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
847 []>;
848
849def MPYSr16:
850 RRForm<0b11100011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
851 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
852 []>;
853
854// mpyhh: multiply high-high (returns the 32-bit result from multiplying
855// the top 16 bits of the $rA, $rB)
856def MPYHHv8i16:
857 RRForm<0b01100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
858 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
859 [(set (v8i16 VECREG:$rT),
860 (SPUmpyhh_v8i16 (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)))]>;
861
862def MPYHHr32:
863 RRForm<0b01100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
864 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
865 []>;
866
867// mpyhha: Multiply high-high, add to $rT:
868def MPYHHAvec:
869 RRForm<0b01100010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
870 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
871 []>;
872
873def MPYHHAr32:
874 RRForm<0b01100010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
875 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
876 []>;
877
878// mpyhhu: Multiply high-high, unsigned
879def MPYHHUvec:
880 RRForm<0b01110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
881 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
882 []>;
883
884def MPYHHUr32:
885 RRForm<0b01110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
886 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
887 []>;
888
889// mpyhhau: Multiply high-high, unsigned
890def MPYHHAUvec:
891 RRForm<0b01110010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
892 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
893 []>;
894
895def MPYHHAUr32:
896 RRForm<0b01110010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
897 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
898 []>;
899
900// clz: Count leading zeroes
901def CLZv4i32:
902 RRForm_1<0b10100101010, (outs VECREG:$rT), (ins VECREG:$rA),
903 "clz\t$rT, $rA", IntegerOp,
904 [/* intrinsic */]>;
905
906def CLZr32:
907 RRForm_1<0b10100101010, (outs R32C:$rT), (ins R32C:$rA),
908 "clz\t$rT, $rA", IntegerOp,
909 [(set R32C:$rT, (ctlz R32C:$rA))]>;
910
911// cntb: Count ones in bytes (aka "population count")
912// NOTE: This instruction is really a vector instruction, but the custom
913// lowering code uses it in unorthodox ways to support CTPOP for other
914// data types!
915def CNTBv16i8:
916 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
917 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000918 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000919
920def CNTBv8i16 :
921 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
922 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000923 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000924
925def CNTBv4i32 :
926 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
927 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000928 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000929
Scott Michel8b6b4202007-12-04 22:35:58 +0000930// gbb: Gather all low order bits from each byte in $rA into a single 16-bit
931// quantity stored into $rT
932def GBB:
933 RRForm_1<0b01001101100, (outs R16C:$rT), (ins VECREG:$rA),
934 "gbb\t$rT, $rA", GatherOp,
935 []>;
936
937// gbh: Gather all low order bits from each halfword in $rA into a single
938// 8-bit quantity stored in $rT
939def GBH:
940 RRForm_1<0b10001101100, (outs R16C:$rT), (ins VECREG:$rA),
941 "gbh\t$rT, $rA", GatherOp,
942 []>;
943
944// gb: Gather all low order bits from each word in $rA into a single
945// 4-bit quantity stored in $rT
946def GB:
947 RRForm_1<0b00001101100, (outs R16C:$rT), (ins VECREG:$rA),
948 "gb\t$rT, $rA", GatherOp,
949 []>;
950
951// avgb: average bytes
952def AVGB:
953 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
954 "avgb\t$rT, $rA, $rB", ByteOp,
955 []>;
956
957// absdb: absolute difference of bytes
958def ABSDB:
959 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
960 "absdb\t$rT, $rA, $rB", ByteOp,
961 []>;
962
963// sumb: sum bytes into halfwords
964def SUMB:
965 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
966 "sumb\t$rT, $rA, $rB", ByteOp,
967 []>;
968
969// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +0000970class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
971 RRForm_1<0b01101101010, OOL, IOL,
972 "xsbh\t$rDst, $rSrc",
973 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000974
Scott Michel67224b22008-06-02 22:18:03 +0000975class XSBHVecInst<ValueType vectype>:
976 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
977 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000978
Scott Michel67224b22008-06-02 22:18:03 +0000979class XSBHRegInst<RegisterClass rclass>:
980 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
981 [(set rclass:$rDst, (sext_inreg rclass:$rSrc, i8))]>;
982
983multiclass ExtendByteHalfword {
984 def v16i8: XSBHVecInst<v8i16>;
985 def r16: XSBHRegInst<R16C>;
986
987 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
988 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
989 // pattern below). Intentionally doesn't match a pattern because we want the
990 // sext 8->32 pattern to do the work for us, namely because we need the extra
991 // XSHWr32.
992 def r32: XSBHRegInst<R32C>;
993}
994
995defm XSBH : ExtendByteHalfword;
996
997// Sign-extend, but take an 8-bit register to a 16-bit register (not done as
998// sext_inreg)
Scott Michel438be252007-12-17 22:32:34 +0000999def XSBHr8:
Scott Michel67224b22008-06-02 22:18:03 +00001000 XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1001 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001002
1003// Sign extend halfwords to words:
1004def XSHWvec:
1005 RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
1006 "xshw\t$rDest, $rSrc", IntegerOp,
1007 [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
1008
1009def XSHWr32:
1010 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
1011 "xshw\t$rDst, $rSrc", IntegerOp,
1012 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
1013
1014def XSHWr16:
1015 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
1016 "xshw\t$rDst, $rSrc", IntegerOp,
1017 [(set R32C:$rDst, (sext R16C:$rSrc))]>;
1018
1019def XSWDvec:
1020 RRForm_1<0b01100101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
1021 "xswd\t$rDst, $rSrc", IntegerOp,
1022 [(set (v2i64 VECREG:$rDst), (sext (v4i32 VECREG:$rSrc)))]>;
1023
1024def XSWDr64:
1025 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R64C:$rSrc),
1026 "xswd\t$rDst, $rSrc", IntegerOp,
1027 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1028
1029def XSWDr32:
1030 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R32C:$rSrc),
1031 "xswd\t$rDst, $rSrc", IntegerOp,
1032 [(set R64C:$rDst, (SPUsext32_to_64 R32C:$rSrc))]>;
1033
1034def : Pat<(sext R32C:$inp),
1035 (XSWDr32 R32C:$inp)>;
1036
1037// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001038
Scott Michel97872d32008-02-23 18:41:37 +00001039class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1040 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1041 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001042
Scott Michel97872d32008-02-23 18:41:37 +00001043class ANDVecInst<ValueType vectype>:
1044 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1045 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1046 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001047
Scott Michel6baba072008-03-05 23:02:02 +00001048class ANDRegInst<RegisterClass rclass>:
1049 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1050 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1051
Scott Michel97872d32008-02-23 18:41:37 +00001052multiclass BitwiseAnd
1053{
1054 def v16i8: ANDVecInst<v16i8>;
1055 def v8i16: ANDVecInst<v8i16>;
1056 def v4i32: ANDVecInst<v4i32>;
1057 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001058
Scott Michel6baba072008-03-05 23:02:02 +00001059 def r128: ANDRegInst<GPRC>;
1060 def r64: ANDRegInst<R64C>;
1061 def r32: ANDRegInst<R32C>;
1062 def r16: ANDRegInst<R16C>;
1063 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001064
Scott Michel97872d32008-02-23 18:41:37 +00001065 //===---------------------------------------------
1066 // Special instructions to perform the fabs instruction
1067 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1068 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001069
Scott Michel97872d32008-02-23 18:41:37 +00001070 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1071 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001072
Scott Michel97872d32008-02-23 18:41:37 +00001073 // Could use v4i32, but won't for clarity
1074 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1075 [/* Intentionally does not match a pattern */]>;
1076
1077 //===---------------------------------------------
1078
1079 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1080 // quantities -- see 16->32 zext pattern.
1081 //
1082 // This pattern is somewhat artificial, since it might match some
1083 // compiler generated pattern but it is unlikely to do so.
1084
1085 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1086 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1087}
1088
1089defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001090
1091// N.B.: vnot_conv is one of those special target selection pattern fragments,
1092// in which we expect there to be a bit_convert on the constant. Bear in mind
1093// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1094// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001095
Scott Michel97872d32008-02-23 18:41:37 +00001096class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1097 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1098 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001099
Scott Michel97872d32008-02-23 18:41:37 +00001100class ANDCVecInst<ValueType vectype>:
1101 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1102 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1103 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001104
Scott Michel97872d32008-02-23 18:41:37 +00001105class ANDCRegInst<RegisterClass rclass>:
1106 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1107 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001108
Scott Michel97872d32008-02-23 18:41:37 +00001109multiclass AndComplement
1110{
1111 def v16i8: ANDCVecInst<v16i8>;
1112 def v8i16: ANDCVecInst<v8i16>;
1113 def v4i32: ANDCVecInst<v4i32>;
1114 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001115
Scott Michel97872d32008-02-23 18:41:37 +00001116 def r128: ANDCRegInst<GPRC>;
1117 def r64: ANDCRegInst<R64C>;
1118 def r32: ANDCRegInst<R32C>;
1119 def r16: ANDCRegInst<R16C>;
1120 def r8: ANDCRegInst<R8C>;
1121}
Scott Michel438be252007-12-17 22:32:34 +00001122
Scott Michel97872d32008-02-23 18:41:37 +00001123defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001124
Scott Michel97872d32008-02-23 18:41:37 +00001125class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1126 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
1127 IntegerOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001128
Scott Michel97872d32008-02-23 18:41:37 +00001129multiclass AndByteImm
1130{
1131 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1132 [(set (v16i8 VECREG:$rT),
1133 (and (v16i8 VECREG:$rA),
1134 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001135
Scott Michel97872d32008-02-23 18:41:37 +00001136 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1137 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1138}
Scott Michel438be252007-12-17 22:32:34 +00001139
Scott Michel97872d32008-02-23 18:41:37 +00001140defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001141
Scott Michel97872d32008-02-23 18:41:37 +00001142class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1143 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
1144 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001145
Scott Michel97872d32008-02-23 18:41:37 +00001146multiclass AndHalfwordImm
1147{
1148 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1149 [(set (v8i16 VECREG:$rT),
1150 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001151
Scott Michel97872d32008-02-23 18:41:37 +00001152 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1153 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001154
Scott Michel97872d32008-02-23 18:41:37 +00001155 // Zero-extend i8 to i16:
1156 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1157 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1158}
Scott Michel8b6b4202007-12-04 22:35:58 +00001159
Scott Michel97872d32008-02-23 18:41:37 +00001160defm ANDHI : AndHalfwordImm;
1161
1162class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1163 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1164 IntegerOp, pattern>;
1165
1166multiclass AndWordImm
1167{
1168 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1169 [(set (v4i32 VECREG:$rT),
1170 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1171
1172 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1173 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1174
1175 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1176 // pattern below.
1177 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1178 [(set R32C:$rT,
1179 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1180
1181 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1182 // zext 16->32 pattern below.
1183 //
1184 // Note that this pattern is somewhat artificial, since it might match
1185 // something the compiler generates but is unlikely to occur in practice.
1186 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1187 [(set R32C:$rT,
1188 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1189}
1190
1191defm ANDI : AndWordImm;
1192
1193//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001194// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001195//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1196
Scott Michel8b6b4202007-12-04 22:35:58 +00001197// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001198class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1199 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1200 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001201
Scott Michel97872d32008-02-23 18:41:37 +00001202class ORVecInst<ValueType vectype>:
1203 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1204 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1205 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001206
Scott Michel97872d32008-02-23 18:41:37 +00001207class ORRegInst<RegisterClass rclass>:
1208 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1209 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001210
Scott Michel97872d32008-02-23 18:41:37 +00001211class ORPromoteScalar<RegisterClass rclass>:
1212 ORInst<(outs VECREG:$rT), (ins rclass:$rA, rclass:$rB),
1213 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001214
Scott Michel97872d32008-02-23 18:41:37 +00001215class ORExtractElt<RegisterClass rclass>:
1216 ORInst<(outs rclass:$rT), (ins VECREG:$rA, VECREG:$rB),
1217 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001218
Scott Michel97872d32008-02-23 18:41:37 +00001219multiclass BitwiseOr
1220{
1221 def v16i8: ORVecInst<v16i8>;
1222 def v8i16: ORVecInst<v8i16>;
1223 def v4i32: ORVecInst<v4i32>;
1224 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001225
Scott Michel97872d32008-02-23 18:41:37 +00001226 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1227 [(set (v4f32 VECREG:$rT),
1228 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1229 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001230
Scott Michel97872d32008-02-23 18:41:37 +00001231 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1232 [(set (v2f64 VECREG:$rT),
1233 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1234 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001235
Scott Michel97872d32008-02-23 18:41:37 +00001236 def r64: ORRegInst<R64C>;
1237 def r32: ORRegInst<R32C>;
1238 def r16: ORRegInst<R16C>;
1239 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001240
Scott Michel97872d32008-02-23 18:41:37 +00001241 // OR instructions used to copy f32 and f64 registers.
1242 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1243 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001244
Scott Michel97872d32008-02-23 18:41:37 +00001245 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1246 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001247
Scott Michel97872d32008-02-23 18:41:37 +00001248 // scalar->vector promotion:
1249 def v16i8_i8: ORPromoteScalar<R8C>;
1250 def v8i16_i16: ORPromoteScalar<R16C>;
1251 def v4i32_i32: ORPromoteScalar<R32C>;
1252 def v2i64_i64: ORPromoteScalar<R64C>;
1253 def v4f32_f32: ORPromoteScalar<R32FP>;
1254 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001255
Scott Michel97872d32008-02-23 18:41:37 +00001256 // extract element 0:
1257 def i8_v16i8: ORExtractElt<R8C>;
1258 def i16_v8i16: ORExtractElt<R16C>;
1259 def i32_v4i32: ORExtractElt<R32C>;
1260 def i64_v2i64: ORExtractElt<R64C>;
1261 def f32_v4f32: ORExtractElt<R32FP>;
1262 def f64_v2f64: ORExtractElt<R64FP>;
1263}
Scott Michel438be252007-12-17 22:32:34 +00001264
Scott Michel97872d32008-02-23 18:41:37 +00001265defm OR : BitwiseOr;
1266
1267// scalar->vector promotion patterns:
Scott Michel438be252007-12-17 22:32:34 +00001268def : Pat<(v16i8 (SPUpromote_scalar R8C:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001269 (ORv16i8_i8 R8C:$rA, R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001270
Scott Michel8b6b4202007-12-04 22:35:58 +00001271def : Pat<(v8i16 (SPUpromote_scalar R16C:$rA)),
1272 (ORv8i16_i16 R16C:$rA, R16C:$rA)>;
1273
Scott Michel8b6b4202007-12-04 22:35:58 +00001274def : Pat<(v4i32 (SPUpromote_scalar R32C:$rA)),
1275 (ORv4i32_i32 R32C:$rA, R32C:$rA)>;
1276
Scott Michel8b6b4202007-12-04 22:35:58 +00001277def : Pat<(v2i64 (SPUpromote_scalar R64C:$rA)),
1278 (ORv2i64_i64 R64C:$rA, R64C:$rA)>;
1279
Scott Michel8b6b4202007-12-04 22:35:58 +00001280def : Pat<(v4f32 (SPUpromote_scalar R32FP:$rA)),
1281 (ORv4f32_f32 R32FP:$rA, R32FP:$rA)>;
1282
Scott Michel8b6b4202007-12-04 22:35:58 +00001283def : Pat<(v2f64 (SPUpromote_scalar R64FP:$rA)),
1284 (ORv2f64_f64 R64FP:$rA, R64FP:$rA)>;
1285
1286// ORi*_v*: Used to extract vector element 0 (the preferred slot)
Scott Michel438be252007-12-17 22:32:34 +00001287
Scott Michelc630c412008-11-24 17:11:17 +00001288def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001289 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001290
Scott Michelc630c412008-11-24 17:11:17 +00001291def : Pat<(SPUvec2prefslot_chained (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001292 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel394e26d2008-01-17 20:38:41 +00001293
Scott Michelc630c412008-11-24 17:11:17 +00001294def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001295 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1296
Scott Michelc630c412008-11-24 17:11:17 +00001297def : Pat<(SPUvec2prefslot_chained (v8i16 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001298 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1299
Scott Michelc630c412008-11-24 17:11:17 +00001300def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001301 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1302
Scott Michelc630c412008-11-24 17:11:17 +00001303def : Pat<(SPUvec2prefslot_chained (v4i32 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001304 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1305
Scott Michelc630c412008-11-24 17:11:17 +00001306def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001307 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1308
Scott Michelc630c412008-11-24 17:11:17 +00001309def : Pat<(SPUvec2prefslot_chained (v2i64 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001310 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1311
Scott Michelc630c412008-11-24 17:11:17 +00001312def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001313 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1314
Scott Michelc630c412008-11-24 17:11:17 +00001315def : Pat<(SPUvec2prefslot_chained (v4f32 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001316 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1317
Scott Michelc630c412008-11-24 17:11:17 +00001318def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001319 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1320
Scott Michelc630c412008-11-24 17:11:17 +00001321def : Pat<(SPUvec2prefslot_chained (v2f64 VECREG:$rA)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001322 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1323
Scott Michel97872d32008-02-23 18:41:37 +00001324// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001325
Scott Michel97872d32008-02-23 18:41:37 +00001326class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1327 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1328 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001329
Scott Michel97872d32008-02-23 18:41:37 +00001330class ORCVecInst<ValueType vectype>:
1331 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1332 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1333 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001334
Scott Michel97872d32008-02-23 18:41:37 +00001335class ORCRegInst<RegisterClass rclass>:
1336 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1337 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001338
Scott Michel97872d32008-02-23 18:41:37 +00001339multiclass BitwiseOrComplement
1340{
1341 def v16i8: ORCVecInst<v16i8>;
1342 def v8i16: ORCVecInst<v8i16>;
1343 def v4i32: ORCVecInst<v4i32>;
1344 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001345
Scott Michel97872d32008-02-23 18:41:37 +00001346 def r64: ORCRegInst<R64C>;
1347 def r32: ORCRegInst<R32C>;
1348 def r16: ORCRegInst<R16C>;
1349 def r8: ORCRegInst<R8C>;
1350}
1351
1352defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001353
Scott Michel8b6b4202007-12-04 22:35:58 +00001354// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001355class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1356 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1357 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001358
Scott Michel97872d32008-02-23 18:41:37 +00001359class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1360 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1361 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1362 (vectype immpred:$val)))]>;
1363
1364multiclass BitwiseOrByteImm
1365{
1366 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1367
1368 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1369 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1370}
1371
1372defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001373
Scott Michel8b6b4202007-12-04 22:35:58 +00001374// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001375class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1376 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1377 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001378
Scott Michel97872d32008-02-23 18:41:37 +00001379class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1380 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1381 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1382 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001383
Scott Michel97872d32008-02-23 18:41:37 +00001384multiclass BitwiseOrHalfwordImm
1385{
1386 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1387
1388 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1389 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1390
1391 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1392 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1393 [(set R16C:$rT, (or (anyext R8C:$rA),
1394 i16ImmSExt10:$val))]>;
1395}
1396
1397defm ORHI : BitwiseOrHalfwordImm;
1398
1399class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1400 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1401 IntegerOp, pattern>;
1402
1403class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1404 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1405 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1406 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001407
1408// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001409multiclass BitwiseOrImm
1410{
1411 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001412
Scott Michel97872d32008-02-23 18:41:37 +00001413 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1414 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001415
Scott Michel97872d32008-02-23 18:41:37 +00001416 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1417 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1418 // infra "anyext 16->32" pattern.)
1419 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1420 [(set R32C:$rT, (or (anyext R16C:$rA),
1421 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001422
Scott Michel97872d32008-02-23 18:41:37 +00001423 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1424 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1425 // infra "anyext 16->32" pattern.)
1426 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1427 [(set R32C:$rT, (or (anyext R8C:$rA),
1428 i32ImmSExt10:$val))]>;
1429}
Scott Michel8b6b4202007-12-04 22:35:58 +00001430
Scott Michel97872d32008-02-23 18:41:37 +00001431defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001432
Scott Michel8b6b4202007-12-04 22:35:58 +00001433// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1434// $rT[0], slots 1-3 are zeroed.
1435//
Scott Michel438be252007-12-17 22:32:34 +00001436// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001437def ORXv4i32:
1438 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1439 "orx\t$rT, $rA, $rB", IntegerOp,
1440 []>;
1441
Scott Michel438be252007-12-17 22:32:34 +00001442// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001443
Scott Michel6baba072008-03-05 23:02:02 +00001444class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1445 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1446 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001447
Scott Michel6baba072008-03-05 23:02:02 +00001448class XORVecInst<ValueType vectype>:
1449 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1450 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1451 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001452
Scott Michel6baba072008-03-05 23:02:02 +00001453class XORRegInst<RegisterClass rclass>:
1454 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1455 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1456
1457multiclass BitwiseExclusiveOr
1458{
1459 def v16i8: XORVecInst<v16i8>;
1460 def v8i16: XORVecInst<v8i16>;
1461 def v4i32: XORVecInst<v4i32>;
1462 def v2i64: XORVecInst<v2i64>;
1463
1464 def r128: XORRegInst<GPRC>;
1465 def r64: XORRegInst<R64C>;
1466 def r32: XORRegInst<R32C>;
1467 def r16: XORRegInst<R16C>;
1468 def r8: XORRegInst<R8C>;
1469
1470 // Special forms for floating point instructions.
1471 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1472
1473 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1474 [/* no pattern */]>;
1475
1476 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1477 [/* no pattern */]>;
1478
1479 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1480 [/* no pattern, see fneg{32,64} */]>;
1481}
1482
1483defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001484
1485//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001486
Scott Michel97872d32008-02-23 18:41:37 +00001487class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1488 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1489 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001490
Scott Michel97872d32008-02-23 18:41:37 +00001491multiclass XorByteImm
1492{
1493 def v16i8:
1494 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1495 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1496
1497 def r8:
1498 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1499 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1500}
1501
1502defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001503
Scott Michel8b6b4202007-12-04 22:35:58 +00001504def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001505 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001506 "xorhi\t$rT, $rA, $val", IntegerOp,
1507 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1508 v8i16SExt10Imm:$val))]>;
1509
1510def XORHIr16:
1511 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1512 "xorhi\t$rT, $rA, $val", IntegerOp,
1513 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1514
1515def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001516 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001517 "xori\t$rT, $rA, $val", IntegerOp,
1518 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1519 v4i32SExt10Imm:$val))]>;
1520
1521def XORIr32:
1522 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1523 "xori\t$rT, $rA, $val", IntegerOp,
1524 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1525
1526// NAND:
1527def NANDv16i8:
1528 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1529 "nand\t$rT, $rA, $rB", IntegerOp,
1530 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1531 (v16i8 VECREG:$rB))))]>;
1532
1533def NANDv8i16:
1534 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1535 "nand\t$rT, $rA, $rB", IntegerOp,
1536 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1537 (v8i16 VECREG:$rB))))]>;
1538
1539def NANDv4i32:
1540 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1541 "nand\t$rT, $rA, $rB", IntegerOp,
1542 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1543 (v4i32 VECREG:$rB))))]>;
1544
1545def NANDr32:
1546 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1547 "nand\t$rT, $rA, $rB", IntegerOp,
1548 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1549
1550def NANDr16:
1551 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1552 "nand\t$rT, $rA, $rB", IntegerOp,
1553 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1554
Scott Michel438be252007-12-17 22:32:34 +00001555def NANDr8:
1556 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1557 "nand\t$rT, $rA, $rB", IntegerOp,
1558 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1559
Scott Michel8b6b4202007-12-04 22:35:58 +00001560// NOR:
1561def NORv16i8:
1562 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1563 "nor\t$rT, $rA, $rB", IntegerOp,
1564 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1565 (v16i8 VECREG:$rB))))]>;
1566
1567def NORv8i16:
1568 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1569 "nor\t$rT, $rA, $rB", IntegerOp,
1570 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1571 (v8i16 VECREG:$rB))))]>;
1572
1573def NORv4i32:
1574 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1575 "nor\t$rT, $rA, $rB", IntegerOp,
1576 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1577 (v4i32 VECREG:$rB))))]>;
1578
1579def NORr32:
1580 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1581 "nor\t$rT, $rA, $rB", IntegerOp,
1582 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1583
1584def NORr16:
1585 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1586 "nor\t$rT, $rA, $rB", IntegerOp,
1587 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1588
Scott Michel438be252007-12-17 22:32:34 +00001589def NORr8:
1590 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1591 "nor\t$rT, $rA, $rB", IntegerOp,
1592 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1593
Scott Michel8b6b4202007-12-04 22:35:58 +00001594// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001595class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1596 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1597 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001598
Scott Michel6baba072008-03-05 23:02:02 +00001599class SELBVecInst<ValueType vectype>:
1600 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1601 [(set (vectype VECREG:$rT),
1602 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1603 (and (vnot (vectype VECREG:$rC)),
1604 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001605
Scott Michel6baba072008-03-05 23:02:02 +00001606class SELBRegInst<RegisterClass rclass>:
1607 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1608 [(set rclass:$rT,
1609 (or (and rclass:$rA, rclass:$rC),
1610 (and rclass:$rB, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001611
Scott Michel6baba072008-03-05 23:02:02 +00001612multiclass SelectBits
1613{
1614 def v16i8: SELBVecInst<v16i8>;
1615 def v8i16: SELBVecInst<v8i16>;
1616 def v4i32: SELBVecInst<v4i32>;
1617 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001618
Scott Michel6baba072008-03-05 23:02:02 +00001619 def r128: SELBRegInst<GPRC>;
1620 def r64: SELBRegInst<R64C>;
1621 def r32: SELBRegInst<R32C>;
1622 def r16: SELBRegInst<R16C>;
1623 def r8: SELBRegInst<R8C>;
1624}
Scott Michel8b6b4202007-12-04 22:35:58 +00001625
Scott Michel6baba072008-03-05 23:02:02 +00001626defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001627
Scott Michel56a125e2008-11-22 23:50:42 +00001628class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001629 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1630 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001631
Scott Michel56a125e2008-11-22 23:50:42 +00001632def : SPUselbPatVec<v16i8, SELBv16i8>;
1633def : SPUselbPatVec<v8i16, SELBv8i16>;
1634def : SPUselbPatVec<v4i32, SELBv4i32>;
1635def : SPUselbPatVec<v2i64, SELBv2i64>;
1636
1637class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1638 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1639 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1640
1641def : SPUselbPatReg<R8C, SELBr8>;
1642def : SPUselbPatReg<R16C, SELBr16>;
1643def : SPUselbPatReg<R32C, SELBr32>;
1644def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001645
Scott Michel6baba072008-03-05 23:02:02 +00001646class SelectConditional<RegisterClass rclass, SPUInstr inst>:
1647 Pat<(select rclass:$rCond, rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00001648 (inst rclass:$rFalse, rclass:$rTrue, rclass:$rCond)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001649
Scott Michel6baba072008-03-05 23:02:02 +00001650def : SelectConditional<R32C, SELBr32>;
1651def : SelectConditional<R16C, SELBr16>;
1652def : SelectConditional<R8C, SELBr8>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001653
Scott Michel6baba072008-03-05 23:02:02 +00001654// EQV: Equivalence (1 for each same bit, otherwise 0)
1655//
1656// Note: There are a lot of ways to match this bit operator and these patterns
1657// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001658
Scott Michel6baba072008-03-05 23:02:02 +00001659class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1660 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1661 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001662
Scott Michel6baba072008-03-05 23:02:02 +00001663class EQVVecInst<ValueType vectype>:
1664 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1665 [(set (vectype VECREG:$rT),
1666 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1667 (and (vnot (vectype VECREG:$rA)),
1668 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001669
Scott Michel6baba072008-03-05 23:02:02 +00001670class EQVRegInst<RegisterClass rclass>:
1671 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1672 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1673 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001674
Scott Michel6baba072008-03-05 23:02:02 +00001675class EQVVecPattern1<ValueType vectype>:
1676 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1677 [(set (vectype VECREG:$rT),
1678 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001679
Scott Michel6baba072008-03-05 23:02:02 +00001680class EQVRegPattern1<RegisterClass rclass>:
1681 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1682 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001683
Scott Michel6baba072008-03-05 23:02:02 +00001684class EQVVecPattern2<ValueType vectype>:
1685 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1686 [(set (vectype VECREG:$rT),
1687 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1688 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001689
Scott Michel6baba072008-03-05 23:02:02 +00001690class EQVRegPattern2<RegisterClass rclass>:
1691 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1692 [(set rclass:$rT,
1693 (or (and rclass:$rA, rclass:$rB),
1694 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001695
Scott Michel6baba072008-03-05 23:02:02 +00001696class EQVVecPattern3<ValueType vectype>:
1697 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1698 [(set (vectype VECREG:$rT),
1699 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001700
Scott Michel6baba072008-03-05 23:02:02 +00001701class EQVRegPattern3<RegisterClass rclass>:
1702 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1703 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001704
Scott Michel6baba072008-03-05 23:02:02 +00001705multiclass BitEquivalence
1706{
1707 def v16i8: EQVVecInst<v16i8>;
1708 def v8i16: EQVVecInst<v8i16>;
1709 def v4i32: EQVVecInst<v4i32>;
1710 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001711
Scott Michel6baba072008-03-05 23:02:02 +00001712 def v16i8_1: EQVVecPattern1<v16i8>;
1713 def v8i16_1: EQVVecPattern1<v8i16>;
1714 def v4i32_1: EQVVecPattern1<v4i32>;
1715 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001716
Scott Michel6baba072008-03-05 23:02:02 +00001717 def v16i8_2: EQVVecPattern2<v16i8>;
1718 def v8i16_2: EQVVecPattern2<v8i16>;
1719 def v4i32_2: EQVVecPattern2<v4i32>;
1720 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001721
Scott Michel6baba072008-03-05 23:02:02 +00001722 def v16i8_3: EQVVecPattern3<v16i8>;
1723 def v8i16_3: EQVVecPattern3<v8i16>;
1724 def v4i32_3: EQVVecPattern3<v4i32>;
1725 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001726
Scott Michel6baba072008-03-05 23:02:02 +00001727 def r128: EQVRegInst<GPRC>;
1728 def r64: EQVRegInst<R64C>;
1729 def r32: EQVRegInst<R32C>;
1730 def r16: EQVRegInst<R16C>;
1731 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001732
Scott Michel6baba072008-03-05 23:02:02 +00001733 def r128_1: EQVRegPattern1<GPRC>;
1734 def r64_1: EQVRegPattern1<R64C>;
1735 def r32_1: EQVRegPattern1<R32C>;
1736 def r16_1: EQVRegPattern1<R16C>;
1737 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001738
Scott Michel6baba072008-03-05 23:02:02 +00001739 def r128_2: EQVRegPattern2<GPRC>;
1740 def r64_2: EQVRegPattern2<R64C>;
1741 def r32_2: EQVRegPattern2<R32C>;
1742 def r16_2: EQVRegPattern2<R16C>;
1743 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001744
Scott Michel6baba072008-03-05 23:02:02 +00001745 def r128_3: EQVRegPattern3<GPRC>;
1746 def r64_3: EQVRegPattern3<R64C>;
1747 def r32_3: EQVRegPattern3<R32C>;
1748 def r16_3: EQVRegPattern3<R16C>;
1749 def r8_3: EQVRegPattern3<R8C>;
1750}
Scott Michel438be252007-12-17 22:32:34 +00001751
Scott Michel6baba072008-03-05 23:02:02 +00001752defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00001753
1754//===----------------------------------------------------------------------===//
1755// Vector shuffle...
1756//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001757// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
1758// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
1759// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
1760// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00001761//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001762
Scott Michel97872d32008-02-23 18:41:37 +00001763class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
1764 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
1765 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001766
Scott Michel0718cd82008-12-01 17:56:02 +00001767class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00001768 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00001769 [(set (resultvec VECREG:$rT),
1770 (SPUshuffle (resultvec VECREG:$rA),
1771 (resultvec VECREG:$rB),
1772 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00001773
Scott Michel97872d32008-02-23 18:41:37 +00001774multiclass ShuffleBytes
1775{
Scott Michel0718cd82008-12-01 17:56:02 +00001776 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
1777 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
1778 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
1779 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
1780 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
1781 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
1782 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
1783 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001784
Scott Michel0718cd82008-12-01 17:56:02 +00001785 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
1786 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
1787
1788 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
1789 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel97872d32008-02-23 18:41:37 +00001790}
1791
1792defm SHUFB : ShuffleBytes;
1793
Scott Michel8b6b4202007-12-04 22:35:58 +00001794//===----------------------------------------------------------------------===//
1795// Shift and rotate group:
1796//===----------------------------------------------------------------------===//
1797
Scott Michel97872d32008-02-23 18:41:37 +00001798class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
1799 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
1800 RotateShift, pattern>;
1801
1802class SHLHVecInst<ValueType vectype>:
1803 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1804 [(set (vectype VECREG:$rT),
1805 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001806
1807// $rB gets promoted to 32-bit register type when confronted with
1808// this llvm assembly code:
1809//
1810// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
1811// %A = shl i16 %arg1, %arg2
1812// ret i16 %A
1813// }
Scott Michel8b6b4202007-12-04 22:35:58 +00001814
Scott Michel97872d32008-02-23 18:41:37 +00001815multiclass ShiftLeftHalfword
1816{
1817 def v8i16: SHLHVecInst<v8i16>;
1818 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1819 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
1820 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
1821 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
1822}
Scott Michel8b6b4202007-12-04 22:35:58 +00001823
Scott Michel97872d32008-02-23 18:41:37 +00001824defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001825
Scott Michel97872d32008-02-23 18:41:37 +00001826//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00001827
Scott Michel97872d32008-02-23 18:41:37 +00001828class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
1829 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
1830 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001831
Scott Michel97872d32008-02-23 18:41:37 +00001832class SHLHIVecInst<ValueType vectype>:
1833 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
1834 [(set (vectype VECREG:$rT),
1835 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001836
Scott Michel97872d32008-02-23 18:41:37 +00001837multiclass ShiftLeftHalfwordImm
1838{
1839 def v8i16: SHLHIVecInst<v8i16>;
1840 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
1841 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
1842}
1843
1844defm SHLHI : ShiftLeftHalfwordImm;
1845
1846def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
1847 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
1848
1849def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00001850 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001851
Scott Michel97872d32008-02-23 18:41:37 +00001852//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001853
Scott Michel97872d32008-02-23 18:41:37 +00001854class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
1855 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
1856 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001857
Scott Michel97872d32008-02-23 18:41:37 +00001858multiclass ShiftLeftWord
1859{
1860 def v4i32:
1861 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1862 [(set (v4i32 VECREG:$rT),
1863 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
1864 def r32:
1865 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1866 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
1867}
Scott Michel8b6b4202007-12-04 22:35:58 +00001868
Scott Michel97872d32008-02-23 18:41:37 +00001869defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00001870
Scott Michel97872d32008-02-23 18:41:37 +00001871//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001872
Scott Michel97872d32008-02-23 18:41:37 +00001873class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
1874 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
1875 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001876
Scott Michel97872d32008-02-23 18:41:37 +00001877multiclass ShiftLeftWordImm
1878{
1879 def v4i32:
1880 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1881 [(set (v4i32 VECREG:$rT),
1882 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001883
Scott Michel97872d32008-02-23 18:41:37 +00001884 def r32:
1885 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
1886 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
1887}
Scott Michel8b6b4202007-12-04 22:35:58 +00001888
Scott Michel97872d32008-02-23 18:41:37 +00001889defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00001890
Scott Michel97872d32008-02-23 18:41:37 +00001891//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001892// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
1893// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00001894//
1895// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
1896// of 7 bits is actually possible.
1897//
1898// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
1899// to shift i64 and i128. SHLQBI is the residual left over after shifting by
1900// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00001901
Scott Michel97872d32008-02-23 18:41:37 +00001902class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
1903 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
1904 RotateShift, pattern>;
1905
1906class SHLQBIVecInst<ValueType vectype>:
1907 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1908 [(set (vectype VECREG:$rT),
1909 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
1910
1911multiclass ShiftLeftQuadByBits
1912{
1913 def v16i8: SHLQBIVecInst<v16i8>;
1914 def v8i16: SHLQBIVecInst<v8i16>;
1915 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00001916 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00001917 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00001918 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00001919}
1920
1921defm SHLQBI : ShiftLeftQuadByBits;
1922
1923// See note above on SHLQBI. In this case, the predicate actually does then
1924// enforcement, whereas with SHLQBI, we have to "take it on faith."
1925class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
1926 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
1927 RotateShift, pattern>;
1928
1929class SHLQBIIVecInst<ValueType vectype>:
1930 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1931 [(set (vectype VECREG:$rT),
1932 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
1933
1934multiclass ShiftLeftQuadByBitsImm
1935{
1936 def v16i8 : SHLQBIIVecInst<v16i8>;
1937 def v8i16 : SHLQBIIVecInst<v8i16>;
1938 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00001939 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00001940 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00001941 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00001942}
1943
1944defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001945
1946// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00001947// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00001948
Scott Michel97872d32008-02-23 18:41:37 +00001949class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00001950 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00001951 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001952
Scott Michel97872d32008-02-23 18:41:37 +00001953class SHLQBYVecInst<ValueType vectype>:
1954 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1955 [(set (vectype VECREG:$rT),
1956 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001957
Scott Michel97872d32008-02-23 18:41:37 +00001958multiclass ShiftLeftQuadBytes
1959{
1960 def v16i8: SHLQBYVecInst<v16i8>;
1961 def v8i16: SHLQBYVecInst<v8i16>;
1962 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00001963 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00001964 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00001965 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00001966 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
1967 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
1968}
Scott Michel8b6b4202007-12-04 22:35:58 +00001969
Scott Michel97872d32008-02-23 18:41:37 +00001970defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001971
Scott Michel97872d32008-02-23 18:41:37 +00001972class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
1973 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
1974 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001975
Scott Michel97872d32008-02-23 18:41:37 +00001976class SHLQBYIVecInst<ValueType vectype>:
1977 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1978 [(set (vectype VECREG:$rT),
1979 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00001980
Scott Michel97872d32008-02-23 18:41:37 +00001981multiclass ShiftLeftQuadBytesImm
1982{
1983 def v16i8: SHLQBYIVecInst<v16i8>;
1984 def v8i16: SHLQBYIVecInst<v8i16>;
1985 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00001986 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00001987 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00001988 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00001989 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
1990 [(set GPRC:$rT,
1991 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
1992}
Scott Michel438be252007-12-17 22:32:34 +00001993
Scott Michel97872d32008-02-23 18:41:37 +00001994defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00001995
Scott Michel97872d32008-02-23 18:41:37 +00001996//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1997// Rotate halfword:
1998//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1999class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2000 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2001 RotateShift, pattern>;
2002
2003class ROTHVecInst<ValueType vectype>:
2004 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2005 [(set (vectype VECREG:$rT),
2006 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2007
2008class ROTHRegInst<RegisterClass rclass>:
2009 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2010 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2011
2012multiclass RotateLeftHalfword
2013{
2014 def v8i16: ROTHVecInst<v8i16>;
2015 def r16: ROTHRegInst<R16C>;
2016}
2017
2018defm ROTH: RotateLeftHalfword;
2019
2020def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2021 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2022
2023//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2024// Rotate halfword, immediate:
2025//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2026class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2027 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2028 RotateShift, pattern>;
2029
2030class ROTHIVecInst<ValueType vectype>:
2031 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2032 [(set (vectype VECREG:$rT),
2033 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2034
2035multiclass RotateLeftHalfwordImm
2036{
2037 def v8i16: ROTHIVecInst<v8i16>;
2038 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2039 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2040 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2041 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2042}
2043
2044defm ROTHI: RotateLeftHalfwordImm;
2045
2046def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002047 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
2048
Scott Michel97872d32008-02-23 18:41:37 +00002049//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2050// Rotate word:
2051//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002052
Scott Michel97872d32008-02-23 18:41:37 +00002053class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2054 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2055 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002056
Scott Michel97872d32008-02-23 18:41:37 +00002057class ROTVecInst<ValueType vectype>:
2058 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2059 [(set (vectype VECREG:$rT),
2060 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002061
Scott Michel97872d32008-02-23 18:41:37 +00002062class ROTRegInst<RegisterClass rclass>:
2063 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2064 [(set rclass:$rT,
2065 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002066
Scott Michel97872d32008-02-23 18:41:37 +00002067multiclass RotateLeftWord
2068{
2069 def v4i32: ROTVecInst<v4i32>;
2070 def r32: ROTRegInst<R32C>;
2071}
2072
2073defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002074
Scott Michel438be252007-12-17 22:32:34 +00002075// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2076// 32-bit register
2077def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002078 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2079 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002080
2081def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2082 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2083
2084def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2085 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2086
2087def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002088 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2089 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002090
2091def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2092 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2093
2094def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2095 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2096
Scott Michel97872d32008-02-23 18:41:37 +00002097//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2098// Rotate word, immediate
2099//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002100
Scott Michel97872d32008-02-23 18:41:37 +00002101class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2102 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2103 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002104
Scott Michel97872d32008-02-23 18:41:37 +00002105class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2106 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2107 [(set (vectype VECREG:$rT),
2108 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002109
Scott Michel97872d32008-02-23 18:41:37 +00002110class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2111 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2112 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002113
Scott Michel97872d32008-02-23 18:41:37 +00002114multiclass RotateLeftWordImm
2115{
2116 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2117 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2118 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002119
Scott Michel97872d32008-02-23 18:41:37 +00002120 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2121 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2122 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2123}
Scott Michel438be252007-12-17 22:32:34 +00002124
Scott Michel97872d32008-02-23 18:41:37 +00002125defm ROTI : RotateLeftWordImm;
2126
2127//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2128// Rotate quad by byte (count)
2129//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2130
2131class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2132 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2133 RotateShift, pattern>;
2134
2135class ROTQBYVecInst<ValueType vectype>:
2136 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2137 [(set (vectype VECREG:$rT),
2138 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2139
2140multiclass RotateQuadLeftByBytes
2141{
2142 def v16i8: ROTQBYVecInst<v16i8>;
2143 def v8i16: ROTQBYVecInst<v8i16>;
2144 def v4i32: ROTQBYVecInst<v4i32>;
2145 def v2i64: ROTQBYVecInst<v2i64>;
2146}
2147
2148defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002149
Scott Micheldbac4cf2008-01-11 02:53:15 +00002150def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002151 (ROTQBYv16i8 VECREG:$rA, R32C:$rB)>;
2152def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), R32C:$rB),
2153 (ROTQBYv8i16 VECREG:$rA, R32C:$rB)>;
2154def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), R32C:$rB),
2155 (ROTQBYv4i32 VECREG:$rA, R32C:$rB)>;
2156def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), R32C:$rB),
2157 (ROTQBYv2i64 VECREG:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002158
Scott Michel97872d32008-02-23 18:41:37 +00002159//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2160// Rotate quad by byte (count), immediate
2161//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2162
2163class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2164 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2165 RotateShift, pattern>;
2166
2167class ROTQBYIVecInst<ValueType vectype>:
2168 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2169 [(set (vectype VECREG:$rT),
2170 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2171
2172multiclass RotateQuadByBytesImm
2173{
2174 def v16i8: ROTQBYIVecInst<v16i8>;
2175 def v8i16: ROTQBYIVecInst<v8i16>;
2176 def v4i32: ROTQBYIVecInst<v4i32>;
2177 def v2i64: ROTQBYIVecInst<v2i64>;
2178}
2179
2180defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002181
2182def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel97872d32008-02-23 18:41:37 +00002183 (ROTQBYIv16i8 VECREG:$rA, uimm7:$val)>;
2184def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), (i16 uimm7:$val)),
2185 (ROTQBYIv8i16 VECREG:$rA, uimm7:$val)>;
2186def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2187 (ROTQBYIv4i32 VECREG:$rA, uimm7:$val)>;
2188def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), (i16 uimm7:$val)),
2189 (ROTQBYIv2i64 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002190
2191// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002192class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2193 RI7Form<0b00110011100, OOL, IOL,
2194 "rotqbybi\t$rT, $rA, $shift",
2195 RotateShift, pattern>;
2196
2197class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2198 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2199 [(set (vectype VECREG:$rT),
2200 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2201
2202multiclass RotateQuadByBytesByBitshift {
2203 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2204 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2205 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2206 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2207}
2208
2209defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002210
Scott Michel97872d32008-02-23 18:41:37 +00002211//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002212// See ROTQBY note above.
2213//
2214// Assume that the user of this instruction knows to shift the rotate count
2215// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002216//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002217
Scott Michel97872d32008-02-23 18:41:37 +00002218class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2219 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2220 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002221
Scott Michel97872d32008-02-23 18:41:37 +00002222class ROTQBIVecInst<ValueType vectype>:
2223 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2224 [/* no pattern yet */]>;
2225
2226class ROTQBIRegInst<RegisterClass rclass>:
2227 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2228 [/* no pattern yet */]>;
2229
2230multiclass RotateQuadByBitCount
2231{
2232 def v16i8: ROTQBIVecInst<v16i8>;
2233 def v8i16: ROTQBIVecInst<v8i16>;
2234 def v4i32: ROTQBIVecInst<v4i32>;
2235 def v2i64: ROTQBIVecInst<v2i64>;
2236
2237 def r128: ROTQBIRegInst<GPRC>;
2238 def r64: ROTQBIRegInst<R64C>;
2239}
2240
2241defm ROTQBI: RotateQuadByBitCount;
2242
2243class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2244 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2245 RotateShift, pattern>;
2246
2247class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2248 PatLeaf pred>:
2249 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2250 [/* no pattern yet */]>;
2251
2252class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2253 PatLeaf pred>:
2254 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2255 [/* no pattern yet */]>;
2256
2257multiclass RotateQuadByBitCountImm
2258{
2259 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2260 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2261 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2262 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2263
2264 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2265 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2266}
2267
2268defm ROTQBII : RotateQuadByBitCountImm;
2269
2270//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002271// ROTHM v8i16 form:
2272// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2273// so this only matches a synthetically generated/lowered code
2274// fragment.
2275// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002276//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002277
Scott Michel97872d32008-02-23 18:41:37 +00002278class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2279 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2280 RotateShift, pattern>;
2281
2282def ROTHMv8i16:
2283 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2284 [/* see patterns below - $rB must be negated */]>;
2285
2286def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002287 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2288
Scott Michel97872d32008-02-23 18:41:37 +00002289def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002290 (ROTHMv8i16 VECREG:$rA,
2291 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2292
Scott Michel97872d32008-02-23 18:41:37 +00002293def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002294 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002295 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002296
2297// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2298// Note: This instruction doesn't match a pattern because rB must be negated
2299// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002300
Scott Michel8b6b4202007-12-04 22:35:58 +00002301def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002302 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2303 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002304
2305def : Pat<(srl R16C:$rA, R32C:$rB),
2306 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2307
2308def : Pat<(srl R16C:$rA, R16C:$rB),
2309 (ROTHMr16 R16C:$rA,
2310 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2311
Scott Michel438be252007-12-17 22:32:34 +00002312def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002313 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002314 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002315
2316// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2317// that the immediate can be complemented, so that the user doesn't have to
2318// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002319
Scott Michel97872d32008-02-23 18:41:37 +00002320class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2321 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2322 RotateShift, pattern>;
2323
2324def ROTHMIv8i16:
2325 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2326 [/* no pattern */]>;
2327
2328def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2329 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2330
2331def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002332 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002333
Scott Michel97872d32008-02-23 18:41:37 +00002334def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002335 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002336
2337def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002338 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2339 [/* no pattern */]>;
2340
2341def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2342 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002343
2344def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2345 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2346
Scott Michel438be252007-12-17 22:32:34 +00002347def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2348 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2349
Scott Michel8b6b4202007-12-04 22:35:58 +00002350// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002351class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2352 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2353 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002354
Scott Michel97872d32008-02-23 18:41:37 +00002355def ROTMv4i32:
2356 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2357 [/* see patterns below - $rB must be negated */]>;
2358
2359def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002360 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2361
Scott Michel97872d32008-02-23 18:41:37 +00002362def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002363 (ROTMv4i32 VECREG:$rA,
2364 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2365
Scott Michel97872d32008-02-23 18:41:37 +00002366def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002367 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002368 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002369
2370def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002371 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2372 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002373
2374def : Pat<(srl R32C:$rA, R32C:$rB),
2375 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2376
2377def : Pat<(srl R32C:$rA, R16C:$rB),
2378 (ROTMr32 R32C:$rA,
2379 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2380
Scott Michel438be252007-12-17 22:32:34 +00002381def : Pat<(srl R32C:$rA, R8C:$rB),
2382 (ROTMr32 R32C:$rA,
2383 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2384
Scott Michel8b6b4202007-12-04 22:35:58 +00002385// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2386def ROTMIv4i32:
2387 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2388 "rotmi\t$rT, $rA, $val", RotateShift,
2389 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002390 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002391
Scott Michel97872d32008-02-23 18:41:37 +00002392def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002393 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002394
Scott Michel97872d32008-02-23 18:41:37 +00002395def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002396 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002397
2398// ROTMI r32 form: know how to complement the immediate value.
2399def ROTMIr32:
2400 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2401 "rotmi\t$rT, $rA, $val", RotateShift,
2402 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2403
2404def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2405 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2406
Scott Michel438be252007-12-17 22:32:34 +00002407def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2408 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2409
Scott Michel97872d32008-02-23 18:41:37 +00002410//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002411// ROTQMBYvec: This is a vector form merely so that when used in an
2412// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002413// that the user knew to negate $rB.
2414//
2415// Using the SPUrotquad_rz_bytes target-specific DAG node, the patterns
2416// ensure that $rB is negated.
2417//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002418
Scott Michel97872d32008-02-23 18:41:37 +00002419class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2420 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2421 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002422
Scott Michel97872d32008-02-23 18:41:37 +00002423class ROTQMBYVecInst<ValueType vectype>:
2424 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2425 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002426
Scott Michel97872d32008-02-23 18:41:37 +00002427class ROTQMBYRegInst<RegisterClass rclass>:
2428 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2429 [(set rclass:$rT,
2430 (SPUrotquad_rz_bytes rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002431
Scott Michel97872d32008-02-23 18:41:37 +00002432multiclass RotateQuadBytes
2433{
2434 def v16i8: ROTQMBYVecInst<v16i8>;
2435 def v8i16: ROTQMBYVecInst<v8i16>;
2436 def v4i32: ROTQMBYVecInst<v4i32>;
2437 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002438
Scott Michel97872d32008-02-23 18:41:37 +00002439 def r128: ROTQMBYRegInst<GPRC>;
2440 def r64: ROTQMBYRegInst<R64C>;
2441}
2442
2443defm ROTQMBY : RotateQuadBytes;
2444
2445def : Pat<(SPUrotquad_rz_bytes (v16i8 VECREG:$rA), R32C:$rB),
2446 (ROTQMBYv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2447def : Pat<(SPUrotquad_rz_bytes (v8i16 VECREG:$rA), R32C:$rB),
2448 (ROTQMBYv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2449def : Pat<(SPUrotquad_rz_bytes (v4i32 VECREG:$rA), R32C:$rB),
2450 (ROTQMBYv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2451def : Pat<(SPUrotquad_rz_bytes (v2i64 VECREG:$rA), R32C:$rB),
2452 (ROTQMBYv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2453def : Pat<(SPUrotquad_rz_bytes GPRC:$rA, R32C:$rB),
2454 (ROTQMBYr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2455def : Pat<(SPUrotquad_rz_bytes R64C:$rA, R32C:$rB),
2456 (ROTQMBYr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2457
2458class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2459 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2460 RotateShift, pattern>;
2461
2462class ROTQMBYIVecInst<ValueType vectype>:
2463 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2464 [(set (vectype VECREG:$rT),
2465 (SPUrotquad_rz_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2466
2467class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2468 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2469 [(set rclass:$rT,
2470 (SPUrotquad_rz_bytes rclass:$rA, (inttype pred:$val)))]>;
2471
2472multiclass RotateQuadBytesImm
2473{
2474 def v16i8: ROTQMBYIVecInst<v16i8>;
2475 def v8i16: ROTQMBYIVecInst<v8i16>;
2476 def v4i32: ROTQMBYIVecInst<v4i32>;
2477 def v2i64: ROTQMBYIVecInst<v2i64>;
2478
2479 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2480 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2481}
2482
2483defm ROTQMBYI : RotateQuadBytesImm;
2484
Scott Michel97872d32008-02-23 18:41:37 +00002485//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2486// Rotate right and mask by bit count
2487//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2488
2489class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2490 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2491 RotateShift, pattern>;
2492
2493class ROTQMBYBIVecInst<ValueType vectype>:
2494 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2495 [/* no pattern, intrinsic? */]>;
2496
2497multiclass RotateMaskQuadByBitCount
2498{
2499 def v16i8: ROTQMBYBIVecInst<v16i8>;
2500 def v8i16: ROTQMBYBIVecInst<v8i16>;
2501 def v4i32: ROTQMBYBIVecInst<v4i32>;
2502 def v2i64: ROTQMBYBIVecInst<v2i64>;
2503}
2504
2505defm ROTQMBYBI: RotateMaskQuadByBitCount;
2506
2507//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2508// Rotate quad and mask by bits
2509// Note that the rotate amount has to be negated
2510//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2511
2512class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2513 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2514 RotateShift, pattern>;
2515
2516class ROTQMBIVecInst<ValueType vectype>:
2517 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2518 [/* no pattern */]>;
2519
2520class ROTQMBIRegInst<RegisterClass rclass>:
2521 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2522 [/* no pattern */]>;
2523
2524multiclass RotateMaskQuadByBits
2525{
2526 def v16i8: ROTQMBIVecInst<v16i8>;
2527 def v8i16: ROTQMBIVecInst<v8i16>;
2528 def v4i32: ROTQMBIVecInst<v4i32>;
2529 def v2i64: ROTQMBIVecInst<v2i64>;
2530
2531 def r128: ROTQMBIRegInst<GPRC>;
2532 def r64: ROTQMBIRegInst<R64C>;
2533}
2534
2535defm ROTQMBI: RotateMaskQuadByBits;
2536
2537def : Pat<(SPUrotquad_rz_bits (v16i8 VECREG:$rA), R32C:$rB),
2538 (ROTQMBIv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2539def : Pat<(SPUrotquad_rz_bits (v8i16 VECREG:$rA), R32C:$rB),
2540 (ROTQMBIv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2541def : Pat<(SPUrotquad_rz_bits (v4i32 VECREG:$rA), R32C:$rB),
2542 (ROTQMBIv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2543def : Pat<(SPUrotquad_rz_bits (v2i64 VECREG:$rA), R32C:$rB),
2544 (ROTQMBIv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2545def : Pat<(SPUrotquad_rz_bits GPRC:$rA, R32C:$rB),
2546 (ROTQMBIr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2547def : Pat<(SPUrotquad_rz_bits R64C:$rA, R32C:$rB),
2548 (ROTQMBIr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2549
2550//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2551// Rotate quad and mask by bits, immediate
2552//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2553
2554class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2555 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2556 RotateShift, pattern>;
2557
2558class ROTQMBIIVecInst<ValueType vectype>:
2559 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2560 [(set (vectype VECREG:$rT),
2561 (SPUrotquad_rz_bits (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2562
2563class ROTQMBIIRegInst<RegisterClass rclass>:
2564 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2565 [(set rclass:$rT,
2566 (SPUrotquad_rz_bits rclass:$rA, (i32 uimm7:$val)))]>;
2567
2568multiclass RotateMaskQuadByBitsImm
2569{
2570 def v16i8: ROTQMBIIVecInst<v16i8>;
2571 def v8i16: ROTQMBIIVecInst<v8i16>;
2572 def v4i32: ROTQMBIIVecInst<v4i32>;
2573 def v2i64: ROTQMBIIVecInst<v2i64>;
2574
2575 def r128: ROTQMBIIRegInst<GPRC>;
2576 def r64: ROTQMBIIRegInst<R64C>;
2577}
2578
2579defm ROTQMBII: RotateMaskQuadByBitsImm;
2580
2581//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2582//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002583
2584def ROTMAHv8i16:
2585 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2586 "rotmah\t$rT, $rA, $rB", RotateShift,
2587 [/* see patterns below - $rB must be negated */]>;
2588
Scott Michel97872d32008-02-23 18:41:37 +00002589def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002590 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2591
Scott Michel97872d32008-02-23 18:41:37 +00002592def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002593 (ROTMAHv8i16 VECREG:$rA,
2594 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2595
Scott Michel97872d32008-02-23 18:41:37 +00002596def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002597 (ROTMAHv8i16 VECREG:$rA,
2598 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2599
Scott Michel8b6b4202007-12-04 22:35:58 +00002600def ROTMAHr16:
2601 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2602 "rotmah\t$rT, $rA, $rB", RotateShift,
2603 [/* see patterns below - $rB must be negated */]>;
2604
2605def : Pat<(sra R16C:$rA, R32C:$rB),
2606 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2607
2608def : Pat<(sra R16C:$rA, R16C:$rB),
2609 (ROTMAHr16 R16C:$rA,
2610 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2611
Scott Michel438be252007-12-17 22:32:34 +00002612def : Pat<(sra R16C:$rA, R8C:$rB),
2613 (ROTMAHr16 R16C:$rA,
2614 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2615
Scott Michel8b6b4202007-12-04 22:35:58 +00002616def ROTMAHIv8i16:
2617 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2618 "rotmahi\t$rT, $rA, $val", RotateShift,
2619 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002620 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002621
Scott Michel97872d32008-02-23 18:41:37 +00002622def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002623 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2624
Scott Michel97872d32008-02-23 18:41:37 +00002625def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002626 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2627
Scott Michel8b6b4202007-12-04 22:35:58 +00002628def ROTMAHIr16:
2629 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2630 "rotmahi\t$rT, $rA, $val", RotateShift,
2631 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2632
2633def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2634 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2635
Scott Michel438be252007-12-17 22:32:34 +00002636def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2637 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2638
Scott Michel8b6b4202007-12-04 22:35:58 +00002639def ROTMAv4i32:
2640 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2641 "rotma\t$rT, $rA, $rB", RotateShift,
2642 [/* see patterns below - $rB must be negated */]>;
2643
Scott Michel97872d32008-02-23 18:41:37 +00002644def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002645 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2646
Scott Michel97872d32008-02-23 18:41:37 +00002647def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002648 (ROTMAv4i32 (v4i32 VECREG:$rA),
2649 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2650
Scott Michel97872d32008-02-23 18:41:37 +00002651def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002652 (ROTMAv4i32 (v4i32 VECREG:$rA),
2653 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2654
Scott Michel8b6b4202007-12-04 22:35:58 +00002655def ROTMAr32:
2656 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2657 "rotma\t$rT, $rA, $rB", RotateShift,
2658 [/* see patterns below - $rB must be negated */]>;
2659
2660def : Pat<(sra R32C:$rA, R32C:$rB),
2661 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2662
2663def : Pat<(sra R32C:$rA, R16C:$rB),
2664 (ROTMAr32 R32C:$rA,
2665 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2666
Scott Michel438be252007-12-17 22:32:34 +00002667def : Pat<(sra R32C:$rA, R8C:$rB),
2668 (ROTMAr32 R32C:$rA,
2669 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2670
Scott Michel67224b22008-06-02 22:18:03 +00002671class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2672 RRForm<0b01011110000, OOL, IOL,
2673 "rotmai\t$rT, $rA, $val",
2674 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002675
Scott Michel67224b22008-06-02 22:18:03 +00002676class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2677 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2678 [(set (vectype VECREG:$rT),
2679 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002680
Scott Michel67224b22008-06-02 22:18:03 +00002681class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2682 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2683 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002684
Scott Michel67224b22008-06-02 22:18:03 +00002685multiclass RotateMaskAlgebraicImm {
2686 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2687 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2688 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2689 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2690}
Scott Michel8b6b4202007-12-04 22:35:58 +00002691
Scott Michel67224b22008-06-02 22:18:03 +00002692defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00002693
Scott Michel8b6b4202007-12-04 22:35:58 +00002694//===----------------------------------------------------------------------===//
2695// Branch and conditionals:
2696//===----------------------------------------------------------------------===//
2697
2698let isTerminator = 1, isBarrier = 1 in {
2699 // Halt If Equal (r32 preferred slot only, no vector form)
2700 def HEQr32:
2701 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2702 "heq\t$rA, $rB", BranchResolv,
2703 [/* no pattern to match */]>;
2704
2705 def HEQIr32 :
2706 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2707 "heqi\t$rA, $val", BranchResolv,
2708 [/* no pattern to match */]>;
2709
2710 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2711 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2712 def HGTr32:
2713 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2714 "hgt\t$rA, $rB", BranchResolv,
2715 [/* no pattern to match */]>;
2716
2717 def HGTIr32:
2718 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2719 "hgti\t$rA, $val", BranchResolv,
2720 [/* no pattern to match */]>;
2721
2722 def HLGTr32:
2723 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2724 "hlgt\t$rA, $rB", BranchResolv,
2725 [/* no pattern to match */]>;
2726
2727 def HLGTIr32:
2728 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2729 "hlgti\t$rA, $val", BranchResolv,
2730 [/* no pattern to match */]>;
2731}
2732
Scott Michel97872d32008-02-23 18:41:37 +00002733//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002734// Comparison operators:
Scott Michel97872d32008-02-23 18:41:37 +00002735//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002736
Scott Michel97872d32008-02-23 18:41:37 +00002737class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2738 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2739 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002740
Scott Michel97872d32008-02-23 18:41:37 +00002741multiclass CmpEqualByte
2742{
2743 def v16i8 :
2744 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2745 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2746 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002747
Scott Michel97872d32008-02-23 18:41:37 +00002748 def r8 :
2749 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2750 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2751}
Scott Michel8b6b4202007-12-04 22:35:58 +00002752
Scott Michel97872d32008-02-23 18:41:37 +00002753class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2754 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2755 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002756
Scott Michel97872d32008-02-23 18:41:37 +00002757multiclass CmpEqualByteImm
2758{
2759 def v16i8 :
2760 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2761 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2762 v16i8SExt8Imm:$val))]>;
2763 def r8:
2764 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2765 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
2766}
Scott Michel8b6b4202007-12-04 22:35:58 +00002767
Scott Michel97872d32008-02-23 18:41:37 +00002768class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
2769 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
2770 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002771
Scott Michel97872d32008-02-23 18:41:37 +00002772multiclass CmpEqualHalfword
2773{
2774 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2775 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2776 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002777
Scott Michel97872d32008-02-23 18:41:37 +00002778 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2779 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
2780}
Scott Michel8b6b4202007-12-04 22:35:58 +00002781
Scott Michel97872d32008-02-23 18:41:37 +00002782class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
2783 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
2784 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002785
Scott Michel97872d32008-02-23 18:41:37 +00002786multiclass CmpEqualHalfwordImm
2787{
2788 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2789 [(set (v8i16 VECREG:$rT),
2790 (seteq (v8i16 VECREG:$rA),
2791 (v8i16 v8i16SExt10Imm:$val)))]>;
2792 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2793 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
2794}
Scott Michel8b6b4202007-12-04 22:35:58 +00002795
Scott Michel97872d32008-02-23 18:41:37 +00002796class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
2797 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
2798 ByteOp, pattern>;
2799
2800multiclass CmpEqualWord
2801{
2802 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2803 [(set (v4i32 VECREG:$rT),
2804 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2805
2806 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2807 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
2808}
2809
2810class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
2811 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
2812 ByteOp, pattern>;
2813
2814multiclass CmpEqualWordImm
2815{
2816 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2817 [(set (v4i32 VECREG:$rT),
2818 (seteq (v4i32 VECREG:$rA),
2819 (v4i32 v4i32SExt16Imm:$val)))]>;
2820
2821 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2822 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
2823}
2824
2825class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
2826 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
2827 ByteOp, pattern>;
2828
2829multiclass CmpGtrByte
2830{
2831 def v16i8 :
2832 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2833 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2834 (v8i16 VECREG:$rB)))]>;
2835
2836 def r8 :
2837 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2838 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
2839}
2840
2841class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
2842 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
2843 ByteOp, pattern>;
2844
2845multiclass CmpGtrByteImm
2846{
2847 def v16i8 :
2848 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2849 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
2850 v16i8SExt8Imm:$val))]>;
2851 def r8:
2852 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00002853 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002854}
2855
2856class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
2857 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
2858 ByteOp, pattern>;
2859
2860multiclass CmpGtrHalfword
2861{
2862 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2863 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2864 (v8i16 VECREG:$rB)))]>;
2865
2866 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2867 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
2868}
2869
2870class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
2871 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
2872 ByteOp, pattern>;
2873
2874multiclass CmpGtrHalfwordImm
2875{
2876 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2877 [(set (v8i16 VECREG:$rT),
2878 (setgt (v8i16 VECREG:$rA),
2879 (v8i16 v8i16SExt10Imm:$val)))]>;
2880 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2881 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
2882}
2883
2884class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
2885 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
2886 ByteOp, pattern>;
2887
2888multiclass CmpGtrWord
2889{
2890 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2891 [(set (v4i32 VECREG:$rT),
2892 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2893
2894 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2895 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
2896}
2897
2898class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
2899 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
2900 ByteOp, pattern>;
2901
2902multiclass CmpGtrWordImm
2903{
2904 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2905 [(set (v4i32 VECREG:$rT),
2906 (setgt (v4i32 VECREG:$rA),
2907 (v4i32 v4i32SExt16Imm:$val)))]>;
2908
2909 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2910 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
2911}
2912
2913class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002914 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002915 ByteOp, pattern>;
2916
2917multiclass CmpLGtrByte
2918{
2919 def v16i8 :
2920 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2921 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2922 (v8i16 VECREG:$rB)))]>;
2923
2924 def r8 :
2925 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2926 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
2927}
2928
2929class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002930 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002931 ByteOp, pattern>;
2932
2933multiclass CmpLGtrByteImm
2934{
2935 def v16i8 :
2936 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2937 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
2938 v16i8SExt8Imm:$val))]>;
2939 def r8:
2940 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2941 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
2942}
2943
2944class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002945 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002946 ByteOp, pattern>;
2947
2948multiclass CmpLGtrHalfword
2949{
2950 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2951 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2952 (v8i16 VECREG:$rB)))]>;
2953
2954 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2955 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
2956}
2957
2958class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002959 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002960 ByteOp, pattern>;
2961
2962multiclass CmpLGtrHalfwordImm
2963{
2964 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2965 [(set (v8i16 VECREG:$rT),
2966 (setugt (v8i16 VECREG:$rA),
2967 (v8i16 v8i16SExt10Imm:$val)))]>;
2968 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2969 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
2970}
2971
2972class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002973 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002974 ByteOp, pattern>;
2975
2976multiclass CmpLGtrWord
2977{
2978 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2979 [(set (v4i32 VECREG:$rT),
2980 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2981
2982 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2983 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
2984}
2985
2986class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002987 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002988 ByteOp, pattern>;
2989
2990multiclass CmpLGtrWordImm
2991{
2992 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2993 [(set (v4i32 VECREG:$rT),
2994 (setugt (v4i32 VECREG:$rA),
2995 (v4i32 v4i32SExt16Imm:$val)))]>;
2996
2997 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00002998 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002999}
3000
3001defm CEQB : CmpEqualByte;
3002defm CEQBI : CmpEqualByteImm;
3003defm CEQH : CmpEqualHalfword;
3004defm CEQHI : CmpEqualHalfwordImm;
3005defm CEQ : CmpEqualWord;
3006defm CEQI : CmpEqualWordImm;
3007defm CGTB : CmpGtrByte;
3008defm CGTBI : CmpGtrByteImm;
3009defm CGTH : CmpGtrHalfword;
3010defm CGTHI : CmpGtrHalfwordImm;
3011defm CGT : CmpGtrWord;
3012defm CGTI : CmpGtrWordImm;
3013defm CLGTB : CmpLGtrByte;
3014defm CLGTBI : CmpLGtrByteImm;
3015defm CLGTH : CmpLGtrHalfword;
3016defm CLGTHI : CmpLGtrHalfwordImm;
3017defm CLGT : CmpLGtrWord;
3018defm CLGTI : CmpLGtrWordImm;
3019
Scott Michel53ab7792008-03-10 16:58:52 +00003020//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003021// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3022// define a pattern to generate the right code, as a binary operator
3023// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003024//
3025// N.B.: This only matches the setcc set of conditionals. Special pattern
3026// matching is used for select conditionals.
3027//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003028
Scott Michel53ab7792008-03-10 16:58:52 +00003029class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3030 SPUInstr xorinst, SPUInstr cmpare>:
3031 Pat<(cond rclass:$rA, rclass:$rB),
3032 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3033
3034class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3035 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3036 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3037 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3038
3039def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
3040def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3041
3042def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
3043def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3044
3045def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3046def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003047
3048class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3049 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3050 Pat<(cond rclass:$rA, rclass:$rB),
3051 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3052 (cmpOp2 rclass:$rA, rclass:$rB))>;
3053
3054class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3055 ValueType immtype,
3056 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3057 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3058 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3059 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3060
Scott Michel53ab7792008-03-10 16:58:52 +00003061def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3062def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3063def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3064def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3065def : Pat<(setle R8C:$rA, R8C:$rB),
3066 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3067def : Pat<(setle R8C:$rA, immU8:$imm),
3068 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003069
Scott Michel53ab7792008-03-10 16:58:52 +00003070def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3071def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3072 ORr16, CGTHIr16, CEQHIr16>;
3073def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3074def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3075def : Pat<(setle R16C:$rA, R16C:$rB),
3076 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3077def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3078 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003079
Scott Michel53ab7792008-03-10 16:58:52 +00003080def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3081def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3082 ORr32, CGTIr32, CEQIr32>;
3083def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3084def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3085def : Pat<(setle R32C:$rA, R32C:$rB),
3086 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3087def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3088 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003089
Scott Michel53ab7792008-03-10 16:58:52 +00003090def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3091def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3092def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3093def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3094def : Pat<(setule R8C:$rA, R8C:$rB),
3095 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3096def : Pat<(setule R8C:$rA, immU8:$imm),
3097 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003098
Scott Michel53ab7792008-03-10 16:58:52 +00003099def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3100def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3101 ORr16, CLGTHIr16, CEQHIr16>;
3102def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3103def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3104 CLGTHIr16, CEQHIr16>;
3105def : Pat<(setule R16C:$rA, R16C:$rB),
3106 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003107def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003108 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003109
Scott Michel53ab7792008-03-10 16:58:52 +00003110def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003111def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003112 ORr32, CLGTIr32, CEQIr32>;
3113def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003114def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003115def : Pat<(setule R32C:$rA, R32C:$rB),
3116 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3117def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3118 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003119
Scott Michel53ab7792008-03-10 16:58:52 +00003120//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3121// select conditional patterns:
3122//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3123
3124class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3125 SPUInstr selinstr, SPUInstr cmpare>:
3126 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3127 rclass:$rTrue, rclass:$rFalse),
3128 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003129 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003130
3131class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3132 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3133 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003134 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003135 (selinstr rclass:$rTrue, rclass:$rFalse,
3136 (cmpare rclass:$rA, immpred:$imm))>;
3137
3138def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3139def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3140def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3141def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3142def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3143def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3144
3145def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3146def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3147def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3148def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3149def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3150def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3151
3152def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3153def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3154def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3155def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3156def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3157def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3158
3159class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3160 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3161 SPUInstr cmpOp2>:
3162 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3163 rclass:$rFalse, rclass:$rTrue),
3164 (selinstr rclass:$rTrue, rclass:$rFalse,
3165 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3166 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3167
3168class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3169 ValueType inttype,
3170 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3171 SPUInstr cmpOp2>:
3172 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003173 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003174 (selinstr rclass:$rFalse, rclass:$rTrue,
3175 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3176 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3177
3178def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3179def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3180 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3181
3182def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3183def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3184 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3185
3186def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3187def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3188 SELBr32, ORr32, CGTIr32, CEQIr32>;
3189
3190def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3191def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3192 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3193
3194def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3195def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3196 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3197
3198def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3199def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3200 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003201
3202//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003203
3204let isCall = 1,
3205 // All calls clobber the non-callee-saved registers:
3206 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3207 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3208 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3209 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3210 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3211 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3212 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3213 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3214 // All of these instructions use $lr (aka $0)
3215 Uses = [R0] in {
3216 // Branch relative and set link: Used if we actually know that the target
3217 // is within [-32768, 32767] bytes of the target
3218 def BRSL:
3219 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3220 "brsl\t$$lr, $func",
3221 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3222
3223 // Branch absolute and set link: Used if we actually know that the target
3224 // is an absolute address
3225 def BRASL:
3226 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3227 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003228 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003229
3230 // Branch indirect and set link if external data. These instructions are not
3231 // actually generated, matched by an intrinsic:
3232 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3233 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3234 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3235 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3236
3237 // Branch indirect and set link. This is the "X-form" address version of a
3238 // function call
3239 def BISL:
3240 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3241}
3242
3243// Unconditional branches:
3244let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3245 def BR :
3246 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3247 "br\t$dest",
3248 [(br bb:$dest)]>;
3249
3250 // Unconditional, absolute address branch
3251 def BRA:
3252 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3253 "bra\t$dest",
3254 [/* no pattern */]>;
3255
3256 // Indirect branch
3257 def BI:
3258 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3259
3260 // Various branches:
3261 def BRNZ:
3262 RI16Form<0b010000100, (outs), (ins R32C:$rCond, brtarget:$dest),
3263 "brnz\t$rCond,$dest",
3264 BranchResolv,
3265 [(brcond R32C:$rCond, bb:$dest)]>;
3266
3267 def BRZ:
3268 RI16Form<0b000000100, (outs), (ins R32C:$rT, brtarget:$dest),
3269 "brz\t$rT,$dest",
3270 BranchResolv,
3271 [/* no pattern */]>;
3272
3273 def BRHNZ:
3274 RI16Form<0b011000100, (outs), (ins R16C:$rCond, brtarget:$dest),
3275 "brhnz\t$rCond,$dest",
3276 BranchResolv,
3277 [(brcond R16C:$rCond, bb:$dest)]>;
3278
3279 def BRHZ:
3280 RI16Form<0b001000100, (outs), (ins R16C:$rT, brtarget:$dest),
3281 "brhz\t$rT,$dest",
3282 BranchResolv,
3283 [/* no pattern */]>;
3284
3285/*
3286 def BINZ:
3287 BICondForm<0b10010100100, "binz\t$rA, $func",
3288 [(SPUbinz R32C:$rA, R32C:$func)]>;
3289
3290 def BIZ:
3291 BICondForm<0b00010100100, "biz\t$rA, $func",
3292 [(SPUbiz R32C:$rA, R32C:$func)]>;
3293*/
3294}
3295
Scott Michel394e26d2008-01-17 20:38:41 +00003296//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003297// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003298//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003299
Scott Michel8b6b4202007-12-04 22:35:58 +00003300def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3301 (BRHZ R16C:$rA, bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003302def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3303 (BRHNZ R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003304
3305def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3306 (BRZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003307def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
Scott Michel394e26d2008-01-17 20:38:41 +00003308 (BRNZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003309
Scott Michel97872d32008-02-23 18:41:37 +00003310multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3311{
3312 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3313 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003314
Scott Michel97872d32008-02-23 18:41:37 +00003315 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3316 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3317
3318 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3319 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3320
3321 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3322 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3323}
3324
3325defm BRCONDeq : BranchCondEQ<seteq, BRHZ, BRZ>;
3326defm BRCONDne : BranchCondEQ<setne, BRHNZ, BRNZ>;
3327
3328multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3329{
3330 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3331 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3332
3333 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3334 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3335
3336 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3337 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3338
3339 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3340 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3341}
3342
3343defm BRCONDugt : BranchCondLGT<setugt, BRHNZ, BRNZ>;
3344defm BRCONDule : BranchCondLGT<setule, BRHZ, BRZ>;
3345
3346multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3347 SPUInstr orinst32, SPUInstr brinst32>
3348{
3349 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3350 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3351 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3352 bb:$dest)>;
3353
3354 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3355 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3356 (CEQHr16 R16C:$rA, R16:$rB)),
3357 bb:$dest)>;
3358
3359 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3360 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3361 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3362 bb:$dest)>;
3363
3364 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3365 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3366 (CEQr32 R32C:$rA, R32C:$rB)),
3367 bb:$dest)>;
3368}
3369
3370defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZ, ORr32, BRNZ>;
3371defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZ, ORr32, BRZ>;
3372
3373multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3374{
3375 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3376 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3377
3378 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3379 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3380
3381 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3382 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3383
3384 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3385 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3386}
3387
3388defm BRCONDgt : BranchCondGT<setgt, BRHNZ, BRNZ>;
3389defm BRCONDle : BranchCondGT<setle, BRHZ, BRZ>;
3390
3391multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3392 SPUInstr orinst32, SPUInstr brinst32>
3393{
3394 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3395 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3396 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3397 bb:$dest)>;
3398
3399 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3400 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3401 (CEQHr16 R16C:$rA, R16:$rB)),
3402 bb:$dest)>;
3403
3404 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3405 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3406 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3407 bb:$dest)>;
3408
3409 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3410 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3411 (CEQr32 R32C:$rA, R32C:$rB)),
3412 bb:$dest)>;
3413}
3414
3415defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZ, ORr32, BRNZ>;
3416defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZ, ORr32, BRZ>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003417
Scott Michel8b6b4202007-12-04 22:35:58 +00003418let isTerminator = 1, isBarrier = 1 in {
3419 let isReturn = 1 in {
3420 def RET:
3421 RETForm<"bi\t$$lr", [(retflag)]>;
3422 }
3423}
3424
3425//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003426// Single precision floating point instructions
3427//===----------------------------------------------------------------------===//
3428
3429def FAv4f32:
3430 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3431 "fa\t$rT, $rA, $rB", SPrecFP,
3432 [(set (v4f32 VECREG:$rT), (fadd (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3433
3434def FAf32 :
3435 RRForm<0b00100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3436 "fa\t$rT, $rA, $rB", SPrecFP,
3437 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3438
3439def FSv4f32:
3440 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3441 "fs\t$rT, $rA, $rB", SPrecFP,
3442 [(set (v4f32 VECREG:$rT), (fsub (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3443
3444def FSf32 :
3445 RRForm<0b10100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3446 "fs\t$rT, $rA, $rB", SPrecFP,
3447 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3448
3449// Floating point reciprocal estimate
3450def FREv4f32 :
3451 RRForm_1<0b00011101100, (outs VECREG:$rT), (ins VECREG:$rA),
3452 "frest\t$rT, $rA", SPrecFP,
3453 [(set (v4f32 VECREG:$rT), (SPUreciprocalEst (v4f32 VECREG:$rA)))]>;
3454
3455def FREf32 :
3456 RRForm_1<0b00011101100, (outs R32FP:$rT), (ins R32FP:$rA),
3457 "frest\t$rT, $rA", SPrecFP,
3458 [(set R32FP:$rT, (SPUreciprocalEst R32FP:$rA))]>;
3459
3460// Floating point interpolate (used in conjunction with reciprocal estimate)
3461def FIv4f32 :
3462 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3463 "fi\t$rT, $rA, $rB", SPrecFP,
3464 [(set (v4f32 VECREG:$rT), (SPUinterpolate (v4f32 VECREG:$rA),
3465 (v4f32 VECREG:$rB)))]>;
3466
3467def FIf32 :
3468 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3469 "fi\t$rT, $rA, $rB", SPrecFP,
3470 [(set R32FP:$rT, (SPUinterpolate R32FP:$rA, R32FP:$rB))]>;
3471
Scott Michel33d73eb2008-11-21 02:56:16 +00003472//--------------------------------------------------------------------------
3473// Basic single precision floating point comparisons:
3474//
3475// Note: There is no support on SPU for single precision NaN. Consequently,
3476// ordered and unordered comparisons are the same.
3477//--------------------------------------------------------------------------
3478
Scott Michel8b6b4202007-12-04 22:35:58 +00003479def FCEQf32 :
3480 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3481 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003482 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3483
3484def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3485 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003486
3487def FCMEQf32 :
3488 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3489 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003490 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3491
3492def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3493 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003494
3495def FCGTf32 :
3496 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3497 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003498 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3499
3500def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3501 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003502
3503def FCMGTf32 :
3504 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3505 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003506 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3507
3508def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3509 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3510
3511//--------------------------------------------------------------------------
3512// Single precision floating point comparisons and SETCC equivalents:
3513//--------------------------------------------------------------------------
3514
3515def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3516def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3517
3518def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3519def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3520
3521def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3522def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3523
3524def : Pat<(setule R32FP:$rA, R32FP:$rB),
3525 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3526def : Pat<(setole R32FP:$rA, R32FP:$rB),
3527 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003528
3529// FP Status and Control Register Write
3530// Why isn't rT a don't care in the ISA?
3531// Should we create a special RRForm_3 for this guy and zero out the rT?
3532def FSCRWf32 :
3533 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3534 "fscrwr\t$rA", SPrecFP,
3535 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3536
3537// FP Status and Control Register Read
3538def FSCRRf32 :
3539 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3540 "fscrrd\t$rT", SPrecFP,
3541 [/* This instruction requires an intrinsic */]>;
3542
3543// llvm instruction space
3544// How do these map onto cell instructions?
3545// fdiv rA rB
3546// frest rC rB # c = 1/b (both lines)
3547// fi rC rB rC
3548// fm rD rA rC # d = a * 1/b
3549// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3550// fma rB rB rC rD # b = b * c + d
3551// = -(d *b -a) * c + d
3552// = a * c - c ( a *b *c - a)
3553
3554// fcopysign (???)
3555
3556// Library calls:
3557// These llvm instructions will actually map to library calls.
3558// All that's needed, then, is to check that the appropriate library is
3559// imported and do a brsl to the proper function name.
3560// frem # fmod(x, y): x - (x/y) * y
3561// (Note: fmod(double, double), fmodf(float,float)
3562// fsqrt?
3563// fsin?
3564// fcos?
3565// Unimplemented SPU instruction space
3566// floating reciprocal absolute square root estimate (frsqest)
3567
3568// The following are probably just intrinsics
3569// status and control register write
3570// status and control register read
3571
3572//--------------------------------------
3573// Floating point multiply instructions
3574//--------------------------------------
3575
3576def FMv4f32:
3577 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3578 "fm\t$rT, $rA, $rB", SPrecFP,
3579 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3580 (v4f32 VECREG:$rB)))]>;
3581
3582def FMf32 :
3583 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3584 "fm\t$rT, $rA, $rB", SPrecFP,
3585 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3586
3587// Floating point multiply and add
3588// e.g. d = c + (a * b)
3589def FMAv4f32:
3590 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3591 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3592 [(set (v4f32 VECREG:$rT),
3593 (fadd (v4f32 VECREG:$rC),
3594 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3595
3596def FMAf32:
3597 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3598 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3599 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3600
3601// FP multiply and subtract
3602// Subtracts value in rC from product
3603// res = a * b - c
3604def FMSv4f32 :
3605 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3606 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3607 [(set (v4f32 VECREG:$rT),
3608 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3609 (v4f32 VECREG:$rC)))]>;
3610
3611def FMSf32 :
3612 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3613 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3614 [(set R32FP:$rT,
3615 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3616
3617// Floating Negative Mulitply and Subtract
3618// Subtracts product from value in rC
3619// res = fneg(fms a b c)
3620// = - (a * b - c)
3621// = c - a * b
3622// NOTE: subtraction order
3623// fsub a b = a - b
3624// fs a b = b - a?
3625def FNMSf32 :
3626 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3627 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3628 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3629
3630def FNMSv4f32 :
3631 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3632 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3633 [(set (v4f32 VECREG:$rT),
3634 (fsub (v4f32 VECREG:$rC),
3635 (fmul (v4f32 VECREG:$rA),
3636 (v4f32 VECREG:$rB))))]>;
3637
3638//--------------------------------------
3639// Floating Point Conversions
3640// Signed conversions:
3641def CSiFv4f32:
3642 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3643 "csflt\t$rT, $rA, 0", SPrecFP,
3644 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3645
3646// Convert signed integer to floating point
3647def CSiFf32 :
3648 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3649 "csflt\t$rT, $rA, 0", SPrecFP,
3650 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3651
3652// Convert unsigned into to float
3653def CUiFv4f32 :
3654 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3655 "cuflt\t$rT, $rA, 0", SPrecFP,
3656 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3657
3658def CUiFf32 :
3659 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3660 "cuflt\t$rT, $rA, 0", SPrecFP,
3661 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
3662
3663// Convert float to unsigned int
3664// Assume that scale = 0
3665
3666def CFUiv4f32 :
3667 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3668 "cfltu\t$rT, $rA, 0", SPrecFP,
3669 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
3670
3671def CFUif32 :
3672 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3673 "cfltu\t$rT, $rA, 0", SPrecFP,
3674 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
3675
3676// Convert float to signed int
3677// Assume that scale = 0
3678
3679def CFSiv4f32 :
3680 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3681 "cflts\t$rT, $rA, 0", SPrecFP,
3682 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
3683
3684def CFSif32 :
3685 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3686 "cflts\t$rT, $rA, 0", SPrecFP,
3687 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
3688
3689//===----------------------------------------------------------------------==//
3690// Single<->Double precision conversions
3691//===----------------------------------------------------------------------==//
3692
3693// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
3694// v4f32, output is v2f64--which goes in the name?)
3695
3696// Floating point extend single to double
3697// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
3698// operates on two double-word slots (i.e. 1st and 3rd fp numbers
3699// are ignored).
3700def FESDvec :
3701 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3702 "fesd\t$rT, $rA", SPrecFP,
3703 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
3704
3705def FESDf32 :
3706 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
3707 "fesd\t$rT, $rA", SPrecFP,
3708 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
3709
3710// Floating point round double to single
3711//def FRDSvec :
3712// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3713// "frds\t$rT, $rA,", SPrecFP,
3714// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
3715
3716def FRDSf64 :
3717 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
3718 "frds\t$rT, $rA", SPrecFP,
3719 [(set R32FP:$rT, (fround R64FP:$rA))]>;
3720
3721//ToDo include anyextend?
3722
3723//===----------------------------------------------------------------------==//
3724// Double precision floating point instructions
3725//===----------------------------------------------------------------------==//
3726def FAf64 :
3727 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3728 "dfa\t$rT, $rA, $rB", DPrecFP,
3729 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
3730
3731def FAv2f64 :
3732 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3733 "dfa\t$rT, $rA, $rB", DPrecFP,
3734 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3735
3736def FSf64 :
3737 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3738 "dfs\t$rT, $rA, $rB", DPrecFP,
3739 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
3740
3741def FSv2f64 :
3742 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3743 "dfs\t$rT, $rA, $rB", DPrecFP,
3744 [(set (v2f64 VECREG:$rT),
3745 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3746
3747def FMf64 :
3748 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3749 "dfm\t$rT, $rA, $rB", DPrecFP,
3750 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
3751
3752def FMv2f64:
3753 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3754 "dfm\t$rT, $rA, $rB", DPrecFP,
3755 [(set (v2f64 VECREG:$rT),
3756 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3757
3758def FMAf64:
3759 RRForm<0b00111010110, (outs R64FP:$rT),
3760 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3761 "dfma\t$rT, $rA, $rB", DPrecFP,
3762 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3763 RegConstraint<"$rC = $rT">,
3764 NoEncode<"$rC">;
3765
3766def FMAv2f64:
3767 RRForm<0b00111010110, (outs VECREG:$rT),
3768 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3769 "dfma\t$rT, $rA, $rB", DPrecFP,
3770 [(set (v2f64 VECREG:$rT),
3771 (fadd (v2f64 VECREG:$rC),
3772 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
3773 RegConstraint<"$rC = $rT">,
3774 NoEncode<"$rC">;
3775
3776def FMSf64 :
3777 RRForm<0b10111010110, (outs R64FP:$rT),
3778 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3779 "dfms\t$rT, $rA, $rB", DPrecFP,
3780 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
3781 RegConstraint<"$rC = $rT">,
3782 NoEncode<"$rC">;
3783
3784def FMSv2f64 :
3785 RRForm<0b10111010110, (outs VECREG:$rT),
3786 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3787 "dfms\t$rT, $rA, $rB", DPrecFP,
3788 [(set (v2f64 VECREG:$rT),
3789 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3790 (v2f64 VECREG:$rC)))]>;
3791
3792// FNMS: - (a * b - c)
3793// - (a * b) + c => c - (a * b)
3794def FNMSf64 :
3795 RRForm<0b01111010110, (outs R64FP:$rT),
3796 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3797 "dfnms\t$rT, $rA, $rB", DPrecFP,
3798 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3799 RegConstraint<"$rC = $rT">,
3800 NoEncode<"$rC">;
3801
3802def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
3803 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
3804
3805def FNMSv2f64 :
3806 RRForm<0b01111010110, (outs VECREG:$rT),
3807 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3808 "dfnms\t$rT, $rA, $rB", DPrecFP,
3809 [(set (v2f64 VECREG:$rT),
3810 (fsub (v2f64 VECREG:$rC),
3811 (fmul (v2f64 VECREG:$rA),
3812 (v2f64 VECREG:$rB))))]>,
3813 RegConstraint<"$rC = $rT">,
3814 NoEncode<"$rC">;
3815
3816def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3817 (v2f64 VECREG:$rC))),
3818 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
3819
3820// - (a * b + c)
3821// - (a * b) - c
3822def FNMAf64 :
3823 RRForm<0b11111010110, (outs R64FP:$rT),
3824 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3825 "dfnma\t$rT, $rA, $rB", DPrecFP,
3826 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
3827 RegConstraint<"$rC = $rT">,
3828 NoEncode<"$rC">;
3829
3830def FNMAv2f64 :
3831 RRForm<0b11111010110, (outs VECREG:$rT),
3832 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3833 "dfnma\t$rT, $rA, $rB", DPrecFP,
3834 [(set (v2f64 VECREG:$rT),
3835 (fneg (fadd (v2f64 VECREG:$rC),
3836 (fmul (v2f64 VECREG:$rA),
3837 (v2f64 VECREG:$rB)))))]>,
3838 RegConstraint<"$rC = $rT">,
3839 NoEncode<"$rC">;
3840
3841//===----------------------------------------------------------------------==//
3842// Floating point negation and absolute value
3843//===----------------------------------------------------------------------==//
3844
3845def : Pat<(fneg (v4f32 VECREG:$rA)),
3846 (XORfnegvec (v4f32 VECREG:$rA),
3847 (v4f32 (ILHUv4i32 0x8000)))>;
3848
3849def : Pat<(fneg R32FP:$rA),
3850 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
3851
3852def : Pat<(fneg (v2f64 VECREG:$rA)),
3853 (XORfnegvec (v2f64 VECREG:$rA),
3854 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
3855
3856def : Pat<(fneg R64FP:$rA),
3857 (XORfneg64 R64FP:$rA,
3858 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
3859
3860// Floating point absolute value
3861
3862def : Pat<(fabs R32FP:$rA),
3863 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
3864
3865def : Pat<(fabs (v4f32 VECREG:$rA)),
3866 (ANDfabsvec (v4f32 VECREG:$rA),
3867 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3868
3869def : Pat<(fabs R64FP:$rA),
3870 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
3871
3872def : Pat<(fabs (v2f64 VECREG:$rA)),
3873 (ANDfabsvec (v2f64 VECREG:$rA),
3874 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3875
3876//===----------------------------------------------------------------------===//
3877// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
3878// in the odd pipeline)
3879//===----------------------------------------------------------------------===//
3880
Scott Michel97872d32008-02-23 18:41:37 +00003881def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003882 let Pattern = [];
3883
3884 let Inst{0-10} = 0b10000000010;
3885 let Inst{11-17} = 0;
3886 let Inst{18-24} = 0;
3887 let Inst{25-31} = 0;
3888}
3889
Scott Michel97872d32008-02-23 18:41:37 +00003890def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003891 let Pattern = [];
3892
3893 let Inst{0-10} = 0b10000000000;
3894 let Inst{11-17} = 0;
3895 let Inst{18-24} = 0;
3896 let Inst{25-31} = 0;
3897}
3898
3899//===----------------------------------------------------------------------===//
3900// Bit conversions (type conversions between vector/packed types)
3901// NOTE: Promotions are handled using the XS* instructions. Truncation
3902// is not handled.
3903//===----------------------------------------------------------------------===//
3904def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
3905def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
3906def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
3907def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
3908def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
3909
3910def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
3911def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
3912def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
3913def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
3914def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
3915
3916def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
3917def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
3918def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
3919def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
3920def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
3921
3922def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
3923def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
3924def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
3925def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
3926def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
3927
3928def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
3929def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
3930def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
3931def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
3932def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
3933
3934def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
3935def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
3936def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
3937def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
3938def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
3939
3940def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00003941def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003942
3943//===----------------------------------------------------------------------===//
3944// Instruction patterns:
3945//===----------------------------------------------------------------------===//
3946
3947// General 32-bit constants:
3948def : Pat<(i32 imm:$imm),
3949 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
3950
3951// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00003952def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00003953 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
3954
3955// General constant 32-bit vectors
3956def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00003957 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
3958 (LO16_vec v4i32Imm:$imm))>;
Scott Michel438be252007-12-17 22:32:34 +00003959
3960// 8-bit constants
3961def : Pat<(i8 imm:$imm),
3962 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003963
3964//===----------------------------------------------------------------------===//
3965// Call instruction patterns:
3966//===----------------------------------------------------------------------===//
3967// Return void
3968def : Pat<(ret),
3969 (RET)>;
3970
3971//===----------------------------------------------------------------------===//
3972// Zero/Any/Sign extensions
3973//===----------------------------------------------------------------------===//
3974
3975// zext 1->32: Zero extend i1 to i32
3976def : Pat<(SPUextract_i1_zext R32C:$rSrc),
3977 (ANDIr32 R32C:$rSrc, 0x1)>;
3978
3979// sext 8->32: Sign extend bytes to words
3980def : Pat<(sext_inreg R32C:$rSrc, i8),
3981 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
3982
Scott Michel438be252007-12-17 22:32:34 +00003983def : Pat<(i32 (sext R8C:$rSrc)),
3984 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
3985
Scott Michel8b6b4202007-12-04 22:35:58 +00003986def : Pat<(SPUextract_i8_sext VECREG:$rSrc),
3987 (XSHWr32 (XSBHr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc),
3988 (v4i32 VECREG:$rSrc))))>;
3989
Scott Michel438be252007-12-17 22:32:34 +00003990// zext 8->16: Zero extend bytes to halfwords
3991def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003992 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00003993
3994// zext 8->32 from preferred slot in load/store
Scott Michel8b6b4202007-12-04 22:35:58 +00003995def : Pat<(SPUextract_i8_zext VECREG:$rSrc),
3996 (ANDIr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc), (v4i32 VECREG:$rSrc)),
3997 0xff)>;
3998
Scott Michel438be252007-12-17 22:32:34 +00003999// zext 8->32: Zero extend bytes to words
4000def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004001 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004002
4003// anyext 8->16: Extend 8->16 bits, irrespective of sign
4004def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004005 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004006
4007// anyext 8->32: Extend 8->32 bits, irrespective of sign
4008def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004009 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004010
Scott Michel97872d32008-02-23 18:41:37 +00004011// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004012def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004013 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004014
4015def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004016 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004017
4018def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004019 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004020
4021def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004022 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004023
4024// anyext 16->32: Extend 16->32 bits, irrespective of sign
4025def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004026 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004027
4028//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004029// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004030// low parts in order to load them into a register.
4031//===----------------------------------------------------------------------===//
4032
Scott Michelf9f42e62008-01-29 02:16:57 +00004033def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4034def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4035def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4036def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4037
4038def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4039 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004040 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004041
Scott Michelf9f42e62008-01-29 02:16:57 +00004042def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4043 (SPUlo texternalsym:$in, 0)),
4044 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4045
4046def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4047 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004048 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004049
Scott Michelf9f42e62008-01-29 02:16:57 +00004050def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4051 (SPUlo tconstpool:$in, 0)),
4052 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4053
Scott Michelbc5fbc12008-04-30 00:30:08 +00004054def : Pat<(SPUindirect R32C:$sp, i32ImmSExt10:$imm),
4055 (AIr32 R32C:$sp, i32ImmSExt10:$imm)>;
4056
4057def : Pat<(SPUindirect R32C:$sp, imm:$imm),
4058 (Ar32 R32C:$sp,
4059 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm)))>;
4060
Scott Michelf9f42e62008-01-29 02:16:57 +00004061def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4062 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4063
4064def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4065 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4066
4067def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4068 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4069
4070def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4071 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004072
Scott Michel8b6b4202007-12-04 22:35:58 +00004073// Instrinsics:
4074include "CellSDKIntrinsics.td"