blob: 8db2fa7fced3ef24d1fbb96dbc6ead4b6645465e [file] [log] [blame]
Scott Michel8b6b4202007-12-04 22:35:58 +00001//==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
Scott Michel06eabde2008-12-27 04:51:36 +00002//
Scott Michel8b6b4202007-12-04 22:35:58 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michel06eabde2008-12-27 04:51:36 +00007//
Scott Michel8b6b4202007-12-04 22:35:58 +00008//===----------------------------------------------------------------------===//
9// Cell SPU Instructions:
10//===----------------------------------------------------------------------===//
11
12//===----------------------------------------------------------------------===//
13// TODO Items (not urgent today, but would be nice, low priority)
14//
15// ANDBI, ORBI: SPU constructs a 4-byte constant for these instructions by
16// concatenating the byte argument b as "bbbb". Could recognize this bit pattern
17// in 16-bit and 32-bit constants and reduce instruction count.
18//===----------------------------------------------------------------------===//
19
20//===----------------------------------------------------------------------===//
21// Pseudo instructions:
22//===----------------------------------------------------------------------===//
23
24let hasCtrlDep = 1, Defs = [R1], Uses = [R1] in {
Scott Michelbc5fbc12008-04-30 00:30:08 +000025 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000026 "${:comment} ADJCALLSTACKDOWN",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000027 [(callseq_start timm:$amt)]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +000028 def ADJCALLSTACKUP : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000029 "${:comment} ADJCALLSTACKUP",
Chris Lattnerfe5d4022008-10-11 22:08:30 +000030 [(callseq_end timm:$amt)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +000031}
32
33//===----------------------------------------------------------------------===//
34// DWARF debugging Pseudo Instructions
35//===----------------------------------------------------------------------===//
36
37def DWARF_LOC : Pseudo<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
38 "${:comment} .loc $file, $line, $col",
39 [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
40 (i32 imm:$file))]>;
41
42//===----------------------------------------------------------------------===//
43// Loads:
44// NB: The ordering is actually important, since the instruction selection
45// will try each of the instructions in sequence, i.e., the D-form first with
46// the 10-bit displacement, then the A-form with the 16 bit displacement, and
47// finally the X-form with the register-register.
48//===----------------------------------------------------------------------===//
49
Dan Gohman5574cc72008-12-03 18:15:48 +000050let canFoldAsLoad = 1 in {
Scott Michelf9f42e62008-01-29 02:16:57 +000051 class LoadDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +000052 : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000053 "lqd\t$rT, $src",
54 LoadStore,
55 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
56 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000057
Scott Michelf9f42e62008-01-29 02:16:57 +000058 class LoadDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +000059 : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000060 "lqd\t$rT, $src",
61 LoadStore,
62 [(set rclass:$rT, (load dform_addr:$src))]>
63 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000064
Scott Michelf9f42e62008-01-29 02:16:57 +000065 multiclass LoadDForms
66 {
67 def v16i8: LoadDFormVec<v16i8>;
68 def v8i16: LoadDFormVec<v8i16>;
69 def v4i32: LoadDFormVec<v4i32>;
70 def v2i64: LoadDFormVec<v2i64>;
71 def v4f32: LoadDFormVec<v4f32>;
72 def v2f64: LoadDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000073
Scott Michel70741542009-01-06 23:10:38 +000074 def v2i32: LoadDFormVec<v2i32>;
75
Scott Michelf9f42e62008-01-29 02:16:57 +000076 def r128: LoadDForm<GPRC>;
77 def r64: LoadDForm<R64C>;
78 def r32: LoadDForm<R32C>;
79 def f32: LoadDForm<R32FP>;
80 def f64: LoadDForm<R64FP>;
81 def r16: LoadDForm<R16C>;
82 def r8: LoadDForm<R8C>;
83 }
Scott Michel8b6b4202007-12-04 22:35:58 +000084
Scott Michelf9f42e62008-01-29 02:16:57 +000085 class LoadAFormVec<ValueType vectype>
86 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
87 "lqa\t$rT, $src",
88 LoadStore,
89 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
90 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000091
Scott Michelf9f42e62008-01-29 02:16:57 +000092 class LoadAForm<RegisterClass rclass>
93 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
94 "lqa\t$rT, $src",
95 LoadStore,
96 [(set rclass:$rT, (load aform_addr:$src))]>
97 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000098
Scott Michelf9f42e62008-01-29 02:16:57 +000099 multiclass LoadAForms
100 {
101 def v16i8: LoadAFormVec<v16i8>;
102 def v8i16: LoadAFormVec<v8i16>;
103 def v4i32: LoadAFormVec<v4i32>;
104 def v2i64: LoadAFormVec<v2i64>;
105 def v4f32: LoadAFormVec<v4f32>;
106 def v2f64: LoadAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000107
Scott Michel70741542009-01-06 23:10:38 +0000108 def v2i32: LoadAFormVec<v2i32>;
109
Scott Michelf9f42e62008-01-29 02:16:57 +0000110 def r128: LoadAForm<GPRC>;
111 def r64: LoadAForm<R64C>;
112 def r32: LoadAForm<R32C>;
113 def f32: LoadAForm<R32FP>;
114 def f64: LoadAForm<R64FP>;
115 def r16: LoadAForm<R16C>;
116 def r8: LoadAForm<R8C>;
117 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000118
Scott Michelf9f42e62008-01-29 02:16:57 +0000119 class LoadXFormVec<ValueType vectype>
120 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
121 "lqx\t$rT, $src",
122 LoadStore,
123 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
124 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000125
Scott Michelf9f42e62008-01-29 02:16:57 +0000126 class LoadXForm<RegisterClass rclass>
127 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
128 "lqx\t$rT, $src",
129 LoadStore,
130 [(set rclass:$rT, (load xform_addr:$src))]>
131 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000132
Scott Michelf9f42e62008-01-29 02:16:57 +0000133 multiclass LoadXForms
134 {
135 def v16i8: LoadXFormVec<v16i8>;
136 def v8i16: LoadXFormVec<v8i16>;
137 def v4i32: LoadXFormVec<v4i32>;
138 def v2i64: LoadXFormVec<v2i64>;
139 def v4f32: LoadXFormVec<v4f32>;
140 def v2f64: LoadXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000141
Scott Michel70741542009-01-06 23:10:38 +0000142 def v2i32: LoadXFormVec<v2i32>;
143
Scott Michelf9f42e62008-01-29 02:16:57 +0000144 def r128: LoadXForm<GPRC>;
145 def r64: LoadXForm<R64C>;
146 def r32: LoadXForm<R32C>;
147 def f32: LoadXForm<R32FP>;
148 def f64: LoadXForm<R64FP>;
149 def r16: LoadXForm<R16C>;
150 def r8: LoadXForm<R8C>;
151 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000152
Scott Michelf9f42e62008-01-29 02:16:57 +0000153 defm LQA : LoadAForms;
154 defm LQD : LoadDForms;
155 defm LQX : LoadXForms;
Scott Michel438be252007-12-17 22:32:34 +0000156
Scott Michel8b6b4202007-12-04 22:35:58 +0000157/* Load quadword, PC relative: Not much use at this point in time.
Scott Michelf9f42e62008-01-29 02:16:57 +0000158 Might be of use later for relocatable code. It's effectively the
159 same as LQA, but uses PC-relative addressing.
Scott Michel8b6b4202007-12-04 22:35:58 +0000160 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
161 "lqr\t$rT, $disp", LoadStore,
162 [(set VECREG:$rT, (load iaddr:$disp))]>;
163 */
Scott Michel8b6b4202007-12-04 22:35:58 +0000164}
165
166//===----------------------------------------------------------------------===//
167// Stores:
168//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +0000169class StoreDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +0000170 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000171 "stqd\t$rT, $src",
172 LoadStore,
173 [(store (vectype VECREG:$rT), dform_addr:$src)]>
174{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000175
Scott Michelf9f42e62008-01-29 02:16:57 +0000176class StoreDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +0000177 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000178 "stqd\t$rT, $src",
179 LoadStore,
180 [(store rclass:$rT, dform_addr:$src)]>
181{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000182
Scott Michelf9f42e62008-01-29 02:16:57 +0000183multiclass StoreDForms
184{
185 def v16i8: StoreDFormVec<v16i8>;
186 def v8i16: StoreDFormVec<v8i16>;
187 def v4i32: StoreDFormVec<v4i32>;
188 def v2i64: StoreDFormVec<v2i64>;
189 def v4f32: StoreDFormVec<v4f32>;
190 def v2f64: StoreDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000191
Scott Michel70741542009-01-06 23:10:38 +0000192 def v2i32: StoreDFormVec<v2i32>;
193
Scott Michelf9f42e62008-01-29 02:16:57 +0000194 def r128: StoreDForm<GPRC>;
195 def r64: StoreDForm<R64C>;
196 def r32: StoreDForm<R32C>;
197 def f32: StoreDForm<R32FP>;
198 def f64: StoreDForm<R64FP>;
199 def r16: StoreDForm<R16C>;
200 def r8: StoreDForm<R8C>;
201}
Scott Michel8b6b4202007-12-04 22:35:58 +0000202
Scott Michelf9f42e62008-01-29 02:16:57 +0000203class StoreAFormVec<ValueType vectype>
204 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000205 "stqa\t$rT, $src",
206 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000207 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000208
Scott Michelf9f42e62008-01-29 02:16:57 +0000209class StoreAForm<RegisterClass rclass>
210 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000211 "stqa\t$rT, $src",
212 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000213 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000214
Scott Michelf9f42e62008-01-29 02:16:57 +0000215multiclass StoreAForms
216{
217 def v16i8: StoreAFormVec<v16i8>;
218 def v8i16: StoreAFormVec<v8i16>;
219 def v4i32: StoreAFormVec<v4i32>;
220 def v2i64: StoreAFormVec<v2i64>;
221 def v4f32: StoreAFormVec<v4f32>;
222 def v2f64: StoreAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000223
Scott Michel70741542009-01-06 23:10:38 +0000224 def v2i32: StoreAFormVec<v2i32>;
225
Scott Michelf9f42e62008-01-29 02:16:57 +0000226 def r128: StoreAForm<GPRC>;
227 def r64: StoreAForm<R64C>;
228 def r32: StoreAForm<R32C>;
229 def f32: StoreAForm<R32FP>;
230 def f64: StoreAForm<R64FP>;
231 def r16: StoreAForm<R16C>;
232 def r8: StoreAForm<R8C>;
233}
Scott Michel8b6b4202007-12-04 22:35:58 +0000234
Scott Michelf9f42e62008-01-29 02:16:57 +0000235class StoreXFormVec<ValueType vectype>
236 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000237 "stqx\t$rT, $src",
238 LoadStore,
239 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000240{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000241
Scott Michelf9f42e62008-01-29 02:16:57 +0000242class StoreXForm<RegisterClass rclass>
243 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000244 "stqx\t$rT, $src",
245 LoadStore,
246 [(store rclass:$rT, xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000247{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000248
Scott Michelf9f42e62008-01-29 02:16:57 +0000249multiclass StoreXForms
250{
251 def v16i8: StoreXFormVec<v16i8>;
252 def v8i16: StoreXFormVec<v8i16>;
253 def v4i32: StoreXFormVec<v4i32>;
254 def v2i64: StoreXFormVec<v2i64>;
255 def v4f32: StoreXFormVec<v4f32>;
256 def v2f64: StoreXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000257
Scott Michel70741542009-01-06 23:10:38 +0000258 def v2i32: StoreXFormVec<v2i32>;
259
Scott Michelf9f42e62008-01-29 02:16:57 +0000260 def r128: StoreXForm<GPRC>;
261 def r64: StoreXForm<R64C>;
262 def r32: StoreXForm<R32C>;
263 def f32: StoreXForm<R32FP>;
264 def f64: StoreXForm<R64FP>;
265 def r16: StoreXForm<R16C>;
266 def r8: StoreXForm<R8C>;
267}
Scott Michel8b6b4202007-12-04 22:35:58 +0000268
Scott Michelf9f42e62008-01-29 02:16:57 +0000269defm STQD : StoreDForms;
270defm STQA : StoreAForms;
271defm STQX : StoreXForms;
Scott Michel8b6b4202007-12-04 22:35:58 +0000272
273/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michelf9f42e62008-01-29 02:16:57 +0000274 be useful for relocatable code.
Chris Lattneref8d6082008-01-06 06:44:58 +0000275def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
276 "stqr\t$rT, $disp", LoadStore,
277 [(store VECREG:$rT, iaddr:$disp)]>;
278*/
Scott Michel8b6b4202007-12-04 22:35:58 +0000279
280//===----------------------------------------------------------------------===//
281// Generate Controls for Insertion:
282//===----------------------------------------------------------------------===//
283
Scott Michel06eabde2008-12-27 04:51:36 +0000284def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000285 "cbd\t$rT, $src", ShuffleOp,
286 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000287
Scott Michel0718cd82008-12-01 17:56:02 +0000288def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000289 "cbx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000290 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000291
Scott Michel06eabde2008-12-27 04:51:36 +0000292def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000293 "chd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000294 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000295
Scott Michel0718cd82008-12-01 17:56:02 +0000296def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000297 "chx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000298 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000299
Scott Michel06eabde2008-12-27 04:51:36 +0000300def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000301 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000302 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000303
Scott Michel0718cd82008-12-01 17:56:02 +0000304def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000305 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000306 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000307
Scott Michel06eabde2008-12-27 04:51:36 +0000308def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000309 "cwd\t$rT, $src", ShuffleOp,
310 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
311
312def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000313 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000314 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000315
Scott Michel06eabde2008-12-27 04:51:36 +0000316def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000317 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000318 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000319
Scott Michel0718cd82008-12-01 17:56:02 +0000320def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000321 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000322 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000323
Scott Michel06eabde2008-12-27 04:51:36 +0000324def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000325 "cdd\t$rT, $src", ShuffleOp,
326 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
327
328def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000329 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000330 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000331
Scott Michel8b6b4202007-12-04 22:35:58 +0000332//===----------------------------------------------------------------------===//
333// Constant formation:
334//===----------------------------------------------------------------------===//
335
336def ILHv8i16:
337 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
338 "ilh\t$rT, $val", ImmLoad,
339 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
340
341def ILHr16:
342 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
343 "ilh\t$rT, $val", ImmLoad,
344 [(set R16C:$rT, immSExt16:$val)]>;
345
Scott Michel438be252007-12-17 22:32:34 +0000346// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
347// the right constant")
348def ILHr8:
349 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
350 "ilh\t$rT, $val", ImmLoad,
351 [(set R8C:$rT, immSExt8:$val)]>;
352
Scott Michel8b6b4202007-12-04 22:35:58 +0000353// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000354
Scott Michel6baba072008-03-05 23:02:02 +0000355class ILInst<dag OOL, dag IOL, list<dag> pattern>:
356 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
357 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000358
Scott Michel6baba072008-03-05 23:02:02 +0000359class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
360 ILInst<(outs VECREG:$rT), (ins immtype:$val),
361 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000362
Scott Michel6baba072008-03-05 23:02:02 +0000363class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
364 ILInst<(outs rclass:$rT), (ins immtype:$val),
365 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000366
Scott Michel6baba072008-03-05 23:02:02 +0000367multiclass ImmediateLoad
368{
369 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
370 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000371
Scott Michel6baba072008-03-05 23:02:02 +0000372 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000373
Scott Michel6baba072008-03-05 23:02:02 +0000374 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
375 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
376 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
377 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
378}
Scott Michel8b6b4202007-12-04 22:35:58 +0000379
Scott Michel6baba072008-03-05 23:02:02 +0000380defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000381
Scott Michel6baba072008-03-05 23:02:02 +0000382class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
383 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
384 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000385
Scott Michel6baba072008-03-05 23:02:02 +0000386class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
387 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
388 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
389
390class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
391 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
392 [(set rclass:$rT, xform:$val)]>;
393
394multiclass ImmLoadHalfwordUpper
395{
396 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000397 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000398
399 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000400 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000401
402 // Loads the high portion of an address
403 def hi: ILHURegInst<R32C, symbolHi, hi16>;
404
405 // Used in custom lowering constant SFP loads:
406 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
407}
408
409defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000410
411// Immediate load address (can also be used to load 18-bit unsigned constants,
412// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000413
Scott Michel97872d32008-02-23 18:41:37 +0000414class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
415 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
416 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000417
Scott Michel6baba072008-03-05 23:02:02 +0000418class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
419 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
420 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
421
422class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
423 ILAInst<(outs rclass:$rT), (ins immtype:$val),
424 [(set rclass:$rT, xform:$val)]>;
425
Scott Michel97872d32008-02-23 18:41:37 +0000426multiclass ImmLoadAddress
427{
Scott Michel6baba072008-03-05 23:02:02 +0000428 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
429 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000430
Scott Michel6baba072008-03-05 23:02:02 +0000431 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
432 def r32: ILARegInst<R32C, u18imm, imm18>;
433 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
434 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000435
Scott Michel06eabde2008-12-27 04:51:36 +0000436 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michel6baba072008-03-05 23:02:02 +0000437 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000438
Scott Michel97872d32008-02-23 18:41:37 +0000439 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
440 [/* no pattern */]>;
441}
442
443defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000444
445// Immediate OR, Halfword Lower: The "other" part of loading large constants
446// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
447// Note that these are really two operand instructions, but they're encoded
448// as three operands with the first two arguments tied-to each other.
449
Scott Michel6baba072008-03-05 23:02:02 +0000450class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
451 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
452 ImmLoad, pattern>,
453 RegConstraint<"$rS = $rT">,
454 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000455
Scott Michel6baba072008-03-05 23:02:02 +0000456class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
457 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
458 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000459
Scott Michel6baba072008-03-05 23:02:02 +0000460class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
461 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
462 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000463
Scott Michel6baba072008-03-05 23:02:02 +0000464multiclass ImmOrHalfwordLower
465{
466 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000467 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000468
469 def r32: IOHLRegInst<R32C, i32imm>;
470 def f32: IOHLRegInst<R32FP, f32imm>;
471
472 def lo: IOHLRegInst<R32C, symbolLo>;
473}
474
475defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000476
Scott Michel8b6b4202007-12-04 22:35:58 +0000477// Form select mask for bytes using immediate, used in conjunction with the
478// SELB instruction:
479
Scott Michel6baba072008-03-05 23:02:02 +0000480class FSMBIVec<ValueType vectype>:
481 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
482 "fsmbi\t$rT, $val",
483 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000484 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000485
Scott Michel97872d32008-02-23 18:41:37 +0000486multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000487{
488 def v16i8: FSMBIVec<v16i8>;
489 def v8i16: FSMBIVec<v8i16>;
490 def v4i32: FSMBIVec<v4i32>;
491 def v2i64: FSMBIVec<v2i64>;
492}
Scott Michel8b6b4202007-12-04 22:35:58 +0000493
Scott Michel97872d32008-02-23 18:41:37 +0000494defm FSMBI : FormSelectMaskBytesImm;
495
496// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michel06eabde2008-12-27 04:51:36 +0000497class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
498 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
499 pattern>;
500
501class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
502 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
503 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
504
505class FSMBVecInst<ValueType vectype>:
506 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
507 [(set (vectype VECREG:$rT),
508 (SPUselmask (vectype VECREG:$rA)))]>;
509
510multiclass FormSelectMaskBits {
511 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
512 def v16i8: FSMBVecInst<v16i8>;
513}
514
515defm FSMB: FormSelectMaskBits;
Scott Michel97872d32008-02-23 18:41:37 +0000516
517// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
518// only 8-bits wide (even though it's input as 16-bits here)
Scott Michel06eabde2008-12-27 04:51:36 +0000519
520class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
521 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
522 pattern>;
523
524class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
525 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
526 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
527
528class FSMHVecInst<ValueType vectype>:
529 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
530 [(set (vectype VECREG:$rT),
531 (SPUselmask (vectype VECREG:$rA)))]>;
532
533multiclass FormSelectMaskHalfword {
534 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
535 def v8i16: FSMHVecInst<v8i16>;
536}
537
538defm FSMH: FormSelectMaskHalfword;
Scott Michel97872d32008-02-23 18:41:37 +0000539
540// fsm: Form select mask for words. Like the other fsm* instructions,
541// only the lower 4 bits of $rA are significant.
Scott Michel06eabde2008-12-27 04:51:36 +0000542
543class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
544 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
545 pattern>;
546
547class FSMRegInst<ValueType vectype, RegisterClass rclass>:
548 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
549 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
550
551class FSMVecInst<ValueType vectype>:
552 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
553 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel67224b22008-06-02 22:18:03 +0000554
555multiclass FormSelectMaskWord {
Scott Michel06eabde2008-12-27 04:51:36 +0000556 def v4i32: FSMVecInst<v4i32>;
557
558 def r32 : FSMRegInst<v4i32, R32C>;
559 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000560}
561
562defm FSM : FormSelectMaskWord;
563
564// Special case when used for i64 math operations
565multiclass FormSelectMaskWord64 {
Scott Michel06eabde2008-12-27 04:51:36 +0000566 def r32 : FSMRegInst<v2i64, R32C>;
567 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000568}
569
570defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000571
572//===----------------------------------------------------------------------===//
573// Integer and Logical Operations:
574//===----------------------------------------------------------------------===//
575
576def AHv8i16:
577 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
578 "ah\t$rT, $rA, $rB", IntegerOp,
579 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
580
581def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
582 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
583
Scott Michel8b6b4202007-12-04 22:35:58 +0000584def AHr16:
585 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
586 "ah\t$rT, $rA, $rB", IntegerOp,
587 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
588
589def AHIvec:
590 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
591 "ahi\t$rT, $rA, $val", IntegerOp,
592 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
593 v8i16SExt10Imm:$val))]>;
594
Scott Michel97872d32008-02-23 18:41:37 +0000595def AHIr16:
596 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
597 "ahi\t$rT, $rA, $val", IntegerOp,
Scott Michel4d07fb72008-12-30 23:28:25 +0000598 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
599
600// v4i32, i32 add instruction:
Scott Michel8b6b4202007-12-04 22:35:58 +0000601
Scott Michelae5cbf52008-12-29 03:23:36 +0000602class AInst<dag OOL, dag IOL, list<dag> pattern>:
603 RRForm<0b00000011000, OOL, IOL,
604 "a\t$rT, $rA, $rB", IntegerOp,
605 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000606
Scott Michelae5cbf52008-12-29 03:23:36 +0000607class AVecInst<ValueType vectype>:
608 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
609 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
610 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000611
Scott Michelae5cbf52008-12-29 03:23:36 +0000612class ARegInst<RegisterClass rclass>:
613 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
614 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
615
616multiclass AddInstruction {
617 def v4i32: AVecInst<v4i32>;
618 def v16i8: AVecInst<v16i8>;
619
620 def r32: ARegInst<R32C>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000621}
Scott Michel8b6b4202007-12-04 22:35:58 +0000622
Scott Michelae5cbf52008-12-29 03:23:36 +0000623defm A : AddInstruction;
Scott Michel438be252007-12-17 22:32:34 +0000624
Scott Michel4d07fb72008-12-30 23:28:25 +0000625class AIInst<dag OOL, dag IOL, list<dag> pattern>:
626 RI10Form<0b00111000, OOL, IOL,
627 "ai\t$rT, $rA, $val", IntegerOp,
628 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000629
Scott Michel4d07fb72008-12-30 23:28:25 +0000630class AIVecInst<ValueType vectype, PatLeaf immpred>:
631 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
632 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
633
634class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
635 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
636 [/* no pattern */]>;
637
638class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
639 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
640 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
641
642// This is used to add epsilons to floating point numbers in the f32 fdiv code:
643class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
644 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
645 [/* no pattern */]>;
646
647multiclass AddImmediate {
648 def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
649
650 def r32: AIRegInst<R32C, i32ImmSExt10>;
651
652 def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
653 def f32: AIFPInst<R32FP, i32ImmSExt10>;
654}
655
656defm AI : AddImmediate;
Scott Michel8b6b4202007-12-04 22:35:58 +0000657
Scott Michel438be252007-12-17 22:32:34 +0000658def SFHvec:
659 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
660 "sfh\t$rT, $rA, $rB", IntegerOp,
661 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
662 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000663
Scott Michel438be252007-12-17 22:32:34 +0000664def SFHr16:
665 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
666 "sfh\t$rT, $rA, $rB", IntegerOp,
667 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000668
669def SFHIvec:
670 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
671 "sfhi\t$rT, $rA, $val", IntegerOp,
672 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
673 (v8i16 VECREG:$rA)))]>;
674
675def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
676 "sfhi\t$rT, $rA, $val", IntegerOp,
677 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
678
679def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
680 (ins VECREG:$rA, VECREG:$rB),
681 "sf\t$rT, $rA, $rB", IntegerOp,
682 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
683
684def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
685 "sf\t$rT, $rA, $rB", IntegerOp,
686 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
687
688def SFIvec:
689 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
690 "sfi\t$rT, $rA, $val", IntegerOp,
691 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
692 (v4i32 VECREG:$rA)))]>;
693
694def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
695 (ins R32C:$rA, s10imm_i32:$val),
696 "sfi\t$rT, $rA, $val", IntegerOp,
697 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
698
699// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000700class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
701 RRForm<0b00000010110, OOL, IOL,
702 "addx\t$rT, $rA, $rB",
703 IntegerOp, pattern>;
704
705class ADDXVecInst<ValueType vectype>:
706 ADDXInst<(outs VECREG:$rT),
707 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000708 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000709 RegConstraint<"$rCarry = $rT">,
710 NoEncode<"$rCarry">;
711
Scott Michel67224b22008-06-02 22:18:03 +0000712class ADDXRegInst<RegisterClass rclass>:
713 ADDXInst<(outs rclass:$rT),
714 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000715 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000716 RegConstraint<"$rCarry = $rT">,
717 NoEncode<"$rCarry">;
718
Scott Michel67224b22008-06-02 22:18:03 +0000719multiclass AddExtended {
720 def v2i64 : ADDXVecInst<v2i64>;
721 def v4i32 : ADDXVecInst<v4i32>;
722 def r64 : ADDXRegInst<R64C>;
723 def r32 : ADDXRegInst<R32C>;
724}
725
726defm ADDX : AddExtended;
727
728// CG: Generate carry for add
729class CGInst<dag OOL, dag IOL, list<dag> pattern>:
730 RRForm<0b01000011000, OOL, IOL,
731 "cg\t$rT, $rA, $rB",
732 IntegerOp, pattern>;
733
734class CGVecInst<ValueType vectype>:
735 CGInst<(outs VECREG:$rT),
736 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000737 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000738
739class CGRegInst<RegisterClass rclass>:
740 CGInst<(outs rclass:$rT),
741 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000742 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000743
744multiclass CarryGenerate {
745 def v2i64 : CGVecInst<v2i64>;
746 def v4i32 : CGVecInst<v4i32>;
747 def r64 : CGRegInst<R64C>;
748 def r32 : CGRegInst<R32C>;
749}
750
751defm CG : CarryGenerate;
752
753// SFX: Subract from, extended. This is used in conjunction with BG to subtract
754// with carry (borrow, in this case)
755class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
756 RRForm<0b10000010110, OOL, IOL,
757 "sfx\t$rT, $rA, $rB",
758 IntegerOp, pattern>;
759
760class SFXVecInst<ValueType vectype>:
761 SFXInst<(outs VECREG:$rT),
762 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000763 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000764 RegConstraint<"$rCarry = $rT">,
765 NoEncode<"$rCarry">;
766
Scott Michel67224b22008-06-02 22:18:03 +0000767class SFXRegInst<RegisterClass rclass>:
768 SFXInst<(outs rclass:$rT),
769 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000770 [/* no pattern */]>,
Scott Michel67224b22008-06-02 22:18:03 +0000771 RegConstraint<"$rCarry = $rT">,
772 NoEncode<"$rCarry">;
773
774multiclass SubtractExtended {
775 def v2i64 : SFXVecInst<v2i64>;
776 def v4i32 : SFXVecInst<v4i32>;
777 def r64 : SFXRegInst<R64C>;
778 def r32 : SFXRegInst<R32C>;
779}
780
781defm SFX : SubtractExtended;
782
Scott Michel8b6b4202007-12-04 22:35:58 +0000783// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000784class BGInst<dag OOL, dag IOL, list<dag> pattern>:
785 RRForm<0b01000010000, OOL, IOL,
786 "bg\t$rT, $rA, $rB",
787 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000788
Scott Michel67224b22008-06-02 22:18:03 +0000789class BGVecInst<ValueType vectype>:
790 BGInst<(outs VECREG:$rT),
791 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000792 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000793
794class BGRegInst<RegisterClass rclass>:
795 BGInst<(outs rclass:$rT),
796 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000797 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000798
799multiclass BorrowGenerate {
800 def v4i32 : BGVecInst<v4i32>;
801 def v2i64 : BGVecInst<v2i64>;
802 def r64 : BGRegInst<R64C>;
803 def r32 : BGRegInst<R32C>;
804}
805
806defm BG : BorrowGenerate;
807
808// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000809def BGXvec:
810 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000811 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000812 "bgx\t$rT, $rA, $rB", IntegerOp,
813 []>,
814 RegConstraint<"$rCarry = $rT">,
815 NoEncode<"$rCarry">;
816
817// Halfword multiply variants:
818// N.B: These can be used to build up larger quantities (16x16 -> 32)
819
820def MPYv8i16:
821 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
822 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000823 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000824
825def MPYr16:
826 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
827 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
828 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
829
Scott Michelae5cbf52008-12-29 03:23:36 +0000830// Unsigned 16-bit multiply:
831
832class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
833 RRForm<0b00110011110, OOL, IOL,
834 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
835 pattern>;
836
Scott Michel8b6b4202007-12-04 22:35:58 +0000837def MPYUv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000838 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000839 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000840
841def MPYUr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000842 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
843 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000844
845def MPYUr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000846 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000847 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000848
Scott Michelae5cbf52008-12-29 03:23:36 +0000849// mpyi: multiply 16 x s10imm -> 32 result.
850
851class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
852 RI10Form<0b00101110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000853 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000854 pattern>;
855
856def MPYIvec:
857 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
858 [(set (v8i16 VECREG:$rT),
859 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000860
861def MPYIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000862 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
863 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000864
865// mpyui: same issues as other multiplies, plus, this doesn't match a
866// pattern... but may be used during target DAG selection or lowering
Scott Michelae5cbf52008-12-29 03:23:36 +0000867
868class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
869 RI10Form<0b10101110, OOL, IOL,
870 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
871 pattern>;
872
Scott Michel8b6b4202007-12-04 22:35:58 +0000873def MPYUIvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000874 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
875 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000876
877def MPYUIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000878 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
879 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000880
881// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michelae5cbf52008-12-29 03:23:36 +0000882class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
883 RRRForm<0b0011, OOL, IOL,
884 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
885 pattern>;
886
Scott Michel750b93f2009-01-15 04:41:47 +0000887def MPYAv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000888 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
889 [(set (v4i32 VECREG:$rT),
890 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
891 (v8i16 VECREG:$rB)))),
892 (v4i32 VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000893
894def MPYAr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000895 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
896 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
897 R32C:$rC))]>;
898
899def MPYAr32_sext:
900 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
901 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
902 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000903
904def MPYAr32_sextinreg:
Scott Michelae5cbf52008-12-29 03:23:36 +0000905 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
906 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
907 (sext_inreg R32C:$rB, i16)),
908 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000909
910// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michelae5cbf52008-12-29 03:23:36 +0000911class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
912 RRForm<0b10100011110, OOL, IOL,
913 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
914 pattern>;
915
Scott Michel8b6b4202007-12-04 22:35:58 +0000916def MPYHv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000917 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000918 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000919
920def MPYHr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000921 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000922 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000923
924// mpys: multiply high and shift right (returns the top half of
925// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000926
Scott Michel4d07fb72008-12-30 23:28:25 +0000927class MPYSInst<dag OOL, dag IOL>:
928 RRForm<0b11100011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000929 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000930 [/* no pattern */]>;
931
Scott Michel750b93f2009-01-15 04:41:47 +0000932def MPYSv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000933 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
934
935def MPYSr16:
936 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000937
938// mpyhh: multiply high-high (returns the 32-bit result from multiplying
939// the top 16 bits of the $rA, $rB)
Scott Michel4d07fb72008-12-30 23:28:25 +0000940
941class MPYHHInst<dag OOL, dag IOL>:
942 RRForm<0b01100011110, OOL, IOL,
943 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
944 [/* no pattern */]>;
945
Scott Michel8b6b4202007-12-04 22:35:58 +0000946def MPYHHv8i16:
Scott Michel4d07fb72008-12-30 23:28:25 +0000947 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000948
949def MPYHHr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000950 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000951
952// mpyhha: Multiply high-high, add to $rT:
Scott Michel8b6b4202007-12-04 22:35:58 +0000953
Scott Michel4d07fb72008-12-30 23:28:25 +0000954class MPYHHAInst<dag OOL, dag IOL>:
955 RRForm<0b01100010110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000956 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000957 [/* no pattern */]>;
958
959def MPYHHAvec:
960 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
961
962def MPYHHAr32:
963 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000964
Scott Michel750b93f2009-01-15 04:41:47 +0000965// mpyhhu: Multiply high-high, unsigned, e.g.:
966//
967// +-------+-------+ +-------+-------+ +---------+
968// | a0 . a1 | x | b0 . b1 | = | a0 x b0 |
969// +-------+-------+ +-------+-------+ +---------+
970//
971// where a0, b0 are the upper 16 bits of the 32-bit word
Scott Michel8b6b4202007-12-04 22:35:58 +0000972
Scott Michel4d07fb72008-12-30 23:28:25 +0000973class MPYHHUInst<dag OOL, dag IOL>:
974 RRForm<0b01110011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000975 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000976 [/* no pattern */]>;
977
Scott Michel750b93f2009-01-15 04:41:47 +0000978def MPYHHUv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000979 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
980
981def MPYHHUr32:
982 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000983
984// mpyhhau: Multiply high-high, unsigned
Scott Michel4d07fb72008-12-30 23:28:25 +0000985
986class MPYHHAUInst<dag OOL, dag IOL>:
987 RRForm<0b01110010110, OOL, IOL,
988 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
989 [/* no pattern */]>;
990
Scott Michel8b6b4202007-12-04 22:35:58 +0000991def MPYHHAUvec:
Scott Michel4d07fb72008-12-30 23:28:25 +0000992 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
993
Scott Michel8b6b4202007-12-04 22:35:58 +0000994def MPYHHAUr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000995 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000996
997//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +0000998// clz: Count leading zeroes
Scott Michelae5cbf52008-12-29 03:23:36 +0000999//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel06eabde2008-12-27 04:51:36 +00001000class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
1001 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
1002 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001003
Scott Michel06eabde2008-12-27 04:51:36 +00001004class CLZRegInst<RegisterClass rclass>:
1005 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel4d07fb72008-12-30 23:28:25 +00001006 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001007
1008class CLZVecInst<ValueType vectype>:
1009 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1010 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1011
1012multiclass CountLeadingZeroes {
1013 def v4i32 : CLZVecInst<v4i32>;
1014 def r32 : CLZRegInst<R32C>;
1015}
1016
1017defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001018
1019// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +00001020//
Scott Michel8b6b4202007-12-04 22:35:58 +00001021// NOTE: This instruction is really a vector instruction, but the custom
1022// lowering code uses it in unorthodox ways to support CTPOP for other
1023// data types!
Scott Michel06eabde2008-12-27 04:51:36 +00001024
Scott Michel8b6b4202007-12-04 22:35:58 +00001025def CNTBv16i8:
1026 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1027 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001028 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001029
1030def CNTBv8i16 :
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 (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001034
1035def CNTBv4i32 :
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 (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001039
Scott Michel06eabde2008-12-27 04:51:36 +00001040// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1041// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1042// slots 1-3.
1043//
1044// Note: This instruction "pairs" with the fsmb instruction for all of the
1045// various types defined here.
1046//
1047// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1048// a vector or register.
1049
1050class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1051 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1052
1053class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1054 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001055 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001056
1057class GBBVecInst<ValueType vectype>:
1058 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001059 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001060
1061multiclass GatherBitsFromBytes {
1062 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1063 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1064 def v16i8: GBBVecInst<v16i8>;
1065}
1066
1067defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001068
1069// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001070// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1071// and slots 1-3 also set to 0.
1072//
1073// See notes for GBBInst, above.
1074
1075class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1076 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1077 pattern>;
1078
1079class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1080 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001081 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001082
1083class GBHVecInst<ValueType vectype>:
1084 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001085 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001086
1087multiclass GatherBitsHalfword {
1088 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1089 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1090 def v8i16: GBHVecInst<v8i16>;
1091}
1092
1093defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001094
1095// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001096// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1097// as well as slots 1-3.
1098//
1099// See notes for gbb, above.
1100
1101class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1102 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1103 pattern>;
1104
1105class GBRegInst<RegisterClass rclass, ValueType vectype>:
1106 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001107 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001108
1109class GBVecInst<ValueType vectype>:
1110 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001111 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001112
1113multiclass GatherBitsWord {
1114 def v4i32_r32: GBRegInst<R32C, v4i32>;
1115 def v4i32_r16: GBRegInst<R16C, v4i32>;
1116 def v4i32: GBVecInst<v4i32>;
1117}
1118
1119defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001120
1121// avgb: average bytes
1122def AVGB:
1123 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1124 "avgb\t$rT, $rA, $rB", ByteOp,
1125 []>;
1126
1127// absdb: absolute difference of bytes
1128def ABSDB:
1129 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1130 "absdb\t$rT, $rA, $rB", ByteOp,
1131 []>;
1132
1133// sumb: sum bytes into halfwords
1134def SUMB:
1135 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1136 "sumb\t$rT, $rA, $rB", ByteOp,
1137 []>;
1138
1139// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001140class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1141 RRForm_1<0b01101101010, OOL, IOL,
1142 "xsbh\t$rDst, $rSrc",
1143 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001144
Scott Michel67224b22008-06-02 22:18:03 +00001145class XSBHVecInst<ValueType vectype>:
1146 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1147 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001148
Scott Michel2ef773a2009-01-06 03:36:14 +00001149class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel67224b22008-06-02 22:18:03 +00001150 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Michel2ef773a2009-01-06 03:36:14 +00001151 pattern>;
Scott Michel67224b22008-06-02 22:18:03 +00001152
1153multiclass ExtendByteHalfword {
Scott Michel2ef773a2009-01-06 03:36:14 +00001154 def v16i8: XSBHVecInst<v8i16>;
1155 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1156 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1157 def r16: XSBHInRegInst<R16C,
1158 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001159
1160 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1161 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1162 // pattern below). Intentionally doesn't match a pattern because we want the
1163 // sext 8->32 pattern to do the work for us, namely because we need the extra
1164 // XSHWr32.
Scott Michel2ef773a2009-01-06 03:36:14 +00001165 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1166
1167 // Same as the 32-bit version, but for i64
1168 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +00001169}
1170
1171defm XSBH : ExtendByteHalfword;
1172
Scott Michel8b6b4202007-12-04 22:35:58 +00001173// Sign extend halfwords to words:
Scott Michel8b6b4202007-12-04 22:35:58 +00001174
Scott Michel2ef773a2009-01-06 03:36:14 +00001175class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1176 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1177 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001178
Scott Michel2ef773a2009-01-06 03:36:14 +00001179class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1180 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1181 [(set (out_vectype VECREG:$rDest),
1182 (sext (in_vectype VECREG:$rSrc)))]>;
1183
1184class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1185 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1186 pattern>;
1187
1188class XSHWRegInst<RegisterClass rclass>:
1189 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1190 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1191
1192multiclass ExtendHalfwordWord {
1193 def v4i32: XSHWVecInst<v4i32, v8i16>;
1194
1195 def r16: XSHWRegInst<R32C>;
1196
1197 def r32: XSHWInRegInst<R32C,
1198 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1199 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1200}
1201
1202defm XSHW : ExtendHalfwordWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001203
Scott Michele0168c12009-01-05 01:34:35 +00001204// Sign-extend words to doublewords (32->64 bits)
Scott Michel8b6b4202007-12-04 22:35:58 +00001205
Scott Michele0168c12009-01-05 01:34:35 +00001206class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel2ef773a2009-01-06 03:36:14 +00001207 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1208 IntegerOp, pattern>;
Scott Michele0168c12009-01-05 01:34:35 +00001209
1210class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1211 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1212 [(set (out_vectype VECREG:$rDst),
1213 (sext (out_vectype VECREG:$rSrc)))]>;
1214
1215class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1216 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1217 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1218
1219multiclass ExtendWordToDoubleWord {
1220 def v2i64: XSWDVecInst<v4i32, v2i64>;
1221 def r64: XSWDRegInst<R32C, R64C>;
1222
1223 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1224 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1225}
Scott Michel8b6b4202007-12-04 22:35:58 +00001226
Scott Michele0168c12009-01-05 01:34:35 +00001227defm XSWD : ExtendWordToDoubleWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001228
1229// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001230
Scott Michel97872d32008-02-23 18:41:37 +00001231class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1232 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1233 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001234
Scott Michel97872d32008-02-23 18:41:37 +00001235class ANDVecInst<ValueType vectype>:
1236 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1237 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1238 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001239
Scott Michel6baba072008-03-05 23:02:02 +00001240class ANDRegInst<RegisterClass rclass>:
1241 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1242 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1243
Scott Michel97872d32008-02-23 18:41:37 +00001244multiclass BitwiseAnd
1245{
1246 def v16i8: ANDVecInst<v16i8>;
1247 def v8i16: ANDVecInst<v8i16>;
1248 def v4i32: ANDVecInst<v4i32>;
1249 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001250
Scott Michel6baba072008-03-05 23:02:02 +00001251 def r128: ANDRegInst<GPRC>;
1252 def r64: ANDRegInst<R64C>;
1253 def r32: ANDRegInst<R32C>;
1254 def r16: ANDRegInst<R16C>;
1255 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001256
Scott Michel97872d32008-02-23 18:41:37 +00001257 //===---------------------------------------------
1258 // Special instructions to perform the fabs instruction
1259 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1260 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001261
pingbak2f387e82009-01-26 03:31:40 +00001262 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1263 [/* Intentionally does not match a pattern */]>;
1264
Scott Michel97872d32008-02-23 18:41:37 +00001265 // Could use v4i32, but won't for clarity
1266 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1267 [/* Intentionally does not match a pattern */]>;
1268
1269 //===---------------------------------------------
1270
1271 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1272 // quantities -- see 16->32 zext pattern.
1273 //
1274 // This pattern is somewhat artificial, since it might match some
1275 // compiler generated pattern but it is unlikely to do so.
1276
1277 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1278 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1279}
1280
1281defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001282
1283// N.B.: vnot_conv is one of those special target selection pattern fragments,
1284// in which we expect there to be a bit_convert on the constant. Bear in mind
1285// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1286// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001287
Scott Michel97872d32008-02-23 18:41:37 +00001288class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1289 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1290 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001291
Scott Michel97872d32008-02-23 18:41:37 +00001292class ANDCVecInst<ValueType vectype>:
1293 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1294 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1295 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001296
Scott Michel97872d32008-02-23 18:41:37 +00001297class ANDCRegInst<RegisterClass rclass>:
1298 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1299 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001300
Scott Michel97872d32008-02-23 18:41:37 +00001301multiclass AndComplement
1302{
1303 def v16i8: ANDCVecInst<v16i8>;
1304 def v8i16: ANDCVecInst<v8i16>;
1305 def v4i32: ANDCVecInst<v4i32>;
1306 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001307
Scott Michel97872d32008-02-23 18:41:37 +00001308 def r128: ANDCRegInst<GPRC>;
1309 def r64: ANDCRegInst<R64C>;
1310 def r32: ANDCRegInst<R32C>;
1311 def r16: ANDCRegInst<R16C>;
1312 def r8: ANDCRegInst<R8C>;
1313}
Scott Michel438be252007-12-17 22:32:34 +00001314
Scott Michel97872d32008-02-23 18:41:37 +00001315defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001316
Scott Michel97872d32008-02-23 18:41:37 +00001317class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1318 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001319 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001320
Scott Michel97872d32008-02-23 18:41:37 +00001321multiclass AndByteImm
1322{
1323 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1324 [(set (v16i8 VECREG:$rT),
1325 (and (v16i8 VECREG:$rA),
1326 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001327
Scott Michel97872d32008-02-23 18:41:37 +00001328 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1329 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1330}
Scott Michel438be252007-12-17 22:32:34 +00001331
Scott Michel97872d32008-02-23 18:41:37 +00001332defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001333
Scott Michel97872d32008-02-23 18:41:37 +00001334class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1335 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001336 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001337
Scott Michel97872d32008-02-23 18:41:37 +00001338multiclass AndHalfwordImm
1339{
1340 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1341 [(set (v8i16 VECREG:$rT),
1342 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001343
Scott Michel97872d32008-02-23 18:41:37 +00001344 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1345 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001346
Scott Michel97872d32008-02-23 18:41:37 +00001347 // Zero-extend i8 to i16:
1348 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1349 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1350}
Scott Michel8b6b4202007-12-04 22:35:58 +00001351
Scott Michel97872d32008-02-23 18:41:37 +00001352defm ANDHI : AndHalfwordImm;
1353
1354class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1355 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1356 IntegerOp, pattern>;
1357
1358multiclass AndWordImm
1359{
1360 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1361 [(set (v4i32 VECREG:$rT),
1362 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1363
1364 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1365 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1366
1367 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1368 // pattern below.
1369 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1370 [(set R32C:$rT,
1371 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1372
1373 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1374 // zext 16->32 pattern below.
1375 //
1376 // Note that this pattern is somewhat artificial, since it might match
1377 // something the compiler generates but is unlikely to occur in practice.
1378 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1379 [(set R32C:$rT,
1380 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1381}
1382
1383defm ANDI : AndWordImm;
1384
1385//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001386// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001387//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1388
Scott Michel8b6b4202007-12-04 22:35:58 +00001389// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001390class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1391 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1392 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001393
Scott Michel97872d32008-02-23 18:41:37 +00001394class ORVecInst<ValueType vectype>:
1395 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1396 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1397 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001398
Scott Michel97872d32008-02-23 18:41:37 +00001399class ORRegInst<RegisterClass rclass>:
1400 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1401 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001402
Scott Michel06eabde2008-12-27 04:51:36 +00001403// ORCvtForm: OR conversion form
1404//
1405// This is used to "convert" the preferred slot to its vector equivalent, as
1406// well as convert a vector back to its preferred slot.
1407//
1408// These are effectively no-ops, but need to exist for proper type conversion
1409// and type coercion.
1410
Scott Michel8c67fa42009-01-21 04:58:48 +00001411class ORCvtForm<dag OOL, dag IOL, list<dag> pattern = [/* no pattern */]>
Scott Michel06eabde2008-12-27 04:51:36 +00001412 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1413 bits<7> RA;
1414 bits<7> RT;
1415
Scott Michel8c67fa42009-01-21 04:58:48 +00001416 let Pattern = pattern;
Scott Michel06eabde2008-12-27 04:51:36 +00001417
1418 let Inst{0-10} = 0b10000010000;
1419 let Inst{11-17} = RA;
1420 let Inst{18-24} = RA;
1421 let Inst{25-31} = RT;
1422}
1423
Scott Michel97872d32008-02-23 18:41:37 +00001424class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001425 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001426
Scott Michel97872d32008-02-23 18:41:37 +00001427class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001428 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1429
Scott Michel8c67fa42009-01-21 04:58:48 +00001430/* class ORCvtRegGPRC<RegisterClass rclass>:
1431 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>; */
Scott Michel06eabde2008-12-27 04:51:36 +00001432
Scott Michel8c67fa42009-01-21 04:58:48 +00001433/* class ORCvtVecGPRC:
1434 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>; */
Scott Michel06eabde2008-12-27 04:51:36 +00001435
Scott Michel8c67fa42009-01-21 04:58:48 +00001436/* class ORCvtGPRCReg<RegisterClass rclass>:
1437 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>; */
Scott Michel2ef773a2009-01-06 03:36:14 +00001438
Scott Michel8c67fa42009-01-21 04:58:48 +00001439class ORCvtFormR32Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1440 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001441
Scott Michel8c67fa42009-01-21 04:58:48 +00001442class ORCvtFormRegR32<RegisterClass rclass, list<dag> pattern = [ ]>:
1443 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001444
Scott Michel8c67fa42009-01-21 04:58:48 +00001445class ORCvtFormR64Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1446 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001447
Scott Michel8c67fa42009-01-21 04:58:48 +00001448class ORCvtFormRegR64<RegisterClass rclass, list<dag> pattern = [ ]>:
1449 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA), pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00001450
Scott Michel8c67fa42009-01-21 04:58:48 +00001451/* class ORCvtGPRCVec:
1452 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>; */
Scott Michel8b6b4202007-12-04 22:35:58 +00001453
Scott Michel97872d32008-02-23 18:41:37 +00001454multiclass BitwiseOr
1455{
1456 def v16i8: ORVecInst<v16i8>;
1457 def v8i16: ORVecInst<v8i16>;
1458 def v4i32: ORVecInst<v4i32>;
1459 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001460
Scott Michel97872d32008-02-23 18:41:37 +00001461 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1462 [(set (v4f32 VECREG:$rT),
1463 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1464 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001465
Scott Michel97872d32008-02-23 18:41:37 +00001466 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001467 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001468 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1469 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001470
Scott Michel8c67fa42009-01-21 04:58:48 +00001471 def r128: ORRegInst<GPRC>;
1472 def r64: ORRegInst<R64C>;
1473 def r32: ORRegInst<R32C>;
1474 def r16: ORRegInst<R16C>;
1475 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001476
Scott Michel97872d32008-02-23 18:41:37 +00001477 // OR instructions used to copy f32 and f64 registers.
1478 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1479 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001480
Scott Michel97872d32008-02-23 18:41:37 +00001481 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1482 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001483
Scott Michel4d07fb72008-12-30 23:28:25 +00001484 // scalar->vector promotion, prefslot2vec:
Scott Michel97872d32008-02-23 18:41:37 +00001485 def v16i8_i8: ORPromoteScalar<R8C>;
1486 def v8i16_i16: ORPromoteScalar<R16C>;
1487 def v4i32_i32: ORPromoteScalar<R32C>;
1488 def v2i64_i64: ORPromoteScalar<R64C>;
1489 def v4f32_f32: ORPromoteScalar<R32FP>;
1490 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001491
Scott Michel4d07fb72008-12-30 23:28:25 +00001492 // vector->scalar demotion, vec2prefslot:
Scott Michel97872d32008-02-23 18:41:37 +00001493 def i8_v16i8: ORExtractElt<R8C>;
1494 def i16_v8i16: ORExtractElt<R16C>;
1495 def i32_v4i32: ORExtractElt<R32C>;
1496 def i64_v2i64: ORExtractElt<R64C>;
1497 def f32_v4f32: ORExtractElt<R32FP>;
1498 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001499
Scott Michel8c67fa42009-01-21 04:58:48 +00001500/*
Scott Michel06eabde2008-12-27 04:51:36 +00001501 // Conversion from GPRC to register
1502 def i128_r64: ORCvtRegGPRC<R64C>;
1503 def i128_f64: ORCvtRegGPRC<R64FP>;
1504 def i128_r32: ORCvtRegGPRC<R32C>;
1505 def i128_f32: ORCvtRegGPRC<R32FP>;
1506 def i128_r16: ORCvtRegGPRC<R16C>;
1507 def i128_r8: ORCvtRegGPRC<R8C>;
1508
1509 // Conversion from GPRC to vector
1510 def i128_vec: ORCvtVecGPRC;
1511
1512 // Conversion from register to GPRC
1513 def r64_i128: ORCvtGPRCReg<R64C>;
1514 def f64_i128: ORCvtGPRCReg<R64FP>;
1515 def r32_i128: ORCvtGPRCReg<R32C>;
1516 def f32_i128: ORCvtGPRCReg<R32FP>;
1517 def r16_i128: ORCvtGPRCReg<R16C>;
1518 def r8_i128: ORCvtGPRCReg<R8C>;
1519
1520 // Conversion from vector to GPRC
1521 def vec_i128: ORCvtGPRCVec;
Scott Michel8c67fa42009-01-21 04:58:48 +00001522*/
1523/*
Scott Michel2ef773a2009-01-06 03:36:14 +00001524 // Conversion from register to R32C:
1525 def r16_r32: ORCvtFormRegR32<R16C>;
1526 def r8_r32: ORCvtFormRegR32<R8C>;
1527
1528 // Conversion from R32C to register
1529 def r32_r16: ORCvtFormR32Reg<R16C>;
1530 def r32_r8: ORCvtFormR32Reg<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001531*/
pingbak2f387e82009-01-26 03:31:40 +00001532
1533 // Conversion to register from R64C:
1534 def r32_r64: ORCvtFormR64Reg<R32C>;
1535 // def r16_r64: ORCvtFormR64Reg<R16C>;
1536 // def r8_r64: ORCvtFormR64Reg<R8C>;
1537
1538 // Conversion to R64C from register
1539 def r64_r32: ORCvtFormRegR64<R32C>;
1540 // def r64_r16: ORCvtFormRegR64<R16C>;
1541 // def r64_r8: ORCvtFormRegR64<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001542
1543 // bitconvert patterns:
1544 def r32_f32: ORCvtFormR32Reg<R32FP,
1545 [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1546 def f32_r32: ORCvtFormRegR32<R32FP,
1547 [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1548
1549 def r64_f64: ORCvtFormR64Reg<R64FP,
1550 [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1551 def f64_r64: ORCvtFormRegR64<R64FP,
1552 [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +00001553}
Scott Michel438be252007-12-17 22:32:34 +00001554
Scott Michel97872d32008-02-23 18:41:37 +00001555defm OR : BitwiseOr;
1556
Scott Michel06eabde2008-12-27 04:51:36 +00001557// scalar->vector promotion patterns (preferred slot to vector):
1558def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1559 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001560
Scott Michel06eabde2008-12-27 04:51:36 +00001561def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1562 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001563
Scott Michel06eabde2008-12-27 04:51:36 +00001564def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1565 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001566
Scott Michel06eabde2008-12-27 04:51:36 +00001567def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1568 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001569
Scott Michel06eabde2008-12-27 04:51:36 +00001570def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1571 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001572
Scott Michel06eabde2008-12-27 04:51:36 +00001573def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1574 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001575
Scott Michel06eabde2008-12-27 04:51:36 +00001576// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1577// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001578
Scott Michelc630c412008-11-24 17:11:17 +00001579def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001580 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001581
Scott Michelc630c412008-11-24 17:11:17 +00001582def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001583 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001584
Scott Michelc630c412008-11-24 17:11:17 +00001585def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001586 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001587
Scott Michelc630c412008-11-24 17:11:17 +00001588def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001589 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001590
Scott Michelc630c412008-11-24 17:11:17 +00001591def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001592 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001593
Scott Michelc630c412008-11-24 17:11:17 +00001594def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001595 (ORf64_v2f64 VECREG:$rA)>;
1596
1597// Load Register: This is an assembler alias for a bitwise OR of a register
1598// against itself. It's here because it brings some clarity to assembly
1599// language output.
1600
1601let hasCtrlDep = 1 in {
1602 class LRInst<dag OOL, dag IOL>
1603 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1604 bits<7> RA;
1605 bits<7> RT;
1606
1607 let Pattern = [/*no pattern*/];
1608
1609 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1610 let Inst{11-17} = RA;
1611 let Inst{18-24} = RA;
1612 let Inst{25-31} = RT;
1613 }
1614
1615 class LRVecInst<ValueType vectype>:
1616 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1617
1618 class LRRegInst<RegisterClass rclass>:
1619 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1620
1621 multiclass LoadRegister {
1622 def v2i64: LRVecInst<v2i64>;
1623 def v2f64: LRVecInst<v2f64>;
1624 def v4i32: LRVecInst<v4i32>;
1625 def v4f32: LRVecInst<v4f32>;
1626 def v8i16: LRVecInst<v8i16>;
1627 def v16i8: LRVecInst<v16i8>;
1628
1629 def r128: LRRegInst<GPRC>;
1630 def r64: LRRegInst<R64C>;
1631 def f64: LRRegInst<R64FP>;
1632 def r32: LRRegInst<R32C>;
1633 def f32: LRRegInst<R32FP>;
1634 def r16: LRRegInst<R16C>;
1635 def r8: LRRegInst<R8C>;
1636 }
1637
1638 defm LR: LoadRegister;
1639}
Scott Michel8b6b4202007-12-04 22:35:58 +00001640
Scott Michel97872d32008-02-23 18:41:37 +00001641// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001642
Scott Michel97872d32008-02-23 18:41:37 +00001643class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1644 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1645 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001646
Scott Michel97872d32008-02-23 18:41:37 +00001647class ORCVecInst<ValueType vectype>:
1648 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1649 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1650 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001651
Scott Michel97872d32008-02-23 18:41:37 +00001652class ORCRegInst<RegisterClass rclass>:
1653 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1654 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001655
Scott Michel97872d32008-02-23 18:41:37 +00001656multiclass BitwiseOrComplement
1657{
1658 def v16i8: ORCVecInst<v16i8>;
1659 def v8i16: ORCVecInst<v8i16>;
1660 def v4i32: ORCVecInst<v4i32>;
1661 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001662
Scott Michel97872d32008-02-23 18:41:37 +00001663 def r64: ORCRegInst<R64C>;
1664 def r32: ORCRegInst<R32C>;
1665 def r16: ORCRegInst<R16C>;
1666 def r8: ORCRegInst<R8C>;
1667}
1668
1669defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001670
Scott Michel8b6b4202007-12-04 22:35:58 +00001671// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001672class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1673 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1674 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001675
Scott Michel97872d32008-02-23 18:41:37 +00001676class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1677 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1678 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1679 (vectype immpred:$val)))]>;
1680
1681multiclass BitwiseOrByteImm
1682{
1683 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1684
1685 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1686 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1687}
1688
1689defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001690
Scott Michel8b6b4202007-12-04 22:35:58 +00001691// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001692class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1693 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1694 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001695
Scott Michel97872d32008-02-23 18:41:37 +00001696class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1697 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1698 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1699 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001700
Scott Michel97872d32008-02-23 18:41:37 +00001701multiclass BitwiseOrHalfwordImm
1702{
1703 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1704
1705 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1706 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1707
1708 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1709 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1710 [(set R16C:$rT, (or (anyext R8C:$rA),
1711 i16ImmSExt10:$val))]>;
1712}
1713
1714defm ORHI : BitwiseOrHalfwordImm;
1715
1716class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1717 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1718 IntegerOp, pattern>;
1719
1720class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1721 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1722 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1723 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001724
1725// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001726multiclass BitwiseOrImm
1727{
1728 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001729
Scott Michel97872d32008-02-23 18:41:37 +00001730 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1731 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001732
Scott Michel97872d32008-02-23 18:41:37 +00001733 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1734 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1735 // infra "anyext 16->32" pattern.)
1736 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1737 [(set R32C:$rT, (or (anyext R16C:$rA),
1738 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001739
Scott Michel97872d32008-02-23 18:41:37 +00001740 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1741 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1742 // infra "anyext 16->32" pattern.)
1743 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1744 [(set R32C:$rT, (or (anyext R8C:$rA),
1745 i32ImmSExt10:$val))]>;
1746}
Scott Michel8b6b4202007-12-04 22:35:58 +00001747
Scott Michel97872d32008-02-23 18:41:37 +00001748defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001749
Scott Michel8b6b4202007-12-04 22:35:58 +00001750// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1751// $rT[0], slots 1-3 are zeroed.
1752//
Scott Michel438be252007-12-17 22:32:34 +00001753// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001754def ORXv4i32:
1755 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1756 "orx\t$rT, $rA, $rB", IntegerOp,
1757 []>;
1758
Scott Michel438be252007-12-17 22:32:34 +00001759// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001760
Scott Michel6baba072008-03-05 23:02:02 +00001761class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1762 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1763 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001764
Scott Michel6baba072008-03-05 23:02:02 +00001765class XORVecInst<ValueType vectype>:
1766 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1767 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1768 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001769
Scott Michel6baba072008-03-05 23:02:02 +00001770class XORRegInst<RegisterClass rclass>:
1771 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1772 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1773
1774multiclass BitwiseExclusiveOr
1775{
1776 def v16i8: XORVecInst<v16i8>;
1777 def v8i16: XORVecInst<v8i16>;
1778 def v4i32: XORVecInst<v4i32>;
1779 def v2i64: XORVecInst<v2i64>;
1780
1781 def r128: XORRegInst<GPRC>;
1782 def r64: XORRegInst<R64C>;
1783 def r32: XORRegInst<R32C>;
1784 def r16: XORRegInst<R16C>;
1785 def r8: XORRegInst<R8C>;
1786
1787 // Special forms for floating point instructions.
1788 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1789
1790 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1791 [/* no pattern */]>;
1792
1793 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1794 [/* no pattern */]>;
1795
1796 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1797 [/* no pattern, see fneg{32,64} */]>;
1798}
1799
1800defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001801
1802//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001803
Scott Michel97872d32008-02-23 18:41:37 +00001804class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1805 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1806 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001807
Scott Michel97872d32008-02-23 18:41:37 +00001808multiclass XorByteImm
1809{
1810 def v16i8:
1811 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1812 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1813
1814 def r8:
1815 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1816 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1817}
1818
1819defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001820
Scott Michel8b6b4202007-12-04 22:35:58 +00001821def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001822 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001823 "xorhi\t$rT, $rA, $val", IntegerOp,
1824 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1825 v8i16SExt10Imm:$val))]>;
1826
1827def XORHIr16:
1828 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1829 "xorhi\t$rT, $rA, $val", IntegerOp,
1830 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1831
1832def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001833 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001834 "xori\t$rT, $rA, $val", IntegerOp,
1835 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1836 v4i32SExt10Imm:$val))]>;
1837
1838def XORIr32:
1839 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1840 "xori\t$rT, $rA, $val", IntegerOp,
1841 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1842
1843// NAND:
1844def NANDv16i8:
1845 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1846 "nand\t$rT, $rA, $rB", IntegerOp,
1847 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1848 (v16i8 VECREG:$rB))))]>;
1849
1850def NANDv8i16:
1851 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1852 "nand\t$rT, $rA, $rB", IntegerOp,
1853 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1854 (v8i16 VECREG:$rB))))]>;
1855
1856def NANDv4i32:
1857 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1858 "nand\t$rT, $rA, $rB", IntegerOp,
1859 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1860 (v4i32 VECREG:$rB))))]>;
1861
1862def NANDr32:
1863 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1864 "nand\t$rT, $rA, $rB", IntegerOp,
1865 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1866
1867def NANDr16:
1868 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1869 "nand\t$rT, $rA, $rB", IntegerOp,
1870 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1871
Scott Michel438be252007-12-17 22:32:34 +00001872def NANDr8:
1873 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1874 "nand\t$rT, $rA, $rB", IntegerOp,
1875 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1876
Scott Michel8b6b4202007-12-04 22:35:58 +00001877// NOR:
1878def NORv16i8:
1879 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1880 "nor\t$rT, $rA, $rB", IntegerOp,
1881 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1882 (v16i8 VECREG:$rB))))]>;
1883
1884def NORv8i16:
1885 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1886 "nor\t$rT, $rA, $rB", IntegerOp,
1887 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1888 (v8i16 VECREG:$rB))))]>;
1889
1890def NORv4i32:
1891 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1892 "nor\t$rT, $rA, $rB", IntegerOp,
1893 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1894 (v4i32 VECREG:$rB))))]>;
1895
1896def NORr32:
1897 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1898 "nor\t$rT, $rA, $rB", IntegerOp,
1899 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1900
1901def NORr16:
1902 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1903 "nor\t$rT, $rA, $rB", IntegerOp,
1904 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1905
Scott Michel438be252007-12-17 22:32:34 +00001906def NORr8:
1907 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1908 "nor\t$rT, $rA, $rB", IntegerOp,
1909 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1910
Scott Michel8b6b4202007-12-04 22:35:58 +00001911// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001912class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1913 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1914 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001915
pingbak2f387e82009-01-26 03:31:40 +00001916class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michel6baba072008-03-05 23:02:02 +00001917 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1918 [(set (vectype VECREG:$rT),
1919 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
pingbak2f387e82009-01-26 03:31:40 +00001920 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michel6baba072008-03-05 23:02:02 +00001921 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001922
Scott Michel4d07fb72008-12-30 23:28:25 +00001923class SELBVecVCondInst<ValueType vectype>:
1924 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1925 [(set (vectype VECREG:$rT),
1926 (select (vectype VECREG:$rC),
1927 (vectype VECREG:$rB),
1928 (vectype VECREG:$rA)))]>;
1929
Scott Michel06eabde2008-12-27 04:51:36 +00001930class SELBVecCondInst<ValueType vectype>:
1931 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1932 [(set (vectype VECREG:$rT),
1933 (select R32C:$rC,
1934 (vectype VECREG:$rB),
1935 (vectype VECREG:$rA)))]>;
1936
Scott Michel6baba072008-03-05 23:02:02 +00001937class SELBRegInst<RegisterClass rclass>:
1938 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1939 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001940 (or (and rclass:$rB, rclass:$rC),
1941 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001942
Scott Michel06eabde2008-12-27 04:51:36 +00001943class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1944 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1945 [(set rclass:$rT,
1946 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1947
Scott Michel6baba072008-03-05 23:02:02 +00001948multiclass SelectBits
1949{
1950 def v16i8: SELBVecInst<v16i8>;
1951 def v8i16: SELBVecInst<v8i16>;
1952 def v4i32: SELBVecInst<v4i32>;
pingbak2f387e82009-01-26 03:31:40 +00001953 def v2i64: SELBVecInst<v2i64, vnot_conv>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001954
Scott Michel6baba072008-03-05 23:02:02 +00001955 def r128: SELBRegInst<GPRC>;
1956 def r64: SELBRegInst<R64C>;
1957 def r32: SELBRegInst<R32C>;
1958 def r16: SELBRegInst<R16C>;
1959 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001960
1961 def v16i8_cond: SELBVecCondInst<v16i8>;
1962 def v8i16_cond: SELBVecCondInst<v8i16>;
1963 def v4i32_cond: SELBVecCondInst<v4i32>;
1964 def v2i64_cond: SELBVecCondInst<v2i64>;
1965
Scott Michel4d07fb72008-12-30 23:28:25 +00001966 def v16i8_vcond: SELBVecCondInst<v16i8>;
1967 def v8i16_vcond: SELBVecCondInst<v8i16>;
1968 def v4i32_vcond: SELBVecCondInst<v4i32>;
1969 def v2i64_vcond: SELBVecCondInst<v2i64>;
1970
1971 def v4f32_cond:
1972 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1973 [(set (v4f32 VECREG:$rT),
1974 (select (v4i32 VECREG:$rC),
1975 (v4f32 VECREG:$rB),
1976 (v4f32 VECREG:$rA)))]>;
1977
Scott Michel8c67fa42009-01-21 04:58:48 +00001978 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michel06eabde2008-12-27 04:51:36 +00001979 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001980 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001981 def r16_cond: SELBRegCondInst<R16C, R16C>;
1982 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001983}
Scott Michel8b6b4202007-12-04 22:35:58 +00001984
Scott Michel6baba072008-03-05 23:02:02 +00001985defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001986
Scott Michel56a125e2008-11-22 23:50:42 +00001987class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001988 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1989 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001990
Scott Michel56a125e2008-11-22 23:50:42 +00001991def : SPUselbPatVec<v16i8, SELBv16i8>;
1992def : SPUselbPatVec<v8i16, SELBv8i16>;
1993def : SPUselbPatVec<v4i32, SELBv4i32>;
1994def : SPUselbPatVec<v2i64, SELBv2i64>;
1995
1996class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1997 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1998 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1999
2000def : SPUselbPatReg<R8C, SELBr8>;
2001def : SPUselbPatReg<R16C, SELBr16>;
2002def : SPUselbPatReg<R32C, SELBr32>;
2003def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002004
Scott Michel6baba072008-03-05 23:02:02 +00002005// EQV: Equivalence (1 for each same bit, otherwise 0)
2006//
2007// Note: There are a lot of ways to match this bit operator and these patterns
2008// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00002009
Scott Michel6baba072008-03-05 23:02:02 +00002010class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2011 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2012 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002013
Scott Michel6baba072008-03-05 23:02:02 +00002014class EQVVecInst<ValueType vectype>:
2015 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2016 [(set (vectype VECREG:$rT),
2017 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2018 (and (vnot (vectype VECREG:$rA)),
2019 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002020
Scott Michel6baba072008-03-05 23:02:02 +00002021class EQVRegInst<RegisterClass rclass>:
2022 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2023 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2024 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002025
Scott Michel6baba072008-03-05 23:02:02 +00002026class EQVVecPattern1<ValueType vectype>:
2027 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2028 [(set (vectype VECREG:$rT),
2029 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002030
Scott Michel6baba072008-03-05 23:02:02 +00002031class EQVRegPattern1<RegisterClass rclass>:
2032 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2033 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002034
Scott Michel6baba072008-03-05 23:02:02 +00002035class EQVVecPattern2<ValueType vectype>:
2036 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2037 [(set (vectype VECREG:$rT),
2038 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2039 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002040
Scott Michel6baba072008-03-05 23:02:02 +00002041class EQVRegPattern2<RegisterClass rclass>:
2042 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2043 [(set rclass:$rT,
2044 (or (and rclass:$rA, rclass:$rB),
2045 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002046
Scott Michel6baba072008-03-05 23:02:02 +00002047class EQVVecPattern3<ValueType vectype>:
2048 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2049 [(set (vectype VECREG:$rT),
2050 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002051
Scott Michel6baba072008-03-05 23:02:02 +00002052class EQVRegPattern3<RegisterClass rclass>:
2053 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2054 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002055
Scott Michel6baba072008-03-05 23:02:02 +00002056multiclass BitEquivalence
2057{
2058 def v16i8: EQVVecInst<v16i8>;
2059 def v8i16: EQVVecInst<v8i16>;
2060 def v4i32: EQVVecInst<v4i32>;
2061 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002062
Scott Michel6baba072008-03-05 23:02:02 +00002063 def v16i8_1: EQVVecPattern1<v16i8>;
2064 def v8i16_1: EQVVecPattern1<v8i16>;
2065 def v4i32_1: EQVVecPattern1<v4i32>;
2066 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002067
Scott Michel6baba072008-03-05 23:02:02 +00002068 def v16i8_2: EQVVecPattern2<v16i8>;
2069 def v8i16_2: EQVVecPattern2<v8i16>;
2070 def v4i32_2: EQVVecPattern2<v4i32>;
2071 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002072
Scott Michel6baba072008-03-05 23:02:02 +00002073 def v16i8_3: EQVVecPattern3<v16i8>;
2074 def v8i16_3: EQVVecPattern3<v8i16>;
2075 def v4i32_3: EQVVecPattern3<v4i32>;
2076 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002077
Scott Michel6baba072008-03-05 23:02:02 +00002078 def r128: EQVRegInst<GPRC>;
2079 def r64: EQVRegInst<R64C>;
2080 def r32: EQVRegInst<R32C>;
2081 def r16: EQVRegInst<R16C>;
2082 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002083
Scott Michel6baba072008-03-05 23:02:02 +00002084 def r128_1: EQVRegPattern1<GPRC>;
2085 def r64_1: EQVRegPattern1<R64C>;
2086 def r32_1: EQVRegPattern1<R32C>;
2087 def r16_1: EQVRegPattern1<R16C>;
2088 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002089
Scott Michel6baba072008-03-05 23:02:02 +00002090 def r128_2: EQVRegPattern2<GPRC>;
2091 def r64_2: EQVRegPattern2<R64C>;
2092 def r32_2: EQVRegPattern2<R32C>;
2093 def r16_2: EQVRegPattern2<R16C>;
2094 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002095
Scott Michel6baba072008-03-05 23:02:02 +00002096 def r128_3: EQVRegPattern3<GPRC>;
2097 def r64_3: EQVRegPattern3<R64C>;
2098 def r32_3: EQVRegPattern3<R32C>;
2099 def r16_3: EQVRegPattern3<R16C>;
2100 def r8_3: EQVRegPattern3<R8C>;
2101}
Scott Michel438be252007-12-17 22:32:34 +00002102
Scott Michel6baba072008-03-05 23:02:02 +00002103defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00002104
2105//===----------------------------------------------------------------------===//
2106// Vector shuffle...
2107//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002108// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2109// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2110// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2111// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002112//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002113
Scott Michel97872d32008-02-23 18:41:37 +00002114class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2115 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2116 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002117
Scott Michel0718cd82008-12-01 17:56:02 +00002118class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002119 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002120 [(set (resultvec VECREG:$rT),
2121 (SPUshuffle (resultvec VECREG:$rA),
2122 (resultvec VECREG:$rB),
2123 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002124
Scott Michel06eabde2008-12-27 04:51:36 +00002125class SHUFBGPRCInst:
2126 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2127 [/* no pattern */]>;
2128
Scott Michel97872d32008-02-23 18:41:37 +00002129multiclass ShuffleBytes
2130{
Scott Michel0718cd82008-12-01 17:56:02 +00002131 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2132 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2133 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2134 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2135 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2136 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2137 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2138 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002139
Scott Michel0718cd82008-12-01 17:56:02 +00002140 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2141 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2142
2143 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2144 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002145
2146 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002147}
2148
2149defm SHUFB : ShuffleBytes;
2150
Scott Michel8b6b4202007-12-04 22:35:58 +00002151//===----------------------------------------------------------------------===//
2152// Shift and rotate group:
2153//===----------------------------------------------------------------------===//
2154
Scott Michel97872d32008-02-23 18:41:37 +00002155class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2156 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2157 RotateShift, pattern>;
2158
2159class SHLHVecInst<ValueType vectype>:
2160 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2161 [(set (vectype VECREG:$rT),
2162 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002163
Scott Michel97872d32008-02-23 18:41:37 +00002164multiclass ShiftLeftHalfword
2165{
2166 def v8i16: SHLHVecInst<v8i16>;
2167 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2168 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2169 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2170 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2171}
Scott Michel8b6b4202007-12-04 22:35:58 +00002172
Scott Michel97872d32008-02-23 18:41:37 +00002173defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002174
Scott Michel97872d32008-02-23 18:41:37 +00002175//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002176
Scott Michel97872d32008-02-23 18:41:37 +00002177class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2178 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2179 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002180
Scott Michel97872d32008-02-23 18:41:37 +00002181class SHLHIVecInst<ValueType vectype>:
2182 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2183 [(set (vectype VECREG:$rT),
2184 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002185
Scott Michel97872d32008-02-23 18:41:37 +00002186multiclass ShiftLeftHalfwordImm
2187{
2188 def v8i16: SHLHIVecInst<v8i16>;
2189 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2190 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2191}
2192
2193defm SHLHI : ShiftLeftHalfwordImm;
2194
2195def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2196 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2197
2198def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002199 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002200
Scott Michel97872d32008-02-23 18:41:37 +00002201//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002202
Scott Michel97872d32008-02-23 18:41:37 +00002203class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2204 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2205 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002206
Scott Michel97872d32008-02-23 18:41:37 +00002207multiclass ShiftLeftWord
2208{
2209 def v4i32:
2210 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2211 [(set (v4i32 VECREG:$rT),
2212 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2213 def r32:
2214 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2215 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2216}
Scott Michel8b6b4202007-12-04 22:35:58 +00002217
Scott Michel97872d32008-02-23 18:41:37 +00002218defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +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 SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2223 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2224 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002225
Scott Michel97872d32008-02-23 18:41:37 +00002226multiclass ShiftLeftWordImm
2227{
2228 def v4i32:
2229 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2230 [(set (v4i32 VECREG:$rT),
2231 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002232
Scott Michel97872d32008-02-23 18:41:37 +00002233 def r32:
2234 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2235 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2236}
Scott Michel8b6b4202007-12-04 22:35:58 +00002237
Scott Michel97872d32008-02-23 18:41:37 +00002238defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002239
Scott Michel97872d32008-02-23 18:41:37 +00002240//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002241// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2242// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002243//
2244// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2245// of 7 bits is actually possible.
2246//
2247// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2248// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2249// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002250
Scott Michel97872d32008-02-23 18:41:37 +00002251class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2252 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2253 RotateShift, pattern>;
2254
2255class SHLQBIVecInst<ValueType vectype>:
2256 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2257 [(set (vectype VECREG:$rT),
2258 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2259
Scott Michel8c67fa42009-01-21 04:58:48 +00002260class SHLQBIRegInst<RegisterClass rclass>:
2261 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2262 [/* no pattern */]>;
2263
Scott Michel97872d32008-02-23 18:41:37 +00002264multiclass ShiftLeftQuadByBits
2265{
2266 def v16i8: SHLQBIVecInst<v16i8>;
2267 def v8i16: SHLQBIVecInst<v8i16>;
2268 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002269 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002270 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002271 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel8c67fa42009-01-21 04:58:48 +00002272
2273 def r128: SHLQBIRegInst<GPRC>;
Scott Michel97872d32008-02-23 18:41:37 +00002274}
2275
2276defm SHLQBI : ShiftLeftQuadByBits;
2277
2278// See note above on SHLQBI. In this case, the predicate actually does then
2279// enforcement, whereas with SHLQBI, we have to "take it on faith."
2280class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2281 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2282 RotateShift, pattern>;
2283
2284class SHLQBIIVecInst<ValueType vectype>:
2285 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2286 [(set (vectype VECREG:$rT),
2287 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2288
2289multiclass ShiftLeftQuadByBitsImm
2290{
2291 def v16i8 : SHLQBIIVecInst<v16i8>;
2292 def v8i16 : SHLQBIIVecInst<v8i16>;
2293 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002294 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002295 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002296 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002297}
2298
2299defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002300
2301// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002302// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002303
Scott Michel97872d32008-02-23 18:41:37 +00002304class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002305 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002306 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002307
Scott Michel97872d32008-02-23 18:41:37 +00002308class SHLQBYVecInst<ValueType vectype>:
2309 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2310 [(set (vectype VECREG:$rT),
2311 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002312
Scott Michel97872d32008-02-23 18:41:37 +00002313multiclass ShiftLeftQuadBytes
2314{
2315 def v16i8: SHLQBYVecInst<v16i8>;
2316 def v8i16: SHLQBYVecInst<v8i16>;
2317 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002318 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002319 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002320 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002321 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2322 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2323}
Scott Michel8b6b4202007-12-04 22:35:58 +00002324
Scott Michel97872d32008-02-23 18:41:37 +00002325defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002326
Scott Michel97872d32008-02-23 18:41:37 +00002327class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2328 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2329 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002330
Scott Michel97872d32008-02-23 18:41:37 +00002331class SHLQBYIVecInst<ValueType vectype>:
2332 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2333 [(set (vectype VECREG:$rT),
2334 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002335
Scott Michel97872d32008-02-23 18:41:37 +00002336multiclass ShiftLeftQuadBytesImm
2337{
2338 def v16i8: SHLQBYIVecInst<v16i8>;
2339 def v8i16: SHLQBYIVecInst<v8i16>;
2340 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002341 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002342 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002343 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002344 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2345 [(set GPRC:$rT,
2346 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2347}
Scott Michel438be252007-12-17 22:32:34 +00002348
Scott Michel97872d32008-02-23 18:41:37 +00002349defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002350
Scott Michel8c67fa42009-01-21 04:58:48 +00002351class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2352 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2353 RotateShift, pattern>;
2354
2355class SHLQBYBIVecInst<ValueType vectype>:
2356 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2357 [/* no pattern */]>;
2358
2359class SHLQBYBIRegInst<RegisterClass rclass>:
2360 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2361 [/* no pattern */]>;
2362
2363multiclass ShiftLeftQuadBytesBitCount
2364{
2365 def v16i8: SHLQBYBIVecInst<v16i8>;
2366 def v8i16: SHLQBYBIVecInst<v8i16>;
2367 def v4i32: SHLQBYBIVecInst<v4i32>;
2368 def v4f32: SHLQBYBIVecInst<v4f32>;
2369 def v2i64: SHLQBYBIVecInst<v2i64>;
2370 def v2f64: SHLQBYBIVecInst<v2f64>;
2371
2372 def r128: SHLQBYBIRegInst<GPRC>;
2373}
2374
2375defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2376
Scott Michel97872d32008-02-23 18:41:37 +00002377//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2378// Rotate halfword:
2379//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2380class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2381 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2382 RotateShift, pattern>;
2383
2384class ROTHVecInst<ValueType vectype>:
2385 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2386 [(set (vectype VECREG:$rT),
2387 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2388
2389class ROTHRegInst<RegisterClass rclass>:
2390 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2391 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2392
2393multiclass RotateLeftHalfword
2394{
2395 def v8i16: ROTHVecInst<v8i16>;
2396 def r16: ROTHRegInst<R16C>;
2397}
2398
2399defm ROTH: RotateLeftHalfword;
2400
2401def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2402 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2403
2404//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2405// Rotate halfword, immediate:
2406//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2407class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2408 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2409 RotateShift, pattern>;
2410
2411class ROTHIVecInst<ValueType vectype>:
2412 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2413 [(set (vectype VECREG:$rT),
2414 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2415
2416multiclass RotateLeftHalfwordImm
2417{
2418 def v8i16: ROTHIVecInst<v8i16>;
2419 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2420 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2421 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2422 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2423}
2424
2425defm ROTHI: RotateLeftHalfwordImm;
2426
2427def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002428 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002429
Scott Michel97872d32008-02-23 18:41:37 +00002430//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2431// Rotate word:
2432//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002433
Scott Michel97872d32008-02-23 18:41:37 +00002434class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2435 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2436 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002437
Scott Michel97872d32008-02-23 18:41:37 +00002438class ROTVecInst<ValueType vectype>:
2439 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2440 [(set (vectype VECREG:$rT),
2441 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002442
Scott Michel97872d32008-02-23 18:41:37 +00002443class ROTRegInst<RegisterClass rclass>:
2444 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2445 [(set rclass:$rT,
2446 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002447
Scott Michel97872d32008-02-23 18:41:37 +00002448multiclass RotateLeftWord
2449{
2450 def v4i32: ROTVecInst<v4i32>;
2451 def r32: ROTRegInst<R32C>;
2452}
2453
2454defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002455
Scott Michel438be252007-12-17 22:32:34 +00002456// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2457// 32-bit register
2458def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002459 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2460 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002461
2462def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2463 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2464
2465def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2466 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2467
2468def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002469 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2470 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002471
2472def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2473 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2474
2475def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2476 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2477
Scott Michel97872d32008-02-23 18:41:37 +00002478//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2479// Rotate word, immediate
2480//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002481
Scott Michel97872d32008-02-23 18:41:37 +00002482class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2483 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2484 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002485
Scott Michel97872d32008-02-23 18:41:37 +00002486class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2487 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2488 [(set (vectype VECREG:$rT),
2489 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002490
Scott Michel97872d32008-02-23 18:41:37 +00002491class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2492 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2493 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002494
Scott Michel97872d32008-02-23 18:41:37 +00002495multiclass RotateLeftWordImm
2496{
2497 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2498 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2499 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002500
Scott Michel97872d32008-02-23 18:41:37 +00002501 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2502 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2503 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2504}
Scott Michel438be252007-12-17 22:32:34 +00002505
Scott Michel97872d32008-02-23 18:41:37 +00002506defm ROTI : RotateLeftWordImm;
2507
2508//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2509// Rotate quad by byte (count)
2510//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2511
2512class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2513 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2514 RotateShift, pattern>;
2515
2516class ROTQBYVecInst<ValueType vectype>:
2517 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2518 [(set (vectype VECREG:$rT),
2519 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2520
2521multiclass RotateQuadLeftByBytes
2522{
2523 def v16i8: ROTQBYVecInst<v16i8>;
2524 def v8i16: ROTQBYVecInst<v8i16>;
2525 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002526 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002527 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002528 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002529}
2530
2531defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002532
Scott Michel97872d32008-02-23 18:41:37 +00002533//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2534// Rotate quad by byte (count), immediate
2535//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2536
2537class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2538 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2539 RotateShift, pattern>;
2540
2541class ROTQBYIVecInst<ValueType vectype>:
2542 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2543 [(set (vectype VECREG:$rT),
2544 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2545
2546multiclass RotateQuadByBytesImm
2547{
2548 def v16i8: ROTQBYIVecInst<v16i8>;
2549 def v8i16: ROTQBYIVecInst<v8i16>;
2550 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002551 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002552 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002553 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002554}
2555
2556defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002557
Scott Michel8b6b4202007-12-04 22:35:58 +00002558// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002559class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2560 RI7Form<0b00110011100, OOL, IOL,
2561 "rotqbybi\t$rT, $rA, $shift",
2562 RotateShift, pattern>;
2563
2564class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2565 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2566 [(set (vectype VECREG:$rT),
2567 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2568
2569multiclass RotateQuadByBytesByBitshift {
2570 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2571 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2572 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2573 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2574}
2575
2576defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002577
Scott Michel97872d32008-02-23 18:41:37 +00002578//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002579// See ROTQBY note above.
2580//
2581// Assume that the user of this instruction knows to shift the rotate count
2582// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002583//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002584
Scott Michel97872d32008-02-23 18:41:37 +00002585class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2586 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2587 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002588
Scott Michel97872d32008-02-23 18:41:37 +00002589class ROTQBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002590 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002591 [/* no pattern yet */]>;
2592
2593class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002594 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002595 [/* no pattern yet */]>;
2596
2597multiclass RotateQuadByBitCount
2598{
2599 def v16i8: ROTQBIVecInst<v16i8>;
2600 def v8i16: ROTQBIVecInst<v8i16>;
2601 def v4i32: ROTQBIVecInst<v4i32>;
2602 def v2i64: ROTQBIVecInst<v2i64>;
2603
2604 def r128: ROTQBIRegInst<GPRC>;
2605 def r64: ROTQBIRegInst<R64C>;
2606}
2607
2608defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002609
Scott Michel97872d32008-02-23 18:41:37 +00002610class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2611 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2612 RotateShift, pattern>;
2613
2614class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2615 PatLeaf pred>:
2616 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2617 [/* no pattern yet */]>;
2618
2619class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2620 PatLeaf pred>:
2621 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2622 [/* no pattern yet */]>;
2623
2624multiclass RotateQuadByBitCountImm
2625{
2626 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2627 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2628 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2629 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2630
2631 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2632 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2633}
2634
2635defm ROTQBII : RotateQuadByBitCountImm;
2636
2637//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002638// ROTHM v8i16 form:
2639// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2640// so this only matches a synthetically generated/lowered code
2641// fragment.
2642// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002643//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002644
Scott Michel97872d32008-02-23 18:41:37 +00002645class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2646 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2647 RotateShift, pattern>;
2648
2649def ROTHMv8i16:
2650 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2651 [/* see patterns below - $rB must be negated */]>;
2652
2653def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002654 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2655
Scott Michel97872d32008-02-23 18:41:37 +00002656def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002657 (ROTHMv8i16 VECREG:$rA,
2658 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2659
Scott Michel97872d32008-02-23 18:41:37 +00002660def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002661 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002662 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002663
2664// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2665// Note: This instruction doesn't match a pattern because rB must be negated
2666// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002667
Scott Michel8b6b4202007-12-04 22:35:58 +00002668def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002669 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2670 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002671
2672def : Pat<(srl R16C:$rA, R32C:$rB),
2673 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2674
2675def : Pat<(srl R16C:$rA, R16C:$rB),
2676 (ROTHMr16 R16C:$rA,
2677 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2678
Scott Michel438be252007-12-17 22:32:34 +00002679def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002680 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002681 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002682
2683// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2684// that the immediate can be complemented, so that the user doesn't have to
2685// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002686
Scott Michel97872d32008-02-23 18:41:37 +00002687class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2688 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2689 RotateShift, pattern>;
2690
2691def ROTHMIv8i16:
2692 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2693 [/* no pattern */]>;
2694
2695def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2696 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2697
2698def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002699 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002700
Scott Michel97872d32008-02-23 18:41:37 +00002701def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002702 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002703
2704def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002705 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2706 [/* no pattern */]>;
2707
2708def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2709 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002710
2711def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2712 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2713
Scott Michel438be252007-12-17 22:32:34 +00002714def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2715 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2716
Scott Michel8b6b4202007-12-04 22:35:58 +00002717// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002718class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2719 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2720 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002721
Scott Michel97872d32008-02-23 18:41:37 +00002722def ROTMv4i32:
2723 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2724 [/* see patterns below - $rB must be negated */]>;
2725
2726def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002727 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2728
Scott Michel97872d32008-02-23 18:41:37 +00002729def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002730 (ROTMv4i32 VECREG:$rA,
2731 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2732
Scott Michel97872d32008-02-23 18:41:37 +00002733def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002734 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002735 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002736
2737def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002738 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2739 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002740
2741def : Pat<(srl R32C:$rA, R32C:$rB),
2742 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2743
2744def : Pat<(srl R32C:$rA, R16C:$rB),
2745 (ROTMr32 R32C:$rA,
2746 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2747
Scott Michel438be252007-12-17 22:32:34 +00002748def : Pat<(srl R32C:$rA, R8C:$rB),
2749 (ROTMr32 R32C:$rA,
2750 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2751
Scott Michel8b6b4202007-12-04 22:35:58 +00002752// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2753def ROTMIv4i32:
2754 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2755 "rotmi\t$rT, $rA, $val", RotateShift,
2756 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002757 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002758
Scott Michel97872d32008-02-23 18:41:37 +00002759def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002760 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002761
Scott Michel97872d32008-02-23 18:41:37 +00002762def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002763 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002764
2765// ROTMI r32 form: know how to complement the immediate value.
2766def ROTMIr32:
2767 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2768 "rotmi\t$rT, $rA, $val", RotateShift,
2769 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2770
2771def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2772 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2773
Scott Michel438be252007-12-17 22:32:34 +00002774def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2775 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2776
Scott Michel97872d32008-02-23 18:41:37 +00002777//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel2ef773a2009-01-06 03:36:14 +00002778// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel8b6b4202007-12-04 22:35:58 +00002779// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002780// that the user knew to negate $rB.
Scott Michel97872d32008-02-23 18:41:37 +00002781//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002782
Scott Michel97872d32008-02-23 18:41:37 +00002783class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2784 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2785 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002786
Scott Michel97872d32008-02-23 18:41:37 +00002787class ROTQMBYVecInst<ValueType vectype>:
2788 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2789 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002790
Scott Michel97872d32008-02-23 18:41:37 +00002791class ROTQMBYRegInst<RegisterClass rclass>:
2792 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00002793 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002794
Scott Michel97872d32008-02-23 18:41:37 +00002795multiclass RotateQuadBytes
2796{
2797 def v16i8: ROTQMBYVecInst<v16i8>;
2798 def v8i16: ROTQMBYVecInst<v8i16>;
2799 def v4i32: ROTQMBYVecInst<v4i32>;
2800 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002801
Scott Michel97872d32008-02-23 18:41:37 +00002802 def r128: ROTQMBYRegInst<GPRC>;
2803 def r64: ROTQMBYRegInst<R64C>;
2804}
2805
2806defm ROTQMBY : RotateQuadBytes;
2807
Scott Michel97872d32008-02-23 18:41:37 +00002808class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2809 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2810 RotateShift, pattern>;
2811
2812class ROTQMBYIVecInst<ValueType vectype>:
2813 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002814 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002815
Scott Michel2ef773a2009-01-06 03:36:14 +00002816class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2817 PatLeaf pred>:
Scott Michel97872d32008-02-23 18:41:37 +00002818 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002819 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002820
Scott Michel2ef773a2009-01-06 03:36:14 +00002821// 128-bit zero extension form:
2822class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2823 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2824 [/* no pattern */]>;
2825
Scott Michel97872d32008-02-23 18:41:37 +00002826multiclass RotateQuadBytesImm
2827{
2828 def v16i8: ROTQMBYIVecInst<v16i8>;
2829 def v8i16: ROTQMBYIVecInst<v8i16>;
2830 def v4i32: ROTQMBYIVecInst<v4i32>;
2831 def v2i64: ROTQMBYIVecInst<v2i64>;
2832
2833 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2834 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Michel2ef773a2009-01-06 03:36:14 +00002835
2836 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2837 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2838 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2839 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michel97872d32008-02-23 18:41:37 +00002840}
2841
2842defm ROTQMBYI : RotateQuadBytesImm;
2843
Scott Michel97872d32008-02-23 18:41:37 +00002844//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2845// Rotate right and mask by bit count
2846//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2847
2848class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2849 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2850 RotateShift, pattern>;
2851
2852class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002853 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2854 [/* no pattern, */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002855
2856multiclass RotateMaskQuadByBitCount
2857{
2858 def v16i8: ROTQMBYBIVecInst<v16i8>;
2859 def v8i16: ROTQMBYBIVecInst<v8i16>;
2860 def v4i32: ROTQMBYBIVecInst<v4i32>;
2861 def v2i64: ROTQMBYBIVecInst<v2i64>;
2862}
2863
2864defm ROTQMBYBI: RotateMaskQuadByBitCount;
2865
2866//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2867// Rotate quad and mask by bits
2868// Note that the rotate amount has to be negated
2869//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2870
2871class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2872 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2873 RotateShift, pattern>;
2874
2875class ROTQMBIVecInst<ValueType vectype>:
2876 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2877 [/* no pattern */]>;
2878
2879class ROTQMBIRegInst<RegisterClass rclass>:
2880 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2881 [/* no pattern */]>;
2882
2883multiclass RotateMaskQuadByBits
2884{
2885 def v16i8: ROTQMBIVecInst<v16i8>;
2886 def v8i16: ROTQMBIVecInst<v8i16>;
2887 def v4i32: ROTQMBIVecInst<v4i32>;
2888 def v2i64: ROTQMBIVecInst<v2i64>;
2889
2890 def r128: ROTQMBIRegInst<GPRC>;
2891 def r64: ROTQMBIRegInst<R64C>;
2892}
2893
2894defm ROTQMBI: RotateMaskQuadByBits;
2895
Scott Michel97872d32008-02-23 18:41:37 +00002896//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2897// Rotate quad and mask by bits, immediate
2898//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2899
2900class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2901 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2902 RotateShift, pattern>;
2903
2904class ROTQMBIIVecInst<ValueType vectype>:
2905 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002906 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002907
2908class ROTQMBIIRegInst<RegisterClass rclass>:
2909 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002910 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002911
2912multiclass RotateMaskQuadByBitsImm
2913{
2914 def v16i8: ROTQMBIIVecInst<v16i8>;
2915 def v8i16: ROTQMBIIVecInst<v8i16>;
2916 def v4i32: ROTQMBIIVecInst<v4i32>;
2917 def v2i64: ROTQMBIIVecInst<v2i64>;
2918
2919 def r128: ROTQMBIIRegInst<GPRC>;
2920 def r64: ROTQMBIIRegInst<R64C>;
2921}
2922
2923defm ROTQMBII: RotateMaskQuadByBitsImm;
2924
2925//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2926//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002927
2928def ROTMAHv8i16:
2929 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2930 "rotmah\t$rT, $rA, $rB", RotateShift,
2931 [/* see patterns below - $rB must be negated */]>;
2932
Scott Michel97872d32008-02-23 18:41:37 +00002933def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002934 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2935
Scott Michel97872d32008-02-23 18:41:37 +00002936def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002937 (ROTMAHv8i16 VECREG:$rA,
2938 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2939
Scott Michel97872d32008-02-23 18:41:37 +00002940def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002941 (ROTMAHv8i16 VECREG:$rA,
2942 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2943
Scott Michel8b6b4202007-12-04 22:35:58 +00002944def ROTMAHr16:
2945 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2946 "rotmah\t$rT, $rA, $rB", RotateShift,
2947 [/* see patterns below - $rB must be negated */]>;
2948
2949def : Pat<(sra R16C:$rA, R32C:$rB),
2950 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2951
2952def : Pat<(sra R16C:$rA, R16C:$rB),
2953 (ROTMAHr16 R16C:$rA,
2954 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2955
Scott Michel438be252007-12-17 22:32:34 +00002956def : Pat<(sra R16C:$rA, R8C:$rB),
2957 (ROTMAHr16 R16C:$rA,
2958 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2959
Scott Michel8b6b4202007-12-04 22:35:58 +00002960def ROTMAHIv8i16:
2961 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2962 "rotmahi\t$rT, $rA, $val", RotateShift,
2963 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002964 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002965
Scott Michel97872d32008-02-23 18:41:37 +00002966def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002967 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2968
Scott Michel97872d32008-02-23 18:41:37 +00002969def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002970 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2971
Scott Michel8b6b4202007-12-04 22:35:58 +00002972def ROTMAHIr16:
2973 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2974 "rotmahi\t$rT, $rA, $val", RotateShift,
2975 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2976
2977def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2978 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2979
Scott Michel438be252007-12-17 22:32:34 +00002980def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2981 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2982
Scott Michel8b6b4202007-12-04 22:35:58 +00002983def ROTMAv4i32:
2984 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2985 "rotma\t$rT, $rA, $rB", RotateShift,
2986 [/* see patterns below - $rB must be negated */]>;
2987
Scott Michel97872d32008-02-23 18:41:37 +00002988def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002989 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2990
Scott Michel97872d32008-02-23 18:41:37 +00002991def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002992 (ROTMAv4i32 (v4i32 VECREG:$rA),
2993 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2994
Scott Michel97872d32008-02-23 18:41:37 +00002995def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002996 (ROTMAv4i32 (v4i32 VECREG:$rA),
2997 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2998
Scott Michel8b6b4202007-12-04 22:35:58 +00002999def ROTMAr32:
3000 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3001 "rotma\t$rT, $rA, $rB", RotateShift,
3002 [/* see patterns below - $rB must be negated */]>;
3003
3004def : Pat<(sra R32C:$rA, R32C:$rB),
3005 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
3006
3007def : Pat<(sra R32C:$rA, R16C:$rB),
3008 (ROTMAr32 R32C:$rA,
3009 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3010
Scott Michel438be252007-12-17 22:32:34 +00003011def : Pat<(sra R32C:$rA, R8C:$rB),
3012 (ROTMAr32 R32C:$rA,
3013 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3014
Scott Michel67224b22008-06-02 22:18:03 +00003015class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
3016 RRForm<0b01011110000, OOL, IOL,
3017 "rotmai\t$rT, $rA, $val",
3018 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003019
Scott Michel67224b22008-06-02 22:18:03 +00003020class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3021 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3022 [(set (vectype VECREG:$rT),
3023 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003024
Scott Michel67224b22008-06-02 22:18:03 +00003025class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3026 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3027 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003028
Scott Michel67224b22008-06-02 22:18:03 +00003029multiclass RotateMaskAlgebraicImm {
3030 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3031 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3032 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3033 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3034}
Scott Michel8b6b4202007-12-04 22:35:58 +00003035
Scott Michel67224b22008-06-02 22:18:03 +00003036defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00003037
Scott Michel8b6b4202007-12-04 22:35:58 +00003038//===----------------------------------------------------------------------===//
3039// Branch and conditionals:
3040//===----------------------------------------------------------------------===//
3041
3042let isTerminator = 1, isBarrier = 1 in {
3043 // Halt If Equal (r32 preferred slot only, no vector form)
3044 def HEQr32:
3045 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3046 "heq\t$rA, $rB", BranchResolv,
3047 [/* no pattern to match */]>;
3048
3049 def HEQIr32 :
3050 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3051 "heqi\t$rA, $val", BranchResolv,
3052 [/* no pattern to match */]>;
3053
3054 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3055 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3056 def HGTr32:
3057 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3058 "hgt\t$rA, $rB", BranchResolv,
3059 [/* no pattern to match */]>;
3060
Scott Michel06eabde2008-12-27 04:51:36 +00003061 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00003062 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3063 "hgti\t$rA, $val", BranchResolv,
3064 [/* no pattern to match */]>;
3065
3066 def HLGTr32:
3067 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3068 "hlgt\t$rA, $rB", BranchResolv,
3069 [/* no pattern to match */]>;
3070
3071 def HLGTIr32:
3072 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3073 "hlgti\t$rA, $val", BranchResolv,
3074 [/* no pattern to match */]>;
3075}
3076
Scott Michel06eabde2008-12-27 04:51:36 +00003077//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3078// Comparison operators for i8, i16 and i32:
3079//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003080
Scott Michel97872d32008-02-23 18:41:37 +00003081class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3082 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3083 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003084
Scott Michel97872d32008-02-23 18:41:37 +00003085multiclass CmpEqualByte
3086{
3087 def v16i8 :
3088 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3089 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3090 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00003091
Scott Michel97872d32008-02-23 18:41:37 +00003092 def r8 :
3093 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3094 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3095}
Scott Michel8b6b4202007-12-04 22:35:58 +00003096
Scott Michel97872d32008-02-23 18:41:37 +00003097class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3098 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3099 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003100
Scott Michel97872d32008-02-23 18:41:37 +00003101multiclass CmpEqualByteImm
3102{
3103 def v16i8 :
3104 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3105 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3106 v16i8SExt8Imm:$val))]>;
3107 def r8:
3108 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3109 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3110}
Scott Michel8b6b4202007-12-04 22:35:58 +00003111
Scott Michel97872d32008-02-23 18:41:37 +00003112class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3113 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3114 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003115
Scott Michel97872d32008-02-23 18:41:37 +00003116multiclass CmpEqualHalfword
3117{
3118 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3119 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3120 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003121
Scott Michel97872d32008-02-23 18:41:37 +00003122 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3123 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3124}
Scott Michel8b6b4202007-12-04 22:35:58 +00003125
Scott Michel97872d32008-02-23 18:41:37 +00003126class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3127 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3128 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003129
Scott Michel97872d32008-02-23 18:41:37 +00003130multiclass CmpEqualHalfwordImm
3131{
3132 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3133 [(set (v8i16 VECREG:$rT),
3134 (seteq (v8i16 VECREG:$rA),
3135 (v8i16 v8i16SExt10Imm:$val)))]>;
3136 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3137 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3138}
Scott Michel8b6b4202007-12-04 22:35:58 +00003139
Scott Michel97872d32008-02-23 18:41:37 +00003140class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3141 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3142 ByteOp, pattern>;
3143
3144multiclass CmpEqualWord
3145{
3146 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3147 [(set (v4i32 VECREG:$rT),
3148 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3149
3150 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3151 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3152}
3153
3154class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3155 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3156 ByteOp, pattern>;
3157
3158multiclass CmpEqualWordImm
3159{
3160 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3161 [(set (v4i32 VECREG:$rT),
3162 (seteq (v4i32 VECREG:$rA),
3163 (v4i32 v4i32SExt16Imm:$val)))]>;
3164
3165 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3166 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3167}
3168
3169class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3170 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3171 ByteOp, pattern>;
3172
3173multiclass CmpGtrByte
3174{
3175 def v16i8 :
3176 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3177 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3178 (v8i16 VECREG:$rB)))]>;
3179
3180 def r8 :
3181 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3182 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3183}
3184
3185class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3186 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3187 ByteOp, pattern>;
3188
3189multiclass CmpGtrByteImm
3190{
3191 def v16i8 :
3192 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3193 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3194 v16i8SExt8Imm:$val))]>;
3195 def r8:
3196 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003197 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003198}
3199
3200class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3201 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3202 ByteOp, pattern>;
3203
3204multiclass CmpGtrHalfword
3205{
3206 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3207 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3208 (v8i16 VECREG:$rB)))]>;
3209
3210 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3211 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3212}
3213
3214class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3215 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3216 ByteOp, pattern>;
3217
3218multiclass CmpGtrHalfwordImm
3219{
3220 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3221 [(set (v8i16 VECREG:$rT),
3222 (setgt (v8i16 VECREG:$rA),
3223 (v8i16 v8i16SExt10Imm:$val)))]>;
3224 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3225 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3226}
3227
3228class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3229 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3230 ByteOp, pattern>;
3231
3232multiclass CmpGtrWord
3233{
3234 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3235 [(set (v4i32 VECREG:$rT),
3236 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3237
3238 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3239 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3240}
3241
3242class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3243 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3244 ByteOp, pattern>;
3245
3246multiclass CmpGtrWordImm
3247{
3248 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3249 [(set (v4i32 VECREG:$rT),
3250 (setgt (v4i32 VECREG:$rA),
3251 (v4i32 v4i32SExt16Imm:$val)))]>;
3252
3253 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3254 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003255
3256 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3257 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3258 [(set (v4i32 VECREG:$rT),
3259 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3260 (v4i32 v4i32SExt16Imm:$val)))]>;
3261
3262 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
3263 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00003264}
3265
3266class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003267 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003268 ByteOp, pattern>;
3269
3270multiclass CmpLGtrByte
3271{
3272 def v16i8 :
3273 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3274 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3275 (v8i16 VECREG:$rB)))]>;
3276
3277 def r8 :
3278 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3279 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3280}
3281
3282class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003283 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003284 ByteOp, pattern>;
3285
3286multiclass CmpLGtrByteImm
3287{
3288 def v16i8 :
3289 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3290 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3291 v16i8SExt8Imm:$val))]>;
3292 def r8:
3293 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3294 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3295}
3296
3297class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003298 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003299 ByteOp, pattern>;
3300
3301multiclass CmpLGtrHalfword
3302{
3303 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3304 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3305 (v8i16 VECREG:$rB)))]>;
3306
3307 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3308 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3309}
3310
3311class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003312 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003313 ByteOp, pattern>;
3314
3315multiclass CmpLGtrHalfwordImm
3316{
3317 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3318 [(set (v8i16 VECREG:$rT),
3319 (setugt (v8i16 VECREG:$rA),
3320 (v8i16 v8i16SExt10Imm:$val)))]>;
3321 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3322 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3323}
3324
3325class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003326 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003327 ByteOp, pattern>;
3328
3329multiclass CmpLGtrWord
3330{
3331 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3332 [(set (v4i32 VECREG:$rT),
3333 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3334
3335 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3336 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3337}
3338
3339class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003340 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003341 ByteOp, pattern>;
3342
3343multiclass CmpLGtrWordImm
3344{
3345 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3346 [(set (v4i32 VECREG:$rT),
3347 (setugt (v4i32 VECREG:$rA),
3348 (v4i32 v4i32SExt16Imm:$val)))]>;
3349
3350 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003351 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003352}
3353
3354defm CEQB : CmpEqualByte;
3355defm CEQBI : CmpEqualByteImm;
3356defm CEQH : CmpEqualHalfword;
3357defm CEQHI : CmpEqualHalfwordImm;
3358defm CEQ : CmpEqualWord;
3359defm CEQI : CmpEqualWordImm;
3360defm CGTB : CmpGtrByte;
3361defm CGTBI : CmpGtrByteImm;
3362defm CGTH : CmpGtrHalfword;
3363defm CGTHI : CmpGtrHalfwordImm;
3364defm CGT : CmpGtrWord;
3365defm CGTI : CmpGtrWordImm;
3366defm CLGTB : CmpLGtrByte;
3367defm CLGTBI : CmpLGtrByteImm;
3368defm CLGTH : CmpLGtrHalfword;
3369defm CLGTHI : CmpLGtrHalfwordImm;
3370defm CLGT : CmpLGtrWord;
3371defm CLGTI : CmpLGtrWordImm;
3372
Scott Michel53ab7792008-03-10 16:58:52 +00003373//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003374// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3375// define a pattern to generate the right code, as a binary operator
3376// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003377//
Scott Michel06eabde2008-12-27 04:51:36 +00003378// Notes:
3379// 1. This only matches the setcc set of conditionals. Special pattern
3380// matching is used for select conditionals.
3381//
3382// 2. The "DAG" versions of these classes is almost exclusively used for
3383// i64 comparisons. See the tblgen fundamentals documentation for what
3384// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3385// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003386//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003387
Scott Michel53ab7792008-03-10 16:58:52 +00003388class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3389 SPUInstr xorinst, SPUInstr cmpare>:
3390 Pat<(cond rclass:$rA, rclass:$rB),
3391 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3392
3393class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3394 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3395 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3396 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3397
Scott Michel06eabde2008-12-27 04:51:36 +00003398def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003399def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3400
Scott Michel06eabde2008-12-27 04:51:36 +00003401def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003402def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3403
3404def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3405def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003406
3407class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3408 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3409 Pat<(cond rclass:$rA, rclass:$rB),
3410 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3411 (cmpOp2 rclass:$rA, rclass:$rB))>;
3412
3413class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3414 ValueType immtype,
3415 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3416 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3417 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3418 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3419
Scott Michel53ab7792008-03-10 16:58:52 +00003420def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3421def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3422def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3423def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3424def : Pat<(setle R8C:$rA, R8C:$rB),
3425 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3426def : Pat<(setle R8C:$rA, immU8:$imm),
3427 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003428
Scott Michel53ab7792008-03-10 16:58:52 +00003429def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3430def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3431 ORr16, CGTHIr16, CEQHIr16>;
3432def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3433def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3434def : Pat<(setle R16C:$rA, R16C:$rB),
3435 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3436def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3437 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003438
Scott Michel53ab7792008-03-10 16:58:52 +00003439def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3440def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3441 ORr32, CGTIr32, CEQIr32>;
3442def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3443def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3444def : Pat<(setle R32C:$rA, R32C:$rB),
3445 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3446def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3447 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003448
Scott Michel53ab7792008-03-10 16:58:52 +00003449def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3450def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3451def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3452def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3453def : Pat<(setule R8C:$rA, R8C:$rB),
3454 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3455def : Pat<(setule R8C:$rA, immU8:$imm),
3456 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003457
Scott Michel53ab7792008-03-10 16:58:52 +00003458def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3459def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3460 ORr16, CLGTHIr16, CEQHIr16>;
3461def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3462def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3463 CLGTHIr16, CEQHIr16>;
3464def : Pat<(setule R16C:$rA, R16C:$rB),
3465 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003466def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003467 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003468
Scott Michel53ab7792008-03-10 16:58:52 +00003469def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003470def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003471 ORr32, CLGTIr32, CEQIr32>;
3472def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003473def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003474def : Pat<(setule R32C:$rA, R32C:$rB),
3475 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3476def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3477 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003478
Scott Michel53ab7792008-03-10 16:58:52 +00003479//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3480// select conditional patterns:
3481//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3482
3483class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3484 SPUInstr selinstr, SPUInstr cmpare>:
3485 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3486 rclass:$rTrue, rclass:$rFalse),
3487 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003488 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003489
3490class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3491 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3492 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003493 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003494 (selinstr rclass:$rTrue, rclass:$rFalse,
3495 (cmpare rclass:$rA, immpred:$imm))>;
3496
3497def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3498def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3499def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3500def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3501def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3502def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3503
3504def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3505def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3506def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3507def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3508def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3509def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3510
3511def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3512def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3513def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3514def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3515def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3516def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3517
3518class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3519 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3520 SPUInstr cmpOp2>:
3521 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003522 rclass:$rTrue, rclass:$rFalse),
3523 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003524 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3525 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3526
3527class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3528 ValueType inttype,
3529 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3530 SPUInstr cmpOp2>:
3531 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003532 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003533 (selinstr rclass:$rFalse, rclass:$rTrue,
3534 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3535 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3536
3537def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3538def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3539 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3540
3541def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3542def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3543 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3544
3545def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3546def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3547 SELBr32, ORr32, CGTIr32, CEQIr32>;
3548
3549def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3550def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3551 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3552
3553def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3554def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3555 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3556
3557def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3558def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3559 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003560
3561//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003562
3563let isCall = 1,
3564 // All calls clobber the non-callee-saved registers:
3565 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3566 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3567 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3568 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3569 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3570 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3571 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3572 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3573 // All of these instructions use $lr (aka $0)
3574 Uses = [R0] in {
3575 // Branch relative and set link: Used if we actually know that the target
3576 // is within [-32768, 32767] bytes of the target
3577 def BRSL:
3578 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3579 "brsl\t$$lr, $func",
3580 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3581
3582 // Branch absolute and set link: Used if we actually know that the target
3583 // is an absolute address
3584 def BRASL:
3585 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3586 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003587 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003588
3589 // Branch indirect and set link if external data. These instructions are not
3590 // actually generated, matched by an intrinsic:
3591 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3592 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3593 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3594 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3595
3596 // Branch indirect and set link. This is the "X-form" address version of a
3597 // function call
3598 def BISL:
3599 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3600}
3601
Scott Michelae5cbf52008-12-29 03:23:36 +00003602// Support calls to external symbols:
3603def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3604 (BRSL texternalsym:$func)>;
3605
3606def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3607 (BRASL texternalsym:$func)>;
3608
Scott Michel8b6b4202007-12-04 22:35:58 +00003609// Unconditional branches:
3610let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3611 def BR :
3612 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3613 "br\t$dest",
3614 [(br bb:$dest)]>;
3615
3616 // Unconditional, absolute address branch
3617 def BRA:
3618 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3619 "bra\t$dest",
3620 [/* no pattern */]>;
3621
3622 // Indirect branch
3623 def BI:
3624 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3625
Scott Michele0168c12009-01-05 01:34:35 +00003626 // Conditional branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003627 class BRNZInst<dag IOL, list<dag> pattern>:
3628 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3629 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003630
Scott Michel06eabde2008-12-27 04:51:36 +00003631 class BRNZRegInst<RegisterClass rclass>:
3632 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3633 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003634
Scott Michel06eabde2008-12-27 04:51:36 +00003635 class BRNZVecInst<ValueType vectype>:
3636 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3637 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003638
Scott Michel06eabde2008-12-27 04:51:36 +00003639 multiclass BranchNotZero {
3640 def v4i32 : BRNZVecInst<v4i32>;
3641 def r32 : BRNZRegInst<R32C>;
3642 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003643
Scott Michel06eabde2008-12-27 04:51:36 +00003644 defm BRNZ : BranchNotZero;
3645
3646 class BRZInst<dag IOL, list<dag> pattern>:
3647 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3648 BranchResolv, pattern>;
3649
3650 class BRZRegInst<RegisterClass rclass>:
3651 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3652
3653 class BRZVecInst<ValueType vectype>:
3654 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3655
3656 multiclass BranchZero {
3657 def v4i32: BRZVecInst<v4i32>;
3658 def r32: BRZRegInst<R32C>;
3659 }
3660
3661 defm BRZ: BranchZero;
3662
3663 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3664 // be useful:
3665 /*
3666 class BINZInst<dag IOL, list<dag> pattern>:
3667 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3668
3669 class BINZRegInst<RegisterClass rclass>:
3670 BINZInst<(ins rclass:$rA, brtarget:$dest),
3671 [(brcond rclass:$rA, R32C:$dest)]>;
3672
3673 class BINZVecInst<ValueType vectype>:
3674 BINZInst<(ins VECREG:$rA, R32C:$dest),
3675 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3676
3677 multiclass BranchNotZeroIndirect {
3678 def v4i32: BINZVecInst<v4i32>;
3679 def r32: BINZRegInst<R32C>;
3680 }
3681
3682 defm BINZ: BranchNotZeroIndirect;
3683
3684 class BIZInst<dag IOL, list<dag> pattern>:
3685 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3686
3687 class BIZRegInst<RegisterClass rclass>:
3688 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3689
3690 class BIZVecInst<ValueType vectype>:
3691 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3692
3693 multiclass BranchZeroIndirect {
3694 def v4i32: BIZVecInst<v4i32>;
3695 def r32: BIZRegInst<R32C>;
3696 }
3697
3698 defm BIZ: BranchZeroIndirect;
3699 */
3700
3701 class BRHNZInst<dag IOL, list<dag> pattern>:
3702 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3703 pattern>;
3704
3705 class BRHNZRegInst<RegisterClass rclass>:
3706 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3707 [(brcond rclass:$rCond, bb:$dest)]>;
3708
3709 class BRHNZVecInst<ValueType vectype>:
3710 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3711
3712 multiclass BranchNotZeroHalfword {
3713 def v8i16: BRHNZVecInst<v8i16>;
3714 def r16: BRHNZRegInst<R16C>;
3715 }
3716
3717 defm BRHNZ: BranchNotZeroHalfword;
3718
3719 class BRHZInst<dag IOL, list<dag> pattern>:
3720 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3721 pattern>;
3722
3723 class BRHZRegInst<RegisterClass rclass>:
3724 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3725
3726 class BRHZVecInst<ValueType vectype>:
3727 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3728
3729 multiclass BranchZeroHalfword {
3730 def v8i16: BRHZVecInst<v8i16>;
3731 def r16: BRHZRegInst<R16C>;
3732 }
3733
3734 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003735}
3736
Scott Michel394e26d2008-01-17 20:38:41 +00003737//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003738// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003739//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003740
Scott Michel06eabde2008-12-27 04:51:36 +00003741def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3742 (BRHZr16 R16C:$rA, bb:$dest)>;
3743def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3744 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003745
Scott Michel06eabde2008-12-27 04:51:36 +00003746def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3747 (BRZr32 R32C:$rA, bb:$dest)>;
3748def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3749 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003750
Scott Michel97872d32008-02-23 18:41:37 +00003751multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3752{
3753 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3754 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003755
Scott Michel97872d32008-02-23 18:41:37 +00003756 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3757 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3758
3759 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3760 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3761
3762 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3763 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3764}
3765
Scott Michele0168c12009-01-05 01:34:35 +00003766defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3767defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003768
3769multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3770{
3771 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3772 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3773
3774 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3775 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3776
3777 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3778 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3779
3780 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3781 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3782}
3783
Scott Michel06eabde2008-12-27 04:51:36 +00003784defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3785defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003786
3787multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3788 SPUInstr orinst32, SPUInstr brinst32>
3789{
3790 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3791 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3792 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3793 bb:$dest)>;
3794
3795 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3796 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3797 (CEQHr16 R16C:$rA, R16:$rB)),
3798 bb:$dest)>;
3799
3800 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3801 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3802 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3803 bb:$dest)>;
3804
3805 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3806 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3807 (CEQr32 R32C:$rA, R32C:$rB)),
3808 bb:$dest)>;
3809}
3810
Scott Michel06eabde2008-12-27 04:51:36 +00003811defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3812defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003813
3814multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3815{
3816 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3817 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3818
3819 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3820 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3821
3822 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3823 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3824
3825 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3826 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3827}
3828
Scott Michel06eabde2008-12-27 04:51:36 +00003829defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3830defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003831
3832multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3833 SPUInstr orinst32, SPUInstr brinst32>
3834{
3835 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3836 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3837 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3838 bb:$dest)>;
3839
3840 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3841 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3842 (CEQHr16 R16C:$rA, R16:$rB)),
3843 bb:$dest)>;
3844
3845 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3846 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3847 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3848 bb:$dest)>;
3849
3850 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3851 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3852 (CEQr32 R32C:$rA, R32C:$rB)),
3853 bb:$dest)>;
3854}
3855
Scott Michel06eabde2008-12-27 04:51:36 +00003856defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3857defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003858
Scott Michel8b6b4202007-12-04 22:35:58 +00003859let isTerminator = 1, isBarrier = 1 in {
3860 let isReturn = 1 in {
3861 def RET:
3862 RETForm<"bi\t$$lr", [(retflag)]>;
3863 }
3864}
3865
3866//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003867// Single precision floating point instructions
3868//===----------------------------------------------------------------------===//
3869
Scott Michel61895fe2008-12-10 00:15:19 +00003870class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3871 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003872 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003873
Scott Michel61895fe2008-12-10 00:15:19 +00003874class FAVecInst<ValueType vectype>:
3875 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3876 [(set (vectype VECREG:$rT),
Scott Michel4d07fb72008-12-30 23:28:25 +00003877 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003878
Scott Michel61895fe2008-12-10 00:15:19 +00003879multiclass SFPAdd
3880{
3881 def v4f32: FAVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003882 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3883 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003884}
Scott Michel8b6b4202007-12-04 22:35:58 +00003885
Scott Michel61895fe2008-12-10 00:15:19 +00003886defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003887
Scott Michel61895fe2008-12-10 00:15:19 +00003888class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3889 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003890 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003891
Scott Michel61895fe2008-12-10 00:15:19 +00003892class FSVecInst<ValueType vectype>:
3893 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00003894 [(set (vectype VECREG:$rT),
3895 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003896
3897multiclass SFPSub
3898{
3899 def v4f32: FSVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003900 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3901 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003902}
3903
3904defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003905
3906// Floating point reciprocal estimate
Scott Michel8b6b4202007-12-04 22:35:58 +00003907
Scott Michel4d07fb72008-12-30 23:28:25 +00003908class FRESTInst<dag OOL, dag IOL>:
3909 RRForm_1<0b00110111000, OOL, IOL,
3910 "frest\t$rT, $rA", SPrecFP,
3911 [/* no pattern */]>;
3912
3913def FRESTv4f32 :
3914 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3915
3916def FRESTf32 :
3917 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003918
3919// Floating point interpolate (used in conjunction with reciprocal estimate)
3920def FIv4f32 :
3921 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3922 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003923 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003924
3925def FIf32 :
3926 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3927 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003928 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003929
Scott Michel33d73eb2008-11-21 02:56:16 +00003930//--------------------------------------------------------------------------
3931// Basic single precision floating point comparisons:
3932//
3933// Note: There is no support on SPU for single precision NaN. Consequently,
3934// ordered and unordered comparisons are the same.
3935//--------------------------------------------------------------------------
3936
Scott Michel8b6b4202007-12-04 22:35:58 +00003937def FCEQf32 :
3938 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3939 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003940 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3941
3942def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3943 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003944
3945def FCMEQf32 :
3946 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3947 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003948 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3949
3950def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3951 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003952
3953def FCGTf32 :
3954 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3955 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003956 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3957
3958def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3959 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003960
3961def FCMGTf32 :
3962 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3963 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003964 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3965
3966def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3967 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3968
3969//--------------------------------------------------------------------------
3970// Single precision floating point comparisons and SETCC equivalents:
3971//--------------------------------------------------------------------------
3972
3973def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3974def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3975
3976def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3977def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3978
3979def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3980def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3981
3982def : Pat<(setule R32FP:$rA, R32FP:$rB),
3983 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3984def : Pat<(setole R32FP:$rA, R32FP:$rB),
3985 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003986
3987// FP Status and Control Register Write
3988// Why isn't rT a don't care in the ISA?
3989// Should we create a special RRForm_3 for this guy and zero out the rT?
3990def FSCRWf32 :
3991 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3992 "fscrwr\t$rA", SPrecFP,
3993 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3994
3995// FP Status and Control Register Read
3996def FSCRRf32 :
3997 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3998 "fscrrd\t$rT", SPrecFP,
3999 [/* This instruction requires an intrinsic */]>;
4000
4001// llvm instruction space
4002// How do these map onto cell instructions?
4003// fdiv rA rB
4004// frest rC rB # c = 1/b (both lines)
4005// fi rC rB rC
4006// fm rD rA rC # d = a * 1/b
4007// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4008// fma rB rB rC rD # b = b * c + d
4009// = -(d *b -a) * c + d
4010// = a * c - c ( a *b *c - a)
4011
4012// fcopysign (???)
4013
4014// Library calls:
4015// These llvm instructions will actually map to library calls.
4016// All that's needed, then, is to check that the appropriate library is
4017// imported and do a brsl to the proper function name.
4018// frem # fmod(x, y): x - (x/y) * y
4019// (Note: fmod(double, double), fmodf(float,float)
4020// fsqrt?
4021// fsin?
4022// fcos?
4023// Unimplemented SPU instruction space
4024// floating reciprocal absolute square root estimate (frsqest)
4025
4026// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00004027// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00004028// status and control register read
4029
4030//--------------------------------------
4031// Floating point multiply instructions
4032//--------------------------------------
4033
4034def FMv4f32:
4035 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4036 "fm\t$rT, $rA, $rB", SPrecFP,
4037 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
4038 (v4f32 VECREG:$rB)))]>;
4039
4040def FMf32 :
4041 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4042 "fm\t$rT, $rA, $rB", SPrecFP,
4043 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
4044
4045// Floating point multiply and add
4046// e.g. d = c + (a * b)
4047def FMAv4f32:
4048 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4049 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4050 [(set (v4f32 VECREG:$rT),
4051 (fadd (v4f32 VECREG:$rC),
4052 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
4053
4054def FMAf32:
4055 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4056 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4057 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4058
4059// FP multiply and subtract
4060// Subtracts value in rC from product
4061// res = a * b - c
4062def FMSv4f32 :
4063 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4064 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4065 [(set (v4f32 VECREG:$rT),
4066 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
4067 (v4f32 VECREG:$rC)))]>;
4068
4069def FMSf32 :
4070 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4071 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4072 [(set R32FP:$rT,
4073 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
4074
4075// Floating Negative Mulitply and Subtract
4076// Subtracts product from value in rC
4077// res = fneg(fms a b c)
4078// = - (a * b - c)
4079// = c - a * b
4080// NOTE: subtraction order
4081// fsub a b = a - b
Scott Michel06eabde2008-12-27 04:51:36 +00004082// fs a b = b - a?
Scott Michel8b6b4202007-12-04 22:35:58 +00004083def FNMSf32 :
4084 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4085 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4086 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4087
4088def FNMSv4f32 :
4089 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4090 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004091 [(set (v4f32 VECREG:$rT),
4092 (fsub (v4f32 VECREG:$rC),
4093 (fmul (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004094 (v4f32 VECREG:$rB))))]>;
4095
4096//--------------------------------------
4097// Floating Point Conversions
4098// Signed conversions:
4099def CSiFv4f32:
4100 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4101 "csflt\t$rT, $rA, 0", SPrecFP,
4102 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4103
Scott Michel06eabde2008-12-27 04:51:36 +00004104// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00004105def CSiFf32 :
4106 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4107 "csflt\t$rT, $rA, 0", SPrecFP,
4108 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4109
4110// Convert unsigned into to float
4111def CUiFv4f32 :
4112 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4113 "cuflt\t$rT, $rA, 0", SPrecFP,
4114 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4115
4116def CUiFf32 :
4117 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4118 "cuflt\t$rT, $rA, 0", SPrecFP,
4119 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4120
Scott Michel06eabde2008-12-27 04:51:36 +00004121// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004122// Assume that scale = 0
4123
4124def CFUiv4f32 :
4125 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4126 "cfltu\t$rT, $rA, 0", SPrecFP,
4127 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4128
4129def CFUif32 :
4130 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4131 "cfltu\t$rT, $rA, 0", SPrecFP,
4132 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4133
Scott Michel06eabde2008-12-27 04:51:36 +00004134// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004135// Assume that scale = 0
4136
4137def CFSiv4f32 :
4138 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4139 "cflts\t$rT, $rA, 0", SPrecFP,
4140 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4141
4142def CFSif32 :
4143 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4144 "cflts\t$rT, $rA, 0", SPrecFP,
4145 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4146
4147//===----------------------------------------------------------------------==//
4148// Single<->Double precision conversions
4149//===----------------------------------------------------------------------==//
4150
4151// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4152// v4f32, output is v2f64--which goes in the name?)
4153
4154// Floating point extend single to double
4155// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4156// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4157// are ignored).
4158def FESDvec :
4159 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4160 "fesd\t$rT, $rA", SPrecFP,
4161 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4162
4163def FESDf32 :
4164 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4165 "fesd\t$rT, $rA", SPrecFP,
4166 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4167
4168// Floating point round double to single
4169//def FRDSvec :
4170// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4171// "frds\t$rT, $rA,", SPrecFP,
4172// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4173
4174def FRDSf64 :
4175 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4176 "frds\t$rT, $rA", SPrecFP,
4177 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4178
4179//ToDo include anyextend?
4180
4181//===----------------------------------------------------------------------==//
4182// Double precision floating point instructions
4183//===----------------------------------------------------------------------==//
4184def FAf64 :
4185 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4186 "dfa\t$rT, $rA, $rB", DPrecFP,
4187 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4188
4189def FAv2f64 :
4190 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4191 "dfa\t$rT, $rA, $rB", DPrecFP,
4192 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4193
4194def FSf64 :
4195 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4196 "dfs\t$rT, $rA, $rB", DPrecFP,
4197 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4198
4199def FSv2f64 :
4200 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4201 "dfs\t$rT, $rA, $rB", DPrecFP,
4202 [(set (v2f64 VECREG:$rT),
4203 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4204
4205def FMf64 :
4206 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4207 "dfm\t$rT, $rA, $rB", DPrecFP,
4208 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4209
4210def FMv2f64:
4211 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4212 "dfm\t$rT, $rA, $rB", DPrecFP,
4213 [(set (v2f64 VECREG:$rT),
4214 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4215
4216def FMAf64:
4217 RRForm<0b00111010110, (outs R64FP:$rT),
4218 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4219 "dfma\t$rT, $rA, $rB", DPrecFP,
4220 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4221 RegConstraint<"$rC = $rT">,
4222 NoEncode<"$rC">;
4223
4224def FMAv2f64:
4225 RRForm<0b00111010110, (outs VECREG:$rT),
4226 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4227 "dfma\t$rT, $rA, $rB", DPrecFP,
4228 [(set (v2f64 VECREG:$rT),
4229 (fadd (v2f64 VECREG:$rC),
4230 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4231 RegConstraint<"$rC = $rT">,
4232 NoEncode<"$rC">;
4233
4234def FMSf64 :
4235 RRForm<0b10111010110, (outs R64FP:$rT),
4236 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4237 "dfms\t$rT, $rA, $rB", DPrecFP,
4238 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4239 RegConstraint<"$rC = $rT">,
4240 NoEncode<"$rC">;
4241
4242def FMSv2f64 :
4243 RRForm<0b10111010110, (outs VECREG:$rT),
4244 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4245 "dfms\t$rT, $rA, $rB", DPrecFP,
4246 [(set (v2f64 VECREG:$rT),
4247 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4248 (v2f64 VECREG:$rC)))]>;
4249
4250// FNMS: - (a * b - c)
4251// - (a * b) + c => c - (a * b)
4252def FNMSf64 :
4253 RRForm<0b01111010110, (outs R64FP:$rT),
4254 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4255 "dfnms\t$rT, $rA, $rB", DPrecFP,
4256 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4257 RegConstraint<"$rC = $rT">,
4258 NoEncode<"$rC">;
4259
4260def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4261 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4262
4263def FNMSv2f64 :
4264 RRForm<0b01111010110, (outs VECREG:$rT),
4265 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4266 "dfnms\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004267 [(set (v2f64 VECREG:$rT),
4268 (fsub (v2f64 VECREG:$rC),
4269 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004270 (v2f64 VECREG:$rB))))]>,
4271 RegConstraint<"$rC = $rT">,
4272 NoEncode<"$rC">;
4273
4274def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4275 (v2f64 VECREG:$rC))),
4276 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4277
4278// - (a * b + c)
4279// - (a * b) - c
4280def FNMAf64 :
4281 RRForm<0b11111010110, (outs R64FP:$rT),
4282 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4283 "dfnma\t$rT, $rA, $rB", DPrecFP,
4284 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4285 RegConstraint<"$rC = $rT">,
4286 NoEncode<"$rC">;
4287
4288def FNMAv2f64 :
4289 RRForm<0b11111010110, (outs VECREG:$rT),
4290 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4291 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004292 [(set (v2f64 VECREG:$rT),
4293 (fneg (fadd (v2f64 VECREG:$rC),
4294 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004295 (v2f64 VECREG:$rB)))))]>,
4296 RegConstraint<"$rC = $rT">,
4297 NoEncode<"$rC">;
4298
4299//===----------------------------------------------------------------------==//
4300// Floating point negation and absolute value
4301//===----------------------------------------------------------------------==//
4302
4303def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00004304 (XORfnegvec (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004305 (v4f32 (ILHUv4i32 0x8000)))>;
4306
4307def : Pat<(fneg R32FP:$rA),
4308 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4309
4310def : Pat<(fneg (v2f64 VECREG:$rA)),
4311 (XORfnegvec (v2f64 VECREG:$rA),
4312 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4313
4314def : Pat<(fneg R64FP:$rA),
4315 (XORfneg64 R64FP:$rA,
4316 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4317
4318// Floating point absolute value
4319
4320def : Pat<(fabs R32FP:$rA),
4321 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4322
4323def : Pat<(fabs (v4f32 VECREG:$rA)),
4324 (ANDfabsvec (v4f32 VECREG:$rA),
4325 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4326
pingbak2f387e82009-01-26 03:31:40 +00004327def : Pat<(fabs R64FP:$rA),
4328 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4329
4330def : Pat<(fabs (v2f64 VECREG:$rA)),
4331 (ANDfabsvec (v2f64 VECREG:$rA),
4332 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4333
Scott Michel8b6b4202007-12-04 22:35:58 +00004334//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004335// Hint for branch instructions:
4336//===----------------------------------------------------------------------===//
4337
4338/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4339
4340//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004341// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4342// in the odd pipeline)
4343//===----------------------------------------------------------------------===//
4344
Scott Michel97872d32008-02-23 18:41:37 +00004345def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004346 let Pattern = [];
4347
4348 let Inst{0-10} = 0b10000000010;
4349 let Inst{11-17} = 0;
4350 let Inst{18-24} = 0;
4351 let Inst{25-31} = 0;
4352}
4353
Scott Michel97872d32008-02-23 18:41:37 +00004354def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004355 let Pattern = [];
4356
4357 let Inst{0-10} = 0b10000000000;
4358 let Inst{11-17} = 0;
4359 let Inst{18-24} = 0;
4360 let Inst{25-31} = 0;
4361}
4362
4363//===----------------------------------------------------------------------===//
4364// Bit conversions (type conversions between vector/packed types)
4365// NOTE: Promotions are handled using the XS* instructions. Truncation
4366// is not handled.
4367//===----------------------------------------------------------------------===//
4368def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4369def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4370def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4371def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4372def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4373
4374def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4375def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4376def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4377def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4378def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4379
4380def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4381def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4382def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4383def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4384def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4385
4386def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4387def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4388def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4389def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4390def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4391
4392def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4393def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4394def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4395def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4396def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4397
4398def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4399def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4400def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4401def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4402def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4403
4404def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00004405def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004406
4407//===----------------------------------------------------------------------===//
4408// Instruction patterns:
4409//===----------------------------------------------------------------------===//
4410
4411// General 32-bit constants:
4412def : Pat<(i32 imm:$imm),
4413 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4414
4415// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004416def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004417 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4418
4419// General constant 32-bit vectors
4420def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004421 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4422 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004423
Scott Michel438be252007-12-17 22:32:34 +00004424// 8-bit constants
4425def : Pat<(i8 imm:$imm),
4426 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004427
4428//===----------------------------------------------------------------------===//
4429// Call instruction patterns:
4430//===----------------------------------------------------------------------===//
4431// Return void
4432def : Pat<(ret),
4433 (RET)>;
4434
4435//===----------------------------------------------------------------------===//
4436// Zero/Any/Sign extensions
4437//===----------------------------------------------------------------------===//
4438
Scott Michel8b6b4202007-12-04 22:35:58 +00004439// sext 8->32: Sign extend bytes to words
4440def : Pat<(sext_inreg R32C:$rSrc, i8),
4441 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4442
Scott Michel438be252007-12-17 22:32:34 +00004443def : Pat<(i32 (sext R8C:$rSrc)),
4444 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4445
Scott Michel2ef773a2009-01-06 03:36:14 +00004446// sext 8->64: Sign extend bytes to double word
4447def : Pat<(sext_inreg R64C:$rSrc, i8),
4448 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4449
4450def : Pat<(i64 (sext R8C:$rSrc)),
4451 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4452
Scott Michel438be252007-12-17 22:32:34 +00004453// zext 8->16: Zero extend bytes to halfwords
4454def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004455 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004456
Scott Michel438be252007-12-17 22:32:34 +00004457// zext 8->32: Zero extend bytes to words
4458def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004459 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004460
Scott Michel2ef773a2009-01-06 03:36:14 +00004461// zext 8->64: Zero extend bytes to double words
4462def : Pat<(i64 (zext R8C:$rSrc)),
4463 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4464 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4465 0x4),
4466 (ILv4i32 0x0),
4467 (FSMBIv4i32 0x0f0f)))>;
4468
4469// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004470def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004471 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004472
Scott Michel2ef773a2009-01-06 03:36:14 +00004473// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004474def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004475 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004476
Scott Michel2ef773a2009-01-06 03:36:14 +00004477// sext 16->64: Sign extend halfword to double word
4478def : Pat<(sext_inreg R64C:$rSrc, i16),
4479 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4480
4481def : Pat<(sext R16C:$rSrc),
4482 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4483
Scott Michel97872d32008-02-23 18:41:37 +00004484// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004485def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004486 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004487
4488def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004489 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004490
4491def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004492 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004493
4494def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004495 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004496
4497// anyext 16->32: Extend 16->32 bits, irrespective of sign
4498def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004499 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004500
4501//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004502// Truncates:
4503// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4504// above are custom lowered.
4505//===----------------------------------------------------------------------===//
4506
4507def : Pat<(i8 (trunc GPRC:$src)),
4508 (ORi8_v16i8
4509 (SHUFBgprc GPRC:$src, GPRC:$src,
4510 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4511
4512def : Pat<(i8 (trunc R64C:$src)),
4513 (ORi8_v16i8
4514 (SHUFBv2i64_m32
4515 (ORv2i64_i64 R64C:$src),
4516 (ORv2i64_i64 R64C:$src),
4517 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4518
4519def : Pat<(i8 (trunc R32C:$src)),
4520 (ORi8_v16i8
4521 (SHUFBv4i32_m32
4522 (ORv4i32_i32 R32C:$src),
4523 (ORv4i32_i32 R32C:$src),
4524 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4525
4526def : Pat<(i8 (trunc R16C:$src)),
4527 (ORi8_v16i8
4528 (SHUFBv4i32_m32
4529 (ORv8i16_i16 R16C:$src),
4530 (ORv8i16_i16 R16C:$src),
4531 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4532
4533def : Pat<(i16 (trunc GPRC:$src)),
4534 (ORi16_v8i16
4535 (SHUFBgprc GPRC:$src, GPRC:$src,
4536 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4537
4538def : Pat<(i16 (trunc R64C:$src)),
4539 (ORi16_v8i16
4540 (SHUFBv2i64_m32
4541 (ORv2i64_i64 R64C:$src),
4542 (ORv2i64_i64 R64C:$src),
4543 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4544
4545def : Pat<(i16 (trunc R32C:$src)),
4546 (ORi16_v8i16
4547 (SHUFBv4i32_m32
4548 (ORv4i32_i32 R32C:$src),
4549 (ORv4i32_i32 R32C:$src),
4550 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4551
4552def : Pat<(i32 (trunc GPRC:$src)),
4553 (ORi32_v4i32
4554 (SHUFBgprc GPRC:$src, GPRC:$src,
4555 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4556
4557def : Pat<(i32 (trunc R64C:$src)),
4558 (ORi32_v4i32
4559 (SHUFBv2i64_m32
4560 (ORv2i64_i64 R64C:$src),
4561 (ORv2i64_i64 R64C:$src),
4562 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4563
4564//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004565// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004566// low parts in order to load them into a register.
4567//===----------------------------------------------------------------------===//
4568
Scott Michelf9f42e62008-01-29 02:16:57 +00004569def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4570def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4571def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4572def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4573
4574def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4575 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004576 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004577
Scott Michelf9f42e62008-01-29 02:16:57 +00004578def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4579 (SPUlo texternalsym:$in, 0)),
4580 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4581
4582def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4583 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004584 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004585
Scott Michelf9f42e62008-01-29 02:16:57 +00004586def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4587 (SPUlo tconstpool:$in, 0)),
4588 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4589
4590def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4591 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4592
4593def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4594 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4595
4596def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4597 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4598
4599def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4600 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004601
Scott Michel8b6b4202007-12-04 22:35:58 +00004602// Instrinsics:
4603include "CellSDKIntrinsics.td"
Scott Michel4d07fb72008-12-30 23:28:25 +00004604// Various math operator instruction sequences
4605include "SPUMathInstr.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004606// 64-bit "instructions"/support
4607include "SPU64InstrInfo.td"
Scott Michel2ef773a2009-01-06 03:36:14 +00004608// 128-bit "instructions"/support
4609include "SPU128InstrInfo.td"