blob: 08d767684af66d372e7a8a9a3a91cb06026798f7 [file] [log] [blame]
Scott Michel8b6b4202007-12-04 22:35:58 +00001//==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
Scott Michel06eabde2008-12-27 04:51:36 +00002//
Scott Michel8b6b4202007-12-04 22:35:58 +00003// 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 Michel06eabde2008-12-27 04:51:36 +00007//
Scott Michel8b6b4202007-12-04 22:35:58 +00008//===----------------------------------------------------------------------===//
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>
Scott Michel06eabde2008-12-27 04:51:36 +000052 : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000053 "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>
Scott Michel06eabde2008-12-27 04:51:36 +000059 : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000060 "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>
Scott Michel06eabde2008-12-27 04:51:36 +0000164 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000165 "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>
Scott Michel06eabde2008-12-27 04:51:36 +0000171 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000172 "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 Michel06eabde2008-12-27 04:51:36 +0000272def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000273 "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 Michel06eabde2008-12-27 04:51:36 +0000280def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$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 Michel06eabde2008-12-27 04:51:36 +0000288def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$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 Michel06eabde2008-12-27 04:51:36 +0000296def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000297 "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 Michel06eabde2008-12-27 04:51:36 +0000304def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$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 Michel06eabde2008-12-27 04:51:36 +0000312def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000313 "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 Michel06eabde2008-12-27 04:51:36 +0000424 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michel6baba072008-03-05 23:02:02 +0000425 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000426
Scott Michel97872d32008-02-23 18:41:37 +0000427 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
428 [/* no pattern */]>;
429}
430
431defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000432
433// Immediate OR, Halfword Lower: The "other" part of loading large constants
434// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
435// Note that these are really two operand instructions, but they're encoded
436// as three operands with the first two arguments tied-to each other.
437
Scott Michel6baba072008-03-05 23:02:02 +0000438class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
439 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
440 ImmLoad, pattern>,
441 RegConstraint<"$rS = $rT">,
442 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000443
Scott Michel6baba072008-03-05 23:02:02 +0000444class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
445 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
446 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000447
Scott Michel6baba072008-03-05 23:02:02 +0000448class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
449 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
450 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000451
Scott Michel6baba072008-03-05 23:02:02 +0000452multiclass ImmOrHalfwordLower
453{
454 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000455 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000456
457 def r32: IOHLRegInst<R32C, i32imm>;
458 def f32: IOHLRegInst<R32FP, f32imm>;
459
460 def lo: IOHLRegInst<R32C, symbolLo>;
461}
462
463defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000464
Scott Michel8b6b4202007-12-04 22:35:58 +0000465// Form select mask for bytes using immediate, used in conjunction with the
466// SELB instruction:
467
Scott Michel6baba072008-03-05 23:02:02 +0000468class FSMBIVec<ValueType vectype>:
469 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
470 "fsmbi\t$rT, $val",
471 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000472 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000473
Scott Michel97872d32008-02-23 18:41:37 +0000474multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000475{
476 def v16i8: FSMBIVec<v16i8>;
477 def v8i16: FSMBIVec<v8i16>;
478 def v4i32: FSMBIVec<v4i32>;
479 def v2i64: FSMBIVec<v2i64>;
480}
Scott Michel8b6b4202007-12-04 22:35:58 +0000481
Scott Michel97872d32008-02-23 18:41:37 +0000482defm FSMBI : FormSelectMaskBytesImm;
483
484// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michel06eabde2008-12-27 04:51:36 +0000485class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
486 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
487 pattern>;
488
489class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
490 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
491 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
492
493class FSMBVecInst<ValueType vectype>:
494 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
495 [(set (vectype VECREG:$rT),
496 (SPUselmask (vectype VECREG:$rA)))]>;
497
498multiclass FormSelectMaskBits {
499 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
500 def v16i8: FSMBVecInst<v16i8>;
501}
502
503defm FSMB: FormSelectMaskBits;
Scott Michel97872d32008-02-23 18:41:37 +0000504
505// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
506// only 8-bits wide (even though it's input as 16-bits here)
Scott Michel06eabde2008-12-27 04:51:36 +0000507
508class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
509 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
510 pattern>;
511
512class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
513 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
514 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
515
516class FSMHVecInst<ValueType vectype>:
517 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
518 [(set (vectype VECREG:$rT),
519 (SPUselmask (vectype VECREG:$rA)))]>;
520
521multiclass FormSelectMaskHalfword {
522 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
523 def v8i16: FSMHVecInst<v8i16>;
524}
525
526defm FSMH: FormSelectMaskHalfword;
Scott Michel97872d32008-02-23 18:41:37 +0000527
528// fsm: Form select mask for words. Like the other fsm* instructions,
529// only the lower 4 bits of $rA are significant.
Scott Michel06eabde2008-12-27 04:51:36 +0000530
531class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
532 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
533 pattern>;
534
535class FSMRegInst<ValueType vectype, RegisterClass rclass>:
536 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
537 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
538
539class FSMVecInst<ValueType vectype>:
540 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
541 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel67224b22008-06-02 22:18:03 +0000542
543multiclass FormSelectMaskWord {
Scott Michel06eabde2008-12-27 04:51:36 +0000544 def v4i32: FSMVecInst<v4i32>;
545
546 def r32 : FSMRegInst<v4i32, R32C>;
547 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000548}
549
550defm FSM : FormSelectMaskWord;
551
552// Special case when used for i64 math operations
553multiclass FormSelectMaskWord64 {
Scott Michel06eabde2008-12-27 04:51:36 +0000554 def r32 : FSMRegInst<v2i64, R32C>;
555 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000556}
557
558defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000559
560//===----------------------------------------------------------------------===//
561// Integer and Logical Operations:
562//===----------------------------------------------------------------------===//
563
564def AHv8i16:
565 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
566 "ah\t$rT, $rA, $rB", IntegerOp,
567 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
568
569def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
570 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
571
Scott Michel8b6b4202007-12-04 22:35:58 +0000572def AHr16:
573 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
574 "ah\t$rT, $rA, $rB", IntegerOp,
575 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
576
577def AHIvec:
578 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
579 "ahi\t$rT, $rA, $val", IntegerOp,
580 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
581 v8i16SExt10Imm:$val))]>;
582
Scott Michel97872d32008-02-23 18:41:37 +0000583def AHIr16:
584 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
585 "ahi\t$rT, $rA, $val", IntegerOp,
586 [(set R16C:$rT, (add R16C:$rA, v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000587
Scott Michel97872d32008-02-23 18:41:37 +0000588def Avec:
589 RRForm<0b00000011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
590 "a\t$rT, $rA, $rB", IntegerOp,
591 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000592
593def : Pat<(add (v16i8 VECREG:$rA), (v16i8 VECREG:$rB)),
594 (Avec VECREG:$rA, VECREG:$rB)>;
595
Scott Michel97872d32008-02-23 18:41:37 +0000596def Ar32:
597 RRForm<0b00000011000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
598 "a\t$rT, $rA, $rB", IntegerOp,
599 [(set R32C:$rT, (add R32C:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000600
Scott Michel438be252007-12-17 22:32:34 +0000601def Ar8:
602 RRForm<0b00000011000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
603 "a\t$rT, $rA, $rB", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000604 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +0000605
Scott Michel8b6b4202007-12-04 22:35:58 +0000606def AIvec:
607 RI10Form<0b00111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
608 "ai\t$rT, $rA, $val", IntegerOp,
609 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA),
610 v4i32SExt10Imm:$val))]>;
611
Scott Michel438be252007-12-17 22:32:34 +0000612def AIr32:
613 RI10Form<0b00111000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
614 "ai\t$rT, $rA, $val", IntegerOp,
615 [(set R32C:$rT, (add R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000616
Scott Michel438be252007-12-17 22:32:34 +0000617def SFHvec:
618 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
619 "sfh\t$rT, $rA, $rB", IntegerOp,
620 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
621 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000622
Scott Michel438be252007-12-17 22:32:34 +0000623def SFHr16:
624 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
625 "sfh\t$rT, $rA, $rB", IntegerOp,
626 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000627
628def SFHIvec:
629 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
630 "sfhi\t$rT, $rA, $val", IntegerOp,
631 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
632 (v8i16 VECREG:$rA)))]>;
633
634def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
635 "sfhi\t$rT, $rA, $val", IntegerOp,
636 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
637
638def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
639 (ins VECREG:$rA, VECREG:$rB),
640 "sf\t$rT, $rA, $rB", IntegerOp,
641 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
642
643def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
644 "sf\t$rT, $rA, $rB", IntegerOp,
645 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
646
647def SFIvec:
648 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
649 "sfi\t$rT, $rA, $val", IntegerOp,
650 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
651 (v4i32 VECREG:$rA)))]>;
652
653def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
654 (ins R32C:$rA, s10imm_i32:$val),
655 "sfi\t$rT, $rA, $val", IntegerOp,
656 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
657
658// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000659class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
660 RRForm<0b00000010110, OOL, IOL,
661 "addx\t$rT, $rA, $rB",
662 IntegerOp, pattern>;
663
664class ADDXVecInst<ValueType vectype>:
665 ADDXInst<(outs VECREG:$rT),
666 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
667 [(set (vectype VECREG:$rT),
668 (SPUaddx (vectype VECREG:$rA), (vectype VECREG:$rB),
669 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000670 RegConstraint<"$rCarry = $rT">,
671 NoEncode<"$rCarry">;
672
Scott Michel67224b22008-06-02 22:18:03 +0000673class ADDXRegInst<RegisterClass rclass>:
674 ADDXInst<(outs rclass:$rT),
675 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
676 [(set rclass:$rT,
677 (SPUaddx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000678 RegConstraint<"$rCarry = $rT">,
679 NoEncode<"$rCarry">;
680
Scott Michel67224b22008-06-02 22:18:03 +0000681multiclass AddExtended {
682 def v2i64 : ADDXVecInst<v2i64>;
683 def v4i32 : ADDXVecInst<v4i32>;
684 def r64 : ADDXRegInst<R64C>;
685 def r32 : ADDXRegInst<R32C>;
686}
687
688defm ADDX : AddExtended;
689
690// CG: Generate carry for add
691class CGInst<dag OOL, dag IOL, list<dag> pattern>:
692 RRForm<0b01000011000, OOL, IOL,
693 "cg\t$rT, $rA, $rB",
694 IntegerOp, pattern>;
695
696class CGVecInst<ValueType vectype>:
697 CGInst<(outs VECREG:$rT),
698 (ins VECREG:$rA, VECREG:$rB),
699 [(set (vectype VECREG:$rT),
700 (SPUcarry_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
701
702class CGRegInst<RegisterClass rclass>:
703 CGInst<(outs rclass:$rT),
704 (ins rclass:$rA, rclass:$rB),
705 [(set rclass:$rT,
706 (SPUcarry_gen rclass:$rA, rclass:$rB))]>;
707
708multiclass CarryGenerate {
709 def v2i64 : CGVecInst<v2i64>;
710 def v4i32 : CGVecInst<v4i32>;
711 def r64 : CGRegInst<R64C>;
712 def r32 : CGRegInst<R32C>;
713}
714
715defm CG : CarryGenerate;
716
717// SFX: Subract from, extended. This is used in conjunction with BG to subtract
718// with carry (borrow, in this case)
719class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
720 RRForm<0b10000010110, OOL, IOL,
721 "sfx\t$rT, $rA, $rB",
722 IntegerOp, pattern>;
723
724class SFXVecInst<ValueType vectype>:
725 SFXInst<(outs VECREG:$rT),
726 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
727 [(set (vectype VECREG:$rT),
728 (SPUsubx (vectype VECREG:$rA), (vectype VECREG:$rB),
729 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000730 RegConstraint<"$rCarry = $rT">,
731 NoEncode<"$rCarry">;
732
Scott Michel67224b22008-06-02 22:18:03 +0000733class SFXRegInst<RegisterClass rclass>:
734 SFXInst<(outs rclass:$rT),
735 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
736 [(set rclass:$rT,
737 (SPUsubx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
738 RegConstraint<"$rCarry = $rT">,
739 NoEncode<"$rCarry">;
740
741multiclass SubtractExtended {
742 def v2i64 : SFXVecInst<v2i64>;
743 def v4i32 : SFXVecInst<v4i32>;
744 def r64 : SFXRegInst<R64C>;
745 def r32 : SFXRegInst<R32C>;
746}
747
748defm SFX : SubtractExtended;
749
Scott Michel8b6b4202007-12-04 22:35:58 +0000750// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000751class BGInst<dag OOL, dag IOL, list<dag> pattern>:
752 RRForm<0b01000010000, OOL, IOL,
753 "bg\t$rT, $rA, $rB",
754 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000755
Scott Michel67224b22008-06-02 22:18:03 +0000756class BGVecInst<ValueType vectype>:
757 BGInst<(outs VECREG:$rT),
758 (ins VECREG:$rA, VECREG:$rB),
759 [(set (vectype VECREG:$rT),
760 (SPUborrow_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
761
762class BGRegInst<RegisterClass rclass>:
763 BGInst<(outs rclass:$rT),
764 (ins rclass:$rA, rclass:$rB),
765 [(set rclass:$rT,
766 (SPUborrow_gen rclass:$rA, rclass:$rB))]>;
767
768multiclass BorrowGenerate {
769 def v4i32 : BGVecInst<v4i32>;
770 def v2i64 : BGVecInst<v2i64>;
771 def r64 : BGRegInst<R64C>;
772 def r32 : BGRegInst<R32C>;
773}
774
775defm BG : BorrowGenerate;
776
777// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000778def BGXvec:
779 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000780 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000781 "bgx\t$rT, $rA, $rB", IntegerOp,
782 []>,
783 RegConstraint<"$rCarry = $rT">,
784 NoEncode<"$rCarry">;
785
786// Halfword multiply variants:
787// N.B: These can be used to build up larger quantities (16x16 -> 32)
788
789def MPYv8i16:
790 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
791 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
792 [(set (v8i16 VECREG:$rT), (SPUmpy_v8i16 (v8i16 VECREG:$rA),
793 (v8i16 VECREG:$rB)))]>;
794
795def MPYr16:
796 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
797 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
798 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
799
800def MPYUv4i32:
801 RRForm<0b00110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
802 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
803 [(set (v4i32 VECREG:$rT),
804 (SPUmpyu_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
805
806def MPYUr16:
807 RRForm<0b00110011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
808 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
809 [(set R32C:$rT, (mul (zext R16C:$rA),
810 (zext R16C:$rB)))]>;
811
812def MPYUr32:
813 RRForm<0b00110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
814 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
815 [(set R32C:$rT, (SPUmpyu_i32 R32C:$rA, R32C:$rB))]>;
816
817// mpyi: multiply 16 x s10imm -> 32 result (custom lowering for 32 bit result,
818// this only produces the lower 16 bits)
819def MPYIvec:
820 RI10Form<0b00101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
821 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
822 [(set (v8i16 VECREG:$rT), (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
823
824def MPYIr16:
825 RI10Form<0b00101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
826 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
827 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
828
829// mpyui: same issues as other multiplies, plus, this doesn't match a
830// pattern... but may be used during target DAG selection or lowering
831def MPYUIvec:
832 RI10Form<0b10101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
833 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
834 []>;
835
836def MPYUIr16:
837 RI10Form<0b10101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
838 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
839 []>;
840
841// mpya: 16 x 16 + 16 -> 32 bit result
842def MPYAvec:
843 RRRForm<0b0011, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
844 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
845 [(set (v4i32 VECREG:$rT), (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
846 (v8i16 VECREG:$rB)))),
847 (v4i32 VECREG:$rC)))]>;
848
849def MPYAr32:
850 RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
851 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
852 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
853 R32C:$rC))]>;
854
855def : Pat<(add (mul (sext R16C:$rA), (sext R16C:$rB)), R32C:$rC),
856 (MPYAr32 R16C:$rA, R16C:$rB, R32C:$rC)>;
857
858def MPYAr32_sextinreg:
859 RRRForm<0b0011, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
860 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
861 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
862 (sext_inreg R32C:$rB, i16)),
863 R32C:$rC))]>;
864
865//def MPYAr32:
866// RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
867// "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
868// [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
869// R32C:$rC))]>;
870
871// mpyh: multiply high, used to synthesize 32-bit multiplies
872def MPYHv4i32:
873 RRForm<0b10100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
874 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
875 [(set (v4i32 VECREG:$rT),
876 (SPUmpyh_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
877
878def MPYHr32:
879 RRForm<0b10100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
880 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
881 [(set R32C:$rT, (SPUmpyh_i32 R32C:$rA, R32C:$rB))]>;
882
883// mpys: multiply high and shift right (returns the top half of
884// a 16-bit multiply, sign extended to 32 bits.)
885def MPYSvec:
886 RRForm<0b11100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
887 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
888 []>;
889
890def MPYSr16:
891 RRForm<0b11100011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
892 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
893 []>;
894
895// mpyhh: multiply high-high (returns the 32-bit result from multiplying
896// the top 16 bits of the $rA, $rB)
897def MPYHHv8i16:
898 RRForm<0b01100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
899 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
900 [(set (v8i16 VECREG:$rT),
901 (SPUmpyhh_v8i16 (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)))]>;
902
903def MPYHHr32:
904 RRForm<0b01100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
905 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
906 []>;
907
908// mpyhha: Multiply high-high, add to $rT:
909def MPYHHAvec:
910 RRForm<0b01100010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
911 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
912 []>;
913
914def MPYHHAr32:
915 RRForm<0b01100010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
916 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
917 []>;
918
919// mpyhhu: Multiply high-high, unsigned
920def MPYHHUvec:
921 RRForm<0b01110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
922 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
923 []>;
924
925def MPYHHUr32:
926 RRForm<0b01110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
927 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
928 []>;
929
930// mpyhhau: Multiply high-high, unsigned
931def MPYHHAUvec:
932 RRForm<0b01110010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
933 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
934 []>;
935
936def MPYHHAUr32:
937 RRForm<0b01110010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
938 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
939 []>;
940
941// clz: Count leading zeroes
Scott Michel06eabde2008-12-27 04:51:36 +0000942class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
943 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
944 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000945
Scott Michel06eabde2008-12-27 04:51:36 +0000946class CLZRegInst<RegisterClass rclass>:
947 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
948 [(set rclass:$rT, (ctlz rclass:$rA))]>;
949
950class CLZVecInst<ValueType vectype>:
951 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
952 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
953
954multiclass CountLeadingZeroes {
955 def v4i32 : CLZVecInst<v4i32>;
956 def r32 : CLZRegInst<R32C>;
957}
958
959defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +0000960
961// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +0000962//
Scott Michel8b6b4202007-12-04 22:35:58 +0000963// NOTE: This instruction is really a vector instruction, but the custom
964// lowering code uses it in unorthodox ways to support CTPOP for other
965// data types!
Scott Michel06eabde2008-12-27 04:51:36 +0000966
Scott Michel8b6b4202007-12-04 22:35:58 +0000967def CNTBv16i8:
968 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
969 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000970 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000971
972def CNTBv8i16 :
973 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
974 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000975 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000976
977def CNTBv4i32 :
978 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
979 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +0000980 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000981
Scott Michel06eabde2008-12-27 04:51:36 +0000982// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
983// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
984// slots 1-3.
985//
986// Note: This instruction "pairs" with the fsmb instruction for all of the
987// various types defined here.
988//
989// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
990// a vector or register.
991
992class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
993 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
994
995class GBBRegInst<RegisterClass rclass, ValueType vectype>:
996 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
997 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
998
999class GBBVecInst<ValueType vectype>:
1000 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1001 [(set (vectype VECREG:$rT), (SPUgatherbits (vectype VECREG:$rA)))]>;
1002
1003multiclass GatherBitsFromBytes {
1004 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1005 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1006 def v16i8: GBBVecInst<v16i8>;
1007}
1008
1009defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001010
1011// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001012// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1013// and slots 1-3 also set to 0.
1014//
1015// See notes for GBBInst, above.
1016
1017class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1018 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1019 pattern>;
1020
1021class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1022 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
1023 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1024
1025class GBHVecInst<ValueType vectype>:
1026 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
1027 [(set (vectype VECREG:$rT),
1028 (SPUgatherbits (vectype VECREG:$rA)))]>;
1029
1030multiclass GatherBitsHalfword {
1031 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1032 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1033 def v8i16: GBHVecInst<v8i16>;
1034}
1035
1036defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001037
1038// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001039// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1040// as well as slots 1-3.
1041//
1042// See notes for gbb, above.
1043
1044class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1045 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1046 pattern>;
1047
1048class GBRegInst<RegisterClass rclass, ValueType vectype>:
1049 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
1050 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1051
1052class GBVecInst<ValueType vectype>:
1053 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1054 [(set (vectype VECREG:$rT),
1055 (SPUgatherbits (vectype VECREG:$rA)))]>;
1056
1057multiclass GatherBitsWord {
1058 def v4i32_r32: GBRegInst<R32C, v4i32>;
1059 def v4i32_r16: GBRegInst<R16C, v4i32>;
1060 def v4i32: GBVecInst<v4i32>;
1061}
1062
1063defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001064
1065// avgb: average bytes
1066def AVGB:
1067 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1068 "avgb\t$rT, $rA, $rB", ByteOp,
1069 []>;
1070
1071// absdb: absolute difference of bytes
1072def ABSDB:
1073 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1074 "absdb\t$rT, $rA, $rB", ByteOp,
1075 []>;
1076
1077// sumb: sum bytes into halfwords
1078def SUMB:
1079 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1080 "sumb\t$rT, $rA, $rB", ByteOp,
1081 []>;
1082
1083// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001084class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1085 RRForm_1<0b01101101010, OOL, IOL,
1086 "xsbh\t$rDst, $rSrc",
1087 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001088
Scott Michel67224b22008-06-02 22:18:03 +00001089class XSBHVecInst<ValueType vectype>:
1090 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1091 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001092
Scott Michel06eabde2008-12-27 04:51:36 +00001093class XSBHInRegInst<RegisterClass rclass>:
Scott Michel67224b22008-06-02 22:18:03 +00001094 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
1095 [(set rclass:$rDst, (sext_inreg rclass:$rSrc, i8))]>;
1096
1097multiclass ExtendByteHalfword {
1098 def v16i8: XSBHVecInst<v8i16>;
Scott Michel06eabde2008-12-27 04:51:36 +00001099 def r16: XSBHInRegInst<R16C>;
1100 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1101 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001102
1103 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1104 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1105 // pattern below). Intentionally doesn't match a pattern because we want the
1106 // sext 8->32 pattern to do the work for us, namely because we need the extra
1107 // XSHWr32.
Scott Michel06eabde2008-12-27 04:51:36 +00001108 def r32: XSBHInRegInst<R32C>;
Scott Michel67224b22008-06-02 22:18:03 +00001109}
1110
1111defm XSBH : ExtendByteHalfword;
1112
Scott Michel8b6b4202007-12-04 22:35:58 +00001113// Sign extend halfwords to words:
1114def XSHWvec:
1115 RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
1116 "xshw\t$rDest, $rSrc", IntegerOp,
1117 [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
1118
1119def XSHWr32:
1120 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
1121 "xshw\t$rDst, $rSrc", IntegerOp,
1122 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
1123
1124def XSHWr16:
1125 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
1126 "xshw\t$rDst, $rSrc", IntegerOp,
1127 [(set R32C:$rDst, (sext R16C:$rSrc))]>;
1128
1129def XSWDvec:
1130 RRForm_1<0b01100101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
1131 "xswd\t$rDst, $rSrc", IntegerOp,
1132 [(set (v2i64 VECREG:$rDst), (sext (v4i32 VECREG:$rSrc)))]>;
1133
1134def XSWDr64:
1135 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R64C:$rSrc),
1136 "xswd\t$rDst, $rSrc", IntegerOp,
1137 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1138
1139def XSWDr32:
1140 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R32C:$rSrc),
1141 "xswd\t$rDst, $rSrc", IntegerOp,
1142 [(set R64C:$rDst, (SPUsext32_to_64 R32C:$rSrc))]>;
1143
1144def : Pat<(sext R32C:$inp),
1145 (XSWDr32 R32C:$inp)>;
1146
1147// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001148
Scott Michel97872d32008-02-23 18:41:37 +00001149class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1150 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1151 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001152
Scott Michel97872d32008-02-23 18:41:37 +00001153class ANDVecInst<ValueType vectype>:
1154 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1155 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1156 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001157
Scott Michel6baba072008-03-05 23:02:02 +00001158class ANDRegInst<RegisterClass rclass>:
1159 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1160 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1161
Scott Michel97872d32008-02-23 18:41:37 +00001162multiclass BitwiseAnd
1163{
1164 def v16i8: ANDVecInst<v16i8>;
1165 def v8i16: ANDVecInst<v8i16>;
1166 def v4i32: ANDVecInst<v4i32>;
1167 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001168
Scott Michel6baba072008-03-05 23:02:02 +00001169 def r128: ANDRegInst<GPRC>;
1170 def r64: ANDRegInst<R64C>;
1171 def r32: ANDRegInst<R32C>;
1172 def r16: ANDRegInst<R16C>;
1173 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001174
Scott Michel97872d32008-02-23 18:41:37 +00001175 //===---------------------------------------------
1176 // Special instructions to perform the fabs instruction
1177 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1178 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001179
Scott Michel97872d32008-02-23 18:41:37 +00001180 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1181 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001182
Scott Michel97872d32008-02-23 18:41:37 +00001183 // Could use v4i32, but won't for clarity
1184 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1185 [/* Intentionally does not match a pattern */]>;
1186
1187 //===---------------------------------------------
1188
1189 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1190 // quantities -- see 16->32 zext pattern.
1191 //
1192 // This pattern is somewhat artificial, since it might match some
1193 // compiler generated pattern but it is unlikely to do so.
1194
1195 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1196 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1197}
1198
1199defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001200
1201// N.B.: vnot_conv is one of those special target selection pattern fragments,
1202// in which we expect there to be a bit_convert on the constant. Bear in mind
1203// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1204// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001205
Scott Michel97872d32008-02-23 18:41:37 +00001206class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1207 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1208 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001209
Scott Michel97872d32008-02-23 18:41:37 +00001210class ANDCVecInst<ValueType vectype>:
1211 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1212 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1213 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001214
Scott Michel97872d32008-02-23 18:41:37 +00001215class ANDCRegInst<RegisterClass rclass>:
1216 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1217 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001218
Scott Michel97872d32008-02-23 18:41:37 +00001219multiclass AndComplement
1220{
1221 def v16i8: ANDCVecInst<v16i8>;
1222 def v8i16: ANDCVecInst<v8i16>;
1223 def v4i32: ANDCVecInst<v4i32>;
1224 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001225
Scott Michel97872d32008-02-23 18:41:37 +00001226 def r128: ANDCRegInst<GPRC>;
1227 def r64: ANDCRegInst<R64C>;
1228 def r32: ANDCRegInst<R32C>;
1229 def r16: ANDCRegInst<R16C>;
1230 def r8: ANDCRegInst<R8C>;
1231}
Scott Michel438be252007-12-17 22:32:34 +00001232
Scott Michel97872d32008-02-23 18:41:37 +00001233defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001234
Scott Michel97872d32008-02-23 18:41:37 +00001235class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1236 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001237 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001238
Scott Michel97872d32008-02-23 18:41:37 +00001239multiclass AndByteImm
1240{
1241 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1242 [(set (v16i8 VECREG:$rT),
1243 (and (v16i8 VECREG:$rA),
1244 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001245
Scott Michel97872d32008-02-23 18:41:37 +00001246 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1247 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1248}
Scott Michel438be252007-12-17 22:32:34 +00001249
Scott Michel97872d32008-02-23 18:41:37 +00001250defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001251
Scott Michel97872d32008-02-23 18:41:37 +00001252class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1253 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001254 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001255
Scott Michel97872d32008-02-23 18:41:37 +00001256multiclass AndHalfwordImm
1257{
1258 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1259 [(set (v8i16 VECREG:$rT),
1260 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001261
Scott Michel97872d32008-02-23 18:41:37 +00001262 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1263 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001264
Scott Michel97872d32008-02-23 18:41:37 +00001265 // Zero-extend i8 to i16:
1266 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1267 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1268}
Scott Michel8b6b4202007-12-04 22:35:58 +00001269
Scott Michel97872d32008-02-23 18:41:37 +00001270defm ANDHI : AndHalfwordImm;
1271
1272class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1273 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1274 IntegerOp, pattern>;
1275
1276multiclass AndWordImm
1277{
1278 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1279 [(set (v4i32 VECREG:$rT),
1280 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1281
1282 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1283 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1284
1285 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1286 // pattern below.
1287 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1288 [(set R32C:$rT,
1289 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1290
1291 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1292 // zext 16->32 pattern below.
1293 //
1294 // Note that this pattern is somewhat artificial, since it might match
1295 // something the compiler generates but is unlikely to occur in practice.
1296 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1297 [(set R32C:$rT,
1298 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1299}
1300
1301defm ANDI : AndWordImm;
1302
1303//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001304// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001305//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1306
Scott Michel8b6b4202007-12-04 22:35:58 +00001307// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001308class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1309 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1310 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001311
Scott Michel97872d32008-02-23 18:41:37 +00001312class ORVecInst<ValueType vectype>:
1313 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1314 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1315 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001316
Scott Michel97872d32008-02-23 18:41:37 +00001317class ORRegInst<RegisterClass rclass>:
1318 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1319 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001320
Scott Michel06eabde2008-12-27 04:51:36 +00001321// ORCvtForm: OR conversion form
1322//
1323// This is used to "convert" the preferred slot to its vector equivalent, as
1324// well as convert a vector back to its preferred slot.
1325//
1326// These are effectively no-ops, but need to exist for proper type conversion
1327// and type coercion.
1328
1329class ORCvtForm<dag OOL, dag IOL>
1330 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1331 bits<7> RA;
1332 bits<7> RT;
1333
1334 let Pattern = [/* no pattern */];
1335
1336 let Inst{0-10} = 0b10000010000;
1337 let Inst{11-17} = RA;
1338 let Inst{18-24} = RA;
1339 let Inst{25-31} = RT;
1340}
1341
Scott Michel97872d32008-02-23 18:41:37 +00001342class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001343 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001344
Scott Michel97872d32008-02-23 18:41:37 +00001345class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001346 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1347
1348class ORCvtRegGPRC<RegisterClass rclass>:
1349 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>;
1350
1351class ORCvtVecGPRC:
1352 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
1353
1354class ORCvtGPRCReg<RegisterClass rclass>:
1355 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>;
1356
1357class ORCvtGPRCVec:
1358 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001359
Scott Michel97872d32008-02-23 18:41:37 +00001360multiclass BitwiseOr
1361{
1362 def v16i8: ORVecInst<v16i8>;
1363 def v8i16: ORVecInst<v8i16>;
1364 def v4i32: ORVecInst<v4i32>;
1365 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001366
Scott Michel97872d32008-02-23 18:41:37 +00001367 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1368 [(set (v4f32 VECREG:$rT),
1369 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1370 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001371
Scott Michel97872d32008-02-23 18:41:37 +00001372 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001373 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001374 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1375 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001376
Scott Michel97872d32008-02-23 18:41:37 +00001377 def r64: ORRegInst<R64C>;
1378 def r32: ORRegInst<R32C>;
1379 def r16: ORRegInst<R16C>;
1380 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001381
Scott Michel97872d32008-02-23 18:41:37 +00001382 // OR instructions used to copy f32 and f64 registers.
1383 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1384 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001385
Scott Michel97872d32008-02-23 18:41:37 +00001386 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1387 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001388
Scott Michel97872d32008-02-23 18:41:37 +00001389 // scalar->vector promotion:
1390 def v16i8_i8: ORPromoteScalar<R8C>;
1391 def v8i16_i16: ORPromoteScalar<R16C>;
1392 def v4i32_i32: ORPromoteScalar<R32C>;
1393 def v2i64_i64: ORPromoteScalar<R64C>;
1394 def v4f32_f32: ORPromoteScalar<R32FP>;
1395 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001396
Scott Michel97872d32008-02-23 18:41:37 +00001397 // extract element 0:
1398 def i8_v16i8: ORExtractElt<R8C>;
1399 def i16_v8i16: ORExtractElt<R16C>;
1400 def i32_v4i32: ORExtractElt<R32C>;
1401 def i64_v2i64: ORExtractElt<R64C>;
1402 def f32_v4f32: ORExtractElt<R32FP>;
1403 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001404
1405 // Conversion from GPRC to register
1406 def i128_r64: ORCvtRegGPRC<R64C>;
1407 def i128_f64: ORCvtRegGPRC<R64FP>;
1408 def i128_r32: ORCvtRegGPRC<R32C>;
1409 def i128_f32: ORCvtRegGPRC<R32FP>;
1410 def i128_r16: ORCvtRegGPRC<R16C>;
1411 def i128_r8: ORCvtRegGPRC<R8C>;
1412
1413 // Conversion from GPRC to vector
1414 def i128_vec: ORCvtVecGPRC;
1415
1416 // Conversion from register to GPRC
1417 def r64_i128: ORCvtGPRCReg<R64C>;
1418 def f64_i128: ORCvtGPRCReg<R64FP>;
1419 def r32_i128: ORCvtGPRCReg<R32C>;
1420 def f32_i128: ORCvtGPRCReg<R32FP>;
1421 def r16_i128: ORCvtGPRCReg<R16C>;
1422 def r8_i128: ORCvtGPRCReg<R8C>;
1423
1424 // Conversion from vector to GPRC
1425 def vec_i128: ORCvtGPRCVec;
Scott Michel97872d32008-02-23 18:41:37 +00001426}
Scott Michel438be252007-12-17 22:32:34 +00001427
Scott Michel97872d32008-02-23 18:41:37 +00001428defm OR : BitwiseOr;
1429
Scott Michel06eabde2008-12-27 04:51:36 +00001430// scalar->vector promotion patterns (preferred slot to vector):
1431def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1432 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001433
Scott Michel06eabde2008-12-27 04:51:36 +00001434def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1435 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001436
Scott Michel06eabde2008-12-27 04:51:36 +00001437def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1438 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001439
Scott Michel06eabde2008-12-27 04:51:36 +00001440def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1441 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001442
Scott Michel06eabde2008-12-27 04:51:36 +00001443def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1444 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001445
Scott Michel06eabde2008-12-27 04:51:36 +00001446def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1447 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001448
Scott Michel06eabde2008-12-27 04:51:36 +00001449// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1450// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001451
Scott Michelc630c412008-11-24 17:11:17 +00001452def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001453 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001454
Scott Michelc630c412008-11-24 17:11:17 +00001455def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001456 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001457
Scott Michelc630c412008-11-24 17:11:17 +00001458def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001459 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001460
Scott Michelc630c412008-11-24 17:11:17 +00001461def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001462 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001463
Scott Michelc630c412008-11-24 17:11:17 +00001464def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001465 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001466
Scott Michelc630c412008-11-24 17:11:17 +00001467def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001468 (ORf64_v2f64 VECREG:$rA)>;
1469
1470// Load Register: This is an assembler alias for a bitwise OR of a register
1471// against itself. It's here because it brings some clarity to assembly
1472// language output.
1473
1474let hasCtrlDep = 1 in {
1475 class LRInst<dag OOL, dag IOL>
1476 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1477 bits<7> RA;
1478 bits<7> RT;
1479
1480 let Pattern = [/*no pattern*/];
1481
1482 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1483 let Inst{11-17} = RA;
1484 let Inst{18-24} = RA;
1485 let Inst{25-31} = RT;
1486 }
1487
1488 class LRVecInst<ValueType vectype>:
1489 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1490
1491 class LRRegInst<RegisterClass rclass>:
1492 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1493
1494 multiclass LoadRegister {
1495 def v2i64: LRVecInst<v2i64>;
1496 def v2f64: LRVecInst<v2f64>;
1497 def v4i32: LRVecInst<v4i32>;
1498 def v4f32: LRVecInst<v4f32>;
1499 def v8i16: LRVecInst<v8i16>;
1500 def v16i8: LRVecInst<v16i8>;
1501
1502 def r128: LRRegInst<GPRC>;
1503 def r64: LRRegInst<R64C>;
1504 def f64: LRRegInst<R64FP>;
1505 def r32: LRRegInst<R32C>;
1506 def f32: LRRegInst<R32FP>;
1507 def r16: LRRegInst<R16C>;
1508 def r8: LRRegInst<R8C>;
1509 }
1510
1511 defm LR: LoadRegister;
1512}
Scott Michel8b6b4202007-12-04 22:35:58 +00001513
Scott Michel97872d32008-02-23 18:41:37 +00001514// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001515
Scott Michel97872d32008-02-23 18:41:37 +00001516class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1517 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1518 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001519
Scott Michel97872d32008-02-23 18:41:37 +00001520class ORCVecInst<ValueType vectype>:
1521 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1522 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1523 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001524
Scott Michel97872d32008-02-23 18:41:37 +00001525class ORCRegInst<RegisterClass rclass>:
1526 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1527 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001528
Scott Michel97872d32008-02-23 18:41:37 +00001529multiclass BitwiseOrComplement
1530{
1531 def v16i8: ORCVecInst<v16i8>;
1532 def v8i16: ORCVecInst<v8i16>;
1533 def v4i32: ORCVecInst<v4i32>;
1534 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001535
Scott Michel97872d32008-02-23 18:41:37 +00001536 def r64: ORCRegInst<R64C>;
1537 def r32: ORCRegInst<R32C>;
1538 def r16: ORCRegInst<R16C>;
1539 def r8: ORCRegInst<R8C>;
1540}
1541
1542defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001543
Scott Michel8b6b4202007-12-04 22:35:58 +00001544// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001545class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1546 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1547 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001548
Scott Michel97872d32008-02-23 18:41:37 +00001549class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1550 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1551 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1552 (vectype immpred:$val)))]>;
1553
1554multiclass BitwiseOrByteImm
1555{
1556 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1557
1558 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1559 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1560}
1561
1562defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001563
Scott Michel8b6b4202007-12-04 22:35:58 +00001564// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001565class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1566 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1567 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001568
Scott Michel97872d32008-02-23 18:41:37 +00001569class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1570 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1571 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1572 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001573
Scott Michel97872d32008-02-23 18:41:37 +00001574multiclass BitwiseOrHalfwordImm
1575{
1576 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1577
1578 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1579 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1580
1581 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1582 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1583 [(set R16C:$rT, (or (anyext R8C:$rA),
1584 i16ImmSExt10:$val))]>;
1585}
1586
1587defm ORHI : BitwiseOrHalfwordImm;
1588
1589class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1590 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1591 IntegerOp, pattern>;
1592
1593class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1594 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1595 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1596 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001597
1598// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001599multiclass BitwiseOrImm
1600{
1601 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001602
Scott Michel97872d32008-02-23 18:41:37 +00001603 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1604 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001605
Scott Michel97872d32008-02-23 18:41:37 +00001606 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1607 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1608 // infra "anyext 16->32" pattern.)
1609 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1610 [(set R32C:$rT, (or (anyext R16C:$rA),
1611 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001612
Scott Michel97872d32008-02-23 18:41:37 +00001613 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1614 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1615 // infra "anyext 16->32" pattern.)
1616 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1617 [(set R32C:$rT, (or (anyext R8C:$rA),
1618 i32ImmSExt10:$val))]>;
1619}
Scott Michel8b6b4202007-12-04 22:35:58 +00001620
Scott Michel97872d32008-02-23 18:41:37 +00001621defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001622
Scott Michel8b6b4202007-12-04 22:35:58 +00001623// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1624// $rT[0], slots 1-3 are zeroed.
1625//
Scott Michel438be252007-12-17 22:32:34 +00001626// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001627def ORXv4i32:
1628 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1629 "orx\t$rT, $rA, $rB", IntegerOp,
1630 []>;
1631
Scott Michel438be252007-12-17 22:32:34 +00001632// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001633
Scott Michel6baba072008-03-05 23:02:02 +00001634class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1635 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1636 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001637
Scott Michel6baba072008-03-05 23:02:02 +00001638class XORVecInst<ValueType vectype>:
1639 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1640 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1641 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001642
Scott Michel6baba072008-03-05 23:02:02 +00001643class XORRegInst<RegisterClass rclass>:
1644 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1645 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1646
1647multiclass BitwiseExclusiveOr
1648{
1649 def v16i8: XORVecInst<v16i8>;
1650 def v8i16: XORVecInst<v8i16>;
1651 def v4i32: XORVecInst<v4i32>;
1652 def v2i64: XORVecInst<v2i64>;
1653
1654 def r128: XORRegInst<GPRC>;
1655 def r64: XORRegInst<R64C>;
1656 def r32: XORRegInst<R32C>;
1657 def r16: XORRegInst<R16C>;
1658 def r8: XORRegInst<R8C>;
1659
1660 // Special forms for floating point instructions.
1661 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1662
1663 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1664 [/* no pattern */]>;
1665
1666 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1667 [/* no pattern */]>;
1668
1669 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1670 [/* no pattern, see fneg{32,64} */]>;
1671}
1672
1673defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001674
1675//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001676
Scott Michel97872d32008-02-23 18:41:37 +00001677class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1678 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1679 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001680
Scott Michel97872d32008-02-23 18:41:37 +00001681multiclass XorByteImm
1682{
1683 def v16i8:
1684 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1685 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1686
1687 def r8:
1688 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1689 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1690}
1691
1692defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001693
Scott Michel8b6b4202007-12-04 22:35:58 +00001694def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001695 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001696 "xorhi\t$rT, $rA, $val", IntegerOp,
1697 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1698 v8i16SExt10Imm:$val))]>;
1699
1700def XORHIr16:
1701 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1702 "xorhi\t$rT, $rA, $val", IntegerOp,
1703 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1704
1705def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001706 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001707 "xori\t$rT, $rA, $val", IntegerOp,
1708 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1709 v4i32SExt10Imm:$val))]>;
1710
1711def XORIr32:
1712 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1713 "xori\t$rT, $rA, $val", IntegerOp,
1714 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1715
1716// NAND:
1717def NANDv16i8:
1718 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1719 "nand\t$rT, $rA, $rB", IntegerOp,
1720 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1721 (v16i8 VECREG:$rB))))]>;
1722
1723def NANDv8i16:
1724 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1725 "nand\t$rT, $rA, $rB", IntegerOp,
1726 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1727 (v8i16 VECREG:$rB))))]>;
1728
1729def NANDv4i32:
1730 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1731 "nand\t$rT, $rA, $rB", IntegerOp,
1732 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1733 (v4i32 VECREG:$rB))))]>;
1734
1735def NANDr32:
1736 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1737 "nand\t$rT, $rA, $rB", IntegerOp,
1738 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1739
1740def NANDr16:
1741 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1742 "nand\t$rT, $rA, $rB", IntegerOp,
1743 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1744
Scott Michel438be252007-12-17 22:32:34 +00001745def NANDr8:
1746 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1747 "nand\t$rT, $rA, $rB", IntegerOp,
1748 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1749
Scott Michel8b6b4202007-12-04 22:35:58 +00001750// NOR:
1751def NORv16i8:
1752 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1753 "nor\t$rT, $rA, $rB", IntegerOp,
1754 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1755 (v16i8 VECREG:$rB))))]>;
1756
1757def NORv8i16:
1758 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1759 "nor\t$rT, $rA, $rB", IntegerOp,
1760 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1761 (v8i16 VECREG:$rB))))]>;
1762
1763def NORv4i32:
1764 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1765 "nor\t$rT, $rA, $rB", IntegerOp,
1766 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1767 (v4i32 VECREG:$rB))))]>;
1768
1769def NORr32:
1770 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1771 "nor\t$rT, $rA, $rB", IntegerOp,
1772 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1773
1774def NORr16:
1775 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1776 "nor\t$rT, $rA, $rB", IntegerOp,
1777 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1778
Scott Michel438be252007-12-17 22:32:34 +00001779def NORr8:
1780 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1781 "nor\t$rT, $rA, $rB", IntegerOp,
1782 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1783
Scott Michel8b6b4202007-12-04 22:35:58 +00001784// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001785class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1786 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1787 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001788
Scott Michel6baba072008-03-05 23:02:02 +00001789class SELBVecInst<ValueType vectype>:
1790 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1791 [(set (vectype VECREG:$rT),
1792 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1793 (and (vnot (vectype VECREG:$rC)),
1794 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001795
Scott Michel06eabde2008-12-27 04:51:36 +00001796class SELBVecCondInst<ValueType vectype>:
1797 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1798 [(set (vectype VECREG:$rT),
1799 (select R32C:$rC,
1800 (vectype VECREG:$rB),
1801 (vectype VECREG:$rA)))]>;
1802
Scott Michel6baba072008-03-05 23:02:02 +00001803class SELBRegInst<RegisterClass rclass>:
1804 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1805 [(set rclass:$rT,
1806 (or (and rclass:$rA, rclass:$rC),
1807 (and rclass:$rB, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001808
Scott Michel06eabde2008-12-27 04:51:36 +00001809class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1810 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1811 [(set rclass:$rT,
1812 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1813
Scott Michel6baba072008-03-05 23:02:02 +00001814multiclass SelectBits
1815{
1816 def v16i8: SELBVecInst<v16i8>;
1817 def v8i16: SELBVecInst<v8i16>;
1818 def v4i32: SELBVecInst<v4i32>;
1819 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001820
Scott Michel6baba072008-03-05 23:02:02 +00001821 def r128: SELBRegInst<GPRC>;
1822 def r64: SELBRegInst<R64C>;
1823 def r32: SELBRegInst<R32C>;
1824 def r16: SELBRegInst<R16C>;
1825 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001826
1827 def v16i8_cond: SELBVecCondInst<v16i8>;
1828 def v8i16_cond: SELBVecCondInst<v8i16>;
1829 def v4i32_cond: SELBVecCondInst<v4i32>;
1830 def v2i64_cond: SELBVecCondInst<v2i64>;
1831
1832 // SELBr64_cond is defined further down, look for i64 comparisons
1833 def r32_cond: SELBRegCondInst<R32C, R32C>;
1834 def r16_cond: SELBRegCondInst<R16C, R16C>;
1835 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001836}
Scott Michel8b6b4202007-12-04 22:35:58 +00001837
Scott Michel6baba072008-03-05 23:02:02 +00001838defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001839
Scott Michel56a125e2008-11-22 23:50:42 +00001840class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001841 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1842 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001843
Scott Michel56a125e2008-11-22 23:50:42 +00001844def : SPUselbPatVec<v16i8, SELBv16i8>;
1845def : SPUselbPatVec<v8i16, SELBv8i16>;
1846def : SPUselbPatVec<v4i32, SELBv4i32>;
1847def : SPUselbPatVec<v2i64, SELBv2i64>;
1848
1849class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1850 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1851 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1852
1853def : SPUselbPatReg<R8C, SELBr8>;
1854def : SPUselbPatReg<R16C, SELBr16>;
1855def : SPUselbPatReg<R32C, SELBr32>;
1856def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001857
Scott Michel6baba072008-03-05 23:02:02 +00001858// EQV: Equivalence (1 for each same bit, otherwise 0)
1859//
1860// Note: There are a lot of ways to match this bit operator and these patterns
1861// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001862
Scott Michel6baba072008-03-05 23:02:02 +00001863class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1864 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1865 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001866
Scott Michel6baba072008-03-05 23:02:02 +00001867class EQVVecInst<ValueType vectype>:
1868 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1869 [(set (vectype VECREG:$rT),
1870 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1871 (and (vnot (vectype VECREG:$rA)),
1872 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001873
Scott Michel6baba072008-03-05 23:02:02 +00001874class EQVRegInst<RegisterClass rclass>:
1875 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1876 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1877 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001878
Scott Michel6baba072008-03-05 23:02:02 +00001879class EQVVecPattern1<ValueType vectype>:
1880 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1881 [(set (vectype VECREG:$rT),
1882 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001883
Scott Michel6baba072008-03-05 23:02:02 +00001884class EQVRegPattern1<RegisterClass rclass>:
1885 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1886 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001887
Scott Michel6baba072008-03-05 23:02:02 +00001888class EQVVecPattern2<ValueType vectype>:
1889 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1890 [(set (vectype VECREG:$rT),
1891 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1892 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001893
Scott Michel6baba072008-03-05 23:02:02 +00001894class EQVRegPattern2<RegisterClass rclass>:
1895 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1896 [(set rclass:$rT,
1897 (or (and rclass:$rA, rclass:$rB),
1898 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001899
Scott Michel6baba072008-03-05 23:02:02 +00001900class EQVVecPattern3<ValueType vectype>:
1901 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1902 [(set (vectype VECREG:$rT),
1903 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001904
Scott Michel6baba072008-03-05 23:02:02 +00001905class EQVRegPattern3<RegisterClass rclass>:
1906 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1907 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001908
Scott Michel6baba072008-03-05 23:02:02 +00001909multiclass BitEquivalence
1910{
1911 def v16i8: EQVVecInst<v16i8>;
1912 def v8i16: EQVVecInst<v8i16>;
1913 def v4i32: EQVVecInst<v4i32>;
1914 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001915
Scott Michel6baba072008-03-05 23:02:02 +00001916 def v16i8_1: EQVVecPattern1<v16i8>;
1917 def v8i16_1: EQVVecPattern1<v8i16>;
1918 def v4i32_1: EQVVecPattern1<v4i32>;
1919 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001920
Scott Michel6baba072008-03-05 23:02:02 +00001921 def v16i8_2: EQVVecPattern2<v16i8>;
1922 def v8i16_2: EQVVecPattern2<v8i16>;
1923 def v4i32_2: EQVVecPattern2<v4i32>;
1924 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001925
Scott Michel6baba072008-03-05 23:02:02 +00001926 def v16i8_3: EQVVecPattern3<v16i8>;
1927 def v8i16_3: EQVVecPattern3<v8i16>;
1928 def v4i32_3: EQVVecPattern3<v4i32>;
1929 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001930
Scott Michel6baba072008-03-05 23:02:02 +00001931 def r128: EQVRegInst<GPRC>;
1932 def r64: EQVRegInst<R64C>;
1933 def r32: EQVRegInst<R32C>;
1934 def r16: EQVRegInst<R16C>;
1935 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001936
Scott Michel6baba072008-03-05 23:02:02 +00001937 def r128_1: EQVRegPattern1<GPRC>;
1938 def r64_1: EQVRegPattern1<R64C>;
1939 def r32_1: EQVRegPattern1<R32C>;
1940 def r16_1: EQVRegPattern1<R16C>;
1941 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001942
Scott Michel6baba072008-03-05 23:02:02 +00001943 def r128_2: EQVRegPattern2<GPRC>;
1944 def r64_2: EQVRegPattern2<R64C>;
1945 def r32_2: EQVRegPattern2<R32C>;
1946 def r16_2: EQVRegPattern2<R16C>;
1947 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001948
Scott Michel6baba072008-03-05 23:02:02 +00001949 def r128_3: EQVRegPattern3<GPRC>;
1950 def r64_3: EQVRegPattern3<R64C>;
1951 def r32_3: EQVRegPattern3<R32C>;
1952 def r16_3: EQVRegPattern3<R16C>;
1953 def r8_3: EQVRegPattern3<R8C>;
1954}
Scott Michel438be252007-12-17 22:32:34 +00001955
Scott Michel6baba072008-03-05 23:02:02 +00001956defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00001957
1958//===----------------------------------------------------------------------===//
1959// Vector shuffle...
1960//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001961// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
1962// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
1963// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
1964// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00001965//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001966
Scott Michel97872d32008-02-23 18:41:37 +00001967class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
1968 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
1969 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001970
Scott Michel0718cd82008-12-01 17:56:02 +00001971class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00001972 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00001973 [(set (resultvec VECREG:$rT),
1974 (SPUshuffle (resultvec VECREG:$rA),
1975 (resultvec VECREG:$rB),
1976 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00001977
Scott Michel06eabde2008-12-27 04:51:36 +00001978class SHUFBGPRCInst:
1979 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
1980 [/* no pattern */]>;
1981
Scott Michel97872d32008-02-23 18:41:37 +00001982multiclass ShuffleBytes
1983{
Scott Michel0718cd82008-12-01 17:56:02 +00001984 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
1985 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
1986 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
1987 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
1988 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
1989 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
1990 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
1991 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001992
Scott Michel0718cd82008-12-01 17:56:02 +00001993 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
1994 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
1995
1996 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
1997 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00001998
1999 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002000}
2001
2002defm SHUFB : ShuffleBytes;
2003
Scott Michel8b6b4202007-12-04 22:35:58 +00002004//===----------------------------------------------------------------------===//
2005// Shift and rotate group:
2006//===----------------------------------------------------------------------===//
2007
Scott Michel97872d32008-02-23 18:41:37 +00002008class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2009 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2010 RotateShift, pattern>;
2011
2012class SHLHVecInst<ValueType vectype>:
2013 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2014 [(set (vectype VECREG:$rT),
2015 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002016
2017// $rB gets promoted to 32-bit register type when confronted with
2018// this llvm assembly code:
2019//
2020// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
2021// %A = shl i16 %arg1, %arg2
2022// ret i16 %A
2023// }
Scott Michel8b6b4202007-12-04 22:35:58 +00002024
Scott Michel97872d32008-02-23 18:41:37 +00002025multiclass ShiftLeftHalfword
2026{
2027 def v8i16: SHLHVecInst<v8i16>;
2028 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2029 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2030 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2031 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2032}
Scott Michel8b6b4202007-12-04 22:35:58 +00002033
Scott Michel97872d32008-02-23 18:41:37 +00002034defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002035
Scott Michel97872d32008-02-23 18:41:37 +00002036//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002037
Scott Michel97872d32008-02-23 18:41:37 +00002038class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2039 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2040 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002041
Scott Michel97872d32008-02-23 18:41:37 +00002042class SHLHIVecInst<ValueType vectype>:
2043 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2044 [(set (vectype VECREG:$rT),
2045 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002046
Scott Michel97872d32008-02-23 18:41:37 +00002047multiclass ShiftLeftHalfwordImm
2048{
2049 def v8i16: SHLHIVecInst<v8i16>;
2050 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2051 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2052}
2053
2054defm SHLHI : ShiftLeftHalfwordImm;
2055
2056def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2057 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2058
2059def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002060 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002061
Scott Michel97872d32008-02-23 18:41:37 +00002062//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002063
Scott Michel97872d32008-02-23 18:41:37 +00002064class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2065 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2066 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002067
Scott Michel97872d32008-02-23 18:41:37 +00002068multiclass ShiftLeftWord
2069{
2070 def v4i32:
2071 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2072 [(set (v4i32 VECREG:$rT),
2073 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2074 def r32:
2075 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2076 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2077}
Scott Michel8b6b4202007-12-04 22:35:58 +00002078
Scott Michel97872d32008-02-23 18:41:37 +00002079defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002080
Scott Michel97872d32008-02-23 18:41:37 +00002081//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002082
Scott Michel97872d32008-02-23 18:41:37 +00002083class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2084 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2085 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002086
Scott Michel97872d32008-02-23 18:41:37 +00002087multiclass ShiftLeftWordImm
2088{
2089 def v4i32:
2090 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2091 [(set (v4i32 VECREG:$rT),
2092 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002093
Scott Michel97872d32008-02-23 18:41:37 +00002094 def r32:
2095 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2096 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2097}
Scott Michel8b6b4202007-12-04 22:35:58 +00002098
Scott Michel97872d32008-02-23 18:41:37 +00002099defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002100
Scott Michel97872d32008-02-23 18:41:37 +00002101//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002102// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2103// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002104//
2105// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2106// of 7 bits is actually possible.
2107//
2108// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2109// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2110// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002111
Scott Michel97872d32008-02-23 18:41:37 +00002112class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2113 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2114 RotateShift, pattern>;
2115
2116class SHLQBIVecInst<ValueType vectype>:
2117 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2118 [(set (vectype VECREG:$rT),
2119 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2120
2121multiclass ShiftLeftQuadByBits
2122{
2123 def v16i8: SHLQBIVecInst<v16i8>;
2124 def v8i16: SHLQBIVecInst<v8i16>;
2125 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002126 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002127 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002128 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002129}
2130
2131defm SHLQBI : ShiftLeftQuadByBits;
2132
2133// See note above on SHLQBI. In this case, the predicate actually does then
2134// enforcement, whereas with SHLQBI, we have to "take it on faith."
2135class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2136 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2137 RotateShift, pattern>;
2138
2139class SHLQBIIVecInst<ValueType vectype>:
2140 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2141 [(set (vectype VECREG:$rT),
2142 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2143
2144multiclass ShiftLeftQuadByBitsImm
2145{
2146 def v16i8 : SHLQBIIVecInst<v16i8>;
2147 def v8i16 : SHLQBIIVecInst<v8i16>;
2148 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002149 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002150 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002151 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002152}
2153
2154defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002155
2156// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002157// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002158
Scott Michel97872d32008-02-23 18:41:37 +00002159class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002160 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002161 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002162
Scott Michel97872d32008-02-23 18:41:37 +00002163class SHLQBYVecInst<ValueType vectype>:
2164 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2165 [(set (vectype VECREG:$rT),
2166 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002167
Scott Michel97872d32008-02-23 18:41:37 +00002168multiclass ShiftLeftQuadBytes
2169{
2170 def v16i8: SHLQBYVecInst<v16i8>;
2171 def v8i16: SHLQBYVecInst<v8i16>;
2172 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002173 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002174 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002175 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002176 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2177 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2178}
Scott Michel8b6b4202007-12-04 22:35:58 +00002179
Scott Michel97872d32008-02-23 18:41:37 +00002180defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002181
Scott Michel97872d32008-02-23 18:41:37 +00002182class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2183 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2184 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002185
Scott Michel97872d32008-02-23 18:41:37 +00002186class SHLQBYIVecInst<ValueType vectype>:
2187 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2188 [(set (vectype VECREG:$rT),
2189 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002190
Scott Michel97872d32008-02-23 18:41:37 +00002191multiclass ShiftLeftQuadBytesImm
2192{
2193 def v16i8: SHLQBYIVecInst<v16i8>;
2194 def v8i16: SHLQBYIVecInst<v8i16>;
2195 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002196 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002197 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002198 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002199 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2200 [(set GPRC:$rT,
2201 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2202}
Scott Michel438be252007-12-17 22:32:34 +00002203
Scott Michel97872d32008-02-23 18:41:37 +00002204defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002205
Scott Michel97872d32008-02-23 18:41:37 +00002206//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2207// Rotate halfword:
2208//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2209class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2210 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2211 RotateShift, pattern>;
2212
2213class ROTHVecInst<ValueType vectype>:
2214 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2215 [(set (vectype VECREG:$rT),
2216 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2217
2218class ROTHRegInst<RegisterClass rclass>:
2219 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2220 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2221
2222multiclass RotateLeftHalfword
2223{
2224 def v8i16: ROTHVecInst<v8i16>;
2225 def r16: ROTHRegInst<R16C>;
2226}
2227
2228defm ROTH: RotateLeftHalfword;
2229
2230def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2231 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2232
2233//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2234// Rotate halfword, immediate:
2235//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2236class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2237 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2238 RotateShift, pattern>;
2239
2240class ROTHIVecInst<ValueType vectype>:
2241 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2242 [(set (vectype VECREG:$rT),
2243 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2244
2245multiclass RotateLeftHalfwordImm
2246{
2247 def v8i16: ROTHIVecInst<v8i16>;
2248 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2249 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2250 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2251 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2252}
2253
2254defm ROTHI: RotateLeftHalfwordImm;
2255
2256def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002257 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002258
Scott Michel97872d32008-02-23 18:41:37 +00002259//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2260// Rotate word:
2261//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002262
Scott Michel97872d32008-02-23 18:41:37 +00002263class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2264 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2265 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002266
Scott Michel97872d32008-02-23 18:41:37 +00002267class ROTVecInst<ValueType vectype>:
2268 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2269 [(set (vectype VECREG:$rT),
2270 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002271
Scott Michel97872d32008-02-23 18:41:37 +00002272class ROTRegInst<RegisterClass rclass>:
2273 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2274 [(set rclass:$rT,
2275 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002276
Scott Michel97872d32008-02-23 18:41:37 +00002277multiclass RotateLeftWord
2278{
2279 def v4i32: ROTVecInst<v4i32>;
2280 def r32: ROTRegInst<R32C>;
2281}
2282
2283defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002284
Scott Michel438be252007-12-17 22:32:34 +00002285// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2286// 32-bit register
2287def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002288 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2289 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002290
2291def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2292 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2293
2294def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2295 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2296
2297def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002298 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2299 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002300
2301def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2302 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2303
2304def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2305 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2306
Scott Michel97872d32008-02-23 18:41:37 +00002307//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2308// Rotate word, immediate
2309//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002310
Scott Michel97872d32008-02-23 18:41:37 +00002311class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2312 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2313 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002314
Scott Michel97872d32008-02-23 18:41:37 +00002315class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2316 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2317 [(set (vectype VECREG:$rT),
2318 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002319
Scott Michel97872d32008-02-23 18:41:37 +00002320class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2321 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2322 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002323
Scott Michel97872d32008-02-23 18:41:37 +00002324multiclass RotateLeftWordImm
2325{
2326 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2327 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2328 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002329
Scott Michel97872d32008-02-23 18:41:37 +00002330 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2331 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2332 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2333}
Scott Michel438be252007-12-17 22:32:34 +00002334
Scott Michel97872d32008-02-23 18:41:37 +00002335defm ROTI : RotateLeftWordImm;
2336
2337//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2338// Rotate quad by byte (count)
2339//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2340
2341class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2342 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2343 RotateShift, pattern>;
2344
2345class ROTQBYVecInst<ValueType vectype>:
2346 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2347 [(set (vectype VECREG:$rT),
2348 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2349
2350multiclass RotateQuadLeftByBytes
2351{
2352 def v16i8: ROTQBYVecInst<v16i8>;
2353 def v8i16: ROTQBYVecInst<v8i16>;
2354 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002355 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002356 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002357 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002358}
2359
2360defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002361
Scott Michel97872d32008-02-23 18:41:37 +00002362//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2363// Rotate quad by byte (count), immediate
2364//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2365
2366class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2367 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2368 RotateShift, pattern>;
2369
2370class ROTQBYIVecInst<ValueType vectype>:
2371 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2372 [(set (vectype VECREG:$rT),
2373 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2374
2375multiclass RotateQuadByBytesImm
2376{
2377 def v16i8: ROTQBYIVecInst<v16i8>;
2378 def v8i16: ROTQBYIVecInst<v8i16>;
2379 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002380 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002381 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002382 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002383}
2384
2385defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002386
Scott Michel8b6b4202007-12-04 22:35:58 +00002387// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002388class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2389 RI7Form<0b00110011100, OOL, IOL,
2390 "rotqbybi\t$rT, $rA, $shift",
2391 RotateShift, pattern>;
2392
2393class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2394 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2395 [(set (vectype VECREG:$rT),
2396 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2397
2398multiclass RotateQuadByBytesByBitshift {
2399 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2400 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2401 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2402 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2403}
2404
2405defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002406
Scott Michel97872d32008-02-23 18:41:37 +00002407//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002408// See ROTQBY note above.
2409//
2410// Assume that the user of this instruction knows to shift the rotate count
2411// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002412//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002413
Scott Michel97872d32008-02-23 18:41:37 +00002414class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2415 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2416 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002417
Scott Michel97872d32008-02-23 18:41:37 +00002418class ROTQBIVecInst<ValueType vectype>:
2419 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2420 [/* no pattern yet */]>;
2421
2422class ROTQBIRegInst<RegisterClass rclass>:
2423 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2424 [/* no pattern yet */]>;
2425
2426multiclass RotateQuadByBitCount
2427{
2428 def v16i8: ROTQBIVecInst<v16i8>;
2429 def v8i16: ROTQBIVecInst<v8i16>;
2430 def v4i32: ROTQBIVecInst<v4i32>;
2431 def v2i64: ROTQBIVecInst<v2i64>;
2432
2433 def r128: ROTQBIRegInst<GPRC>;
2434 def r64: ROTQBIRegInst<R64C>;
2435}
2436
2437defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002438
Scott Michel97872d32008-02-23 18:41:37 +00002439class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2440 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2441 RotateShift, pattern>;
2442
2443class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2444 PatLeaf pred>:
2445 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2446 [/* no pattern yet */]>;
2447
2448class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2449 PatLeaf pred>:
2450 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2451 [/* no pattern yet */]>;
2452
2453multiclass RotateQuadByBitCountImm
2454{
2455 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2456 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2457 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2458 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2459
2460 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2461 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2462}
2463
2464defm ROTQBII : RotateQuadByBitCountImm;
2465
2466//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002467// ROTHM v8i16 form:
2468// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2469// so this only matches a synthetically generated/lowered code
2470// fragment.
2471// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002472//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002473
Scott Michel97872d32008-02-23 18:41:37 +00002474class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2475 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2476 RotateShift, pattern>;
2477
2478def ROTHMv8i16:
2479 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2480 [/* see patterns below - $rB must be negated */]>;
2481
2482def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002483 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2484
Scott Michel97872d32008-02-23 18:41:37 +00002485def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002486 (ROTHMv8i16 VECREG:$rA,
2487 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2488
Scott Michel97872d32008-02-23 18:41:37 +00002489def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002490 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002491 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002492
2493// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2494// Note: This instruction doesn't match a pattern because rB must be negated
2495// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002496
Scott Michel8b6b4202007-12-04 22:35:58 +00002497def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002498 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2499 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002500
2501def : Pat<(srl R16C:$rA, R32C:$rB),
2502 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2503
2504def : Pat<(srl R16C:$rA, R16C:$rB),
2505 (ROTHMr16 R16C:$rA,
2506 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2507
Scott Michel438be252007-12-17 22:32:34 +00002508def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002509 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002510 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002511
2512// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2513// that the immediate can be complemented, so that the user doesn't have to
2514// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002515
Scott Michel97872d32008-02-23 18:41:37 +00002516class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2517 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2518 RotateShift, pattern>;
2519
2520def ROTHMIv8i16:
2521 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2522 [/* no pattern */]>;
2523
2524def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2525 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2526
2527def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002528 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002529
Scott Michel97872d32008-02-23 18:41:37 +00002530def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002531 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002532
2533def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002534 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2535 [/* no pattern */]>;
2536
2537def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2538 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002539
2540def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2541 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2542
Scott Michel438be252007-12-17 22:32:34 +00002543def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2544 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2545
Scott Michel8b6b4202007-12-04 22:35:58 +00002546// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002547class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2548 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2549 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002550
Scott Michel97872d32008-02-23 18:41:37 +00002551def ROTMv4i32:
2552 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2553 [/* see patterns below - $rB must be negated */]>;
2554
2555def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002556 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2557
Scott Michel97872d32008-02-23 18:41:37 +00002558def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002559 (ROTMv4i32 VECREG:$rA,
2560 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2561
Scott Michel97872d32008-02-23 18:41:37 +00002562def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002563 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002564 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002565
2566def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002567 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2568 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002569
2570def : Pat<(srl R32C:$rA, R32C:$rB),
2571 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2572
2573def : Pat<(srl R32C:$rA, R16C:$rB),
2574 (ROTMr32 R32C:$rA,
2575 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2576
Scott Michel438be252007-12-17 22:32:34 +00002577def : Pat<(srl R32C:$rA, R8C:$rB),
2578 (ROTMr32 R32C:$rA,
2579 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2580
Scott Michel8b6b4202007-12-04 22:35:58 +00002581// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2582def ROTMIv4i32:
2583 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2584 "rotmi\t$rT, $rA, $val", RotateShift,
2585 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002586 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002587
Scott Michel97872d32008-02-23 18:41:37 +00002588def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002589 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002590
Scott Michel97872d32008-02-23 18:41:37 +00002591def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002592 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002593
2594// ROTMI r32 form: know how to complement the immediate value.
2595def ROTMIr32:
2596 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2597 "rotmi\t$rT, $rA, $val", RotateShift,
2598 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2599
2600def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2601 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2602
Scott Michel438be252007-12-17 22:32:34 +00002603def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2604 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2605
Scott Michel97872d32008-02-23 18:41:37 +00002606//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002607// ROTQMBYvec: This is a vector form merely so that when used in an
2608// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002609// that the user knew to negate $rB.
2610//
2611// Using the SPUrotquad_rz_bytes target-specific DAG node, the patterns
2612// ensure that $rB is negated.
2613//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002614
Scott Michel97872d32008-02-23 18:41:37 +00002615class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2616 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2617 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002618
Scott Michel97872d32008-02-23 18:41:37 +00002619class ROTQMBYVecInst<ValueType vectype>:
2620 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2621 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002622
Scott Michel97872d32008-02-23 18:41:37 +00002623class ROTQMBYRegInst<RegisterClass rclass>:
2624 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2625 [(set rclass:$rT,
2626 (SPUrotquad_rz_bytes rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002627
Scott Michel97872d32008-02-23 18:41:37 +00002628multiclass RotateQuadBytes
2629{
2630 def v16i8: ROTQMBYVecInst<v16i8>;
2631 def v8i16: ROTQMBYVecInst<v8i16>;
2632 def v4i32: ROTQMBYVecInst<v4i32>;
2633 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002634
Scott Michel97872d32008-02-23 18:41:37 +00002635 def r128: ROTQMBYRegInst<GPRC>;
2636 def r64: ROTQMBYRegInst<R64C>;
2637}
2638
2639defm ROTQMBY : RotateQuadBytes;
2640
2641def : Pat<(SPUrotquad_rz_bytes (v16i8 VECREG:$rA), R32C:$rB),
2642 (ROTQMBYv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2643def : Pat<(SPUrotquad_rz_bytes (v8i16 VECREG:$rA), R32C:$rB),
2644 (ROTQMBYv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2645def : Pat<(SPUrotquad_rz_bytes (v4i32 VECREG:$rA), R32C:$rB),
2646 (ROTQMBYv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2647def : Pat<(SPUrotquad_rz_bytes (v2i64 VECREG:$rA), R32C:$rB),
2648 (ROTQMBYv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2649def : Pat<(SPUrotquad_rz_bytes GPRC:$rA, R32C:$rB),
2650 (ROTQMBYr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2651def : Pat<(SPUrotquad_rz_bytes R64C:$rA, R32C:$rB),
2652 (ROTQMBYr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2653
2654class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2655 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2656 RotateShift, pattern>;
2657
2658class ROTQMBYIVecInst<ValueType vectype>:
2659 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2660 [(set (vectype VECREG:$rT),
2661 (SPUrotquad_rz_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2662
2663class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2664 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2665 [(set rclass:$rT,
2666 (SPUrotquad_rz_bytes rclass:$rA, (inttype pred:$val)))]>;
2667
2668multiclass RotateQuadBytesImm
2669{
2670 def v16i8: ROTQMBYIVecInst<v16i8>;
2671 def v8i16: ROTQMBYIVecInst<v8i16>;
2672 def v4i32: ROTQMBYIVecInst<v4i32>;
2673 def v2i64: ROTQMBYIVecInst<v2i64>;
2674
2675 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2676 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2677}
2678
2679defm ROTQMBYI : RotateQuadBytesImm;
2680
Scott Michel97872d32008-02-23 18:41:37 +00002681//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2682// Rotate right and mask by bit count
2683//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2684
2685class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2686 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2687 RotateShift, pattern>;
2688
2689class ROTQMBYBIVecInst<ValueType vectype>:
2690 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2691 [/* no pattern, intrinsic? */]>;
2692
2693multiclass RotateMaskQuadByBitCount
2694{
2695 def v16i8: ROTQMBYBIVecInst<v16i8>;
2696 def v8i16: ROTQMBYBIVecInst<v8i16>;
2697 def v4i32: ROTQMBYBIVecInst<v4i32>;
2698 def v2i64: ROTQMBYBIVecInst<v2i64>;
2699}
2700
2701defm ROTQMBYBI: RotateMaskQuadByBitCount;
2702
2703//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2704// Rotate quad and mask by bits
2705// Note that the rotate amount has to be negated
2706//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2707
2708class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2709 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2710 RotateShift, pattern>;
2711
2712class ROTQMBIVecInst<ValueType vectype>:
2713 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2714 [/* no pattern */]>;
2715
2716class ROTQMBIRegInst<RegisterClass rclass>:
2717 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2718 [/* no pattern */]>;
2719
2720multiclass RotateMaskQuadByBits
2721{
2722 def v16i8: ROTQMBIVecInst<v16i8>;
2723 def v8i16: ROTQMBIVecInst<v8i16>;
2724 def v4i32: ROTQMBIVecInst<v4i32>;
2725 def v2i64: ROTQMBIVecInst<v2i64>;
2726
2727 def r128: ROTQMBIRegInst<GPRC>;
2728 def r64: ROTQMBIRegInst<R64C>;
2729}
2730
2731defm ROTQMBI: RotateMaskQuadByBits;
2732
2733def : Pat<(SPUrotquad_rz_bits (v16i8 VECREG:$rA), R32C:$rB),
2734 (ROTQMBIv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2735def : Pat<(SPUrotquad_rz_bits (v8i16 VECREG:$rA), R32C:$rB),
2736 (ROTQMBIv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2737def : Pat<(SPUrotquad_rz_bits (v4i32 VECREG:$rA), R32C:$rB),
2738 (ROTQMBIv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2739def : Pat<(SPUrotquad_rz_bits (v2i64 VECREG:$rA), R32C:$rB),
2740 (ROTQMBIv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2741def : Pat<(SPUrotquad_rz_bits GPRC:$rA, R32C:$rB),
2742 (ROTQMBIr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2743def : Pat<(SPUrotquad_rz_bits R64C:$rA, R32C:$rB),
2744 (ROTQMBIr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2745
2746//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2747// Rotate quad and mask by bits, immediate
2748//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2749
2750class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2751 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2752 RotateShift, pattern>;
2753
2754class ROTQMBIIVecInst<ValueType vectype>:
2755 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2756 [(set (vectype VECREG:$rT),
2757 (SPUrotquad_rz_bits (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2758
2759class ROTQMBIIRegInst<RegisterClass rclass>:
2760 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2761 [(set rclass:$rT,
2762 (SPUrotquad_rz_bits rclass:$rA, (i32 uimm7:$val)))]>;
2763
2764multiclass RotateMaskQuadByBitsImm
2765{
2766 def v16i8: ROTQMBIIVecInst<v16i8>;
2767 def v8i16: ROTQMBIIVecInst<v8i16>;
2768 def v4i32: ROTQMBIIVecInst<v4i32>;
2769 def v2i64: ROTQMBIIVecInst<v2i64>;
2770
2771 def r128: ROTQMBIIRegInst<GPRC>;
2772 def r64: ROTQMBIIRegInst<R64C>;
2773}
2774
2775defm ROTQMBII: RotateMaskQuadByBitsImm;
2776
2777//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2778//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002779
2780def ROTMAHv8i16:
2781 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2782 "rotmah\t$rT, $rA, $rB", RotateShift,
2783 [/* see patterns below - $rB must be negated */]>;
2784
Scott Michel97872d32008-02-23 18:41:37 +00002785def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002786 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2787
Scott Michel97872d32008-02-23 18:41:37 +00002788def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002789 (ROTMAHv8i16 VECREG:$rA,
2790 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2791
Scott Michel97872d32008-02-23 18:41:37 +00002792def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002793 (ROTMAHv8i16 VECREG:$rA,
2794 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2795
Scott Michel8b6b4202007-12-04 22:35:58 +00002796def ROTMAHr16:
2797 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2798 "rotmah\t$rT, $rA, $rB", RotateShift,
2799 [/* see patterns below - $rB must be negated */]>;
2800
2801def : Pat<(sra R16C:$rA, R32C:$rB),
2802 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2803
2804def : Pat<(sra R16C:$rA, R16C:$rB),
2805 (ROTMAHr16 R16C:$rA,
2806 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2807
Scott Michel438be252007-12-17 22:32:34 +00002808def : Pat<(sra R16C:$rA, R8C:$rB),
2809 (ROTMAHr16 R16C:$rA,
2810 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2811
Scott Michel8b6b4202007-12-04 22:35:58 +00002812def ROTMAHIv8i16:
2813 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2814 "rotmahi\t$rT, $rA, $val", RotateShift,
2815 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002816 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002817
Scott Michel97872d32008-02-23 18:41:37 +00002818def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002819 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2820
Scott Michel97872d32008-02-23 18:41:37 +00002821def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002822 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2823
Scott Michel8b6b4202007-12-04 22:35:58 +00002824def ROTMAHIr16:
2825 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2826 "rotmahi\t$rT, $rA, $val", RotateShift,
2827 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2828
2829def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2830 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2831
Scott Michel438be252007-12-17 22:32:34 +00002832def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2833 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2834
Scott Michel8b6b4202007-12-04 22:35:58 +00002835def ROTMAv4i32:
2836 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2837 "rotma\t$rT, $rA, $rB", RotateShift,
2838 [/* see patterns below - $rB must be negated */]>;
2839
Scott Michel97872d32008-02-23 18:41:37 +00002840def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002841 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2842
Scott Michel97872d32008-02-23 18:41:37 +00002843def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002844 (ROTMAv4i32 (v4i32 VECREG:$rA),
2845 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2846
Scott Michel97872d32008-02-23 18:41:37 +00002847def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002848 (ROTMAv4i32 (v4i32 VECREG:$rA),
2849 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2850
Scott Michel8b6b4202007-12-04 22:35:58 +00002851def ROTMAr32:
2852 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2853 "rotma\t$rT, $rA, $rB", RotateShift,
2854 [/* see patterns below - $rB must be negated */]>;
2855
2856def : Pat<(sra R32C:$rA, R32C:$rB),
2857 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2858
2859def : Pat<(sra R32C:$rA, R16C:$rB),
2860 (ROTMAr32 R32C:$rA,
2861 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2862
Scott Michel438be252007-12-17 22:32:34 +00002863def : Pat<(sra R32C:$rA, R8C:$rB),
2864 (ROTMAr32 R32C:$rA,
2865 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2866
Scott Michel67224b22008-06-02 22:18:03 +00002867class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2868 RRForm<0b01011110000, OOL, IOL,
2869 "rotmai\t$rT, $rA, $val",
2870 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002871
Scott Michel67224b22008-06-02 22:18:03 +00002872class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2873 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2874 [(set (vectype VECREG:$rT),
2875 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002876
Scott Michel67224b22008-06-02 22:18:03 +00002877class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2878 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2879 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002880
Scott Michel67224b22008-06-02 22:18:03 +00002881multiclass RotateMaskAlgebraicImm {
2882 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2883 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2884 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2885 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2886}
Scott Michel8b6b4202007-12-04 22:35:58 +00002887
Scott Michel67224b22008-06-02 22:18:03 +00002888defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00002889
Scott Michel8b6b4202007-12-04 22:35:58 +00002890//===----------------------------------------------------------------------===//
2891// Branch and conditionals:
2892//===----------------------------------------------------------------------===//
2893
2894let isTerminator = 1, isBarrier = 1 in {
2895 // Halt If Equal (r32 preferred slot only, no vector form)
2896 def HEQr32:
2897 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2898 "heq\t$rA, $rB", BranchResolv,
2899 [/* no pattern to match */]>;
2900
2901 def HEQIr32 :
2902 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2903 "heqi\t$rA, $val", BranchResolv,
2904 [/* no pattern to match */]>;
2905
2906 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2907 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2908 def HGTr32:
2909 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2910 "hgt\t$rA, $rB", BranchResolv,
2911 [/* no pattern to match */]>;
2912
Scott Michel06eabde2008-12-27 04:51:36 +00002913 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00002914 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2915 "hgti\t$rA, $val", BranchResolv,
2916 [/* no pattern to match */]>;
2917
2918 def HLGTr32:
2919 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2920 "hlgt\t$rA, $rB", BranchResolv,
2921 [/* no pattern to match */]>;
2922
2923 def HLGTIr32:
2924 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2925 "hlgti\t$rA, $val", BranchResolv,
2926 [/* no pattern to match */]>;
2927}
2928
Scott Michel06eabde2008-12-27 04:51:36 +00002929//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2930// Comparison operators for i8, i16 and i32:
2931//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002932
Scott Michel97872d32008-02-23 18:41:37 +00002933class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2934 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2935 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002936
Scott Michel97872d32008-02-23 18:41:37 +00002937multiclass CmpEqualByte
2938{
2939 def v16i8 :
2940 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2941 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2942 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002943
Scott Michel97872d32008-02-23 18:41:37 +00002944 def r8 :
2945 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2946 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2947}
Scott Michel8b6b4202007-12-04 22:35:58 +00002948
Scott Michel97872d32008-02-23 18:41:37 +00002949class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2950 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2951 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002952
Scott Michel97872d32008-02-23 18:41:37 +00002953multiclass CmpEqualByteImm
2954{
2955 def v16i8 :
2956 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2957 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2958 v16i8SExt8Imm:$val))]>;
2959 def r8:
2960 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2961 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
2962}
Scott Michel8b6b4202007-12-04 22:35:58 +00002963
Scott Michel97872d32008-02-23 18:41:37 +00002964class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
2965 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
2966 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002967
Scott Michel97872d32008-02-23 18:41:37 +00002968multiclass CmpEqualHalfword
2969{
2970 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2971 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2972 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002973
Scott Michel97872d32008-02-23 18:41:37 +00002974 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2975 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
2976}
Scott Michel8b6b4202007-12-04 22:35:58 +00002977
Scott Michel97872d32008-02-23 18:41:37 +00002978class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
2979 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
2980 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002981
Scott Michel97872d32008-02-23 18:41:37 +00002982multiclass CmpEqualHalfwordImm
2983{
2984 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2985 [(set (v8i16 VECREG:$rT),
2986 (seteq (v8i16 VECREG:$rA),
2987 (v8i16 v8i16SExt10Imm:$val)))]>;
2988 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2989 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
2990}
Scott Michel8b6b4202007-12-04 22:35:58 +00002991
Scott Michel97872d32008-02-23 18:41:37 +00002992class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
2993 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
2994 ByteOp, pattern>;
2995
2996multiclass CmpEqualWord
2997{
2998 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2999 [(set (v4i32 VECREG:$rT),
3000 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3001
3002 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3003 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3004}
3005
3006class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3007 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3008 ByteOp, pattern>;
3009
3010multiclass CmpEqualWordImm
3011{
3012 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3013 [(set (v4i32 VECREG:$rT),
3014 (seteq (v4i32 VECREG:$rA),
3015 (v4i32 v4i32SExt16Imm:$val)))]>;
3016
3017 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3018 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3019}
3020
3021class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3022 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3023 ByteOp, pattern>;
3024
3025multiclass CmpGtrByte
3026{
3027 def v16i8 :
3028 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3029 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3030 (v8i16 VECREG:$rB)))]>;
3031
3032 def r8 :
3033 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3034 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3035}
3036
3037class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3038 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3039 ByteOp, pattern>;
3040
3041multiclass CmpGtrByteImm
3042{
3043 def v16i8 :
3044 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3045 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3046 v16i8SExt8Imm:$val))]>;
3047 def r8:
3048 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003049 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003050}
3051
3052class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3053 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3054 ByteOp, pattern>;
3055
3056multiclass CmpGtrHalfword
3057{
3058 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3059 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3060 (v8i16 VECREG:$rB)))]>;
3061
3062 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3063 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3064}
3065
3066class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3067 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3068 ByteOp, pattern>;
3069
3070multiclass CmpGtrHalfwordImm
3071{
3072 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3073 [(set (v8i16 VECREG:$rT),
3074 (setgt (v8i16 VECREG:$rA),
3075 (v8i16 v8i16SExt10Imm:$val)))]>;
3076 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3077 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3078}
3079
3080class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3081 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3082 ByteOp, pattern>;
3083
3084multiclass CmpGtrWord
3085{
3086 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3087 [(set (v4i32 VECREG:$rT),
3088 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3089
3090 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3091 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3092}
3093
3094class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3095 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3096 ByteOp, pattern>;
3097
3098multiclass CmpGtrWordImm
3099{
3100 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3101 [(set (v4i32 VECREG:$rT),
3102 (setgt (v4i32 VECREG:$rA),
3103 (v4i32 v4i32SExt16Imm:$val)))]>;
3104
3105 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3106 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
3107}
3108
3109class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003110 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003111 ByteOp, pattern>;
3112
3113multiclass CmpLGtrByte
3114{
3115 def v16i8 :
3116 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3117 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3118 (v8i16 VECREG:$rB)))]>;
3119
3120 def r8 :
3121 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3122 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3123}
3124
3125class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003126 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003127 ByteOp, pattern>;
3128
3129multiclass CmpLGtrByteImm
3130{
3131 def v16i8 :
3132 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3133 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3134 v16i8SExt8Imm:$val))]>;
3135 def r8:
3136 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3137 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3138}
3139
3140class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003141 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003142 ByteOp, pattern>;
3143
3144multiclass CmpLGtrHalfword
3145{
3146 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3147 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3148 (v8i16 VECREG:$rB)))]>;
3149
3150 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3151 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3152}
3153
3154class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003155 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003156 ByteOp, pattern>;
3157
3158multiclass CmpLGtrHalfwordImm
3159{
3160 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3161 [(set (v8i16 VECREG:$rT),
3162 (setugt (v8i16 VECREG:$rA),
3163 (v8i16 v8i16SExt10Imm:$val)))]>;
3164 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3165 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3166}
3167
3168class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003169 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003170 ByteOp, pattern>;
3171
3172multiclass CmpLGtrWord
3173{
3174 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3175 [(set (v4i32 VECREG:$rT),
3176 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3177
3178 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3179 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3180}
3181
3182class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003183 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003184 ByteOp, pattern>;
3185
3186multiclass CmpLGtrWordImm
3187{
3188 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3189 [(set (v4i32 VECREG:$rT),
3190 (setugt (v4i32 VECREG:$rA),
3191 (v4i32 v4i32SExt16Imm:$val)))]>;
3192
3193 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003194 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003195}
3196
3197defm CEQB : CmpEqualByte;
3198defm CEQBI : CmpEqualByteImm;
3199defm CEQH : CmpEqualHalfword;
3200defm CEQHI : CmpEqualHalfwordImm;
3201defm CEQ : CmpEqualWord;
3202defm CEQI : CmpEqualWordImm;
3203defm CGTB : CmpGtrByte;
3204defm CGTBI : CmpGtrByteImm;
3205defm CGTH : CmpGtrHalfword;
3206defm CGTHI : CmpGtrHalfwordImm;
3207defm CGT : CmpGtrWord;
3208defm CGTI : CmpGtrWordImm;
3209defm CLGTB : CmpLGtrByte;
3210defm CLGTBI : CmpLGtrByteImm;
3211defm CLGTH : CmpLGtrHalfword;
3212defm CLGTHI : CmpLGtrHalfwordImm;
3213defm CLGT : CmpLGtrWord;
3214defm CLGTI : CmpLGtrWordImm;
3215
Scott Michel53ab7792008-03-10 16:58:52 +00003216//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003217// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3218// define a pattern to generate the right code, as a binary operator
3219// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003220//
Scott Michel06eabde2008-12-27 04:51:36 +00003221// Notes:
3222// 1. This only matches the setcc set of conditionals. Special pattern
3223// matching is used for select conditionals.
3224//
3225// 2. The "DAG" versions of these classes is almost exclusively used for
3226// i64 comparisons. See the tblgen fundamentals documentation for what
3227// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3228// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003229//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003230
Scott Michel53ab7792008-03-10 16:58:52 +00003231class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3232 SPUInstr xorinst, SPUInstr cmpare>:
3233 Pat<(cond rclass:$rA, rclass:$rB),
3234 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3235
3236class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3237 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3238 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3239 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3240
Scott Michel06eabde2008-12-27 04:51:36 +00003241def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003242def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3243
Scott Michel06eabde2008-12-27 04:51:36 +00003244def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003245def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3246
3247def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3248def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003249
3250class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3251 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3252 Pat<(cond rclass:$rA, rclass:$rB),
3253 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3254 (cmpOp2 rclass:$rA, rclass:$rB))>;
3255
3256class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3257 ValueType immtype,
3258 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3259 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3260 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3261 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3262
Scott Michel53ab7792008-03-10 16:58:52 +00003263def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3264def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3265def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3266def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3267def : Pat<(setle R8C:$rA, R8C:$rB),
3268 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3269def : Pat<(setle R8C:$rA, immU8:$imm),
3270 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003271
Scott Michel53ab7792008-03-10 16:58:52 +00003272def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3273def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3274 ORr16, CGTHIr16, CEQHIr16>;
3275def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3276def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3277def : Pat<(setle R16C:$rA, R16C:$rB),
3278 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3279def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3280 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003281
Scott Michel53ab7792008-03-10 16:58:52 +00003282def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3283def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3284 ORr32, CGTIr32, CEQIr32>;
3285def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3286def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3287def : Pat<(setle R32C:$rA, R32C:$rB),
3288 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3289def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3290 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003291
Scott Michel53ab7792008-03-10 16:58:52 +00003292def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3293def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3294def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3295def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3296def : Pat<(setule R8C:$rA, R8C:$rB),
3297 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3298def : Pat<(setule R8C:$rA, immU8:$imm),
3299 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003300
Scott Michel53ab7792008-03-10 16:58:52 +00003301def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3302def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3303 ORr16, CLGTHIr16, CEQHIr16>;
3304def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3305def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3306 CLGTHIr16, CEQHIr16>;
3307def : Pat<(setule R16C:$rA, R16C:$rB),
3308 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003309def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003310 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003311
Scott Michel53ab7792008-03-10 16:58:52 +00003312def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003313def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003314 ORr32, CLGTIr32, CEQIr32>;
3315def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003316def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003317def : Pat<(setule R32C:$rA, R32C:$rB),
3318 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3319def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3320 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003321
Scott Michel53ab7792008-03-10 16:58:52 +00003322//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3323// select conditional patterns:
3324//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3325
3326class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3327 SPUInstr selinstr, SPUInstr cmpare>:
3328 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3329 rclass:$rTrue, rclass:$rFalse),
3330 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003331 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003332
3333class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3334 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3335 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003336 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003337 (selinstr rclass:$rTrue, rclass:$rFalse,
3338 (cmpare rclass:$rA, immpred:$imm))>;
3339
3340def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3341def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3342def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3343def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3344def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3345def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3346
3347def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3348def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3349def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3350def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3351def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3352def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3353
3354def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3355def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3356def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3357def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3358def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3359def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3360
3361class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3362 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3363 SPUInstr cmpOp2>:
3364 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003365 rclass:$rTrue, rclass:$rFalse),
3366 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003367 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3368 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3369
3370class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3371 ValueType inttype,
3372 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3373 SPUInstr cmpOp2>:
3374 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003375 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003376 (selinstr rclass:$rFalse, rclass:$rTrue,
3377 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3378 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3379
3380def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3381def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3382 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3383
3384def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3385def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3386 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3387
3388def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3389def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3390 SELBr32, ORr32, CGTIr32, CEQIr32>;
3391
3392def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3393def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3394 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3395
3396def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3397def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3398 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3399
3400def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3401def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3402 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003403
3404//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003405
3406let isCall = 1,
3407 // All calls clobber the non-callee-saved registers:
3408 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3409 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3410 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3411 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3412 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3413 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3414 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3415 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3416 // All of these instructions use $lr (aka $0)
3417 Uses = [R0] in {
3418 // Branch relative and set link: Used if we actually know that the target
3419 // is within [-32768, 32767] bytes of the target
3420 def BRSL:
3421 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3422 "brsl\t$$lr, $func",
3423 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3424
3425 // Branch absolute and set link: Used if we actually know that the target
3426 // is an absolute address
3427 def BRASL:
3428 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3429 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003430 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003431
3432 // Branch indirect and set link if external data. These instructions are not
3433 // actually generated, matched by an intrinsic:
3434 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3435 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3436 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3437 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3438
3439 // Branch indirect and set link. This is the "X-form" address version of a
3440 // function call
3441 def BISL:
3442 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3443}
3444
3445// Unconditional branches:
3446let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3447 def BR :
3448 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3449 "br\t$dest",
3450 [(br bb:$dest)]>;
3451
3452 // Unconditional, absolute address branch
3453 def BRA:
3454 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3455 "bra\t$dest",
3456 [/* no pattern */]>;
3457
3458 // Indirect branch
3459 def BI:
3460 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3461
3462 // Various branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003463 class BRNZInst<dag IOL, list<dag> pattern>:
3464 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3465 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003466
Scott Michel06eabde2008-12-27 04:51:36 +00003467 class BRNZRegInst<RegisterClass rclass>:
3468 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3469 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003470
Scott Michel06eabde2008-12-27 04:51:36 +00003471 class BRNZVecInst<ValueType vectype>:
3472 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3473 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003474
Scott Michel06eabde2008-12-27 04:51:36 +00003475 multiclass BranchNotZero {
3476 def v4i32 : BRNZVecInst<v4i32>;
3477 def r32 : BRNZRegInst<R32C>;
3478 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003479
Scott Michel06eabde2008-12-27 04:51:36 +00003480 defm BRNZ : BranchNotZero;
3481
3482 class BRZInst<dag IOL, list<dag> pattern>:
3483 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3484 BranchResolv, pattern>;
3485
3486 class BRZRegInst<RegisterClass rclass>:
3487 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3488
3489 class BRZVecInst<ValueType vectype>:
3490 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3491
3492 multiclass BranchZero {
3493 def v4i32: BRZVecInst<v4i32>;
3494 def r32: BRZRegInst<R32C>;
3495 }
3496
3497 defm BRZ: BranchZero;
3498
3499 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3500 // be useful:
3501 /*
3502 class BINZInst<dag IOL, list<dag> pattern>:
3503 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3504
3505 class BINZRegInst<RegisterClass rclass>:
3506 BINZInst<(ins rclass:$rA, brtarget:$dest),
3507 [(brcond rclass:$rA, R32C:$dest)]>;
3508
3509 class BINZVecInst<ValueType vectype>:
3510 BINZInst<(ins VECREG:$rA, R32C:$dest),
3511 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3512
3513 multiclass BranchNotZeroIndirect {
3514 def v4i32: BINZVecInst<v4i32>;
3515 def r32: BINZRegInst<R32C>;
3516 }
3517
3518 defm BINZ: BranchNotZeroIndirect;
3519
3520 class BIZInst<dag IOL, list<dag> pattern>:
3521 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3522
3523 class BIZRegInst<RegisterClass rclass>:
3524 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3525
3526 class BIZVecInst<ValueType vectype>:
3527 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3528
3529 multiclass BranchZeroIndirect {
3530 def v4i32: BIZVecInst<v4i32>;
3531 def r32: BIZRegInst<R32C>;
3532 }
3533
3534 defm BIZ: BranchZeroIndirect;
3535 */
3536
3537 class BRHNZInst<dag IOL, list<dag> pattern>:
3538 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3539 pattern>;
3540
3541 class BRHNZRegInst<RegisterClass rclass>:
3542 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3543 [(brcond rclass:$rCond, bb:$dest)]>;
3544
3545 class BRHNZVecInst<ValueType vectype>:
3546 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3547
3548 multiclass BranchNotZeroHalfword {
3549 def v8i16: BRHNZVecInst<v8i16>;
3550 def r16: BRHNZRegInst<R16C>;
3551 }
3552
3553 defm BRHNZ: BranchNotZeroHalfword;
3554
3555 class BRHZInst<dag IOL, list<dag> pattern>:
3556 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3557 pattern>;
3558
3559 class BRHZRegInst<RegisterClass rclass>:
3560 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3561
3562 class BRHZVecInst<ValueType vectype>:
3563 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3564
3565 multiclass BranchZeroHalfword {
3566 def v8i16: BRHZVecInst<v8i16>;
3567 def r16: BRHZRegInst<R16C>;
3568 }
3569
3570 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003571}
3572
Scott Michel394e26d2008-01-17 20:38:41 +00003573//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003574// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003575//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003576
Scott Michel06eabde2008-12-27 04:51:36 +00003577def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3578 (BRHZr16 R16C:$rA, bb:$dest)>;
3579def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3580 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003581
Scott Michel06eabde2008-12-27 04:51:36 +00003582def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3583 (BRZr32 R32C:$rA, bb:$dest)>;
3584def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3585 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003586
Scott Michel97872d32008-02-23 18:41:37 +00003587multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3588{
3589 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3590 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003591
Scott Michel97872d32008-02-23 18:41:37 +00003592 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3593 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3594
3595 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3596 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3597
3598 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3599 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3600}
3601
Scott Michel06eabde2008-12-27 04:51:36 +00003602defm BRCONDeq : BranchCondEQ<seteq, BRHZr16, BRZr32>;
3603defm BRCONDne : BranchCondEQ<setne, BRHNZr16, BRNZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003604
3605multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3606{
3607 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3608 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3609
3610 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3611 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3612
3613 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3614 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3615
3616 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3617 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3618}
3619
Scott Michel06eabde2008-12-27 04:51:36 +00003620defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3621defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003622
3623multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3624 SPUInstr orinst32, SPUInstr brinst32>
3625{
3626 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3627 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3628 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3629 bb:$dest)>;
3630
3631 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3632 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3633 (CEQHr16 R16C:$rA, R16:$rB)),
3634 bb:$dest)>;
3635
3636 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3637 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3638 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3639 bb:$dest)>;
3640
3641 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3642 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3643 (CEQr32 R32C:$rA, R32C:$rB)),
3644 bb:$dest)>;
3645}
3646
Scott Michel06eabde2008-12-27 04:51:36 +00003647defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3648defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003649
3650multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3651{
3652 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3653 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3654
3655 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3656 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3657
3658 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3659 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3660
3661 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3662 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3663}
3664
Scott Michel06eabde2008-12-27 04:51:36 +00003665defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3666defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003667
3668multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3669 SPUInstr orinst32, SPUInstr brinst32>
3670{
3671 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3672 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3673 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3674 bb:$dest)>;
3675
3676 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3677 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3678 (CEQHr16 R16C:$rA, R16:$rB)),
3679 bb:$dest)>;
3680
3681 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3682 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3683 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3684 bb:$dest)>;
3685
3686 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3687 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3688 (CEQr32 R32C:$rA, R32C:$rB)),
3689 bb:$dest)>;
3690}
3691
Scott Michel06eabde2008-12-27 04:51:36 +00003692defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3693defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003694
Scott Michel8b6b4202007-12-04 22:35:58 +00003695let isTerminator = 1, isBarrier = 1 in {
3696 let isReturn = 1 in {
3697 def RET:
3698 RETForm<"bi\t$$lr", [(retflag)]>;
3699 }
3700}
3701
3702//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003703// Single precision floating point instructions
3704//===----------------------------------------------------------------------===//
3705
Scott Michel61895fe2008-12-10 00:15:19 +00003706class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3707 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
3708 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003709
Scott Michel61895fe2008-12-10 00:15:19 +00003710class FAVecInst<ValueType vectype>:
3711 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3712 [(set (vectype VECREG:$rT),
3713 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003714
Scott Michel61895fe2008-12-10 00:15:19 +00003715multiclass SFPAdd
3716{
3717 def v4f32: FAVecInst<v4f32>;
3718 def r32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3719 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3720}
Scott Michel8b6b4202007-12-04 22:35:58 +00003721
Scott Michel61895fe2008-12-10 00:15:19 +00003722defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003723
Scott Michel61895fe2008-12-10 00:15:19 +00003724class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3725 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
3726 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003727
Scott Michel61895fe2008-12-10 00:15:19 +00003728class FSVecInst<ValueType vectype>:
3729 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3730 [(set (vectype VECREG:$rT),
3731 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
3732
3733multiclass SFPSub
3734{
3735 def v4f32: FSVecInst<v4f32>;
3736 def r32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3737 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3738}
3739
3740defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003741
3742// Floating point reciprocal estimate
3743def FREv4f32 :
3744 RRForm_1<0b00011101100, (outs VECREG:$rT), (ins VECREG:$rA),
3745 "frest\t$rT, $rA", SPrecFP,
3746 [(set (v4f32 VECREG:$rT), (SPUreciprocalEst (v4f32 VECREG:$rA)))]>;
3747
3748def FREf32 :
3749 RRForm_1<0b00011101100, (outs R32FP:$rT), (ins R32FP:$rA),
3750 "frest\t$rT, $rA", SPrecFP,
3751 [(set R32FP:$rT, (SPUreciprocalEst R32FP:$rA))]>;
3752
3753// Floating point interpolate (used in conjunction with reciprocal estimate)
3754def FIv4f32 :
3755 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3756 "fi\t$rT, $rA, $rB", SPrecFP,
3757 [(set (v4f32 VECREG:$rT), (SPUinterpolate (v4f32 VECREG:$rA),
3758 (v4f32 VECREG:$rB)))]>;
3759
3760def FIf32 :
3761 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3762 "fi\t$rT, $rA, $rB", SPrecFP,
3763 [(set R32FP:$rT, (SPUinterpolate R32FP:$rA, R32FP:$rB))]>;
3764
Scott Michel33d73eb2008-11-21 02:56:16 +00003765//--------------------------------------------------------------------------
3766// Basic single precision floating point comparisons:
3767//
3768// Note: There is no support on SPU for single precision NaN. Consequently,
3769// ordered and unordered comparisons are the same.
3770//--------------------------------------------------------------------------
3771
Scott Michel8b6b4202007-12-04 22:35:58 +00003772def FCEQf32 :
3773 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3774 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003775 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3776
3777def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3778 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003779
3780def FCMEQf32 :
3781 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3782 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003783 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3784
3785def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3786 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003787
3788def FCGTf32 :
3789 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3790 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003791 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3792
3793def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3794 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003795
3796def FCMGTf32 :
3797 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3798 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003799 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3800
3801def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3802 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3803
3804//--------------------------------------------------------------------------
3805// Single precision floating point comparisons and SETCC equivalents:
3806//--------------------------------------------------------------------------
3807
3808def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3809def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3810
3811def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3812def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3813
3814def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3815def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3816
3817def : Pat<(setule R32FP:$rA, R32FP:$rB),
3818 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3819def : Pat<(setole R32FP:$rA, R32FP:$rB),
3820 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003821
3822// FP Status and Control Register Write
3823// Why isn't rT a don't care in the ISA?
3824// Should we create a special RRForm_3 for this guy and zero out the rT?
3825def FSCRWf32 :
3826 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3827 "fscrwr\t$rA", SPrecFP,
3828 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3829
3830// FP Status and Control Register Read
3831def FSCRRf32 :
3832 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3833 "fscrrd\t$rT", SPrecFP,
3834 [/* This instruction requires an intrinsic */]>;
3835
3836// llvm instruction space
3837// How do these map onto cell instructions?
3838// fdiv rA rB
3839// frest rC rB # c = 1/b (both lines)
3840// fi rC rB rC
3841// fm rD rA rC # d = a * 1/b
3842// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3843// fma rB rB rC rD # b = b * c + d
3844// = -(d *b -a) * c + d
3845// = a * c - c ( a *b *c - a)
3846
3847// fcopysign (???)
3848
3849// Library calls:
3850// These llvm instructions will actually map to library calls.
3851// All that's needed, then, is to check that the appropriate library is
3852// imported and do a brsl to the proper function name.
3853// frem # fmod(x, y): x - (x/y) * y
3854// (Note: fmod(double, double), fmodf(float,float)
3855// fsqrt?
3856// fsin?
3857// fcos?
3858// Unimplemented SPU instruction space
3859// floating reciprocal absolute square root estimate (frsqest)
3860
3861// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00003862// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00003863// status and control register read
3864
3865//--------------------------------------
3866// Floating point multiply instructions
3867//--------------------------------------
3868
3869def FMv4f32:
3870 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3871 "fm\t$rT, $rA, $rB", SPrecFP,
3872 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3873 (v4f32 VECREG:$rB)))]>;
3874
3875def FMf32 :
3876 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3877 "fm\t$rT, $rA, $rB", SPrecFP,
3878 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3879
3880// Floating point multiply and add
3881// e.g. d = c + (a * b)
3882def FMAv4f32:
3883 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3884 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3885 [(set (v4f32 VECREG:$rT),
3886 (fadd (v4f32 VECREG:$rC),
3887 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3888
3889def FMAf32:
3890 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3891 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3892 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3893
3894// FP multiply and subtract
3895// Subtracts value in rC from product
3896// res = a * b - c
3897def FMSv4f32 :
3898 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3899 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3900 [(set (v4f32 VECREG:$rT),
3901 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3902 (v4f32 VECREG:$rC)))]>;
3903
3904def FMSf32 :
3905 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3906 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3907 [(set R32FP:$rT,
3908 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3909
3910// Floating Negative Mulitply and Subtract
3911// Subtracts product from value in rC
3912// res = fneg(fms a b c)
3913// = - (a * b - c)
3914// = c - a * b
3915// NOTE: subtraction order
3916// fsub a b = a - b
Scott Michel06eabde2008-12-27 04:51:36 +00003917// fs a b = b - a?
Scott Michel8b6b4202007-12-04 22:35:58 +00003918def FNMSf32 :
3919 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3920 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3921 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3922
3923def FNMSv4f32 :
3924 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3925 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00003926 [(set (v4f32 VECREG:$rT),
3927 (fsub (v4f32 VECREG:$rC),
3928 (fmul (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00003929 (v4f32 VECREG:$rB))))]>;
3930
3931//--------------------------------------
3932// Floating Point Conversions
3933// Signed conversions:
3934def CSiFv4f32:
3935 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3936 "csflt\t$rT, $rA, 0", SPrecFP,
3937 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3938
Scott Michel06eabde2008-12-27 04:51:36 +00003939// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00003940def CSiFf32 :
3941 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3942 "csflt\t$rT, $rA, 0", SPrecFP,
3943 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3944
3945// Convert unsigned into to float
3946def CUiFv4f32 :
3947 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3948 "cuflt\t$rT, $rA, 0", SPrecFP,
3949 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3950
3951def CUiFf32 :
3952 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3953 "cuflt\t$rT, $rA, 0", SPrecFP,
3954 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
3955
Scott Michel06eabde2008-12-27 04:51:36 +00003956// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00003957// Assume that scale = 0
3958
3959def CFUiv4f32 :
3960 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3961 "cfltu\t$rT, $rA, 0", SPrecFP,
3962 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
3963
3964def CFUif32 :
3965 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3966 "cfltu\t$rT, $rA, 0", SPrecFP,
3967 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
3968
Scott Michel06eabde2008-12-27 04:51:36 +00003969// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00003970// Assume that scale = 0
3971
3972def CFSiv4f32 :
3973 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3974 "cflts\t$rT, $rA, 0", SPrecFP,
3975 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
3976
3977def CFSif32 :
3978 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3979 "cflts\t$rT, $rA, 0", SPrecFP,
3980 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
3981
3982//===----------------------------------------------------------------------==//
3983// Single<->Double precision conversions
3984//===----------------------------------------------------------------------==//
3985
3986// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
3987// v4f32, output is v2f64--which goes in the name?)
3988
3989// Floating point extend single to double
3990// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
3991// operates on two double-word slots (i.e. 1st and 3rd fp numbers
3992// are ignored).
3993def FESDvec :
3994 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3995 "fesd\t$rT, $rA", SPrecFP,
3996 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
3997
3998def FESDf32 :
3999 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4000 "fesd\t$rT, $rA", SPrecFP,
4001 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4002
4003// Floating point round double to single
4004//def FRDSvec :
4005// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4006// "frds\t$rT, $rA,", SPrecFP,
4007// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4008
4009def FRDSf64 :
4010 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4011 "frds\t$rT, $rA", SPrecFP,
4012 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4013
4014//ToDo include anyextend?
4015
4016//===----------------------------------------------------------------------==//
4017// Double precision floating point instructions
4018//===----------------------------------------------------------------------==//
4019def FAf64 :
4020 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4021 "dfa\t$rT, $rA, $rB", DPrecFP,
4022 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4023
4024def FAv2f64 :
4025 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4026 "dfa\t$rT, $rA, $rB", DPrecFP,
4027 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4028
4029def FSf64 :
4030 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4031 "dfs\t$rT, $rA, $rB", DPrecFP,
4032 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4033
4034def FSv2f64 :
4035 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4036 "dfs\t$rT, $rA, $rB", DPrecFP,
4037 [(set (v2f64 VECREG:$rT),
4038 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4039
4040def FMf64 :
4041 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4042 "dfm\t$rT, $rA, $rB", DPrecFP,
4043 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4044
4045def FMv2f64:
4046 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4047 "dfm\t$rT, $rA, $rB", DPrecFP,
4048 [(set (v2f64 VECREG:$rT),
4049 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4050
4051def FMAf64:
4052 RRForm<0b00111010110, (outs R64FP:$rT),
4053 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4054 "dfma\t$rT, $rA, $rB", DPrecFP,
4055 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4056 RegConstraint<"$rC = $rT">,
4057 NoEncode<"$rC">;
4058
4059def FMAv2f64:
4060 RRForm<0b00111010110, (outs VECREG:$rT),
4061 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4062 "dfma\t$rT, $rA, $rB", DPrecFP,
4063 [(set (v2f64 VECREG:$rT),
4064 (fadd (v2f64 VECREG:$rC),
4065 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4066 RegConstraint<"$rC = $rT">,
4067 NoEncode<"$rC">;
4068
4069def FMSf64 :
4070 RRForm<0b10111010110, (outs R64FP:$rT),
4071 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4072 "dfms\t$rT, $rA, $rB", DPrecFP,
4073 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4074 RegConstraint<"$rC = $rT">,
4075 NoEncode<"$rC">;
4076
4077def FMSv2f64 :
4078 RRForm<0b10111010110, (outs VECREG:$rT),
4079 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4080 "dfms\t$rT, $rA, $rB", DPrecFP,
4081 [(set (v2f64 VECREG:$rT),
4082 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4083 (v2f64 VECREG:$rC)))]>;
4084
4085// FNMS: - (a * b - c)
4086// - (a * b) + c => c - (a * b)
4087def FNMSf64 :
4088 RRForm<0b01111010110, (outs R64FP:$rT),
4089 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4090 "dfnms\t$rT, $rA, $rB", DPrecFP,
4091 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4092 RegConstraint<"$rC = $rT">,
4093 NoEncode<"$rC">;
4094
4095def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4096 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4097
4098def FNMSv2f64 :
4099 RRForm<0b01111010110, (outs VECREG:$rT),
4100 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4101 "dfnms\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004102 [(set (v2f64 VECREG:$rT),
4103 (fsub (v2f64 VECREG:$rC),
4104 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004105 (v2f64 VECREG:$rB))))]>,
4106 RegConstraint<"$rC = $rT">,
4107 NoEncode<"$rC">;
4108
4109def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4110 (v2f64 VECREG:$rC))),
4111 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4112
4113// - (a * b + c)
4114// - (a * b) - c
4115def FNMAf64 :
4116 RRForm<0b11111010110, (outs R64FP:$rT),
4117 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4118 "dfnma\t$rT, $rA, $rB", DPrecFP,
4119 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4120 RegConstraint<"$rC = $rT">,
4121 NoEncode<"$rC">;
4122
4123def FNMAv2f64 :
4124 RRForm<0b11111010110, (outs VECREG:$rT),
4125 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4126 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004127 [(set (v2f64 VECREG:$rT),
4128 (fneg (fadd (v2f64 VECREG:$rC),
4129 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004130 (v2f64 VECREG:$rB)))))]>,
4131 RegConstraint<"$rC = $rT">,
4132 NoEncode<"$rC">;
4133
4134//===----------------------------------------------------------------------==//
4135// Floating point negation and absolute value
4136//===----------------------------------------------------------------------==//
4137
4138def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00004139 (XORfnegvec (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004140 (v4f32 (ILHUv4i32 0x8000)))>;
4141
4142def : Pat<(fneg R32FP:$rA),
4143 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4144
4145def : Pat<(fneg (v2f64 VECREG:$rA)),
4146 (XORfnegvec (v2f64 VECREG:$rA),
4147 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4148
4149def : Pat<(fneg R64FP:$rA),
4150 (XORfneg64 R64FP:$rA,
4151 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4152
4153// Floating point absolute value
4154
4155def : Pat<(fabs R32FP:$rA),
4156 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4157
4158def : Pat<(fabs (v4f32 VECREG:$rA)),
4159 (ANDfabsvec (v4f32 VECREG:$rA),
4160 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4161
4162def : Pat<(fabs R64FP:$rA),
4163 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4164
4165def : Pat<(fabs (v2f64 VECREG:$rA)),
4166 (ANDfabsvec (v2f64 VECREG:$rA),
4167 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4168
4169//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004170// Hint for branch instructions:
4171//===----------------------------------------------------------------------===//
4172
4173/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4174
4175//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004176// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4177// in the odd pipeline)
4178//===----------------------------------------------------------------------===//
4179
Scott Michel97872d32008-02-23 18:41:37 +00004180def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004181 let Pattern = [];
4182
4183 let Inst{0-10} = 0b10000000010;
4184 let Inst{11-17} = 0;
4185 let Inst{18-24} = 0;
4186 let Inst{25-31} = 0;
4187}
4188
Scott Michel97872d32008-02-23 18:41:37 +00004189def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004190 let Pattern = [];
4191
4192 let Inst{0-10} = 0b10000000000;
4193 let Inst{11-17} = 0;
4194 let Inst{18-24} = 0;
4195 let Inst{25-31} = 0;
4196}
4197
4198//===----------------------------------------------------------------------===//
4199// Bit conversions (type conversions between vector/packed types)
4200// NOTE: Promotions are handled using the XS* instructions. Truncation
4201// is not handled.
4202//===----------------------------------------------------------------------===//
4203def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4204def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4205def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4206def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4207def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4208
4209def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4210def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4211def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4212def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4213def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4214
4215def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4216def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4217def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4218def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4219def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4220
4221def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4222def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4223def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4224def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4225def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4226
4227def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4228def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4229def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4230def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4231def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4232
4233def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4234def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4235def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4236def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4237def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4238
4239def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00004240def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004241
4242//===----------------------------------------------------------------------===//
4243// Instruction patterns:
4244//===----------------------------------------------------------------------===//
4245
4246// General 32-bit constants:
4247def : Pat<(i32 imm:$imm),
4248 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4249
4250// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004251def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004252 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4253
4254// General constant 32-bit vectors
4255def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004256 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4257 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004258
Scott Michel438be252007-12-17 22:32:34 +00004259// 8-bit constants
4260def : Pat<(i8 imm:$imm),
4261 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004262
4263//===----------------------------------------------------------------------===//
4264// Call instruction patterns:
4265//===----------------------------------------------------------------------===//
4266// Return void
4267def : Pat<(ret),
4268 (RET)>;
4269
4270//===----------------------------------------------------------------------===//
4271// Zero/Any/Sign extensions
4272//===----------------------------------------------------------------------===//
4273
Scott Michel8b6b4202007-12-04 22:35:58 +00004274// sext 8->32: Sign extend bytes to words
4275def : Pat<(sext_inreg R32C:$rSrc, i8),
4276 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4277
Scott Michel438be252007-12-17 22:32:34 +00004278def : Pat<(i32 (sext R8C:$rSrc)),
4279 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4280
Scott Michel438be252007-12-17 22:32:34 +00004281// zext 8->16: Zero extend bytes to halfwords
4282def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004283 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004284
Scott Michel438be252007-12-17 22:32:34 +00004285// zext 8->32: Zero extend bytes to words
4286def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004287 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004288
4289// anyext 8->16: Extend 8->16 bits, irrespective of sign
4290def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004291 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004292
4293// anyext 8->32: Extend 8->32 bits, irrespective of sign
4294def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004295 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004296
Scott Michel97872d32008-02-23 18:41:37 +00004297// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004298def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004299 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004300
4301def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004302 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004303
4304def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004305 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004306
4307def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004308 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004309
4310// anyext 16->32: Extend 16->32 bits, irrespective of sign
4311def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004312 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004313
4314//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004315// Truncates:
4316// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4317// above are custom lowered.
4318//===----------------------------------------------------------------------===//
4319
4320def : Pat<(i8 (trunc GPRC:$src)),
4321 (ORi8_v16i8
4322 (SHUFBgprc GPRC:$src, GPRC:$src,
4323 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4324
4325def : Pat<(i8 (trunc R64C:$src)),
4326 (ORi8_v16i8
4327 (SHUFBv2i64_m32
4328 (ORv2i64_i64 R64C:$src),
4329 (ORv2i64_i64 R64C:$src),
4330 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4331
4332def : Pat<(i8 (trunc R32C:$src)),
4333 (ORi8_v16i8
4334 (SHUFBv4i32_m32
4335 (ORv4i32_i32 R32C:$src),
4336 (ORv4i32_i32 R32C:$src),
4337 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4338
4339def : Pat<(i8 (trunc R16C:$src)),
4340 (ORi8_v16i8
4341 (SHUFBv4i32_m32
4342 (ORv8i16_i16 R16C:$src),
4343 (ORv8i16_i16 R16C:$src),
4344 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4345
4346def : Pat<(i16 (trunc GPRC:$src)),
4347 (ORi16_v8i16
4348 (SHUFBgprc GPRC:$src, GPRC:$src,
4349 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4350
4351def : Pat<(i16 (trunc R64C:$src)),
4352 (ORi16_v8i16
4353 (SHUFBv2i64_m32
4354 (ORv2i64_i64 R64C:$src),
4355 (ORv2i64_i64 R64C:$src),
4356 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4357
4358def : Pat<(i16 (trunc R32C:$src)),
4359 (ORi16_v8i16
4360 (SHUFBv4i32_m32
4361 (ORv4i32_i32 R32C:$src),
4362 (ORv4i32_i32 R32C:$src),
4363 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4364
4365def : Pat<(i32 (trunc GPRC:$src)),
4366 (ORi32_v4i32
4367 (SHUFBgprc GPRC:$src, GPRC:$src,
4368 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4369
4370def : Pat<(i32 (trunc R64C:$src)),
4371 (ORi32_v4i32
4372 (SHUFBv2i64_m32
4373 (ORv2i64_i64 R64C:$src),
4374 (ORv2i64_i64 R64C:$src),
4375 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4376
4377//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004378// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004379// low parts in order to load them into a register.
4380//===----------------------------------------------------------------------===//
4381
Scott Michelf9f42e62008-01-29 02:16:57 +00004382def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4383def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4384def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4385def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4386
4387def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4388 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004389 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004390
Scott Michelf9f42e62008-01-29 02:16:57 +00004391def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4392 (SPUlo texternalsym:$in, 0)),
4393 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4394
4395def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4396 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004397 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004398
Scott Michelf9f42e62008-01-29 02:16:57 +00004399def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4400 (SPUlo tconstpool:$in, 0)),
4401 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4402
Scott Michelbc5fbc12008-04-30 00:30:08 +00004403def : Pat<(SPUindirect R32C:$sp, i32ImmSExt10:$imm),
4404 (AIr32 R32C:$sp, i32ImmSExt10:$imm)>;
4405
4406def : Pat<(SPUindirect R32C:$sp, imm:$imm),
4407 (Ar32 R32C:$sp,
4408 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm)))>;
4409
Scott Michelf9f42e62008-01-29 02:16:57 +00004410def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4411 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4412
4413def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4414 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4415
4416def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4417 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4418
4419def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4420 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004421
Scott Michel8b6b4202007-12-04 22:35:58 +00004422// Instrinsics:
4423include "CellSDKIntrinsics.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004424// 64-bit "instructions"/support
4425include "SPU64InstrInfo.td"