blob: ca0fe00e37f89283f0bf8b53f57eb97140b3cf8e [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//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +000034// Loads:
35// NB: The ordering is actually important, since the instruction selection
36// will try each of the instructions in sequence, i.e., the D-form first with
37// the 10-bit displacement, then the A-form with the 16 bit displacement, and
38// finally the X-form with the register-register.
39//===----------------------------------------------------------------------===//
40
Dan Gohman5574cc72008-12-03 18:15:48 +000041let canFoldAsLoad = 1 in {
Scott Michelf9f42e62008-01-29 02:16:57 +000042 class LoadDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +000043 : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000044 "lqd\t$rT, $src",
45 LoadStore,
46 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
47 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000048
Scott Michelf9f42e62008-01-29 02:16:57 +000049 class LoadDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +000050 : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000051 "lqd\t$rT, $src",
52 LoadStore,
53 [(set rclass:$rT, (load dform_addr:$src))]>
54 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000055
Scott Michelf9f42e62008-01-29 02:16:57 +000056 multiclass LoadDForms
57 {
58 def v16i8: LoadDFormVec<v16i8>;
59 def v8i16: LoadDFormVec<v8i16>;
60 def v4i32: LoadDFormVec<v4i32>;
61 def v2i64: LoadDFormVec<v2i64>;
62 def v4f32: LoadDFormVec<v4f32>;
63 def v2f64: LoadDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000064
Scott Michelf9f42e62008-01-29 02:16:57 +000065 def r128: LoadDForm<GPRC>;
66 def r64: LoadDForm<R64C>;
67 def r32: LoadDForm<R32C>;
68 def f32: LoadDForm<R32FP>;
69 def f64: LoadDForm<R64FP>;
70 def r16: LoadDForm<R16C>;
71 def r8: LoadDForm<R8C>;
72 }
Scott Michel8b6b4202007-12-04 22:35:58 +000073
Scott Michelf9f42e62008-01-29 02:16:57 +000074 class LoadAFormVec<ValueType vectype>
75 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
76 "lqa\t$rT, $src",
77 LoadStore,
78 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
79 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000080
Scott Michelf9f42e62008-01-29 02:16:57 +000081 class LoadAForm<RegisterClass rclass>
82 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
83 "lqa\t$rT, $src",
84 LoadStore,
85 [(set rclass:$rT, (load aform_addr:$src))]>
86 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000087
Scott Michelf9f42e62008-01-29 02:16:57 +000088 multiclass LoadAForms
89 {
90 def v16i8: LoadAFormVec<v16i8>;
91 def v8i16: LoadAFormVec<v8i16>;
92 def v4i32: LoadAFormVec<v4i32>;
93 def v2i64: LoadAFormVec<v2i64>;
94 def v4f32: LoadAFormVec<v4f32>;
95 def v2f64: LoadAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000096
Scott Michelf9f42e62008-01-29 02:16:57 +000097 def r128: LoadAForm<GPRC>;
98 def r64: LoadAForm<R64C>;
99 def r32: LoadAForm<R32C>;
100 def f32: LoadAForm<R32FP>;
101 def f64: LoadAForm<R64FP>;
102 def r16: LoadAForm<R16C>;
103 def r8: LoadAForm<R8C>;
104 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000105
Scott Michelf9f42e62008-01-29 02:16:57 +0000106 class LoadXFormVec<ValueType vectype>
107 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
108 "lqx\t$rT, $src",
109 LoadStore,
110 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
111 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000112
Scott Michelf9f42e62008-01-29 02:16:57 +0000113 class LoadXForm<RegisterClass rclass>
114 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
115 "lqx\t$rT, $src",
116 LoadStore,
117 [(set rclass:$rT, (load xform_addr:$src))]>
118 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000119
Scott Michelf9f42e62008-01-29 02:16:57 +0000120 multiclass LoadXForms
121 {
122 def v16i8: LoadXFormVec<v16i8>;
123 def v8i16: LoadXFormVec<v8i16>;
124 def v4i32: LoadXFormVec<v4i32>;
125 def v2i64: LoadXFormVec<v2i64>;
126 def v4f32: LoadXFormVec<v4f32>;
127 def v2f64: LoadXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000128
Scott Michelf9f42e62008-01-29 02:16:57 +0000129 def r128: LoadXForm<GPRC>;
130 def r64: LoadXForm<R64C>;
131 def r32: LoadXForm<R32C>;
132 def f32: LoadXForm<R32FP>;
133 def f64: LoadXForm<R64FP>;
134 def r16: LoadXForm<R16C>;
135 def r8: LoadXForm<R8C>;
136 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000137
Scott Michelf9f42e62008-01-29 02:16:57 +0000138 defm LQA : LoadAForms;
139 defm LQD : LoadDForms;
140 defm LQX : LoadXForms;
Scott Michel438be252007-12-17 22:32:34 +0000141
Scott Michel8b6b4202007-12-04 22:35:58 +0000142/* Load quadword, PC relative: Not much use at this point in time.
Scott Michelf9f42e62008-01-29 02:16:57 +0000143 Might be of use later for relocatable code. It's effectively the
144 same as LQA, but uses PC-relative addressing.
Scott Michel8b6b4202007-12-04 22:35:58 +0000145 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
146 "lqr\t$rT, $disp", LoadStore,
147 [(set VECREG:$rT, (load iaddr:$disp))]>;
148 */
Scott Michel8b6b4202007-12-04 22:35:58 +0000149}
150
151//===----------------------------------------------------------------------===//
152// Stores:
153//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +0000154class StoreDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +0000155 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000156 "stqd\t$rT, $src",
157 LoadStore,
158 [(store (vectype VECREG:$rT), dform_addr:$src)]>
159{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000160
Scott Michelf9f42e62008-01-29 02:16:57 +0000161class StoreDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +0000162 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000163 "stqd\t$rT, $src",
164 LoadStore,
165 [(store rclass:$rT, dform_addr:$src)]>
166{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000167
Scott Michelf9f42e62008-01-29 02:16:57 +0000168multiclass StoreDForms
169{
170 def v16i8: StoreDFormVec<v16i8>;
171 def v8i16: StoreDFormVec<v8i16>;
172 def v4i32: StoreDFormVec<v4i32>;
173 def v2i64: StoreDFormVec<v2i64>;
174 def v4f32: StoreDFormVec<v4f32>;
175 def v2f64: StoreDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000176
Scott Michelf9f42e62008-01-29 02:16:57 +0000177 def r128: StoreDForm<GPRC>;
178 def r64: StoreDForm<R64C>;
179 def r32: StoreDForm<R32C>;
180 def f32: StoreDForm<R32FP>;
181 def f64: StoreDForm<R64FP>;
182 def r16: StoreDForm<R16C>;
183 def r8: StoreDForm<R8C>;
184}
Scott Michel8b6b4202007-12-04 22:35:58 +0000185
Scott Michelf9f42e62008-01-29 02:16:57 +0000186class StoreAFormVec<ValueType vectype>
187 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000188 "stqa\t$rT, $src",
189 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000190 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000191
Scott Michelf9f42e62008-01-29 02:16:57 +0000192class StoreAForm<RegisterClass rclass>
193 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000194 "stqa\t$rT, $src",
195 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000196 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000197
Scott Michelf9f42e62008-01-29 02:16:57 +0000198multiclass StoreAForms
199{
200 def v16i8: StoreAFormVec<v16i8>;
201 def v8i16: StoreAFormVec<v8i16>;
202 def v4i32: StoreAFormVec<v4i32>;
203 def v2i64: StoreAFormVec<v2i64>;
204 def v4f32: StoreAFormVec<v4f32>;
205 def v2f64: StoreAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000206
Scott Michelf9f42e62008-01-29 02:16:57 +0000207 def r128: StoreAForm<GPRC>;
208 def r64: StoreAForm<R64C>;
209 def r32: StoreAForm<R32C>;
210 def f32: StoreAForm<R32FP>;
211 def f64: StoreAForm<R64FP>;
212 def r16: StoreAForm<R16C>;
213 def r8: StoreAForm<R8C>;
214}
Scott Michel8b6b4202007-12-04 22:35:58 +0000215
Scott Michelf9f42e62008-01-29 02:16:57 +0000216class StoreXFormVec<ValueType vectype>
217 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000218 "stqx\t$rT, $src",
219 LoadStore,
220 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000221{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000222
Scott Michelf9f42e62008-01-29 02:16:57 +0000223class StoreXForm<RegisterClass rclass>
224 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000225 "stqx\t$rT, $src",
226 LoadStore,
227 [(store rclass:$rT, xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000228{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000229
Scott Michelf9f42e62008-01-29 02:16:57 +0000230multiclass StoreXForms
231{
232 def v16i8: StoreXFormVec<v16i8>;
233 def v8i16: StoreXFormVec<v8i16>;
234 def v4i32: StoreXFormVec<v4i32>;
235 def v2i64: StoreXFormVec<v2i64>;
236 def v4f32: StoreXFormVec<v4f32>;
237 def v2f64: StoreXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000238
Scott Michelf9f42e62008-01-29 02:16:57 +0000239 def r128: StoreXForm<GPRC>;
240 def r64: StoreXForm<R64C>;
241 def r32: StoreXForm<R32C>;
242 def f32: StoreXForm<R32FP>;
243 def f64: StoreXForm<R64FP>;
244 def r16: StoreXForm<R16C>;
245 def r8: StoreXForm<R8C>;
246}
Scott Michel8b6b4202007-12-04 22:35:58 +0000247
Scott Michelf9f42e62008-01-29 02:16:57 +0000248defm STQD : StoreDForms;
249defm STQA : StoreAForms;
250defm STQX : StoreXForms;
Scott Michel8b6b4202007-12-04 22:35:58 +0000251
252/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michelf9f42e62008-01-29 02:16:57 +0000253 be useful for relocatable code.
Chris Lattneref8d6082008-01-06 06:44:58 +0000254def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
255 "stqr\t$rT, $disp", LoadStore,
256 [(store VECREG:$rT, iaddr:$disp)]>;
257*/
Scott Michel8b6b4202007-12-04 22:35:58 +0000258
259//===----------------------------------------------------------------------===//
260// Generate Controls for Insertion:
261//===----------------------------------------------------------------------===//
262
Scott Michel06eabde2008-12-27 04:51:36 +0000263def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000264 "cbd\t$rT, $src", ShuffleOp,
265 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000266
Scott Michel0718cd82008-12-01 17:56:02 +0000267def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000268 "cbx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000269 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000270
Scott Michel06eabde2008-12-27 04:51:36 +0000271def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000272 "chd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000273 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000274
Scott Michel0718cd82008-12-01 17:56:02 +0000275def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000276 "chx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000277 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000278
Scott Michel06eabde2008-12-27 04:51:36 +0000279def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000280 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000281 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000282
Scott Michel0718cd82008-12-01 17:56:02 +0000283def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000284 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000285 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000286
Scott Michel06eabde2008-12-27 04:51:36 +0000287def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000288 "cwd\t$rT, $src", ShuffleOp,
289 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
290
291def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000292 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000293 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000294
Scott Michel06eabde2008-12-27 04:51:36 +0000295def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000296 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000297 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000298
Scott Michel0718cd82008-12-01 17:56:02 +0000299def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000300 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000301 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000302
Scott Michel06eabde2008-12-27 04:51:36 +0000303def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000304 "cdd\t$rT, $src", ShuffleOp,
305 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
306
307def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000308 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000309 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000310
Scott Michel8b6b4202007-12-04 22:35:58 +0000311//===----------------------------------------------------------------------===//
312// Constant formation:
313//===----------------------------------------------------------------------===//
314
315def ILHv8i16:
316 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
317 "ilh\t$rT, $val", ImmLoad,
318 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
319
320def ILHr16:
321 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
322 "ilh\t$rT, $val", ImmLoad,
323 [(set R16C:$rT, immSExt16:$val)]>;
324
Scott Michel438be252007-12-17 22:32:34 +0000325// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
326// the right constant")
327def ILHr8:
328 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
329 "ilh\t$rT, $val", ImmLoad,
330 [(set R8C:$rT, immSExt8:$val)]>;
331
Scott Michel8b6b4202007-12-04 22:35:58 +0000332// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000333
Scott Michel6baba072008-03-05 23:02:02 +0000334class ILInst<dag OOL, dag IOL, list<dag> pattern>:
335 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
336 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000337
Scott Michel6baba072008-03-05 23:02:02 +0000338class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
339 ILInst<(outs VECREG:$rT), (ins immtype:$val),
340 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000341
Scott Michel6baba072008-03-05 23:02:02 +0000342class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
343 ILInst<(outs rclass:$rT), (ins immtype:$val),
344 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000345
Scott Michel6baba072008-03-05 23:02:02 +0000346multiclass ImmediateLoad
347{
348 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
349 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000350
Scott Michel6baba072008-03-05 23:02:02 +0000351 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000352
Scott Michel6baba072008-03-05 23:02:02 +0000353 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
354 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
355 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
356 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
357}
Scott Michel8b6b4202007-12-04 22:35:58 +0000358
Scott Michel6baba072008-03-05 23:02:02 +0000359defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000360
Scott Michel6baba072008-03-05 23:02:02 +0000361class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
362 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
363 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000364
Scott Michel6baba072008-03-05 23:02:02 +0000365class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
366 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
367 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
368
369class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
370 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
371 [(set rclass:$rT, xform:$val)]>;
372
373multiclass ImmLoadHalfwordUpper
374{
375 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000376 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000377
378 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000379 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000380
381 // Loads the high portion of an address
382 def hi: ILHURegInst<R32C, symbolHi, hi16>;
383
384 // Used in custom lowering constant SFP loads:
385 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
386}
387
388defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000389
390// Immediate load address (can also be used to load 18-bit unsigned constants,
391// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000392
Scott Michel97872d32008-02-23 18:41:37 +0000393class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
394 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
395 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000396
Scott Michel6baba072008-03-05 23:02:02 +0000397class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
398 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
399 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
400
401class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
402 ILAInst<(outs rclass:$rT), (ins immtype:$val),
403 [(set rclass:$rT, xform:$val)]>;
404
Scott Michel97872d32008-02-23 18:41:37 +0000405multiclass ImmLoadAddress
406{
Scott Michel6baba072008-03-05 23:02:02 +0000407 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
408 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000409
Scott Michel6baba072008-03-05 23:02:02 +0000410 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
411 def r32: ILARegInst<R32C, u18imm, imm18>;
412 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
413 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000414
Scott Michel06eabde2008-12-27 04:51:36 +0000415 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michel6baba072008-03-05 23:02:02 +0000416 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000417
Scott Michel97872d32008-02-23 18:41:37 +0000418 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
419 [/* no pattern */]>;
420}
421
422defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000423
424// Immediate OR, Halfword Lower: The "other" part of loading large constants
425// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
426// Note that these are really two operand instructions, but they're encoded
427// as three operands with the first two arguments tied-to each other.
428
Scott Michel6baba072008-03-05 23:02:02 +0000429class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
430 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
431 ImmLoad, pattern>,
432 RegConstraint<"$rS = $rT">,
433 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000434
Scott Michel6baba072008-03-05 23:02:02 +0000435class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
436 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
437 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000438
Scott Michel6baba072008-03-05 23:02:02 +0000439class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
440 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
441 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000442
Scott Michel6baba072008-03-05 23:02:02 +0000443multiclass ImmOrHalfwordLower
444{
445 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000446 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000447
448 def r32: IOHLRegInst<R32C, i32imm>;
449 def f32: IOHLRegInst<R32FP, f32imm>;
450
451 def lo: IOHLRegInst<R32C, symbolLo>;
452}
453
454defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000455
Scott Michel8b6b4202007-12-04 22:35:58 +0000456// Form select mask for bytes using immediate, used in conjunction with the
457// SELB instruction:
458
Scott Michel6baba072008-03-05 23:02:02 +0000459class FSMBIVec<ValueType vectype>:
460 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
461 "fsmbi\t$rT, $val",
462 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000463 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000464
Scott Michel97872d32008-02-23 18:41:37 +0000465multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000466{
467 def v16i8: FSMBIVec<v16i8>;
468 def v8i16: FSMBIVec<v8i16>;
469 def v4i32: FSMBIVec<v4i32>;
470 def v2i64: FSMBIVec<v2i64>;
471}
Scott Michel8b6b4202007-12-04 22:35:58 +0000472
Scott Michel97872d32008-02-23 18:41:37 +0000473defm FSMBI : FormSelectMaskBytesImm;
474
475// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michel06eabde2008-12-27 04:51:36 +0000476class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
477 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
478 pattern>;
479
480class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
481 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
482 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
483
484class FSMBVecInst<ValueType vectype>:
485 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
486 [(set (vectype VECREG:$rT),
487 (SPUselmask (vectype VECREG:$rA)))]>;
488
489multiclass FormSelectMaskBits {
490 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
491 def v16i8: FSMBVecInst<v16i8>;
492}
493
494defm FSMB: FormSelectMaskBits;
Scott Michel97872d32008-02-23 18:41:37 +0000495
496// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
497// only 8-bits wide (even though it's input as 16-bits here)
Scott Michel06eabde2008-12-27 04:51:36 +0000498
499class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
500 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
501 pattern>;
502
503class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
504 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
505 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
506
507class FSMHVecInst<ValueType vectype>:
508 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
509 [(set (vectype VECREG:$rT),
510 (SPUselmask (vectype VECREG:$rA)))]>;
511
512multiclass FormSelectMaskHalfword {
513 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
514 def v8i16: FSMHVecInst<v8i16>;
515}
516
517defm FSMH: FormSelectMaskHalfword;
Scott Michel97872d32008-02-23 18:41:37 +0000518
519// fsm: Form select mask for words. Like the other fsm* instructions,
520// only the lower 4 bits of $rA are significant.
Scott Michel06eabde2008-12-27 04:51:36 +0000521
522class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
523 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
524 pattern>;
525
526class FSMRegInst<ValueType vectype, RegisterClass rclass>:
527 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
528 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
529
530class FSMVecInst<ValueType vectype>:
531 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
532 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel67224b22008-06-02 22:18:03 +0000533
534multiclass FormSelectMaskWord {
Scott Michel06eabde2008-12-27 04:51:36 +0000535 def v4i32: FSMVecInst<v4i32>;
536
537 def r32 : FSMRegInst<v4i32, R32C>;
538 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000539}
540
541defm FSM : FormSelectMaskWord;
542
543// Special case when used for i64 math operations
544multiclass FormSelectMaskWord64 {
Scott Michel06eabde2008-12-27 04:51:36 +0000545 def r32 : FSMRegInst<v2i64, R32C>;
546 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000547}
548
549defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000550
551//===----------------------------------------------------------------------===//
552// Integer and Logical Operations:
553//===----------------------------------------------------------------------===//
554
555def AHv8i16:
556 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
557 "ah\t$rT, $rA, $rB", IntegerOp,
558 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
559
560def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
561 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
562
Scott Michel8b6b4202007-12-04 22:35:58 +0000563def AHr16:
564 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
565 "ah\t$rT, $rA, $rB", IntegerOp,
566 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
567
568def AHIvec:
569 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
570 "ahi\t$rT, $rA, $val", IntegerOp,
571 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
572 v8i16SExt10Imm:$val))]>;
573
Scott Michel97872d32008-02-23 18:41:37 +0000574def AHIr16:
575 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
576 "ahi\t$rT, $rA, $val", IntegerOp,
Scott Michel4d07fb72008-12-30 23:28:25 +0000577 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
578
579// v4i32, i32 add instruction:
Scott Michel8b6b4202007-12-04 22:35:58 +0000580
Scott Michelae5cbf52008-12-29 03:23:36 +0000581class AInst<dag OOL, dag IOL, list<dag> pattern>:
582 RRForm<0b00000011000, OOL, IOL,
583 "a\t$rT, $rA, $rB", IntegerOp,
584 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000585
Scott Michelae5cbf52008-12-29 03:23:36 +0000586class AVecInst<ValueType vectype>:
587 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
588 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
589 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000590
Scott Michelae5cbf52008-12-29 03:23:36 +0000591class ARegInst<RegisterClass rclass>:
592 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
593 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
594
595multiclass AddInstruction {
596 def v4i32: AVecInst<v4i32>;
597 def v16i8: AVecInst<v16i8>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000598 def r32: ARegInst<R32C>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000599}
Scott Michel8b6b4202007-12-04 22:35:58 +0000600
Scott Michelae5cbf52008-12-29 03:23:36 +0000601defm A : AddInstruction;
Scott Michel438be252007-12-17 22:32:34 +0000602
Scott Michel4d07fb72008-12-30 23:28:25 +0000603class AIInst<dag OOL, dag IOL, list<dag> pattern>:
604 RI10Form<0b00111000, OOL, IOL,
pingbakb8913342009-01-26 03:37:41 +0000605 "ai\t$rT, $rA, $val", IntegerOp,
606 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000607
Scott Michel4d07fb72008-12-30 23:28:25 +0000608class AIVecInst<ValueType vectype, PatLeaf immpred>:
609 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
pingbakb8913342009-01-26 03:37:41 +0000610 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000611
612class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
613 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
pingbakb8913342009-01-26 03:37:41 +0000614 [/* no pattern */]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000615
616class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
617 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +0000618 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000619
620// This is used to add epsilons to floating point numbers in the f32 fdiv code:
621class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
622 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +0000623 [/* no pattern */]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000624
625multiclass AddImmediate {
626 def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
627
628 def r32: AIRegInst<R32C, i32ImmSExt10>;
629
630 def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
631 def f32: AIFPInst<R32FP, i32ImmSExt10>;
632}
633
634defm AI : AddImmediate;
Scott Michel8b6b4202007-12-04 22:35:58 +0000635
Scott Michel438be252007-12-17 22:32:34 +0000636def SFHvec:
637 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
638 "sfh\t$rT, $rA, $rB", IntegerOp,
639 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
640 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000641
Scott Michel438be252007-12-17 22:32:34 +0000642def SFHr16:
643 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
644 "sfh\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskilab2e65212010-05-10 08:13:49 +0000645 [(set R16C:$rT, (sub R16C:$rB, R16C:$rA))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000646
647def SFHIvec:
648 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
649 "sfhi\t$rT, $rA, $val", IntegerOp,
650 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
651 (v8i16 VECREG:$rA)))]>;
652
653def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
654 "sfhi\t$rT, $rA, $val", IntegerOp,
655 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
656
657def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
658 (ins VECREG:$rA, VECREG:$rB),
659 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskilab2e65212010-05-10 08:13:49 +0000660 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rB), (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000661
Kalle Raiskila602375b2010-08-02 08:54:39 +0000662
Scott Michel8b6b4202007-12-04 22:35:58 +0000663def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
664 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskilab2e65212010-05-10 08:13:49 +0000665 [(set R32C:$rT, (sub R32C:$rB, R32C:$rA))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000666
667def SFIvec:
668 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
669 "sfi\t$rT, $rA, $val", IntegerOp,
670 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
671 (v4i32 VECREG:$rA)))]>;
672
673def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
674 (ins R32C:$rA, s10imm_i32:$val),
675 "sfi\t$rT, $rA, $val", IntegerOp,
676 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
677
678// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000679class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
680 RRForm<0b00000010110, OOL, IOL,
681 "addx\t$rT, $rA, $rB",
682 IntegerOp, pattern>;
683
684class ADDXVecInst<ValueType vectype>:
685 ADDXInst<(outs VECREG:$rT),
686 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000687 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000688 RegConstraint<"$rCarry = $rT">,
689 NoEncode<"$rCarry">;
690
Scott Michel67224b22008-06-02 22:18:03 +0000691class ADDXRegInst<RegisterClass rclass>:
692 ADDXInst<(outs rclass:$rT),
693 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000694 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000695 RegConstraint<"$rCarry = $rT">,
696 NoEncode<"$rCarry">;
697
Scott Michel67224b22008-06-02 22:18:03 +0000698multiclass AddExtended {
699 def v2i64 : ADDXVecInst<v2i64>;
700 def v4i32 : ADDXVecInst<v4i32>;
701 def r64 : ADDXRegInst<R64C>;
702 def r32 : ADDXRegInst<R32C>;
703}
704
705defm ADDX : AddExtended;
706
707// CG: Generate carry for add
708class CGInst<dag OOL, dag IOL, list<dag> pattern>:
709 RRForm<0b01000011000, OOL, IOL,
710 "cg\t$rT, $rA, $rB",
711 IntegerOp, pattern>;
712
713class CGVecInst<ValueType vectype>:
714 CGInst<(outs VECREG:$rT),
715 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000716 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000717
718class CGRegInst<RegisterClass rclass>:
719 CGInst<(outs rclass:$rT),
720 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000721 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000722
723multiclass CarryGenerate {
724 def v2i64 : CGVecInst<v2i64>;
725 def v4i32 : CGVecInst<v4i32>;
726 def r64 : CGRegInst<R64C>;
727 def r32 : CGRegInst<R32C>;
728}
729
730defm CG : CarryGenerate;
731
732// SFX: Subract from, extended. This is used in conjunction with BG to subtract
733// with carry (borrow, in this case)
734class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
735 RRForm<0b10000010110, OOL, IOL,
736 "sfx\t$rT, $rA, $rB",
737 IntegerOp, pattern>;
738
739class SFXVecInst<ValueType vectype>:
740 SFXInst<(outs VECREG:$rT),
741 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000742 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000743 RegConstraint<"$rCarry = $rT">,
744 NoEncode<"$rCarry">;
745
Scott Michel67224b22008-06-02 22:18:03 +0000746class SFXRegInst<RegisterClass rclass>:
747 SFXInst<(outs rclass:$rT),
748 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000749 [/* no pattern */]>,
Scott Michel67224b22008-06-02 22:18:03 +0000750 RegConstraint<"$rCarry = $rT">,
751 NoEncode<"$rCarry">;
752
753multiclass SubtractExtended {
754 def v2i64 : SFXVecInst<v2i64>;
755 def v4i32 : SFXVecInst<v4i32>;
756 def r64 : SFXRegInst<R64C>;
757 def r32 : SFXRegInst<R32C>;
758}
759
760defm SFX : SubtractExtended;
761
Scott Michel8b6b4202007-12-04 22:35:58 +0000762// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000763class BGInst<dag OOL, dag IOL, list<dag> pattern>:
764 RRForm<0b01000010000, OOL, IOL,
765 "bg\t$rT, $rA, $rB",
766 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000767
Scott Michel67224b22008-06-02 22:18:03 +0000768class BGVecInst<ValueType vectype>:
769 BGInst<(outs VECREG:$rT),
770 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000771 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000772
773class BGRegInst<RegisterClass rclass>:
774 BGInst<(outs rclass:$rT),
775 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000776 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000777
778multiclass BorrowGenerate {
779 def v4i32 : BGVecInst<v4i32>;
780 def v2i64 : BGVecInst<v2i64>;
781 def r64 : BGRegInst<R64C>;
782 def r32 : BGRegInst<R32C>;
783}
784
785defm BG : BorrowGenerate;
786
787// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000788def BGXvec:
789 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000790 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000791 "bgx\t$rT, $rA, $rB", IntegerOp,
792 []>,
793 RegConstraint<"$rCarry = $rT">,
794 NoEncode<"$rCarry">;
795
796// Halfword multiply variants:
797// N.B: These can be used to build up larger quantities (16x16 -> 32)
798
799def MPYv8i16:
800 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
801 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000802 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000803
804def MPYr16:
805 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
806 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
807 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
808
Scott Michelae5cbf52008-12-29 03:23:36 +0000809// Unsigned 16-bit multiply:
810
811class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
812 RRForm<0b00110011110, OOL, IOL,
813 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
814 pattern>;
815
Scott Michel8b6b4202007-12-04 22:35:58 +0000816def MPYUv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000817 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000818 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000819
820def MPYUr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000821 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
822 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000823
824def MPYUr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000825 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000826 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000827
Scott Michelae5cbf52008-12-29 03:23:36 +0000828// mpyi: multiply 16 x s10imm -> 32 result.
829
830class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
831 RI10Form<0b00101110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000832 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000833 pattern>;
834
835def MPYIvec:
836 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
837 [(set (v8i16 VECREG:$rT),
838 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000839
840def MPYIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000841 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
842 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000843
844// mpyui: same issues as other multiplies, plus, this doesn't match a
845// pattern... but may be used during target DAG selection or lowering
Scott Michelae5cbf52008-12-29 03:23:36 +0000846
847class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
848 RI10Form<0b10101110, OOL, IOL,
849 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
850 pattern>;
851
Scott Michel8b6b4202007-12-04 22:35:58 +0000852def MPYUIvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000853 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
854 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000855
856def MPYUIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000857 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
858 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000859
860// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michelae5cbf52008-12-29 03:23:36 +0000861class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
862 RRRForm<0b0011, OOL, IOL,
863 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
864 pattern>;
865
Scott Michel750b93f2009-01-15 04:41:47 +0000866def MPYAv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000867 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
868 [(set (v4i32 VECREG:$rT),
869 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
870 (v8i16 VECREG:$rB)))),
871 (v4i32 VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000872
873def MPYAr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000874 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
875 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
876 R32C:$rC))]>;
877
878def MPYAr32_sext:
879 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
880 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
881 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000882
883def MPYAr32_sextinreg:
Scott Michelae5cbf52008-12-29 03:23:36 +0000884 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
885 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
886 (sext_inreg R32C:$rB, i16)),
887 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000888
889// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michelae5cbf52008-12-29 03:23:36 +0000890class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
891 RRForm<0b10100011110, OOL, IOL,
892 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
893 pattern>;
894
Scott Michel8b6b4202007-12-04 22:35:58 +0000895def MPYHv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000896 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000897 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000898
899def MPYHr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000900 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000901 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000902
903// mpys: multiply high and shift right (returns the top half of
904// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000905
Scott Michel4d07fb72008-12-30 23:28:25 +0000906class MPYSInst<dag OOL, dag IOL>:
907 RRForm<0b11100011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000908 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000909 [/* no pattern */]>;
910
Scott Michel750b93f2009-01-15 04:41:47 +0000911def MPYSv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000912 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
913
914def MPYSr16:
915 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000916
917// mpyhh: multiply high-high (returns the 32-bit result from multiplying
918// the top 16 bits of the $rA, $rB)
Scott Michel4d07fb72008-12-30 23:28:25 +0000919
920class MPYHHInst<dag OOL, dag IOL>:
921 RRForm<0b01100011110, OOL, IOL,
922 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
923 [/* no pattern */]>;
924
Scott Michel8b6b4202007-12-04 22:35:58 +0000925def MPYHHv8i16:
Scott Michel4d07fb72008-12-30 23:28:25 +0000926 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000927
928def MPYHHr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000929 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000930
931// mpyhha: Multiply high-high, add to $rT:
Scott Michel8b6b4202007-12-04 22:35:58 +0000932
Scott Michel4d07fb72008-12-30 23:28:25 +0000933class MPYHHAInst<dag OOL, dag IOL>:
934 RRForm<0b01100010110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000935 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000936 [/* no pattern */]>;
937
938def MPYHHAvec:
939 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
940
941def MPYHHAr32:
942 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000943
Scott Michel750b93f2009-01-15 04:41:47 +0000944// mpyhhu: Multiply high-high, unsigned, e.g.:
945//
946// +-------+-------+ +-------+-------+ +---------+
947// | a0 . a1 | x | b0 . b1 | = | a0 x b0 |
948// +-------+-------+ +-------+-------+ +---------+
949//
950// where a0, b0 are the upper 16 bits of the 32-bit word
Scott Michel8b6b4202007-12-04 22:35:58 +0000951
Scott Michel4d07fb72008-12-30 23:28:25 +0000952class MPYHHUInst<dag OOL, dag IOL>:
953 RRForm<0b01110011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000954 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000955 [/* no pattern */]>;
956
Scott Michel750b93f2009-01-15 04:41:47 +0000957def MPYHHUv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000958 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
959
960def MPYHHUr32:
961 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000962
963// mpyhhau: Multiply high-high, unsigned
Scott Michel4d07fb72008-12-30 23:28:25 +0000964
965class MPYHHAUInst<dag OOL, dag IOL>:
966 RRForm<0b01110010110, OOL, IOL,
967 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
968 [/* no pattern */]>;
969
Scott Michel8b6b4202007-12-04 22:35:58 +0000970def MPYHHAUvec:
Scott Michel4d07fb72008-12-30 23:28:25 +0000971 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
972
Scott Michel8b6b4202007-12-04 22:35:58 +0000973def MPYHHAUr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000974 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000975
976//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +0000977// clz: Count leading zeroes
Scott Michelae5cbf52008-12-29 03:23:36 +0000978//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel06eabde2008-12-27 04:51:36 +0000979class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
980 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
981 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000982
Scott Michel06eabde2008-12-27 04:51:36 +0000983class CLZRegInst<RegisterClass rclass>:
984 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel4d07fb72008-12-30 23:28:25 +0000985 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michel06eabde2008-12-27 04:51:36 +0000986
987class CLZVecInst<ValueType vectype>:
988 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
989 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
990
991multiclass CountLeadingZeroes {
992 def v4i32 : CLZVecInst<v4i32>;
993 def r32 : CLZRegInst<R32C>;
994}
995
996defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +0000997
998// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +0000999//
Scott Michel8b6b4202007-12-04 22:35:58 +00001000// NOTE: This instruction is really a vector instruction, but the custom
1001// lowering code uses it in unorthodox ways to support CTPOP for other
1002// data types!
Scott Michel06eabde2008-12-27 04:51:36 +00001003
Scott Michel8b6b4202007-12-04 22:35:58 +00001004def CNTBv16i8:
1005 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1006 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001007 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001008
1009def CNTBv8i16 :
1010 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1011 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001012 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001013
1014def CNTBv4i32 :
1015 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1016 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001017 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001018
Scott Michel06eabde2008-12-27 04:51:36 +00001019// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1020// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1021// slots 1-3.
1022//
1023// Note: This instruction "pairs" with the fsmb instruction for all of the
1024// various types defined here.
1025//
1026// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1027// a vector or register.
1028
1029class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1030 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1031
1032class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1033 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001034 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001035
1036class GBBVecInst<ValueType vectype>:
1037 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001038 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001039
1040multiclass GatherBitsFromBytes {
1041 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1042 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1043 def v16i8: GBBVecInst<v16i8>;
1044}
1045
1046defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001047
1048// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001049// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1050// and slots 1-3 also set to 0.
1051//
1052// See notes for GBBInst, above.
1053
1054class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1055 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1056 pattern>;
1057
1058class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1059 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001060 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001061
1062class GBHVecInst<ValueType vectype>:
1063 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001064 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001065
1066multiclass GatherBitsHalfword {
1067 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1068 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1069 def v8i16: GBHVecInst<v8i16>;
1070}
1071
1072defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001073
1074// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001075// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1076// as well as slots 1-3.
1077//
1078// See notes for gbb, above.
1079
1080class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1081 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1082 pattern>;
1083
1084class GBRegInst<RegisterClass rclass, ValueType vectype>:
1085 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001086 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001087
1088class GBVecInst<ValueType vectype>:
1089 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001090 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001091
1092multiclass GatherBitsWord {
1093 def v4i32_r32: GBRegInst<R32C, v4i32>;
1094 def v4i32_r16: GBRegInst<R16C, v4i32>;
1095 def v4i32: GBVecInst<v4i32>;
1096}
1097
1098defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001099
1100// avgb: average bytes
1101def AVGB:
1102 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1103 "avgb\t$rT, $rA, $rB", ByteOp,
1104 []>;
1105
1106// absdb: absolute difference of bytes
1107def ABSDB:
1108 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1109 "absdb\t$rT, $rA, $rB", ByteOp,
1110 []>;
1111
1112// sumb: sum bytes into halfwords
1113def SUMB:
1114 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1115 "sumb\t$rT, $rA, $rB", ByteOp,
1116 []>;
1117
1118// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001119class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1120 RRForm_1<0b01101101010, OOL, IOL,
1121 "xsbh\t$rDst, $rSrc",
1122 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001123
Scott Michel2ef773a2009-01-06 03:36:14 +00001124class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel67224b22008-06-02 22:18:03 +00001125 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Michel2ef773a2009-01-06 03:36:14 +00001126 pattern>;
Scott Michel67224b22008-06-02 22:18:03 +00001127
1128multiclass ExtendByteHalfword {
Chris Lattnera5c69832010-03-19 04:53:47 +00001129 def v16i8: XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1130 [
1131 /*(set (v8i16 VECREG:$rDst), (sext (v8i16 VECREG:$rSrc)))*/]>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001132 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1133 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1134 def r16: XSBHInRegInst<R16C,
1135 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001136
1137 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1138 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1139 // pattern below). Intentionally doesn't match a pattern because we want the
1140 // sext 8->32 pattern to do the work for us, namely because we need the extra
1141 // XSHWr32.
Scott Michel2ef773a2009-01-06 03:36:14 +00001142 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1143
1144 // Same as the 32-bit version, but for i64
1145 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +00001146}
1147
1148defm XSBH : ExtendByteHalfword;
1149
Scott Michel8b6b4202007-12-04 22:35:58 +00001150// Sign extend halfwords to words:
Scott Michel8b6b4202007-12-04 22:35:58 +00001151
Scott Michel2ef773a2009-01-06 03:36:14 +00001152class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1153 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1154 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001155
Scott Michel2ef773a2009-01-06 03:36:14 +00001156class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1157 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1158 [(set (out_vectype VECREG:$rDest),
1159 (sext (in_vectype VECREG:$rSrc)))]>;
1160
1161class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1162 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1163 pattern>;
1164
1165class XSHWRegInst<RegisterClass rclass>:
1166 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1167 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1168
1169multiclass ExtendHalfwordWord {
1170 def v4i32: XSHWVecInst<v4i32, v8i16>;
1171
1172 def r16: XSHWRegInst<R32C>;
1173
1174 def r32: XSHWInRegInst<R32C,
1175 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1176 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1177}
1178
1179defm XSHW : ExtendHalfwordWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001180
Scott Michele0168c12009-01-05 01:34:35 +00001181// Sign-extend words to doublewords (32->64 bits)
Scott Michel8b6b4202007-12-04 22:35:58 +00001182
Scott Michele0168c12009-01-05 01:34:35 +00001183class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel2ef773a2009-01-06 03:36:14 +00001184 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1185 IntegerOp, pattern>;
Scott Michele0168c12009-01-05 01:34:35 +00001186
1187class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1188 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
Chris Lattnera5c69832010-03-19 04:53:47 +00001189 [/*(set (out_vectype VECREG:$rDst),
1190 (sext (out_vectype VECREG:$rSrc)))*/]>;
Scott Michele0168c12009-01-05 01:34:35 +00001191
1192class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1193 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1194 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1195
1196multiclass ExtendWordToDoubleWord {
1197 def v2i64: XSWDVecInst<v4i32, v2i64>;
1198 def r64: XSWDRegInst<R32C, R64C>;
1199
1200 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1201 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1202}
Scott Michel8b6b4202007-12-04 22:35:58 +00001203
Scott Michele0168c12009-01-05 01:34:35 +00001204defm XSWD : ExtendWordToDoubleWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001205
1206// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001207
Scott Michel97872d32008-02-23 18:41:37 +00001208class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1209 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1210 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001211
Scott Michel97872d32008-02-23 18:41:37 +00001212class ANDVecInst<ValueType vectype>:
1213 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1214 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1215 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001216
Scott Michel6baba072008-03-05 23:02:02 +00001217class ANDRegInst<RegisterClass rclass>:
1218 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1219 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1220
Scott Michel97872d32008-02-23 18:41:37 +00001221multiclass BitwiseAnd
1222{
1223 def v16i8: ANDVecInst<v16i8>;
1224 def v8i16: ANDVecInst<v8i16>;
1225 def v4i32: ANDVecInst<v4i32>;
1226 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001227
Scott Michel6baba072008-03-05 23:02:02 +00001228 def r128: ANDRegInst<GPRC>;
1229 def r64: ANDRegInst<R64C>;
1230 def r32: ANDRegInst<R32C>;
1231 def r16: ANDRegInst<R16C>;
1232 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001233
Scott Michel97872d32008-02-23 18:41:37 +00001234 //===---------------------------------------------
1235 // Special instructions to perform the fabs instruction
1236 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1237 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001238
Scott Michel0d5eae02009-03-17 01:15:45 +00001239 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
pingbak2f387e82009-01-26 03:31:40 +00001240 [/* Intentionally does not match a pattern */]>;
1241
Scott Michel97872d32008-02-23 18:41:37 +00001242 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1243 [/* Intentionally does not match a pattern */]>;
1244
1245 //===---------------------------------------------
1246
1247 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1248 // quantities -- see 16->32 zext pattern.
1249 //
1250 // This pattern is somewhat artificial, since it might match some
1251 // compiler generated pattern but it is unlikely to do so.
1252
1253 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1254 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1255}
1256
1257defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001258
Chris Lattnerfe29aee2010-03-28 07:48:17 +00001259
1260def vnot_cell_conv : PatFrag<(ops node:$in),
1261 (xor node:$in, (bitconvert (v4i32 immAllOnesV)))>;
1262
1263// N.B.: vnot_cell_conv is one of those special target selection pattern
1264// fragments,
Scott Michel8b6b4202007-12-04 22:35:58 +00001265// in which we expect there to be a bit_convert on the constant. Bear in mind
1266// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1267// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001268
Scott Michel97872d32008-02-23 18:41:37 +00001269class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1270 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1271 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001272
Scott Michel0d5eae02009-03-17 01:15:45 +00001273class ANDCVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michel97872d32008-02-23 18:41:37 +00001274 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel0d5eae02009-03-17 01:15:45 +00001275 [(set (vectype VECREG:$rT),
1276 (and (vectype VECREG:$rA),
1277 (vnot_frag (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001278
Scott Michel97872d32008-02-23 18:41:37 +00001279class ANDCRegInst<RegisterClass rclass>:
1280 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1281 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001282
Scott Michel97872d32008-02-23 18:41:37 +00001283multiclass AndComplement
1284{
1285 def v16i8: ANDCVecInst<v16i8>;
1286 def v8i16: ANDCVecInst<v8i16>;
1287 def v4i32: ANDCVecInst<v4i32>;
1288 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001289
Scott Michel97872d32008-02-23 18:41:37 +00001290 def r128: ANDCRegInst<GPRC>;
1291 def r64: ANDCRegInst<R64C>;
1292 def r32: ANDCRegInst<R32C>;
1293 def r16: ANDCRegInst<R16C>;
1294 def r8: ANDCRegInst<R8C>;
Scott Michel0d5eae02009-03-17 01:15:45 +00001295
1296 // Sometimes, the xor pattern has a bitcast constant:
Chris Lattnerfe29aee2010-03-28 07:48:17 +00001297 def v16i8_conv: ANDCVecInst<v16i8, vnot_cell_conv>;
Scott Michel97872d32008-02-23 18:41:37 +00001298}
Scott Michel438be252007-12-17 22:32:34 +00001299
Scott Michel97872d32008-02-23 18:41:37 +00001300defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001301
Scott Michel97872d32008-02-23 18:41:37 +00001302class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1303 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001304 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001305
Scott Michel97872d32008-02-23 18:41:37 +00001306multiclass AndByteImm
1307{
1308 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1309 [(set (v16i8 VECREG:$rT),
1310 (and (v16i8 VECREG:$rA),
1311 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001312
Scott Michel97872d32008-02-23 18:41:37 +00001313 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1314 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1315}
Scott Michel438be252007-12-17 22:32:34 +00001316
Scott Michel97872d32008-02-23 18:41:37 +00001317defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001318
Scott Michel97872d32008-02-23 18:41:37 +00001319class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1320 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001321 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001322
Scott Michel97872d32008-02-23 18:41:37 +00001323multiclass AndHalfwordImm
1324{
1325 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1326 [(set (v8i16 VECREG:$rT),
1327 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001328
Scott Michel97872d32008-02-23 18:41:37 +00001329 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1330 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001331
Scott Michel97872d32008-02-23 18:41:37 +00001332 // Zero-extend i8 to i16:
1333 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1334 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1335}
Scott Michel8b6b4202007-12-04 22:35:58 +00001336
Scott Michel97872d32008-02-23 18:41:37 +00001337defm ANDHI : AndHalfwordImm;
1338
1339class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1340 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1341 IntegerOp, pattern>;
1342
1343multiclass AndWordImm
1344{
1345 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1346 [(set (v4i32 VECREG:$rT),
1347 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1348
1349 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1350 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1351
1352 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1353 // pattern below.
1354 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1355 [(set R32C:$rT,
1356 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1357
1358 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1359 // zext 16->32 pattern below.
1360 //
1361 // Note that this pattern is somewhat artificial, since it might match
1362 // something the compiler generates but is unlikely to occur in practice.
1363 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1364 [(set R32C:$rT,
1365 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1366}
1367
1368defm ANDI : AndWordImm;
1369
1370//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001371// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001372//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1373
Scott Michel8b6b4202007-12-04 22:35:58 +00001374// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001375class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1376 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1377 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001378
Scott Michel97872d32008-02-23 18:41:37 +00001379class ORVecInst<ValueType vectype>:
1380 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1381 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1382 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001383
Scott Michel97872d32008-02-23 18:41:37 +00001384class ORRegInst<RegisterClass rclass>:
1385 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1386 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001387
Scott Michel06eabde2008-12-27 04:51:36 +00001388// ORCvtForm: OR conversion form
1389//
1390// This is used to "convert" the preferred slot to its vector equivalent, as
1391// well as convert a vector back to its preferred slot.
1392//
1393// These are effectively no-ops, but need to exist for proper type conversion
1394// and type coercion.
1395
Scott Michel8c67fa42009-01-21 04:58:48 +00001396class ORCvtForm<dag OOL, dag IOL, list<dag> pattern = [/* no pattern */]>
Scott Michel06eabde2008-12-27 04:51:36 +00001397 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1398 bits<7> RA;
1399 bits<7> RT;
1400
Scott Michel8c67fa42009-01-21 04:58:48 +00001401 let Pattern = pattern;
Scott Michel06eabde2008-12-27 04:51:36 +00001402
1403 let Inst{0-10} = 0b10000010000;
1404 let Inst{11-17} = RA;
1405 let Inst{18-24} = RA;
1406 let Inst{25-31} = RT;
1407}
1408
Scott Michel97872d32008-02-23 18:41:37 +00001409class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001410 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001411
Scott Michel97872d32008-02-23 18:41:37 +00001412class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001413 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1414
Scott Michel8c67fa42009-01-21 04:58:48 +00001415/* class ORCvtRegGPRC<RegisterClass rclass>:
1416 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>; */
Scott Michel06eabde2008-12-27 04:51:36 +00001417
Scott Michel8c67fa42009-01-21 04:58:48 +00001418/* class ORCvtGPRCReg<RegisterClass rclass>:
1419 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>; */
Scott Michel2ef773a2009-01-06 03:36:14 +00001420
Scott Michel8c67fa42009-01-21 04:58:48 +00001421class ORCvtFormR32Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1422 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001423
Scott Michel8c67fa42009-01-21 04:58:48 +00001424class ORCvtFormRegR32<RegisterClass rclass, list<dag> pattern = [ ]>:
1425 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001426
Scott Michel8c67fa42009-01-21 04:58:48 +00001427class ORCvtFormR64Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1428 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001429
Scott Michel8c67fa42009-01-21 04:58:48 +00001430class ORCvtFormRegR64<RegisterClass rclass, list<dag> pattern = [ ]>:
1431 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA), pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00001432
Scott Michel34712c32009-03-16 18:47:25 +00001433class ORCvtGPRCVec:
1434 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
1435
1436class ORCvtVecGPRC:
1437 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001438
Kalle Raiskila53f08782010-08-09 16:33:00 +00001439class ORCvtVecVec:
1440 ORCvtForm<(outs VECREG:$rT), (ins VECREG:$rA)>;
1441
Scott Michel97872d32008-02-23 18:41:37 +00001442multiclass BitwiseOr
1443{
1444 def v16i8: ORVecInst<v16i8>;
1445 def v8i16: ORVecInst<v8i16>;
1446 def v4i32: ORVecInst<v4i32>;
1447 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001448
Scott Michel97872d32008-02-23 18:41:37 +00001449 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1450 [(set (v4f32 VECREG:$rT),
1451 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1452 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001453
Scott Michel97872d32008-02-23 18:41:37 +00001454 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001455 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001456 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1457 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001458
Scott Michel8c67fa42009-01-21 04:58:48 +00001459 def r128: ORRegInst<GPRC>;
1460 def r64: ORRegInst<R64C>;
1461 def r32: ORRegInst<R32C>;
1462 def r16: ORRegInst<R16C>;
1463 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001464
Scott Michel97872d32008-02-23 18:41:37 +00001465 // OR instructions used to copy f32 and f64 registers.
1466 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1467 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001468
Scott Michel97872d32008-02-23 18:41:37 +00001469 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1470 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001471
Scott Michel4d07fb72008-12-30 23:28:25 +00001472 // scalar->vector promotion, prefslot2vec:
Scott Michel97872d32008-02-23 18:41:37 +00001473 def v16i8_i8: ORPromoteScalar<R8C>;
1474 def v8i16_i16: ORPromoteScalar<R16C>;
1475 def v4i32_i32: ORPromoteScalar<R32C>;
1476 def v2i64_i64: ORPromoteScalar<R64C>;
1477 def v4f32_f32: ORPromoteScalar<R32FP>;
1478 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001479
Scott Michel4d07fb72008-12-30 23:28:25 +00001480 // vector->scalar demotion, vec2prefslot:
Scott Michel97872d32008-02-23 18:41:37 +00001481 def i8_v16i8: ORExtractElt<R8C>;
1482 def i16_v8i16: ORExtractElt<R16C>;
1483 def i32_v4i32: ORExtractElt<R32C>;
1484 def i64_v2i64: ORExtractElt<R64C>;
1485 def f32_v4f32: ORExtractElt<R32FP>;
1486 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001487
Scott Michel34712c32009-03-16 18:47:25 +00001488 // Conversion from vector to GPRC
1489 def i128_vec: ORCvtVecGPRC;
1490
1491 // Conversion from GPRC to vector
1492 def vec_i128: ORCvtGPRCVec;
1493
Scott Michel8c67fa42009-01-21 04:58:48 +00001494/*
Scott Michel34712c32009-03-16 18:47:25 +00001495 // Conversion from register to GPRC
Scott Michel06eabde2008-12-27 04:51:36 +00001496 def i128_r64: ORCvtRegGPRC<R64C>;
1497 def i128_f64: ORCvtRegGPRC<R64FP>;
1498 def i128_r32: ORCvtRegGPRC<R32C>;
1499 def i128_f32: ORCvtRegGPRC<R32FP>;
1500 def i128_r16: ORCvtRegGPRC<R16C>;
1501 def i128_r8: ORCvtRegGPRC<R8C>;
1502
Scott Michel34712c32009-03-16 18:47:25 +00001503 // Conversion from GPRC to register
Scott Michel06eabde2008-12-27 04:51:36 +00001504 def r64_i128: ORCvtGPRCReg<R64C>;
1505 def f64_i128: ORCvtGPRCReg<R64FP>;
1506 def r32_i128: ORCvtGPRCReg<R32C>;
1507 def f32_i128: ORCvtGPRCReg<R32FP>;
1508 def r16_i128: ORCvtGPRCReg<R16C>;
1509 def r8_i128: ORCvtGPRCReg<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001510*/
1511/*
Scott Michel2ef773a2009-01-06 03:36:14 +00001512 // Conversion from register to R32C:
Scott Michel34712c32009-03-16 18:47:25 +00001513 def r32_r16: ORCvtFormRegR32<R16C>;
1514 def r32_r8: ORCvtFormRegR32<R8C>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001515
1516 // Conversion from R32C to register
1517 def r32_r16: ORCvtFormR32Reg<R16C>;
1518 def r32_r8: ORCvtFormR32Reg<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001519*/
pingbak2f387e82009-01-26 03:31:40 +00001520
Scott Michel34712c32009-03-16 18:47:25 +00001521 // Conversion from R64C to register:
pingbak2f387e82009-01-26 03:31:40 +00001522 def r32_r64: ORCvtFormR64Reg<R32C>;
1523 // def r16_r64: ORCvtFormR64Reg<R16C>;
1524 // def r8_r64: ORCvtFormR64Reg<R8C>;
1525
Scott Michel34712c32009-03-16 18:47:25 +00001526 // Conversion to R64C from register:
pingbak2f387e82009-01-26 03:31:40 +00001527 def r64_r32: ORCvtFormRegR64<R32C>;
1528 // def r64_r16: ORCvtFormRegR64<R16C>;
1529 // def r64_r8: ORCvtFormRegR64<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001530
1531 // bitconvert patterns:
1532 def r32_f32: ORCvtFormR32Reg<R32FP,
1533 [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1534 def f32_r32: ORCvtFormRegR32<R32FP,
1535 [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1536
1537 def r64_f64: ORCvtFormR64Reg<R64FP,
1538 [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1539 def f64_r64: ORCvtFormRegR64<R64FP,
1540 [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +00001541}
Scott Michel438be252007-12-17 22:32:34 +00001542
Scott Michel97872d32008-02-23 18:41:37 +00001543defm OR : BitwiseOr;
1544
Scott Michel06eabde2008-12-27 04:51:36 +00001545// scalar->vector promotion patterns (preferred slot to vector):
1546def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1547 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001548
Scott Michel06eabde2008-12-27 04:51:36 +00001549def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1550 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001551
Scott Michel06eabde2008-12-27 04:51:36 +00001552def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1553 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001554
Scott Michel06eabde2008-12-27 04:51:36 +00001555def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1556 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001557
Scott Michel06eabde2008-12-27 04:51:36 +00001558def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1559 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001560
Scott Michel06eabde2008-12-27 04:51:36 +00001561def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1562 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001563
Scott Michel06eabde2008-12-27 04:51:36 +00001564// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1565// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001566
Scott Michelc630c412008-11-24 17:11:17 +00001567def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001568 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001569
Scott Michelc630c412008-11-24 17:11:17 +00001570def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001571 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001572
Scott Michelc630c412008-11-24 17:11:17 +00001573def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001574 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001575
Scott Michelc630c412008-11-24 17:11:17 +00001576def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001577 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001578
Scott Michelc630c412008-11-24 17:11:17 +00001579def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001580 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001581
Scott Michelc630c412008-11-24 17:11:17 +00001582def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001583 (ORf64_v2f64 VECREG:$rA)>;
1584
1585// Load Register: This is an assembler alias for a bitwise OR of a register
1586// against itself. It's here because it brings some clarity to assembly
1587// language output.
1588
1589let hasCtrlDep = 1 in {
1590 class LRInst<dag OOL, dag IOL>
1591 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1592 bits<7> RA;
1593 bits<7> RT;
1594
1595 let Pattern = [/*no pattern*/];
1596
1597 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1598 let Inst{11-17} = RA;
1599 let Inst{18-24} = RA;
1600 let Inst{25-31} = RT;
1601 }
1602
1603 class LRVecInst<ValueType vectype>:
1604 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1605
1606 class LRRegInst<RegisterClass rclass>:
1607 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1608
1609 multiclass LoadRegister {
1610 def v2i64: LRVecInst<v2i64>;
1611 def v2f64: LRVecInst<v2f64>;
1612 def v4i32: LRVecInst<v4i32>;
1613 def v4f32: LRVecInst<v4f32>;
1614 def v8i16: LRVecInst<v8i16>;
1615 def v16i8: LRVecInst<v16i8>;
1616
1617 def r128: LRRegInst<GPRC>;
1618 def r64: LRRegInst<R64C>;
1619 def f64: LRRegInst<R64FP>;
1620 def r32: LRRegInst<R32C>;
1621 def f32: LRRegInst<R32FP>;
1622 def r16: LRRegInst<R16C>;
1623 def r8: LRRegInst<R8C>;
1624 }
1625
1626 defm LR: LoadRegister;
1627}
Scott Michel8b6b4202007-12-04 22:35:58 +00001628
Scott Michel97872d32008-02-23 18:41:37 +00001629// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001630
Scott Michel97872d32008-02-23 18:41:37 +00001631class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1632 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1633 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001634
Scott Michel97872d32008-02-23 18:41:37 +00001635class ORCVecInst<ValueType vectype>:
1636 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1637 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1638 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001639
Scott Michel97872d32008-02-23 18:41:37 +00001640class ORCRegInst<RegisterClass rclass>:
1641 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1642 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001643
Scott Michel97872d32008-02-23 18:41:37 +00001644multiclass BitwiseOrComplement
1645{
1646 def v16i8: ORCVecInst<v16i8>;
1647 def v8i16: ORCVecInst<v8i16>;
1648 def v4i32: ORCVecInst<v4i32>;
1649 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001650
Scott Michel34712c32009-03-16 18:47:25 +00001651 def r128: ORCRegInst<GPRC>;
Scott Michel97872d32008-02-23 18:41:37 +00001652 def r64: ORCRegInst<R64C>;
1653 def r32: ORCRegInst<R32C>;
1654 def r16: ORCRegInst<R16C>;
1655 def r8: ORCRegInst<R8C>;
1656}
1657
1658defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001659
Scott Michel8b6b4202007-12-04 22:35:58 +00001660// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001661class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1662 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1663 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001664
Scott Michel97872d32008-02-23 18:41:37 +00001665class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1666 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1667 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1668 (vectype immpred:$val)))]>;
1669
1670multiclass BitwiseOrByteImm
1671{
1672 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1673
1674 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1675 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1676}
1677
1678defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001679
Scott Michel8b6b4202007-12-04 22:35:58 +00001680// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001681class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1682 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1683 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001684
Scott Michel97872d32008-02-23 18:41:37 +00001685class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1686 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1687 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1688 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001689
Scott Michel97872d32008-02-23 18:41:37 +00001690multiclass BitwiseOrHalfwordImm
1691{
1692 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1693
1694 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1695 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1696
1697 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1698 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1699 [(set R16C:$rT, (or (anyext R8C:$rA),
1700 i16ImmSExt10:$val))]>;
1701}
1702
1703defm ORHI : BitwiseOrHalfwordImm;
1704
1705class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1706 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1707 IntegerOp, pattern>;
1708
1709class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1710 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1711 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1712 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001713
1714// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001715multiclass BitwiseOrImm
1716{
1717 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001718
Scott Michel97872d32008-02-23 18:41:37 +00001719 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1720 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001721
Scott Michel97872d32008-02-23 18:41:37 +00001722 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1723 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1724 // infra "anyext 16->32" pattern.)
1725 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1726 [(set R32C:$rT, (or (anyext R16C:$rA),
1727 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001728
Scott Michel97872d32008-02-23 18:41:37 +00001729 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1730 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1731 // infra "anyext 16->32" pattern.)
1732 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1733 [(set R32C:$rT, (or (anyext R8C:$rA),
1734 i32ImmSExt10:$val))]>;
1735}
Scott Michel8b6b4202007-12-04 22:35:58 +00001736
Scott Michel97872d32008-02-23 18:41:37 +00001737defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001738
Scott Michel8b6b4202007-12-04 22:35:58 +00001739// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1740// $rT[0], slots 1-3 are zeroed.
1741//
Scott Michel438be252007-12-17 22:32:34 +00001742// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001743def ORXv4i32:
1744 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1745 "orx\t$rT, $rA, $rB", IntegerOp,
1746 []>;
1747
Scott Michel438be252007-12-17 22:32:34 +00001748// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001749
Scott Michel6baba072008-03-05 23:02:02 +00001750class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1751 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1752 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001753
Scott Michel6baba072008-03-05 23:02:02 +00001754class XORVecInst<ValueType vectype>:
1755 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1756 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1757 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001758
Scott Michel6baba072008-03-05 23:02:02 +00001759class XORRegInst<RegisterClass rclass>:
1760 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1761 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1762
1763multiclass BitwiseExclusiveOr
1764{
1765 def v16i8: XORVecInst<v16i8>;
1766 def v8i16: XORVecInst<v8i16>;
1767 def v4i32: XORVecInst<v4i32>;
1768 def v2i64: XORVecInst<v2i64>;
1769
1770 def r128: XORRegInst<GPRC>;
1771 def r64: XORRegInst<R64C>;
1772 def r32: XORRegInst<R32C>;
1773 def r16: XORRegInst<R16C>;
1774 def r8: XORRegInst<R8C>;
Scott Michele13d8392009-03-17 16:45:16 +00001775
1776 // XOR instructions used to negate f32 and f64 quantities.
1777
1778 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1779 [/* no pattern */]>;
1780
1781 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1782 [/* no pattern */]>;
1783
1784 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1785 [/* no pattern, see fneg{32,64} */]>;
Scott Michel6baba072008-03-05 23:02:02 +00001786}
1787
1788defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001789
1790//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001791
Scott Michel97872d32008-02-23 18:41:37 +00001792class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1793 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1794 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001795
Scott Michel97872d32008-02-23 18:41:37 +00001796multiclass XorByteImm
1797{
1798 def v16i8:
1799 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1800 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1801
1802 def r8:
1803 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1804 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1805}
1806
1807defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001808
Scott Michel8b6b4202007-12-04 22:35:58 +00001809def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001810 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001811 "xorhi\t$rT, $rA, $val", IntegerOp,
1812 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1813 v8i16SExt10Imm:$val))]>;
1814
1815def XORHIr16:
1816 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1817 "xorhi\t$rT, $rA, $val", IntegerOp,
1818 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1819
1820def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001821 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001822 "xori\t$rT, $rA, $val", IntegerOp,
1823 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1824 v4i32SExt10Imm:$val))]>;
1825
1826def XORIr32:
1827 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1828 "xori\t$rT, $rA, $val", IntegerOp,
1829 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1830
1831// NAND:
Scott Michel8b6b4202007-12-04 22:35:58 +00001832
Scott Michel34712c32009-03-16 18:47:25 +00001833class NANDInst<dag OOL, dag IOL, list<dag> pattern>:
1834 RRForm<0b10010011000, OOL, IOL, "nand\t$rT, $rA, $rB",
1835 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001836
Scott Michel34712c32009-03-16 18:47:25 +00001837class NANDVecInst<ValueType vectype>:
1838 NANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1839 [(set (vectype VECREG:$rT), (vnot (and (vectype VECREG:$rA),
1840 (vectype VECREG:$rB))))]>;
1841class NANDRegInst<RegisterClass rclass>:
1842 NANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1843 [(set rclass:$rT, (not (and rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001844
Scott Michel34712c32009-03-16 18:47:25 +00001845multiclass BitwiseNand
1846{
1847 def v16i8: NANDVecInst<v16i8>;
1848 def v8i16: NANDVecInst<v8i16>;
1849 def v4i32: NANDVecInst<v4i32>;
1850 def v2i64: NANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001851
Scott Michel34712c32009-03-16 18:47:25 +00001852 def r128: NANDRegInst<GPRC>;
1853 def r64: NANDRegInst<R64C>;
1854 def r32: NANDRegInst<R32C>;
1855 def r16: NANDRegInst<R16C>;
1856 def r8: NANDRegInst<R8C>;
1857}
Scott Michel8b6b4202007-12-04 22:35:58 +00001858
Scott Michel34712c32009-03-16 18:47:25 +00001859defm NAND : BitwiseNand;
Scott Michel438be252007-12-17 22:32:34 +00001860
Scott Michel8b6b4202007-12-04 22:35:58 +00001861// NOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001862
Scott Michel34712c32009-03-16 18:47:25 +00001863class NORInst<dag OOL, dag IOL, list<dag> pattern>:
1864 RRForm<0b10010010000, OOL, IOL, "nor\t$rT, $rA, $rB",
1865 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001866
Scott Michel34712c32009-03-16 18:47:25 +00001867class NORVecInst<ValueType vectype>:
1868 NORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1869 [(set (vectype VECREG:$rT), (vnot (or (vectype VECREG:$rA),
1870 (vectype VECREG:$rB))))]>;
1871class NORRegInst<RegisterClass rclass>:
1872 NORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1873 [(set rclass:$rT, (not (or rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001874
Scott Michel34712c32009-03-16 18:47:25 +00001875multiclass BitwiseNor
1876{
1877 def v16i8: NORVecInst<v16i8>;
1878 def v8i16: NORVecInst<v8i16>;
1879 def v4i32: NORVecInst<v4i32>;
1880 def v2i64: NORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001881
Scott Michel34712c32009-03-16 18:47:25 +00001882 def r128: NORRegInst<GPRC>;
1883 def r64: NORRegInst<R64C>;
1884 def r32: NORRegInst<R32C>;
1885 def r16: NORRegInst<R16C>;
1886 def r8: NORRegInst<R8C>;
1887}
Scott Michel8b6b4202007-12-04 22:35:58 +00001888
Scott Michel34712c32009-03-16 18:47:25 +00001889defm NOR : BitwiseNor;
Scott Michel438be252007-12-17 22:32:34 +00001890
Scott Michel8b6b4202007-12-04 22:35:58 +00001891// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001892class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1893 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1894 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001895
pingbak2f387e82009-01-26 03:31:40 +00001896class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michel6baba072008-03-05 23:02:02 +00001897 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1898 [(set (vectype VECREG:$rT),
1899 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
pingbak2f387e82009-01-26 03:31:40 +00001900 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michel6baba072008-03-05 23:02:02 +00001901 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001902
Scott Michel4d07fb72008-12-30 23:28:25 +00001903class SELBVecVCondInst<ValueType vectype>:
1904 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1905 [(set (vectype VECREG:$rT),
1906 (select (vectype VECREG:$rC),
1907 (vectype VECREG:$rB),
1908 (vectype VECREG:$rA)))]>;
1909
Scott Michel06eabde2008-12-27 04:51:36 +00001910class SELBVecCondInst<ValueType vectype>:
1911 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1912 [(set (vectype VECREG:$rT),
1913 (select R32C:$rC,
1914 (vectype VECREG:$rB),
1915 (vectype VECREG:$rA)))]>;
1916
Scott Michel6baba072008-03-05 23:02:02 +00001917class SELBRegInst<RegisterClass rclass>:
1918 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1919 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001920 (or (and rclass:$rB, rclass:$rC),
1921 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001922
Scott Michel06eabde2008-12-27 04:51:36 +00001923class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1924 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1925 [(set rclass:$rT,
1926 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1927
Scott Michel6baba072008-03-05 23:02:02 +00001928multiclass SelectBits
1929{
1930 def v16i8: SELBVecInst<v16i8>;
1931 def v8i16: SELBVecInst<v8i16>;
1932 def v4i32: SELBVecInst<v4i32>;
Chris Lattnerfe29aee2010-03-28 07:48:17 +00001933 def v2i64: SELBVecInst<v2i64, vnot_cell_conv>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001934
Scott Michel6baba072008-03-05 23:02:02 +00001935 def r128: SELBRegInst<GPRC>;
1936 def r64: SELBRegInst<R64C>;
1937 def r32: SELBRegInst<R32C>;
1938 def r16: SELBRegInst<R16C>;
1939 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001940
1941 def v16i8_cond: SELBVecCondInst<v16i8>;
1942 def v8i16_cond: SELBVecCondInst<v8i16>;
1943 def v4i32_cond: SELBVecCondInst<v4i32>;
1944 def v2i64_cond: SELBVecCondInst<v2i64>;
1945
Scott Michel4d07fb72008-12-30 23:28:25 +00001946 def v16i8_vcond: SELBVecCondInst<v16i8>;
1947 def v8i16_vcond: SELBVecCondInst<v8i16>;
1948 def v4i32_vcond: SELBVecCondInst<v4i32>;
1949 def v2i64_vcond: SELBVecCondInst<v2i64>;
1950
1951 def v4f32_cond:
pingbakb8913342009-01-26 03:37:41 +00001952 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1953 [(set (v4f32 VECREG:$rT),
1954 (select (v4i32 VECREG:$rC),
1955 (v4f32 VECREG:$rB),
1956 (v4f32 VECREG:$rA)))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001957
Scott Michel8c67fa42009-01-21 04:58:48 +00001958 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michel06eabde2008-12-27 04:51:36 +00001959 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001960 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001961 def r16_cond: SELBRegCondInst<R16C, R16C>;
1962 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001963}
Scott Michel8b6b4202007-12-04 22:35:58 +00001964
Scott Michel6baba072008-03-05 23:02:02 +00001965defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001966
Scott Michel56a125e2008-11-22 23:50:42 +00001967class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001968 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1969 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001970
Scott Michel56a125e2008-11-22 23:50:42 +00001971def : SPUselbPatVec<v16i8, SELBv16i8>;
1972def : SPUselbPatVec<v8i16, SELBv8i16>;
1973def : SPUselbPatVec<v4i32, SELBv4i32>;
1974def : SPUselbPatVec<v2i64, SELBv2i64>;
1975
1976class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1977 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1978 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1979
1980def : SPUselbPatReg<R8C, SELBr8>;
1981def : SPUselbPatReg<R16C, SELBr16>;
1982def : SPUselbPatReg<R32C, SELBr32>;
1983def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001984
Scott Michel6baba072008-03-05 23:02:02 +00001985// EQV: Equivalence (1 for each same bit, otherwise 0)
1986//
1987// Note: There are a lot of ways to match this bit operator and these patterns
1988// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001989
Scott Michel6baba072008-03-05 23:02:02 +00001990class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1991 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1992 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001993
Scott Michel6baba072008-03-05 23:02:02 +00001994class EQVVecInst<ValueType vectype>:
1995 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1996 [(set (vectype VECREG:$rT),
1997 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1998 (and (vnot (vectype VECREG:$rA)),
1999 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002000
Scott Michel6baba072008-03-05 23:02:02 +00002001class EQVRegInst<RegisterClass rclass>:
2002 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2003 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2004 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002005
Scott Michel6baba072008-03-05 23:02:02 +00002006class EQVVecPattern1<ValueType vectype>:
2007 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2008 [(set (vectype VECREG:$rT),
2009 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002010
Scott Michel6baba072008-03-05 23:02:02 +00002011class EQVRegPattern1<RegisterClass rclass>:
2012 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2013 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002014
Scott Michel6baba072008-03-05 23:02:02 +00002015class EQVVecPattern2<ValueType vectype>:
2016 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2017 [(set (vectype VECREG:$rT),
2018 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2019 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002020
Scott Michel6baba072008-03-05 23:02:02 +00002021class EQVRegPattern2<RegisterClass rclass>:
2022 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2023 [(set rclass:$rT,
2024 (or (and rclass:$rA, rclass:$rB),
2025 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002026
Scott Michel6baba072008-03-05 23:02:02 +00002027class EQVVecPattern3<ValueType vectype>:
2028 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2029 [(set (vectype VECREG:$rT),
2030 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002031
Scott Michel6baba072008-03-05 23:02:02 +00002032class EQVRegPattern3<RegisterClass rclass>:
2033 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2034 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002035
Scott Michel6baba072008-03-05 23:02:02 +00002036multiclass BitEquivalence
2037{
2038 def v16i8: EQVVecInst<v16i8>;
2039 def v8i16: EQVVecInst<v8i16>;
2040 def v4i32: EQVVecInst<v4i32>;
2041 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002042
Scott Michel6baba072008-03-05 23:02:02 +00002043 def v16i8_1: EQVVecPattern1<v16i8>;
2044 def v8i16_1: EQVVecPattern1<v8i16>;
2045 def v4i32_1: EQVVecPattern1<v4i32>;
2046 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002047
Scott Michel6baba072008-03-05 23:02:02 +00002048 def v16i8_2: EQVVecPattern2<v16i8>;
2049 def v8i16_2: EQVVecPattern2<v8i16>;
2050 def v4i32_2: EQVVecPattern2<v4i32>;
2051 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002052
Scott Michel6baba072008-03-05 23:02:02 +00002053 def v16i8_3: EQVVecPattern3<v16i8>;
2054 def v8i16_3: EQVVecPattern3<v8i16>;
2055 def v4i32_3: EQVVecPattern3<v4i32>;
2056 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002057
Scott Michel6baba072008-03-05 23:02:02 +00002058 def r128: EQVRegInst<GPRC>;
2059 def r64: EQVRegInst<R64C>;
2060 def r32: EQVRegInst<R32C>;
2061 def r16: EQVRegInst<R16C>;
2062 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002063
Scott Michel6baba072008-03-05 23:02:02 +00002064 def r128_1: EQVRegPattern1<GPRC>;
2065 def r64_1: EQVRegPattern1<R64C>;
2066 def r32_1: EQVRegPattern1<R32C>;
2067 def r16_1: EQVRegPattern1<R16C>;
2068 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002069
Scott Michel6baba072008-03-05 23:02:02 +00002070 def r128_2: EQVRegPattern2<GPRC>;
2071 def r64_2: EQVRegPattern2<R64C>;
2072 def r32_2: EQVRegPattern2<R32C>;
2073 def r16_2: EQVRegPattern2<R16C>;
2074 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002075
Scott Michel6baba072008-03-05 23:02:02 +00002076 def r128_3: EQVRegPattern3<GPRC>;
2077 def r64_3: EQVRegPattern3<R64C>;
2078 def r32_3: EQVRegPattern3<R32C>;
2079 def r16_3: EQVRegPattern3<R16C>;
2080 def r8_3: EQVRegPattern3<R8C>;
2081}
Scott Michel438be252007-12-17 22:32:34 +00002082
Scott Michel6baba072008-03-05 23:02:02 +00002083defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00002084
2085//===----------------------------------------------------------------------===//
2086// Vector shuffle...
2087//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002088// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2089// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2090// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2091// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002092//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002093
Scott Michel97872d32008-02-23 18:41:37 +00002094class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2095 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2096 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002097
Scott Michel0718cd82008-12-01 17:56:02 +00002098class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002099 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002100 [(set (resultvec VECREG:$rT),
2101 (SPUshuffle (resultvec VECREG:$rA),
2102 (resultvec VECREG:$rB),
2103 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002104
Scott Michel06eabde2008-12-27 04:51:36 +00002105class SHUFBGPRCInst:
2106 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2107 [/* no pattern */]>;
2108
Scott Michel97872d32008-02-23 18:41:37 +00002109multiclass ShuffleBytes
2110{
Scott Michel0718cd82008-12-01 17:56:02 +00002111 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2112 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2113 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2114 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2115 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2116 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2117 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2118 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002119
Scott Michel0718cd82008-12-01 17:56:02 +00002120 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2121 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2122
2123 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2124 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002125
2126 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002127}
2128
2129defm SHUFB : ShuffleBytes;
2130
Scott Michel8b6b4202007-12-04 22:35:58 +00002131//===----------------------------------------------------------------------===//
2132// Shift and rotate group:
2133//===----------------------------------------------------------------------===//
2134
Scott Michel97872d32008-02-23 18:41:37 +00002135class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2136 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2137 RotateShift, pattern>;
2138
2139class SHLHVecInst<ValueType vectype>:
2140 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2141 [(set (vectype VECREG:$rT),
2142 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002143
Scott Michel97872d32008-02-23 18:41:37 +00002144multiclass ShiftLeftHalfword
2145{
2146 def v8i16: SHLHVecInst<v8i16>;
2147 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2148 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2149 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2150 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2151}
Scott Michel8b6b4202007-12-04 22:35:58 +00002152
Scott Michel97872d32008-02-23 18:41:37 +00002153defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002154
Scott Michel97872d32008-02-23 18:41:37 +00002155//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002156
Scott Michel97872d32008-02-23 18:41:37 +00002157class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2158 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2159 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002160
Scott Michel97872d32008-02-23 18:41:37 +00002161class SHLHIVecInst<ValueType vectype>:
2162 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2163 [(set (vectype VECREG:$rT),
2164 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002165
Scott Michel97872d32008-02-23 18:41:37 +00002166multiclass ShiftLeftHalfwordImm
2167{
2168 def v8i16: SHLHIVecInst<v8i16>;
2169 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2170 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2171}
2172
2173defm SHLHI : ShiftLeftHalfwordImm;
2174
2175def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002176 (SHLHIv8i16 VECREG:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel97872d32008-02-23 18:41:37 +00002177
2178def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002179 (SHLHIr16 R16C:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002180
Scott Michel97872d32008-02-23 18:41:37 +00002181//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002182
Scott Michel97872d32008-02-23 18:41:37 +00002183class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2184 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2185 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002186
Scott Michel97872d32008-02-23 18:41:37 +00002187multiclass ShiftLeftWord
2188{
2189 def v4i32:
2190 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2191 [(set (v4i32 VECREG:$rT),
2192 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2193 def r32:
2194 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2195 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2196}
Scott Michel8b6b4202007-12-04 22:35:58 +00002197
Scott Michel97872d32008-02-23 18:41:37 +00002198defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002199
Scott Michel97872d32008-02-23 18:41:37 +00002200//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002201
Scott Michel97872d32008-02-23 18:41:37 +00002202class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2203 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2204 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002205
Scott Michel97872d32008-02-23 18:41:37 +00002206multiclass ShiftLeftWordImm
2207{
2208 def v4i32:
2209 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2210 [(set (v4i32 VECREG:$rT),
2211 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002212
Scott Michel97872d32008-02-23 18:41:37 +00002213 def r32:
2214 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2215 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2216}
Scott Michel8b6b4202007-12-04 22:35:58 +00002217
Scott Michel97872d32008-02-23 18:41:37 +00002218defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002219
Scott Michel97872d32008-02-23 18:41:37 +00002220//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002221// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2222// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002223//
2224// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2225// of 7 bits is actually possible.
2226//
2227// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2228// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2229// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002230
Scott Michel97872d32008-02-23 18:41:37 +00002231class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2232 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2233 RotateShift, pattern>;
2234
2235class SHLQBIVecInst<ValueType vectype>:
2236 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2237 [(set (vectype VECREG:$rT),
2238 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2239
Scott Michel8c67fa42009-01-21 04:58:48 +00002240class SHLQBIRegInst<RegisterClass rclass>:
2241 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2242 [/* no pattern */]>;
2243
Scott Michel97872d32008-02-23 18:41:37 +00002244multiclass ShiftLeftQuadByBits
2245{
2246 def v16i8: SHLQBIVecInst<v16i8>;
2247 def v8i16: SHLQBIVecInst<v8i16>;
2248 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002249 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002250 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002251 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel8c67fa42009-01-21 04:58:48 +00002252
2253 def r128: SHLQBIRegInst<GPRC>;
Scott Michel97872d32008-02-23 18:41:37 +00002254}
2255
2256defm SHLQBI : ShiftLeftQuadByBits;
2257
2258// See note above on SHLQBI. In this case, the predicate actually does then
2259// enforcement, whereas with SHLQBI, we have to "take it on faith."
2260class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2261 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2262 RotateShift, pattern>;
2263
2264class SHLQBIIVecInst<ValueType vectype>:
2265 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2266 [(set (vectype VECREG:$rT),
2267 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2268
2269multiclass ShiftLeftQuadByBitsImm
2270{
2271 def v16i8 : SHLQBIIVecInst<v16i8>;
2272 def v8i16 : SHLQBIIVecInst<v8i16>;
2273 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002274 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002275 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002276 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002277}
2278
2279defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002280
2281// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002282// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002283
Scott Michel97872d32008-02-23 18:41:37 +00002284class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002285 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002286 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002287
Scott Michel97872d32008-02-23 18:41:37 +00002288class SHLQBYVecInst<ValueType vectype>:
2289 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2290 [(set (vectype VECREG:$rT),
2291 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002292
Scott Michel97872d32008-02-23 18:41:37 +00002293multiclass ShiftLeftQuadBytes
2294{
2295 def v16i8: SHLQBYVecInst<v16i8>;
2296 def v8i16: SHLQBYVecInst<v8i16>;
2297 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002298 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002299 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002300 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002301 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2302 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2303}
Scott Michel8b6b4202007-12-04 22:35:58 +00002304
Scott Michel97872d32008-02-23 18:41:37 +00002305defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002306
Scott Michel97872d32008-02-23 18:41:37 +00002307class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2308 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2309 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002310
Scott Michel97872d32008-02-23 18:41:37 +00002311class SHLQBYIVecInst<ValueType vectype>:
2312 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2313 [(set (vectype VECREG:$rT),
2314 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002315
Scott Michel97872d32008-02-23 18:41:37 +00002316multiclass ShiftLeftQuadBytesImm
2317{
2318 def v16i8: SHLQBYIVecInst<v16i8>;
2319 def v8i16: SHLQBYIVecInst<v8i16>;
2320 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002321 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002322 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002323 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002324 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2325 [(set GPRC:$rT,
2326 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2327}
Scott Michel438be252007-12-17 22:32:34 +00002328
Scott Michel97872d32008-02-23 18:41:37 +00002329defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002330
Scott Michel8c67fa42009-01-21 04:58:48 +00002331class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2332 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2333 RotateShift, pattern>;
2334
2335class SHLQBYBIVecInst<ValueType vectype>:
2336 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2337 [/* no pattern */]>;
2338
2339class SHLQBYBIRegInst<RegisterClass rclass>:
2340 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2341 [/* no pattern */]>;
2342
2343multiclass ShiftLeftQuadBytesBitCount
2344{
2345 def v16i8: SHLQBYBIVecInst<v16i8>;
2346 def v8i16: SHLQBYBIVecInst<v8i16>;
2347 def v4i32: SHLQBYBIVecInst<v4i32>;
2348 def v4f32: SHLQBYBIVecInst<v4f32>;
2349 def v2i64: SHLQBYBIVecInst<v2i64>;
2350 def v2f64: SHLQBYBIVecInst<v2f64>;
2351
2352 def r128: SHLQBYBIRegInst<GPRC>;
2353}
2354
2355defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2356
Scott Michel97872d32008-02-23 18:41:37 +00002357//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2358// Rotate halfword:
2359//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2360class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2361 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2362 RotateShift, pattern>;
2363
2364class ROTHVecInst<ValueType vectype>:
2365 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2366 [(set (vectype VECREG:$rT),
Chris Lattner744c5a82010-03-08 18:59:49 +00002367 (SPUvec_rotl VECREG:$rA, (v8i16 VECREG:$rB)))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002368
2369class ROTHRegInst<RegisterClass rclass>:
2370 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2371 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2372
2373multiclass RotateLeftHalfword
2374{
2375 def v8i16: ROTHVecInst<v8i16>;
2376 def r16: ROTHRegInst<R16C>;
2377}
2378
2379defm ROTH: RotateLeftHalfword;
2380
2381def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2382 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2383
2384//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2385// Rotate halfword, immediate:
2386//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2387class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2388 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2389 RotateShift, pattern>;
2390
2391class ROTHIVecInst<ValueType vectype>:
2392 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2393 [(set (vectype VECREG:$rT),
2394 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2395
2396multiclass RotateLeftHalfwordImm
2397{
2398 def v8i16: ROTHIVecInst<v8i16>;
2399 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2400 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2401 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2402 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2403}
2404
2405defm ROTHI: RotateLeftHalfwordImm;
2406
Chris Lattnera041d892010-03-15 05:53:47 +00002407def : Pat<(SPUvec_rotl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2408 (ROTHIv8i16 VECREG:$rA, (TO_IMM16 imm:$val))>;
Scott Michel06eabde2008-12-27 04:51:36 +00002409
Scott Michel97872d32008-02-23 18:41:37 +00002410//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2411// Rotate word:
2412//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002413
Scott Michel97872d32008-02-23 18:41:37 +00002414class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2415 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2416 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002417
Scott Michel97872d32008-02-23 18:41:37 +00002418class ROTVecInst<ValueType vectype>:
2419 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2420 [(set (vectype VECREG:$rT),
2421 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002422
Scott Michel97872d32008-02-23 18:41:37 +00002423class ROTRegInst<RegisterClass rclass>:
2424 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2425 [(set rclass:$rT,
2426 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002427
Scott Michel97872d32008-02-23 18:41:37 +00002428multiclass RotateLeftWord
2429{
2430 def v4i32: ROTVecInst<v4i32>;
2431 def r32: ROTRegInst<R32C>;
2432}
2433
2434defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002435
Scott Michel438be252007-12-17 22:32:34 +00002436// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2437// 32-bit register
2438def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002439 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2440 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002441
2442def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2443 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2444
2445def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2446 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2447
2448def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002449 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2450 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002451
2452def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2453 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2454
2455def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2456 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2457
Scott Michel97872d32008-02-23 18:41:37 +00002458//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2459// Rotate word, immediate
2460//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002461
Scott Michel97872d32008-02-23 18:41:37 +00002462class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2463 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2464 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002465
Scott Michel97872d32008-02-23 18:41:37 +00002466class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2467 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2468 [(set (vectype VECREG:$rT),
2469 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002470
Scott Michel97872d32008-02-23 18:41:37 +00002471class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2472 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2473 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002474
Scott Michel97872d32008-02-23 18:41:37 +00002475multiclass RotateLeftWordImm
2476{
2477 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2478 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2479 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002480
Scott Michel97872d32008-02-23 18:41:37 +00002481 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2482 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2483 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2484}
Scott Michel438be252007-12-17 22:32:34 +00002485
Scott Michel97872d32008-02-23 18:41:37 +00002486defm ROTI : RotateLeftWordImm;
2487
2488//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2489// Rotate quad by byte (count)
2490//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2491
2492class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2493 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2494 RotateShift, pattern>;
2495
2496class ROTQBYVecInst<ValueType vectype>:
2497 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2498 [(set (vectype VECREG:$rT),
2499 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2500
2501multiclass RotateQuadLeftByBytes
2502{
2503 def v16i8: ROTQBYVecInst<v16i8>;
2504 def v8i16: ROTQBYVecInst<v8i16>;
2505 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002506 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002507 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002508 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002509}
2510
2511defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002512
Scott Michel97872d32008-02-23 18:41:37 +00002513//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2514// Rotate quad by byte (count), immediate
2515//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2516
2517class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2518 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2519 RotateShift, pattern>;
2520
2521class ROTQBYIVecInst<ValueType vectype>:
2522 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2523 [(set (vectype VECREG:$rT),
2524 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2525
2526multiclass RotateQuadByBytesImm
2527{
2528 def v16i8: ROTQBYIVecInst<v16i8>;
2529 def v8i16: ROTQBYIVecInst<v8i16>;
2530 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002531 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002532 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002533 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002534}
2535
2536defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002537
Scott Michel8b6b4202007-12-04 22:35:58 +00002538// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002539class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2540 RI7Form<0b00110011100, OOL, IOL,
2541 "rotqbybi\t$rT, $rA, $shift",
2542 RotateShift, pattern>;
2543
2544class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2545 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2546 [(set (vectype VECREG:$rT),
2547 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2548
2549multiclass RotateQuadByBytesByBitshift {
2550 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2551 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2552 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2553 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2554}
2555
2556defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002557
Scott Michel97872d32008-02-23 18:41:37 +00002558//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002559// See ROTQBY note above.
2560//
2561// Assume that the user of this instruction knows to shift the rotate count
2562// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002563//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002564
Scott Michel97872d32008-02-23 18:41:37 +00002565class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2566 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2567 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002568
Scott Michel97872d32008-02-23 18:41:37 +00002569class ROTQBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002570 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002571 [/* no pattern yet */]>;
2572
2573class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002574 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002575 [/* no pattern yet */]>;
2576
2577multiclass RotateQuadByBitCount
2578{
2579 def v16i8: ROTQBIVecInst<v16i8>;
2580 def v8i16: ROTQBIVecInst<v8i16>;
2581 def v4i32: ROTQBIVecInst<v4i32>;
2582 def v2i64: ROTQBIVecInst<v2i64>;
2583
2584 def r128: ROTQBIRegInst<GPRC>;
2585 def r64: ROTQBIRegInst<R64C>;
2586}
2587
2588defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002589
Scott Michel97872d32008-02-23 18:41:37 +00002590class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2591 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2592 RotateShift, pattern>;
2593
2594class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2595 PatLeaf pred>:
2596 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2597 [/* no pattern yet */]>;
2598
2599class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2600 PatLeaf pred>:
2601 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2602 [/* no pattern yet */]>;
2603
2604multiclass RotateQuadByBitCountImm
2605{
2606 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2607 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2608 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2609 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2610
2611 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2612 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2613}
2614
2615defm ROTQBII : RotateQuadByBitCountImm;
2616
2617//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002618// ROTHM v8i16 form:
2619// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2620// so this only matches a synthetically generated/lowered code
2621// fragment.
2622// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002623//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002624
Scott Michel97872d32008-02-23 18:41:37 +00002625class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2626 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2627 RotateShift, pattern>;
2628
2629def ROTHMv8i16:
2630 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2631 [/* see patterns below - $rB must be negated */]>;
2632
2633def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002634 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2635
Scott Michel97872d32008-02-23 18:41:37 +00002636def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002637 (ROTHMv8i16 VECREG:$rA,
2638 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2639
Scott Michel97872d32008-02-23 18:41:37 +00002640def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002641 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002642 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002643
2644// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2645// Note: This instruction doesn't match a pattern because rB must be negated
2646// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002647
Scott Michel8b6b4202007-12-04 22:35:58 +00002648def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002649 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2650 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002651
2652def : Pat<(srl R16C:$rA, R32C:$rB),
2653 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2654
2655def : Pat<(srl R16C:$rA, R16C:$rB),
2656 (ROTHMr16 R16C:$rA,
2657 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2658
Scott Michel438be252007-12-17 22:32:34 +00002659def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002660 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002661 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002662
2663// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2664// that the immediate can be complemented, so that the user doesn't have to
2665// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002666
Scott Michel97872d32008-02-23 18:41:37 +00002667class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2668 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2669 RotateShift, pattern>;
2670
2671def ROTHMIv8i16:
2672 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2673 [/* no pattern */]>;
2674
2675def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2676 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2677
2678def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002679 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel06eabde2008-12-27 04:51:36 +00002680
Scott Michel97872d32008-02-23 18:41:37 +00002681def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002682 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002683
2684def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002685 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2686 [/* no pattern */]>;
2687
2688def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2689 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002690
2691def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002692 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002693
Scott Michel438be252007-12-17 22:32:34 +00002694def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002695 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00002696
Scott Michel8b6b4202007-12-04 22:35:58 +00002697// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002698class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2699 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2700 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002701
Scott Michel97872d32008-02-23 18:41:37 +00002702def ROTMv4i32:
2703 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2704 [/* see patterns below - $rB must be negated */]>;
2705
Chris Lattnera041d892010-03-15 05:53:47 +00002706def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002707 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2708
Chris Lattnera041d892010-03-15 05:53:47 +00002709def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002710 (ROTMv4i32 VECREG:$rA,
2711 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2712
Chris Lattnera041d892010-03-15 05:53:47 +00002713def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002714 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002715 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002716
2717def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002718 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2719 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002720
2721def : Pat<(srl R32C:$rA, R32C:$rB),
2722 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2723
2724def : Pat<(srl R32C:$rA, R16C:$rB),
2725 (ROTMr32 R32C:$rA,
2726 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2727
Scott Michel438be252007-12-17 22:32:34 +00002728def : Pat<(srl R32C:$rA, R8C:$rB),
2729 (ROTMr32 R32C:$rA,
2730 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2731
Scott Michel8b6b4202007-12-04 22:35:58 +00002732// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2733def ROTMIv4i32:
2734 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2735 "rotmi\t$rT, $rA, $val", RotateShift,
2736 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002737 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002738
Chris Lattnera041d892010-03-15 05:53:47 +00002739def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2740 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel06eabde2008-12-27 04:51:36 +00002741
Chris Lattnera041d892010-03-15 05:53:47 +00002742def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i8 uimm7:$val)),
2743 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002744
2745// ROTMI r32 form: know how to complement the immediate value.
2746def ROTMIr32:
2747 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2748 "rotmi\t$rT, $rA, $val", RotateShift,
2749 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2750
2751def : Pat<(srl R32C:$rA, (i16 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002752 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002753
Scott Michel438be252007-12-17 22:32:34 +00002754def : Pat<(srl R32C:$rA, (i8 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002755 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00002756
Scott Michel97872d32008-02-23 18:41:37 +00002757//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel2ef773a2009-01-06 03:36:14 +00002758// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel8b6b4202007-12-04 22:35:58 +00002759// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002760// that the user knew to negate $rB.
Scott Michel97872d32008-02-23 18:41:37 +00002761//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002762
Scott Michel97872d32008-02-23 18:41:37 +00002763class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2764 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2765 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002766
Scott Michel97872d32008-02-23 18:41:37 +00002767class ROTQMBYVecInst<ValueType vectype>:
2768 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2769 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002770
Scott Michel97872d32008-02-23 18:41:37 +00002771class ROTQMBYRegInst<RegisterClass rclass>:
2772 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00002773 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002774
Scott Michel97872d32008-02-23 18:41:37 +00002775multiclass RotateQuadBytes
2776{
2777 def v16i8: ROTQMBYVecInst<v16i8>;
2778 def v8i16: ROTQMBYVecInst<v8i16>;
2779 def v4i32: ROTQMBYVecInst<v4i32>;
2780 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002781
Scott Michel97872d32008-02-23 18:41:37 +00002782 def r128: ROTQMBYRegInst<GPRC>;
2783 def r64: ROTQMBYRegInst<R64C>;
2784}
2785
2786defm ROTQMBY : RotateQuadBytes;
2787
Scott Michel97872d32008-02-23 18:41:37 +00002788class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2789 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2790 RotateShift, pattern>;
2791
2792class ROTQMBYIVecInst<ValueType vectype>:
2793 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002794 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002795
Scott Michel2ef773a2009-01-06 03:36:14 +00002796class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2797 PatLeaf pred>:
Scott Michel97872d32008-02-23 18:41:37 +00002798 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002799 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002800
Scott Michel2ef773a2009-01-06 03:36:14 +00002801// 128-bit zero extension form:
2802class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2803 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2804 [/* no pattern */]>;
2805
Scott Michel97872d32008-02-23 18:41:37 +00002806multiclass RotateQuadBytesImm
2807{
2808 def v16i8: ROTQMBYIVecInst<v16i8>;
2809 def v8i16: ROTQMBYIVecInst<v8i16>;
2810 def v4i32: ROTQMBYIVecInst<v4i32>;
2811 def v2i64: ROTQMBYIVecInst<v2i64>;
2812
2813 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2814 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Michel2ef773a2009-01-06 03:36:14 +00002815
2816 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2817 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2818 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2819 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michel97872d32008-02-23 18:41:37 +00002820}
2821
2822defm ROTQMBYI : RotateQuadBytesImm;
2823
Scott Michel97872d32008-02-23 18:41:37 +00002824//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2825// Rotate right and mask by bit count
2826//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2827
2828class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2829 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2830 RotateShift, pattern>;
2831
2832class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002833 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2834 [/* no pattern, */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002835
2836multiclass RotateMaskQuadByBitCount
2837{
2838 def v16i8: ROTQMBYBIVecInst<v16i8>;
2839 def v8i16: ROTQMBYBIVecInst<v8i16>;
2840 def v4i32: ROTQMBYBIVecInst<v4i32>;
2841 def v2i64: ROTQMBYBIVecInst<v2i64>;
2842}
2843
2844defm ROTQMBYBI: RotateMaskQuadByBitCount;
2845
2846//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2847// Rotate quad and mask by bits
2848// Note that the rotate amount has to be negated
2849//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2850
2851class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2852 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2853 RotateShift, pattern>;
2854
2855class ROTQMBIVecInst<ValueType vectype>:
2856 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2857 [/* no pattern */]>;
2858
2859class ROTQMBIRegInst<RegisterClass rclass>:
2860 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2861 [/* no pattern */]>;
2862
2863multiclass RotateMaskQuadByBits
2864{
2865 def v16i8: ROTQMBIVecInst<v16i8>;
2866 def v8i16: ROTQMBIVecInst<v8i16>;
2867 def v4i32: ROTQMBIVecInst<v4i32>;
2868 def v2i64: ROTQMBIVecInst<v2i64>;
2869
2870 def r128: ROTQMBIRegInst<GPRC>;
2871 def r64: ROTQMBIRegInst<R64C>;
2872}
2873
2874defm ROTQMBI: RotateMaskQuadByBits;
2875
Scott Michel97872d32008-02-23 18:41:37 +00002876//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2877// Rotate quad and mask by bits, immediate
2878//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2879
2880class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2881 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2882 RotateShift, pattern>;
2883
2884class ROTQMBIIVecInst<ValueType vectype>:
2885 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002886 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002887
2888class ROTQMBIIRegInst<RegisterClass rclass>:
2889 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002890 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002891
2892multiclass RotateMaskQuadByBitsImm
2893{
2894 def v16i8: ROTQMBIIVecInst<v16i8>;
2895 def v8i16: ROTQMBIIVecInst<v8i16>;
2896 def v4i32: ROTQMBIIVecInst<v4i32>;
2897 def v2i64: ROTQMBIIVecInst<v2i64>;
2898
2899 def r128: ROTQMBIIRegInst<GPRC>;
2900 def r64: ROTQMBIIRegInst<R64C>;
2901}
2902
2903defm ROTQMBII: RotateMaskQuadByBitsImm;
2904
2905//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2906//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002907
2908def ROTMAHv8i16:
2909 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2910 "rotmah\t$rT, $rA, $rB", RotateShift,
2911 [/* see patterns below - $rB must be negated */]>;
2912
Chris Lattnera041d892010-03-15 05:53:47 +00002913def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002914 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2915
Chris Lattnera041d892010-03-15 05:53:47 +00002916def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002917 (ROTMAHv8i16 VECREG:$rA,
2918 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2919
Chris Lattnera041d892010-03-15 05:53:47 +00002920def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002921 (ROTMAHv8i16 VECREG:$rA,
2922 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2923
Scott Michel8b6b4202007-12-04 22:35:58 +00002924def ROTMAHr16:
2925 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2926 "rotmah\t$rT, $rA, $rB", RotateShift,
2927 [/* see patterns below - $rB must be negated */]>;
2928
2929def : Pat<(sra R16C:$rA, R32C:$rB),
2930 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2931
2932def : Pat<(sra R16C:$rA, R16C:$rB),
2933 (ROTMAHr16 R16C:$rA,
2934 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2935
Scott Michel438be252007-12-17 22:32:34 +00002936def : Pat<(sra R16C:$rA, R8C:$rB),
2937 (ROTMAHr16 R16C:$rA,
2938 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2939
Scott Michel8b6b4202007-12-04 22:35:58 +00002940def ROTMAHIv8i16:
2941 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2942 "rotmahi\t$rT, $rA, $val", RotateShift,
2943 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002944 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002945
Scott Michel97872d32008-02-23 18:41:37 +00002946def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002947 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002948
Scott Michel97872d32008-02-23 18:41:37 +00002949def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002950 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00002951
Scott Michel8b6b4202007-12-04 22:35:58 +00002952def ROTMAHIr16:
2953 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2954 "rotmahi\t$rT, $rA, $val", RotateShift,
2955 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2956
2957def : Pat<(sra R16C:$rA, (i32 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002958 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002959
Scott Michel438be252007-12-17 22:32:34 +00002960def : Pat<(sra R16C:$rA, (i8 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002961 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00002962
Scott Michel8b6b4202007-12-04 22:35:58 +00002963def ROTMAv4i32:
2964 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2965 "rotma\t$rT, $rA, $rB", RotateShift,
2966 [/* see patterns below - $rB must be negated */]>;
2967
Chris Lattnera041d892010-03-15 05:53:47 +00002968def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R32C:$rB),
2969 (ROTMAv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002970
Chris Lattnera041d892010-03-15 05:53:47 +00002971def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R16C:$rB),
2972 (ROTMAv4i32 VECREG:$rA,
Scott Michel8b6b4202007-12-04 22:35:58 +00002973 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2974
Chris Lattnera041d892010-03-15 05:53:47 +00002975def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R8C:$rB),
2976 (ROTMAv4i32 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002977 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2978
Scott Michel8b6b4202007-12-04 22:35:58 +00002979def ROTMAr32:
2980 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2981 "rotma\t$rT, $rA, $rB", RotateShift,
2982 [/* see patterns below - $rB must be negated */]>;
2983
2984def : Pat<(sra R32C:$rA, R32C:$rB),
2985 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2986
2987def : Pat<(sra R32C:$rA, R16C:$rB),
2988 (ROTMAr32 R32C:$rA,
2989 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2990
Scott Michel438be252007-12-17 22:32:34 +00002991def : Pat<(sra R32C:$rA, R8C:$rB),
2992 (ROTMAr32 R32C:$rA,
2993 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2994
Scott Michel67224b22008-06-02 22:18:03 +00002995class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2996 RRForm<0b01011110000, OOL, IOL,
2997 "rotmai\t$rT, $rA, $val",
2998 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002999
Scott Michel67224b22008-06-02 22:18:03 +00003000class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3001 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3002 [(set (vectype VECREG:$rT),
3003 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003004
Scott Michel67224b22008-06-02 22:18:03 +00003005class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3006 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3007 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003008
Scott Michel67224b22008-06-02 22:18:03 +00003009multiclass RotateMaskAlgebraicImm {
3010 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3011 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3012 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3013 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3014}
Scott Michel8b6b4202007-12-04 22:35:58 +00003015
Scott Michel67224b22008-06-02 22:18:03 +00003016defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00003017
Scott Michel8b6b4202007-12-04 22:35:58 +00003018//===----------------------------------------------------------------------===//
3019// Branch and conditionals:
3020//===----------------------------------------------------------------------===//
3021
3022let isTerminator = 1, isBarrier = 1 in {
3023 // Halt If Equal (r32 preferred slot only, no vector form)
3024 def HEQr32:
3025 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3026 "heq\t$rA, $rB", BranchResolv,
3027 [/* no pattern to match */]>;
3028
3029 def HEQIr32 :
3030 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3031 "heqi\t$rA, $val", BranchResolv,
3032 [/* no pattern to match */]>;
3033
3034 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3035 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3036 def HGTr32:
3037 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3038 "hgt\t$rA, $rB", BranchResolv,
3039 [/* no pattern to match */]>;
3040
Scott Michel06eabde2008-12-27 04:51:36 +00003041 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00003042 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3043 "hgti\t$rA, $val", BranchResolv,
3044 [/* no pattern to match */]>;
3045
3046 def HLGTr32:
3047 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3048 "hlgt\t$rA, $rB", BranchResolv,
3049 [/* no pattern to match */]>;
3050
3051 def HLGTIr32:
3052 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3053 "hlgti\t$rA, $val", BranchResolv,
3054 [/* no pattern to match */]>;
3055}
3056
Scott Michel06eabde2008-12-27 04:51:36 +00003057//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3058// Comparison operators for i8, i16 and i32:
3059//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003060
Scott Michel97872d32008-02-23 18:41:37 +00003061class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3062 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3063 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003064
Scott Michel97872d32008-02-23 18:41:37 +00003065multiclass CmpEqualByte
3066{
3067 def v16i8 :
3068 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3069 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3070 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00003071
Scott Michel97872d32008-02-23 18:41:37 +00003072 def r8 :
3073 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3074 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3075}
Scott Michel8b6b4202007-12-04 22:35:58 +00003076
Scott Michel97872d32008-02-23 18:41:37 +00003077class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3078 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3079 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003080
Scott Michel97872d32008-02-23 18:41:37 +00003081multiclass CmpEqualByteImm
3082{
3083 def v16i8 :
3084 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3085 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3086 v16i8SExt8Imm:$val))]>;
3087 def r8:
3088 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3089 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3090}
Scott Michel8b6b4202007-12-04 22:35:58 +00003091
Scott Michel97872d32008-02-23 18:41:37 +00003092class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3093 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3094 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003095
Scott Michel97872d32008-02-23 18:41:37 +00003096multiclass CmpEqualHalfword
3097{
3098 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3099 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3100 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003101
Scott Michel97872d32008-02-23 18:41:37 +00003102 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3103 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3104}
Scott Michel8b6b4202007-12-04 22:35:58 +00003105
Scott Michel97872d32008-02-23 18:41:37 +00003106class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3107 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3108 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003109
Scott Michel97872d32008-02-23 18:41:37 +00003110multiclass CmpEqualHalfwordImm
3111{
3112 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3113 [(set (v8i16 VECREG:$rT),
3114 (seteq (v8i16 VECREG:$rA),
3115 (v8i16 v8i16SExt10Imm:$val)))]>;
3116 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3117 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3118}
Scott Michel8b6b4202007-12-04 22:35:58 +00003119
Scott Michel97872d32008-02-23 18:41:37 +00003120class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3121 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3122 ByteOp, pattern>;
3123
3124multiclass CmpEqualWord
3125{
3126 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3127 [(set (v4i32 VECREG:$rT),
3128 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3129
3130 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3131 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3132}
3133
3134class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3135 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3136 ByteOp, pattern>;
3137
3138multiclass CmpEqualWordImm
3139{
3140 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3141 [(set (v4i32 VECREG:$rT),
3142 (seteq (v4i32 VECREG:$rA),
3143 (v4i32 v4i32SExt16Imm:$val)))]>;
3144
3145 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3146 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3147}
3148
3149class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3150 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3151 ByteOp, pattern>;
3152
3153multiclass CmpGtrByte
3154{
3155 def v16i8 :
3156 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3157 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3158 (v8i16 VECREG:$rB)))]>;
3159
3160 def r8 :
3161 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3162 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3163}
3164
3165class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3166 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3167 ByteOp, pattern>;
3168
3169multiclass CmpGtrByteImm
3170{
3171 def v16i8 :
3172 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3173 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3174 v16i8SExt8Imm:$val))]>;
3175 def r8:
3176 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003177 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003178}
3179
3180class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3181 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3182 ByteOp, pattern>;
3183
3184multiclass CmpGtrHalfword
3185{
3186 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3187 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3188 (v8i16 VECREG:$rB)))]>;
3189
3190 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3191 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3192}
3193
3194class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3195 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3196 ByteOp, pattern>;
3197
3198multiclass CmpGtrHalfwordImm
3199{
3200 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3201 [(set (v8i16 VECREG:$rT),
3202 (setgt (v8i16 VECREG:$rA),
3203 (v8i16 v8i16SExt10Imm:$val)))]>;
3204 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3205 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3206}
3207
3208class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3209 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3210 ByteOp, pattern>;
3211
3212multiclass CmpGtrWord
3213{
3214 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3215 [(set (v4i32 VECREG:$rT),
3216 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3217
3218 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3219 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3220}
3221
3222class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3223 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3224 ByteOp, pattern>;
3225
3226multiclass CmpGtrWordImm
3227{
3228 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3229 [(set (v4i32 VECREG:$rT),
3230 (setgt (v4i32 VECREG:$rA),
3231 (v4i32 v4i32SExt16Imm:$val)))]>;
3232
3233 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3234 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003235
3236 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3237 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3238 [(set (v4i32 VECREG:$rT),
3239 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3240 (v4i32 v4i32SExt16Imm:$val)))]>;
3241
3242 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +00003243 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00003244}
3245
3246class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003247 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003248 ByteOp, pattern>;
3249
3250multiclass CmpLGtrByte
3251{
3252 def v16i8 :
3253 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3254 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3255 (v8i16 VECREG:$rB)))]>;
3256
3257 def r8 :
3258 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3259 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3260}
3261
3262class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003263 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003264 ByteOp, pattern>;
3265
3266multiclass CmpLGtrByteImm
3267{
3268 def v16i8 :
3269 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3270 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3271 v16i8SExt8Imm:$val))]>;
3272 def r8:
3273 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3274 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3275}
3276
3277class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003278 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003279 ByteOp, pattern>;
3280
3281multiclass CmpLGtrHalfword
3282{
3283 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3284 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3285 (v8i16 VECREG:$rB)))]>;
3286
3287 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3288 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3289}
3290
3291class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003292 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003293 ByteOp, pattern>;
3294
3295multiclass CmpLGtrHalfwordImm
3296{
3297 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3298 [(set (v8i16 VECREG:$rT),
3299 (setugt (v8i16 VECREG:$rA),
3300 (v8i16 v8i16SExt10Imm:$val)))]>;
3301 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3302 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3303}
3304
3305class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003306 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003307 ByteOp, pattern>;
3308
3309multiclass CmpLGtrWord
3310{
3311 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3312 [(set (v4i32 VECREG:$rT),
3313 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3314
3315 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3316 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3317}
3318
3319class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003320 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003321 ByteOp, pattern>;
3322
3323multiclass CmpLGtrWordImm
3324{
3325 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3326 [(set (v4i32 VECREG:$rT),
3327 (setugt (v4i32 VECREG:$rA),
3328 (v4i32 v4i32SExt16Imm:$val)))]>;
3329
3330 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003331 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003332}
3333
3334defm CEQB : CmpEqualByte;
3335defm CEQBI : CmpEqualByteImm;
3336defm CEQH : CmpEqualHalfword;
3337defm CEQHI : CmpEqualHalfwordImm;
3338defm CEQ : CmpEqualWord;
3339defm CEQI : CmpEqualWordImm;
3340defm CGTB : CmpGtrByte;
3341defm CGTBI : CmpGtrByteImm;
3342defm CGTH : CmpGtrHalfword;
3343defm CGTHI : CmpGtrHalfwordImm;
3344defm CGT : CmpGtrWord;
3345defm CGTI : CmpGtrWordImm;
3346defm CLGTB : CmpLGtrByte;
3347defm CLGTBI : CmpLGtrByteImm;
3348defm CLGTH : CmpLGtrHalfword;
3349defm CLGTHI : CmpLGtrHalfwordImm;
3350defm CLGT : CmpLGtrWord;
3351defm CLGTI : CmpLGtrWordImm;
3352
Scott Michel53ab7792008-03-10 16:58:52 +00003353//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003354// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3355// define a pattern to generate the right code, as a binary operator
3356// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003357//
Scott Michel06eabde2008-12-27 04:51:36 +00003358// Notes:
3359// 1. This only matches the setcc set of conditionals. Special pattern
3360// matching is used for select conditionals.
3361//
3362// 2. The "DAG" versions of these classes is almost exclusively used for
3363// i64 comparisons. See the tblgen fundamentals documentation for what
3364// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3365// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003366//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003367
Scott Michel53ab7792008-03-10 16:58:52 +00003368class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3369 SPUInstr xorinst, SPUInstr cmpare>:
3370 Pat<(cond rclass:$rA, rclass:$rB),
3371 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3372
3373class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3374 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3375 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3376 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3377
Scott Michel06eabde2008-12-27 04:51:36 +00003378def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003379def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3380
Scott Michel06eabde2008-12-27 04:51:36 +00003381def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003382def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3383
3384def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3385def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003386
3387class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3388 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3389 Pat<(cond rclass:$rA, rclass:$rB),
3390 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3391 (cmpOp2 rclass:$rA, rclass:$rB))>;
3392
3393class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3394 ValueType immtype,
3395 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3396 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3397 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3398 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3399
Scott Michel53ab7792008-03-10 16:58:52 +00003400def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3401def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3402def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3403def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3404def : Pat<(setle R8C:$rA, R8C:$rB),
3405 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3406def : Pat<(setle R8C:$rA, immU8:$imm),
3407 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003408
Scott Michel53ab7792008-03-10 16:58:52 +00003409def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3410def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3411 ORr16, CGTHIr16, CEQHIr16>;
3412def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3413def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3414def : Pat<(setle R16C:$rA, R16C:$rB),
3415 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3416def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3417 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003418
Scott Michel53ab7792008-03-10 16:58:52 +00003419def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3420def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3421 ORr32, CGTIr32, CEQIr32>;
3422def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3423def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3424def : Pat<(setle R32C:$rA, R32C:$rB),
3425 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3426def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3427 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003428
Scott Michel53ab7792008-03-10 16:58:52 +00003429def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3430def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3431def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3432def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3433def : Pat<(setule R8C:$rA, R8C:$rB),
3434 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3435def : Pat<(setule R8C:$rA, immU8:$imm),
3436 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003437
Scott Michel53ab7792008-03-10 16:58:52 +00003438def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3439def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3440 ORr16, CLGTHIr16, CEQHIr16>;
3441def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3442def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3443 CLGTHIr16, CEQHIr16>;
3444def : Pat<(setule R16C:$rA, R16C:$rB),
3445 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003446def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003447 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003448
Scott Michel53ab7792008-03-10 16:58:52 +00003449def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003450def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003451 ORr32, CLGTIr32, CEQIr32>;
3452def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003453def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003454def : Pat<(setule R32C:$rA, R32C:$rB),
3455 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3456def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3457 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003458
Scott Michel53ab7792008-03-10 16:58:52 +00003459//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3460// select conditional patterns:
3461//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3462
3463class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3464 SPUInstr selinstr, SPUInstr cmpare>:
3465 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3466 rclass:$rTrue, rclass:$rFalse),
3467 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003468 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003469
3470class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3471 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3472 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003473 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003474 (selinstr rclass:$rTrue, rclass:$rFalse,
3475 (cmpare rclass:$rA, immpred:$imm))>;
3476
3477def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3478def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3479def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3480def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3481def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3482def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3483
3484def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3485def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3486def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3487def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3488def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3489def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3490
3491def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3492def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3493def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3494def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3495def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3496def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3497
3498class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3499 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3500 SPUInstr cmpOp2>:
3501 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003502 rclass:$rTrue, rclass:$rFalse),
3503 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003504 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3505 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3506
3507class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3508 ValueType inttype,
3509 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3510 SPUInstr cmpOp2>:
3511 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003512 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003513 (selinstr rclass:$rFalse, rclass:$rTrue,
3514 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3515 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3516
3517def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3518def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3519 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3520
3521def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3522def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3523 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3524
3525def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3526def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3527 SELBr32, ORr32, CGTIr32, CEQIr32>;
3528
3529def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3530def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3531 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3532
3533def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3534def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3535 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3536
3537def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3538def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3539 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003540
3541//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003542
3543let isCall = 1,
3544 // All calls clobber the non-callee-saved registers:
3545 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3546 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3547 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3548 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3549 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3550 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3551 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3552 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3553 // All of these instructions use $lr (aka $0)
3554 Uses = [R0] in {
3555 // Branch relative and set link: Used if we actually know that the target
3556 // is within [-32768, 32767] bytes of the target
3557 def BRSL:
3558 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3559 "brsl\t$$lr, $func",
3560 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3561
3562 // Branch absolute and set link: Used if we actually know that the target
3563 // is an absolute address
3564 def BRASL:
3565 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3566 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003567 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003568
3569 // Branch indirect and set link if external data. These instructions are not
3570 // actually generated, matched by an intrinsic:
3571 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3572 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3573 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3574 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3575
3576 // Branch indirect and set link. This is the "X-form" address version of a
3577 // function call
3578 def BISL:
3579 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3580}
3581
Scott Michelae5cbf52008-12-29 03:23:36 +00003582// Support calls to external symbols:
3583def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3584 (BRSL texternalsym:$func)>;
3585
3586def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3587 (BRASL texternalsym:$func)>;
3588
Scott Michel8b6b4202007-12-04 22:35:58 +00003589// Unconditional branches:
Dan Gohman7a94dac2009-11-10 22:16:57 +00003590let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
3591 let isBarrier = 1 in {
3592 def BR :
3593 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3594 "br\t$dest",
3595 [(br bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003596
Dan Gohman7a94dac2009-11-10 22:16:57 +00003597 // Unconditional, absolute address branch
3598 def BRA:
3599 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3600 "bra\t$dest",
3601 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003602
Dan Gohman7a94dac2009-11-10 22:16:57 +00003603 // Indirect branch
3604 def BI:
3605 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3606 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003607
Scott Michele0168c12009-01-05 01:34:35 +00003608 // Conditional branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003609 class BRNZInst<dag IOL, list<dag> pattern>:
3610 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3611 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003612
Scott Michel06eabde2008-12-27 04:51:36 +00003613 class BRNZRegInst<RegisterClass rclass>:
3614 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3615 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003616
Scott Michel06eabde2008-12-27 04:51:36 +00003617 class BRNZVecInst<ValueType vectype>:
3618 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3619 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003620
Scott Michel06eabde2008-12-27 04:51:36 +00003621 multiclass BranchNotZero {
3622 def v4i32 : BRNZVecInst<v4i32>;
3623 def r32 : BRNZRegInst<R32C>;
3624 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003625
Scott Michel06eabde2008-12-27 04:51:36 +00003626 defm BRNZ : BranchNotZero;
3627
3628 class BRZInst<dag IOL, list<dag> pattern>:
3629 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3630 BranchResolv, pattern>;
3631
3632 class BRZRegInst<RegisterClass rclass>:
3633 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3634
3635 class BRZVecInst<ValueType vectype>:
3636 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3637
3638 multiclass BranchZero {
3639 def v4i32: BRZVecInst<v4i32>;
3640 def r32: BRZRegInst<R32C>;
3641 }
3642
3643 defm BRZ: BranchZero;
3644
3645 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3646 // be useful:
3647 /*
3648 class BINZInst<dag IOL, list<dag> pattern>:
3649 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3650
3651 class BINZRegInst<RegisterClass rclass>:
3652 BINZInst<(ins rclass:$rA, brtarget:$dest),
3653 [(brcond rclass:$rA, R32C:$dest)]>;
3654
3655 class BINZVecInst<ValueType vectype>:
3656 BINZInst<(ins VECREG:$rA, R32C:$dest),
3657 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3658
3659 multiclass BranchNotZeroIndirect {
3660 def v4i32: BINZVecInst<v4i32>;
3661 def r32: BINZRegInst<R32C>;
3662 }
3663
3664 defm BINZ: BranchNotZeroIndirect;
3665
3666 class BIZInst<dag IOL, list<dag> pattern>:
3667 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3668
3669 class BIZRegInst<RegisterClass rclass>:
3670 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3671
3672 class BIZVecInst<ValueType vectype>:
3673 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3674
3675 multiclass BranchZeroIndirect {
3676 def v4i32: BIZVecInst<v4i32>;
3677 def r32: BIZRegInst<R32C>;
3678 }
3679
3680 defm BIZ: BranchZeroIndirect;
3681 */
3682
3683 class BRHNZInst<dag IOL, list<dag> pattern>:
3684 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3685 pattern>;
3686
3687 class BRHNZRegInst<RegisterClass rclass>:
3688 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3689 [(brcond rclass:$rCond, bb:$dest)]>;
3690
3691 class BRHNZVecInst<ValueType vectype>:
3692 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3693
3694 multiclass BranchNotZeroHalfword {
3695 def v8i16: BRHNZVecInst<v8i16>;
3696 def r16: BRHNZRegInst<R16C>;
3697 }
3698
3699 defm BRHNZ: BranchNotZeroHalfword;
3700
3701 class BRHZInst<dag IOL, list<dag> pattern>:
3702 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3703 pattern>;
3704
3705 class BRHZRegInst<RegisterClass rclass>:
3706 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3707
3708 class BRHZVecInst<ValueType vectype>:
3709 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3710
3711 multiclass BranchZeroHalfword {
3712 def v8i16: BRHZVecInst<v8i16>;
3713 def r16: BRHZRegInst<R16C>;
3714 }
3715
3716 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003717}
3718
Scott Michel394e26d2008-01-17 20:38:41 +00003719//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003720// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003721//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003722
Scott Michel06eabde2008-12-27 04:51:36 +00003723def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3724 (BRHZr16 R16C:$rA, bb:$dest)>;
3725def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3726 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003727
Scott Michel06eabde2008-12-27 04:51:36 +00003728def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3729 (BRZr32 R32C:$rA, bb:$dest)>;
3730def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3731 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003732
Scott Michel97872d32008-02-23 18:41:37 +00003733multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3734{
3735 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3736 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003737
Scott Michel97872d32008-02-23 18:41:37 +00003738 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3739 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3740
3741 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3742 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3743
3744 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3745 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3746}
3747
Scott Michele0168c12009-01-05 01:34:35 +00003748defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3749defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003750
3751multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3752{
3753 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3754 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3755
3756 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3757 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3758
3759 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3760 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3761
3762 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3763 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3764}
3765
Scott Michel06eabde2008-12-27 04:51:36 +00003766defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3767defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003768
3769multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3770 SPUInstr orinst32, SPUInstr brinst32>
3771{
3772 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3773 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3774 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3775 bb:$dest)>;
3776
3777 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3778 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3779 (CEQHr16 R16C:$rA, R16:$rB)),
3780 bb:$dest)>;
3781
3782 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3783 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3784 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3785 bb:$dest)>;
3786
3787 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3788 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3789 (CEQr32 R32C:$rA, R32C:$rB)),
3790 bb:$dest)>;
3791}
3792
Scott Michel06eabde2008-12-27 04:51:36 +00003793defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3794defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003795
3796multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3797{
3798 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3799 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3800
3801 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3802 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3803
3804 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3805 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3806
3807 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3808 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3809}
3810
Scott Michel06eabde2008-12-27 04:51:36 +00003811defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3812defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003813
3814multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3815 SPUInstr orinst32, SPUInstr brinst32>
3816{
3817 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3818 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3819 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3820 bb:$dest)>;
3821
3822 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3823 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3824 (CEQHr16 R16C:$rA, R16:$rB)),
3825 bb:$dest)>;
3826
3827 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3828 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3829 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3830 bb:$dest)>;
3831
3832 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3833 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3834 (CEQr32 R32C:$rA, R32C:$rB)),
3835 bb:$dest)>;
3836}
3837
Scott Michel06eabde2008-12-27 04:51:36 +00003838defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3839defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003840
Scott Michel8b6b4202007-12-04 22:35:58 +00003841let isTerminator = 1, isBarrier = 1 in {
3842 let isReturn = 1 in {
3843 def RET:
3844 RETForm<"bi\t$$lr", [(retflag)]>;
3845 }
3846}
3847
3848//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003849// Single precision floating point instructions
3850//===----------------------------------------------------------------------===//
3851
Scott Michel61895fe2008-12-10 00:15:19 +00003852class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3853 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003854 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003855
Scott Michel61895fe2008-12-10 00:15:19 +00003856class FAVecInst<ValueType vectype>:
3857 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3858 [(set (vectype VECREG:$rT),
Scott Michel4d07fb72008-12-30 23:28:25 +00003859 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003860
Scott Michel61895fe2008-12-10 00:15:19 +00003861multiclass SFPAdd
3862{
3863 def v4f32: FAVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003864 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3865 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003866}
Scott Michel8b6b4202007-12-04 22:35:58 +00003867
Scott Michel61895fe2008-12-10 00:15:19 +00003868defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003869
Scott Michel61895fe2008-12-10 00:15:19 +00003870class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3871 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003872 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003873
Scott Michel61895fe2008-12-10 00:15:19 +00003874class FSVecInst<ValueType vectype>:
3875 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00003876 [(set (vectype VECREG:$rT),
3877 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003878
3879multiclass SFPSub
3880{
3881 def v4f32: FSVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003882 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3883 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003884}
3885
3886defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003887
Kalle Raiskilae73c0e82010-08-02 10:25:47 +00003888class FMInst<dag OOL, dag IOL, list<dag> pattern>:
3889 RRForm<0b01100011010, OOL, IOL,
3890 "fm\t$rT, $rA, $rB", SPrecFP,
3891 pattern>;
3892
3893class FMVecInst<ValueType type>:
3894 FMInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3895 [(set (type VECREG:$rT),
3896 (fmul (type VECREG:$rA), (type VECREG:$rB)))]>;
3897
3898multiclass SFPMul
3899{
3900 def v4f32: FMVecInst<v4f32>;
Kalle Raiskilae73c0e82010-08-02 10:25:47 +00003901 def f32: FMInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3902 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3903}
3904
3905defm FM : SFPMul;
3906
3907// Floating point multiply and add
3908// e.g. d = c + (a * b)
3909def FMAv4f32:
3910 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3911 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3912 [(set (v4f32 VECREG:$rT),
3913 (fadd (v4f32 VECREG:$rC),
3914 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3915
3916def FMAf32:
3917 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3918 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3919 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3920
3921// FP multiply and subtract
3922// Subtracts value in rC from product
3923// res = a * b - c
3924def FMSv4f32 :
3925 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3926 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3927 [(set (v4f32 VECREG:$rT),
3928 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3929 (v4f32 VECREG:$rC)))]>;
3930
3931def FMSf32 :
3932 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3933 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3934 [(set R32FP:$rT,
3935 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3936
3937// Floating Negative Mulitply and Subtract
3938// Subtracts product from value in rC
3939// res = fneg(fms a b c)
3940// = - (a * b - c)
3941// = c - a * b
3942// NOTE: subtraction order
3943// fsub a b = a - b
3944// fs a b = b - a?
3945def FNMSf32 :
3946 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3947 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3948 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3949
3950def FNMSv4f32 :
3951 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3952 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3953 [(set (v4f32 VECREG:$rT),
3954 (fsub (v4f32 VECREG:$rC),
3955 (fmul (v4f32 VECREG:$rA),
3956 (v4f32 VECREG:$rB))))]>;
3957
3958
3959
3960
Scott Michel8b6b4202007-12-04 22:35:58 +00003961// Floating point reciprocal estimate
Scott Michel8b6b4202007-12-04 22:35:58 +00003962
Scott Michel4d07fb72008-12-30 23:28:25 +00003963class FRESTInst<dag OOL, dag IOL>:
3964 RRForm_1<0b00110111000, OOL, IOL,
3965 "frest\t$rT, $rA", SPrecFP,
3966 [/* no pattern */]>;
3967
3968def FRESTv4f32 :
3969 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3970
3971def FRESTf32 :
3972 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003973
3974// Floating point interpolate (used in conjunction with reciprocal estimate)
3975def FIv4f32 :
3976 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3977 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003978 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003979
3980def FIf32 :
3981 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3982 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003983 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003984
Scott Michel33d73eb2008-11-21 02:56:16 +00003985//--------------------------------------------------------------------------
3986// Basic single precision floating point comparisons:
3987//
3988// Note: There is no support on SPU for single precision NaN. Consequently,
3989// ordered and unordered comparisons are the same.
3990//--------------------------------------------------------------------------
3991
Scott Michel8b6b4202007-12-04 22:35:58 +00003992def FCEQf32 :
3993 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3994 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003995 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3996
3997def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3998 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003999
4000def FCMEQf32 :
4001 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4002 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00004003 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4004
4005def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
4006 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004007
4008def FCGTf32 :
4009 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4010 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00004011 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
4012
4013def : Pat<(setugt R32FP:$rA, R32FP:$rB),
4014 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004015
4016def FCMGTf32 :
4017 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4018 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00004019 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4020
4021def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
4022 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
4023
4024//--------------------------------------------------------------------------
4025// Single precision floating point comparisons and SETCC equivalents:
4026//--------------------------------------------------------------------------
4027
4028def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
4029def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
4030
4031def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
4032def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
4033
4034def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
4035def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
4036
4037def : Pat<(setule R32FP:$rA, R32FP:$rB),
4038 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
4039def : Pat<(setole R32FP:$rA, R32FP:$rB),
4040 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004041
4042// FP Status and Control Register Write
4043// Why isn't rT a don't care in the ISA?
4044// Should we create a special RRForm_3 for this guy and zero out the rT?
4045def FSCRWf32 :
4046 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
4047 "fscrwr\t$rA", SPrecFP,
4048 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
4049
4050// FP Status and Control Register Read
4051def FSCRRf32 :
4052 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
4053 "fscrrd\t$rT", SPrecFP,
4054 [/* This instruction requires an intrinsic */]>;
4055
4056// llvm instruction space
4057// How do these map onto cell instructions?
4058// fdiv rA rB
4059// frest rC rB # c = 1/b (both lines)
4060// fi rC rB rC
4061// fm rD rA rC # d = a * 1/b
4062// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4063// fma rB rB rC rD # b = b * c + d
4064// = -(d *b -a) * c + d
4065// = a * c - c ( a *b *c - a)
4066
4067// fcopysign (???)
4068
4069// Library calls:
4070// These llvm instructions will actually map to library calls.
4071// All that's needed, then, is to check that the appropriate library is
4072// imported and do a brsl to the proper function name.
4073// frem # fmod(x, y): x - (x/y) * y
4074// (Note: fmod(double, double), fmodf(float,float)
4075// fsqrt?
4076// fsin?
4077// fcos?
4078// Unimplemented SPU instruction space
4079// floating reciprocal absolute square root estimate (frsqest)
4080
4081// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00004082// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00004083// status and control register read
4084
4085//--------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00004086// Floating Point Conversions
4087// Signed conversions:
4088def CSiFv4f32:
4089 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4090 "csflt\t$rT, $rA, 0", SPrecFP,
4091 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4092
Scott Michel06eabde2008-12-27 04:51:36 +00004093// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00004094def CSiFf32 :
4095 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4096 "csflt\t$rT, $rA, 0", SPrecFP,
4097 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4098
4099// Convert unsigned into to float
4100def CUiFv4f32 :
4101 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4102 "cuflt\t$rT, $rA, 0", SPrecFP,
4103 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4104
4105def CUiFf32 :
4106 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4107 "cuflt\t$rT, $rA, 0", SPrecFP,
4108 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4109
Scott Michel06eabde2008-12-27 04:51:36 +00004110// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004111// Assume that scale = 0
4112
4113def CFUiv4f32 :
4114 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4115 "cfltu\t$rT, $rA, 0", SPrecFP,
4116 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4117
4118def CFUif32 :
4119 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4120 "cfltu\t$rT, $rA, 0", SPrecFP,
4121 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4122
Scott Michel06eabde2008-12-27 04:51:36 +00004123// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004124// Assume that scale = 0
4125
4126def CFSiv4f32 :
4127 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4128 "cflts\t$rT, $rA, 0", SPrecFP,
4129 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4130
4131def CFSif32 :
4132 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4133 "cflts\t$rT, $rA, 0", SPrecFP,
4134 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4135
4136//===----------------------------------------------------------------------==//
4137// Single<->Double precision conversions
4138//===----------------------------------------------------------------------==//
4139
4140// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4141// v4f32, output is v2f64--which goes in the name?)
4142
4143// Floating point extend single to double
4144// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4145// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4146// are ignored).
4147def FESDvec :
4148 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4149 "fesd\t$rT, $rA", SPrecFP,
Chris Lattnera5c69832010-03-19 04:53:47 +00004150 [/*(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))*/]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004151
4152def FESDf32 :
4153 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4154 "fesd\t$rT, $rA", SPrecFP,
4155 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4156
4157// Floating point round double to single
4158//def FRDSvec :
4159// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4160// "frds\t$rT, $rA,", SPrecFP,
4161// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4162
4163def FRDSf64 :
4164 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4165 "frds\t$rT, $rA", SPrecFP,
4166 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4167
4168//ToDo include anyextend?
4169
4170//===----------------------------------------------------------------------==//
4171// Double precision floating point instructions
4172//===----------------------------------------------------------------------==//
4173def FAf64 :
4174 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4175 "dfa\t$rT, $rA, $rB", DPrecFP,
4176 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4177
4178def FAv2f64 :
4179 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4180 "dfa\t$rT, $rA, $rB", DPrecFP,
4181 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4182
4183def FSf64 :
4184 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4185 "dfs\t$rT, $rA, $rB", DPrecFP,
4186 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4187
4188def FSv2f64 :
4189 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4190 "dfs\t$rT, $rA, $rB", DPrecFP,
4191 [(set (v2f64 VECREG:$rT),
4192 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4193
4194def FMf64 :
4195 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4196 "dfm\t$rT, $rA, $rB", DPrecFP,
4197 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4198
4199def FMv2f64:
4200 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4201 "dfm\t$rT, $rA, $rB", DPrecFP,
4202 [(set (v2f64 VECREG:$rT),
4203 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4204
4205def FMAf64:
4206 RRForm<0b00111010110, (outs R64FP:$rT),
4207 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4208 "dfma\t$rT, $rA, $rB", DPrecFP,
4209 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4210 RegConstraint<"$rC = $rT">,
4211 NoEncode<"$rC">;
4212
4213def FMAv2f64:
4214 RRForm<0b00111010110, (outs VECREG:$rT),
4215 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4216 "dfma\t$rT, $rA, $rB", DPrecFP,
4217 [(set (v2f64 VECREG:$rT),
4218 (fadd (v2f64 VECREG:$rC),
4219 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4220 RegConstraint<"$rC = $rT">,
4221 NoEncode<"$rC">;
4222
4223def FMSf64 :
4224 RRForm<0b10111010110, (outs R64FP:$rT),
4225 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4226 "dfms\t$rT, $rA, $rB", DPrecFP,
4227 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4228 RegConstraint<"$rC = $rT">,
4229 NoEncode<"$rC">;
4230
4231def FMSv2f64 :
4232 RRForm<0b10111010110, (outs VECREG:$rT),
4233 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4234 "dfms\t$rT, $rA, $rB", DPrecFP,
4235 [(set (v2f64 VECREG:$rT),
4236 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4237 (v2f64 VECREG:$rC)))]>;
4238
Scott Michel0d5eae02009-03-17 01:15:45 +00004239// DFNMS: - (a * b - c)
Scott Michel8b6b4202007-12-04 22:35:58 +00004240// - (a * b) + c => c - (a * b)
Scott Michel0d5eae02009-03-17 01:15:45 +00004241
4242class DFNMSInst<dag OOL, dag IOL, list<dag> pattern>:
4243 RRForm<0b01111010110, OOL, IOL, "dfnms\t$rT, $rA, $rB",
4244 DPrecFP, pattern>,
Scott Michel8b6b4202007-12-04 22:35:58 +00004245 RegConstraint<"$rC = $rT">,
4246 NoEncode<"$rC">;
4247
Scott Michel0d5eae02009-03-17 01:15:45 +00004248class DFNMSVecInst<list<dag> pattern>:
4249 DFNMSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4250 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004251
Scott Michel0d5eae02009-03-17 01:15:45 +00004252class DFNMSRegInst<list<dag> pattern>:
4253 DFNMSInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4254 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004255
Scott Michel0d5eae02009-03-17 01:15:45 +00004256multiclass DFMultiplySubtract
4257{
4258 def v2f64 : DFNMSVecInst<[(set (v2f64 VECREG:$rT),
4259 (fsub (v2f64 VECREG:$rC),
4260 (fmul (v2f64 VECREG:$rA),
4261 (v2f64 VECREG:$rB))))]>;
4262
4263 def f64 : DFNMSRegInst<[(set R64FP:$rT,
4264 (fsub R64FP:$rC,
4265 (fmul R64FP:$rA, R64FP:$rB)))]>;
4266}
4267
4268defm DFNMS : DFMultiplySubtract;
Scott Michel8b6b4202007-12-04 22:35:58 +00004269
4270// - (a * b + c)
4271// - (a * b) - c
4272def FNMAf64 :
4273 RRForm<0b11111010110, (outs R64FP:$rT),
4274 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4275 "dfnma\t$rT, $rA, $rB", DPrecFP,
4276 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4277 RegConstraint<"$rC = $rT">,
4278 NoEncode<"$rC">;
4279
4280def FNMAv2f64 :
4281 RRForm<0b11111010110, (outs VECREG:$rT),
4282 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4283 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004284 [(set (v2f64 VECREG:$rT),
4285 (fneg (fadd (v2f64 VECREG:$rC),
4286 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004287 (v2f64 VECREG:$rB)))))]>,
4288 RegConstraint<"$rC = $rT">,
4289 NoEncode<"$rC">;
4290
4291//===----------------------------------------------------------------------==//
4292// Floating point negation and absolute value
4293//===----------------------------------------------------------------------==//
4294
4295def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michele13d8392009-03-17 16:45:16 +00004296 (XORfnegvec (v4f32 VECREG:$rA),
4297 (v4f32 (ILHUv4i32 0x8000)))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004298
4299def : Pat<(fneg R32FP:$rA),
Scott Michele13d8392009-03-17 16:45:16 +00004300 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004301
4302// Floating point absolute value
Scott Michel0d5eae02009-03-17 01:15:45 +00004303// Note: f64 fabs is custom-selected.
Scott Michel8b6b4202007-12-04 22:35:58 +00004304
4305def : Pat<(fabs R32FP:$rA),
4306 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4307
4308def : Pat<(fabs (v4f32 VECREG:$rA)),
4309 (ANDfabsvec (v4f32 VECREG:$rA),
Scott Michel0d5eae02009-03-17 01:15:45 +00004310 (IOHLv4i32 (ILHUv4i32 0x7fff), 0xffff))>;
pingbak2f387e82009-01-26 03:31:40 +00004311
Scott Michel8b6b4202007-12-04 22:35:58 +00004312//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004313// Hint for branch instructions:
4314//===----------------------------------------------------------------------===//
4315
4316/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4317
4318//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004319// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4320// in the odd pipeline)
4321//===----------------------------------------------------------------------===//
4322
Scott Michel97872d32008-02-23 18:41:37 +00004323def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004324 let Pattern = [];
4325
4326 let Inst{0-10} = 0b10000000010;
4327 let Inst{11-17} = 0;
4328 let Inst{18-24} = 0;
4329 let Inst{25-31} = 0;
4330}
4331
Scott Michel97872d32008-02-23 18:41:37 +00004332def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004333 let Pattern = [];
4334
4335 let Inst{0-10} = 0b10000000000;
4336 let Inst{11-17} = 0;
4337 let Inst{18-24} = 0;
4338 let Inst{25-31} = 0;
4339}
4340
4341//===----------------------------------------------------------------------===//
4342// Bit conversions (type conversions between vector/packed types)
Scott Michel34712c32009-03-16 18:47:25 +00004343// NOTE: Promotions are handled using the XS* instructions.
Scott Michel8b6b4202007-12-04 22:35:58 +00004344//===----------------------------------------------------------------------===//
4345def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4346def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4347def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4348def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4349def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4350
4351def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4352def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4353def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4354def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4355def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4356
4357def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4358def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4359def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4360def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4361def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4362
4363def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4364def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4365def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4366def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4367def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4368
4369def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4370def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4371def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4372def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4373def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4374
4375def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4376def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4377def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4378def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
Chris Lattner05c96242010-03-28 08:36:45 +00004379def : Pat<(v2f64 (bitconvert (v4f32 VECREG:$src))), (v2f64 VECREG:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004380
Scott Michel34712c32009-03-16 18:47:25 +00004381def : Pat<(i128 (bitconvert (v16i8 VECREG:$src))),
4382 (ORi128_vec VECREG:$src)>;
4383def : Pat<(i128 (bitconvert (v8i16 VECREG:$src))),
4384 (ORi128_vec VECREG:$src)>;
4385def : Pat<(i128 (bitconvert (v4i32 VECREG:$src))),
4386 (ORi128_vec VECREG:$src)>;
4387def : Pat<(i128 (bitconvert (v2i64 VECREG:$src))),
4388 (ORi128_vec VECREG:$src)>;
4389def : Pat<(i128 (bitconvert (v4f32 VECREG:$src))),
4390 (ORi128_vec VECREG:$src)>;
4391def : Pat<(i128 (bitconvert (v2f64 VECREG:$src))),
4392 (ORi128_vec VECREG:$src)>;
4393
4394def : Pat<(v16i8 (bitconvert (i128 GPRC:$src))),
4395 (v16i8 (ORvec_i128 GPRC:$src))>;
4396def : Pat<(v8i16 (bitconvert (i128 GPRC:$src))),
4397 (v8i16 (ORvec_i128 GPRC:$src))>;
4398def : Pat<(v4i32 (bitconvert (i128 GPRC:$src))),
4399 (v4i32 (ORvec_i128 GPRC:$src))>;
4400def : Pat<(v2i64 (bitconvert (i128 GPRC:$src))),
4401 (v2i64 (ORvec_i128 GPRC:$src))>;
4402def : Pat<(v4f32 (bitconvert (i128 GPRC:$src))),
4403 (v4f32 (ORvec_i128 GPRC:$src))>;
4404def : Pat<(v2f64 (bitconvert (i128 GPRC:$src))),
4405 (v2f64 (ORvec_i128 GPRC:$src))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004406
4407//===----------------------------------------------------------------------===//
4408// Instruction patterns:
4409//===----------------------------------------------------------------------===//
4410
4411// General 32-bit constants:
4412def : Pat<(i32 imm:$imm),
4413 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4414
4415// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004416def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004417 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4418
4419// General constant 32-bit vectors
4420def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004421 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4422 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004423
Scott Michel438be252007-12-17 22:32:34 +00004424// 8-bit constants
4425def : Pat<(i8 imm:$imm),
4426 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004427
4428//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004429// Zero/Any/Sign extensions
4430//===----------------------------------------------------------------------===//
4431
Scott Michel8b6b4202007-12-04 22:35:58 +00004432// sext 8->32: Sign extend bytes to words
4433def : Pat<(sext_inreg R32C:$rSrc, i8),
4434 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4435
Scott Michel438be252007-12-17 22:32:34 +00004436def : Pat<(i32 (sext R8C:$rSrc)),
4437 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4438
Scott Michel2ef773a2009-01-06 03:36:14 +00004439// sext 8->64: Sign extend bytes to double word
4440def : Pat<(sext_inreg R64C:$rSrc, i8),
4441 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4442
4443def : Pat<(i64 (sext R8C:$rSrc)),
4444 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4445
Scott Michel438be252007-12-17 22:32:34 +00004446// zext 8->16: Zero extend bytes to halfwords
4447def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004448 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004449
Scott Michel438be252007-12-17 22:32:34 +00004450// zext 8->32: Zero extend bytes to words
4451def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004452 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004453
Scott Michel2ef773a2009-01-06 03:36:14 +00004454// zext 8->64: Zero extend bytes to double words
4455def : Pat<(i64 (zext R8C:$rSrc)),
4456 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4457 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4458 0x4),
4459 (ILv4i32 0x0),
4460 (FSMBIv4i32 0x0f0f)))>;
4461
4462// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004463def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004464 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004465
Scott Michel2ef773a2009-01-06 03:36:14 +00004466// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004467def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004468 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004469
Scott Michel2ef773a2009-01-06 03:36:14 +00004470// sext 16->64: Sign extend halfword to double word
4471def : Pat<(sext_inreg R64C:$rSrc, i16),
4472 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4473
4474def : Pat<(sext R16C:$rSrc),
4475 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4476
Scott Michel97872d32008-02-23 18:41:37 +00004477// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004478def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004479 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004480
4481def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004482 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004483
4484def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004485 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004486
4487def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004488 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004489
4490// anyext 16->32: Extend 16->32 bits, irrespective of sign
4491def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004492 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004493
4494//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004495// Truncates:
4496// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4497// above are custom lowered.
4498//===----------------------------------------------------------------------===//
4499
4500def : Pat<(i8 (trunc GPRC:$src)),
4501 (ORi8_v16i8
4502 (SHUFBgprc GPRC:$src, GPRC:$src,
4503 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4504
4505def : Pat<(i8 (trunc R64C:$src)),
4506 (ORi8_v16i8
4507 (SHUFBv2i64_m32
4508 (ORv2i64_i64 R64C:$src),
4509 (ORv2i64_i64 R64C:$src),
4510 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4511
4512def : Pat<(i8 (trunc R32C:$src)),
4513 (ORi8_v16i8
4514 (SHUFBv4i32_m32
4515 (ORv4i32_i32 R32C:$src),
4516 (ORv4i32_i32 R32C:$src),
4517 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4518
4519def : Pat<(i8 (trunc R16C:$src)),
4520 (ORi8_v16i8
4521 (SHUFBv4i32_m32
4522 (ORv8i16_i16 R16C:$src),
4523 (ORv8i16_i16 R16C:$src),
4524 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4525
4526def : Pat<(i16 (trunc GPRC:$src)),
4527 (ORi16_v8i16
4528 (SHUFBgprc GPRC:$src, GPRC:$src,
4529 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4530
4531def : Pat<(i16 (trunc R64C:$src)),
4532 (ORi16_v8i16
4533 (SHUFBv2i64_m32
4534 (ORv2i64_i64 R64C:$src),
4535 (ORv2i64_i64 R64C:$src),
4536 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4537
4538def : Pat<(i16 (trunc R32C:$src)),
4539 (ORi16_v8i16
4540 (SHUFBv4i32_m32
4541 (ORv4i32_i32 R32C:$src),
4542 (ORv4i32_i32 R32C:$src),
4543 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4544
4545def : Pat<(i32 (trunc GPRC:$src)),
4546 (ORi32_v4i32
4547 (SHUFBgprc GPRC:$src, GPRC:$src,
4548 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4549
4550def : Pat<(i32 (trunc R64C:$src)),
4551 (ORi32_v4i32
4552 (SHUFBv2i64_m32
4553 (ORv2i64_i64 R64C:$src),
4554 (ORv2i64_i64 R64C:$src),
4555 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4556
4557//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004558// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004559// low parts in order to load them into a register.
4560//===----------------------------------------------------------------------===//
4561
Scott Michelf9f42e62008-01-29 02:16:57 +00004562def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4563def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4564def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4565def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4566
4567def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4568 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004569 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004570
Scott Michelf9f42e62008-01-29 02:16:57 +00004571def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4572 (SPUlo texternalsym:$in, 0)),
4573 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4574
4575def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4576 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004577 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004578
Scott Michelf9f42e62008-01-29 02:16:57 +00004579def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4580 (SPUlo tconstpool:$in, 0)),
4581 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4582
4583def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4584 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4585
4586def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4587 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4588
4589def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4590 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4591
4592def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4593 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004594
Scott Michel34712c32009-03-16 18:47:25 +00004595// Intrinsics:
Scott Michel8b6b4202007-12-04 22:35:58 +00004596include "CellSDKIntrinsics.td"
Scott Michel4d07fb72008-12-30 23:28:25 +00004597// Various math operator instruction sequences
4598include "SPUMathInstr.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004599// 64-bit "instructions"/support
4600include "SPU64InstrInfo.td"
Scott Michel2ef773a2009-01-06 03:36:14 +00004601// 128-bit "instructions"/support
4602include "SPU128InstrInfo.td"