blob: ff327eb09e2eae716b808e8c754044fc95360ce3 [file] [log] [blame]
Scott Michel66377522007-12-04 22:35:58 +00001//==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
Scott Michelf0569be2008-12-27 04:51:36 +00002//
Scott Michel66377522007-12-04 22:35:58 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Michelf0569be2008-12-27 04:51:36 +00007//
Scott Michel66377522007-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 Michel203b2d62008-04-30 00:30:08 +000025 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel66377522007-12-04 22:35:58 +000026 "${:comment} ADJCALLSTACKDOWN",
Chris Lattnere563bbc2008-10-11 22:08:30 +000027 [(callseq_start timm:$amt)]>;
Scott Michel203b2d62008-04-30 00:30:08 +000028 def ADJCALLSTACKUP : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel66377522007-12-04 22:35:58 +000029 "${:comment} ADJCALLSTACKUP",
Chris Lattnere563bbc2008-10-11 22:08:30 +000030 [(callseq_end timm:$amt)]>;
Scott Michel66377522007-12-04 22:35:58 +000031}
32
33//===----------------------------------------------------------------------===//
Scott Michel66377522007-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 Gohman15511cf2008-12-03 18:15:48 +000041let canFoldAsLoad = 1 in {
Scott Michel053c1da2008-01-29 02:16:57 +000042 class LoadDFormVec<ValueType vectype>
Scott Michelf0569be2008-12-27 04:51:36 +000043 : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +000044 "lqd\t$rT, $src",
45 LoadStore,
46 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
47 { }
Scott Michel66377522007-12-04 22:35:58 +000048
Scott Michel053c1da2008-01-29 02:16:57 +000049 class LoadDForm<RegisterClass rclass>
Scott Michelf0569be2008-12-27 04:51:36 +000050 : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +000051 "lqd\t$rT, $src",
52 LoadStore,
53 [(set rclass:$rT, (load dform_addr:$src))]>
54 { }
Scott Michel66377522007-12-04 22:35:58 +000055
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +000064
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +000073
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +000080
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +000087
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +000096
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000105
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000112
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000119
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000128
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000137
Scott Michel053c1da2008-01-29 02:16:57 +0000138 defm LQA : LoadAForms;
139 defm LQD : LoadDForms;
140 defm LQX : LoadXForms;
Scott Michel504c3692007-12-17 22:32:34 +0000141
Scott Michel66377522007-12-04 22:35:58 +0000142/* Load quadword, PC relative: Not much use at this point in time.
Scott Michel053c1da2008-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 Michel66377522007-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 Michel66377522007-12-04 22:35:58 +0000149}
150
151//===----------------------------------------------------------------------===//
152// Stores:
153//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +0000154class StoreDFormVec<ValueType vectype>
Scott Michelf0569be2008-12-27 04:51:36 +0000155 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +0000156 "stqd\t$rT, $src",
157 LoadStore,
158 [(store (vectype VECREG:$rT), dform_addr:$src)]>
159{ }
Scott Michel66377522007-12-04 22:35:58 +0000160
Scott Michel053c1da2008-01-29 02:16:57 +0000161class StoreDForm<RegisterClass rclass>
Scott Michelf0569be2008-12-27 04:51:36 +0000162 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +0000163 "stqd\t$rT, $src",
164 LoadStore,
165 [(store rclass:$rT, dform_addr:$src)]>
166{ }
Scott Michel66377522007-12-04 22:35:58 +0000167
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000176
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000185
Scott Michel053c1da2008-01-29 02:16:57 +0000186class StoreAFormVec<ValueType vectype>
187 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000188 "stqa\t$rT, $src",
189 LoadStore,
Scott Michelad2715e2008-03-05 23:02:02 +0000190 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel66377522007-12-04 22:35:58 +0000191
Scott Michel053c1da2008-01-29 02:16:57 +0000192class StoreAForm<RegisterClass rclass>
193 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000194 "stqa\t$rT, $src",
195 LoadStore,
Scott Michelad2715e2008-03-05 23:02:02 +0000196 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel66377522007-12-04 22:35:58 +0000197
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000206
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000215
Scott Michel053c1da2008-01-29 02:16:57 +0000216class StoreXFormVec<ValueType vectype>
217 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000218 "stqx\t$rT, $src",
219 LoadStore,
220 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michel053c1da2008-01-29 02:16:57 +0000221{ }
Scott Michel66377522007-12-04 22:35:58 +0000222
Scott Michel053c1da2008-01-29 02:16:57 +0000223class StoreXForm<RegisterClass rclass>
224 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000225 "stqx\t$rT, $src",
226 LoadStore,
227 [(store rclass:$rT, xform_addr:$src)]>
Scott Michel053c1da2008-01-29 02:16:57 +0000228{ }
Scott Michel66377522007-12-04 22:35:58 +0000229
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000238
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000247
Scott Michel053c1da2008-01-29 02:16:57 +0000248defm STQD : StoreDForms;
249defm STQA : StoreAForms;
250defm STQX : StoreXForms;
Scott Michel66377522007-12-04 22:35:58 +0000251
252/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michel053c1da2008-01-29 02:16:57 +0000253 be useful for relocatable code.
Chris Lattnerc8478d82008-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 Michel66377522007-12-04 22:35:58 +0000258
259//===----------------------------------------------------------------------===//
260// Generate Controls for Insertion:
261//===----------------------------------------------------------------------===//
262
Scott Michelf0569be2008-12-27 04:51:36 +0000263def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-12-01 17:56:02 +0000264 "cbd\t$rT, $src", ShuffleOp,
265 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000266
Scott Michel1a6cdb62008-12-01 17:56:02 +0000267def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000268 "cbx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000269 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000270
Scott Michelf0569be2008-12-27 04:51:36 +0000271def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000272 "chd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000273 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000274
Scott Michel1a6cdb62008-12-01 17:56:02 +0000275def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000276 "chx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000277 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000278
Scott Michelf0569be2008-12-27 04:51:36 +0000279def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000280 "cwd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000281 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000282
Scott Michel1a6cdb62008-12-01 17:56:02 +0000283def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000284 "cwx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000285 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000286
Scott Michelf0569be2008-12-27 04:51:36 +0000287def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-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 Michel203b2d62008-04-30 00:30:08 +0000292 "cwx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000293 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel203b2d62008-04-30 00:30:08 +0000294
Scott Michelf0569be2008-12-27 04:51:36 +0000295def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000296 "cdd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000297 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000298
Scott Michel1a6cdb62008-12-01 17:56:02 +0000299def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000300 "cdx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000301 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000302
Scott Michelf0569be2008-12-27 04:51:36 +0000303def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-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 Michel203b2d62008-04-30 00:30:08 +0000308 "cdx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000309 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel203b2d62008-04-30 00:30:08 +0000310
Scott Michel66377522007-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 Michel504c3692007-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 Michel66377522007-12-04 22:35:58 +0000332// IL does sign extension!
Scott Michel66377522007-12-04 22:35:58 +0000333
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000337
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000341
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000345
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000350
Scott Michelad2715e2008-03-05 23:02:02 +0000351 // TODO: Need v2f64, v4f32
Scott Michel66377522007-12-04 22:35:58 +0000352
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000358
Scott Michelad2715e2008-03-05 23:02:02 +0000359defm IL : ImmediateLoad;
Scott Michel66377522007-12-04 22:35:58 +0000360
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000364
Scott Michelad2715e2008-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 Michel203b2d62008-04-30 00:30:08 +0000376 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michelad2715e2008-03-05 23:02:02 +0000377
378 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michel203b2d62008-04-30 00:30:08 +0000379 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michelad2715e2008-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 Michel66377522007-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 Michelad2715e2008-03-05 23:02:02 +0000392
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +0000396
Scott Michelad2715e2008-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 Michela59d4692008-02-23 18:41:37 +0000405multiclass ImmLoadAddress
406{
Scott Michelad2715e2008-03-05 23:02:02 +0000407 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
408 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel66377522007-12-04 22:35:58 +0000409
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000414
Scott Michelf0569be2008-12-27 04:51:36 +0000415 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michelad2715e2008-03-05 23:02:02 +0000416 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel66377522007-12-04 22:35:58 +0000417
Scott Michela59d4692008-02-23 18:41:37 +0000418 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
419 [/* no pattern */]>;
420}
421
422defm ILA : ImmLoadAddress;
Scott Michel66377522007-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 Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000434
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000438
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +0000442
Scott Michelad2715e2008-03-05 23:02:02 +0000443multiclass ImmOrHalfwordLower
444{
445 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michel203b2d62008-04-30 00:30:08 +0000446 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michelad2715e2008-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 Michel9de5d0d2008-01-11 02:53:15 +0000455
Scott Michel66377522007-12-04 22:35:58 +0000456// Form select mask for bytes using immediate, used in conjunction with the
457// SELB instruction:
458
Scott Michelad2715e2008-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 Michel8bf61e82008-06-02 22:18:03 +0000463 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000464
Scott Michela59d4692008-02-23 18:41:37 +0000465multiclass FormSelectMaskBytesImm
Scott Michel053c1da2008-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 Michel66377522007-12-04 22:35:58 +0000472
Scott Michela59d4692008-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 Michelf0569be2008-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 Michela59d4692008-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 Michelf0569be2008-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 Michela59d4692008-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 Michelf0569be2008-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 Michel8bf61e82008-06-02 22:18:03 +0000533
534multiclass FormSelectMaskWord {
Scott Michelf0569be2008-12-27 04:51:36 +0000535 def v4i32: FSMVecInst<v4i32>;
536
537 def r32 : FSMRegInst<v4i32, R32C>;
538 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000539}
540
541defm FSM : FormSelectMaskWord;
542
543// Special case when used for i64 math operations
544multiclass FormSelectMaskWord64 {
Scott Michelf0569be2008-12-27 04:51:36 +0000545 def r32 : FSMRegInst<v2i64, R32C>;
546 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000547}
548
549defm FSM64 : FormSelectMaskWord64;
Scott Michel66377522007-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 Michel66377522007-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 Michela59d4692008-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 Michel02d711b2008-12-30 23:28:25 +0000577 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
578
579// v4i32, i32 add instruction:
Scott Michel66377522007-12-04 22:35:58 +0000580
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000585
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000590
Scott Michel1df30c42008-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 Michel1df30c42008-12-29 03:23:36 +0000598 def r32: ARegInst<R32C>;
Scott Michel1df30c42008-12-29 03:23:36 +0000599}
Scott Michel66377522007-12-04 22:35:58 +0000600
Scott Michel1df30c42008-12-29 03:23:36 +0000601defm A : AddInstruction;
Scott Michel504c3692007-12-17 22:32:34 +0000602
Scott Michel02d711b2008-12-30 23:28:25 +0000603class AIInst<dag OOL, dag IOL, list<dag> pattern>:
604 RI10Form<0b00111000, OOL, IOL,
Scott Michel19c10e62009-01-26 03:37:41 +0000605 "ai\t$rT, $rA, $val", IntegerOp,
606 pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000607
Scott Michel02d711b2008-12-30 23:28:25 +0000608class AIVecInst<ValueType vectype, PatLeaf immpred>:
609 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000610 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000611
612class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
613 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000614 [/* no pattern */]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000615
616class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
617 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000618 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
Scott Michel02d711b2008-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),
Scott Michel19c10e62009-01-26 03:37:41 +0000623 [/* no pattern */]>;
Scott Michel02d711b2008-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 Michel66377522007-12-04 22:35:58 +0000635
Scott Michel504c3692007-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 Michel66377522007-12-04 22:35:58 +0000641
Scott Michel504c3692007-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 Raiskila26c4cf4c2010-05-10 08:13:49 +0000645 [(set R16C:$rT, (sub R16C:$rB, R16C:$rA))]>;
Scott Michel66377522007-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 Raiskila26c4cf4c2010-05-10 08:13:49 +0000660 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rB), (v4i32 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000661
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000662
Scott Michel66377522007-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 Raiskila26c4cf4c2010-05-10 08:13:49 +0000665 [(set R32C:$rT, (sub R32C:$rB, R32C:$rA))]>;
Scott Michel66377522007-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 Michel8bf61e82008-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 Michel94bd57e2009-01-15 04:41:47 +0000687 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000688 RegConstraint<"$rCarry = $rT">,
689 NoEncode<"$rCarry">;
690
Scott Michel8bf61e82008-06-02 22:18:03 +0000691class ADDXRegInst<RegisterClass rclass>:
692 ADDXInst<(outs rclass:$rT),
693 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000694 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000695 RegConstraint<"$rCarry = $rT">,
696 NoEncode<"$rCarry">;
697
Scott Michel8bf61e82008-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 Michel94bd57e2009-01-15 04:41:47 +0000716 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000717
718class CGRegInst<RegisterClass rclass>:
719 CGInst<(outs rclass:$rT),
720 (ins rclass:$rA, rclass:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000721 [/* no pattern */]>;
Scott Michel8bf61e82008-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 Michel94bd57e2009-01-15 04:41:47 +0000742 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000743 RegConstraint<"$rCarry = $rT">,
744 NoEncode<"$rCarry">;
745
Scott Michel8bf61e82008-06-02 22:18:03 +0000746class SFXRegInst<RegisterClass rclass>:
747 SFXInst<(outs rclass:$rT),
748 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000749 [/* no pattern */]>,
Scott Michel8bf61e82008-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 Michel66377522007-12-04 22:35:58 +0000762// BG: only available in vector form, doesn't match a pattern.
Scott Michel8bf61e82008-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 Michel66377522007-12-04 22:35:58 +0000767
Scott Michel8bf61e82008-06-02 22:18:03 +0000768class BGVecInst<ValueType vectype>:
769 BGInst<(outs VECREG:$rT),
770 (ins VECREG:$rA, VECREG:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000771 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000772
773class BGRegInst<RegisterClass rclass>:
774 BGInst<(outs rclass:$rT),
775 (ins rclass:$rA, rclass:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000776 [/* no pattern */]>;
Scott Michel8bf61e82008-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 Michel66377522007-12-04 22:35:58 +0000788def BGXvec:
789 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michelf0569be2008-12-27 04:51:36 +0000790 VECREG:$rCarry),
Scott Michel66377522007-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 Michel02d711b2008-12-30 23:28:25 +0000802 [/* no pattern */]>;
Scott Michel66377522007-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 Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000816def MPYUv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000817 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000818 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000819
820def MPYUr16:
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000823
824def MPYUr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000825 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000826 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000827
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000832 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000839
840def MPYIr16:
Scott Michel1df30c42008-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 Michel66377522007-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 Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000852def MPYUIvec:
Scott Michel1df30c42008-12-29 03:23:36 +0000853 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
854 []>;
Scott Michel66377522007-12-04 22:35:58 +0000855
856def MPYUIr16:
Scott Michel1df30c42008-12-29 03:23:36 +0000857 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
858 []>;
Scott Michel66377522007-12-04 22:35:58 +0000859
860// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michel1df30c42008-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 Michel94bd57e2009-01-15 04:41:47 +0000866def MPYAv4i32:
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000872
873def MPYAr32:
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000882
883def MPYAr32_sextinreg:
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000888
889// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michel1df30c42008-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 Michel66377522007-12-04 22:35:58 +0000895def MPYHv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000896 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000897 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000898
899def MPYHr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000900 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000901 [/* no pattern */]>;
Scott Michel66377522007-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 Michel66377522007-12-04 22:35:58 +0000905
Scott Michel02d711b2008-12-30 23:28:25 +0000906class MPYSInst<dag OOL, dag IOL>:
907 RRForm<0b11100011110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000908 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000909 [/* no pattern */]>;
910
Scott Michel94bd57e2009-01-15 04:41:47 +0000911def MPYSv4i32:
Scott Michel02d711b2008-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 Michel66377522007-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 Michel02d711b2008-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 Michel66377522007-12-04 22:35:58 +0000925def MPYHHv8i16:
Scott Michel02d711b2008-12-30 23:28:25 +0000926 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000927
928def MPYHHr32:
Scott Michel02d711b2008-12-30 23:28:25 +0000929 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000930
931// mpyhha: Multiply high-high, add to $rT:
Scott Michel66377522007-12-04 22:35:58 +0000932
Scott Michel02d711b2008-12-30 23:28:25 +0000933class MPYHHAInst<dag OOL, dag IOL>:
934 RRForm<0b01100010110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000935 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-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 Michel66377522007-12-04 22:35:58 +0000943
Scott Michel94bd57e2009-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 Michel66377522007-12-04 22:35:58 +0000951
Scott Michel02d711b2008-12-30 23:28:25 +0000952class MPYHHUInst<dag OOL, dag IOL>:
953 RRForm<0b01110011110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000954 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000955 [/* no pattern */]>;
956
Scott Michel94bd57e2009-01-15 04:41:47 +0000957def MPYHHUv4i32:
Scott Michel02d711b2008-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 Michel66377522007-12-04 22:35:58 +0000962
963// mpyhhau: Multiply high-high, unsigned
Scott Michel02d711b2008-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 Michel66377522007-12-04 22:35:58 +0000970def MPYHHAUvec:
Scott Michel02d711b2008-12-30 23:28:25 +0000971 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
972
Scott Michel66377522007-12-04 22:35:58 +0000973def MPYHHAUr32:
Scott Michel02d711b2008-12-30 23:28:25 +0000974 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel1df30c42008-12-29 03:23:36 +0000975
976//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +0000977// clz: Count leading zeroes
Scott Michel1df30c42008-12-29 03:23:36 +0000978//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michelf0569be2008-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 Michel66377522007-12-04 22:35:58 +0000982
Scott Michelf0569be2008-12-27 04:51:36 +0000983class CLZRegInst<RegisterClass rclass>:
984 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel02d711b2008-12-30 23:28:25 +0000985 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michelf0569be2008-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 Michel66377522007-12-04 22:35:58 +0000997
998// cntb: Count ones in bytes (aka "population count")
Scott Michelf0569be2008-12-27 04:51:36 +0000999//
Scott Michel66377522007-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 Michelf0569be2008-12-27 04:51:36 +00001003
Scott Michel66377522007-12-04 22:35:58 +00001004def CNTBv16i8:
1005 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1006 "cntb\t$rT, $rA", IntegerOp,
Scott Michel8bf61e82008-06-02 22:18:03 +00001007 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel66377522007-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 Michel8bf61e82008-06-02 22:18:03 +00001012 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel66377522007-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 Michel8bf61e82008-06-02 22:18:03 +00001017 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001018
Scott Michelf0569be2008-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 Michel21213e72009-01-06 23:10:38 +00001034 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001035
1036class GBBVecInst<ValueType vectype>:
1037 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001038 [/* no pattern */]>;
Scott Michelf0569be2008-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 Michel66377522007-12-04 22:35:58 +00001047
1048// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michelf0569be2008-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 Michel21213e72009-01-06 23:10:38 +00001060 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001061
1062class GBHVecInst<ValueType vectype>:
1063 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001064 [/* no pattern */]>;
Scott Michelf0569be2008-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 Michel66377522007-12-04 22:35:58 +00001073
1074// gb: Gather all low order bits from each word in $rA into a single
Scott Michelf0569be2008-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 Michel21213e72009-01-06 23:10:38 +00001086 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001087
1088class GBVecInst<ValueType vectype>:
1089 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001090 [/* no pattern */]>;
Scott Michelf0569be2008-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 Michel66377522007-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 Michel8bf61e82008-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 Michel66377522007-12-04 22:35:58 +00001123
Scott Micheldd950092009-01-06 03:36:14 +00001124class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel8bf61e82008-06-02 22:18:03 +00001125 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Micheldd950092009-01-06 03:36:14 +00001126 pattern>;
Scott Michel8bf61e82008-06-02 22:18:03 +00001127
1128multiclass ExtendByteHalfword {
Chris Lattnere9eda0f2010-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 Micheldd950092009-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 Michel8bf61e82008-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 Micheldd950092009-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 Michel8bf61e82008-06-02 22:18:03 +00001146}
1147
1148defm XSBH : ExtendByteHalfword;
1149
Scott Michel66377522007-12-04 22:35:58 +00001150// Sign extend halfwords to words:
Scott Michel66377522007-12-04 22:35:58 +00001151
Scott Micheldd950092009-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 Michel66377522007-12-04 22:35:58 +00001155
Scott Micheldd950092009-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 Michel66377522007-12-04 22:35:58 +00001180
Scott Micheled741dd2009-01-05 01:34:35 +00001181// Sign-extend words to doublewords (32->64 bits)
Scott Michel66377522007-12-04 22:35:58 +00001182
Scott Micheled741dd2009-01-05 01:34:35 +00001183class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Micheldd950092009-01-06 03:36:14 +00001184 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1185 IntegerOp, pattern>;
Scott Micheled741dd2009-01-05 01:34:35 +00001186
1187class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1188 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
Chris Lattnere9eda0f2010-03-19 04:53:47 +00001189 [/*(set (out_vectype VECREG:$rDst),
1190 (sext (out_vectype VECREG:$rSrc)))*/]>;
Scott Micheled741dd2009-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 Michel66377522007-12-04 22:35:58 +00001203
Scott Micheled741dd2009-01-05 01:34:35 +00001204defm XSWD : ExtendWordToDoubleWord;
Scott Michel66377522007-12-04 22:35:58 +00001205
1206// AND operations
Scott Michel66377522007-12-04 22:35:58 +00001207
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001211
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001216
Scott Michelad2715e2008-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 Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001227
Scott Michelad2715e2008-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 Michel66377522007-12-04 22:35:58 +00001233
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001238
Scott Michel7ea02ff2009-03-17 01:15:45 +00001239 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001240 [/* Intentionally does not match a pattern */]>;
1241
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001258
Chris Lattner918472a2010-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 Michel66377522007-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 Michel66377522007-12-04 22:35:58 +00001268
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001272
Scott Michel7ea02ff2009-03-17 01:15:45 +00001273class ANDCVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michela59d4692008-02-23 18:41:37 +00001274 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel7ea02ff2009-03-17 01:15:45 +00001275 [(set (vectype VECREG:$rT),
1276 (and (vectype VECREG:$rA),
1277 (vnot_frag (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001278
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001282
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001289
Scott Michela59d4692008-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 Michel7ea02ff2009-03-17 01:15:45 +00001295
1296 // Sometimes, the xor pattern has a bitcast constant:
Chris Lattner918472a2010-03-28 07:48:17 +00001297 def v16i8_conv: ANDCVecInst<v16i8, vnot_cell_conv>;
Scott Michela59d4692008-02-23 18:41:37 +00001298}
Scott Michel504c3692007-12-17 22:32:34 +00001299
Scott Michela59d4692008-02-23 18:41:37 +00001300defm ANDC : AndComplement;
Scott Michel66377522007-12-04 22:35:58 +00001301
Scott Michela59d4692008-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 Michelaedc6372008-12-10 00:15:19 +00001304 ByteOp, pattern>;
Scott Michel504c3692007-12-17 22:32:34 +00001305
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001312
Scott Michela59d4692008-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 Michel504c3692007-12-17 22:32:34 +00001316
Scott Michela59d4692008-02-23 18:41:37 +00001317defm ANDBI : AndByteImm;
Scott Michel66377522007-12-04 22:35:58 +00001318
Scott Michela59d4692008-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 Michelaedc6372008-12-10 00:15:19 +00001321 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001322
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001328
Scott Michela59d4692008-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 Michel504c3692007-12-17 22:32:34 +00001331
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001336
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001371// Bitwise OR group:
Scott Michela59d4692008-02-23 18:41:37 +00001372//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1373
Scott Michel66377522007-12-04 22:35:58 +00001374// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001378
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001383
Scott Michela59d4692008-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 Michel66377522007-12-04 22:35:58 +00001387
Kalle Raiskila99534bb2010-08-09 16:33:00 +00001388
Scott Michela59d4692008-02-23 18:41:37 +00001389multiclass BitwiseOr
1390{
1391 def v16i8: ORVecInst<v16i8>;
1392 def v8i16: ORVecInst<v8i16>;
1393 def v4i32: ORVecInst<v4i32>;
1394 def v2i64: ORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001395
Scott Michela59d4692008-02-23 18:41:37 +00001396 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1397 [(set (v4f32 VECREG:$rT),
1398 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1399 (v4i32 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001400
Scott Michela59d4692008-02-23 18:41:37 +00001401 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michelf0569be2008-12-27 04:51:36 +00001402 [(set (v2f64 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00001403 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1404 (v2i64 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001405
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001406 def r128: ORRegInst<GPRC>;
1407 def r64: ORRegInst<R64C>;
1408 def r32: ORRegInst<R32C>;
1409 def r16: ORRegInst<R16C>;
1410 def r8: ORRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001411
Scott Michela59d4692008-02-23 18:41:37 +00001412 // OR instructions used to copy f32 and f64 registers.
1413 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1414 [/* no pattern */]>;
Scott Michel504c3692007-12-17 22:32:34 +00001415
Scott Michela59d4692008-02-23 18:41:37 +00001416 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1417 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00001418}
Scott Michel504c3692007-12-17 22:32:34 +00001419
Scott Michela59d4692008-02-23 18:41:37 +00001420defm OR : BitwiseOr;
1421
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001422//===----------------------------------------------------------------------===//
1423// SPU::PREFSLOT2VEC and VEC2PREFSLOT re-interpretations of registers
1424//===----------------------------------------------------------------------===//
Scott Michelf0569be2008-12-27 04:51:36 +00001425def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001426 (COPY_TO_REGCLASS R8C:$rA, VECREG)>;
Scott Michel504c3692007-12-17 22:32:34 +00001427
Scott Michelf0569be2008-12-27 04:51:36 +00001428def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001429 (COPY_TO_REGCLASS R16C:$rA, VECREG)>;
Scott Michel66377522007-12-04 22:35:58 +00001430
Scott Michelf0569be2008-12-27 04:51:36 +00001431def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001432 (COPY_TO_REGCLASS R32C:$rA, VECREG)>;
Scott Michel66377522007-12-04 22:35:58 +00001433
Scott Michelf0569be2008-12-27 04:51:36 +00001434def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001435 (COPY_TO_REGCLASS R64C:$rA, VECREG)>;
Scott Michel66377522007-12-04 22:35:58 +00001436
Scott Michelf0569be2008-12-27 04:51:36 +00001437def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001438 (COPY_TO_REGCLASS R32FP:$rA, VECREG)>;
Scott Michel66377522007-12-04 22:35:58 +00001439
Scott Michelf0569be2008-12-27 04:51:36 +00001440def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001441 (COPY_TO_REGCLASS R64FP:$rA, VECREG)>;
1442
1443def : Pat<(i8 (SPUvec2prefslot (v16i8 VECREG:$rA))),
1444 (COPY_TO_REGCLASS (v16i8 VECREG:$rA), R8C)>;
Scott Michel66377522007-12-04 22:35:58 +00001445
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001446def : Pat<(i16 (SPUvec2prefslot (v8i16 VECREG:$rA))),
1447 (COPY_TO_REGCLASS (v8i16 VECREG:$rA), R16C)>;
Scott Michel504c3692007-12-17 22:32:34 +00001448
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001449def : Pat<(i32 (SPUvec2prefslot (v4i32 VECREG:$rA))),
1450 (COPY_TO_REGCLASS (v4i32 VECREG:$rA), R32C)>;
Scott Michel504c3692007-12-17 22:32:34 +00001451
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001452def : Pat<(i64 (SPUvec2prefslot (v2i64 VECREG:$rA))),
1453 (COPY_TO_REGCLASS (v2i64 VECREG:$rA), R64C)>;
Scott Michel66377522007-12-04 22:35:58 +00001454
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001455def : Pat<(f32 (SPUvec2prefslot (v4f32 VECREG:$rA))),
1456 (COPY_TO_REGCLASS (v4f32 VECREG:$rA), R32FP)>;
Scott Michel66377522007-12-04 22:35:58 +00001457
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00001458def : Pat<(f64 (SPUvec2prefslot (v2f64 VECREG:$rA))),
1459 (COPY_TO_REGCLASS (v2f64 VECREG:$rA), R64FP)>;
Scott Michelf0569be2008-12-27 04:51:36 +00001460
1461// Load Register: This is an assembler alias for a bitwise OR of a register
1462// against itself. It's here because it brings some clarity to assembly
1463// language output.
1464
1465let hasCtrlDep = 1 in {
1466 class LRInst<dag OOL, dag IOL>
1467 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1468 bits<7> RA;
1469 bits<7> RT;
1470
1471 let Pattern = [/*no pattern*/];
1472
1473 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1474 let Inst{11-17} = RA;
1475 let Inst{18-24} = RA;
1476 let Inst{25-31} = RT;
1477 }
1478
1479 class LRVecInst<ValueType vectype>:
1480 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1481
1482 class LRRegInst<RegisterClass rclass>:
1483 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1484
1485 multiclass LoadRegister {
1486 def v2i64: LRVecInst<v2i64>;
1487 def v2f64: LRVecInst<v2f64>;
1488 def v4i32: LRVecInst<v4i32>;
1489 def v4f32: LRVecInst<v4f32>;
1490 def v8i16: LRVecInst<v8i16>;
1491 def v16i8: LRVecInst<v16i8>;
1492
1493 def r128: LRRegInst<GPRC>;
1494 def r64: LRRegInst<R64C>;
1495 def f64: LRRegInst<R64FP>;
1496 def r32: LRRegInst<R32C>;
1497 def f32: LRRegInst<R32FP>;
1498 def r16: LRRegInst<R16C>;
1499 def r8: LRRegInst<R8C>;
1500 }
1501
1502 defm LR: LoadRegister;
1503}
Scott Michel66377522007-12-04 22:35:58 +00001504
Scott Michela59d4692008-02-23 18:41:37 +00001505// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel66377522007-12-04 22:35:58 +00001506
Scott Michela59d4692008-02-23 18:41:37 +00001507class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1508 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1509 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001510
Scott Michela59d4692008-02-23 18:41:37 +00001511class ORCVecInst<ValueType vectype>:
1512 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1513 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1514 (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001515
Scott Michela59d4692008-02-23 18:41:37 +00001516class ORCRegInst<RegisterClass rclass>:
1517 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1518 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001519
Scott Michela59d4692008-02-23 18:41:37 +00001520multiclass BitwiseOrComplement
1521{
1522 def v16i8: ORCVecInst<v16i8>;
1523 def v8i16: ORCVecInst<v8i16>;
1524 def v4i32: ORCVecInst<v4i32>;
1525 def v2i64: ORCVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001526
Scott Michel6e1d1472009-03-16 18:47:25 +00001527 def r128: ORCRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00001528 def r64: ORCRegInst<R64C>;
1529 def r32: ORCRegInst<R32C>;
1530 def r16: ORCRegInst<R16C>;
1531 def r8: ORCRegInst<R8C>;
1532}
1533
1534defm ORC : BitwiseOrComplement;
Scott Michel504c3692007-12-17 22:32:34 +00001535
Scott Michel66377522007-12-04 22:35:58 +00001536// OR byte immediate
Scott Michela59d4692008-02-23 18:41:37 +00001537class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1538 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1539 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001540
Scott Michela59d4692008-02-23 18:41:37 +00001541class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1542 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1543 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1544 (vectype immpred:$val)))]>;
1545
1546multiclass BitwiseOrByteImm
1547{
1548 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1549
1550 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1551 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1552}
1553
1554defm ORBI : BitwiseOrByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001555
Scott Michel66377522007-12-04 22:35:58 +00001556// OR halfword immediate
Scott Michela59d4692008-02-23 18:41:37 +00001557class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1558 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1559 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001560
Scott Michela59d4692008-02-23 18:41:37 +00001561class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1562 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1563 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1564 immpred:$val))]>;
Scott Michel504c3692007-12-17 22:32:34 +00001565
Scott Michela59d4692008-02-23 18:41:37 +00001566multiclass BitwiseOrHalfwordImm
1567{
1568 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1569
1570 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1571 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1572
1573 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1574 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1575 [(set R16C:$rT, (or (anyext R8C:$rA),
1576 i16ImmSExt10:$val))]>;
1577}
1578
1579defm ORHI : BitwiseOrHalfwordImm;
1580
1581class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1582 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1583 IntegerOp, pattern>;
1584
1585class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1586 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1587 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1588 immpred:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001589
1590// Bitwise "or" with immediate
Scott Michela59d4692008-02-23 18:41:37 +00001591multiclass BitwiseOrImm
1592{
1593 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel66377522007-12-04 22:35:58 +00001594
Scott Michela59d4692008-02-23 18:41:37 +00001595 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1596 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001597
Scott Michela59d4692008-02-23 18:41:37 +00001598 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1599 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1600 // infra "anyext 16->32" pattern.)
1601 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1602 [(set R32C:$rT, (or (anyext R16C:$rA),
1603 i32ImmSExt10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001604
Scott Michela59d4692008-02-23 18:41:37 +00001605 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1606 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1607 // infra "anyext 16->32" pattern.)
1608 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1609 [(set R32C:$rT, (or (anyext R8C:$rA),
1610 i32ImmSExt10:$val))]>;
1611}
Scott Michel66377522007-12-04 22:35:58 +00001612
Scott Michela59d4692008-02-23 18:41:37 +00001613defm ORI : BitwiseOrImm;
Scott Michel504c3692007-12-17 22:32:34 +00001614
Scott Michel66377522007-12-04 22:35:58 +00001615// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1616// $rT[0], slots 1-3 are zeroed.
1617//
Scott Michel504c3692007-12-17 22:32:34 +00001618// FIXME: Needs to match an intrinsic pattern.
Scott Michel66377522007-12-04 22:35:58 +00001619def ORXv4i32:
1620 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1621 "orx\t$rT, $rA, $rB", IntegerOp,
1622 []>;
1623
Scott Michel504c3692007-12-17 22:32:34 +00001624// XOR:
Scott Michel66377522007-12-04 22:35:58 +00001625
Scott Michelad2715e2008-03-05 23:02:02 +00001626class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1627 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1628 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001629
Scott Michelad2715e2008-03-05 23:02:02 +00001630class XORVecInst<ValueType vectype>:
1631 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1632 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1633 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001634
Scott Michelad2715e2008-03-05 23:02:02 +00001635class XORRegInst<RegisterClass rclass>:
1636 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1637 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1638
1639multiclass BitwiseExclusiveOr
1640{
1641 def v16i8: XORVecInst<v16i8>;
1642 def v8i16: XORVecInst<v8i16>;
1643 def v4i32: XORVecInst<v4i32>;
1644 def v2i64: XORVecInst<v2i64>;
1645
1646 def r128: XORRegInst<GPRC>;
1647 def r64: XORRegInst<R64C>;
1648 def r32: XORRegInst<R32C>;
1649 def r16: XORRegInst<R16C>;
1650 def r8: XORRegInst<R8C>;
Scott Michela82d3f72009-03-17 16:45:16 +00001651
1652 // XOR instructions used to negate f32 and f64 quantities.
1653
1654 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1655 [/* no pattern */]>;
1656
1657 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1658 [/* no pattern */]>;
1659
1660 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1661 [/* no pattern, see fneg{32,64} */]>;
Scott Michelad2715e2008-03-05 23:02:02 +00001662}
1663
1664defm XOR : BitwiseExclusiveOr;
Scott Michel66377522007-12-04 22:35:58 +00001665
1666//==----------------------------------------------------------
Scott Michel504c3692007-12-17 22:32:34 +00001667
Scott Michela59d4692008-02-23 18:41:37 +00001668class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1669 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1670 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001671
Scott Michela59d4692008-02-23 18:41:37 +00001672multiclass XorByteImm
1673{
1674 def v16i8:
1675 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1676 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1677
1678 def r8:
1679 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1680 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1681}
1682
1683defm XORBI : XorByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001684
Scott Michel66377522007-12-04 22:35:58 +00001685def XORHIv8i16:
Scott Michela59d4692008-02-23 18:41:37 +00001686 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel66377522007-12-04 22:35:58 +00001687 "xorhi\t$rT, $rA, $val", IntegerOp,
1688 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1689 v8i16SExt10Imm:$val))]>;
1690
1691def XORHIr16:
1692 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1693 "xorhi\t$rT, $rA, $val", IntegerOp,
1694 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1695
1696def XORIv4i32:
Scott Michel78c47fa2008-03-10 16:58:52 +00001697 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel66377522007-12-04 22:35:58 +00001698 "xori\t$rT, $rA, $val", IntegerOp,
1699 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1700 v4i32SExt10Imm:$val))]>;
1701
1702def XORIr32:
1703 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1704 "xori\t$rT, $rA, $val", IntegerOp,
1705 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1706
1707// NAND:
Scott Michel66377522007-12-04 22:35:58 +00001708
Scott Michel6e1d1472009-03-16 18:47:25 +00001709class NANDInst<dag OOL, dag IOL, list<dag> pattern>:
1710 RRForm<0b10010011000, OOL, IOL, "nand\t$rT, $rA, $rB",
1711 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001712
Scott Michel6e1d1472009-03-16 18:47:25 +00001713class NANDVecInst<ValueType vectype>:
1714 NANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1715 [(set (vectype VECREG:$rT), (vnot (and (vectype VECREG:$rA),
1716 (vectype VECREG:$rB))))]>;
1717class NANDRegInst<RegisterClass rclass>:
1718 NANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1719 [(set rclass:$rT, (not (and rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001720
Scott Michel6e1d1472009-03-16 18:47:25 +00001721multiclass BitwiseNand
1722{
1723 def v16i8: NANDVecInst<v16i8>;
1724 def v8i16: NANDVecInst<v8i16>;
1725 def v4i32: NANDVecInst<v4i32>;
1726 def v2i64: NANDVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001727
Scott Michel6e1d1472009-03-16 18:47:25 +00001728 def r128: NANDRegInst<GPRC>;
1729 def r64: NANDRegInst<R64C>;
1730 def r32: NANDRegInst<R32C>;
1731 def r16: NANDRegInst<R16C>;
1732 def r8: NANDRegInst<R8C>;
1733}
Scott Michel66377522007-12-04 22:35:58 +00001734
Scott Michel6e1d1472009-03-16 18:47:25 +00001735defm NAND : BitwiseNand;
Scott Michel504c3692007-12-17 22:32:34 +00001736
Scott Michel66377522007-12-04 22:35:58 +00001737// NOR:
Scott Michel66377522007-12-04 22:35:58 +00001738
Scott Michel6e1d1472009-03-16 18:47:25 +00001739class NORInst<dag OOL, dag IOL, list<dag> pattern>:
1740 RRForm<0b10010010000, OOL, IOL, "nor\t$rT, $rA, $rB",
1741 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001742
Scott Michel6e1d1472009-03-16 18:47:25 +00001743class NORVecInst<ValueType vectype>:
1744 NORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1745 [(set (vectype VECREG:$rT), (vnot (or (vectype VECREG:$rA),
1746 (vectype VECREG:$rB))))]>;
1747class NORRegInst<RegisterClass rclass>:
1748 NORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1749 [(set rclass:$rT, (not (or rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001750
Scott Michel6e1d1472009-03-16 18:47:25 +00001751multiclass BitwiseNor
1752{
1753 def v16i8: NORVecInst<v16i8>;
1754 def v8i16: NORVecInst<v8i16>;
1755 def v4i32: NORVecInst<v4i32>;
1756 def v2i64: NORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001757
Scott Michel6e1d1472009-03-16 18:47:25 +00001758 def r128: NORRegInst<GPRC>;
1759 def r64: NORRegInst<R64C>;
1760 def r32: NORRegInst<R32C>;
1761 def r16: NORRegInst<R16C>;
1762 def r8: NORRegInst<R8C>;
1763}
Scott Michel66377522007-12-04 22:35:58 +00001764
Scott Michel6e1d1472009-03-16 18:47:25 +00001765defm NOR : BitwiseNor;
Scott Michel504c3692007-12-17 22:32:34 +00001766
Scott Michel66377522007-12-04 22:35:58 +00001767// Select bits:
Scott Michelad2715e2008-03-05 23:02:02 +00001768class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1769 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1770 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001771
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001772class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michelad2715e2008-03-05 23:02:02 +00001773 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1774 [(set (vectype VECREG:$rT),
1775 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001776 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michelad2715e2008-03-05 23:02:02 +00001777 (vectype VECREG:$rA))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001778
Scott Michel02d711b2008-12-30 23:28:25 +00001779class SELBVecVCondInst<ValueType vectype>:
1780 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1781 [(set (vectype VECREG:$rT),
1782 (select (vectype VECREG:$rC),
1783 (vectype VECREG:$rB),
1784 (vectype VECREG:$rA)))]>;
1785
Scott Michelf0569be2008-12-27 04:51:36 +00001786class SELBVecCondInst<ValueType vectype>:
1787 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1788 [(set (vectype VECREG:$rT),
1789 (select R32C:$rC,
1790 (vectype VECREG:$rB),
1791 (vectype VECREG:$rA)))]>;
1792
Scott Michelad2715e2008-03-05 23:02:02 +00001793class SELBRegInst<RegisterClass rclass>:
1794 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1795 [(set rclass:$rT,
Scott Michel1df30c42008-12-29 03:23:36 +00001796 (or (and rclass:$rB, rclass:$rC),
1797 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001798
Scott Michelf0569be2008-12-27 04:51:36 +00001799class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1800 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1801 [(set rclass:$rT,
1802 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1803
Scott Michelad2715e2008-03-05 23:02:02 +00001804multiclass SelectBits
1805{
1806 def v16i8: SELBVecInst<v16i8>;
1807 def v8i16: SELBVecInst<v8i16>;
1808 def v4i32: SELBVecInst<v4i32>;
Chris Lattner918472a2010-03-28 07:48:17 +00001809 def v2i64: SELBVecInst<v2i64, vnot_cell_conv>;
Scott Michel66377522007-12-04 22:35:58 +00001810
Scott Michelad2715e2008-03-05 23:02:02 +00001811 def r128: SELBRegInst<GPRC>;
1812 def r64: SELBRegInst<R64C>;
1813 def r32: SELBRegInst<R32C>;
1814 def r16: SELBRegInst<R16C>;
1815 def r8: SELBRegInst<R8C>;
Scott Michelf0569be2008-12-27 04:51:36 +00001816
1817 def v16i8_cond: SELBVecCondInst<v16i8>;
1818 def v8i16_cond: SELBVecCondInst<v8i16>;
1819 def v4i32_cond: SELBVecCondInst<v4i32>;
1820 def v2i64_cond: SELBVecCondInst<v2i64>;
1821
Scott Michel02d711b2008-12-30 23:28:25 +00001822 def v16i8_vcond: SELBVecCondInst<v16i8>;
1823 def v8i16_vcond: SELBVecCondInst<v8i16>;
1824 def v4i32_vcond: SELBVecCondInst<v4i32>;
1825 def v2i64_vcond: SELBVecCondInst<v2i64>;
1826
1827 def v4f32_cond:
Scott Michel19c10e62009-01-26 03:37:41 +00001828 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1829 [(set (v4f32 VECREG:$rT),
1830 (select (v4i32 VECREG:$rC),
1831 (v4f32 VECREG:$rB),
1832 (v4f32 VECREG:$rA)))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00001833
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001834 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michelf0569be2008-12-27 04:51:36 +00001835 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel02d711b2008-12-30 23:28:25 +00001836 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michelf0569be2008-12-27 04:51:36 +00001837 def r16_cond: SELBRegCondInst<R16C, R16C>;
1838 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michelad2715e2008-03-05 23:02:02 +00001839}
Scott Michel66377522007-12-04 22:35:58 +00001840
Scott Michelad2715e2008-03-05 23:02:02 +00001841defm SELB : SelectBits;
Scott Michel66377522007-12-04 22:35:58 +00001842
Scott Michel7a1c9e92008-11-22 23:50:42 +00001843class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michelad2715e2008-03-05 23:02:02 +00001844 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1845 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel66377522007-12-04 22:35:58 +00001846
Scott Michel7a1c9e92008-11-22 23:50:42 +00001847def : SPUselbPatVec<v16i8, SELBv16i8>;
1848def : SPUselbPatVec<v8i16, SELBv8i16>;
1849def : SPUselbPatVec<v4i32, SELBv4i32>;
1850def : SPUselbPatVec<v2i64, SELBv2i64>;
1851
1852class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1853 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1854 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1855
1856def : SPUselbPatReg<R8C, SELBr8>;
1857def : SPUselbPatReg<R16C, SELBr16>;
1858def : SPUselbPatReg<R32C, SELBr32>;
1859def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel66377522007-12-04 22:35:58 +00001860
Scott Michelad2715e2008-03-05 23:02:02 +00001861// EQV: Equivalence (1 for each same bit, otherwise 0)
1862//
1863// Note: There are a lot of ways to match this bit operator and these patterns
1864// attempt to be as exhaustive as possible.
Scott Michel66377522007-12-04 22:35:58 +00001865
Scott Michelad2715e2008-03-05 23:02:02 +00001866class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1867 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1868 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001869
Scott Michelad2715e2008-03-05 23:02:02 +00001870class EQVVecInst<ValueType vectype>:
1871 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1872 [(set (vectype VECREG:$rT),
1873 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1874 (and (vnot (vectype VECREG:$rA)),
1875 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001876
Scott Michelad2715e2008-03-05 23:02:02 +00001877class EQVRegInst<RegisterClass rclass>:
1878 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1879 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1880 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001881
Scott Michelad2715e2008-03-05 23:02:02 +00001882class EQVVecPattern1<ValueType vectype>:
1883 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1884 [(set (vectype VECREG:$rT),
1885 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001886
Scott Michelad2715e2008-03-05 23:02:02 +00001887class EQVRegPattern1<RegisterClass rclass>:
1888 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1889 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001890
Scott Michelad2715e2008-03-05 23:02:02 +00001891class EQVVecPattern2<ValueType vectype>:
1892 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1893 [(set (vectype VECREG:$rT),
1894 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1895 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001896
Scott Michelad2715e2008-03-05 23:02:02 +00001897class EQVRegPattern2<RegisterClass rclass>:
1898 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1899 [(set rclass:$rT,
1900 (or (and rclass:$rA, rclass:$rB),
1901 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001902
Scott Michelad2715e2008-03-05 23:02:02 +00001903class EQVVecPattern3<ValueType vectype>:
1904 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1905 [(set (vectype VECREG:$rT),
1906 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001907
Scott Michelad2715e2008-03-05 23:02:02 +00001908class EQVRegPattern3<RegisterClass rclass>:
1909 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1910 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001911
Scott Michelad2715e2008-03-05 23:02:02 +00001912multiclass BitEquivalence
1913{
1914 def v16i8: EQVVecInst<v16i8>;
1915 def v8i16: EQVVecInst<v8i16>;
1916 def v4i32: EQVVecInst<v4i32>;
1917 def v2i64: EQVVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001918
Scott Michelad2715e2008-03-05 23:02:02 +00001919 def v16i8_1: EQVVecPattern1<v16i8>;
1920 def v8i16_1: EQVVecPattern1<v8i16>;
1921 def v4i32_1: EQVVecPattern1<v4i32>;
1922 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001923
Scott Michelad2715e2008-03-05 23:02:02 +00001924 def v16i8_2: EQVVecPattern2<v16i8>;
1925 def v8i16_2: EQVVecPattern2<v8i16>;
1926 def v4i32_2: EQVVecPattern2<v4i32>;
1927 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001928
Scott Michelad2715e2008-03-05 23:02:02 +00001929 def v16i8_3: EQVVecPattern3<v16i8>;
1930 def v8i16_3: EQVVecPattern3<v8i16>;
1931 def v4i32_3: EQVVecPattern3<v4i32>;
1932 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001933
Scott Michelad2715e2008-03-05 23:02:02 +00001934 def r128: EQVRegInst<GPRC>;
1935 def r64: EQVRegInst<R64C>;
1936 def r32: EQVRegInst<R32C>;
1937 def r16: EQVRegInst<R16C>;
1938 def r8: EQVRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001939
Scott Michelad2715e2008-03-05 23:02:02 +00001940 def r128_1: EQVRegPattern1<GPRC>;
1941 def r64_1: EQVRegPattern1<R64C>;
1942 def r32_1: EQVRegPattern1<R32C>;
1943 def r16_1: EQVRegPattern1<R16C>;
1944 def r8_1: EQVRegPattern1<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001945
Scott Michelad2715e2008-03-05 23:02:02 +00001946 def r128_2: EQVRegPattern2<GPRC>;
1947 def r64_2: EQVRegPattern2<R64C>;
1948 def r32_2: EQVRegPattern2<R32C>;
1949 def r16_2: EQVRegPattern2<R16C>;
1950 def r8_2: EQVRegPattern2<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001951
Scott Michelad2715e2008-03-05 23:02:02 +00001952 def r128_3: EQVRegPattern3<GPRC>;
1953 def r64_3: EQVRegPattern3<R64C>;
1954 def r32_3: EQVRegPattern3<R32C>;
1955 def r16_3: EQVRegPattern3<R16C>;
1956 def r8_3: EQVRegPattern3<R8C>;
1957}
Scott Michel504c3692007-12-17 22:32:34 +00001958
Scott Michelad2715e2008-03-05 23:02:02 +00001959defm EQV: BitEquivalence;
Scott Michel66377522007-12-04 22:35:58 +00001960
1961//===----------------------------------------------------------------------===//
1962// Vector shuffle...
1963//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00001964// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
1965// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
1966// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
1967// the SPUISD::SHUFB opcode.
Scott Michela59d4692008-02-23 18:41:37 +00001968//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00001969
Scott Michela59d4692008-02-23 18:41:37 +00001970class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
1971 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
1972 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001973
Scott Michel1a6cdb62008-12-01 17:56:02 +00001974class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michela59d4692008-02-23 18:41:37 +00001975 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel1a6cdb62008-12-01 17:56:02 +00001976 [(set (resultvec VECREG:$rT),
1977 (SPUshuffle (resultvec VECREG:$rA),
1978 (resultvec VECREG:$rB),
1979 (maskvec VECREG:$rC)))]>;
Scott Michel86c041f2007-12-20 00:44:13 +00001980
Scott Michelf0569be2008-12-27 04:51:36 +00001981class SHUFBGPRCInst:
1982 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
1983 [/* no pattern */]>;
1984
Scott Michela59d4692008-02-23 18:41:37 +00001985multiclass ShuffleBytes
1986{
Scott Michel1a6cdb62008-12-01 17:56:02 +00001987 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
1988 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
1989 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
1990 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
1991 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
1992 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
1993 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
1994 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel66377522007-12-04 22:35:58 +00001995
Scott Michel1a6cdb62008-12-01 17:56:02 +00001996 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
1997 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
1998
1999 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2000 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michelf0569be2008-12-27 04:51:36 +00002001
2002 def gprc : SHUFBGPRCInst;
Scott Michela59d4692008-02-23 18:41:37 +00002003}
2004
2005defm SHUFB : ShuffleBytes;
2006
Scott Michel66377522007-12-04 22:35:58 +00002007//===----------------------------------------------------------------------===//
2008// Shift and rotate group:
2009//===----------------------------------------------------------------------===//
2010
Scott Michela59d4692008-02-23 18:41:37 +00002011class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2012 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2013 RotateShift, pattern>;
2014
2015class SHLHVecInst<ValueType vectype>:
2016 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2017 [(set (vectype VECREG:$rT),
2018 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002019
Scott Michela59d4692008-02-23 18:41:37 +00002020multiclass ShiftLeftHalfword
2021{
2022 def v8i16: SHLHVecInst<v8i16>;
2023 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2024 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2025 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2026 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2027}
Scott Michel66377522007-12-04 22:35:58 +00002028
Scott Michela59d4692008-02-23 18:41:37 +00002029defm SHLH : ShiftLeftHalfword;
Scott Michel66377522007-12-04 22:35:58 +00002030
Scott Michela59d4692008-02-23 18:41:37 +00002031//===----------------------------------------------------------------------===//
Scott Michel504c3692007-12-17 22:32:34 +00002032
Scott Michela59d4692008-02-23 18:41:37 +00002033class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2034 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2035 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002036
Scott Michela59d4692008-02-23 18:41:37 +00002037class SHLHIVecInst<ValueType vectype>:
2038 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2039 [(set (vectype VECREG:$rT),
2040 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002041
Scott Michela59d4692008-02-23 18:41:37 +00002042multiclass ShiftLeftHalfwordImm
2043{
2044 def v8i16: SHLHIVecInst<v8i16>;
2045 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2046 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2047}
2048
2049defm SHLHI : ShiftLeftHalfwordImm;
2050
2051def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002052 (SHLHIv8i16 VECREG:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michela59d4692008-02-23 18:41:37 +00002053
2054def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002055 (SHLHIr16 R16C:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002056
Scott Michela59d4692008-02-23 18:41:37 +00002057//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002058
Scott Michela59d4692008-02-23 18:41:37 +00002059class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2060 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2061 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002062
Scott Michela59d4692008-02-23 18:41:37 +00002063multiclass ShiftLeftWord
2064{
2065 def v4i32:
2066 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2067 [(set (v4i32 VECREG:$rT),
2068 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2069 def r32:
2070 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2071 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2072}
Scott Michel66377522007-12-04 22:35:58 +00002073
Scott Michela59d4692008-02-23 18:41:37 +00002074defm SHL: ShiftLeftWord;
Scott Michel504c3692007-12-17 22:32:34 +00002075
Scott Michela59d4692008-02-23 18:41:37 +00002076//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002077
Scott Michela59d4692008-02-23 18:41:37 +00002078class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2079 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2080 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002081
Scott Michela59d4692008-02-23 18:41:37 +00002082multiclass ShiftLeftWordImm
2083{
2084 def v4i32:
2085 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2086 [(set (v4i32 VECREG:$rT),
2087 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002088
Scott Michela59d4692008-02-23 18:41:37 +00002089 def r32:
2090 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2091 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2092}
Scott Michel66377522007-12-04 22:35:58 +00002093
Scott Michela59d4692008-02-23 18:41:37 +00002094defm SHLI : ShiftLeftWordImm;
Scott Michel504c3692007-12-17 22:32:34 +00002095
Scott Michela59d4692008-02-23 18:41:37 +00002096//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002097// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2098// register) to the left. Vector form is here to ensure type correctness.
Scott Michela59d4692008-02-23 18:41:37 +00002099//
2100// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2101// of 7 bits is actually possible.
2102//
2103// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2104// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2105// bytes with SHLQBY.
Scott Michel66377522007-12-04 22:35:58 +00002106
Scott Michela59d4692008-02-23 18:41:37 +00002107class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2108 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2109 RotateShift, pattern>;
2110
2111class SHLQBIVecInst<ValueType vectype>:
2112 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2113 [(set (vectype VECREG:$rT),
2114 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2115
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002116class SHLQBIRegInst<RegisterClass rclass>:
2117 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2118 [/* no pattern */]>;
2119
Scott Michela59d4692008-02-23 18:41:37 +00002120multiclass ShiftLeftQuadByBits
2121{
2122 def v16i8: SHLQBIVecInst<v16i8>;
2123 def v8i16: SHLQBIVecInst<v8i16>;
2124 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002125 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002126 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002127 def v2f64: SHLQBIVecInst<v2f64>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002128
2129 def r128: SHLQBIRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00002130}
2131
2132defm SHLQBI : ShiftLeftQuadByBits;
2133
2134// See note above on SHLQBI. In this case, the predicate actually does then
2135// enforcement, whereas with SHLQBI, we have to "take it on faith."
2136class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2137 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2138 RotateShift, pattern>;
2139
2140class SHLQBIIVecInst<ValueType vectype>:
2141 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2142 [(set (vectype VECREG:$rT),
2143 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2144
2145multiclass ShiftLeftQuadByBitsImm
2146{
2147 def v16i8 : SHLQBIIVecInst<v16i8>;
2148 def v8i16 : SHLQBIIVecInst<v8i16>;
2149 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002150 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002151 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002152 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002153}
2154
2155defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel66377522007-12-04 22:35:58 +00002156
2157// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michela59d4692008-02-23 18:41:37 +00002158// not by bits. See notes above on SHLQBI.
Scott Michel66377522007-12-04 22:35:58 +00002159
Scott Michela59d4692008-02-23 18:41:37 +00002160class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel662165d2008-11-25 00:23:16 +00002161 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00002162 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002163
Scott Michela59d4692008-02-23 18:41:37 +00002164class SHLQBYVecInst<ValueType vectype>:
2165 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2166 [(set (vectype VECREG:$rT),
2167 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002168
Scott Michela59d4692008-02-23 18:41:37 +00002169multiclass ShiftLeftQuadBytes
2170{
2171 def v16i8: SHLQBYVecInst<v16i8>;
2172 def v8i16: SHLQBYVecInst<v8i16>;
2173 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002174 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002175 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002176 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002177 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2178 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2179}
Scott Michel66377522007-12-04 22:35:58 +00002180
Scott Michela59d4692008-02-23 18:41:37 +00002181defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel66377522007-12-04 22:35:58 +00002182
Scott Michela59d4692008-02-23 18:41:37 +00002183class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2184 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2185 RotateShift, pattern>;
Scott Michel504c3692007-12-17 22:32:34 +00002186
Scott Michela59d4692008-02-23 18:41:37 +00002187class SHLQBYIVecInst<ValueType vectype>:
2188 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2189 [(set (vectype VECREG:$rT),
2190 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002191
Scott Michela59d4692008-02-23 18:41:37 +00002192multiclass ShiftLeftQuadBytesImm
2193{
2194 def v16i8: SHLQBYIVecInst<v16i8>;
2195 def v8i16: SHLQBYIVecInst<v8i16>;
2196 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002197 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002198 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002199 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002200 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2201 [(set GPRC:$rT,
2202 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2203}
Scott Michel504c3692007-12-17 22:32:34 +00002204
Scott Michela59d4692008-02-23 18:41:37 +00002205defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel504c3692007-12-17 22:32:34 +00002206
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002207class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2208 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2209 RotateShift, pattern>;
2210
2211class SHLQBYBIVecInst<ValueType vectype>:
2212 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2213 [/* no pattern */]>;
2214
2215class SHLQBYBIRegInst<RegisterClass rclass>:
2216 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2217 [/* no pattern */]>;
2218
2219multiclass ShiftLeftQuadBytesBitCount
2220{
2221 def v16i8: SHLQBYBIVecInst<v16i8>;
2222 def v8i16: SHLQBYBIVecInst<v8i16>;
2223 def v4i32: SHLQBYBIVecInst<v4i32>;
2224 def v4f32: SHLQBYBIVecInst<v4f32>;
2225 def v2i64: SHLQBYBIVecInst<v2i64>;
2226 def v2f64: SHLQBYBIVecInst<v2f64>;
2227
2228 def r128: SHLQBYBIRegInst<GPRC>;
2229}
2230
2231defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2232
Scott Michela59d4692008-02-23 18:41:37 +00002233//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2234// Rotate halfword:
2235//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2236class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2237 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2238 RotateShift, pattern>;
2239
2240class ROTHVecInst<ValueType vectype>:
2241 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2242 [(set (vectype VECREG:$rT),
Chris Lattnerdd6fbd12010-03-08 18:59:49 +00002243 (SPUvec_rotl VECREG:$rA, (v8i16 VECREG:$rB)))]>;
Scott Michela59d4692008-02-23 18:41:37 +00002244
2245class ROTHRegInst<RegisterClass rclass>:
2246 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2247 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2248
2249multiclass RotateLeftHalfword
2250{
2251 def v8i16: ROTHVecInst<v8i16>;
2252 def r16: ROTHRegInst<R16C>;
2253}
2254
2255defm ROTH: RotateLeftHalfword;
2256
2257def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2258 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2259
2260//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2261// Rotate halfword, immediate:
2262//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2263class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2264 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2265 RotateShift, pattern>;
2266
2267class ROTHIVecInst<ValueType vectype>:
2268 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2269 [(set (vectype VECREG:$rT),
2270 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2271
2272multiclass RotateLeftHalfwordImm
2273{
2274 def v8i16: ROTHIVecInst<v8i16>;
2275 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2276 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2277 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2278 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2279}
2280
2281defm ROTHI: RotateLeftHalfwordImm;
2282
Chris Lattner420c69d2010-03-15 05:53:47 +00002283def : Pat<(SPUvec_rotl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2284 (ROTHIv8i16 VECREG:$rA, (TO_IMM16 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002285
Scott Michela59d4692008-02-23 18:41:37 +00002286//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2287// Rotate word:
2288//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002289
Scott Michela59d4692008-02-23 18:41:37 +00002290class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2291 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2292 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002293
Scott Michela59d4692008-02-23 18:41:37 +00002294class ROTVecInst<ValueType vectype>:
2295 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2296 [(set (vectype VECREG:$rT),
2297 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002298
Scott Michela59d4692008-02-23 18:41:37 +00002299class ROTRegInst<RegisterClass rclass>:
2300 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2301 [(set rclass:$rT,
2302 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002303
Scott Michela59d4692008-02-23 18:41:37 +00002304multiclass RotateLeftWord
2305{
2306 def v4i32: ROTVecInst<v4i32>;
2307 def r32: ROTRegInst<R32C>;
2308}
2309
2310defm ROT: RotateLeftWord;
Scott Michel66377522007-12-04 22:35:58 +00002311
Scott Michel504c3692007-12-17 22:32:34 +00002312// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2313// 32-bit register
2314def ROTr32_r16_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002315 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2316 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002317
2318def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2319 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2320
2321def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2322 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2323
2324def ROTr32_r8_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002325 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2326 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002327
2328def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2329 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2330
2331def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2332 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2333
Scott Michela59d4692008-02-23 18:41:37 +00002334//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2335// Rotate word, immediate
2336//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002337
Scott Michela59d4692008-02-23 18:41:37 +00002338class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2339 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2340 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002341
Scott Michela59d4692008-02-23 18:41:37 +00002342class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2343 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2344 [(set (vectype VECREG:$rT),
2345 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002346
Scott Michela59d4692008-02-23 18:41:37 +00002347class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2348 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2349 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002350
Scott Michela59d4692008-02-23 18:41:37 +00002351multiclass RotateLeftWordImm
2352{
2353 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2354 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2355 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel66377522007-12-04 22:35:58 +00002356
Scott Michela59d4692008-02-23 18:41:37 +00002357 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2358 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2359 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2360}
Scott Michel504c3692007-12-17 22:32:34 +00002361
Scott Michela59d4692008-02-23 18:41:37 +00002362defm ROTI : RotateLeftWordImm;
2363
2364//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2365// Rotate quad by byte (count)
2366//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2367
2368class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2369 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2370 RotateShift, pattern>;
2371
2372class ROTQBYVecInst<ValueType vectype>:
2373 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2374 [(set (vectype VECREG:$rT),
2375 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2376
2377multiclass RotateQuadLeftByBytes
2378{
2379 def v16i8: ROTQBYVecInst<v16i8>;
2380 def v8i16: ROTQBYVecInst<v8i16>;
2381 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002382 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002383 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002384 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002385}
2386
2387defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel66377522007-12-04 22:35:58 +00002388
Scott Michela59d4692008-02-23 18:41:37 +00002389//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2390// Rotate quad by byte (count), immediate
2391//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2392
2393class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2394 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2395 RotateShift, pattern>;
2396
2397class ROTQBYIVecInst<ValueType vectype>:
2398 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2399 [(set (vectype VECREG:$rT),
2400 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2401
2402multiclass RotateQuadByBytesImm
2403{
2404 def v16i8: ROTQBYIVecInst<v16i8>;
2405 def v8i16: ROTQBYIVecInst<v8i16>;
2406 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002407 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002408 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002409 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002410}
2411
2412defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel66377522007-12-04 22:35:58 +00002413
Scott Michel66377522007-12-04 22:35:58 +00002414// See ROTQBY note above.
Scott Michel8bf61e82008-06-02 22:18:03 +00002415class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2416 RI7Form<0b00110011100, OOL, IOL,
2417 "rotqbybi\t$rT, $rA, $shift",
2418 RotateShift, pattern>;
2419
2420class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2421 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2422 [(set (vectype VECREG:$rT),
2423 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2424
2425multiclass RotateQuadByBytesByBitshift {
2426 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2427 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2428 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2429 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2430}
2431
2432defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel66377522007-12-04 22:35:58 +00002433
Scott Michela59d4692008-02-23 18:41:37 +00002434//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002435// See ROTQBY note above.
2436//
2437// Assume that the user of this instruction knows to shift the rotate count
2438// into bit 29
Scott Michela59d4692008-02-23 18:41:37 +00002439//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002440
Scott Michela59d4692008-02-23 18:41:37 +00002441class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2442 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2443 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002444
Scott Michela59d4692008-02-23 18:41:37 +00002445class ROTQBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002446 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002447 [/* no pattern yet */]>;
2448
2449class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel02d711b2008-12-30 23:28:25 +00002450 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002451 [/* no pattern yet */]>;
2452
2453multiclass RotateQuadByBitCount
2454{
2455 def v16i8: ROTQBIVecInst<v16i8>;
2456 def v8i16: ROTQBIVecInst<v8i16>;
2457 def v4i32: ROTQBIVecInst<v4i32>;
2458 def v2i64: ROTQBIVecInst<v2i64>;
2459
2460 def r128: ROTQBIRegInst<GPRC>;
2461 def r64: ROTQBIRegInst<R64C>;
2462}
2463
2464defm ROTQBI: RotateQuadByBitCount;
Scott Michelf0569be2008-12-27 04:51:36 +00002465
Scott Michela59d4692008-02-23 18:41:37 +00002466class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2467 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2468 RotateShift, pattern>;
2469
2470class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2471 PatLeaf pred>:
2472 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2473 [/* no pattern yet */]>;
2474
2475class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2476 PatLeaf pred>:
2477 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2478 [/* no pattern yet */]>;
2479
2480multiclass RotateQuadByBitCountImm
2481{
2482 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2483 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2484 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2485 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2486
2487 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2488 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2489}
2490
2491defm ROTQBII : RotateQuadByBitCountImm;
2492
2493//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002494// ROTHM v8i16 form:
2495// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2496// so this only matches a synthetically generated/lowered code
2497// fragment.
2498// NOTE(2): $rB must be negated before the right rotate!
Scott Michela59d4692008-02-23 18:41:37 +00002499//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002500
Scott Michela59d4692008-02-23 18:41:37 +00002501class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2502 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2503 RotateShift, pattern>;
2504
2505def ROTHMv8i16:
2506 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2507 [/* see patterns below - $rB must be negated */]>;
2508
2509def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002510 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2511
Scott Michela59d4692008-02-23 18:41:37 +00002512def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002513 (ROTHMv8i16 VECREG:$rA,
2514 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2515
Scott Michela59d4692008-02-23 18:41:37 +00002516def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002517 (ROTHMv8i16 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002518 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002519
2520// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2521// Note: This instruction doesn't match a pattern because rB must be negated
2522// for the instruction to work. Thus, the pattern below the instruction!
Scott Michela59d4692008-02-23 18:41:37 +00002523
Scott Michel66377522007-12-04 22:35:58 +00002524def ROTHMr16:
Scott Michela59d4692008-02-23 18:41:37 +00002525 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2526 [/* see patterns below - $rB must be negated! */]>;
Scott Michel66377522007-12-04 22:35:58 +00002527
2528def : Pat<(srl R16C:$rA, R32C:$rB),
2529 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2530
2531def : Pat<(srl R16C:$rA, R16C:$rB),
2532 (ROTHMr16 R16C:$rA,
2533 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2534
Scott Michel504c3692007-12-17 22:32:34 +00002535def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002536 (ROTHMr16 R16C:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002537 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002538
2539// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2540// that the immediate can be complemented, so that the user doesn't have to
2541// worry about it.
Scott Michel66377522007-12-04 22:35:58 +00002542
Scott Michela59d4692008-02-23 18:41:37 +00002543class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2544 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2545 RotateShift, pattern>;
2546
2547def ROTHMIv8i16:
2548 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2549 [/* no pattern */]>;
2550
2551def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2552 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2553
2554def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002555 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002556
Scott Michela59d4692008-02-23 18:41:37 +00002557def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002558 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002559
2560def ROTHMIr16:
Scott Michela59d4692008-02-23 18:41:37 +00002561 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2562 [/* no pattern */]>;
2563
2564def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2565 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel66377522007-12-04 22:35:58 +00002566
2567def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002568 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002569
Scott Michel504c3692007-12-17 22:32:34 +00002570def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002571 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002572
Scott Michel66377522007-12-04 22:35:58 +00002573// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michela59d4692008-02-23 18:41:37 +00002574class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2575 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2576 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002577
Scott Michela59d4692008-02-23 18:41:37 +00002578def ROTMv4i32:
2579 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2580 [/* see patterns below - $rB must be negated */]>;
2581
Chris Lattner420c69d2010-03-15 05:53:47 +00002582def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002583 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2584
Chris Lattner420c69d2010-03-15 05:53:47 +00002585def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002586 (ROTMv4i32 VECREG:$rA,
2587 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2588
Chris Lattner420c69d2010-03-15 05:53:47 +00002589def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002590 (ROTMv4i32 VECREG:$rA,
Scott Michela59d4692008-02-23 18:41:37 +00002591 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002592
2593def ROTMr32:
Scott Michela59d4692008-02-23 18:41:37 +00002594 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2595 [/* see patterns below - $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002596
2597def : Pat<(srl R32C:$rA, R32C:$rB),
2598 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2599
2600def : Pat<(srl R32C:$rA, R16C:$rB),
2601 (ROTMr32 R32C:$rA,
2602 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2603
Scott Michel504c3692007-12-17 22:32:34 +00002604def : Pat<(srl R32C:$rA, R8C:$rB),
2605 (ROTMr32 R32C:$rA,
2606 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2607
Scott Michel66377522007-12-04 22:35:58 +00002608// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2609def ROTMIv4i32:
2610 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2611 "rotmi\t$rT, $rA, $val", RotateShift,
2612 [(set (v4i32 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00002613 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002614
Chris Lattner420c69d2010-03-15 05:53:47 +00002615def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2616 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002617
Chris Lattner420c69d2010-03-15 05:53:47 +00002618def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i8 uimm7:$val)),
2619 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002620
2621// ROTMI r32 form: know how to complement the immediate value.
2622def ROTMIr32:
2623 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2624 "rotmi\t$rT, $rA, $val", RotateShift,
2625 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2626
2627def : Pat<(srl R32C:$rA, (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002628 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002629
Scott Michel504c3692007-12-17 22:32:34 +00002630def : Pat<(srl R32C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002631 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002632
Scott Michela59d4692008-02-23 18:41:37 +00002633//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Micheldd950092009-01-06 03:36:14 +00002634// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel66377522007-12-04 22:35:58 +00002635// instruction pattern, type checking will succeed. This instruction assumes
Scott Michela59d4692008-02-23 18:41:37 +00002636// that the user knew to negate $rB.
Scott Michela59d4692008-02-23 18:41:37 +00002637//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002638
Scott Michela59d4692008-02-23 18:41:37 +00002639class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2640 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2641 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002642
Scott Michela59d4692008-02-23 18:41:37 +00002643class ROTQMBYVecInst<ValueType vectype>:
2644 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2645 [/* no pattern, $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002646
Scott Michela59d4692008-02-23 18:41:37 +00002647class ROTQMBYRegInst<RegisterClass rclass>:
2648 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00002649 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00002650
Scott Michela59d4692008-02-23 18:41:37 +00002651multiclass RotateQuadBytes
2652{
2653 def v16i8: ROTQMBYVecInst<v16i8>;
2654 def v8i16: ROTQMBYVecInst<v8i16>;
2655 def v4i32: ROTQMBYVecInst<v4i32>;
2656 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002657
Scott Michela59d4692008-02-23 18:41:37 +00002658 def r128: ROTQMBYRegInst<GPRC>;
2659 def r64: ROTQMBYRegInst<R64C>;
2660}
2661
2662defm ROTQMBY : RotateQuadBytes;
2663
Scott Michela59d4692008-02-23 18:41:37 +00002664class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2665 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2666 RotateShift, pattern>;
2667
2668class ROTQMBYIVecInst<ValueType vectype>:
2669 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002670 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002671
Scott Micheldd950092009-01-06 03:36:14 +00002672class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2673 PatLeaf pred>:
Scott Michela59d4692008-02-23 18:41:37 +00002674 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002675 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002676
Scott Micheldd950092009-01-06 03:36:14 +00002677// 128-bit zero extension form:
2678class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2679 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2680 [/* no pattern */]>;
2681
Scott Michela59d4692008-02-23 18:41:37 +00002682multiclass RotateQuadBytesImm
2683{
2684 def v16i8: ROTQMBYIVecInst<v16i8>;
2685 def v8i16: ROTQMBYIVecInst<v8i16>;
2686 def v4i32: ROTQMBYIVecInst<v4i32>;
2687 def v2i64: ROTQMBYIVecInst<v2i64>;
2688
2689 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2690 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Micheldd950092009-01-06 03:36:14 +00002691
2692 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2693 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2694 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2695 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michela59d4692008-02-23 18:41:37 +00002696}
2697
2698defm ROTQMBYI : RotateQuadBytesImm;
2699
Scott Michela59d4692008-02-23 18:41:37 +00002700//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2701// Rotate right and mask by bit count
2702//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2703
2704class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2705 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2706 RotateShift, pattern>;
2707
2708class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002709 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2710 [/* no pattern, */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002711
2712multiclass RotateMaskQuadByBitCount
2713{
2714 def v16i8: ROTQMBYBIVecInst<v16i8>;
2715 def v8i16: ROTQMBYBIVecInst<v8i16>;
2716 def v4i32: ROTQMBYBIVecInst<v4i32>;
2717 def v2i64: ROTQMBYBIVecInst<v2i64>;
2718}
2719
2720defm ROTQMBYBI: RotateMaskQuadByBitCount;
2721
2722//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2723// Rotate quad and mask by bits
2724// Note that the rotate amount has to be negated
2725//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2726
2727class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2728 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2729 RotateShift, pattern>;
2730
2731class ROTQMBIVecInst<ValueType vectype>:
2732 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2733 [/* no pattern */]>;
2734
2735class ROTQMBIRegInst<RegisterClass rclass>:
2736 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2737 [/* no pattern */]>;
2738
2739multiclass RotateMaskQuadByBits
2740{
2741 def v16i8: ROTQMBIVecInst<v16i8>;
2742 def v8i16: ROTQMBIVecInst<v8i16>;
2743 def v4i32: ROTQMBIVecInst<v4i32>;
2744 def v2i64: ROTQMBIVecInst<v2i64>;
2745
2746 def r128: ROTQMBIRegInst<GPRC>;
2747 def r64: ROTQMBIRegInst<R64C>;
2748}
2749
2750defm ROTQMBI: RotateMaskQuadByBits;
2751
Scott Michela59d4692008-02-23 18:41:37 +00002752//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2753// Rotate quad and mask by bits, immediate
2754//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2755
2756class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2757 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2758 RotateShift, pattern>;
2759
2760class ROTQMBIIVecInst<ValueType vectype>:
2761 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002762 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002763
2764class ROTQMBIIRegInst<RegisterClass rclass>:
2765 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002766 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002767
2768multiclass RotateMaskQuadByBitsImm
2769{
2770 def v16i8: ROTQMBIIVecInst<v16i8>;
2771 def v8i16: ROTQMBIIVecInst<v8i16>;
2772 def v4i32: ROTQMBIIVecInst<v4i32>;
2773 def v2i64: ROTQMBIIVecInst<v2i64>;
2774
2775 def r128: ROTQMBIIRegInst<GPRC>;
2776 def r64: ROTQMBIIRegInst<R64C>;
2777}
2778
2779defm ROTQMBII: RotateMaskQuadByBitsImm;
2780
2781//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2782//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002783
2784def ROTMAHv8i16:
2785 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2786 "rotmah\t$rT, $rA, $rB", RotateShift,
2787 [/* see patterns below - $rB must be negated */]>;
2788
Chris Lattner420c69d2010-03-15 05:53:47 +00002789def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002790 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2791
Chris Lattner420c69d2010-03-15 05:53:47 +00002792def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002793 (ROTMAHv8i16 VECREG:$rA,
2794 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2795
Chris Lattner420c69d2010-03-15 05:53:47 +00002796def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel504c3692007-12-17 22:32:34 +00002797 (ROTMAHv8i16 VECREG:$rA,
2798 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2799
Scott Michel66377522007-12-04 22:35:58 +00002800def ROTMAHr16:
2801 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2802 "rotmah\t$rT, $rA, $rB", RotateShift,
2803 [/* see patterns below - $rB must be negated */]>;
2804
2805def : Pat<(sra R16C:$rA, R32C:$rB),
2806 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2807
2808def : Pat<(sra R16C:$rA, R16C:$rB),
2809 (ROTMAHr16 R16C:$rA,
2810 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2811
Scott Michel504c3692007-12-17 22:32:34 +00002812def : Pat<(sra R16C:$rA, R8C:$rB),
2813 (ROTMAHr16 R16C:$rA,
2814 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2815
Scott Michel66377522007-12-04 22:35:58 +00002816def ROTMAHIv8i16:
2817 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2818 "rotmahi\t$rT, $rA, $val", RotateShift,
2819 [(set (v8i16 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00002820 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002821
Scott Michela59d4692008-02-23 18:41:37 +00002822def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002823 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002824
Scott Michela59d4692008-02-23 18:41:37 +00002825def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002826 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002827
Scott Michel66377522007-12-04 22:35:58 +00002828def ROTMAHIr16:
2829 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2830 "rotmahi\t$rT, $rA, $val", RotateShift,
2831 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2832
2833def : Pat<(sra R16C:$rA, (i32 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002834 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002835
Scott Michel504c3692007-12-17 22:32:34 +00002836def : Pat<(sra R16C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002837 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002838
Scott Michel66377522007-12-04 22:35:58 +00002839def ROTMAv4i32:
2840 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2841 "rotma\t$rT, $rA, $rB", RotateShift,
2842 [/* see patterns below - $rB must be negated */]>;
2843
Chris Lattner420c69d2010-03-15 05:53:47 +00002844def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R32C:$rB),
2845 (ROTMAv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002846
Chris Lattner420c69d2010-03-15 05:53:47 +00002847def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R16C:$rB),
2848 (ROTMAv4i32 VECREG:$rA,
Scott Michel66377522007-12-04 22:35:58 +00002849 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2850
Chris Lattner420c69d2010-03-15 05:53:47 +00002851def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R8C:$rB),
2852 (ROTMAv4i32 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002853 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2854
Scott Michel66377522007-12-04 22:35:58 +00002855def ROTMAr32:
2856 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2857 "rotma\t$rT, $rA, $rB", RotateShift,
2858 [/* see patterns below - $rB must be negated */]>;
2859
2860def : Pat<(sra R32C:$rA, R32C:$rB),
2861 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2862
2863def : Pat<(sra R32C:$rA, R16C:$rB),
2864 (ROTMAr32 R32C:$rA,
2865 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2866
Scott Michel504c3692007-12-17 22:32:34 +00002867def : Pat<(sra R32C:$rA, R8C:$rB),
2868 (ROTMAr32 R32C:$rA,
2869 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2870
Scott Michel8bf61e82008-06-02 22:18:03 +00002871class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2872 RRForm<0b01011110000, OOL, IOL,
2873 "rotmai\t$rT, $rA, $val",
2874 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002875
Scott Michel8bf61e82008-06-02 22:18:03 +00002876class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2877 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2878 [(set (vectype VECREG:$rT),
2879 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002880
Scott Michel8bf61e82008-06-02 22:18:03 +00002881class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2882 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2883 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002884
Scott Michel8bf61e82008-06-02 22:18:03 +00002885multiclass RotateMaskAlgebraicImm {
2886 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2887 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2888 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2889 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2890}
Scott Michel66377522007-12-04 22:35:58 +00002891
Scott Michel8bf61e82008-06-02 22:18:03 +00002892defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel504c3692007-12-17 22:32:34 +00002893
Scott Michel66377522007-12-04 22:35:58 +00002894//===----------------------------------------------------------------------===//
2895// Branch and conditionals:
2896//===----------------------------------------------------------------------===//
2897
2898let isTerminator = 1, isBarrier = 1 in {
2899 // Halt If Equal (r32 preferred slot only, no vector form)
2900 def HEQr32:
2901 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2902 "heq\t$rA, $rB", BranchResolv,
2903 [/* no pattern to match */]>;
2904
2905 def HEQIr32 :
2906 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2907 "heqi\t$rA, $val", BranchResolv,
2908 [/* no pattern to match */]>;
2909
2910 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2911 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2912 def HGTr32:
2913 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2914 "hgt\t$rA, $rB", BranchResolv,
2915 [/* no pattern to match */]>;
2916
Scott Michelf0569be2008-12-27 04:51:36 +00002917 def HGTIr32:
Scott Michel66377522007-12-04 22:35:58 +00002918 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2919 "hgti\t$rA, $val", BranchResolv,
2920 [/* no pattern to match */]>;
2921
2922 def HLGTr32:
2923 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2924 "hlgt\t$rA, $rB", BranchResolv,
2925 [/* no pattern to match */]>;
2926
2927 def HLGTIr32:
2928 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2929 "hlgti\t$rA, $val", BranchResolv,
2930 [/* no pattern to match */]>;
2931}
2932
Scott Michelf0569be2008-12-27 04:51:36 +00002933//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2934// Comparison operators for i8, i16 and i32:
2935//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002936
Scott Michela59d4692008-02-23 18:41:37 +00002937class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2938 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2939 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002940
Scott Michela59d4692008-02-23 18:41:37 +00002941multiclass CmpEqualByte
2942{
2943 def v16i8 :
2944 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2945 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2946 (v8i16 VECREG:$rB)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002947
Scott Michela59d4692008-02-23 18:41:37 +00002948 def r8 :
2949 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2950 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2951}
Scott Michel66377522007-12-04 22:35:58 +00002952
Scott Michela59d4692008-02-23 18:41:37 +00002953class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2954 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2955 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002956
Scott Michela59d4692008-02-23 18:41:37 +00002957multiclass CmpEqualByteImm
2958{
2959 def v16i8 :
2960 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2961 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2962 v16i8SExt8Imm:$val))]>;
2963 def r8:
2964 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2965 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
2966}
Scott Michel66377522007-12-04 22:35:58 +00002967
Scott Michela59d4692008-02-23 18:41:37 +00002968class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
2969 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
2970 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002971
Scott Michela59d4692008-02-23 18:41:37 +00002972multiclass CmpEqualHalfword
2973{
2974 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2975 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2976 (v8i16 VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002977
Scott Michela59d4692008-02-23 18:41:37 +00002978 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2979 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
2980}
Scott Michel66377522007-12-04 22:35:58 +00002981
Scott Michela59d4692008-02-23 18:41:37 +00002982class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
2983 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
2984 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002985
Scott Michela59d4692008-02-23 18:41:37 +00002986multiclass CmpEqualHalfwordImm
2987{
2988 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2989 [(set (v8i16 VECREG:$rT),
2990 (seteq (v8i16 VECREG:$rA),
2991 (v8i16 v8i16SExt10Imm:$val)))]>;
2992 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2993 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
2994}
Scott Michel66377522007-12-04 22:35:58 +00002995
Scott Michela59d4692008-02-23 18:41:37 +00002996class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
2997 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
2998 ByteOp, pattern>;
2999
3000multiclass CmpEqualWord
3001{
3002 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3003 [(set (v4i32 VECREG:$rT),
3004 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3005
3006 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3007 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3008}
3009
3010class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3011 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3012 ByteOp, pattern>;
3013
3014multiclass CmpEqualWordImm
3015{
3016 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3017 [(set (v4i32 VECREG:$rT),
3018 (seteq (v4i32 VECREG:$rA),
3019 (v4i32 v4i32SExt16Imm:$val)))]>;
3020
3021 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3022 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3023}
3024
3025class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3026 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3027 ByteOp, pattern>;
3028
3029multiclass CmpGtrByte
3030{
3031 def v16i8 :
3032 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3033 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3034 (v8i16 VECREG:$rB)))]>;
3035
3036 def r8 :
3037 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3038 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3039}
3040
3041class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3042 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3043 ByteOp, pattern>;
3044
3045multiclass CmpGtrByteImm
3046{
3047 def v16i8 :
3048 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3049 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3050 v16i8SExt8Imm:$val))]>;
3051 def r8:
3052 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel79698f62008-03-20 00:51:36 +00003053 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003054}
3055
3056class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3057 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3058 ByteOp, pattern>;
3059
3060multiclass CmpGtrHalfword
3061{
3062 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3063 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3064 (v8i16 VECREG:$rB)))]>;
3065
3066 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3067 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3068}
3069
3070class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3071 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3072 ByteOp, pattern>;
3073
3074multiclass CmpGtrHalfwordImm
3075{
3076 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3077 [(set (v8i16 VECREG:$rT),
3078 (setgt (v8i16 VECREG:$rA),
3079 (v8i16 v8i16SExt10Imm:$val)))]>;
3080 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3081 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3082}
3083
3084class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3085 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3086 ByteOp, pattern>;
3087
3088multiclass CmpGtrWord
3089{
3090 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3091 [(set (v4i32 VECREG:$rT),
3092 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3093
3094 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3095 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3096}
3097
3098class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3099 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3100 ByteOp, pattern>;
3101
3102multiclass CmpGtrWordImm
3103{
3104 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3105 [(set (v4i32 VECREG:$rT),
3106 (setgt (v4i32 VECREG:$rA),
3107 (v4i32 v4i32SExt16Imm:$val)))]>;
3108
3109 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3110 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00003111
3112 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3113 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3114 [(set (v4i32 VECREG:$rT),
3115 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3116 (v4i32 v4i32SExt16Imm:$val)))]>;
3117
3118 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +00003119 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00003120}
3121
3122class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003123 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003124 ByteOp, pattern>;
3125
3126multiclass CmpLGtrByte
3127{
3128 def v16i8 :
3129 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3130 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3131 (v8i16 VECREG:$rB)))]>;
3132
3133 def r8 :
3134 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3135 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3136}
3137
3138class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003139 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003140 ByteOp, pattern>;
3141
3142multiclass CmpLGtrByteImm
3143{
3144 def v16i8 :
3145 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3146 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3147 v16i8SExt8Imm:$val))]>;
3148 def r8:
3149 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3150 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3151}
3152
3153class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003154 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003155 ByteOp, pattern>;
3156
3157multiclass CmpLGtrHalfword
3158{
3159 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3160 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3161 (v8i16 VECREG:$rB)))]>;
3162
3163 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3164 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3165}
3166
3167class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003168 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003169 ByteOp, pattern>;
3170
3171multiclass CmpLGtrHalfwordImm
3172{
3173 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3174 [(set (v8i16 VECREG:$rT),
3175 (setugt (v8i16 VECREG:$rA),
3176 (v8i16 v8i16SExt10Imm:$val)))]>;
3177 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3178 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3179}
3180
3181class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003182 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003183 ByteOp, pattern>;
3184
3185multiclass CmpLGtrWord
3186{
3187 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3188 [(set (v4i32 VECREG:$rT),
3189 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3190
3191 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3192 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3193}
3194
3195class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003196 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003197 ByteOp, pattern>;
3198
3199multiclass CmpLGtrWordImm
3200{
3201 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3202 [(set (v4i32 VECREG:$rT),
3203 (setugt (v4i32 VECREG:$rA),
3204 (v4i32 v4i32SExt16Imm:$val)))]>;
3205
3206 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michelad2715e2008-03-05 23:02:02 +00003207 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003208}
3209
3210defm CEQB : CmpEqualByte;
3211defm CEQBI : CmpEqualByteImm;
3212defm CEQH : CmpEqualHalfword;
3213defm CEQHI : CmpEqualHalfwordImm;
3214defm CEQ : CmpEqualWord;
3215defm CEQI : CmpEqualWordImm;
3216defm CGTB : CmpGtrByte;
3217defm CGTBI : CmpGtrByteImm;
3218defm CGTH : CmpGtrHalfword;
3219defm CGTHI : CmpGtrHalfwordImm;
3220defm CGT : CmpGtrWord;
3221defm CGTI : CmpGtrWordImm;
3222defm CLGTB : CmpLGtrByte;
3223defm CLGTBI : CmpLGtrByteImm;
3224defm CLGTH : CmpLGtrHalfword;
3225defm CLGTHI : CmpLGtrHalfwordImm;
3226defm CLGT : CmpLGtrWord;
3227defm CLGTI : CmpLGtrWordImm;
3228
Scott Michel78c47fa2008-03-10 16:58:52 +00003229//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003230// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3231// define a pattern to generate the right code, as a binary operator
3232// (in a manner of speaking.)
Scott Michel78c47fa2008-03-10 16:58:52 +00003233//
Scott Michelf0569be2008-12-27 04:51:36 +00003234// Notes:
3235// 1. This only matches the setcc set of conditionals. Special pattern
3236// matching is used for select conditionals.
3237//
3238// 2. The "DAG" versions of these classes is almost exclusively used for
3239// i64 comparisons. See the tblgen fundamentals documentation for what
3240// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3241// class for where ResultInstrs originates.
Scott Michel78c47fa2008-03-10 16:58:52 +00003242//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003243
Scott Michel78c47fa2008-03-10 16:58:52 +00003244class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3245 SPUInstr xorinst, SPUInstr cmpare>:
3246 Pat<(cond rclass:$rA, rclass:$rB),
3247 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3248
3249class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3250 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3251 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3252 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3253
Scott Michelf0569be2008-12-27 04:51:36 +00003254def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003255def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3256
Scott Michelf0569be2008-12-27 04:51:36 +00003257def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003258def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3259
3260def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3261def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003262
3263class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3264 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3265 Pat<(cond rclass:$rA, rclass:$rB),
3266 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3267 (cmpOp2 rclass:$rA, rclass:$rB))>;
3268
3269class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3270 ValueType immtype,
3271 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3272 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3273 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3274 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3275
Scott Michel78c47fa2008-03-10 16:58:52 +00003276def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3277def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3278def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3279def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3280def : Pat<(setle R8C:$rA, R8C:$rB),
3281 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3282def : Pat<(setle R8C:$rA, immU8:$imm),
3283 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003284
Scott Michel78c47fa2008-03-10 16:58:52 +00003285def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3286def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3287 ORr16, CGTHIr16, CEQHIr16>;
3288def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3289def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3290def : Pat<(setle R16C:$rA, R16C:$rB),
3291 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3292def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3293 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003294
Scott Michel78c47fa2008-03-10 16:58:52 +00003295def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3296def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3297 ORr32, CGTIr32, CEQIr32>;
3298def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3299def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3300def : Pat<(setle R32C:$rA, R32C:$rB),
3301 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3302def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3303 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003304
Scott Michel78c47fa2008-03-10 16:58:52 +00003305def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3306def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3307def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3308def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3309def : Pat<(setule R8C:$rA, R8C:$rB),
3310 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3311def : Pat<(setule R8C:$rA, immU8:$imm),
3312 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003313
Scott Michel78c47fa2008-03-10 16:58:52 +00003314def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3315def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3316 ORr16, CLGTHIr16, CEQHIr16>;
3317def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3318def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3319 CLGTHIr16, CEQHIr16>;
3320def : Pat<(setule R16C:$rA, R16C:$rB),
3321 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel79698f62008-03-20 00:51:36 +00003322def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel78c47fa2008-03-10 16:58:52 +00003323 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003324
Scott Michel78c47fa2008-03-10 16:58:52 +00003325def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003326def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel78c47fa2008-03-10 16:58:52 +00003327 ORr32, CLGTIr32, CEQIr32>;
3328def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003329def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003330def : Pat<(setule R32C:$rA, R32C:$rB),
3331 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3332def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3333 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003334
Scott Michel78c47fa2008-03-10 16:58:52 +00003335//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3336// select conditional patterns:
3337//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3338
3339class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3340 SPUInstr selinstr, SPUInstr cmpare>:
3341 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3342 rclass:$rTrue, rclass:$rFalse),
3343 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003344 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003345
3346class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3347 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3348 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003349 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003350 (selinstr rclass:$rTrue, rclass:$rFalse,
3351 (cmpare rclass:$rA, immpred:$imm))>;
3352
3353def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3354def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3355def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3356def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3357def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3358def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3359
3360def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3361def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3362def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3363def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3364def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3365def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3366
3367def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3368def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3369def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3370def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3371def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3372def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3373
3374class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3375 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3376 SPUInstr cmpOp2>:
3377 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michelf0569be2008-12-27 04:51:36 +00003378 rclass:$rTrue, rclass:$rFalse),
3379 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel78c47fa2008-03-10 16:58:52 +00003380 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3381 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3382
3383class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3384 ValueType inttype,
3385 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3386 SPUInstr cmpOp2>:
3387 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003388 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003389 (selinstr rclass:$rFalse, rclass:$rTrue,
3390 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3391 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3392
3393def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3394def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3395 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3396
3397def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3398def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3399 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3400
3401def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3402def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3403 SELBr32, ORr32, CGTIr32, CEQIr32>;
3404
3405def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3406def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3407 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3408
3409def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3410def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3411 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3412
3413def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3414def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3415 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003416
3417//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00003418
3419let isCall = 1,
3420 // All calls clobber the non-callee-saved registers:
3421 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3422 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3423 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3424 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3425 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3426 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3427 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3428 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3429 // All of these instructions use $lr (aka $0)
3430 Uses = [R0] in {
3431 // Branch relative and set link: Used if we actually know that the target
3432 // is within [-32768, 32767] bytes of the target
3433 def BRSL:
3434 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3435 "brsl\t$$lr, $func",
3436 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3437
3438 // Branch absolute and set link: Used if we actually know that the target
3439 // is an absolute address
3440 def BRASL:
3441 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3442 "brasl\t$$lr, $func",
Scott Michel9de5d0d2008-01-11 02:53:15 +00003443 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel66377522007-12-04 22:35:58 +00003444
3445 // Branch indirect and set link if external data. These instructions are not
3446 // actually generated, matched by an intrinsic:
3447 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3448 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3449 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3450 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3451
3452 // Branch indirect and set link. This is the "X-form" address version of a
3453 // function call
3454 def BISL:
3455 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3456}
3457
Scott Michel1df30c42008-12-29 03:23:36 +00003458// Support calls to external symbols:
3459def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3460 (BRSL texternalsym:$func)>;
3461
3462def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3463 (BRASL texternalsym:$func)>;
3464
Scott Michel66377522007-12-04 22:35:58 +00003465// Unconditional branches:
Dan Gohman5b37fba2009-11-10 22:16:57 +00003466let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
3467 let isBarrier = 1 in {
3468 def BR :
3469 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3470 "br\t$dest",
3471 [(br bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003472
Dan Gohman5b37fba2009-11-10 22:16:57 +00003473 // Unconditional, absolute address branch
3474 def BRA:
3475 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3476 "bra\t$dest",
3477 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003478
Dan Gohman5b37fba2009-11-10 22:16:57 +00003479 // Indirect branch
3480 def BI:
3481 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3482 }
Scott Michel66377522007-12-04 22:35:58 +00003483
Scott Micheled741dd2009-01-05 01:34:35 +00003484 // Conditional branches:
Scott Michelf0569be2008-12-27 04:51:36 +00003485 class BRNZInst<dag IOL, list<dag> pattern>:
3486 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3487 BranchResolv, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003488
Scott Michelf0569be2008-12-27 04:51:36 +00003489 class BRNZRegInst<RegisterClass rclass>:
3490 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3491 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003492
Scott Michelf0569be2008-12-27 04:51:36 +00003493 class BRNZVecInst<ValueType vectype>:
3494 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3495 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003496
Scott Michelf0569be2008-12-27 04:51:36 +00003497 multiclass BranchNotZero {
3498 def v4i32 : BRNZVecInst<v4i32>;
3499 def r32 : BRNZRegInst<R32C>;
3500 }
Scott Michel66377522007-12-04 22:35:58 +00003501
Scott Michelf0569be2008-12-27 04:51:36 +00003502 defm BRNZ : BranchNotZero;
3503
3504 class BRZInst<dag IOL, list<dag> pattern>:
3505 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3506 BranchResolv, pattern>;
3507
3508 class BRZRegInst<RegisterClass rclass>:
3509 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3510
3511 class BRZVecInst<ValueType vectype>:
3512 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3513
3514 multiclass BranchZero {
3515 def v4i32: BRZVecInst<v4i32>;
3516 def r32: BRZRegInst<R32C>;
3517 }
3518
3519 defm BRZ: BranchZero;
3520
3521 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3522 // be useful:
3523 /*
3524 class BINZInst<dag IOL, list<dag> pattern>:
3525 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3526
3527 class BINZRegInst<RegisterClass rclass>:
3528 BINZInst<(ins rclass:$rA, brtarget:$dest),
3529 [(brcond rclass:$rA, R32C:$dest)]>;
3530
3531 class BINZVecInst<ValueType vectype>:
3532 BINZInst<(ins VECREG:$rA, R32C:$dest),
3533 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3534
3535 multiclass BranchNotZeroIndirect {
3536 def v4i32: BINZVecInst<v4i32>;
3537 def r32: BINZRegInst<R32C>;
3538 }
3539
3540 defm BINZ: BranchNotZeroIndirect;
3541
3542 class BIZInst<dag IOL, list<dag> pattern>:
3543 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3544
3545 class BIZRegInst<RegisterClass rclass>:
3546 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3547
3548 class BIZVecInst<ValueType vectype>:
3549 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3550
3551 multiclass BranchZeroIndirect {
3552 def v4i32: BIZVecInst<v4i32>;
3553 def r32: BIZRegInst<R32C>;
3554 }
3555
3556 defm BIZ: BranchZeroIndirect;
3557 */
3558
3559 class BRHNZInst<dag IOL, list<dag> pattern>:
3560 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3561 pattern>;
3562
3563 class BRHNZRegInst<RegisterClass rclass>:
3564 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3565 [(brcond rclass:$rCond, bb:$dest)]>;
3566
3567 class BRHNZVecInst<ValueType vectype>:
3568 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3569
3570 multiclass BranchNotZeroHalfword {
3571 def v8i16: BRHNZVecInst<v8i16>;
3572 def r16: BRHNZRegInst<R16C>;
3573 }
3574
3575 defm BRHNZ: BranchNotZeroHalfword;
3576
3577 class BRHZInst<dag IOL, list<dag> pattern>:
3578 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3579 pattern>;
3580
3581 class BRHZRegInst<RegisterClass rclass>:
3582 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3583
3584 class BRHZVecInst<ValueType vectype>:
3585 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3586
3587 multiclass BranchZeroHalfword {
3588 def v8i16: BRHZVecInst<v8i16>;
3589 def r16: BRHZRegInst<R16C>;
3590 }
3591
3592 defm BRHZ: BranchZeroHalfword;
Scott Michel66377522007-12-04 22:35:58 +00003593}
3594
Scott Michel58c58182008-01-17 20:38:41 +00003595//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003596// setcc and brcond patterns:
Scott Michel58c58182008-01-17 20:38:41 +00003597//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003598
Scott Michelf0569be2008-12-27 04:51:36 +00003599def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3600 (BRHZr16 R16C:$rA, bb:$dest)>;
3601def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3602 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michela59d4692008-02-23 18:41:37 +00003603
Scott Michelf0569be2008-12-27 04:51:36 +00003604def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3605 (BRZr32 R32C:$rA, bb:$dest)>;
3606def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3607 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel66377522007-12-04 22:35:58 +00003608
Scott Michela59d4692008-02-23 18:41:37 +00003609multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3610{
3611 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3612 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michel053c1da2008-01-29 02:16:57 +00003613
Scott Michela59d4692008-02-23 18:41:37 +00003614 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3615 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3616
3617 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3618 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3619
3620 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3621 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3622}
3623
Scott Micheled741dd2009-01-05 01:34:35 +00003624defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3625defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003626
3627multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3628{
3629 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3630 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3631
3632 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3633 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3634
3635 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3636 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3637
3638 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3639 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3640}
3641
Scott Michelf0569be2008-12-27 04:51:36 +00003642defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3643defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003644
3645multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3646 SPUInstr orinst32, SPUInstr brinst32>
3647{
3648 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3649 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3650 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3651 bb:$dest)>;
3652
3653 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3654 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3655 (CEQHr16 R16C:$rA, R16:$rB)),
3656 bb:$dest)>;
3657
3658 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3659 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3660 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3661 bb:$dest)>;
3662
3663 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3664 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3665 (CEQr32 R32C:$rA, R32C:$rB)),
3666 bb:$dest)>;
3667}
3668
Scott Michelf0569be2008-12-27 04:51:36 +00003669defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3670defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003671
3672multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3673{
3674 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3675 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3676
3677 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3678 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3679
3680 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3681 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3682
3683 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3684 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3685}
3686
Scott Michelf0569be2008-12-27 04:51:36 +00003687defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3688defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003689
3690multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3691 SPUInstr orinst32, SPUInstr brinst32>
3692{
3693 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3694 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3695 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3696 bb:$dest)>;
3697
3698 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3699 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3700 (CEQHr16 R16C:$rA, R16:$rB)),
3701 bb:$dest)>;
3702
3703 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3704 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3705 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3706 bb:$dest)>;
3707
3708 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3709 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3710 (CEQr32 R32C:$rA, R32C:$rB)),
3711 bb:$dest)>;
3712}
3713
Scott Michelf0569be2008-12-27 04:51:36 +00003714defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3715defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel053c1da2008-01-29 02:16:57 +00003716
Scott Michel66377522007-12-04 22:35:58 +00003717let isTerminator = 1, isBarrier = 1 in {
3718 let isReturn = 1 in {
3719 def RET:
3720 RETForm<"bi\t$$lr", [(retflag)]>;
3721 }
3722}
3723
3724//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00003725// Single precision floating point instructions
3726//===----------------------------------------------------------------------===//
3727
Scott Michelaedc6372008-12-10 00:15:19 +00003728class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3729 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003730 SPrecFP, pattern>;
Scott Michelf0569be2008-12-27 04:51:36 +00003731
Scott Michelaedc6372008-12-10 00:15:19 +00003732class FAVecInst<ValueType vectype>:
3733 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3734 [(set (vectype VECREG:$rT),
Scott Michel02d711b2008-12-30 23:28:25 +00003735 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelf0569be2008-12-27 04:51:36 +00003736
Scott Michelaedc6372008-12-10 00:15:19 +00003737multiclass SFPAdd
3738{
3739 def v4f32: FAVecInst<v4f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003740 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3741 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003742}
Scott Michel66377522007-12-04 22:35:58 +00003743
Scott Michelaedc6372008-12-10 00:15:19 +00003744defm FA : SFPAdd;
Scott Michel66377522007-12-04 22:35:58 +00003745
Scott Michelaedc6372008-12-10 00:15:19 +00003746class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3747 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003748 SPrecFP, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003749
Scott Michelaedc6372008-12-10 00:15:19 +00003750class FSVecInst<ValueType vectype>:
3751 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00003752 [(set (vectype VECREG:$rT),
3753 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003754
3755multiclass SFPSub
3756{
3757 def v4f32: FSVecInst<v4f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003758 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3759 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003760}
3761
3762defm FS : SFPSub;
Scott Michel66377522007-12-04 22:35:58 +00003763
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003764class FMInst<dag OOL, dag IOL, list<dag> pattern>:
3765 RRForm<0b01100011010, OOL, IOL,
3766 "fm\t$rT, $rA, $rB", SPrecFP,
3767 pattern>;
3768
3769class FMVecInst<ValueType type>:
3770 FMInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3771 [(set (type VECREG:$rT),
3772 (fmul (type VECREG:$rA), (type VECREG:$rB)))]>;
3773
3774multiclass SFPMul
3775{
3776 def v4f32: FMVecInst<v4f32>;
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003777 def f32: FMInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3778 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3779}
3780
3781defm FM : SFPMul;
3782
3783// Floating point multiply and add
3784// e.g. d = c + (a * b)
3785def FMAv4f32:
3786 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3787 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3788 [(set (v4f32 VECREG:$rT),
3789 (fadd (v4f32 VECREG:$rC),
3790 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3791
3792def FMAf32:
3793 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3794 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3795 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3796
3797// FP multiply and subtract
3798// Subtracts value in rC from product
3799// res = a * b - c
3800def FMSv4f32 :
3801 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3802 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3803 [(set (v4f32 VECREG:$rT),
3804 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3805 (v4f32 VECREG:$rC)))]>;
3806
3807def FMSf32 :
3808 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3809 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3810 [(set R32FP:$rT,
3811 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3812
3813// Floating Negative Mulitply and Subtract
3814// Subtracts product from value in rC
3815// res = fneg(fms a b c)
3816// = - (a * b - c)
3817// = c - a * b
3818// NOTE: subtraction order
3819// fsub a b = a - b
3820// fs a b = b - a?
3821def FNMSf32 :
3822 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3823 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3824 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3825
3826def FNMSv4f32 :
3827 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3828 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3829 [(set (v4f32 VECREG:$rT),
3830 (fsub (v4f32 VECREG:$rC),
3831 (fmul (v4f32 VECREG:$rA),
3832 (v4f32 VECREG:$rB))))]>;
3833
3834
3835
3836
Scott Michel66377522007-12-04 22:35:58 +00003837// Floating point reciprocal estimate
Scott Michel66377522007-12-04 22:35:58 +00003838
Scott Michel02d711b2008-12-30 23:28:25 +00003839class FRESTInst<dag OOL, dag IOL>:
3840 RRForm_1<0b00110111000, OOL, IOL,
3841 "frest\t$rT, $rA", SPrecFP,
3842 [/* no pattern */]>;
3843
3844def FRESTv4f32 :
3845 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3846
3847def FRESTf32 :
3848 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00003849
3850// Floating point interpolate (used in conjunction with reciprocal estimate)
3851def FIv4f32 :
3852 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3853 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00003854 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003855
3856def FIf32 :
3857 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3858 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00003859 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003860
Scott Michel9c0c6b22008-11-21 02:56:16 +00003861//--------------------------------------------------------------------------
3862// Basic single precision floating point comparisons:
3863//
3864// Note: There is no support on SPU for single precision NaN. Consequently,
3865// ordered and unordered comparisons are the same.
3866//--------------------------------------------------------------------------
3867
Scott Michel66377522007-12-04 22:35:58 +00003868def FCEQf32 :
3869 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3870 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003871 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3872
3873def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3874 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00003875
3876def FCMEQf32 :
3877 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3878 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003879 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3880
3881def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3882 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00003883
3884def FCGTf32 :
3885 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3886 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003887 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3888
3889def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3890 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00003891
3892def FCMGTf32 :
3893 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3894 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003895 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3896
3897def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3898 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3899
3900//--------------------------------------------------------------------------
3901// Single precision floating point comparisons and SETCC equivalents:
3902//--------------------------------------------------------------------------
3903
3904def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3905def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3906
3907def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3908def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3909
3910def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3911def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3912
3913def : Pat<(setule R32FP:$rA, R32FP:$rB),
3914 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3915def : Pat<(setole R32FP:$rA, R32FP:$rB),
3916 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel66377522007-12-04 22:35:58 +00003917
3918// FP Status and Control Register Write
3919// Why isn't rT a don't care in the ISA?
3920// Should we create a special RRForm_3 for this guy and zero out the rT?
3921def FSCRWf32 :
3922 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3923 "fscrwr\t$rA", SPrecFP,
3924 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3925
3926// FP Status and Control Register Read
3927def FSCRRf32 :
3928 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3929 "fscrrd\t$rT", SPrecFP,
3930 [/* This instruction requires an intrinsic */]>;
3931
3932// llvm instruction space
3933// How do these map onto cell instructions?
3934// fdiv rA rB
3935// frest rC rB # c = 1/b (both lines)
3936// fi rC rB rC
3937// fm rD rA rC # d = a * 1/b
3938// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3939// fma rB rB rC rD # b = b * c + d
3940// = -(d *b -a) * c + d
3941// = a * c - c ( a *b *c - a)
3942
3943// fcopysign (???)
3944
3945// Library calls:
3946// These llvm instructions will actually map to library calls.
3947// All that's needed, then, is to check that the appropriate library is
3948// imported and do a brsl to the proper function name.
3949// frem # fmod(x, y): x - (x/y) * y
3950// (Note: fmod(double, double), fmodf(float,float)
3951// fsqrt?
3952// fsin?
3953// fcos?
3954// Unimplemented SPU instruction space
3955// floating reciprocal absolute square root estimate (frsqest)
3956
3957// The following are probably just intrinsics
Scott Michelf0569be2008-12-27 04:51:36 +00003958// status and control register write
Scott Michel66377522007-12-04 22:35:58 +00003959// status and control register read
3960
3961//--------------------------------------
Scott Michel66377522007-12-04 22:35:58 +00003962// Floating Point Conversions
3963// Signed conversions:
3964def CSiFv4f32:
3965 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3966 "csflt\t$rT, $rA, 0", SPrecFP,
3967 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3968
Scott Michelf0569be2008-12-27 04:51:36 +00003969// Convert signed integer to floating point
Scott Michel66377522007-12-04 22:35:58 +00003970def CSiFf32 :
3971 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3972 "csflt\t$rT, $rA, 0", SPrecFP,
3973 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3974
3975// Convert unsigned into to float
3976def CUiFv4f32 :
3977 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3978 "cuflt\t$rT, $rA, 0", SPrecFP,
3979 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3980
3981def CUiFf32 :
3982 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3983 "cuflt\t$rT, $rA, 0", SPrecFP,
3984 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
3985
Scott Michelf0569be2008-12-27 04:51:36 +00003986// Convert float to unsigned int
Scott Michel66377522007-12-04 22:35:58 +00003987// Assume that scale = 0
3988
3989def CFUiv4f32 :
3990 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3991 "cfltu\t$rT, $rA, 0", SPrecFP,
3992 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
3993
3994def CFUif32 :
3995 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3996 "cfltu\t$rT, $rA, 0", SPrecFP,
3997 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
3998
Scott Michelf0569be2008-12-27 04:51:36 +00003999// Convert float to signed int
Scott Michel66377522007-12-04 22:35:58 +00004000// Assume that scale = 0
4001
4002def CFSiv4f32 :
4003 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4004 "cflts\t$rT, $rA, 0", SPrecFP,
4005 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4006
4007def CFSif32 :
4008 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4009 "cflts\t$rT, $rA, 0", SPrecFP,
4010 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4011
4012//===----------------------------------------------------------------------==//
4013// Single<->Double precision conversions
4014//===----------------------------------------------------------------------==//
4015
4016// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4017// v4f32, output is v2f64--which goes in the name?)
4018
4019// Floating point extend single to double
4020// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4021// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4022// are ignored).
4023def FESDvec :
4024 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4025 "fesd\t$rT, $rA", SPrecFP,
Chris Lattnere9eda0f2010-03-19 04:53:47 +00004026 [/*(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))*/]>;
Scott Michel66377522007-12-04 22:35:58 +00004027
4028def FESDf32 :
4029 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4030 "fesd\t$rT, $rA", SPrecFP,
4031 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4032
4033// Floating point round double to single
4034//def FRDSvec :
4035// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4036// "frds\t$rT, $rA,", SPrecFP,
4037// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4038
4039def FRDSf64 :
4040 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4041 "frds\t$rT, $rA", SPrecFP,
4042 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4043
4044//ToDo include anyextend?
4045
4046//===----------------------------------------------------------------------==//
4047// Double precision floating point instructions
4048//===----------------------------------------------------------------------==//
4049def FAf64 :
4050 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4051 "dfa\t$rT, $rA, $rB", DPrecFP,
4052 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4053
4054def FAv2f64 :
4055 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4056 "dfa\t$rT, $rA, $rB", DPrecFP,
4057 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4058
4059def FSf64 :
4060 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4061 "dfs\t$rT, $rA, $rB", DPrecFP,
4062 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4063
4064def FSv2f64 :
4065 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4066 "dfs\t$rT, $rA, $rB", DPrecFP,
4067 [(set (v2f64 VECREG:$rT),
4068 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4069
4070def FMf64 :
4071 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4072 "dfm\t$rT, $rA, $rB", DPrecFP,
4073 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4074
4075def FMv2f64:
4076 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4077 "dfm\t$rT, $rA, $rB", DPrecFP,
4078 [(set (v2f64 VECREG:$rT),
4079 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4080
4081def FMAf64:
4082 RRForm<0b00111010110, (outs R64FP:$rT),
4083 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4084 "dfma\t$rT, $rA, $rB", DPrecFP,
4085 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4086 RegConstraint<"$rC = $rT">,
4087 NoEncode<"$rC">;
4088
4089def FMAv2f64:
4090 RRForm<0b00111010110, (outs VECREG:$rT),
4091 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4092 "dfma\t$rT, $rA, $rB", DPrecFP,
4093 [(set (v2f64 VECREG:$rT),
4094 (fadd (v2f64 VECREG:$rC),
4095 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4096 RegConstraint<"$rC = $rT">,
4097 NoEncode<"$rC">;
4098
4099def FMSf64 :
4100 RRForm<0b10111010110, (outs R64FP:$rT),
4101 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4102 "dfms\t$rT, $rA, $rB", DPrecFP,
4103 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4104 RegConstraint<"$rC = $rT">,
4105 NoEncode<"$rC">;
4106
4107def FMSv2f64 :
4108 RRForm<0b10111010110, (outs VECREG:$rT),
4109 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4110 "dfms\t$rT, $rA, $rB", DPrecFP,
4111 [(set (v2f64 VECREG:$rT),
4112 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4113 (v2f64 VECREG:$rC)))]>;
4114
Scott Michel7ea02ff2009-03-17 01:15:45 +00004115// DFNMS: - (a * b - c)
Scott Michel66377522007-12-04 22:35:58 +00004116// - (a * b) + c => c - (a * b)
Scott Michel7ea02ff2009-03-17 01:15:45 +00004117
4118class DFNMSInst<dag OOL, dag IOL, list<dag> pattern>:
4119 RRForm<0b01111010110, OOL, IOL, "dfnms\t$rT, $rA, $rB",
4120 DPrecFP, pattern>,
Scott Michel66377522007-12-04 22:35:58 +00004121 RegConstraint<"$rC = $rT">,
4122 NoEncode<"$rC">;
4123
Scott Michel7ea02ff2009-03-17 01:15:45 +00004124class DFNMSVecInst<list<dag> pattern>:
4125 DFNMSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4126 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004127
Scott Michel7ea02ff2009-03-17 01:15:45 +00004128class DFNMSRegInst<list<dag> pattern>:
4129 DFNMSInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4130 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004131
Scott Michel7ea02ff2009-03-17 01:15:45 +00004132multiclass DFMultiplySubtract
4133{
4134 def v2f64 : DFNMSVecInst<[(set (v2f64 VECREG:$rT),
4135 (fsub (v2f64 VECREG:$rC),
4136 (fmul (v2f64 VECREG:$rA),
4137 (v2f64 VECREG:$rB))))]>;
4138
4139 def f64 : DFNMSRegInst<[(set R64FP:$rT,
4140 (fsub R64FP:$rC,
4141 (fmul R64FP:$rA, R64FP:$rB)))]>;
4142}
4143
4144defm DFNMS : DFMultiplySubtract;
Scott Michel66377522007-12-04 22:35:58 +00004145
4146// - (a * b + c)
4147// - (a * b) - c
4148def FNMAf64 :
4149 RRForm<0b11111010110, (outs R64FP:$rT),
4150 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4151 "dfnma\t$rT, $rA, $rB", DPrecFP,
4152 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4153 RegConstraint<"$rC = $rT">,
4154 NoEncode<"$rC">;
4155
4156def FNMAv2f64 :
4157 RRForm<0b11111010110, (outs VECREG:$rT),
4158 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4159 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michelf0569be2008-12-27 04:51:36 +00004160 [(set (v2f64 VECREG:$rT),
4161 (fneg (fadd (v2f64 VECREG:$rC),
4162 (fmul (v2f64 VECREG:$rA),
Scott Michel66377522007-12-04 22:35:58 +00004163 (v2f64 VECREG:$rB)))))]>,
4164 RegConstraint<"$rC = $rT">,
4165 NoEncode<"$rC">;
4166
4167//===----------------------------------------------------------------------==//
4168// Floating point negation and absolute value
4169//===----------------------------------------------------------------------==//
4170
4171def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michela82d3f72009-03-17 16:45:16 +00004172 (XORfnegvec (v4f32 VECREG:$rA),
4173 (v4f32 (ILHUv4i32 0x8000)))>;
Scott Michel66377522007-12-04 22:35:58 +00004174
4175def : Pat<(fneg R32FP:$rA),
Scott Michela82d3f72009-03-17 16:45:16 +00004176 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
Scott Michel66377522007-12-04 22:35:58 +00004177
4178// Floating point absolute value
Scott Michel7ea02ff2009-03-17 01:15:45 +00004179// Note: f64 fabs is custom-selected.
Scott Michel66377522007-12-04 22:35:58 +00004180
4181def : Pat<(fabs R32FP:$rA),
4182 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4183
4184def : Pat<(fabs (v4f32 VECREG:$rA)),
4185 (ANDfabsvec (v4f32 VECREG:$rA),
Scott Michel7ea02ff2009-03-17 01:15:45 +00004186 (IOHLv4i32 (ILHUv4i32 0x7fff), 0xffff))>;
Scott Michelc9c8b2a2009-01-26 03:31:40 +00004187
Scott Michel66377522007-12-04 22:35:58 +00004188//===----------------------------------------------------------------------===//
Scott Michelaedc6372008-12-10 00:15:19 +00004189// Hint for branch instructions:
4190//===----------------------------------------------------------------------===//
4191
4192/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4193
4194//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004195// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4196// in the odd pipeline)
4197//===----------------------------------------------------------------------===//
4198
Scott Michela59d4692008-02-23 18:41:37 +00004199def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004200 let Pattern = [];
4201
4202 let Inst{0-10} = 0b10000000010;
4203 let Inst{11-17} = 0;
4204 let Inst{18-24} = 0;
4205 let Inst{25-31} = 0;
4206}
4207
Scott Michela59d4692008-02-23 18:41:37 +00004208def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004209 let Pattern = [];
4210
4211 let Inst{0-10} = 0b10000000000;
4212 let Inst{11-17} = 0;
4213 let Inst{18-24} = 0;
4214 let Inst{25-31} = 0;
4215}
4216
4217//===----------------------------------------------------------------------===//
4218// Bit conversions (type conversions between vector/packed types)
Scott Michel6e1d1472009-03-16 18:47:25 +00004219// NOTE: Promotions are handled using the XS* instructions.
Scott Michel66377522007-12-04 22:35:58 +00004220//===----------------------------------------------------------------------===//
4221def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4222def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4223def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4224def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4225def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4226
4227def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4228def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4229def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4230def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4231def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4232
4233def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4234def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4235def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4236def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4237def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4238
4239def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4240def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4241def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4242def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4243def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4244
4245def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4246def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4247def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4248def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4249def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4250
4251def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4252def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4253def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4254def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
Chris Lattnere82f3362010-03-28 08:36:45 +00004255def : Pat<(v2f64 (bitconvert (v4f32 VECREG:$src))), (v2f64 VECREG:$src)>;
Scott Michel66377522007-12-04 22:35:58 +00004256
Scott Michel6e1d1472009-03-16 18:47:25 +00004257def : Pat<(i128 (bitconvert (v16i8 VECREG:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004258 (COPY_TO_REGCLASS VECREG:$src, GPRC)>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004259def : Pat<(i128 (bitconvert (v8i16 VECREG:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004260 (COPY_TO_REGCLASS VECREG:$src, GPRC)>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004261def : Pat<(i128 (bitconvert (v4i32 VECREG:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004262 (COPY_TO_REGCLASS VECREG:$src, GPRC)>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004263def : Pat<(i128 (bitconvert (v2i64 VECREG:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004264 (COPY_TO_REGCLASS VECREG:$src, GPRC)>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004265def : Pat<(i128 (bitconvert (v4f32 VECREG:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004266 (COPY_TO_REGCLASS VECREG:$src, GPRC)>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004267def : Pat<(i128 (bitconvert (v2f64 VECREG:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004268 (COPY_TO_REGCLASS VECREG:$src, GPRC)>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004269
4270def : Pat<(v16i8 (bitconvert (i128 GPRC:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004271 (v16i8 (COPY_TO_REGCLASS GPRC:$src, VECREG))>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004272def : Pat<(v8i16 (bitconvert (i128 GPRC:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004273 (v8i16 (COPY_TO_REGCLASS GPRC:$src, VECREG))>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004274def : Pat<(v4i32 (bitconvert (i128 GPRC:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004275 (v4i32 (COPY_TO_REGCLASS GPRC:$src, VECREG))>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004276def : Pat<(v2i64 (bitconvert (i128 GPRC:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004277 (v2i64 (COPY_TO_REGCLASS GPRC:$src, VECREG))>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004278def : Pat<(v4f32 (bitconvert (i128 GPRC:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004279 (v4f32 (COPY_TO_REGCLASS GPRC:$src, VECREG))>;
Scott Michel6e1d1472009-03-16 18:47:25 +00004280def : Pat<(v2f64 (bitconvert (i128 GPRC:$src))),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004281 (v2f64 (COPY_TO_REGCLASS GPRC:$src, VECREG))>;
4282
4283def : Pat<(i32 (bitconvert R32FP:$rA)),
4284 (COPY_TO_REGCLASS R32FP:$rA, R32C)>;
4285
4286def : Pat<(f32 (bitconvert R32C:$rA)),
4287 (COPY_TO_REGCLASS R32C:$rA, R32FP)>;
4288
4289def : Pat<(i64 (bitconvert R64FP:$rA)),
4290 (COPY_TO_REGCLASS R64FP:$rA, R64C)>;
4291
4292def : Pat<(f64 (bitconvert R64C:$rA)),
4293 (COPY_TO_REGCLASS R64C:$rA, R64FP)>;
4294
Scott Michel66377522007-12-04 22:35:58 +00004295
4296//===----------------------------------------------------------------------===//
4297// Instruction patterns:
4298//===----------------------------------------------------------------------===//
4299
4300// General 32-bit constants:
4301def : Pat<(i32 imm:$imm),
4302 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4303
4304// Single precision float constants:
Nate Begemanccef5802008-02-14 18:43:04 +00004305def : Pat<(f32 fpimm:$imm),
Scott Michel66377522007-12-04 22:35:58 +00004306 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4307
4308// General constant 32-bit vectors
4309def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michelad2715e2008-03-05 23:02:02 +00004310 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4311 (LO16_vec v4i32Imm:$imm))>;
Scott Michelf0569be2008-12-27 04:51:36 +00004312
Scott Michel504c3692007-12-17 22:32:34 +00004313// 8-bit constants
4314def : Pat<(i8 imm:$imm),
4315 (ILHr8 imm:$imm)>;
Scott Michel66377522007-12-04 22:35:58 +00004316
4317//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004318// Zero/Any/Sign extensions
4319//===----------------------------------------------------------------------===//
4320
Scott Michel66377522007-12-04 22:35:58 +00004321// sext 8->32: Sign extend bytes to words
4322def : Pat<(sext_inreg R32C:$rSrc, i8),
4323 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4324
Scott Michel504c3692007-12-17 22:32:34 +00004325def : Pat<(i32 (sext R8C:$rSrc)),
4326 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4327
Scott Micheldd950092009-01-06 03:36:14 +00004328// sext 8->64: Sign extend bytes to double word
4329def : Pat<(sext_inreg R64C:$rSrc, i8),
4330 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4331
4332def : Pat<(i64 (sext R8C:$rSrc)),
4333 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4334
Scott Michel504c3692007-12-17 22:32:34 +00004335// zext 8->16: Zero extend bytes to halfwords
4336def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004337 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004338
Scott Michel504c3692007-12-17 22:32:34 +00004339// zext 8->32: Zero extend bytes to words
4340def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004341 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004342
Scott Micheldd950092009-01-06 03:36:14 +00004343// zext 8->64: Zero extend bytes to double words
4344def : Pat<(i64 (zext R8C:$rSrc)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004345 (COPY_TO_REGCLASS (SELBv4i32 (ROTQMBYv4i32
4346 (COPY_TO_REGCLASS
4347 (ANDIi8i32 R8C:$rSrc,0xff), VECREG),
Scott Micheldd950092009-01-06 03:36:14 +00004348 0x4),
4349 (ILv4i32 0x0),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004350 (FSMBIv4i32 0x0f0f)), R64C)>;
Scott Micheldd950092009-01-06 03:36:14 +00004351
4352// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004353def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004354 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel504c3692007-12-17 22:32:34 +00004355
Scott Micheldd950092009-01-06 03:36:14 +00004356// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004357def : Pat<(i32 (anyext R8C:$rSrc)),
Kalle Raiskila82581352010-10-01 09:20:01 +00004358 (COPY_TO_REGCLASS R8C:$rSrc, R32C)>;
Scott Michel504c3692007-12-17 22:32:34 +00004359
Scott Micheldd950092009-01-06 03:36:14 +00004360// sext 16->64: Sign extend halfword to double word
4361def : Pat<(sext_inreg R64C:$rSrc, i16),
4362 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4363
4364def : Pat<(sext R16C:$rSrc),
4365 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4366
Scott Michela59d4692008-02-23 18:41:37 +00004367// zext 16->32: Zero extend halfwords to words
Scott Michel66377522007-12-04 22:35:58 +00004368def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004369 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel66377522007-12-04 22:35:58 +00004370
4371def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michela59d4692008-02-23 18:41:37 +00004372 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel66377522007-12-04 22:35:58 +00004373
4374def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michela59d4692008-02-23 18:41:37 +00004375 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel66377522007-12-04 22:35:58 +00004376
4377def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michela59d4692008-02-23 18:41:37 +00004378 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel66377522007-12-04 22:35:58 +00004379
4380// anyext 16->32: Extend 16->32 bits, irrespective of sign
4381def : Pat<(i32 (anyext R16C:$rSrc)),
Kalle Raiskila82581352010-10-01 09:20:01 +00004382 (COPY_TO_REGCLASS R16C:$rSrc, R32C)>;
Scott Michel66377522007-12-04 22:35:58 +00004383
4384//===----------------------------------------------------------------------===//
Scott Michelf0569be2008-12-27 04:51:36 +00004385// Truncates:
4386// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4387// above are custom lowered.
4388//===----------------------------------------------------------------------===//
4389
4390def : Pat<(i8 (trunc GPRC:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004391 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004392 (SHUFBgprc GPRC:$src, GPRC:$src,
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004393 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)), R8C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004394
4395def : Pat<(i8 (trunc R64C:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004396 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004397 (SHUFBv2i64_m32
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004398 (COPY_TO_REGCLASS R64C:$src, VECREG),
4399 (COPY_TO_REGCLASS R64C:$src, VECREG),
4400 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)), R8C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004401
4402def : Pat<(i8 (trunc R32C:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004403 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004404 (SHUFBv4i32_m32
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004405 (COPY_TO_REGCLASS R32C:$src, VECREG),
4406 (COPY_TO_REGCLASS R32C:$src, VECREG),
4407 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)), R8C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004408
4409def : Pat<(i8 (trunc R16C:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004410 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004411 (SHUFBv4i32_m32
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004412 (COPY_TO_REGCLASS R16C:$src, VECREG),
4413 (COPY_TO_REGCLASS R16C:$src, VECREG),
4414 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)), R8C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004415
4416def : Pat<(i16 (trunc GPRC:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004417 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004418 (SHUFBgprc GPRC:$src, GPRC:$src,
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004419 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)), R16C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004420
4421def : Pat<(i16 (trunc R64C:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004422 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004423 (SHUFBv2i64_m32
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004424 (COPY_TO_REGCLASS R64C:$src, VECREG),
4425 (COPY_TO_REGCLASS R64C:$src, VECREG),
4426 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)), R16C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004427
4428def : Pat<(i16 (trunc R32C:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004429 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004430 (SHUFBv4i32_m32
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004431 (COPY_TO_REGCLASS R32C:$src, VECREG),
4432 (COPY_TO_REGCLASS R32C:$src, VECREG),
4433 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)), R16C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004434
4435def : Pat<(i32 (trunc GPRC:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004436 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004437 (SHUFBgprc GPRC:$src, GPRC:$src,
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004438 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)), R32C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004439
4440def : Pat<(i32 (trunc R64C:$src)),
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004441 (COPY_TO_REGCLASS
Scott Michelf0569be2008-12-27 04:51:36 +00004442 (SHUFBv2i64_m32
Kalle Raiskila1cd1b0b2010-09-16 12:29:33 +00004443 (COPY_TO_REGCLASS R64C:$src, VECREG),
4444 (COPY_TO_REGCLASS R64C:$src, VECREG),
4445 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)), R32C)>;
Scott Michelf0569be2008-12-27 04:51:36 +00004446
4447//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00004448// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel66377522007-12-04 22:35:58 +00004449// low parts in order to load them into a register.
4450//===----------------------------------------------------------------------===//
4451
Scott Michel053c1da2008-01-29 02:16:57 +00004452def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4453def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4454def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4455def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4456
4457def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4458 (SPUlo tglobaladdr:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004459 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004460
Scott Michel053c1da2008-01-29 02:16:57 +00004461def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4462 (SPUlo texternalsym:$in, 0)),
4463 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4464
4465def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4466 (SPUlo tjumptable:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004467 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004468
Scott Michel053c1da2008-01-29 02:16:57 +00004469def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4470 (SPUlo tconstpool:$in, 0)),
4471 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4472
4473def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4474 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4475
4476def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4477 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4478
4479def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4480 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4481
4482def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4483 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel66377522007-12-04 22:35:58 +00004484
Scott Michel6e1d1472009-03-16 18:47:25 +00004485// Intrinsics:
Scott Michel66377522007-12-04 22:35:58 +00004486include "CellSDKIntrinsics.td"
Scott Michel02d711b2008-12-30 23:28:25 +00004487// Various math operator instruction sequences
4488include "SPUMathInstr.td"
Scott Michelf0569be2008-12-27 04:51:36 +00004489// 64-bit "instructions"/support
4490include "SPU64InstrInfo.td"
Scott Micheldd950092009-01-06 03:36:14 +00004491// 128-bit "instructions"/support
4492include "SPU128InstrInfo.td"