blob: 803ce567dc46f818529c7227da6323cb0070c40c [file] [log] [blame]
Scott Michel8b6b4202007-12-04 22:35:58 +00001//==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
Scott Michel06eabde2008-12-27 04:51:36 +00002//
Scott Michel8b6b4202007-12-04 22:35:58 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michel06eabde2008-12-27 04:51:36 +00007//
Scott Michel8b6b4202007-12-04 22:35:58 +00008//===----------------------------------------------------------------------===//
9// Cell SPU Instructions:
10//===----------------------------------------------------------------------===//
11
12//===----------------------------------------------------------------------===//
13// TODO Items (not urgent today, but would be nice, low priority)
14//
15// ANDBI, ORBI: SPU constructs a 4-byte constant for these instructions by
16// concatenating the byte argument b as "bbbb". Could recognize this bit pattern
17// in 16-bit and 32-bit constants and reduce instruction count.
18//===----------------------------------------------------------------------===//
19
20//===----------------------------------------------------------------------===//
21// Pseudo instructions:
22//===----------------------------------------------------------------------===//
23
24let hasCtrlDep = 1, Defs = [R1], Uses = [R1] in {
Scott Michelbc5fbc12008-04-30 00:30:08 +000025 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000026 "${:comment} ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000027 [(callseq_start timm:$amt)]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +000028 def ADJCALLSTACKUP : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000029 "${:comment} ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000030 [(callseq_end timm:$amt)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +000031}
32
33//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +000034// Loads:
35// NB: The ordering is actually important, since the instruction selection
36// will try each of the instructions in sequence, i.e., the D-form first with
37// the 10-bit displacement, then the A-form with the 16 bit displacement, and
38// finally the X-form with the register-register.
39//===----------------------------------------------------------------------===//
40
Dan Gohman5574cc72008-12-03 18:15:48 +000041let canFoldAsLoad = 1 in {
Scott Michelf9f42e62008-01-29 02:16:57 +000042 class LoadDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +000043 : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000044 "lqd\t$rT, $src",
45 LoadStore,
46 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
47 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000048
Scott Michelf9f42e62008-01-29 02:16:57 +000049 class LoadDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +000050 : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000051 "lqd\t$rT, $src",
52 LoadStore,
53 [(set rclass:$rT, (load dform_addr:$src))]>
54 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000055
Scott Michelf9f42e62008-01-29 02:16:57 +000056 multiclass LoadDForms
57 {
58 def v16i8: LoadDFormVec<v16i8>;
59 def v8i16: LoadDFormVec<v8i16>;
60 def v4i32: LoadDFormVec<v4i32>;
61 def v2i64: LoadDFormVec<v2i64>;
62 def v4f32: LoadDFormVec<v4f32>;
63 def v2f64: LoadDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000064
Scott Michel70741542009-01-06 23:10:38 +000065 def v2i32: LoadDFormVec<v2i32>;
66
Scott Michelf9f42e62008-01-29 02:16:57 +000067 def r128: LoadDForm<GPRC>;
68 def r64: LoadDForm<R64C>;
69 def r32: LoadDForm<R32C>;
70 def f32: LoadDForm<R32FP>;
71 def f64: LoadDForm<R64FP>;
72 def r16: LoadDForm<R16C>;
73 def r8: LoadDForm<R8C>;
74 }
Scott Michel8b6b4202007-12-04 22:35:58 +000075
Scott Michelf9f42e62008-01-29 02:16:57 +000076 class LoadAFormVec<ValueType vectype>
77 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
78 "lqa\t$rT, $src",
79 LoadStore,
80 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
81 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000082
Scott Michelf9f42e62008-01-29 02:16:57 +000083 class LoadAForm<RegisterClass rclass>
84 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
85 "lqa\t$rT, $src",
86 LoadStore,
87 [(set rclass:$rT, (load aform_addr:$src))]>
88 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000089
Scott Michelf9f42e62008-01-29 02:16:57 +000090 multiclass LoadAForms
91 {
92 def v16i8: LoadAFormVec<v16i8>;
93 def v8i16: LoadAFormVec<v8i16>;
94 def v4i32: LoadAFormVec<v4i32>;
95 def v2i64: LoadAFormVec<v2i64>;
96 def v4f32: LoadAFormVec<v4f32>;
97 def v2f64: LoadAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000098
Scott Michel70741542009-01-06 23:10:38 +000099 def v2i32: LoadAFormVec<v2i32>;
100
Scott Michelf9f42e62008-01-29 02:16:57 +0000101 def r128: LoadAForm<GPRC>;
102 def r64: LoadAForm<R64C>;
103 def r32: LoadAForm<R32C>;
104 def f32: LoadAForm<R32FP>;
105 def f64: LoadAForm<R64FP>;
106 def r16: LoadAForm<R16C>;
107 def r8: LoadAForm<R8C>;
108 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000109
Scott Michelf9f42e62008-01-29 02:16:57 +0000110 class LoadXFormVec<ValueType vectype>
111 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
112 "lqx\t$rT, $src",
113 LoadStore,
114 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
115 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000116
Scott Michelf9f42e62008-01-29 02:16:57 +0000117 class LoadXForm<RegisterClass rclass>
118 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
119 "lqx\t$rT, $src",
120 LoadStore,
121 [(set rclass:$rT, (load xform_addr:$src))]>
122 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000123
Scott Michelf9f42e62008-01-29 02:16:57 +0000124 multiclass LoadXForms
125 {
126 def v16i8: LoadXFormVec<v16i8>;
127 def v8i16: LoadXFormVec<v8i16>;
128 def v4i32: LoadXFormVec<v4i32>;
129 def v2i64: LoadXFormVec<v2i64>;
130 def v4f32: LoadXFormVec<v4f32>;
131 def v2f64: LoadXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000132
Scott Michel70741542009-01-06 23:10:38 +0000133 def v2i32: LoadXFormVec<v2i32>;
134
Scott Michelf9f42e62008-01-29 02:16:57 +0000135 def r128: LoadXForm<GPRC>;
136 def r64: LoadXForm<R64C>;
137 def r32: LoadXForm<R32C>;
138 def f32: LoadXForm<R32FP>;
139 def f64: LoadXForm<R64FP>;
140 def r16: LoadXForm<R16C>;
141 def r8: LoadXForm<R8C>;
142 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000143
Scott Michelf9f42e62008-01-29 02:16:57 +0000144 defm LQA : LoadAForms;
145 defm LQD : LoadDForms;
146 defm LQX : LoadXForms;
Scott Michel438be252007-12-17 22:32:34 +0000147
Scott Michel8b6b4202007-12-04 22:35:58 +0000148/* Load quadword, PC relative: Not much use at this point in time.
Scott Michelf9f42e62008-01-29 02:16:57 +0000149 Might be of use later for relocatable code. It's effectively the
150 same as LQA, but uses PC-relative addressing.
Scott Michel8b6b4202007-12-04 22:35:58 +0000151 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
152 "lqr\t$rT, $disp", LoadStore,
153 [(set VECREG:$rT, (load iaddr:$disp))]>;
154 */
Scott Michel8b6b4202007-12-04 22:35:58 +0000155}
156
157//===----------------------------------------------------------------------===//
158// Stores:
159//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +0000160class StoreDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +0000161 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000162 "stqd\t$rT, $src",
163 LoadStore,
164 [(store (vectype VECREG:$rT), dform_addr:$src)]>
165{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000166
Scott Michelf9f42e62008-01-29 02:16:57 +0000167class StoreDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +0000168 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000169 "stqd\t$rT, $src",
170 LoadStore,
171 [(store rclass:$rT, dform_addr:$src)]>
172{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000173
Scott Michelf9f42e62008-01-29 02:16:57 +0000174multiclass StoreDForms
175{
176 def v16i8: StoreDFormVec<v16i8>;
177 def v8i16: StoreDFormVec<v8i16>;
178 def v4i32: StoreDFormVec<v4i32>;
179 def v2i64: StoreDFormVec<v2i64>;
180 def v4f32: StoreDFormVec<v4f32>;
181 def v2f64: StoreDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000182
Scott Michel70741542009-01-06 23:10:38 +0000183 def v2i32: StoreDFormVec<v2i32>;
184
Scott Michelf9f42e62008-01-29 02:16:57 +0000185 def r128: StoreDForm<GPRC>;
186 def r64: StoreDForm<R64C>;
187 def r32: StoreDForm<R32C>;
188 def f32: StoreDForm<R32FP>;
189 def f64: StoreDForm<R64FP>;
190 def r16: StoreDForm<R16C>;
191 def r8: StoreDForm<R8C>;
192}
Scott Michel8b6b4202007-12-04 22:35:58 +0000193
Scott Michelf9f42e62008-01-29 02:16:57 +0000194class StoreAFormVec<ValueType vectype>
195 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000196 "stqa\t$rT, $src",
197 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000198 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000199
Scott Michelf9f42e62008-01-29 02:16:57 +0000200class StoreAForm<RegisterClass rclass>
201 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000202 "stqa\t$rT, $src",
203 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000204 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000205
Scott Michelf9f42e62008-01-29 02:16:57 +0000206multiclass StoreAForms
207{
208 def v16i8: StoreAFormVec<v16i8>;
209 def v8i16: StoreAFormVec<v8i16>;
210 def v4i32: StoreAFormVec<v4i32>;
211 def v2i64: StoreAFormVec<v2i64>;
212 def v4f32: StoreAFormVec<v4f32>;
213 def v2f64: StoreAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000214
Scott Michel70741542009-01-06 23:10:38 +0000215 def v2i32: StoreAFormVec<v2i32>;
216
Scott Michelf9f42e62008-01-29 02:16:57 +0000217 def r128: StoreAForm<GPRC>;
218 def r64: StoreAForm<R64C>;
219 def r32: StoreAForm<R32C>;
220 def f32: StoreAForm<R32FP>;
221 def f64: StoreAForm<R64FP>;
222 def r16: StoreAForm<R16C>;
223 def r8: StoreAForm<R8C>;
224}
Scott Michel8b6b4202007-12-04 22:35:58 +0000225
Scott Michelf9f42e62008-01-29 02:16:57 +0000226class StoreXFormVec<ValueType vectype>
227 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000228 "stqx\t$rT, $src",
229 LoadStore,
230 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000231{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000232
Scott Michelf9f42e62008-01-29 02:16:57 +0000233class StoreXForm<RegisterClass rclass>
234 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000235 "stqx\t$rT, $src",
236 LoadStore,
237 [(store rclass:$rT, xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000238{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000239
Scott Michelf9f42e62008-01-29 02:16:57 +0000240multiclass StoreXForms
241{
242 def v16i8: StoreXFormVec<v16i8>;
243 def v8i16: StoreXFormVec<v8i16>;
244 def v4i32: StoreXFormVec<v4i32>;
245 def v2i64: StoreXFormVec<v2i64>;
246 def v4f32: StoreXFormVec<v4f32>;
247 def v2f64: StoreXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000248
Scott Michel70741542009-01-06 23:10:38 +0000249 def v2i32: StoreXFormVec<v2i32>;
250
Scott Michelf9f42e62008-01-29 02:16:57 +0000251 def r128: StoreXForm<GPRC>;
252 def r64: StoreXForm<R64C>;
253 def r32: StoreXForm<R32C>;
254 def f32: StoreXForm<R32FP>;
255 def f64: StoreXForm<R64FP>;
256 def r16: StoreXForm<R16C>;
257 def r8: StoreXForm<R8C>;
258}
Scott Michel8b6b4202007-12-04 22:35:58 +0000259
Scott Michelf9f42e62008-01-29 02:16:57 +0000260defm STQD : StoreDForms;
261defm STQA : StoreAForms;
262defm STQX : StoreXForms;
Scott Michel8b6b4202007-12-04 22:35:58 +0000263
264/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michelf9f42e62008-01-29 02:16:57 +0000265 be useful for relocatable code.
Chris Lattneref8d6082008-01-06 06:44:58 +0000266def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
267 "stqr\t$rT, $disp", LoadStore,
268 [(store VECREG:$rT, iaddr:$disp)]>;
269*/
Scott Michel8b6b4202007-12-04 22:35:58 +0000270
271//===----------------------------------------------------------------------===//
272// Generate Controls for Insertion:
273//===----------------------------------------------------------------------===//
274
Scott Michel06eabde2008-12-27 04:51:36 +0000275def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000276 "cbd\t$rT, $src", ShuffleOp,
277 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000278
Scott Michel0718cd82008-12-01 17:56:02 +0000279def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000280 "cbx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000281 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000282
Scott Michel06eabde2008-12-27 04:51:36 +0000283def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000284 "chd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000285 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000286
Scott Michel0718cd82008-12-01 17:56:02 +0000287def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000288 "chx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000289 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000290
Scott Michel06eabde2008-12-27 04:51:36 +0000291def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000292 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000293 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000294
Scott Michel0718cd82008-12-01 17:56:02 +0000295def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000296 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000297 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000298
Scott Michel06eabde2008-12-27 04:51:36 +0000299def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000300 "cwd\t$rT, $src", ShuffleOp,
301 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
302
303def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000304 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000305 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000306
Scott Michel06eabde2008-12-27 04:51:36 +0000307def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000308 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000309 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000310
Scott Michel0718cd82008-12-01 17:56:02 +0000311def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000312 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000313 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000314
Scott Michel06eabde2008-12-27 04:51:36 +0000315def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000316 "cdd\t$rT, $src", ShuffleOp,
317 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
318
319def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000320 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000321 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000322
Scott Michel8b6b4202007-12-04 22:35:58 +0000323//===----------------------------------------------------------------------===//
324// Constant formation:
325//===----------------------------------------------------------------------===//
326
327def ILHv8i16:
328 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
329 "ilh\t$rT, $val", ImmLoad,
330 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
331
332def ILHr16:
333 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
334 "ilh\t$rT, $val", ImmLoad,
335 [(set R16C:$rT, immSExt16:$val)]>;
336
Scott Michel438be252007-12-17 22:32:34 +0000337// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
338// the right constant")
339def ILHr8:
340 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
341 "ilh\t$rT, $val", ImmLoad,
342 [(set R8C:$rT, immSExt8:$val)]>;
343
Scott Michel8b6b4202007-12-04 22:35:58 +0000344// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000345
Scott Michel6baba072008-03-05 23:02:02 +0000346class ILInst<dag OOL, dag IOL, list<dag> pattern>:
347 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
348 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000349
Scott Michel6baba072008-03-05 23:02:02 +0000350class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
351 ILInst<(outs VECREG:$rT), (ins immtype:$val),
352 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000353
Scott Michel6baba072008-03-05 23:02:02 +0000354class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
355 ILInst<(outs rclass:$rT), (ins immtype:$val),
356 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000357
Scott Michel6baba072008-03-05 23:02:02 +0000358multiclass ImmediateLoad
359{
360 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
361 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000362
Scott Michel6baba072008-03-05 23:02:02 +0000363 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000364
Scott Michel6baba072008-03-05 23:02:02 +0000365 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
366 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
367 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
368 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
369}
Scott Michel8b6b4202007-12-04 22:35:58 +0000370
Scott Michel6baba072008-03-05 23:02:02 +0000371defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000372
Scott Michel6baba072008-03-05 23:02:02 +0000373class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
374 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
375 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000376
Scott Michel6baba072008-03-05 23:02:02 +0000377class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
378 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
379 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
380
381class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
382 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
383 [(set rclass:$rT, xform:$val)]>;
384
385multiclass ImmLoadHalfwordUpper
386{
387 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000388 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000389
390 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000391 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000392
393 // Loads the high portion of an address
394 def hi: ILHURegInst<R32C, symbolHi, hi16>;
395
396 // Used in custom lowering constant SFP loads:
397 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
398}
399
400defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000401
402// Immediate load address (can also be used to load 18-bit unsigned constants,
403// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000404
Scott Michel97872d32008-02-23 18:41:37 +0000405class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
406 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
407 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000408
Scott Michel6baba072008-03-05 23:02:02 +0000409class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
410 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
411 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
412
413class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
414 ILAInst<(outs rclass:$rT), (ins immtype:$val),
415 [(set rclass:$rT, xform:$val)]>;
416
Scott Michel97872d32008-02-23 18:41:37 +0000417multiclass ImmLoadAddress
418{
Scott Michel6baba072008-03-05 23:02:02 +0000419 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
420 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000421
Scott Michel6baba072008-03-05 23:02:02 +0000422 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
423 def r32: ILARegInst<R32C, u18imm, imm18>;
424 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
425 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000426
Scott Michel06eabde2008-12-27 04:51:36 +0000427 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michel6baba072008-03-05 23:02:02 +0000428 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000429
Scott Michel97872d32008-02-23 18:41:37 +0000430 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
431 [/* no pattern */]>;
432}
433
434defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000435
436// Immediate OR, Halfword Lower: The "other" part of loading large constants
437// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
438// Note that these are really two operand instructions, but they're encoded
439// as three operands with the first two arguments tied-to each other.
440
Scott Michel6baba072008-03-05 23:02:02 +0000441class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
442 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
443 ImmLoad, pattern>,
444 RegConstraint<"$rS = $rT">,
445 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000446
Scott Michel6baba072008-03-05 23:02:02 +0000447class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
448 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
449 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000450
Scott Michel6baba072008-03-05 23:02:02 +0000451class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
452 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
453 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000454
Scott Michel6baba072008-03-05 23:02:02 +0000455multiclass ImmOrHalfwordLower
456{
457 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000458 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000459
460 def r32: IOHLRegInst<R32C, i32imm>;
461 def f32: IOHLRegInst<R32FP, f32imm>;
462
463 def lo: IOHLRegInst<R32C, symbolLo>;
464}
465
466defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000467
Scott Michel8b6b4202007-12-04 22:35:58 +0000468// Form select mask for bytes using immediate, used in conjunction with the
469// SELB instruction:
470
Scott Michel6baba072008-03-05 23:02:02 +0000471class FSMBIVec<ValueType vectype>:
472 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
473 "fsmbi\t$rT, $val",
474 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000475 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000476
Scott Michel97872d32008-02-23 18:41:37 +0000477multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000478{
479 def v16i8: FSMBIVec<v16i8>;
480 def v8i16: FSMBIVec<v8i16>;
481 def v4i32: FSMBIVec<v4i32>;
482 def v2i64: FSMBIVec<v2i64>;
483}
Scott Michel8b6b4202007-12-04 22:35:58 +0000484
Scott Michel97872d32008-02-23 18:41:37 +0000485defm FSMBI : FormSelectMaskBytesImm;
486
487// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michel06eabde2008-12-27 04:51:36 +0000488class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
489 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
490 pattern>;
491
492class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
493 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
494 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
495
496class FSMBVecInst<ValueType vectype>:
497 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
498 [(set (vectype VECREG:$rT),
499 (SPUselmask (vectype VECREG:$rA)))]>;
500
501multiclass FormSelectMaskBits {
502 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
503 def v16i8: FSMBVecInst<v16i8>;
504}
505
506defm FSMB: FormSelectMaskBits;
Scott Michel97872d32008-02-23 18:41:37 +0000507
508// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
509// only 8-bits wide (even though it's input as 16-bits here)
Scott Michel06eabde2008-12-27 04:51:36 +0000510
511class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
512 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
513 pattern>;
514
515class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
516 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
517 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
518
519class FSMHVecInst<ValueType vectype>:
520 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
521 [(set (vectype VECREG:$rT),
522 (SPUselmask (vectype VECREG:$rA)))]>;
523
524multiclass FormSelectMaskHalfword {
525 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
526 def v8i16: FSMHVecInst<v8i16>;
527}
528
529defm FSMH: FormSelectMaskHalfword;
Scott Michel97872d32008-02-23 18:41:37 +0000530
531// fsm: Form select mask for words. Like the other fsm* instructions,
532// only the lower 4 bits of $rA are significant.
Scott Michel06eabde2008-12-27 04:51:36 +0000533
534class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
535 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
536 pattern>;
537
538class FSMRegInst<ValueType vectype, RegisterClass rclass>:
539 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
540 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
541
542class FSMVecInst<ValueType vectype>:
543 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
544 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel67224b22008-06-02 22:18:03 +0000545
546multiclass FormSelectMaskWord {
Scott Michel06eabde2008-12-27 04:51:36 +0000547 def v4i32: FSMVecInst<v4i32>;
548
549 def r32 : FSMRegInst<v4i32, R32C>;
550 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000551}
552
553defm FSM : FormSelectMaskWord;
554
555// Special case when used for i64 math operations
556multiclass FormSelectMaskWord64 {
Scott Michel06eabde2008-12-27 04:51:36 +0000557 def r32 : FSMRegInst<v2i64, R32C>;
558 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000559}
560
561defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000562
563//===----------------------------------------------------------------------===//
564// Integer and Logical Operations:
565//===----------------------------------------------------------------------===//
566
567def AHv8i16:
568 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
569 "ah\t$rT, $rA, $rB", IntegerOp,
570 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
571
572def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
573 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
574
Scott Michel8b6b4202007-12-04 22:35:58 +0000575def AHr16:
576 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
577 "ah\t$rT, $rA, $rB", IntegerOp,
578 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
579
580def AHIvec:
581 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
582 "ahi\t$rT, $rA, $val", IntegerOp,
583 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
584 v8i16SExt10Imm:$val))]>;
585
Scott Michel97872d32008-02-23 18:41:37 +0000586def AHIr16:
587 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
588 "ahi\t$rT, $rA, $val", IntegerOp,
Scott Michel4d07fb72008-12-30 23:28:25 +0000589 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
590
591// v4i32, i32 add instruction:
Scott Michel8b6b4202007-12-04 22:35:58 +0000592
Scott Michelae5cbf52008-12-29 03:23:36 +0000593class AInst<dag OOL, dag IOL, list<dag> pattern>:
594 RRForm<0b00000011000, OOL, IOL,
595 "a\t$rT, $rA, $rB", IntegerOp,
596 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000597
Scott Michelae5cbf52008-12-29 03:23:36 +0000598class AVecInst<ValueType vectype>:
599 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
600 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
601 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000602
Scott Michelae5cbf52008-12-29 03:23:36 +0000603class ARegInst<RegisterClass rclass>:
604 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
605 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
606
607multiclass AddInstruction {
608 def v4i32: AVecInst<v4i32>;
609 def v16i8: AVecInst<v16i8>;
Kalle Raiskila602375b2010-08-02 08:54:39 +0000610 def v2i32: AVecInst<v2i32>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000611 def r32: ARegInst<R32C>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000612}
Scott Michel8b6b4202007-12-04 22:35:58 +0000613
Scott Michelae5cbf52008-12-29 03:23:36 +0000614defm A : AddInstruction;
Scott Michel438be252007-12-17 22:32:34 +0000615
Scott Michel4d07fb72008-12-30 23:28:25 +0000616class AIInst<dag OOL, dag IOL, list<dag> pattern>:
617 RI10Form<0b00111000, OOL, IOL,
pingbakb8913342009-01-26 03:37:41 +0000618 "ai\t$rT, $rA, $val", IntegerOp,
619 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000620
Scott Michel4d07fb72008-12-30 23:28:25 +0000621class AIVecInst<ValueType vectype, PatLeaf immpred>:
622 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
pingbakb8913342009-01-26 03:37:41 +0000623 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000624
625class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
626 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
pingbakb8913342009-01-26 03:37:41 +0000627 [/* no pattern */]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000628
629class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
630 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +0000631 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000632
633// This is used to add epsilons to floating point numbers in the f32 fdiv code:
634class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
635 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +0000636 [/* no pattern */]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000637
638multiclass AddImmediate {
639 def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
640
641 def r32: AIRegInst<R32C, i32ImmSExt10>;
642
643 def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
644 def f32: AIFPInst<R32FP, i32ImmSExt10>;
645}
646
647defm AI : AddImmediate;
Scott Michel8b6b4202007-12-04 22:35:58 +0000648
Scott Michel438be252007-12-17 22:32:34 +0000649def SFHvec:
650 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
651 "sfh\t$rT, $rA, $rB", IntegerOp,
652 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
653 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000654
Scott Michel438be252007-12-17 22:32:34 +0000655def SFHr16:
656 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
657 "sfh\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskilab2e65212010-05-10 08:13:49 +0000658 [(set R16C:$rT, (sub R16C:$rB, R16C:$rA))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000659
660def SFHIvec:
661 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
662 "sfhi\t$rT, $rA, $val", IntegerOp,
663 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
664 (v8i16 VECREG:$rA)))]>;
665
666def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
667 "sfhi\t$rT, $rA, $val", IntegerOp,
668 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
669
670def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
671 (ins VECREG:$rA, VECREG:$rB),
672 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskilab2e65212010-05-10 08:13:49 +0000673 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rB), (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000674
Kalle Raiskila602375b2010-08-02 08:54:39 +0000675def SF2vec : RRForm<0b00000010000, (outs VECREG:$rT),
676 (ins VECREG:$rA, VECREG:$rB),
677 "sf\t$rT, $rA, $rB", IntegerOp,
678 [(set (v2i32 VECREG:$rT), (sub (v2i32 VECREG:$rB), (v2i32 VECREG:$rA)))]>;
679
680
Scott Michel8b6b4202007-12-04 22:35:58 +0000681def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
682 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskilab2e65212010-05-10 08:13:49 +0000683 [(set R32C:$rT, (sub R32C:$rB, R32C:$rA))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000684
685def SFIvec:
686 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
687 "sfi\t$rT, $rA, $val", IntegerOp,
688 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
689 (v4i32 VECREG:$rA)))]>;
690
691def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
692 (ins R32C:$rA, s10imm_i32:$val),
693 "sfi\t$rT, $rA, $val", IntegerOp,
694 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
695
696// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000697class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
698 RRForm<0b00000010110, OOL, IOL,
699 "addx\t$rT, $rA, $rB",
700 IntegerOp, pattern>;
701
702class ADDXVecInst<ValueType vectype>:
703 ADDXInst<(outs VECREG:$rT),
704 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000705 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000706 RegConstraint<"$rCarry = $rT">,
707 NoEncode<"$rCarry">;
708
Scott Michel67224b22008-06-02 22:18:03 +0000709class ADDXRegInst<RegisterClass rclass>:
710 ADDXInst<(outs rclass:$rT),
711 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000712 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000713 RegConstraint<"$rCarry = $rT">,
714 NoEncode<"$rCarry">;
715
Scott Michel67224b22008-06-02 22:18:03 +0000716multiclass AddExtended {
717 def v2i64 : ADDXVecInst<v2i64>;
718 def v4i32 : ADDXVecInst<v4i32>;
719 def r64 : ADDXRegInst<R64C>;
720 def r32 : ADDXRegInst<R32C>;
721}
722
723defm ADDX : AddExtended;
724
725// CG: Generate carry for add
726class CGInst<dag OOL, dag IOL, list<dag> pattern>:
727 RRForm<0b01000011000, OOL, IOL,
728 "cg\t$rT, $rA, $rB",
729 IntegerOp, pattern>;
730
731class CGVecInst<ValueType vectype>:
732 CGInst<(outs VECREG:$rT),
733 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000734 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000735
736class CGRegInst<RegisterClass rclass>:
737 CGInst<(outs rclass:$rT),
738 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000739 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000740
741multiclass CarryGenerate {
742 def v2i64 : CGVecInst<v2i64>;
743 def v4i32 : CGVecInst<v4i32>;
744 def r64 : CGRegInst<R64C>;
745 def r32 : CGRegInst<R32C>;
746}
747
748defm CG : CarryGenerate;
749
750// SFX: Subract from, extended. This is used in conjunction with BG to subtract
751// with carry (borrow, in this case)
752class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
753 RRForm<0b10000010110, OOL, IOL,
754 "sfx\t$rT, $rA, $rB",
755 IntegerOp, pattern>;
756
757class SFXVecInst<ValueType vectype>:
758 SFXInst<(outs VECREG:$rT),
759 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000760 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000761 RegConstraint<"$rCarry = $rT">,
762 NoEncode<"$rCarry">;
763
Scott Michel67224b22008-06-02 22:18:03 +0000764class SFXRegInst<RegisterClass rclass>:
765 SFXInst<(outs rclass:$rT),
766 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000767 [/* no pattern */]>,
Scott Michel67224b22008-06-02 22:18:03 +0000768 RegConstraint<"$rCarry = $rT">,
769 NoEncode<"$rCarry">;
770
771multiclass SubtractExtended {
772 def v2i64 : SFXVecInst<v2i64>;
773 def v4i32 : SFXVecInst<v4i32>;
774 def r64 : SFXRegInst<R64C>;
775 def r32 : SFXRegInst<R32C>;
776}
777
778defm SFX : SubtractExtended;
779
Scott Michel8b6b4202007-12-04 22:35:58 +0000780// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000781class BGInst<dag OOL, dag IOL, list<dag> pattern>:
782 RRForm<0b01000010000, OOL, IOL,
783 "bg\t$rT, $rA, $rB",
784 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000785
Scott Michel67224b22008-06-02 22:18:03 +0000786class BGVecInst<ValueType vectype>:
787 BGInst<(outs VECREG:$rT),
788 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000789 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000790
791class BGRegInst<RegisterClass rclass>:
792 BGInst<(outs rclass:$rT),
793 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000794 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000795
796multiclass BorrowGenerate {
797 def v4i32 : BGVecInst<v4i32>;
798 def v2i64 : BGVecInst<v2i64>;
799 def r64 : BGRegInst<R64C>;
800 def r32 : BGRegInst<R32C>;
801}
802
803defm BG : BorrowGenerate;
804
805// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000806def BGXvec:
807 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000808 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000809 "bgx\t$rT, $rA, $rB", IntegerOp,
810 []>,
811 RegConstraint<"$rCarry = $rT">,
812 NoEncode<"$rCarry">;
813
814// Halfword multiply variants:
815// N.B: These can be used to build up larger quantities (16x16 -> 32)
816
817def MPYv8i16:
818 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
819 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000820 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000821
822def MPYr16:
823 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
824 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
825 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
826
Scott Michelae5cbf52008-12-29 03:23:36 +0000827// Unsigned 16-bit multiply:
828
829class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
830 RRForm<0b00110011110, OOL, IOL,
831 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
832 pattern>;
833
Scott Michel8b6b4202007-12-04 22:35:58 +0000834def MPYUv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000835 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000836 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000837
Kalle Raiskila602375b2010-08-02 08:54:39 +0000838def MPYUv2i32:
839 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
840 [/* no pattern */]>;
841
Scott Michel8b6b4202007-12-04 22:35:58 +0000842def MPYUr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000843 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
844 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000845
846def MPYUr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000847 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000848 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000849
Scott Michelae5cbf52008-12-29 03:23:36 +0000850// mpyi: multiply 16 x s10imm -> 32 result.
851
852class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
853 RI10Form<0b00101110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000854 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000855 pattern>;
856
857def MPYIvec:
858 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
859 [(set (v8i16 VECREG:$rT),
860 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000861
862def MPYIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000863 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
864 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000865
866// mpyui: same issues as other multiplies, plus, this doesn't match a
867// pattern... but may be used during target DAG selection or lowering
Scott Michelae5cbf52008-12-29 03:23:36 +0000868
869class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
870 RI10Form<0b10101110, OOL, IOL,
871 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
872 pattern>;
873
Scott Michel8b6b4202007-12-04 22:35:58 +0000874def MPYUIvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000875 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
876 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000877
878def MPYUIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000879 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
880 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000881
882// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michelae5cbf52008-12-29 03:23:36 +0000883class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
884 RRRForm<0b0011, OOL, IOL,
885 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
886 pattern>;
887
Scott Michel750b93f2009-01-15 04:41:47 +0000888def MPYAv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000889 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
890 [(set (v4i32 VECREG:$rT),
891 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
892 (v8i16 VECREG:$rB)))),
893 (v4i32 VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000894
895def MPYAr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000896 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
897 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
898 R32C:$rC))]>;
899
900def MPYAr32_sext:
901 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
902 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
903 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000904
905def MPYAr32_sextinreg:
Scott Michelae5cbf52008-12-29 03:23:36 +0000906 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
907 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
908 (sext_inreg R32C:$rB, i16)),
909 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000910
911// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michelae5cbf52008-12-29 03:23:36 +0000912class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
913 RRForm<0b10100011110, OOL, IOL,
914 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
915 pattern>;
916
Scott Michel8b6b4202007-12-04 22:35:58 +0000917def MPYHv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000918 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000919 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000920
Kalle Raiskila602375b2010-08-02 08:54:39 +0000921def MPYHv2i32:
922 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
923 [/* no pattern */]>;
924
Scott Michel8b6b4202007-12-04 22:35:58 +0000925def MPYHr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000926 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000927 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000928
929// mpys: multiply high and shift right (returns the top half of
930// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000931
Scott Michel4d07fb72008-12-30 23:28:25 +0000932class MPYSInst<dag OOL, dag IOL>:
933 RRForm<0b11100011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000934 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000935 [/* no pattern */]>;
936
Scott Michel750b93f2009-01-15 04:41:47 +0000937def MPYSv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000938 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
939
940def MPYSr16:
941 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000942
943// mpyhh: multiply high-high (returns the 32-bit result from multiplying
944// the top 16 bits of the $rA, $rB)
Scott Michel4d07fb72008-12-30 23:28:25 +0000945
946class MPYHHInst<dag OOL, dag IOL>:
947 RRForm<0b01100011110, OOL, IOL,
948 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
949 [/* no pattern */]>;
950
Scott Michel8b6b4202007-12-04 22:35:58 +0000951def MPYHHv8i16:
Scott Michel4d07fb72008-12-30 23:28:25 +0000952 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000953
954def MPYHHr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000955 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000956
957// mpyhha: Multiply high-high, add to $rT:
Scott Michel8b6b4202007-12-04 22:35:58 +0000958
Scott Michel4d07fb72008-12-30 23:28:25 +0000959class MPYHHAInst<dag OOL, dag IOL>:
960 RRForm<0b01100010110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000961 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000962 [/* no pattern */]>;
963
964def MPYHHAvec:
965 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
966
967def MPYHHAr32:
968 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000969
Scott Michel750b93f2009-01-15 04:41:47 +0000970// mpyhhu: Multiply high-high, unsigned, e.g.:
971//
972// +-------+-------+ +-------+-------+ +---------+
973// | a0 . a1 | x | b0 . b1 | = | a0 x b0 |
974// +-------+-------+ +-------+-------+ +---------+
975//
976// where a0, b0 are the upper 16 bits of the 32-bit word
Scott Michel8b6b4202007-12-04 22:35:58 +0000977
Scott Michel4d07fb72008-12-30 23:28:25 +0000978class MPYHHUInst<dag OOL, dag IOL>:
979 RRForm<0b01110011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000980 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000981 [/* no pattern */]>;
982
Scott Michel750b93f2009-01-15 04:41:47 +0000983def MPYHHUv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000984 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
985
986def MPYHHUr32:
987 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000988
989// mpyhhau: Multiply high-high, unsigned
Scott Michel4d07fb72008-12-30 23:28:25 +0000990
991class MPYHHAUInst<dag OOL, dag IOL>:
992 RRForm<0b01110010110, OOL, IOL,
993 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
994 [/* no pattern */]>;
995
Scott Michel8b6b4202007-12-04 22:35:58 +0000996def MPYHHAUvec:
Scott Michel4d07fb72008-12-30 23:28:25 +0000997 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
998
Scott Michel8b6b4202007-12-04 22:35:58 +0000999def MPYHHAUr32:
Scott Michel4d07fb72008-12-30 23:28:25 +00001000 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michelae5cbf52008-12-29 03:23:36 +00001001
1002//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001003// clz: Count leading zeroes
Scott Michelae5cbf52008-12-29 03:23:36 +00001004//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel06eabde2008-12-27 04:51:36 +00001005class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
1006 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
1007 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001008
Scott Michel06eabde2008-12-27 04:51:36 +00001009class CLZRegInst<RegisterClass rclass>:
1010 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel4d07fb72008-12-30 23:28:25 +00001011 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001012
1013class CLZVecInst<ValueType vectype>:
1014 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1015 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1016
1017multiclass CountLeadingZeroes {
1018 def v4i32 : CLZVecInst<v4i32>;
1019 def r32 : CLZRegInst<R32C>;
1020}
1021
1022defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001023
1024// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +00001025//
Scott Michel8b6b4202007-12-04 22:35:58 +00001026// NOTE: This instruction is really a vector instruction, but the custom
1027// lowering code uses it in unorthodox ways to support CTPOP for other
1028// data types!
Scott Michel06eabde2008-12-27 04:51:36 +00001029
Scott Michel8b6b4202007-12-04 22:35:58 +00001030def CNTBv16i8:
1031 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1032 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001033 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001034
1035def CNTBv8i16 :
1036 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1037 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001038 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001039
1040def CNTBv4i32 :
1041 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1042 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001043 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001044
Scott Michel06eabde2008-12-27 04:51:36 +00001045// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1046// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1047// slots 1-3.
1048//
1049// Note: This instruction "pairs" with the fsmb instruction for all of the
1050// various types defined here.
1051//
1052// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1053// a vector or register.
1054
1055class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1056 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1057
1058class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1059 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001060 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001061
1062class GBBVecInst<ValueType vectype>:
1063 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001064 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001065
1066multiclass GatherBitsFromBytes {
1067 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1068 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1069 def v16i8: GBBVecInst<v16i8>;
1070}
1071
1072defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001073
1074// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001075// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1076// and slots 1-3 also set to 0.
1077//
1078// See notes for GBBInst, above.
1079
1080class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1081 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1082 pattern>;
1083
1084class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1085 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001086 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001087
1088class GBHVecInst<ValueType vectype>:
1089 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001090 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001091
1092multiclass GatherBitsHalfword {
1093 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1094 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1095 def v8i16: GBHVecInst<v8i16>;
1096}
1097
1098defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001099
1100// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001101// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1102// as well as slots 1-3.
1103//
1104// See notes for gbb, above.
1105
1106class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1107 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1108 pattern>;
1109
1110class GBRegInst<RegisterClass rclass, ValueType vectype>:
1111 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001112 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001113
1114class GBVecInst<ValueType vectype>:
1115 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001116 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001117
1118multiclass GatherBitsWord {
1119 def v4i32_r32: GBRegInst<R32C, v4i32>;
1120 def v4i32_r16: GBRegInst<R16C, v4i32>;
1121 def v4i32: GBVecInst<v4i32>;
1122}
1123
1124defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001125
1126// avgb: average bytes
1127def AVGB:
1128 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1129 "avgb\t$rT, $rA, $rB", ByteOp,
1130 []>;
1131
1132// absdb: absolute difference of bytes
1133def ABSDB:
1134 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1135 "absdb\t$rT, $rA, $rB", ByteOp,
1136 []>;
1137
1138// sumb: sum bytes into halfwords
1139def SUMB:
1140 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1141 "sumb\t$rT, $rA, $rB", ByteOp,
1142 []>;
1143
1144// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001145class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1146 RRForm_1<0b01101101010, OOL, IOL,
1147 "xsbh\t$rDst, $rSrc",
1148 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001149
Scott Michel2ef773a2009-01-06 03:36:14 +00001150class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel67224b22008-06-02 22:18:03 +00001151 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Michel2ef773a2009-01-06 03:36:14 +00001152 pattern>;
Scott Michel67224b22008-06-02 22:18:03 +00001153
1154multiclass ExtendByteHalfword {
Chris Lattnera5c69832010-03-19 04:53:47 +00001155 def v16i8: XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1156 [
1157 /*(set (v8i16 VECREG:$rDst), (sext (v8i16 VECREG:$rSrc)))*/]>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001158 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1159 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1160 def r16: XSBHInRegInst<R16C,
1161 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001162
1163 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1164 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1165 // pattern below). Intentionally doesn't match a pattern because we want the
1166 // sext 8->32 pattern to do the work for us, namely because we need the extra
1167 // XSHWr32.
Scott Michel2ef773a2009-01-06 03:36:14 +00001168 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1169
1170 // Same as the 32-bit version, but for i64
1171 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +00001172}
1173
1174defm XSBH : ExtendByteHalfword;
1175
Scott Michel8b6b4202007-12-04 22:35:58 +00001176// Sign extend halfwords to words:
Scott Michel8b6b4202007-12-04 22:35:58 +00001177
Scott Michel2ef773a2009-01-06 03:36:14 +00001178class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1179 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1180 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001181
Scott Michel2ef773a2009-01-06 03:36:14 +00001182class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1183 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1184 [(set (out_vectype VECREG:$rDest),
1185 (sext (in_vectype VECREG:$rSrc)))]>;
1186
1187class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1188 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1189 pattern>;
1190
1191class XSHWRegInst<RegisterClass rclass>:
1192 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1193 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1194
1195multiclass ExtendHalfwordWord {
1196 def v4i32: XSHWVecInst<v4i32, v8i16>;
1197
1198 def r16: XSHWRegInst<R32C>;
1199
1200 def r32: XSHWInRegInst<R32C,
1201 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1202 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1203}
1204
1205defm XSHW : ExtendHalfwordWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001206
Scott Michele0168c12009-01-05 01:34:35 +00001207// Sign-extend words to doublewords (32->64 bits)
Scott Michel8b6b4202007-12-04 22:35:58 +00001208
Scott Michele0168c12009-01-05 01:34:35 +00001209class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel2ef773a2009-01-06 03:36:14 +00001210 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1211 IntegerOp, pattern>;
Scott Michele0168c12009-01-05 01:34:35 +00001212
1213class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1214 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
Chris Lattnera5c69832010-03-19 04:53:47 +00001215 [/*(set (out_vectype VECREG:$rDst),
1216 (sext (out_vectype VECREG:$rSrc)))*/]>;
Scott Michele0168c12009-01-05 01:34:35 +00001217
1218class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1219 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1220 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1221
1222multiclass ExtendWordToDoubleWord {
1223 def v2i64: XSWDVecInst<v4i32, v2i64>;
1224 def r64: XSWDRegInst<R32C, R64C>;
1225
1226 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1227 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1228}
Scott Michel8b6b4202007-12-04 22:35:58 +00001229
Scott Michele0168c12009-01-05 01:34:35 +00001230defm XSWD : ExtendWordToDoubleWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001231
1232// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001233
Scott Michel97872d32008-02-23 18:41:37 +00001234class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1235 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1236 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001237
Scott Michel97872d32008-02-23 18:41:37 +00001238class ANDVecInst<ValueType vectype>:
1239 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1240 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1241 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001242
Scott Michel6baba072008-03-05 23:02:02 +00001243class ANDRegInst<RegisterClass rclass>:
1244 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1245 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1246
Scott Michel97872d32008-02-23 18:41:37 +00001247multiclass BitwiseAnd
1248{
1249 def v16i8: ANDVecInst<v16i8>;
1250 def v8i16: ANDVecInst<v8i16>;
1251 def v4i32: ANDVecInst<v4i32>;
1252 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001253
Scott Michel6baba072008-03-05 23:02:02 +00001254 def r128: ANDRegInst<GPRC>;
1255 def r64: ANDRegInst<R64C>;
1256 def r32: ANDRegInst<R32C>;
1257 def r16: ANDRegInst<R16C>;
1258 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001259
Scott Michel97872d32008-02-23 18:41:37 +00001260 //===---------------------------------------------
1261 // Special instructions to perform the fabs instruction
1262 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1263 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001264
Scott Michel0d5eae02009-03-17 01:15:45 +00001265 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
pingbak2f387e82009-01-26 03:31:40 +00001266 [/* Intentionally does not match a pattern */]>;
1267
Scott Michel97872d32008-02-23 18:41:37 +00001268 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1269 [/* Intentionally does not match a pattern */]>;
1270
1271 //===---------------------------------------------
1272
1273 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1274 // quantities -- see 16->32 zext pattern.
1275 //
1276 // This pattern is somewhat artificial, since it might match some
1277 // compiler generated pattern but it is unlikely to do so.
1278
1279 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1280 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1281}
1282
1283defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001284
Chris Lattnerfe29aee2010-03-28 07:48:17 +00001285
1286def vnot_cell_conv : PatFrag<(ops node:$in),
1287 (xor node:$in, (bitconvert (v4i32 immAllOnesV)))>;
1288
1289// N.B.: vnot_cell_conv is one of those special target selection pattern
1290// fragments,
Scott Michel8b6b4202007-12-04 22:35:58 +00001291// in which we expect there to be a bit_convert on the constant. Bear in mind
1292// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1293// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001294
Scott Michel97872d32008-02-23 18:41:37 +00001295class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1296 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1297 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001298
Scott Michel0d5eae02009-03-17 01:15:45 +00001299class ANDCVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michel97872d32008-02-23 18:41:37 +00001300 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel0d5eae02009-03-17 01:15:45 +00001301 [(set (vectype VECREG:$rT),
1302 (and (vectype VECREG:$rA),
1303 (vnot_frag (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001304
Scott Michel97872d32008-02-23 18:41:37 +00001305class ANDCRegInst<RegisterClass rclass>:
1306 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1307 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001308
Scott Michel97872d32008-02-23 18:41:37 +00001309multiclass AndComplement
1310{
1311 def v16i8: ANDCVecInst<v16i8>;
1312 def v8i16: ANDCVecInst<v8i16>;
1313 def v4i32: ANDCVecInst<v4i32>;
1314 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001315
Scott Michel97872d32008-02-23 18:41:37 +00001316 def r128: ANDCRegInst<GPRC>;
1317 def r64: ANDCRegInst<R64C>;
1318 def r32: ANDCRegInst<R32C>;
1319 def r16: ANDCRegInst<R16C>;
1320 def r8: ANDCRegInst<R8C>;
Scott Michel0d5eae02009-03-17 01:15:45 +00001321
1322 // Sometimes, the xor pattern has a bitcast constant:
Chris Lattnerfe29aee2010-03-28 07:48:17 +00001323 def v16i8_conv: ANDCVecInst<v16i8, vnot_cell_conv>;
Scott Michel97872d32008-02-23 18:41:37 +00001324}
Scott Michel438be252007-12-17 22:32:34 +00001325
Scott Michel97872d32008-02-23 18:41:37 +00001326defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001327
Scott Michel97872d32008-02-23 18:41:37 +00001328class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1329 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001330 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001331
Scott Michel97872d32008-02-23 18:41:37 +00001332multiclass AndByteImm
1333{
1334 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1335 [(set (v16i8 VECREG:$rT),
1336 (and (v16i8 VECREG:$rA),
1337 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001338
Scott Michel97872d32008-02-23 18:41:37 +00001339 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1340 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1341}
Scott Michel438be252007-12-17 22:32:34 +00001342
Scott Michel97872d32008-02-23 18:41:37 +00001343defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001344
Scott Michel97872d32008-02-23 18:41:37 +00001345class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1346 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001347 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001348
Scott Michel97872d32008-02-23 18:41:37 +00001349multiclass AndHalfwordImm
1350{
1351 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1352 [(set (v8i16 VECREG:$rT),
1353 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001354
Scott Michel97872d32008-02-23 18:41:37 +00001355 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1356 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001357
Scott Michel97872d32008-02-23 18:41:37 +00001358 // Zero-extend i8 to i16:
1359 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1360 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1361}
Scott Michel8b6b4202007-12-04 22:35:58 +00001362
Scott Michel97872d32008-02-23 18:41:37 +00001363defm ANDHI : AndHalfwordImm;
1364
1365class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1366 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1367 IntegerOp, pattern>;
1368
1369multiclass AndWordImm
1370{
1371 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1372 [(set (v4i32 VECREG:$rT),
1373 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1374
1375 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1376 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1377
1378 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1379 // pattern below.
1380 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1381 [(set R32C:$rT,
1382 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1383
1384 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1385 // zext 16->32 pattern below.
1386 //
1387 // Note that this pattern is somewhat artificial, since it might match
1388 // something the compiler generates but is unlikely to occur in practice.
1389 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1390 [(set R32C:$rT,
1391 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1392}
1393
1394defm ANDI : AndWordImm;
1395
1396//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001397// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001398//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1399
Scott Michel8b6b4202007-12-04 22:35:58 +00001400// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001401class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1402 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1403 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001404
Scott Michel97872d32008-02-23 18:41:37 +00001405class ORVecInst<ValueType vectype>:
1406 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1407 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1408 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001409
Scott Michel97872d32008-02-23 18:41:37 +00001410class ORRegInst<RegisterClass rclass>:
1411 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1412 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001413
Scott Michel06eabde2008-12-27 04:51:36 +00001414// ORCvtForm: OR conversion form
1415//
1416// This is used to "convert" the preferred slot to its vector equivalent, as
1417// well as convert a vector back to its preferred slot.
1418//
1419// These are effectively no-ops, but need to exist for proper type conversion
1420// and type coercion.
1421
Scott Michel8c67fa42009-01-21 04:58:48 +00001422class ORCvtForm<dag OOL, dag IOL, list<dag> pattern = [/* no pattern */]>
Scott Michel06eabde2008-12-27 04:51:36 +00001423 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1424 bits<7> RA;
1425 bits<7> RT;
1426
Scott Michel8c67fa42009-01-21 04:58:48 +00001427 let Pattern = pattern;
Scott Michel06eabde2008-12-27 04:51:36 +00001428
1429 let Inst{0-10} = 0b10000010000;
1430 let Inst{11-17} = RA;
1431 let Inst{18-24} = RA;
1432 let Inst{25-31} = RT;
1433}
1434
Scott Michel97872d32008-02-23 18:41:37 +00001435class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001436 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001437
Scott Michel97872d32008-02-23 18:41:37 +00001438class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001439 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1440
Scott Michel8c67fa42009-01-21 04:58:48 +00001441/* class ORCvtRegGPRC<RegisterClass rclass>:
1442 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>; */
Scott Michel06eabde2008-12-27 04:51:36 +00001443
Scott Michel8c67fa42009-01-21 04:58:48 +00001444/* class ORCvtGPRCReg<RegisterClass rclass>:
1445 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>; */
Scott Michel2ef773a2009-01-06 03:36:14 +00001446
Scott Michel8c67fa42009-01-21 04:58:48 +00001447class ORCvtFormR32Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1448 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001449
Scott Michel8c67fa42009-01-21 04:58:48 +00001450class ORCvtFormRegR32<RegisterClass rclass, list<dag> pattern = [ ]>:
1451 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001452
Scott Michel8c67fa42009-01-21 04:58:48 +00001453class ORCvtFormR64Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1454 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001455
Scott Michel8c67fa42009-01-21 04:58:48 +00001456class ORCvtFormRegR64<RegisterClass rclass, list<dag> pattern = [ ]>:
1457 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA), pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00001458
Scott Michel34712c32009-03-16 18:47:25 +00001459class ORCvtGPRCVec:
1460 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
1461
1462class ORCvtVecGPRC:
1463 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001464
Scott Michel97872d32008-02-23 18:41:37 +00001465multiclass BitwiseOr
1466{
1467 def v16i8: ORVecInst<v16i8>;
1468 def v8i16: ORVecInst<v8i16>;
1469 def v4i32: ORVecInst<v4i32>;
1470 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001471
Scott Michel97872d32008-02-23 18:41:37 +00001472 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1473 [(set (v4f32 VECREG:$rT),
1474 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1475 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001476
Scott Michel97872d32008-02-23 18:41:37 +00001477 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001478 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001479 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1480 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001481
Scott Michel8c67fa42009-01-21 04:58:48 +00001482 def r128: ORRegInst<GPRC>;
1483 def r64: ORRegInst<R64C>;
1484 def r32: ORRegInst<R32C>;
1485 def r16: ORRegInst<R16C>;
1486 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001487
Scott Michel97872d32008-02-23 18:41:37 +00001488 // OR instructions used to copy f32 and f64 registers.
1489 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1490 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001491
Scott Michel97872d32008-02-23 18:41:37 +00001492 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1493 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001494
Scott Michel4d07fb72008-12-30 23:28:25 +00001495 // scalar->vector promotion, prefslot2vec:
Scott Michel97872d32008-02-23 18:41:37 +00001496 def v16i8_i8: ORPromoteScalar<R8C>;
1497 def v8i16_i16: ORPromoteScalar<R16C>;
1498 def v4i32_i32: ORPromoteScalar<R32C>;
1499 def v2i64_i64: ORPromoteScalar<R64C>;
1500 def v4f32_f32: ORPromoteScalar<R32FP>;
1501 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001502
Scott Michel4d07fb72008-12-30 23:28:25 +00001503 // vector->scalar demotion, vec2prefslot:
Scott Michel97872d32008-02-23 18:41:37 +00001504 def i8_v16i8: ORExtractElt<R8C>;
1505 def i16_v8i16: ORExtractElt<R16C>;
1506 def i32_v4i32: ORExtractElt<R32C>;
1507 def i64_v2i64: ORExtractElt<R64C>;
1508 def f32_v4f32: ORExtractElt<R32FP>;
1509 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001510
Scott Michel34712c32009-03-16 18:47:25 +00001511 // Conversion from vector to GPRC
1512 def i128_vec: ORCvtVecGPRC;
1513
1514 // Conversion from GPRC to vector
1515 def vec_i128: ORCvtGPRCVec;
1516
Scott Michel8c67fa42009-01-21 04:58:48 +00001517/*
Scott Michel34712c32009-03-16 18:47:25 +00001518 // Conversion from register to GPRC
Scott Michel06eabde2008-12-27 04:51:36 +00001519 def i128_r64: ORCvtRegGPRC<R64C>;
1520 def i128_f64: ORCvtRegGPRC<R64FP>;
1521 def i128_r32: ORCvtRegGPRC<R32C>;
1522 def i128_f32: ORCvtRegGPRC<R32FP>;
1523 def i128_r16: ORCvtRegGPRC<R16C>;
1524 def i128_r8: ORCvtRegGPRC<R8C>;
1525
Scott Michel34712c32009-03-16 18:47:25 +00001526 // Conversion from GPRC to register
Scott Michel06eabde2008-12-27 04:51:36 +00001527 def r64_i128: ORCvtGPRCReg<R64C>;
1528 def f64_i128: ORCvtGPRCReg<R64FP>;
1529 def r32_i128: ORCvtGPRCReg<R32C>;
1530 def f32_i128: ORCvtGPRCReg<R32FP>;
1531 def r16_i128: ORCvtGPRCReg<R16C>;
1532 def r8_i128: ORCvtGPRCReg<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001533*/
1534/*
Scott Michel2ef773a2009-01-06 03:36:14 +00001535 // Conversion from register to R32C:
Scott Michel34712c32009-03-16 18:47:25 +00001536 def r32_r16: ORCvtFormRegR32<R16C>;
1537 def r32_r8: ORCvtFormRegR32<R8C>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001538
1539 // Conversion from R32C to register
1540 def r32_r16: ORCvtFormR32Reg<R16C>;
1541 def r32_r8: ORCvtFormR32Reg<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001542*/
pingbak2f387e82009-01-26 03:31:40 +00001543
Scott Michel34712c32009-03-16 18:47:25 +00001544 // Conversion from R64C to register:
pingbak2f387e82009-01-26 03:31:40 +00001545 def r32_r64: ORCvtFormR64Reg<R32C>;
1546 // def r16_r64: ORCvtFormR64Reg<R16C>;
1547 // def r8_r64: ORCvtFormR64Reg<R8C>;
1548
Scott Michel34712c32009-03-16 18:47:25 +00001549 // Conversion to R64C from register:
pingbak2f387e82009-01-26 03:31:40 +00001550 def r64_r32: ORCvtFormRegR64<R32C>;
1551 // def r64_r16: ORCvtFormRegR64<R16C>;
1552 // def r64_r8: ORCvtFormRegR64<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001553
1554 // bitconvert patterns:
1555 def r32_f32: ORCvtFormR32Reg<R32FP,
1556 [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1557 def f32_r32: ORCvtFormRegR32<R32FP,
1558 [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1559
1560 def r64_f64: ORCvtFormR64Reg<R64FP,
1561 [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1562 def f64_r64: ORCvtFormRegR64<R64FP,
1563 [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +00001564}
Scott Michel438be252007-12-17 22:32:34 +00001565
Scott Michel97872d32008-02-23 18:41:37 +00001566defm OR : BitwiseOr;
1567
Scott Michel06eabde2008-12-27 04:51:36 +00001568// scalar->vector promotion patterns (preferred slot to vector):
1569def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1570 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001571
Scott Michel06eabde2008-12-27 04:51:36 +00001572def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1573 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001574
Scott Michel06eabde2008-12-27 04:51:36 +00001575def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1576 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001577
Kalle Raiskila602375b2010-08-02 08:54:39 +00001578def : Pat<(v2i32 (SPUprefslot2vec R32C:$rA)),
1579 (ORv4i32_i32 R32C:$rA)>;
1580
Scott Michel06eabde2008-12-27 04:51:36 +00001581def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1582 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001583
Scott Michel06eabde2008-12-27 04:51:36 +00001584def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1585 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001586
Kalle Raiskila3befdd22010-08-02 11:22:10 +00001587def : Pat<(v2f32 (SPUprefslot2vec R32FP:$rA)),
1588 (ORv4f32_f32 R32FP:$rA)>;
1589
Scott Michel06eabde2008-12-27 04:51:36 +00001590def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1591 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001592
Scott Michel06eabde2008-12-27 04:51:36 +00001593// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1594// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001595
Scott Michelc630c412008-11-24 17:11:17 +00001596def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001597 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001598
Scott Michelc630c412008-11-24 17:11:17 +00001599def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001600 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001601
Scott Michelc630c412008-11-24 17:11:17 +00001602def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001603 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001604
Kalle Raiskila602375b2010-08-02 08:54:39 +00001605def : Pat<(SPUvec2prefslot (v2i32 VECREG:$rA)),
1606 (ORi32_v4i32 VECREG:$rA)>;
1607
Scott Michelc630c412008-11-24 17:11:17 +00001608def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001609 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001610
Scott Michelc630c412008-11-24 17:11:17 +00001611def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001612 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001613
Kalle Raiskila3befdd22010-08-02 11:22:10 +00001614def : Pat<(SPUvec2prefslot (v2f32 VECREG:$rA)),
1615 (ORf32_v4f32 VECREG:$rA)>;
1616
Scott Michelc630c412008-11-24 17:11:17 +00001617def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001618 (ORf64_v2f64 VECREG:$rA)>;
1619
1620// Load Register: This is an assembler alias for a bitwise OR of a register
1621// against itself. It's here because it brings some clarity to assembly
1622// language output.
1623
1624let hasCtrlDep = 1 in {
1625 class LRInst<dag OOL, dag IOL>
1626 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1627 bits<7> RA;
1628 bits<7> RT;
1629
1630 let Pattern = [/*no pattern*/];
1631
1632 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1633 let Inst{11-17} = RA;
1634 let Inst{18-24} = RA;
1635 let Inst{25-31} = RT;
1636 }
1637
1638 class LRVecInst<ValueType vectype>:
1639 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1640
1641 class LRRegInst<RegisterClass rclass>:
1642 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1643
1644 multiclass LoadRegister {
1645 def v2i64: LRVecInst<v2i64>;
1646 def v2f64: LRVecInst<v2f64>;
1647 def v4i32: LRVecInst<v4i32>;
1648 def v4f32: LRVecInst<v4f32>;
1649 def v8i16: LRVecInst<v8i16>;
1650 def v16i8: LRVecInst<v16i8>;
1651
1652 def r128: LRRegInst<GPRC>;
1653 def r64: LRRegInst<R64C>;
1654 def f64: LRRegInst<R64FP>;
1655 def r32: LRRegInst<R32C>;
1656 def f32: LRRegInst<R32FP>;
1657 def r16: LRRegInst<R16C>;
1658 def r8: LRRegInst<R8C>;
1659 }
1660
1661 defm LR: LoadRegister;
1662}
Scott Michel8b6b4202007-12-04 22:35:58 +00001663
Scott Michel97872d32008-02-23 18:41:37 +00001664// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001665
Scott Michel97872d32008-02-23 18:41:37 +00001666class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1667 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1668 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001669
Scott Michel97872d32008-02-23 18:41:37 +00001670class ORCVecInst<ValueType vectype>:
1671 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1672 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1673 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001674
Scott Michel97872d32008-02-23 18:41:37 +00001675class ORCRegInst<RegisterClass rclass>:
1676 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1677 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001678
Scott Michel97872d32008-02-23 18:41:37 +00001679multiclass BitwiseOrComplement
1680{
1681 def v16i8: ORCVecInst<v16i8>;
1682 def v8i16: ORCVecInst<v8i16>;
1683 def v4i32: ORCVecInst<v4i32>;
1684 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001685
Scott Michel34712c32009-03-16 18:47:25 +00001686 def r128: ORCRegInst<GPRC>;
Scott Michel97872d32008-02-23 18:41:37 +00001687 def r64: ORCRegInst<R64C>;
1688 def r32: ORCRegInst<R32C>;
1689 def r16: ORCRegInst<R16C>;
1690 def r8: ORCRegInst<R8C>;
1691}
1692
1693defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001694
Scott Michel8b6b4202007-12-04 22:35:58 +00001695// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001696class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1697 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1698 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001699
Scott Michel97872d32008-02-23 18:41:37 +00001700class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1701 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1702 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1703 (vectype immpred:$val)))]>;
1704
1705multiclass BitwiseOrByteImm
1706{
1707 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1708
1709 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1710 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1711}
1712
1713defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001714
Scott Michel8b6b4202007-12-04 22:35:58 +00001715// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001716class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1717 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1718 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001719
Scott Michel97872d32008-02-23 18:41:37 +00001720class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1721 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1722 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1723 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001724
Scott Michel97872d32008-02-23 18:41:37 +00001725multiclass BitwiseOrHalfwordImm
1726{
1727 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1728
1729 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1730 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1731
1732 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1733 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1734 [(set R16C:$rT, (or (anyext R8C:$rA),
1735 i16ImmSExt10:$val))]>;
1736}
1737
1738defm ORHI : BitwiseOrHalfwordImm;
1739
1740class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1741 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1742 IntegerOp, pattern>;
1743
1744class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1745 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1746 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1747 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001748
1749// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001750multiclass BitwiseOrImm
1751{
1752 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001753
Scott Michel97872d32008-02-23 18:41:37 +00001754 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1755 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001756
Scott Michel97872d32008-02-23 18:41:37 +00001757 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1758 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1759 // infra "anyext 16->32" pattern.)
1760 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1761 [(set R32C:$rT, (or (anyext R16C:$rA),
1762 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001763
Scott Michel97872d32008-02-23 18:41:37 +00001764 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1765 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1766 // infra "anyext 16->32" pattern.)
1767 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1768 [(set R32C:$rT, (or (anyext R8C:$rA),
1769 i32ImmSExt10:$val))]>;
1770}
Scott Michel8b6b4202007-12-04 22:35:58 +00001771
Scott Michel97872d32008-02-23 18:41:37 +00001772defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001773
Scott Michel8b6b4202007-12-04 22:35:58 +00001774// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1775// $rT[0], slots 1-3 are zeroed.
1776//
Scott Michel438be252007-12-17 22:32:34 +00001777// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001778def ORXv4i32:
1779 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1780 "orx\t$rT, $rA, $rB", IntegerOp,
1781 []>;
1782
Scott Michel438be252007-12-17 22:32:34 +00001783// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001784
Scott Michel6baba072008-03-05 23:02:02 +00001785class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1786 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1787 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001788
Scott Michel6baba072008-03-05 23:02:02 +00001789class XORVecInst<ValueType vectype>:
1790 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1791 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1792 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001793
Scott Michel6baba072008-03-05 23:02:02 +00001794class XORRegInst<RegisterClass rclass>:
1795 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1796 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1797
1798multiclass BitwiseExclusiveOr
1799{
1800 def v16i8: XORVecInst<v16i8>;
1801 def v8i16: XORVecInst<v8i16>;
1802 def v4i32: XORVecInst<v4i32>;
1803 def v2i64: XORVecInst<v2i64>;
1804
1805 def r128: XORRegInst<GPRC>;
1806 def r64: XORRegInst<R64C>;
1807 def r32: XORRegInst<R32C>;
1808 def r16: XORRegInst<R16C>;
1809 def r8: XORRegInst<R8C>;
Scott Michele13d8392009-03-17 16:45:16 +00001810
1811 // XOR instructions used to negate f32 and f64 quantities.
1812
1813 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1814 [/* no pattern */]>;
1815
1816 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1817 [/* no pattern */]>;
1818
1819 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1820 [/* no pattern, see fneg{32,64} */]>;
Scott Michel6baba072008-03-05 23:02:02 +00001821}
1822
1823defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001824
1825//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001826
Scott Michel97872d32008-02-23 18:41:37 +00001827class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1828 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1829 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001830
Scott Michel97872d32008-02-23 18:41:37 +00001831multiclass XorByteImm
1832{
1833 def v16i8:
1834 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1835 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1836
1837 def r8:
1838 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1839 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1840}
1841
1842defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001843
Scott Michel8b6b4202007-12-04 22:35:58 +00001844def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001845 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001846 "xorhi\t$rT, $rA, $val", IntegerOp,
1847 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1848 v8i16SExt10Imm:$val))]>;
1849
1850def XORHIr16:
1851 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1852 "xorhi\t$rT, $rA, $val", IntegerOp,
1853 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1854
1855def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001856 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001857 "xori\t$rT, $rA, $val", IntegerOp,
1858 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1859 v4i32SExt10Imm:$val))]>;
1860
1861def XORIr32:
1862 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1863 "xori\t$rT, $rA, $val", IntegerOp,
1864 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1865
1866// NAND:
Scott Michel8b6b4202007-12-04 22:35:58 +00001867
Scott Michel34712c32009-03-16 18:47:25 +00001868class NANDInst<dag OOL, dag IOL, list<dag> pattern>:
1869 RRForm<0b10010011000, OOL, IOL, "nand\t$rT, $rA, $rB",
1870 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001871
Scott Michel34712c32009-03-16 18:47:25 +00001872class NANDVecInst<ValueType vectype>:
1873 NANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1874 [(set (vectype VECREG:$rT), (vnot (and (vectype VECREG:$rA),
1875 (vectype VECREG:$rB))))]>;
1876class NANDRegInst<RegisterClass rclass>:
1877 NANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1878 [(set rclass:$rT, (not (and rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001879
Scott Michel34712c32009-03-16 18:47:25 +00001880multiclass BitwiseNand
1881{
1882 def v16i8: NANDVecInst<v16i8>;
1883 def v8i16: NANDVecInst<v8i16>;
1884 def v4i32: NANDVecInst<v4i32>;
1885 def v2i64: NANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001886
Scott Michel34712c32009-03-16 18:47:25 +00001887 def r128: NANDRegInst<GPRC>;
1888 def r64: NANDRegInst<R64C>;
1889 def r32: NANDRegInst<R32C>;
1890 def r16: NANDRegInst<R16C>;
1891 def r8: NANDRegInst<R8C>;
1892}
Scott Michel8b6b4202007-12-04 22:35:58 +00001893
Scott Michel34712c32009-03-16 18:47:25 +00001894defm NAND : BitwiseNand;
Scott Michel438be252007-12-17 22:32:34 +00001895
Scott Michel8b6b4202007-12-04 22:35:58 +00001896// NOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001897
Scott Michel34712c32009-03-16 18:47:25 +00001898class NORInst<dag OOL, dag IOL, list<dag> pattern>:
1899 RRForm<0b10010010000, OOL, IOL, "nor\t$rT, $rA, $rB",
1900 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001901
Scott Michel34712c32009-03-16 18:47:25 +00001902class NORVecInst<ValueType vectype>:
1903 NORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1904 [(set (vectype VECREG:$rT), (vnot (or (vectype VECREG:$rA),
1905 (vectype VECREG:$rB))))]>;
1906class NORRegInst<RegisterClass rclass>:
1907 NORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1908 [(set rclass:$rT, (not (or rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001909
Scott Michel34712c32009-03-16 18:47:25 +00001910multiclass BitwiseNor
1911{
1912 def v16i8: NORVecInst<v16i8>;
1913 def v8i16: NORVecInst<v8i16>;
1914 def v4i32: NORVecInst<v4i32>;
1915 def v2i64: NORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001916
Scott Michel34712c32009-03-16 18:47:25 +00001917 def r128: NORRegInst<GPRC>;
1918 def r64: NORRegInst<R64C>;
1919 def r32: NORRegInst<R32C>;
1920 def r16: NORRegInst<R16C>;
1921 def r8: NORRegInst<R8C>;
1922}
Scott Michel8b6b4202007-12-04 22:35:58 +00001923
Scott Michel34712c32009-03-16 18:47:25 +00001924defm NOR : BitwiseNor;
Scott Michel438be252007-12-17 22:32:34 +00001925
Scott Michel8b6b4202007-12-04 22:35:58 +00001926// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001927class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1928 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1929 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001930
pingbak2f387e82009-01-26 03:31:40 +00001931class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michel6baba072008-03-05 23:02:02 +00001932 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1933 [(set (vectype VECREG:$rT),
1934 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
pingbak2f387e82009-01-26 03:31:40 +00001935 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michel6baba072008-03-05 23:02:02 +00001936 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001937
Scott Michel4d07fb72008-12-30 23:28:25 +00001938class SELBVecVCondInst<ValueType vectype>:
1939 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1940 [(set (vectype VECREG:$rT),
1941 (select (vectype VECREG:$rC),
1942 (vectype VECREG:$rB),
1943 (vectype VECREG:$rA)))]>;
1944
Scott Michel06eabde2008-12-27 04:51:36 +00001945class SELBVecCondInst<ValueType vectype>:
1946 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1947 [(set (vectype VECREG:$rT),
1948 (select R32C:$rC,
1949 (vectype VECREG:$rB),
1950 (vectype VECREG:$rA)))]>;
1951
Scott Michel6baba072008-03-05 23:02:02 +00001952class SELBRegInst<RegisterClass rclass>:
1953 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1954 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001955 (or (and rclass:$rB, rclass:$rC),
1956 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001957
Scott Michel06eabde2008-12-27 04:51:36 +00001958class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1959 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1960 [(set rclass:$rT,
1961 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1962
Scott Michel6baba072008-03-05 23:02:02 +00001963multiclass SelectBits
1964{
1965 def v16i8: SELBVecInst<v16i8>;
1966 def v8i16: SELBVecInst<v8i16>;
1967 def v4i32: SELBVecInst<v4i32>;
Chris Lattnerfe29aee2010-03-28 07:48:17 +00001968 def v2i64: SELBVecInst<v2i64, vnot_cell_conv>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001969
Scott Michel6baba072008-03-05 23:02:02 +00001970 def r128: SELBRegInst<GPRC>;
1971 def r64: SELBRegInst<R64C>;
1972 def r32: SELBRegInst<R32C>;
1973 def r16: SELBRegInst<R16C>;
1974 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001975
1976 def v16i8_cond: SELBVecCondInst<v16i8>;
1977 def v8i16_cond: SELBVecCondInst<v8i16>;
1978 def v4i32_cond: SELBVecCondInst<v4i32>;
1979 def v2i64_cond: SELBVecCondInst<v2i64>;
1980
Scott Michel4d07fb72008-12-30 23:28:25 +00001981 def v16i8_vcond: SELBVecCondInst<v16i8>;
1982 def v8i16_vcond: SELBVecCondInst<v8i16>;
1983 def v4i32_vcond: SELBVecCondInst<v4i32>;
1984 def v2i64_vcond: SELBVecCondInst<v2i64>;
1985
1986 def v4f32_cond:
pingbakb8913342009-01-26 03:37:41 +00001987 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1988 [(set (v4f32 VECREG:$rT),
1989 (select (v4i32 VECREG:$rC),
1990 (v4f32 VECREG:$rB),
1991 (v4f32 VECREG:$rA)))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001992
Scott Michel8c67fa42009-01-21 04:58:48 +00001993 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michel06eabde2008-12-27 04:51:36 +00001994 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001995 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001996 def r16_cond: SELBRegCondInst<R16C, R16C>;
1997 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001998}
Scott Michel8b6b4202007-12-04 22:35:58 +00001999
Scott Michel6baba072008-03-05 23:02:02 +00002000defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00002001
Scott Michel56a125e2008-11-22 23:50:42 +00002002class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00002003 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
2004 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002005
Scott Michel56a125e2008-11-22 23:50:42 +00002006def : SPUselbPatVec<v16i8, SELBv16i8>;
2007def : SPUselbPatVec<v8i16, SELBv8i16>;
2008def : SPUselbPatVec<v4i32, SELBv4i32>;
2009def : SPUselbPatVec<v2i64, SELBv2i64>;
2010
2011class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
2012 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
2013 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
2014
2015def : SPUselbPatReg<R8C, SELBr8>;
2016def : SPUselbPatReg<R16C, SELBr16>;
2017def : SPUselbPatReg<R32C, SELBr32>;
2018def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002019
Scott Michel6baba072008-03-05 23:02:02 +00002020// EQV: Equivalence (1 for each same bit, otherwise 0)
2021//
2022// Note: There are a lot of ways to match this bit operator and these patterns
2023// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00002024
Scott Michel6baba072008-03-05 23:02:02 +00002025class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2026 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2027 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002028
Scott Michel6baba072008-03-05 23:02:02 +00002029class EQVVecInst<ValueType vectype>:
2030 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2031 [(set (vectype VECREG:$rT),
2032 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2033 (and (vnot (vectype VECREG:$rA)),
2034 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002035
Scott Michel6baba072008-03-05 23:02:02 +00002036class EQVRegInst<RegisterClass rclass>:
2037 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2038 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2039 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002040
Scott Michel6baba072008-03-05 23:02:02 +00002041class EQVVecPattern1<ValueType vectype>:
2042 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2043 [(set (vectype VECREG:$rT),
2044 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002045
Scott Michel6baba072008-03-05 23:02:02 +00002046class EQVRegPattern1<RegisterClass rclass>:
2047 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2048 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002049
Scott Michel6baba072008-03-05 23:02:02 +00002050class EQVVecPattern2<ValueType vectype>:
2051 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2052 [(set (vectype VECREG:$rT),
2053 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2054 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002055
Scott Michel6baba072008-03-05 23:02:02 +00002056class EQVRegPattern2<RegisterClass rclass>:
2057 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2058 [(set rclass:$rT,
2059 (or (and rclass:$rA, rclass:$rB),
2060 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002061
Scott Michel6baba072008-03-05 23:02:02 +00002062class EQVVecPattern3<ValueType vectype>:
2063 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2064 [(set (vectype VECREG:$rT),
2065 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002066
Scott Michel6baba072008-03-05 23:02:02 +00002067class EQVRegPattern3<RegisterClass rclass>:
2068 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2069 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002070
Scott Michel6baba072008-03-05 23:02:02 +00002071multiclass BitEquivalence
2072{
2073 def v16i8: EQVVecInst<v16i8>;
2074 def v8i16: EQVVecInst<v8i16>;
2075 def v4i32: EQVVecInst<v4i32>;
2076 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002077
Scott Michel6baba072008-03-05 23:02:02 +00002078 def v16i8_1: EQVVecPattern1<v16i8>;
2079 def v8i16_1: EQVVecPattern1<v8i16>;
2080 def v4i32_1: EQVVecPattern1<v4i32>;
2081 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002082
Scott Michel6baba072008-03-05 23:02:02 +00002083 def v16i8_2: EQVVecPattern2<v16i8>;
2084 def v8i16_2: EQVVecPattern2<v8i16>;
2085 def v4i32_2: EQVVecPattern2<v4i32>;
2086 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002087
Scott Michel6baba072008-03-05 23:02:02 +00002088 def v16i8_3: EQVVecPattern3<v16i8>;
2089 def v8i16_3: EQVVecPattern3<v8i16>;
2090 def v4i32_3: EQVVecPattern3<v4i32>;
2091 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002092
Scott Michel6baba072008-03-05 23:02:02 +00002093 def r128: EQVRegInst<GPRC>;
2094 def r64: EQVRegInst<R64C>;
2095 def r32: EQVRegInst<R32C>;
2096 def r16: EQVRegInst<R16C>;
2097 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002098
Scott Michel6baba072008-03-05 23:02:02 +00002099 def r128_1: EQVRegPattern1<GPRC>;
2100 def r64_1: EQVRegPattern1<R64C>;
2101 def r32_1: EQVRegPattern1<R32C>;
2102 def r16_1: EQVRegPattern1<R16C>;
2103 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002104
Scott Michel6baba072008-03-05 23:02:02 +00002105 def r128_2: EQVRegPattern2<GPRC>;
2106 def r64_2: EQVRegPattern2<R64C>;
2107 def r32_2: EQVRegPattern2<R32C>;
2108 def r16_2: EQVRegPattern2<R16C>;
2109 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002110
Scott Michel6baba072008-03-05 23:02:02 +00002111 def r128_3: EQVRegPattern3<GPRC>;
2112 def r64_3: EQVRegPattern3<R64C>;
2113 def r32_3: EQVRegPattern3<R32C>;
2114 def r16_3: EQVRegPattern3<R16C>;
2115 def r8_3: EQVRegPattern3<R8C>;
2116}
Scott Michel438be252007-12-17 22:32:34 +00002117
Scott Michel6baba072008-03-05 23:02:02 +00002118defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00002119
2120//===----------------------------------------------------------------------===//
2121// Vector shuffle...
2122//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002123// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2124// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2125// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2126// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002127//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002128
Scott Michel97872d32008-02-23 18:41:37 +00002129class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2130 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2131 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002132
Scott Michel0718cd82008-12-01 17:56:02 +00002133class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002134 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002135 [(set (resultvec VECREG:$rT),
2136 (SPUshuffle (resultvec VECREG:$rA),
2137 (resultvec VECREG:$rB),
2138 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002139
Scott Michel06eabde2008-12-27 04:51:36 +00002140class SHUFBGPRCInst:
2141 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2142 [/* no pattern */]>;
2143
Scott Michel97872d32008-02-23 18:41:37 +00002144multiclass ShuffleBytes
2145{
Scott Michel0718cd82008-12-01 17:56:02 +00002146 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2147 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2148 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2149 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2150 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2151 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
Kalle Raiskila602375b2010-08-02 08:54:39 +00002152 def v2i32 : SHUFBVecInst<v2i32, v16i8>;
2153 def v2i32_m32 : SHUFBVecInst<v2i32, v4i32>;
Scott Michel0718cd82008-12-01 17:56:02 +00002154 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2155 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002156
Scott Michel0718cd82008-12-01 17:56:02 +00002157 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2158 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
Kalle Raiskila3befdd22010-08-02 11:22:10 +00002159 def v2f32 : SHUFBVecInst<v2f32, v16i8>;
2160 def v2f32_m32 : SHUFBVecInst<v2f32, v4i32>;
Scott Michel0718cd82008-12-01 17:56:02 +00002161
2162 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2163 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002164
2165 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002166}
2167
2168defm SHUFB : ShuffleBytes;
2169
Scott Michel8b6b4202007-12-04 22:35:58 +00002170//===----------------------------------------------------------------------===//
2171// Shift and rotate group:
2172//===----------------------------------------------------------------------===//
2173
Scott Michel97872d32008-02-23 18:41:37 +00002174class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2175 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2176 RotateShift, pattern>;
2177
2178class SHLHVecInst<ValueType vectype>:
2179 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2180 [(set (vectype VECREG:$rT),
2181 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002182
Scott Michel97872d32008-02-23 18:41:37 +00002183multiclass ShiftLeftHalfword
2184{
2185 def v8i16: SHLHVecInst<v8i16>;
2186 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2187 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2188 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2189 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2190}
Scott Michel8b6b4202007-12-04 22:35:58 +00002191
Scott Michel97872d32008-02-23 18:41:37 +00002192defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002193
Scott Michel97872d32008-02-23 18:41:37 +00002194//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002195
Scott Michel97872d32008-02-23 18:41:37 +00002196class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2197 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2198 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002199
Scott Michel97872d32008-02-23 18:41:37 +00002200class SHLHIVecInst<ValueType vectype>:
2201 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2202 [(set (vectype VECREG:$rT),
2203 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002204
Scott Michel97872d32008-02-23 18:41:37 +00002205multiclass ShiftLeftHalfwordImm
2206{
2207 def v8i16: SHLHIVecInst<v8i16>;
2208 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2209 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2210}
2211
2212defm SHLHI : ShiftLeftHalfwordImm;
2213
2214def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002215 (SHLHIv8i16 VECREG:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel97872d32008-02-23 18:41:37 +00002216
2217def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002218 (SHLHIr16 R16C:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002219
Scott Michel97872d32008-02-23 18:41:37 +00002220//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002221
Scott Michel97872d32008-02-23 18:41:37 +00002222class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2223 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2224 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002225
Scott Michel97872d32008-02-23 18:41:37 +00002226multiclass ShiftLeftWord
2227{
2228 def v4i32:
2229 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2230 [(set (v4i32 VECREG:$rT),
2231 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2232 def r32:
2233 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2234 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2235}
Scott Michel8b6b4202007-12-04 22:35:58 +00002236
Scott Michel97872d32008-02-23 18:41:37 +00002237defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002238
Scott Michel97872d32008-02-23 18:41:37 +00002239//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002240
Scott Michel97872d32008-02-23 18:41:37 +00002241class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2242 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2243 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002244
Scott Michel97872d32008-02-23 18:41:37 +00002245multiclass ShiftLeftWordImm
2246{
2247 def v4i32:
2248 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2249 [(set (v4i32 VECREG:$rT),
2250 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002251
Scott Michel97872d32008-02-23 18:41:37 +00002252 def r32:
2253 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2254 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2255}
Scott Michel8b6b4202007-12-04 22:35:58 +00002256
Scott Michel97872d32008-02-23 18:41:37 +00002257defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002258
Scott Michel97872d32008-02-23 18:41:37 +00002259//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002260// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2261// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002262//
2263// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2264// of 7 bits is actually possible.
2265//
2266// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2267// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2268// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002269
Scott Michel97872d32008-02-23 18:41:37 +00002270class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2271 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2272 RotateShift, pattern>;
2273
2274class SHLQBIVecInst<ValueType vectype>:
2275 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2276 [(set (vectype VECREG:$rT),
2277 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2278
Scott Michel8c67fa42009-01-21 04:58:48 +00002279class SHLQBIRegInst<RegisterClass rclass>:
2280 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2281 [/* no pattern */]>;
2282
Scott Michel97872d32008-02-23 18:41:37 +00002283multiclass ShiftLeftQuadByBits
2284{
2285 def v16i8: SHLQBIVecInst<v16i8>;
2286 def v8i16: SHLQBIVecInst<v8i16>;
2287 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002288 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002289 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002290 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel8c67fa42009-01-21 04:58:48 +00002291
2292 def r128: SHLQBIRegInst<GPRC>;
Scott Michel97872d32008-02-23 18:41:37 +00002293}
2294
2295defm SHLQBI : ShiftLeftQuadByBits;
2296
2297// See note above on SHLQBI. In this case, the predicate actually does then
2298// enforcement, whereas with SHLQBI, we have to "take it on faith."
2299class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2300 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2301 RotateShift, pattern>;
2302
2303class SHLQBIIVecInst<ValueType vectype>:
2304 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2305 [(set (vectype VECREG:$rT),
2306 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2307
2308multiclass ShiftLeftQuadByBitsImm
2309{
2310 def v16i8 : SHLQBIIVecInst<v16i8>;
2311 def v8i16 : SHLQBIIVecInst<v8i16>;
2312 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002313 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002314 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002315 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002316}
2317
2318defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002319
2320// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002321// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002322
Scott Michel97872d32008-02-23 18:41:37 +00002323class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002324 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002325 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002326
Scott Michel97872d32008-02-23 18:41:37 +00002327class SHLQBYVecInst<ValueType vectype>:
2328 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2329 [(set (vectype VECREG:$rT),
2330 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002331
Scott Michel97872d32008-02-23 18:41:37 +00002332multiclass ShiftLeftQuadBytes
2333{
2334 def v16i8: SHLQBYVecInst<v16i8>;
2335 def v8i16: SHLQBYVecInst<v8i16>;
2336 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002337 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002338 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002339 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002340 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2341 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2342}
Scott Michel8b6b4202007-12-04 22:35:58 +00002343
Scott Michel97872d32008-02-23 18:41:37 +00002344defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002345
Scott Michel97872d32008-02-23 18:41:37 +00002346class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2347 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2348 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002349
Scott Michel97872d32008-02-23 18:41:37 +00002350class SHLQBYIVecInst<ValueType vectype>:
2351 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2352 [(set (vectype VECREG:$rT),
2353 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002354
Scott Michel97872d32008-02-23 18:41:37 +00002355multiclass ShiftLeftQuadBytesImm
2356{
2357 def v16i8: SHLQBYIVecInst<v16i8>;
2358 def v8i16: SHLQBYIVecInst<v8i16>;
2359 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002360 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002361 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002362 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002363 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2364 [(set GPRC:$rT,
2365 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2366}
Scott Michel438be252007-12-17 22:32:34 +00002367
Scott Michel97872d32008-02-23 18:41:37 +00002368defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002369
Scott Michel8c67fa42009-01-21 04:58:48 +00002370class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2371 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2372 RotateShift, pattern>;
2373
2374class SHLQBYBIVecInst<ValueType vectype>:
2375 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2376 [/* no pattern */]>;
2377
2378class SHLQBYBIRegInst<RegisterClass rclass>:
2379 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2380 [/* no pattern */]>;
2381
2382multiclass ShiftLeftQuadBytesBitCount
2383{
2384 def v16i8: SHLQBYBIVecInst<v16i8>;
2385 def v8i16: SHLQBYBIVecInst<v8i16>;
2386 def v4i32: SHLQBYBIVecInst<v4i32>;
2387 def v4f32: SHLQBYBIVecInst<v4f32>;
2388 def v2i64: SHLQBYBIVecInst<v2i64>;
2389 def v2f64: SHLQBYBIVecInst<v2f64>;
2390
2391 def r128: SHLQBYBIRegInst<GPRC>;
2392}
2393
2394defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2395
Scott Michel97872d32008-02-23 18:41:37 +00002396//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2397// Rotate halfword:
2398//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2399class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2400 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2401 RotateShift, pattern>;
2402
2403class ROTHVecInst<ValueType vectype>:
2404 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2405 [(set (vectype VECREG:$rT),
Chris Lattner744c5a82010-03-08 18:59:49 +00002406 (SPUvec_rotl VECREG:$rA, (v8i16 VECREG:$rB)))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002407
2408class ROTHRegInst<RegisterClass rclass>:
2409 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2410 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2411
2412multiclass RotateLeftHalfword
2413{
2414 def v8i16: ROTHVecInst<v8i16>;
2415 def r16: ROTHRegInst<R16C>;
2416}
2417
2418defm ROTH: RotateLeftHalfword;
2419
2420def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2421 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2422
2423//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2424// Rotate halfword, immediate:
2425//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2426class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2427 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2428 RotateShift, pattern>;
2429
2430class ROTHIVecInst<ValueType vectype>:
2431 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2432 [(set (vectype VECREG:$rT),
2433 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2434
2435multiclass RotateLeftHalfwordImm
2436{
2437 def v8i16: ROTHIVecInst<v8i16>;
2438 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2439 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2440 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2441 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2442}
2443
2444defm ROTHI: RotateLeftHalfwordImm;
2445
Chris Lattnera041d892010-03-15 05:53:47 +00002446def : Pat<(SPUvec_rotl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2447 (ROTHIv8i16 VECREG:$rA, (TO_IMM16 imm:$val))>;
Scott Michel06eabde2008-12-27 04:51:36 +00002448
Scott Michel97872d32008-02-23 18:41:37 +00002449//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2450// Rotate word:
2451//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002452
Scott Michel97872d32008-02-23 18:41:37 +00002453class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2454 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2455 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002456
Scott Michel97872d32008-02-23 18:41:37 +00002457class ROTVecInst<ValueType vectype>:
2458 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2459 [(set (vectype VECREG:$rT),
2460 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002461
Scott Michel97872d32008-02-23 18:41:37 +00002462class ROTRegInst<RegisterClass rclass>:
2463 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2464 [(set rclass:$rT,
2465 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002466
Scott Michel97872d32008-02-23 18:41:37 +00002467multiclass RotateLeftWord
2468{
2469 def v4i32: ROTVecInst<v4i32>;
2470 def r32: ROTRegInst<R32C>;
2471}
2472
2473defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002474
Scott Michel438be252007-12-17 22:32:34 +00002475// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2476// 32-bit register
2477def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002478 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2479 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002480
2481def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2482 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2483
2484def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2485 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2486
2487def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002488 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2489 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002490
2491def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2492 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2493
2494def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2495 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2496
Scott Michel97872d32008-02-23 18:41:37 +00002497//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2498// Rotate word, immediate
2499//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002500
Scott Michel97872d32008-02-23 18:41:37 +00002501class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2502 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2503 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002504
Scott Michel97872d32008-02-23 18:41:37 +00002505class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2506 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2507 [(set (vectype VECREG:$rT),
2508 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002509
Scott Michel97872d32008-02-23 18:41:37 +00002510class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2511 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2512 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002513
Scott Michel97872d32008-02-23 18:41:37 +00002514multiclass RotateLeftWordImm
2515{
2516 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2517 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2518 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002519
Scott Michel97872d32008-02-23 18:41:37 +00002520 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2521 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2522 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2523}
Scott Michel438be252007-12-17 22:32:34 +00002524
Scott Michel97872d32008-02-23 18:41:37 +00002525defm ROTI : RotateLeftWordImm;
2526
2527//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2528// Rotate quad by byte (count)
2529//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2530
2531class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2532 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2533 RotateShift, pattern>;
2534
2535class ROTQBYVecInst<ValueType vectype>:
2536 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2537 [(set (vectype VECREG:$rT),
2538 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2539
2540multiclass RotateQuadLeftByBytes
2541{
2542 def v16i8: ROTQBYVecInst<v16i8>;
2543 def v8i16: ROTQBYVecInst<v8i16>;
2544 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002545 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002546 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002547 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002548}
2549
2550defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002551
Scott Michel97872d32008-02-23 18:41:37 +00002552//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2553// Rotate quad by byte (count), immediate
2554//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2555
2556class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2557 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2558 RotateShift, pattern>;
2559
2560class ROTQBYIVecInst<ValueType vectype>:
2561 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2562 [(set (vectype VECREG:$rT),
2563 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2564
2565multiclass RotateQuadByBytesImm
2566{
2567 def v16i8: ROTQBYIVecInst<v16i8>;
2568 def v8i16: ROTQBYIVecInst<v8i16>;
2569 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002570 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002571 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002572 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002573}
2574
2575defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002576
Scott Michel8b6b4202007-12-04 22:35:58 +00002577// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002578class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2579 RI7Form<0b00110011100, OOL, IOL,
2580 "rotqbybi\t$rT, $rA, $shift",
2581 RotateShift, pattern>;
2582
2583class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2584 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2585 [(set (vectype VECREG:$rT),
2586 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2587
2588multiclass RotateQuadByBytesByBitshift {
2589 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2590 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2591 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2592 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2593}
2594
2595defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002596
Scott Michel97872d32008-02-23 18:41:37 +00002597//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002598// See ROTQBY note above.
2599//
2600// Assume that the user of this instruction knows to shift the rotate count
2601// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002602//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002603
Scott Michel97872d32008-02-23 18:41:37 +00002604class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2605 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2606 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002607
Scott Michel97872d32008-02-23 18:41:37 +00002608class ROTQBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002609 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002610 [/* no pattern yet */]>;
2611
2612class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002613 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002614 [/* no pattern yet */]>;
2615
2616multiclass RotateQuadByBitCount
2617{
2618 def v16i8: ROTQBIVecInst<v16i8>;
2619 def v8i16: ROTQBIVecInst<v8i16>;
2620 def v4i32: ROTQBIVecInst<v4i32>;
2621 def v2i64: ROTQBIVecInst<v2i64>;
2622
2623 def r128: ROTQBIRegInst<GPRC>;
2624 def r64: ROTQBIRegInst<R64C>;
2625}
2626
2627defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002628
Scott Michel97872d32008-02-23 18:41:37 +00002629class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2630 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2631 RotateShift, pattern>;
2632
2633class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2634 PatLeaf pred>:
2635 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2636 [/* no pattern yet */]>;
2637
2638class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2639 PatLeaf pred>:
2640 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2641 [/* no pattern yet */]>;
2642
2643multiclass RotateQuadByBitCountImm
2644{
2645 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2646 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2647 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2648 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2649
2650 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2651 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2652}
2653
2654defm ROTQBII : RotateQuadByBitCountImm;
2655
2656//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002657// ROTHM v8i16 form:
2658// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2659// so this only matches a synthetically generated/lowered code
2660// fragment.
2661// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002662//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002663
Scott Michel97872d32008-02-23 18:41:37 +00002664class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2665 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2666 RotateShift, pattern>;
2667
2668def ROTHMv8i16:
2669 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2670 [/* see patterns below - $rB must be negated */]>;
2671
2672def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002673 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2674
Scott Michel97872d32008-02-23 18:41:37 +00002675def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002676 (ROTHMv8i16 VECREG:$rA,
2677 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2678
Scott Michel97872d32008-02-23 18:41:37 +00002679def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002680 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002681 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002682
2683// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2684// Note: This instruction doesn't match a pattern because rB must be negated
2685// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002686
Scott Michel8b6b4202007-12-04 22:35:58 +00002687def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002688 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2689 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002690
2691def : Pat<(srl R16C:$rA, R32C:$rB),
2692 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2693
2694def : Pat<(srl R16C:$rA, R16C:$rB),
2695 (ROTHMr16 R16C:$rA,
2696 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2697
Scott Michel438be252007-12-17 22:32:34 +00002698def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002699 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002700 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002701
2702// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2703// that the immediate can be complemented, so that the user doesn't have to
2704// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002705
Scott Michel97872d32008-02-23 18:41:37 +00002706class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2707 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2708 RotateShift, pattern>;
2709
2710def ROTHMIv8i16:
2711 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2712 [/* no pattern */]>;
2713
2714def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2715 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2716
2717def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002718 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel06eabde2008-12-27 04:51:36 +00002719
Scott Michel97872d32008-02-23 18:41:37 +00002720def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002721 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002722
2723def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002724 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2725 [/* no pattern */]>;
2726
2727def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2728 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002729
2730def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002731 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002732
Scott Michel438be252007-12-17 22:32:34 +00002733def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002734 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00002735
Scott Michel8b6b4202007-12-04 22:35:58 +00002736// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002737class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2738 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2739 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002740
Scott Michel97872d32008-02-23 18:41:37 +00002741def ROTMv4i32:
2742 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2743 [/* see patterns below - $rB must be negated */]>;
2744
Chris Lattnera041d892010-03-15 05:53:47 +00002745def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002746 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2747
Chris Lattnera041d892010-03-15 05:53:47 +00002748def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002749 (ROTMv4i32 VECREG:$rA,
2750 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2751
Chris Lattnera041d892010-03-15 05:53:47 +00002752def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002753 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002754 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002755
2756def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002757 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2758 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002759
2760def : Pat<(srl R32C:$rA, R32C:$rB),
2761 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2762
2763def : Pat<(srl R32C:$rA, R16C:$rB),
2764 (ROTMr32 R32C:$rA,
2765 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2766
Scott Michel438be252007-12-17 22:32:34 +00002767def : Pat<(srl R32C:$rA, R8C:$rB),
2768 (ROTMr32 R32C:$rA,
2769 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2770
Scott Michel8b6b4202007-12-04 22:35:58 +00002771// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2772def ROTMIv4i32:
2773 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2774 "rotmi\t$rT, $rA, $val", RotateShift,
2775 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002776 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002777
Chris Lattnera041d892010-03-15 05:53:47 +00002778def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2779 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel06eabde2008-12-27 04:51:36 +00002780
Chris Lattnera041d892010-03-15 05:53:47 +00002781def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i8 uimm7:$val)),
2782 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002783
2784// ROTMI r32 form: know how to complement the immediate value.
2785def ROTMIr32:
2786 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2787 "rotmi\t$rT, $rA, $val", RotateShift,
2788 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2789
2790def : Pat<(srl R32C:$rA, (i16 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002791 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002792
Scott Michel438be252007-12-17 22:32:34 +00002793def : Pat<(srl R32C:$rA, (i8 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002794 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00002795
Scott Michel97872d32008-02-23 18:41:37 +00002796//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel2ef773a2009-01-06 03:36:14 +00002797// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel8b6b4202007-12-04 22:35:58 +00002798// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002799// that the user knew to negate $rB.
Scott Michel97872d32008-02-23 18:41:37 +00002800//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002801
Scott Michel97872d32008-02-23 18:41:37 +00002802class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2803 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2804 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002805
Scott Michel97872d32008-02-23 18:41:37 +00002806class ROTQMBYVecInst<ValueType vectype>:
2807 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2808 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002809
Scott Michel97872d32008-02-23 18:41:37 +00002810class ROTQMBYRegInst<RegisterClass rclass>:
2811 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00002812 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002813
Scott Michel97872d32008-02-23 18:41:37 +00002814multiclass RotateQuadBytes
2815{
2816 def v16i8: ROTQMBYVecInst<v16i8>;
2817 def v8i16: ROTQMBYVecInst<v8i16>;
2818 def v4i32: ROTQMBYVecInst<v4i32>;
2819 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002820
Scott Michel97872d32008-02-23 18:41:37 +00002821 def r128: ROTQMBYRegInst<GPRC>;
2822 def r64: ROTQMBYRegInst<R64C>;
2823}
2824
2825defm ROTQMBY : RotateQuadBytes;
2826
Scott Michel97872d32008-02-23 18:41:37 +00002827class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2828 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2829 RotateShift, pattern>;
2830
2831class ROTQMBYIVecInst<ValueType vectype>:
2832 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002833 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002834
Scott Michel2ef773a2009-01-06 03:36:14 +00002835class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2836 PatLeaf pred>:
Scott Michel97872d32008-02-23 18:41:37 +00002837 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002838 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002839
Scott Michel2ef773a2009-01-06 03:36:14 +00002840// 128-bit zero extension form:
2841class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2842 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2843 [/* no pattern */]>;
2844
Scott Michel97872d32008-02-23 18:41:37 +00002845multiclass RotateQuadBytesImm
2846{
2847 def v16i8: ROTQMBYIVecInst<v16i8>;
2848 def v8i16: ROTQMBYIVecInst<v8i16>;
2849 def v4i32: ROTQMBYIVecInst<v4i32>;
2850 def v2i64: ROTQMBYIVecInst<v2i64>;
2851
2852 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2853 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Michel2ef773a2009-01-06 03:36:14 +00002854
2855 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2856 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2857 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2858 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michel97872d32008-02-23 18:41:37 +00002859}
2860
2861defm ROTQMBYI : RotateQuadBytesImm;
2862
Scott Michel97872d32008-02-23 18:41:37 +00002863//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2864// Rotate right and mask by bit count
2865//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2866
2867class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2868 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2869 RotateShift, pattern>;
2870
2871class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002872 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2873 [/* no pattern, */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002874
2875multiclass RotateMaskQuadByBitCount
2876{
2877 def v16i8: ROTQMBYBIVecInst<v16i8>;
2878 def v8i16: ROTQMBYBIVecInst<v8i16>;
2879 def v4i32: ROTQMBYBIVecInst<v4i32>;
2880 def v2i64: ROTQMBYBIVecInst<v2i64>;
2881}
2882
2883defm ROTQMBYBI: RotateMaskQuadByBitCount;
2884
2885//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2886// Rotate quad and mask by bits
2887// Note that the rotate amount has to be negated
2888//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2889
2890class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2891 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2892 RotateShift, pattern>;
2893
2894class ROTQMBIVecInst<ValueType vectype>:
2895 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2896 [/* no pattern */]>;
2897
2898class ROTQMBIRegInst<RegisterClass rclass>:
2899 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2900 [/* no pattern */]>;
2901
2902multiclass RotateMaskQuadByBits
2903{
2904 def v16i8: ROTQMBIVecInst<v16i8>;
2905 def v8i16: ROTQMBIVecInst<v8i16>;
2906 def v4i32: ROTQMBIVecInst<v4i32>;
2907 def v2i64: ROTQMBIVecInst<v2i64>;
2908
2909 def r128: ROTQMBIRegInst<GPRC>;
2910 def r64: ROTQMBIRegInst<R64C>;
2911}
2912
2913defm ROTQMBI: RotateMaskQuadByBits;
2914
Scott Michel97872d32008-02-23 18:41:37 +00002915//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2916// Rotate quad and mask by bits, immediate
2917//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2918
2919class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2920 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2921 RotateShift, pattern>;
2922
2923class ROTQMBIIVecInst<ValueType vectype>:
2924 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002925 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002926
2927class ROTQMBIIRegInst<RegisterClass rclass>:
2928 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002929 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002930
2931multiclass RotateMaskQuadByBitsImm
2932{
2933 def v16i8: ROTQMBIIVecInst<v16i8>;
2934 def v8i16: ROTQMBIIVecInst<v8i16>;
2935 def v4i32: ROTQMBIIVecInst<v4i32>;
2936 def v2i64: ROTQMBIIVecInst<v2i64>;
2937
2938 def r128: ROTQMBIIRegInst<GPRC>;
2939 def r64: ROTQMBIIRegInst<R64C>;
2940}
2941
2942defm ROTQMBII: RotateMaskQuadByBitsImm;
2943
2944//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2945//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002946
2947def ROTMAHv8i16:
2948 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2949 "rotmah\t$rT, $rA, $rB", RotateShift,
2950 [/* see patterns below - $rB must be negated */]>;
2951
Chris Lattnera041d892010-03-15 05:53:47 +00002952def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002953 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2954
Chris Lattnera041d892010-03-15 05:53:47 +00002955def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002956 (ROTMAHv8i16 VECREG:$rA,
2957 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2958
Chris Lattnera041d892010-03-15 05:53:47 +00002959def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002960 (ROTMAHv8i16 VECREG:$rA,
2961 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2962
Scott Michel8b6b4202007-12-04 22:35:58 +00002963def ROTMAHr16:
2964 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2965 "rotmah\t$rT, $rA, $rB", RotateShift,
2966 [/* see patterns below - $rB must be negated */]>;
2967
2968def : Pat<(sra R16C:$rA, R32C:$rB),
2969 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2970
2971def : Pat<(sra R16C:$rA, R16C:$rB),
2972 (ROTMAHr16 R16C:$rA,
2973 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2974
Scott Michel438be252007-12-17 22:32:34 +00002975def : Pat<(sra R16C:$rA, R8C:$rB),
2976 (ROTMAHr16 R16C:$rA,
2977 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2978
Scott Michel8b6b4202007-12-04 22:35:58 +00002979def ROTMAHIv8i16:
2980 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2981 "rotmahi\t$rT, $rA, $val", RotateShift,
2982 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002983 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002984
Scott Michel97872d32008-02-23 18:41:37 +00002985def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002986 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002987
Scott Michel97872d32008-02-23 18:41:37 +00002988def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002989 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00002990
Scott Michel8b6b4202007-12-04 22:35:58 +00002991def ROTMAHIr16:
2992 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2993 "rotmahi\t$rT, $rA, $val", RotateShift,
2994 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2995
2996def : Pat<(sra R16C:$rA, (i32 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00002997 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002998
Scott Michel438be252007-12-17 22:32:34 +00002999def : Pat<(sra R16C:$rA, (i8 imm:$val)),
Chris Lattnera041d892010-03-15 05:53:47 +00003000 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel438be252007-12-17 22:32:34 +00003001
Scott Michel8b6b4202007-12-04 22:35:58 +00003002def ROTMAv4i32:
3003 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
3004 "rotma\t$rT, $rA, $rB", RotateShift,
3005 [/* see patterns below - $rB must be negated */]>;
3006
Chris Lattnera041d892010-03-15 05:53:47 +00003007def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R32C:$rB),
3008 (ROTMAv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003009
Chris Lattnera041d892010-03-15 05:53:47 +00003010def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R16C:$rB),
3011 (ROTMAv4i32 VECREG:$rA,
Scott Michel8b6b4202007-12-04 22:35:58 +00003012 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3013
Chris Lattnera041d892010-03-15 05:53:47 +00003014def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R8C:$rB),
3015 (ROTMAv4i32 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00003016 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3017
Scott Michel8b6b4202007-12-04 22:35:58 +00003018def ROTMAr32:
3019 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3020 "rotma\t$rT, $rA, $rB", RotateShift,
3021 [/* see patterns below - $rB must be negated */]>;
3022
3023def : Pat<(sra R32C:$rA, R32C:$rB),
3024 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
3025
3026def : Pat<(sra R32C:$rA, R16C:$rB),
3027 (ROTMAr32 R32C:$rA,
3028 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3029
Scott Michel438be252007-12-17 22:32:34 +00003030def : Pat<(sra R32C:$rA, R8C:$rB),
3031 (ROTMAr32 R32C:$rA,
3032 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3033
Scott Michel67224b22008-06-02 22:18:03 +00003034class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
3035 RRForm<0b01011110000, OOL, IOL,
3036 "rotmai\t$rT, $rA, $val",
3037 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003038
Scott Michel67224b22008-06-02 22:18:03 +00003039class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3040 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3041 [(set (vectype VECREG:$rT),
3042 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003043
Scott Michel67224b22008-06-02 22:18:03 +00003044class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3045 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3046 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003047
Scott Michel67224b22008-06-02 22:18:03 +00003048multiclass RotateMaskAlgebraicImm {
3049 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3050 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3051 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3052 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3053}
Scott Michel8b6b4202007-12-04 22:35:58 +00003054
Scott Michel67224b22008-06-02 22:18:03 +00003055defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00003056
Scott Michel8b6b4202007-12-04 22:35:58 +00003057//===----------------------------------------------------------------------===//
3058// Branch and conditionals:
3059//===----------------------------------------------------------------------===//
3060
3061let isTerminator = 1, isBarrier = 1 in {
3062 // Halt If Equal (r32 preferred slot only, no vector form)
3063 def HEQr32:
3064 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3065 "heq\t$rA, $rB", BranchResolv,
3066 [/* no pattern to match */]>;
3067
3068 def HEQIr32 :
3069 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3070 "heqi\t$rA, $val", BranchResolv,
3071 [/* no pattern to match */]>;
3072
3073 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3074 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3075 def HGTr32:
3076 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3077 "hgt\t$rA, $rB", BranchResolv,
3078 [/* no pattern to match */]>;
3079
Scott Michel06eabde2008-12-27 04:51:36 +00003080 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00003081 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3082 "hgti\t$rA, $val", BranchResolv,
3083 [/* no pattern to match */]>;
3084
3085 def HLGTr32:
3086 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3087 "hlgt\t$rA, $rB", BranchResolv,
3088 [/* no pattern to match */]>;
3089
3090 def HLGTIr32:
3091 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3092 "hlgti\t$rA, $val", BranchResolv,
3093 [/* no pattern to match */]>;
3094}
3095
Scott Michel06eabde2008-12-27 04:51:36 +00003096//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3097// Comparison operators for i8, i16 and i32:
3098//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003099
Scott Michel97872d32008-02-23 18:41:37 +00003100class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3101 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3102 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003103
Scott Michel97872d32008-02-23 18:41:37 +00003104multiclass CmpEqualByte
3105{
3106 def v16i8 :
3107 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3108 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3109 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00003110
Scott Michel97872d32008-02-23 18:41:37 +00003111 def r8 :
3112 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3113 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3114}
Scott Michel8b6b4202007-12-04 22:35:58 +00003115
Scott Michel97872d32008-02-23 18:41:37 +00003116class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3117 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3118 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003119
Scott Michel97872d32008-02-23 18:41:37 +00003120multiclass CmpEqualByteImm
3121{
3122 def v16i8 :
3123 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3124 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3125 v16i8SExt8Imm:$val))]>;
3126 def r8:
3127 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3128 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3129}
Scott Michel8b6b4202007-12-04 22:35:58 +00003130
Scott Michel97872d32008-02-23 18:41:37 +00003131class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3132 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3133 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003134
Scott Michel97872d32008-02-23 18:41:37 +00003135multiclass CmpEqualHalfword
3136{
3137 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3138 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3139 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003140
Scott Michel97872d32008-02-23 18:41:37 +00003141 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3142 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3143}
Scott Michel8b6b4202007-12-04 22:35:58 +00003144
Scott Michel97872d32008-02-23 18:41:37 +00003145class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3146 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3147 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003148
Scott Michel97872d32008-02-23 18:41:37 +00003149multiclass CmpEqualHalfwordImm
3150{
3151 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3152 [(set (v8i16 VECREG:$rT),
3153 (seteq (v8i16 VECREG:$rA),
3154 (v8i16 v8i16SExt10Imm:$val)))]>;
3155 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3156 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3157}
Scott Michel8b6b4202007-12-04 22:35:58 +00003158
Scott Michel97872d32008-02-23 18:41:37 +00003159class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3160 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3161 ByteOp, pattern>;
3162
3163multiclass CmpEqualWord
3164{
3165 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3166 [(set (v4i32 VECREG:$rT),
3167 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3168
3169 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3170 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3171}
3172
3173class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3174 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3175 ByteOp, pattern>;
3176
3177multiclass CmpEqualWordImm
3178{
3179 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3180 [(set (v4i32 VECREG:$rT),
3181 (seteq (v4i32 VECREG:$rA),
3182 (v4i32 v4i32SExt16Imm:$val)))]>;
3183
3184 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3185 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3186}
3187
3188class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3189 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3190 ByteOp, pattern>;
3191
3192multiclass CmpGtrByte
3193{
3194 def v16i8 :
3195 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3196 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3197 (v8i16 VECREG:$rB)))]>;
3198
3199 def r8 :
3200 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3201 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3202}
3203
3204class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3205 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3206 ByteOp, pattern>;
3207
3208multiclass CmpGtrByteImm
3209{
3210 def v16i8 :
3211 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3212 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3213 v16i8SExt8Imm:$val))]>;
3214 def r8:
3215 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003216 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003217}
3218
3219class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3220 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3221 ByteOp, pattern>;
3222
3223multiclass CmpGtrHalfword
3224{
3225 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3226 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3227 (v8i16 VECREG:$rB)))]>;
3228
3229 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3230 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3231}
3232
3233class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3234 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3235 ByteOp, pattern>;
3236
3237multiclass CmpGtrHalfwordImm
3238{
3239 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3240 [(set (v8i16 VECREG:$rT),
3241 (setgt (v8i16 VECREG:$rA),
3242 (v8i16 v8i16SExt10Imm:$val)))]>;
3243 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3244 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3245}
3246
3247class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3248 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3249 ByteOp, pattern>;
3250
3251multiclass CmpGtrWord
3252{
3253 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3254 [(set (v4i32 VECREG:$rT),
3255 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3256
3257 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3258 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3259}
3260
3261class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3262 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3263 ByteOp, pattern>;
3264
3265multiclass CmpGtrWordImm
3266{
3267 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3268 [(set (v4i32 VECREG:$rT),
3269 (setgt (v4i32 VECREG:$rA),
3270 (v4i32 v4i32SExt16Imm:$val)))]>;
3271
3272 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3273 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003274
3275 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3276 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3277 [(set (v4i32 VECREG:$rT),
3278 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3279 (v4i32 v4i32SExt16Imm:$val)))]>;
3280
3281 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +00003282 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00003283}
3284
3285class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003286 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003287 ByteOp, pattern>;
3288
3289multiclass CmpLGtrByte
3290{
3291 def v16i8 :
3292 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3293 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3294 (v8i16 VECREG:$rB)))]>;
3295
3296 def r8 :
3297 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3298 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3299}
3300
3301class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003302 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003303 ByteOp, pattern>;
3304
3305multiclass CmpLGtrByteImm
3306{
3307 def v16i8 :
3308 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3309 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3310 v16i8SExt8Imm:$val))]>;
3311 def r8:
3312 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3313 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3314}
3315
3316class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003317 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003318 ByteOp, pattern>;
3319
3320multiclass CmpLGtrHalfword
3321{
3322 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3323 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3324 (v8i16 VECREG:$rB)))]>;
3325
3326 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3327 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3328}
3329
3330class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003331 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003332 ByteOp, pattern>;
3333
3334multiclass CmpLGtrHalfwordImm
3335{
3336 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3337 [(set (v8i16 VECREG:$rT),
3338 (setugt (v8i16 VECREG:$rA),
3339 (v8i16 v8i16SExt10Imm:$val)))]>;
3340 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3341 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3342}
3343
3344class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003345 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003346 ByteOp, pattern>;
3347
3348multiclass CmpLGtrWord
3349{
3350 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3351 [(set (v4i32 VECREG:$rT),
3352 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3353
3354 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3355 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3356}
3357
3358class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003359 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003360 ByteOp, pattern>;
3361
3362multiclass CmpLGtrWordImm
3363{
3364 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3365 [(set (v4i32 VECREG:$rT),
3366 (setugt (v4i32 VECREG:$rA),
3367 (v4i32 v4i32SExt16Imm:$val)))]>;
3368
3369 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003370 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003371}
3372
3373defm CEQB : CmpEqualByte;
3374defm CEQBI : CmpEqualByteImm;
3375defm CEQH : CmpEqualHalfword;
3376defm CEQHI : CmpEqualHalfwordImm;
3377defm CEQ : CmpEqualWord;
3378defm CEQI : CmpEqualWordImm;
3379defm CGTB : CmpGtrByte;
3380defm CGTBI : CmpGtrByteImm;
3381defm CGTH : CmpGtrHalfword;
3382defm CGTHI : CmpGtrHalfwordImm;
3383defm CGT : CmpGtrWord;
3384defm CGTI : CmpGtrWordImm;
3385defm CLGTB : CmpLGtrByte;
3386defm CLGTBI : CmpLGtrByteImm;
3387defm CLGTH : CmpLGtrHalfword;
3388defm CLGTHI : CmpLGtrHalfwordImm;
3389defm CLGT : CmpLGtrWord;
3390defm CLGTI : CmpLGtrWordImm;
3391
Scott Michel53ab7792008-03-10 16:58:52 +00003392//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003393// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3394// define a pattern to generate the right code, as a binary operator
3395// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003396//
Scott Michel06eabde2008-12-27 04:51:36 +00003397// Notes:
3398// 1. This only matches the setcc set of conditionals. Special pattern
3399// matching is used for select conditionals.
3400//
3401// 2. The "DAG" versions of these classes is almost exclusively used for
3402// i64 comparisons. See the tblgen fundamentals documentation for what
3403// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3404// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003405//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003406
Scott Michel53ab7792008-03-10 16:58:52 +00003407class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3408 SPUInstr xorinst, SPUInstr cmpare>:
3409 Pat<(cond rclass:$rA, rclass:$rB),
3410 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3411
3412class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3413 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3414 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3415 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3416
Scott Michel06eabde2008-12-27 04:51:36 +00003417def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003418def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3419
Scott Michel06eabde2008-12-27 04:51:36 +00003420def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003421def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3422
3423def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3424def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003425
3426class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3427 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3428 Pat<(cond rclass:$rA, rclass:$rB),
3429 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3430 (cmpOp2 rclass:$rA, rclass:$rB))>;
3431
3432class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3433 ValueType immtype,
3434 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3435 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3436 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3437 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3438
Scott Michel53ab7792008-03-10 16:58:52 +00003439def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3440def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3441def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3442def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3443def : Pat<(setle R8C:$rA, R8C:$rB),
3444 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3445def : Pat<(setle R8C:$rA, immU8:$imm),
3446 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003447
Scott Michel53ab7792008-03-10 16:58:52 +00003448def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3449def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3450 ORr16, CGTHIr16, CEQHIr16>;
3451def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3452def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3453def : Pat<(setle R16C:$rA, R16C:$rB),
3454 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3455def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3456 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003457
Scott Michel53ab7792008-03-10 16:58:52 +00003458def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3459def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3460 ORr32, CGTIr32, CEQIr32>;
3461def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3462def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3463def : Pat<(setle R32C:$rA, R32C:$rB),
3464 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3465def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3466 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003467
Scott Michel53ab7792008-03-10 16:58:52 +00003468def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3469def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3470def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3471def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3472def : Pat<(setule R8C:$rA, R8C:$rB),
3473 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3474def : Pat<(setule R8C:$rA, immU8:$imm),
3475 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003476
Scott Michel53ab7792008-03-10 16:58:52 +00003477def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3478def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3479 ORr16, CLGTHIr16, CEQHIr16>;
3480def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3481def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3482 CLGTHIr16, CEQHIr16>;
3483def : Pat<(setule R16C:$rA, R16C:$rB),
3484 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003485def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003486 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003487
Scott Michel53ab7792008-03-10 16:58:52 +00003488def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003489def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003490 ORr32, CLGTIr32, CEQIr32>;
3491def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003492def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003493def : Pat<(setule R32C:$rA, R32C:$rB),
3494 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3495def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3496 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003497
Scott Michel53ab7792008-03-10 16:58:52 +00003498//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3499// select conditional patterns:
3500//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3501
3502class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3503 SPUInstr selinstr, SPUInstr cmpare>:
3504 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3505 rclass:$rTrue, rclass:$rFalse),
3506 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003507 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003508
3509class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3510 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3511 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003512 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003513 (selinstr rclass:$rTrue, rclass:$rFalse,
3514 (cmpare rclass:$rA, immpred:$imm))>;
3515
3516def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3517def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3518def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3519def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3520def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3521def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3522
3523def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3524def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3525def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3526def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3527def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3528def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3529
3530def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3531def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3532def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3533def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3534def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3535def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3536
3537class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3538 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3539 SPUInstr cmpOp2>:
3540 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003541 rclass:$rTrue, rclass:$rFalse),
3542 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003543 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3544 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3545
3546class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3547 ValueType inttype,
3548 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3549 SPUInstr cmpOp2>:
3550 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003551 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003552 (selinstr rclass:$rFalse, rclass:$rTrue,
3553 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3554 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3555
3556def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3557def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3558 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3559
3560def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3561def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3562 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3563
3564def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3565def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3566 SELBr32, ORr32, CGTIr32, CEQIr32>;
3567
3568def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3569def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3570 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3571
3572def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3573def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3574 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3575
3576def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3577def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3578 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003579
3580//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003581
3582let isCall = 1,
3583 // All calls clobber the non-callee-saved registers:
3584 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3585 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3586 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3587 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3588 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3589 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3590 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3591 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3592 // All of these instructions use $lr (aka $0)
3593 Uses = [R0] in {
3594 // Branch relative and set link: Used if we actually know that the target
3595 // is within [-32768, 32767] bytes of the target
3596 def BRSL:
3597 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3598 "brsl\t$$lr, $func",
3599 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3600
3601 // Branch absolute and set link: Used if we actually know that the target
3602 // is an absolute address
3603 def BRASL:
3604 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3605 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003606 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003607
3608 // Branch indirect and set link if external data. These instructions are not
3609 // actually generated, matched by an intrinsic:
3610 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3611 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3612 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3613 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3614
3615 // Branch indirect and set link. This is the "X-form" address version of a
3616 // function call
3617 def BISL:
3618 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3619}
3620
Scott Michelae5cbf52008-12-29 03:23:36 +00003621// Support calls to external symbols:
3622def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3623 (BRSL texternalsym:$func)>;
3624
3625def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3626 (BRASL texternalsym:$func)>;
3627
Scott Michel8b6b4202007-12-04 22:35:58 +00003628// Unconditional branches:
Dan Gohman7a94dac2009-11-10 22:16:57 +00003629let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
3630 let isBarrier = 1 in {
3631 def BR :
3632 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3633 "br\t$dest",
3634 [(br bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003635
Dan Gohman7a94dac2009-11-10 22:16:57 +00003636 // Unconditional, absolute address branch
3637 def BRA:
3638 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3639 "bra\t$dest",
3640 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003641
Dan Gohman7a94dac2009-11-10 22:16:57 +00003642 // Indirect branch
3643 def BI:
3644 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3645 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003646
Scott Michele0168c12009-01-05 01:34:35 +00003647 // Conditional branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003648 class BRNZInst<dag IOL, list<dag> pattern>:
3649 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3650 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003651
Scott Michel06eabde2008-12-27 04:51:36 +00003652 class BRNZRegInst<RegisterClass rclass>:
3653 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3654 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003655
Scott Michel06eabde2008-12-27 04:51:36 +00003656 class BRNZVecInst<ValueType vectype>:
3657 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3658 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003659
Scott Michel06eabde2008-12-27 04:51:36 +00003660 multiclass BranchNotZero {
3661 def v4i32 : BRNZVecInst<v4i32>;
3662 def r32 : BRNZRegInst<R32C>;
3663 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003664
Scott Michel06eabde2008-12-27 04:51:36 +00003665 defm BRNZ : BranchNotZero;
3666
3667 class BRZInst<dag IOL, list<dag> pattern>:
3668 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3669 BranchResolv, pattern>;
3670
3671 class BRZRegInst<RegisterClass rclass>:
3672 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3673
3674 class BRZVecInst<ValueType vectype>:
3675 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3676
3677 multiclass BranchZero {
3678 def v4i32: BRZVecInst<v4i32>;
3679 def r32: BRZRegInst<R32C>;
3680 }
3681
3682 defm BRZ: BranchZero;
3683
3684 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3685 // be useful:
3686 /*
3687 class BINZInst<dag IOL, list<dag> pattern>:
3688 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3689
3690 class BINZRegInst<RegisterClass rclass>:
3691 BINZInst<(ins rclass:$rA, brtarget:$dest),
3692 [(brcond rclass:$rA, R32C:$dest)]>;
3693
3694 class BINZVecInst<ValueType vectype>:
3695 BINZInst<(ins VECREG:$rA, R32C:$dest),
3696 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3697
3698 multiclass BranchNotZeroIndirect {
3699 def v4i32: BINZVecInst<v4i32>;
3700 def r32: BINZRegInst<R32C>;
3701 }
3702
3703 defm BINZ: BranchNotZeroIndirect;
3704
3705 class BIZInst<dag IOL, list<dag> pattern>:
3706 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3707
3708 class BIZRegInst<RegisterClass rclass>:
3709 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3710
3711 class BIZVecInst<ValueType vectype>:
3712 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3713
3714 multiclass BranchZeroIndirect {
3715 def v4i32: BIZVecInst<v4i32>;
3716 def r32: BIZRegInst<R32C>;
3717 }
3718
3719 defm BIZ: BranchZeroIndirect;
3720 */
3721
3722 class BRHNZInst<dag IOL, list<dag> pattern>:
3723 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3724 pattern>;
3725
3726 class BRHNZRegInst<RegisterClass rclass>:
3727 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3728 [(brcond rclass:$rCond, bb:$dest)]>;
3729
3730 class BRHNZVecInst<ValueType vectype>:
3731 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3732
3733 multiclass BranchNotZeroHalfword {
3734 def v8i16: BRHNZVecInst<v8i16>;
3735 def r16: BRHNZRegInst<R16C>;
3736 }
3737
3738 defm BRHNZ: BranchNotZeroHalfword;
3739
3740 class BRHZInst<dag IOL, list<dag> pattern>:
3741 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3742 pattern>;
3743
3744 class BRHZRegInst<RegisterClass rclass>:
3745 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3746
3747 class BRHZVecInst<ValueType vectype>:
3748 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3749
3750 multiclass BranchZeroHalfword {
3751 def v8i16: BRHZVecInst<v8i16>;
3752 def r16: BRHZRegInst<R16C>;
3753 }
3754
3755 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003756}
3757
Scott Michel394e26d2008-01-17 20:38:41 +00003758//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003759// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003760//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003761
Scott Michel06eabde2008-12-27 04:51:36 +00003762def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3763 (BRHZr16 R16C:$rA, bb:$dest)>;
3764def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3765 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003766
Scott Michel06eabde2008-12-27 04:51:36 +00003767def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3768 (BRZr32 R32C:$rA, bb:$dest)>;
3769def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3770 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003771
Scott Michel97872d32008-02-23 18:41:37 +00003772multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3773{
3774 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3775 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003776
Scott Michel97872d32008-02-23 18:41:37 +00003777 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3778 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3779
3780 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3781 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3782
3783 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3784 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3785}
3786
Scott Michele0168c12009-01-05 01:34:35 +00003787defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3788defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003789
3790multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3791{
3792 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3793 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3794
3795 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3796 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3797
3798 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3799 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3800
3801 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3802 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3803}
3804
Scott Michel06eabde2008-12-27 04:51:36 +00003805defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3806defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003807
3808multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3809 SPUInstr orinst32, SPUInstr brinst32>
3810{
3811 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3812 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3813 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3814 bb:$dest)>;
3815
3816 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3817 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3818 (CEQHr16 R16C:$rA, R16:$rB)),
3819 bb:$dest)>;
3820
3821 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3822 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3823 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3824 bb:$dest)>;
3825
3826 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3827 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3828 (CEQr32 R32C:$rA, R32C:$rB)),
3829 bb:$dest)>;
3830}
3831
Scott Michel06eabde2008-12-27 04:51:36 +00003832defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3833defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003834
3835multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3836{
3837 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3838 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3839
3840 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3841 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3842
3843 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3844 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3845
3846 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3847 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3848}
3849
Scott Michel06eabde2008-12-27 04:51:36 +00003850defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3851defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003852
3853multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3854 SPUInstr orinst32, SPUInstr brinst32>
3855{
3856 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3857 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3858 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3859 bb:$dest)>;
3860
3861 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3862 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3863 (CEQHr16 R16C:$rA, R16:$rB)),
3864 bb:$dest)>;
3865
3866 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3867 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3868 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3869 bb:$dest)>;
3870
3871 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3872 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3873 (CEQr32 R32C:$rA, R32C:$rB)),
3874 bb:$dest)>;
3875}
3876
Scott Michel06eabde2008-12-27 04:51:36 +00003877defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3878defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003879
Scott Michel8b6b4202007-12-04 22:35:58 +00003880let isTerminator = 1, isBarrier = 1 in {
3881 let isReturn = 1 in {
3882 def RET:
3883 RETForm<"bi\t$$lr", [(retflag)]>;
3884 }
3885}
3886
3887//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003888// Single precision floating point instructions
3889//===----------------------------------------------------------------------===//
3890
Scott Michel61895fe2008-12-10 00:15:19 +00003891class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3892 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003893 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003894
Scott Michel61895fe2008-12-10 00:15:19 +00003895class FAVecInst<ValueType vectype>:
3896 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3897 [(set (vectype VECREG:$rT),
Scott Michel4d07fb72008-12-30 23:28:25 +00003898 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003899
Scott Michel61895fe2008-12-10 00:15:19 +00003900multiclass SFPAdd
3901{
3902 def v4f32: FAVecInst<v4f32>;
Kalle Raiskilae73c0e82010-08-02 10:25:47 +00003903 def v2f32: FAVecInst<v2f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003904 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3905 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003906}
Scott Michel8b6b4202007-12-04 22:35:58 +00003907
Scott Michel61895fe2008-12-10 00:15:19 +00003908defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003909
Scott Michel61895fe2008-12-10 00:15:19 +00003910class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3911 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003912 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003913
Scott Michel61895fe2008-12-10 00:15:19 +00003914class FSVecInst<ValueType vectype>:
3915 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00003916 [(set (vectype VECREG:$rT),
3917 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003918
3919multiclass SFPSub
3920{
3921 def v4f32: FSVecInst<v4f32>;
Kalle Raiskilae73c0e82010-08-02 10:25:47 +00003922 def v2f32: FSVecInst<v2f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003923 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3924 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003925}
3926
3927defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003928
Kalle Raiskilae73c0e82010-08-02 10:25:47 +00003929class FMInst<dag OOL, dag IOL, list<dag> pattern>:
3930 RRForm<0b01100011010, OOL, IOL,
3931 "fm\t$rT, $rA, $rB", SPrecFP,
3932 pattern>;
3933
3934class FMVecInst<ValueType type>:
3935 FMInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3936 [(set (type VECREG:$rT),
3937 (fmul (type VECREG:$rA), (type VECREG:$rB)))]>;
3938
3939multiclass SFPMul
3940{
3941 def v4f32: FMVecInst<v4f32>;
3942 def v2f32: FMVecInst<v2f32>;
3943 def f32: FMInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3944 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3945}
3946
3947defm FM : SFPMul;
3948
3949// Floating point multiply and add
3950// e.g. d = c + (a * b)
3951def FMAv4f32:
3952 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3953 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3954 [(set (v4f32 VECREG:$rT),
3955 (fadd (v4f32 VECREG:$rC),
3956 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3957
3958def FMAf32:
3959 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3960 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3961 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3962
3963// FP multiply and subtract
3964// Subtracts value in rC from product
3965// res = a * b - c
3966def FMSv4f32 :
3967 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3968 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3969 [(set (v4f32 VECREG:$rT),
3970 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3971 (v4f32 VECREG:$rC)))]>;
3972
3973def FMSf32 :
3974 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3975 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3976 [(set R32FP:$rT,
3977 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3978
3979// Floating Negative Mulitply and Subtract
3980// Subtracts product from value in rC
3981// res = fneg(fms a b c)
3982// = - (a * b - c)
3983// = c - a * b
3984// NOTE: subtraction order
3985// fsub a b = a - b
3986// fs a b = b - a?
3987def FNMSf32 :
3988 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3989 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3990 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3991
3992def FNMSv4f32 :
3993 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3994 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3995 [(set (v4f32 VECREG:$rT),
3996 (fsub (v4f32 VECREG:$rC),
3997 (fmul (v4f32 VECREG:$rA),
3998 (v4f32 VECREG:$rB))))]>;
3999
4000
4001
4002
Scott Michel8b6b4202007-12-04 22:35:58 +00004003// Floating point reciprocal estimate
Scott Michel8b6b4202007-12-04 22:35:58 +00004004
Scott Michel4d07fb72008-12-30 23:28:25 +00004005class FRESTInst<dag OOL, dag IOL>:
4006 RRForm_1<0b00110111000, OOL, IOL,
4007 "frest\t$rT, $rA", SPrecFP,
4008 [/* no pattern */]>;
4009
4010def FRESTv4f32 :
4011 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
4012
4013def FRESTf32 :
4014 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004015
4016// Floating point interpolate (used in conjunction with reciprocal estimate)
4017def FIv4f32 :
4018 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4019 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00004020 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004021
4022def FIf32 :
4023 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4024 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00004025 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004026
Scott Michel33d73eb2008-11-21 02:56:16 +00004027//--------------------------------------------------------------------------
4028// Basic single precision floating point comparisons:
4029//
4030// Note: There is no support on SPU for single precision NaN. Consequently,
4031// ordered and unordered comparisons are the same.
4032//--------------------------------------------------------------------------
4033
Scott Michel8b6b4202007-12-04 22:35:58 +00004034def FCEQf32 :
4035 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4036 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00004037 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
4038
4039def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
4040 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004041
4042def FCMEQf32 :
4043 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4044 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00004045 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4046
4047def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
4048 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004049
4050def FCGTf32 :
4051 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4052 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00004053 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
4054
4055def : Pat<(setugt R32FP:$rA, R32FP:$rB),
4056 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004057
4058def FCMGTf32 :
4059 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4060 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00004061 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4062
4063def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
4064 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
4065
4066//--------------------------------------------------------------------------
4067// Single precision floating point comparisons and SETCC equivalents:
4068//--------------------------------------------------------------------------
4069
4070def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
4071def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
4072
4073def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
4074def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
4075
4076def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
4077def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
4078
4079def : Pat<(setule R32FP:$rA, R32FP:$rB),
4080 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
4081def : Pat<(setole R32FP:$rA, R32FP:$rB),
4082 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004083
4084// FP Status and Control Register Write
4085// Why isn't rT a don't care in the ISA?
4086// Should we create a special RRForm_3 for this guy and zero out the rT?
4087def FSCRWf32 :
4088 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
4089 "fscrwr\t$rA", SPrecFP,
4090 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
4091
4092// FP Status and Control Register Read
4093def FSCRRf32 :
4094 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
4095 "fscrrd\t$rT", SPrecFP,
4096 [/* This instruction requires an intrinsic */]>;
4097
4098// llvm instruction space
4099// How do these map onto cell instructions?
4100// fdiv rA rB
4101// frest rC rB # c = 1/b (both lines)
4102// fi rC rB rC
4103// fm rD rA rC # d = a * 1/b
4104// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4105// fma rB rB rC rD # b = b * c + d
4106// = -(d *b -a) * c + d
4107// = a * c - c ( a *b *c - a)
4108
4109// fcopysign (???)
4110
4111// Library calls:
4112// These llvm instructions will actually map to library calls.
4113// All that's needed, then, is to check that the appropriate library is
4114// imported and do a brsl to the proper function name.
4115// frem # fmod(x, y): x - (x/y) * y
4116// (Note: fmod(double, double), fmodf(float,float)
4117// fsqrt?
4118// fsin?
4119// fcos?
4120// Unimplemented SPU instruction space
4121// floating reciprocal absolute square root estimate (frsqest)
4122
4123// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00004124// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00004125// status and control register read
4126
4127//--------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00004128// Floating Point Conversions
4129// Signed conversions:
4130def CSiFv4f32:
4131 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4132 "csflt\t$rT, $rA, 0", SPrecFP,
4133 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4134
Scott Michel06eabde2008-12-27 04:51:36 +00004135// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00004136def CSiFf32 :
4137 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4138 "csflt\t$rT, $rA, 0", SPrecFP,
4139 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4140
4141// Convert unsigned into to float
4142def CUiFv4f32 :
4143 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4144 "cuflt\t$rT, $rA, 0", SPrecFP,
4145 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4146
4147def CUiFf32 :
4148 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4149 "cuflt\t$rT, $rA, 0", SPrecFP,
4150 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4151
Scott Michel06eabde2008-12-27 04:51:36 +00004152// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004153// Assume that scale = 0
4154
4155def CFUiv4f32 :
4156 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4157 "cfltu\t$rT, $rA, 0", SPrecFP,
4158 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4159
4160def CFUif32 :
4161 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4162 "cfltu\t$rT, $rA, 0", SPrecFP,
4163 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4164
Scott Michel06eabde2008-12-27 04:51:36 +00004165// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004166// Assume that scale = 0
4167
4168def CFSiv4f32 :
4169 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4170 "cflts\t$rT, $rA, 0", SPrecFP,
4171 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4172
4173def CFSif32 :
4174 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4175 "cflts\t$rT, $rA, 0", SPrecFP,
4176 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4177
4178//===----------------------------------------------------------------------==//
4179// Single<->Double precision conversions
4180//===----------------------------------------------------------------------==//
4181
4182// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4183// v4f32, output is v2f64--which goes in the name?)
4184
4185// Floating point extend single to double
4186// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4187// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4188// are ignored).
4189def FESDvec :
4190 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4191 "fesd\t$rT, $rA", SPrecFP,
Chris Lattnera5c69832010-03-19 04:53:47 +00004192 [/*(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))*/]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004193
4194def FESDf32 :
4195 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4196 "fesd\t$rT, $rA", SPrecFP,
4197 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4198
4199// Floating point round double to single
4200//def FRDSvec :
4201// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4202// "frds\t$rT, $rA,", SPrecFP,
4203// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4204
4205def FRDSf64 :
4206 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4207 "frds\t$rT, $rA", SPrecFP,
4208 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4209
4210//ToDo include anyextend?
4211
4212//===----------------------------------------------------------------------==//
4213// Double precision floating point instructions
4214//===----------------------------------------------------------------------==//
4215def FAf64 :
4216 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4217 "dfa\t$rT, $rA, $rB", DPrecFP,
4218 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4219
4220def FAv2f64 :
4221 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4222 "dfa\t$rT, $rA, $rB", DPrecFP,
4223 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4224
4225def FSf64 :
4226 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4227 "dfs\t$rT, $rA, $rB", DPrecFP,
4228 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4229
4230def FSv2f64 :
4231 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4232 "dfs\t$rT, $rA, $rB", DPrecFP,
4233 [(set (v2f64 VECREG:$rT),
4234 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4235
4236def FMf64 :
4237 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4238 "dfm\t$rT, $rA, $rB", DPrecFP,
4239 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4240
4241def FMv2f64:
4242 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4243 "dfm\t$rT, $rA, $rB", DPrecFP,
4244 [(set (v2f64 VECREG:$rT),
4245 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4246
4247def FMAf64:
4248 RRForm<0b00111010110, (outs R64FP:$rT),
4249 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4250 "dfma\t$rT, $rA, $rB", DPrecFP,
4251 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4252 RegConstraint<"$rC = $rT">,
4253 NoEncode<"$rC">;
4254
4255def FMAv2f64:
4256 RRForm<0b00111010110, (outs VECREG:$rT),
4257 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4258 "dfma\t$rT, $rA, $rB", DPrecFP,
4259 [(set (v2f64 VECREG:$rT),
4260 (fadd (v2f64 VECREG:$rC),
4261 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4262 RegConstraint<"$rC = $rT">,
4263 NoEncode<"$rC">;
4264
4265def FMSf64 :
4266 RRForm<0b10111010110, (outs R64FP:$rT),
4267 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4268 "dfms\t$rT, $rA, $rB", DPrecFP,
4269 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4270 RegConstraint<"$rC = $rT">,
4271 NoEncode<"$rC">;
4272
4273def FMSv2f64 :
4274 RRForm<0b10111010110, (outs VECREG:$rT),
4275 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4276 "dfms\t$rT, $rA, $rB", DPrecFP,
4277 [(set (v2f64 VECREG:$rT),
4278 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4279 (v2f64 VECREG:$rC)))]>;
4280
Scott Michel0d5eae02009-03-17 01:15:45 +00004281// DFNMS: - (a * b - c)
Scott Michel8b6b4202007-12-04 22:35:58 +00004282// - (a * b) + c => c - (a * b)
Scott Michel0d5eae02009-03-17 01:15:45 +00004283
4284class DFNMSInst<dag OOL, dag IOL, list<dag> pattern>:
4285 RRForm<0b01111010110, OOL, IOL, "dfnms\t$rT, $rA, $rB",
4286 DPrecFP, pattern>,
Scott Michel8b6b4202007-12-04 22:35:58 +00004287 RegConstraint<"$rC = $rT">,
4288 NoEncode<"$rC">;
4289
Scott Michel0d5eae02009-03-17 01:15:45 +00004290class DFNMSVecInst<list<dag> pattern>:
4291 DFNMSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4292 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004293
Scott Michel0d5eae02009-03-17 01:15:45 +00004294class DFNMSRegInst<list<dag> pattern>:
4295 DFNMSInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4296 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004297
Scott Michel0d5eae02009-03-17 01:15:45 +00004298multiclass DFMultiplySubtract
4299{
4300 def v2f64 : DFNMSVecInst<[(set (v2f64 VECREG:$rT),
4301 (fsub (v2f64 VECREG:$rC),
4302 (fmul (v2f64 VECREG:$rA),
4303 (v2f64 VECREG:$rB))))]>;
4304
4305 def f64 : DFNMSRegInst<[(set R64FP:$rT,
4306 (fsub R64FP:$rC,
4307 (fmul R64FP:$rA, R64FP:$rB)))]>;
4308}
4309
4310defm DFNMS : DFMultiplySubtract;
Scott Michel8b6b4202007-12-04 22:35:58 +00004311
4312// - (a * b + c)
4313// - (a * b) - c
4314def FNMAf64 :
4315 RRForm<0b11111010110, (outs R64FP:$rT),
4316 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4317 "dfnma\t$rT, $rA, $rB", DPrecFP,
4318 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4319 RegConstraint<"$rC = $rT">,
4320 NoEncode<"$rC">;
4321
4322def FNMAv2f64 :
4323 RRForm<0b11111010110, (outs VECREG:$rT),
4324 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4325 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004326 [(set (v2f64 VECREG:$rT),
4327 (fneg (fadd (v2f64 VECREG:$rC),
4328 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004329 (v2f64 VECREG:$rB)))))]>,
4330 RegConstraint<"$rC = $rT">,
4331 NoEncode<"$rC">;
4332
4333//===----------------------------------------------------------------------==//
4334// Floating point negation and absolute value
4335//===----------------------------------------------------------------------==//
4336
4337def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michele13d8392009-03-17 16:45:16 +00004338 (XORfnegvec (v4f32 VECREG:$rA),
4339 (v4f32 (ILHUv4i32 0x8000)))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004340
4341def : Pat<(fneg R32FP:$rA),
Scott Michele13d8392009-03-17 16:45:16 +00004342 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004343
4344// Floating point absolute value
Scott Michel0d5eae02009-03-17 01:15:45 +00004345// Note: f64 fabs is custom-selected.
Scott Michel8b6b4202007-12-04 22:35:58 +00004346
4347def : Pat<(fabs R32FP:$rA),
4348 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4349
4350def : Pat<(fabs (v4f32 VECREG:$rA)),
4351 (ANDfabsvec (v4f32 VECREG:$rA),
Scott Michel0d5eae02009-03-17 01:15:45 +00004352 (IOHLv4i32 (ILHUv4i32 0x7fff), 0xffff))>;
pingbak2f387e82009-01-26 03:31:40 +00004353
Scott Michel8b6b4202007-12-04 22:35:58 +00004354//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004355// Hint for branch instructions:
4356//===----------------------------------------------------------------------===//
4357
4358/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4359
4360//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004361// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4362// in the odd pipeline)
4363//===----------------------------------------------------------------------===//
4364
Scott Michel97872d32008-02-23 18:41:37 +00004365def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004366 let Pattern = [];
4367
4368 let Inst{0-10} = 0b10000000010;
4369 let Inst{11-17} = 0;
4370 let Inst{18-24} = 0;
4371 let Inst{25-31} = 0;
4372}
4373
Scott Michel97872d32008-02-23 18:41:37 +00004374def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004375 let Pattern = [];
4376
4377 let Inst{0-10} = 0b10000000000;
4378 let Inst{11-17} = 0;
4379 let Inst{18-24} = 0;
4380 let Inst{25-31} = 0;
4381}
4382
4383//===----------------------------------------------------------------------===//
4384// Bit conversions (type conversions between vector/packed types)
Scott Michel34712c32009-03-16 18:47:25 +00004385// NOTE: Promotions are handled using the XS* instructions.
Scott Michel8b6b4202007-12-04 22:35:58 +00004386//===----------------------------------------------------------------------===//
4387def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4388def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4389def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4390def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4391def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4392
4393def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4394def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4395def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4396def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4397def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4398
4399def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4400def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4401def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4402def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4403def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4404
4405def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4406def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4407def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4408def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4409def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4410
4411def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4412def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4413def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4414def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4415def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4416
4417def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4418def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4419def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4420def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
Chris Lattner05c96242010-03-28 08:36:45 +00004421def : Pat<(v2f64 (bitconvert (v4f32 VECREG:$src))), (v2f64 VECREG:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004422
Scott Michel34712c32009-03-16 18:47:25 +00004423def : Pat<(i128 (bitconvert (v16i8 VECREG:$src))),
4424 (ORi128_vec VECREG:$src)>;
4425def : Pat<(i128 (bitconvert (v8i16 VECREG:$src))),
4426 (ORi128_vec VECREG:$src)>;
4427def : Pat<(i128 (bitconvert (v4i32 VECREG:$src))),
4428 (ORi128_vec VECREG:$src)>;
4429def : Pat<(i128 (bitconvert (v2i64 VECREG:$src))),
4430 (ORi128_vec VECREG:$src)>;
4431def : Pat<(i128 (bitconvert (v4f32 VECREG:$src))),
4432 (ORi128_vec VECREG:$src)>;
4433def : Pat<(i128 (bitconvert (v2f64 VECREG:$src))),
4434 (ORi128_vec VECREG:$src)>;
4435
4436def : Pat<(v16i8 (bitconvert (i128 GPRC:$src))),
4437 (v16i8 (ORvec_i128 GPRC:$src))>;
4438def : Pat<(v8i16 (bitconvert (i128 GPRC:$src))),
4439 (v8i16 (ORvec_i128 GPRC:$src))>;
4440def : Pat<(v4i32 (bitconvert (i128 GPRC:$src))),
4441 (v4i32 (ORvec_i128 GPRC:$src))>;
4442def : Pat<(v2i64 (bitconvert (i128 GPRC:$src))),
4443 (v2i64 (ORvec_i128 GPRC:$src))>;
4444def : Pat<(v4f32 (bitconvert (i128 GPRC:$src))),
4445 (v4f32 (ORvec_i128 GPRC:$src))>;
4446def : Pat<(v2f64 (bitconvert (i128 GPRC:$src))),
4447 (v2f64 (ORvec_i128 GPRC:$src))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004448
4449//===----------------------------------------------------------------------===//
4450// Instruction patterns:
4451//===----------------------------------------------------------------------===//
4452
4453// General 32-bit constants:
4454def : Pat<(i32 imm:$imm),
4455 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4456
4457// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004458def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004459 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4460
4461// General constant 32-bit vectors
4462def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004463 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4464 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004465
Scott Michel438be252007-12-17 22:32:34 +00004466// 8-bit constants
4467def : Pat<(i8 imm:$imm),
4468 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004469
4470//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004471// Zero/Any/Sign extensions
4472//===----------------------------------------------------------------------===//
4473
Scott Michel8b6b4202007-12-04 22:35:58 +00004474// sext 8->32: Sign extend bytes to words
4475def : Pat<(sext_inreg R32C:$rSrc, i8),
4476 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4477
Scott Michel438be252007-12-17 22:32:34 +00004478def : Pat<(i32 (sext R8C:$rSrc)),
4479 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4480
Scott Michel2ef773a2009-01-06 03:36:14 +00004481// sext 8->64: Sign extend bytes to double word
4482def : Pat<(sext_inreg R64C:$rSrc, i8),
4483 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4484
4485def : Pat<(i64 (sext R8C:$rSrc)),
4486 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4487
Scott Michel438be252007-12-17 22:32:34 +00004488// zext 8->16: Zero extend bytes to halfwords
4489def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004490 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004491
Scott Michel438be252007-12-17 22:32:34 +00004492// zext 8->32: Zero extend bytes to words
4493def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004494 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004495
Scott Michel2ef773a2009-01-06 03:36:14 +00004496// zext 8->64: Zero extend bytes to double words
4497def : Pat<(i64 (zext R8C:$rSrc)),
4498 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4499 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4500 0x4),
4501 (ILv4i32 0x0),
4502 (FSMBIv4i32 0x0f0f)))>;
4503
4504// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004505def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004506 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004507
Scott Michel2ef773a2009-01-06 03:36:14 +00004508// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004509def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004510 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004511
Scott Michel2ef773a2009-01-06 03:36:14 +00004512// sext 16->64: Sign extend halfword to double word
4513def : Pat<(sext_inreg R64C:$rSrc, i16),
4514 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4515
4516def : Pat<(sext R16C:$rSrc),
4517 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4518
Scott Michel97872d32008-02-23 18:41:37 +00004519// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004520def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004521 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004522
4523def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004524 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004525
4526def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004527 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004528
4529def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004530 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004531
4532// anyext 16->32: Extend 16->32 bits, irrespective of sign
4533def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004534 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004535
4536//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004537// Truncates:
4538// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4539// above are custom lowered.
4540//===----------------------------------------------------------------------===//
4541
4542def : Pat<(i8 (trunc GPRC:$src)),
4543 (ORi8_v16i8
4544 (SHUFBgprc GPRC:$src, GPRC:$src,
4545 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4546
4547def : Pat<(i8 (trunc R64C:$src)),
4548 (ORi8_v16i8
4549 (SHUFBv2i64_m32
4550 (ORv2i64_i64 R64C:$src),
4551 (ORv2i64_i64 R64C:$src),
4552 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4553
4554def : Pat<(i8 (trunc R32C:$src)),
4555 (ORi8_v16i8
4556 (SHUFBv4i32_m32
4557 (ORv4i32_i32 R32C:$src),
4558 (ORv4i32_i32 R32C:$src),
4559 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4560
4561def : Pat<(i8 (trunc R16C:$src)),
4562 (ORi8_v16i8
4563 (SHUFBv4i32_m32
4564 (ORv8i16_i16 R16C:$src),
4565 (ORv8i16_i16 R16C:$src),
4566 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4567
4568def : Pat<(i16 (trunc GPRC:$src)),
4569 (ORi16_v8i16
4570 (SHUFBgprc GPRC:$src, GPRC:$src,
4571 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4572
4573def : Pat<(i16 (trunc R64C:$src)),
4574 (ORi16_v8i16
4575 (SHUFBv2i64_m32
4576 (ORv2i64_i64 R64C:$src),
4577 (ORv2i64_i64 R64C:$src),
4578 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4579
4580def : Pat<(i16 (trunc R32C:$src)),
4581 (ORi16_v8i16
4582 (SHUFBv4i32_m32
4583 (ORv4i32_i32 R32C:$src),
4584 (ORv4i32_i32 R32C:$src),
4585 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4586
4587def : Pat<(i32 (trunc GPRC:$src)),
4588 (ORi32_v4i32
4589 (SHUFBgprc GPRC:$src, GPRC:$src,
4590 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4591
4592def : Pat<(i32 (trunc R64C:$src)),
4593 (ORi32_v4i32
4594 (SHUFBv2i64_m32
4595 (ORv2i64_i64 R64C:$src),
4596 (ORv2i64_i64 R64C:$src),
4597 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4598
4599//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004600// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004601// low parts in order to load them into a register.
4602//===----------------------------------------------------------------------===//
4603
Scott Michelf9f42e62008-01-29 02:16:57 +00004604def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4605def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4606def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4607def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4608
4609def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4610 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004611 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004612
Scott Michelf9f42e62008-01-29 02:16:57 +00004613def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4614 (SPUlo texternalsym:$in, 0)),
4615 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4616
4617def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4618 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004619 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004620
Scott Michelf9f42e62008-01-29 02:16:57 +00004621def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4622 (SPUlo tconstpool:$in, 0)),
4623 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4624
4625def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4626 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4627
4628def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4629 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4630
4631def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4632 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4633
4634def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4635 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004636
Scott Michel34712c32009-03-16 18:47:25 +00004637// Intrinsics:
Scott Michel8b6b4202007-12-04 22:35:58 +00004638include "CellSDKIntrinsics.td"
Scott Michel4d07fb72008-12-30 23:28:25 +00004639// Various math operator instruction sequences
4640include "SPUMathInstr.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004641// 64-bit "instructions"/support
4642include "SPU64InstrInfo.td"
Scott Michel2ef773a2009-01-06 03:36:14 +00004643// 128-bit "instructions"/support
4644include "SPU128InstrInfo.td"