blob: b9956402d95ad6fb8ceeea0678a73a848cb31018 [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),
708 [(set (vectype VECREG:$rT),
709 (SPUaddx (vectype VECREG:$rA), (vectype VECREG:$rB),
710 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000711 RegConstraint<"$rCarry = $rT">,
712 NoEncode<"$rCarry">;
713
Scott Michel67224b22008-06-02 22:18:03 +0000714class ADDXRegInst<RegisterClass rclass>:
715 ADDXInst<(outs rclass:$rT),
716 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
717 [(set rclass:$rT,
718 (SPUaddx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000719 RegConstraint<"$rCarry = $rT">,
720 NoEncode<"$rCarry">;
721
Scott Michel67224b22008-06-02 22:18:03 +0000722multiclass AddExtended {
723 def v2i64 : ADDXVecInst<v2i64>;
724 def v4i32 : ADDXVecInst<v4i32>;
725 def r64 : ADDXRegInst<R64C>;
726 def r32 : ADDXRegInst<R32C>;
727}
728
729defm ADDX : AddExtended;
730
731// CG: Generate carry for add
732class CGInst<dag OOL, dag IOL, list<dag> pattern>:
733 RRForm<0b01000011000, OOL, IOL,
734 "cg\t$rT, $rA, $rB",
735 IntegerOp, pattern>;
736
737class CGVecInst<ValueType vectype>:
738 CGInst<(outs VECREG:$rT),
739 (ins VECREG:$rA, VECREG:$rB),
740 [(set (vectype VECREG:$rT),
741 (SPUcarry_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
742
743class CGRegInst<RegisterClass rclass>:
744 CGInst<(outs rclass:$rT),
745 (ins rclass:$rA, rclass:$rB),
746 [(set rclass:$rT,
747 (SPUcarry_gen rclass:$rA, rclass:$rB))]>;
748
749multiclass CarryGenerate {
750 def v2i64 : CGVecInst<v2i64>;
751 def v4i32 : CGVecInst<v4i32>;
752 def r64 : CGRegInst<R64C>;
753 def r32 : CGRegInst<R32C>;
754}
755
756defm CG : CarryGenerate;
757
758// SFX: Subract from, extended. This is used in conjunction with BG to subtract
759// with carry (borrow, in this case)
760class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
761 RRForm<0b10000010110, OOL, IOL,
762 "sfx\t$rT, $rA, $rB",
763 IntegerOp, pattern>;
764
765class SFXVecInst<ValueType vectype>:
766 SFXInst<(outs VECREG:$rT),
767 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
768 [(set (vectype VECREG:$rT),
769 (SPUsubx (vectype VECREG:$rA), (vectype VECREG:$rB),
770 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000771 RegConstraint<"$rCarry = $rT">,
772 NoEncode<"$rCarry">;
773
Scott Michel67224b22008-06-02 22:18:03 +0000774class SFXRegInst<RegisterClass rclass>:
775 SFXInst<(outs rclass:$rT),
776 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
777 [(set rclass:$rT,
778 (SPUsubx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
779 RegConstraint<"$rCarry = $rT">,
780 NoEncode<"$rCarry">;
781
782multiclass SubtractExtended {
783 def v2i64 : SFXVecInst<v2i64>;
784 def v4i32 : SFXVecInst<v4i32>;
785 def r64 : SFXRegInst<R64C>;
786 def r32 : SFXRegInst<R32C>;
787}
788
789defm SFX : SubtractExtended;
790
Scott Michel8b6b4202007-12-04 22:35:58 +0000791// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000792class BGInst<dag OOL, dag IOL, list<dag> pattern>:
793 RRForm<0b01000010000, OOL, IOL,
794 "bg\t$rT, $rA, $rB",
795 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000796
Scott Michel67224b22008-06-02 22:18:03 +0000797class BGVecInst<ValueType vectype>:
798 BGInst<(outs VECREG:$rT),
799 (ins VECREG:$rA, VECREG:$rB),
800 [(set (vectype VECREG:$rT),
801 (SPUborrow_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
802
803class BGRegInst<RegisterClass rclass>:
804 BGInst<(outs rclass:$rT),
805 (ins rclass:$rA, rclass:$rB),
806 [(set rclass:$rT,
807 (SPUborrow_gen rclass:$rA, rclass:$rB))]>;
808
809multiclass BorrowGenerate {
810 def v4i32 : BGVecInst<v4i32>;
811 def v2i64 : BGVecInst<v2i64>;
812 def r64 : BGRegInst<R64C>;
813 def r32 : BGRegInst<R32C>;
814}
815
816defm BG : BorrowGenerate;
817
818// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000819def BGXvec:
820 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000821 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000822 "bgx\t$rT, $rA, $rB", IntegerOp,
823 []>,
824 RegConstraint<"$rCarry = $rT">,
825 NoEncode<"$rCarry">;
826
827// Halfword multiply variants:
828// N.B: These can be used to build up larger quantities (16x16 -> 32)
829
830def MPYv8i16:
831 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
832 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000833 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000834
835def MPYr16:
836 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
837 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
838 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
839
Scott Michelae5cbf52008-12-29 03:23:36 +0000840// Unsigned 16-bit multiply:
841
842class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
843 RRForm<0b00110011110, OOL, IOL,
844 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
845 pattern>;
846
Scott Michel8b6b4202007-12-04 22:35:58 +0000847def MPYUv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000848 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000849 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000850
851def MPYUr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000852 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
853 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000854
855def MPYUr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000856 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000857 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000858
Scott Michelae5cbf52008-12-29 03:23:36 +0000859// mpyi: multiply 16 x s10imm -> 32 result.
860
861class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
862 RI10Form<0b00101110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000863 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000864 pattern>;
865
866def MPYIvec:
867 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
868 [(set (v8i16 VECREG:$rT),
869 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000870
871def MPYIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000872 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
873 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000874
875// mpyui: same issues as other multiplies, plus, this doesn't match a
876// pattern... but may be used during target DAG selection or lowering
Scott Michelae5cbf52008-12-29 03:23:36 +0000877
878class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
879 RI10Form<0b10101110, OOL, IOL,
880 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
881 pattern>;
882
Scott Michel8b6b4202007-12-04 22:35:58 +0000883def MPYUIvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000884 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
885 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000886
887def MPYUIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000888 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
889 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000890
891// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michelae5cbf52008-12-29 03:23:36 +0000892class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
893 RRRForm<0b0011, OOL, IOL,
894 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
895 pattern>;
896
Scott Michel8b6b4202007-12-04 22:35:58 +0000897def MPYAvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000898 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
899 [(set (v4i32 VECREG:$rT),
900 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
901 (v8i16 VECREG:$rB)))),
902 (v4i32 VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000903
904def MPYAr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000905 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
906 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
907 R32C:$rC))]>;
908
909def MPYAr32_sext:
910 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
911 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
912 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000913
914def MPYAr32_sextinreg:
Scott Michelae5cbf52008-12-29 03:23:36 +0000915 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
916 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
917 (sext_inreg R32C:$rB, i16)),
918 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000919
920// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michelae5cbf52008-12-29 03:23:36 +0000921class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
922 RRForm<0b10100011110, OOL, IOL,
923 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
924 pattern>;
925
Scott Michel8b6b4202007-12-04 22:35:58 +0000926def MPYHv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000927 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000928 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000929
930def MPYHr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000931 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000932 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000933
934// mpys: multiply high and shift right (returns the top half of
935// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000936
Scott Michel4d07fb72008-12-30 23:28:25 +0000937class MPYSInst<dag OOL, dag IOL>:
938 RRForm<0b11100011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000939 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000940 [/* no pattern */]>;
941
942def MPYSvec:
943 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
944
945def MPYSr16:
946 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000947
948// mpyhh: multiply high-high (returns the 32-bit result from multiplying
949// the top 16 bits of the $rA, $rB)
Scott Michel4d07fb72008-12-30 23:28:25 +0000950
951class MPYHHInst<dag OOL, dag IOL>:
952 RRForm<0b01100011110, OOL, IOL,
953 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
954 [/* no pattern */]>;
955
Scott Michel8b6b4202007-12-04 22:35:58 +0000956def MPYHHv8i16:
Scott Michel4d07fb72008-12-30 23:28:25 +0000957 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000958
959def MPYHHr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000960 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000961
962// mpyhha: Multiply high-high, add to $rT:
Scott Michel8b6b4202007-12-04 22:35:58 +0000963
Scott Michel4d07fb72008-12-30 23:28:25 +0000964class MPYHHAInst<dag OOL, dag IOL>:
965 RRForm<0b01100010110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000966 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000967 [/* no pattern */]>;
968
969def MPYHHAvec:
970 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
971
972def MPYHHAr32:
973 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000974
975// mpyhhu: Multiply high-high, unsigned
Scott Michel8b6b4202007-12-04 22:35:58 +0000976
Scott Michel4d07fb72008-12-30 23:28:25 +0000977class MPYHHUInst<dag OOL, dag IOL>:
978 RRForm<0b01110011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000979 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000980 [/* no pattern */]>;
981
982def MPYHHUvec:
983 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
984
985def MPYHHUr32:
986 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000987
988// mpyhhau: Multiply high-high, unsigned
Scott Michel4d07fb72008-12-30 23:28:25 +0000989
990class MPYHHAUInst<dag OOL, dag IOL>:
991 RRForm<0b01110010110, OOL, IOL,
992 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
993 [/* no pattern */]>;
994
Scott Michel8b6b4202007-12-04 22:35:58 +0000995def MPYHHAUvec:
Scott Michel4d07fb72008-12-30 23:28:25 +0000996 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
997
Scott Michel8b6b4202007-12-04 22:35:58 +0000998def MPYHHAUr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000999 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michelae5cbf52008-12-29 03:23:36 +00001000
1001//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001002// clz: Count leading zeroes
Scott Michelae5cbf52008-12-29 03:23:36 +00001003//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel06eabde2008-12-27 04:51:36 +00001004class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
1005 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
1006 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001007
Scott Michel06eabde2008-12-27 04:51:36 +00001008class CLZRegInst<RegisterClass rclass>:
1009 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel4d07fb72008-12-30 23:28:25 +00001010 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001011
1012class CLZVecInst<ValueType vectype>:
1013 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1014 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1015
1016multiclass CountLeadingZeroes {
1017 def v4i32 : CLZVecInst<v4i32>;
1018 def r32 : CLZRegInst<R32C>;
1019}
1020
1021defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001022
1023// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +00001024//
Scott Michel8b6b4202007-12-04 22:35:58 +00001025// NOTE: This instruction is really a vector instruction, but the custom
1026// lowering code uses it in unorthodox ways to support CTPOP for other
1027// data types!
Scott Michel06eabde2008-12-27 04:51:36 +00001028
Scott Michel8b6b4202007-12-04 22:35:58 +00001029def CNTBv16i8:
1030 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1031 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001032 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001033
1034def CNTBv8i16 :
1035 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1036 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001037 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001038
1039def CNTBv4i32 :
1040 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1041 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001042 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001043
Scott Michel06eabde2008-12-27 04:51:36 +00001044// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1045// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1046// slots 1-3.
1047//
1048// Note: This instruction "pairs" with the fsmb instruction for all of the
1049// various types defined here.
1050//
1051// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1052// a vector or register.
1053
1054class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1055 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1056
1057class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1058 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001059 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001060
1061class GBBVecInst<ValueType vectype>:
1062 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001063 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001064
1065multiclass GatherBitsFromBytes {
1066 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1067 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1068 def v16i8: GBBVecInst<v16i8>;
1069}
1070
1071defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001072
1073// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001074// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1075// and slots 1-3 also set to 0.
1076//
1077// See notes for GBBInst, above.
1078
1079class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1080 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1081 pattern>;
1082
1083class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1084 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001085 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001086
1087class GBHVecInst<ValueType vectype>:
1088 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001089 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001090
1091multiclass GatherBitsHalfword {
1092 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1093 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1094 def v8i16: GBHVecInst<v8i16>;
1095}
1096
1097defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001098
1099// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001100// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1101// as well as slots 1-3.
1102//
1103// See notes for gbb, above.
1104
1105class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1106 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1107 pattern>;
1108
1109class GBRegInst<RegisterClass rclass, ValueType vectype>:
1110 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001111 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001112
1113class GBVecInst<ValueType vectype>:
1114 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001115 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001116
1117multiclass GatherBitsWord {
1118 def v4i32_r32: GBRegInst<R32C, v4i32>;
1119 def v4i32_r16: GBRegInst<R16C, v4i32>;
1120 def v4i32: GBVecInst<v4i32>;
1121}
1122
1123defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001124
1125// avgb: average bytes
1126def AVGB:
1127 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1128 "avgb\t$rT, $rA, $rB", ByteOp,
1129 []>;
1130
1131// absdb: absolute difference of bytes
1132def ABSDB:
1133 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1134 "absdb\t$rT, $rA, $rB", ByteOp,
1135 []>;
1136
1137// sumb: sum bytes into halfwords
1138def SUMB:
1139 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1140 "sumb\t$rT, $rA, $rB", ByteOp,
1141 []>;
1142
1143// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001144class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1145 RRForm_1<0b01101101010, OOL, IOL,
1146 "xsbh\t$rDst, $rSrc",
1147 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001148
Scott Michel67224b22008-06-02 22:18:03 +00001149class XSBHVecInst<ValueType vectype>:
1150 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1151 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001152
Scott Michel2ef773a2009-01-06 03:36:14 +00001153class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel67224b22008-06-02 22:18:03 +00001154 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Michel2ef773a2009-01-06 03:36:14 +00001155 pattern>;
Scott Michel67224b22008-06-02 22:18:03 +00001156
1157multiclass ExtendByteHalfword {
Scott Michel2ef773a2009-01-06 03:36:14 +00001158 def v16i8: XSBHVecInst<v8i16>;
1159 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1160 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1161 def r16: XSBHInRegInst<R16C,
1162 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001163
1164 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1165 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1166 // pattern below). Intentionally doesn't match a pattern because we want the
1167 // sext 8->32 pattern to do the work for us, namely because we need the extra
1168 // XSHWr32.
Scott Michel2ef773a2009-01-06 03:36:14 +00001169 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1170
1171 // Same as the 32-bit version, but for i64
1172 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +00001173}
1174
1175defm XSBH : ExtendByteHalfword;
1176
Scott Michel8b6b4202007-12-04 22:35:58 +00001177// Sign extend halfwords to words:
Scott Michel8b6b4202007-12-04 22:35:58 +00001178
Scott Michel2ef773a2009-01-06 03:36:14 +00001179class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1180 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1181 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001182
Scott Michel2ef773a2009-01-06 03:36:14 +00001183class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1184 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1185 [(set (out_vectype VECREG:$rDest),
1186 (sext (in_vectype VECREG:$rSrc)))]>;
1187
1188class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1189 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1190 pattern>;
1191
1192class XSHWRegInst<RegisterClass rclass>:
1193 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1194 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1195
1196multiclass ExtendHalfwordWord {
1197 def v4i32: XSHWVecInst<v4i32, v8i16>;
1198
1199 def r16: XSHWRegInst<R32C>;
1200
1201 def r32: XSHWInRegInst<R32C,
1202 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1203 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1204}
1205
1206defm XSHW : ExtendHalfwordWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001207
Scott Michele0168c12009-01-05 01:34:35 +00001208// Sign-extend words to doublewords (32->64 bits)
Scott Michel8b6b4202007-12-04 22:35:58 +00001209
Scott Michele0168c12009-01-05 01:34:35 +00001210class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel2ef773a2009-01-06 03:36:14 +00001211 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1212 IntegerOp, pattern>;
Scott Michele0168c12009-01-05 01:34:35 +00001213
1214class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1215 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1216 [(set (out_vectype VECREG:$rDst),
1217 (sext (out_vectype VECREG:$rSrc)))]>;
1218
1219class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1220 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1221 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1222
1223multiclass ExtendWordToDoubleWord {
1224 def v2i64: XSWDVecInst<v4i32, v2i64>;
1225 def r64: XSWDRegInst<R32C, R64C>;
1226
1227 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1228 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1229}
Scott Michel8b6b4202007-12-04 22:35:58 +00001230
Scott Michele0168c12009-01-05 01:34:35 +00001231defm XSWD : ExtendWordToDoubleWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001232
1233// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001234
Scott Michel97872d32008-02-23 18:41:37 +00001235class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1236 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1237 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001238
Scott Michel97872d32008-02-23 18:41:37 +00001239class ANDVecInst<ValueType vectype>:
1240 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1241 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1242 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001243
Scott Michel6baba072008-03-05 23:02:02 +00001244class ANDRegInst<RegisterClass rclass>:
1245 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1246 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1247
Scott Michel97872d32008-02-23 18:41:37 +00001248multiclass BitwiseAnd
1249{
1250 def v16i8: ANDVecInst<v16i8>;
1251 def v8i16: ANDVecInst<v8i16>;
1252 def v4i32: ANDVecInst<v4i32>;
1253 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001254
Scott Michel6baba072008-03-05 23:02:02 +00001255 def r128: ANDRegInst<GPRC>;
1256 def r64: ANDRegInst<R64C>;
1257 def r32: ANDRegInst<R32C>;
1258 def r16: ANDRegInst<R16C>;
1259 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001260
Scott Michel97872d32008-02-23 18:41:37 +00001261 //===---------------------------------------------
1262 // Special instructions to perform the fabs instruction
1263 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1264 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001265
Scott Michel97872d32008-02-23 18:41:37 +00001266 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1267 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001268
Scott Michel97872d32008-02-23 18:41:37 +00001269 // Could use v4i32, but won't for clarity
1270 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1271 [/* Intentionally does not match a pattern */]>;
1272
1273 //===---------------------------------------------
1274
1275 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1276 // quantities -- see 16->32 zext pattern.
1277 //
1278 // This pattern is somewhat artificial, since it might match some
1279 // compiler generated pattern but it is unlikely to do so.
1280
1281 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1282 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1283}
1284
1285defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001286
1287// N.B.: vnot_conv is one of those special target selection pattern fragments,
1288// in which we expect there to be a bit_convert on the constant. Bear in mind
1289// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1290// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001291
Scott Michel97872d32008-02-23 18:41:37 +00001292class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1293 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1294 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001295
Scott Michel97872d32008-02-23 18:41:37 +00001296class ANDCVecInst<ValueType vectype>:
1297 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1298 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1299 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001300
Scott Michel97872d32008-02-23 18:41:37 +00001301class ANDCRegInst<RegisterClass rclass>:
1302 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1303 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001304
Scott Michel97872d32008-02-23 18:41:37 +00001305multiclass AndComplement
1306{
1307 def v16i8: ANDCVecInst<v16i8>;
1308 def v8i16: ANDCVecInst<v8i16>;
1309 def v4i32: ANDCVecInst<v4i32>;
1310 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001311
Scott Michel97872d32008-02-23 18:41:37 +00001312 def r128: ANDCRegInst<GPRC>;
1313 def r64: ANDCRegInst<R64C>;
1314 def r32: ANDCRegInst<R32C>;
1315 def r16: ANDCRegInst<R16C>;
1316 def r8: ANDCRegInst<R8C>;
1317}
Scott Michel438be252007-12-17 22:32:34 +00001318
Scott Michel97872d32008-02-23 18:41:37 +00001319defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001320
Scott Michel97872d32008-02-23 18:41:37 +00001321class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1322 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001323 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001324
Scott Michel97872d32008-02-23 18:41:37 +00001325multiclass AndByteImm
1326{
1327 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1328 [(set (v16i8 VECREG:$rT),
1329 (and (v16i8 VECREG:$rA),
1330 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001331
Scott Michel97872d32008-02-23 18:41:37 +00001332 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1333 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1334}
Scott Michel438be252007-12-17 22:32:34 +00001335
Scott Michel97872d32008-02-23 18:41:37 +00001336defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001337
Scott Michel97872d32008-02-23 18:41:37 +00001338class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1339 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001340 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001341
Scott Michel97872d32008-02-23 18:41:37 +00001342multiclass AndHalfwordImm
1343{
1344 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1345 [(set (v8i16 VECREG:$rT),
1346 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001347
Scott Michel97872d32008-02-23 18:41:37 +00001348 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1349 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001350
Scott Michel97872d32008-02-23 18:41:37 +00001351 // Zero-extend i8 to i16:
1352 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1353 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1354}
Scott Michel8b6b4202007-12-04 22:35:58 +00001355
Scott Michel97872d32008-02-23 18:41:37 +00001356defm ANDHI : AndHalfwordImm;
1357
1358class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1359 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1360 IntegerOp, pattern>;
1361
1362multiclass AndWordImm
1363{
1364 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1365 [(set (v4i32 VECREG:$rT),
1366 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1367
1368 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1369 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1370
1371 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1372 // pattern below.
1373 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1374 [(set R32C:$rT,
1375 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1376
1377 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1378 // zext 16->32 pattern below.
1379 //
1380 // Note that this pattern is somewhat artificial, since it might match
1381 // something the compiler generates but is unlikely to occur in practice.
1382 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1383 [(set R32C:$rT,
1384 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1385}
1386
1387defm ANDI : AndWordImm;
1388
1389//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001390// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001391//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1392
Scott Michel8b6b4202007-12-04 22:35:58 +00001393// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001394class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1395 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1396 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001397
Scott Michel97872d32008-02-23 18:41:37 +00001398class ORVecInst<ValueType vectype>:
1399 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1400 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1401 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001402
Scott Michel97872d32008-02-23 18:41:37 +00001403class ORRegInst<RegisterClass rclass>:
1404 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1405 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001406
Scott Michel06eabde2008-12-27 04:51:36 +00001407// ORCvtForm: OR conversion form
1408//
1409// This is used to "convert" the preferred slot to its vector equivalent, as
1410// well as convert a vector back to its preferred slot.
1411//
1412// These are effectively no-ops, but need to exist for proper type conversion
1413// and type coercion.
1414
1415class ORCvtForm<dag OOL, dag IOL>
1416 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1417 bits<7> RA;
1418 bits<7> RT;
1419
1420 let Pattern = [/* no pattern */];
1421
1422 let Inst{0-10} = 0b10000010000;
1423 let Inst{11-17} = RA;
1424 let Inst{18-24} = RA;
1425 let Inst{25-31} = RT;
1426}
1427
Scott Michel97872d32008-02-23 18:41:37 +00001428class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001429 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001430
Scott Michel97872d32008-02-23 18:41:37 +00001431class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001432 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1433
1434class ORCvtRegGPRC<RegisterClass rclass>:
1435 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>;
1436
1437class ORCvtVecGPRC:
1438 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
1439
1440class ORCvtGPRCReg<RegisterClass rclass>:
1441 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001442
1443class ORCvtFormR32Reg<RegisterClass rclass>:
1444 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA)>;
1445
1446class ORCvtFormRegR32<RegisterClass rclass>:
1447 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA)>;
1448
1449class ORCvtFormR64Reg<RegisterClass rclass>:
1450 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA)>;
1451
1452class ORCvtFormRegR64<RegisterClass rclass>:
1453 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA)>;
Scott Michel06eabde2008-12-27 04:51:36 +00001454
1455class ORCvtGPRCVec:
1456 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001457
Scott Michel97872d32008-02-23 18:41:37 +00001458multiclass BitwiseOr
1459{
1460 def v16i8: ORVecInst<v16i8>;
1461 def v8i16: ORVecInst<v8i16>;
1462 def v4i32: ORVecInst<v4i32>;
1463 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001464
Scott Michel97872d32008-02-23 18:41:37 +00001465 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1466 [(set (v4f32 VECREG:$rT),
1467 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1468 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001469
Scott Michel97872d32008-02-23 18:41:37 +00001470 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001471 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001472 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1473 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001474
Scott Michel97872d32008-02-23 18:41:37 +00001475 def r64: ORRegInst<R64C>;
1476 def r32: ORRegInst<R32C>;
1477 def r16: ORRegInst<R16C>;
1478 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001479
Scott Michel97872d32008-02-23 18:41:37 +00001480 // OR instructions used to copy f32 and f64 registers.
1481 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1482 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001483
Scott Michel97872d32008-02-23 18:41:37 +00001484 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1485 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001486
Scott Michel4d07fb72008-12-30 23:28:25 +00001487 // scalar->vector promotion, prefslot2vec:
Scott Michel97872d32008-02-23 18:41:37 +00001488 def v16i8_i8: ORPromoteScalar<R8C>;
1489 def v8i16_i16: ORPromoteScalar<R16C>;
1490 def v4i32_i32: ORPromoteScalar<R32C>;
1491 def v2i64_i64: ORPromoteScalar<R64C>;
1492 def v4f32_f32: ORPromoteScalar<R32FP>;
1493 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001494
Scott Michel4d07fb72008-12-30 23:28:25 +00001495 // vector->scalar demotion, vec2prefslot:
Scott Michel97872d32008-02-23 18:41:37 +00001496 def i8_v16i8: ORExtractElt<R8C>;
1497 def i16_v8i16: ORExtractElt<R16C>;
1498 def i32_v4i32: ORExtractElt<R32C>;
1499 def i64_v2i64: ORExtractElt<R64C>;
1500 def f32_v4f32: ORExtractElt<R32FP>;
1501 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001502
1503 // Conversion from GPRC to register
1504 def i128_r64: ORCvtRegGPRC<R64C>;
1505 def i128_f64: ORCvtRegGPRC<R64FP>;
1506 def i128_r32: ORCvtRegGPRC<R32C>;
1507 def i128_f32: ORCvtRegGPRC<R32FP>;
1508 def i128_r16: ORCvtRegGPRC<R16C>;
1509 def i128_r8: ORCvtRegGPRC<R8C>;
1510
1511 // Conversion from GPRC to vector
1512 def i128_vec: ORCvtVecGPRC;
1513
1514 // Conversion from register to GPRC
1515 def r64_i128: ORCvtGPRCReg<R64C>;
1516 def f64_i128: ORCvtGPRCReg<R64FP>;
1517 def r32_i128: ORCvtGPRCReg<R32C>;
1518 def f32_i128: ORCvtGPRCReg<R32FP>;
1519 def r16_i128: ORCvtGPRCReg<R16C>;
1520 def r8_i128: ORCvtGPRCReg<R8C>;
1521
1522 // Conversion from vector to GPRC
1523 def vec_i128: ORCvtGPRCVec;
Scott Michel2ef773a2009-01-06 03:36:14 +00001524
1525 // Conversion from register to R32C:
1526 def r16_r32: ORCvtFormRegR32<R16C>;
1527 def r8_r32: ORCvtFormRegR32<R8C>;
1528
1529 // Conversion from R32C to register
1530 def r32_r16: ORCvtFormR32Reg<R16C>;
1531 def r32_r8: ORCvtFormR32Reg<R8C>;
1532
1533 // Conversion from register to R64C:
1534 def r32_r64: ORCvtFormR64Reg<R32C>;
1535 def r16_r64: ORCvtFormR64Reg<R16C>;
1536 def r8_r64: ORCvtFormR64Reg<R8C>;
1537
1538 // Conversion from R64C to register
1539 def r64_r32: ORCvtFormRegR64<R32C>;
1540 def r64_r16: ORCvtFormRegR64<R16C>;
1541 def r64_r8: ORCvtFormRegR64<R8C>;
Scott Michel97872d32008-02-23 18:41:37 +00001542}
Scott Michel438be252007-12-17 22:32:34 +00001543
Scott Michel97872d32008-02-23 18:41:37 +00001544defm OR : BitwiseOr;
1545
Scott Michel06eabde2008-12-27 04:51:36 +00001546// scalar->vector promotion patterns (preferred slot to vector):
1547def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1548 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001549
Scott Michel06eabde2008-12-27 04:51:36 +00001550def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1551 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001552
Scott Michel06eabde2008-12-27 04:51:36 +00001553def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1554 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001555
Scott Michel06eabde2008-12-27 04:51:36 +00001556def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1557 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001558
Scott Michel06eabde2008-12-27 04:51:36 +00001559def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1560 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001561
Scott Michel06eabde2008-12-27 04:51:36 +00001562def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1563 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001564
Scott Michel06eabde2008-12-27 04:51:36 +00001565// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1566// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001567
Scott Michelc630c412008-11-24 17:11:17 +00001568def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001569 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001570
Scott Michelc630c412008-11-24 17:11:17 +00001571def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001572 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001573
Scott Michelc630c412008-11-24 17:11:17 +00001574def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001575 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001576
Scott Michelc630c412008-11-24 17:11:17 +00001577def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001578 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001579
Scott Michelc630c412008-11-24 17:11:17 +00001580def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001581 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001582
Scott Michelc630c412008-11-24 17:11:17 +00001583def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001584 (ORf64_v2f64 VECREG:$rA)>;
1585
1586// Load Register: This is an assembler alias for a bitwise OR of a register
1587// against itself. It's here because it brings some clarity to assembly
1588// language output.
1589
1590let hasCtrlDep = 1 in {
1591 class LRInst<dag OOL, dag IOL>
1592 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1593 bits<7> RA;
1594 bits<7> RT;
1595
1596 let Pattern = [/*no pattern*/];
1597
1598 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1599 let Inst{11-17} = RA;
1600 let Inst{18-24} = RA;
1601 let Inst{25-31} = RT;
1602 }
1603
1604 class LRVecInst<ValueType vectype>:
1605 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1606
1607 class LRRegInst<RegisterClass rclass>:
1608 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1609
1610 multiclass LoadRegister {
1611 def v2i64: LRVecInst<v2i64>;
1612 def v2f64: LRVecInst<v2f64>;
1613 def v4i32: LRVecInst<v4i32>;
1614 def v4f32: LRVecInst<v4f32>;
1615 def v8i16: LRVecInst<v8i16>;
1616 def v16i8: LRVecInst<v16i8>;
1617
1618 def r128: LRRegInst<GPRC>;
1619 def r64: LRRegInst<R64C>;
1620 def f64: LRRegInst<R64FP>;
1621 def r32: LRRegInst<R32C>;
1622 def f32: LRRegInst<R32FP>;
1623 def r16: LRRegInst<R16C>;
1624 def r8: LRRegInst<R8C>;
1625 }
1626
1627 defm LR: LoadRegister;
1628}
Scott Michel8b6b4202007-12-04 22:35:58 +00001629
Scott Michel97872d32008-02-23 18:41:37 +00001630// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001631
Scott Michel97872d32008-02-23 18:41:37 +00001632class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1633 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1634 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001635
Scott Michel97872d32008-02-23 18:41:37 +00001636class ORCVecInst<ValueType vectype>:
1637 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1638 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1639 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001640
Scott Michel97872d32008-02-23 18:41:37 +00001641class ORCRegInst<RegisterClass rclass>:
1642 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1643 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001644
Scott Michel97872d32008-02-23 18:41:37 +00001645multiclass BitwiseOrComplement
1646{
1647 def v16i8: ORCVecInst<v16i8>;
1648 def v8i16: ORCVecInst<v8i16>;
1649 def v4i32: ORCVecInst<v4i32>;
1650 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001651
Scott Michel97872d32008-02-23 18:41:37 +00001652 def r64: ORCRegInst<R64C>;
1653 def r32: ORCRegInst<R32C>;
1654 def r16: ORCRegInst<R16C>;
1655 def r8: ORCRegInst<R8C>;
1656}
1657
1658defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001659
Scott Michel8b6b4202007-12-04 22:35:58 +00001660// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001661class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1662 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1663 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001664
Scott Michel97872d32008-02-23 18:41:37 +00001665class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1666 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1667 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1668 (vectype immpred:$val)))]>;
1669
1670multiclass BitwiseOrByteImm
1671{
1672 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1673
1674 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1675 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1676}
1677
1678defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001679
Scott Michel8b6b4202007-12-04 22:35:58 +00001680// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001681class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1682 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1683 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001684
Scott Michel97872d32008-02-23 18:41:37 +00001685class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1686 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1687 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1688 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001689
Scott Michel97872d32008-02-23 18:41:37 +00001690multiclass BitwiseOrHalfwordImm
1691{
1692 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1693
1694 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1695 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1696
1697 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1698 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1699 [(set R16C:$rT, (or (anyext R8C:$rA),
1700 i16ImmSExt10:$val))]>;
1701}
1702
1703defm ORHI : BitwiseOrHalfwordImm;
1704
1705class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1706 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1707 IntegerOp, pattern>;
1708
1709class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1710 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1711 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1712 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001713
1714// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001715multiclass BitwiseOrImm
1716{
1717 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001718
Scott Michel97872d32008-02-23 18:41:37 +00001719 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1720 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001721
Scott Michel97872d32008-02-23 18:41:37 +00001722 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1723 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1724 // infra "anyext 16->32" pattern.)
1725 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1726 [(set R32C:$rT, (or (anyext R16C:$rA),
1727 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001728
Scott Michel97872d32008-02-23 18:41:37 +00001729 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1730 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1731 // infra "anyext 16->32" pattern.)
1732 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1733 [(set R32C:$rT, (or (anyext R8C:$rA),
1734 i32ImmSExt10:$val))]>;
1735}
Scott Michel8b6b4202007-12-04 22:35:58 +00001736
Scott Michel97872d32008-02-23 18:41:37 +00001737defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001738
Scott Michel8b6b4202007-12-04 22:35:58 +00001739// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1740// $rT[0], slots 1-3 are zeroed.
1741//
Scott Michel438be252007-12-17 22:32:34 +00001742// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001743def ORXv4i32:
1744 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1745 "orx\t$rT, $rA, $rB", IntegerOp,
1746 []>;
1747
Scott Michel438be252007-12-17 22:32:34 +00001748// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001749
Scott Michel6baba072008-03-05 23:02:02 +00001750class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1751 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1752 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001753
Scott Michel6baba072008-03-05 23:02:02 +00001754class XORVecInst<ValueType vectype>:
1755 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1756 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1757 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001758
Scott Michel6baba072008-03-05 23:02:02 +00001759class XORRegInst<RegisterClass rclass>:
1760 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1761 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1762
1763multiclass BitwiseExclusiveOr
1764{
1765 def v16i8: XORVecInst<v16i8>;
1766 def v8i16: XORVecInst<v8i16>;
1767 def v4i32: XORVecInst<v4i32>;
1768 def v2i64: XORVecInst<v2i64>;
1769
1770 def r128: XORRegInst<GPRC>;
1771 def r64: XORRegInst<R64C>;
1772 def r32: XORRegInst<R32C>;
1773 def r16: XORRegInst<R16C>;
1774 def r8: XORRegInst<R8C>;
1775
1776 // Special forms for floating point instructions.
1777 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1778
1779 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1780 [/* no pattern */]>;
1781
1782 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1783 [/* no pattern */]>;
1784
1785 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1786 [/* no pattern, see fneg{32,64} */]>;
1787}
1788
1789defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001790
1791//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001792
Scott Michel97872d32008-02-23 18:41:37 +00001793class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1794 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1795 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001796
Scott Michel97872d32008-02-23 18:41:37 +00001797multiclass XorByteImm
1798{
1799 def v16i8:
1800 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1801 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1802
1803 def r8:
1804 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1805 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1806}
1807
1808defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001809
Scott Michel8b6b4202007-12-04 22:35:58 +00001810def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001811 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001812 "xorhi\t$rT, $rA, $val", IntegerOp,
1813 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1814 v8i16SExt10Imm:$val))]>;
1815
1816def XORHIr16:
1817 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1818 "xorhi\t$rT, $rA, $val", IntegerOp,
1819 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1820
1821def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001822 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001823 "xori\t$rT, $rA, $val", IntegerOp,
1824 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1825 v4i32SExt10Imm:$val))]>;
1826
1827def XORIr32:
1828 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1829 "xori\t$rT, $rA, $val", IntegerOp,
1830 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1831
1832// NAND:
1833def NANDv16i8:
1834 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1835 "nand\t$rT, $rA, $rB", IntegerOp,
1836 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1837 (v16i8 VECREG:$rB))))]>;
1838
1839def NANDv8i16:
1840 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1841 "nand\t$rT, $rA, $rB", IntegerOp,
1842 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1843 (v8i16 VECREG:$rB))))]>;
1844
1845def NANDv4i32:
1846 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1847 "nand\t$rT, $rA, $rB", IntegerOp,
1848 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1849 (v4i32 VECREG:$rB))))]>;
1850
1851def NANDr32:
1852 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1853 "nand\t$rT, $rA, $rB", IntegerOp,
1854 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1855
1856def NANDr16:
1857 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1858 "nand\t$rT, $rA, $rB", IntegerOp,
1859 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1860
Scott Michel438be252007-12-17 22:32:34 +00001861def NANDr8:
1862 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1863 "nand\t$rT, $rA, $rB", IntegerOp,
1864 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1865
Scott Michel8b6b4202007-12-04 22:35:58 +00001866// NOR:
1867def NORv16i8:
1868 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1869 "nor\t$rT, $rA, $rB", IntegerOp,
1870 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1871 (v16i8 VECREG:$rB))))]>;
1872
1873def NORv8i16:
1874 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1875 "nor\t$rT, $rA, $rB", IntegerOp,
1876 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1877 (v8i16 VECREG:$rB))))]>;
1878
1879def NORv4i32:
1880 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1881 "nor\t$rT, $rA, $rB", IntegerOp,
1882 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1883 (v4i32 VECREG:$rB))))]>;
1884
1885def NORr32:
1886 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1887 "nor\t$rT, $rA, $rB", IntegerOp,
1888 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1889
1890def NORr16:
1891 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1892 "nor\t$rT, $rA, $rB", IntegerOp,
1893 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1894
Scott Michel438be252007-12-17 22:32:34 +00001895def NORr8:
1896 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1897 "nor\t$rT, $rA, $rB", IntegerOp,
1898 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1899
Scott Michel8b6b4202007-12-04 22:35:58 +00001900// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001901class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1902 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1903 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001904
Scott Michel6baba072008-03-05 23:02:02 +00001905class SELBVecInst<ValueType vectype>:
1906 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1907 [(set (vectype VECREG:$rT),
1908 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1909 (and (vnot (vectype VECREG:$rC)),
1910 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001911
Scott Michel4d07fb72008-12-30 23:28:25 +00001912class SELBVecVCondInst<ValueType vectype>:
1913 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1914 [(set (vectype VECREG:$rT),
1915 (select (vectype VECREG:$rC),
1916 (vectype VECREG:$rB),
1917 (vectype VECREG:$rA)))]>;
1918
Scott Michel06eabde2008-12-27 04:51:36 +00001919class SELBVecCondInst<ValueType vectype>:
1920 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1921 [(set (vectype VECREG:$rT),
1922 (select R32C:$rC,
1923 (vectype VECREG:$rB),
1924 (vectype VECREG:$rA)))]>;
1925
Scott Michel6baba072008-03-05 23:02:02 +00001926class SELBRegInst<RegisterClass rclass>:
1927 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1928 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001929 (or (and rclass:$rB, rclass:$rC),
1930 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001931
Scott Michel06eabde2008-12-27 04:51:36 +00001932class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1933 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1934 [(set rclass:$rT,
1935 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1936
Scott Michel6baba072008-03-05 23:02:02 +00001937multiclass SelectBits
1938{
1939 def v16i8: SELBVecInst<v16i8>;
1940 def v8i16: SELBVecInst<v8i16>;
1941 def v4i32: SELBVecInst<v4i32>;
1942 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001943
Scott Michel6baba072008-03-05 23:02:02 +00001944 def r128: SELBRegInst<GPRC>;
1945 def r64: SELBRegInst<R64C>;
1946 def r32: SELBRegInst<R32C>;
1947 def r16: SELBRegInst<R16C>;
1948 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001949
1950 def v16i8_cond: SELBVecCondInst<v16i8>;
1951 def v8i16_cond: SELBVecCondInst<v8i16>;
1952 def v4i32_cond: SELBVecCondInst<v4i32>;
1953 def v2i64_cond: SELBVecCondInst<v2i64>;
1954
Scott Michel4d07fb72008-12-30 23:28:25 +00001955 def v16i8_vcond: SELBVecCondInst<v16i8>;
1956 def v8i16_vcond: SELBVecCondInst<v8i16>;
1957 def v4i32_vcond: SELBVecCondInst<v4i32>;
1958 def v2i64_vcond: SELBVecCondInst<v2i64>;
1959
1960 def v4f32_cond:
1961 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1962 [(set (v4f32 VECREG:$rT),
1963 (select (v4i32 VECREG:$rC),
1964 (v4f32 VECREG:$rB),
1965 (v4f32 VECREG:$rA)))]>;
1966
Scott Michel06eabde2008-12-27 04:51:36 +00001967 // SELBr64_cond is defined further down, look for i64 comparisons
1968 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001969 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001970 def r16_cond: SELBRegCondInst<R16C, R16C>;
1971 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001972}
Scott Michel8b6b4202007-12-04 22:35:58 +00001973
Scott Michel6baba072008-03-05 23:02:02 +00001974defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001975
Scott Michel56a125e2008-11-22 23:50:42 +00001976class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001977 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1978 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001979
Scott Michel56a125e2008-11-22 23:50:42 +00001980def : SPUselbPatVec<v16i8, SELBv16i8>;
1981def : SPUselbPatVec<v8i16, SELBv8i16>;
1982def : SPUselbPatVec<v4i32, SELBv4i32>;
1983def : SPUselbPatVec<v2i64, SELBv2i64>;
1984
1985class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1986 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1987 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1988
1989def : SPUselbPatReg<R8C, SELBr8>;
1990def : SPUselbPatReg<R16C, SELBr16>;
1991def : SPUselbPatReg<R32C, SELBr32>;
1992def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001993
Scott Michel6baba072008-03-05 23:02:02 +00001994// EQV: Equivalence (1 for each same bit, otherwise 0)
1995//
1996// Note: There are a lot of ways to match this bit operator and these patterns
1997// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001998
Scott Michel6baba072008-03-05 23:02:02 +00001999class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2000 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2001 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002002
Scott Michel6baba072008-03-05 23:02:02 +00002003class EQVVecInst<ValueType vectype>:
2004 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2005 [(set (vectype VECREG:$rT),
2006 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2007 (and (vnot (vectype VECREG:$rA)),
2008 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002009
Scott Michel6baba072008-03-05 23:02:02 +00002010class EQVRegInst<RegisterClass rclass>:
2011 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2012 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2013 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002014
Scott Michel6baba072008-03-05 23:02:02 +00002015class EQVVecPattern1<ValueType vectype>:
2016 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2017 [(set (vectype VECREG:$rT),
2018 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002019
Scott Michel6baba072008-03-05 23:02:02 +00002020class EQVRegPattern1<RegisterClass rclass>:
2021 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2022 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002023
Scott Michel6baba072008-03-05 23:02:02 +00002024class EQVVecPattern2<ValueType vectype>:
2025 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2026 [(set (vectype VECREG:$rT),
2027 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2028 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002029
Scott Michel6baba072008-03-05 23:02:02 +00002030class EQVRegPattern2<RegisterClass rclass>:
2031 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2032 [(set rclass:$rT,
2033 (or (and rclass:$rA, rclass:$rB),
2034 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002035
Scott Michel6baba072008-03-05 23:02:02 +00002036class EQVVecPattern3<ValueType vectype>:
2037 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2038 [(set (vectype VECREG:$rT),
2039 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002040
Scott Michel6baba072008-03-05 23:02:02 +00002041class EQVRegPattern3<RegisterClass rclass>:
2042 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2043 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002044
Scott Michel6baba072008-03-05 23:02:02 +00002045multiclass BitEquivalence
2046{
2047 def v16i8: EQVVecInst<v16i8>;
2048 def v8i16: EQVVecInst<v8i16>;
2049 def v4i32: EQVVecInst<v4i32>;
2050 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002051
Scott Michel6baba072008-03-05 23:02:02 +00002052 def v16i8_1: EQVVecPattern1<v16i8>;
2053 def v8i16_1: EQVVecPattern1<v8i16>;
2054 def v4i32_1: EQVVecPattern1<v4i32>;
2055 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002056
Scott Michel6baba072008-03-05 23:02:02 +00002057 def v16i8_2: EQVVecPattern2<v16i8>;
2058 def v8i16_2: EQVVecPattern2<v8i16>;
2059 def v4i32_2: EQVVecPattern2<v4i32>;
2060 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002061
Scott Michel6baba072008-03-05 23:02:02 +00002062 def v16i8_3: EQVVecPattern3<v16i8>;
2063 def v8i16_3: EQVVecPattern3<v8i16>;
2064 def v4i32_3: EQVVecPattern3<v4i32>;
2065 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002066
Scott Michel6baba072008-03-05 23:02:02 +00002067 def r128: EQVRegInst<GPRC>;
2068 def r64: EQVRegInst<R64C>;
2069 def r32: EQVRegInst<R32C>;
2070 def r16: EQVRegInst<R16C>;
2071 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002072
Scott Michel6baba072008-03-05 23:02:02 +00002073 def r128_1: EQVRegPattern1<GPRC>;
2074 def r64_1: EQVRegPattern1<R64C>;
2075 def r32_1: EQVRegPattern1<R32C>;
2076 def r16_1: EQVRegPattern1<R16C>;
2077 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002078
Scott Michel6baba072008-03-05 23:02:02 +00002079 def r128_2: EQVRegPattern2<GPRC>;
2080 def r64_2: EQVRegPattern2<R64C>;
2081 def r32_2: EQVRegPattern2<R32C>;
2082 def r16_2: EQVRegPattern2<R16C>;
2083 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002084
Scott Michel6baba072008-03-05 23:02:02 +00002085 def r128_3: EQVRegPattern3<GPRC>;
2086 def r64_3: EQVRegPattern3<R64C>;
2087 def r32_3: EQVRegPattern3<R32C>;
2088 def r16_3: EQVRegPattern3<R16C>;
2089 def r8_3: EQVRegPattern3<R8C>;
2090}
Scott Michel438be252007-12-17 22:32:34 +00002091
Scott Michel6baba072008-03-05 23:02:02 +00002092defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00002093
2094//===----------------------------------------------------------------------===//
2095// Vector shuffle...
2096//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002097// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2098// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2099// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2100// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002101//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002102
Scott Michel97872d32008-02-23 18:41:37 +00002103class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2104 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2105 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002106
Scott Michel0718cd82008-12-01 17:56:02 +00002107class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002108 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002109 [(set (resultvec VECREG:$rT),
2110 (SPUshuffle (resultvec VECREG:$rA),
2111 (resultvec VECREG:$rB),
2112 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002113
Scott Michel06eabde2008-12-27 04:51:36 +00002114class SHUFBGPRCInst:
2115 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2116 [/* no pattern */]>;
2117
Scott Michel97872d32008-02-23 18:41:37 +00002118multiclass ShuffleBytes
2119{
Scott Michel0718cd82008-12-01 17:56:02 +00002120 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2121 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2122 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2123 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2124 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2125 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2126 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2127 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002128
Scott Michel0718cd82008-12-01 17:56:02 +00002129 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2130 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2131
2132 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2133 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002134
2135 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002136}
2137
2138defm SHUFB : ShuffleBytes;
2139
Scott Michel8b6b4202007-12-04 22:35:58 +00002140//===----------------------------------------------------------------------===//
2141// Shift and rotate group:
2142//===----------------------------------------------------------------------===//
2143
Scott Michel97872d32008-02-23 18:41:37 +00002144class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2145 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2146 RotateShift, pattern>;
2147
2148class SHLHVecInst<ValueType vectype>:
2149 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2150 [(set (vectype VECREG:$rT),
2151 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002152
2153// $rB gets promoted to 32-bit register type when confronted with
2154// this llvm assembly code:
2155//
2156// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
2157// %A = shl i16 %arg1, %arg2
2158// ret i16 %A
2159// }
Scott Michel8b6b4202007-12-04 22:35:58 +00002160
Scott Michel97872d32008-02-23 18:41:37 +00002161multiclass ShiftLeftHalfword
2162{
2163 def v8i16: SHLHVecInst<v8i16>;
2164 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2165 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2166 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2167 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2168}
Scott Michel8b6b4202007-12-04 22:35:58 +00002169
Scott Michel97872d32008-02-23 18:41:37 +00002170defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002171
Scott Michel97872d32008-02-23 18:41:37 +00002172//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002173
Scott Michel97872d32008-02-23 18:41:37 +00002174class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2175 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2176 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002177
Scott Michel97872d32008-02-23 18:41:37 +00002178class SHLHIVecInst<ValueType vectype>:
2179 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2180 [(set (vectype VECREG:$rT),
2181 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002182
Scott Michel97872d32008-02-23 18:41:37 +00002183multiclass ShiftLeftHalfwordImm
2184{
2185 def v8i16: SHLHIVecInst<v8i16>;
2186 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2187 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2188}
2189
2190defm SHLHI : ShiftLeftHalfwordImm;
2191
2192def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2193 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2194
2195def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002196 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002197
Scott Michel97872d32008-02-23 18:41:37 +00002198//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002199
Scott Michel97872d32008-02-23 18:41:37 +00002200class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2201 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2202 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002203
Scott Michel97872d32008-02-23 18:41:37 +00002204multiclass ShiftLeftWord
2205{
2206 def v4i32:
2207 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2208 [(set (v4i32 VECREG:$rT),
2209 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2210 def r32:
2211 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2212 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2213}
Scott Michel8b6b4202007-12-04 22:35:58 +00002214
Scott Michel97872d32008-02-23 18:41:37 +00002215defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002216
Scott Michel97872d32008-02-23 18:41:37 +00002217//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002218
Scott Michel97872d32008-02-23 18:41:37 +00002219class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2220 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2221 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002222
Scott Michel97872d32008-02-23 18:41:37 +00002223multiclass ShiftLeftWordImm
2224{
2225 def v4i32:
2226 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2227 [(set (v4i32 VECREG:$rT),
2228 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002229
Scott Michel97872d32008-02-23 18:41:37 +00002230 def r32:
2231 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2232 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2233}
Scott Michel8b6b4202007-12-04 22:35:58 +00002234
Scott Michel97872d32008-02-23 18:41:37 +00002235defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002236
Scott Michel97872d32008-02-23 18:41:37 +00002237//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002238// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2239// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002240//
2241// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2242// of 7 bits is actually possible.
2243//
2244// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2245// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2246// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002247
Scott Michel97872d32008-02-23 18:41:37 +00002248class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2249 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2250 RotateShift, pattern>;
2251
2252class SHLQBIVecInst<ValueType vectype>:
2253 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2254 [(set (vectype VECREG:$rT),
2255 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2256
2257multiclass ShiftLeftQuadByBits
2258{
2259 def v16i8: SHLQBIVecInst<v16i8>;
2260 def v8i16: SHLQBIVecInst<v8i16>;
2261 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002262 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002263 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002264 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002265}
2266
2267defm SHLQBI : ShiftLeftQuadByBits;
2268
2269// See note above on SHLQBI. In this case, the predicate actually does then
2270// enforcement, whereas with SHLQBI, we have to "take it on faith."
2271class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2272 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2273 RotateShift, pattern>;
2274
2275class SHLQBIIVecInst<ValueType vectype>:
2276 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2277 [(set (vectype VECREG:$rT),
2278 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2279
2280multiclass ShiftLeftQuadByBitsImm
2281{
2282 def v16i8 : SHLQBIIVecInst<v16i8>;
2283 def v8i16 : SHLQBIIVecInst<v8i16>;
2284 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002285 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002286 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002287 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002288}
2289
2290defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002291
2292// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002293// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002294
Scott Michel97872d32008-02-23 18:41:37 +00002295class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002296 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002297 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002298
Scott Michel97872d32008-02-23 18:41:37 +00002299class SHLQBYVecInst<ValueType vectype>:
2300 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2301 [(set (vectype VECREG:$rT),
2302 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002303
Scott Michel97872d32008-02-23 18:41:37 +00002304multiclass ShiftLeftQuadBytes
2305{
2306 def v16i8: SHLQBYVecInst<v16i8>;
2307 def v8i16: SHLQBYVecInst<v8i16>;
2308 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002309 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002310 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002311 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002312 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2313 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2314}
Scott Michel8b6b4202007-12-04 22:35:58 +00002315
Scott Michel97872d32008-02-23 18:41:37 +00002316defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002317
Scott Michel97872d32008-02-23 18:41:37 +00002318class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2319 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2320 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002321
Scott Michel97872d32008-02-23 18:41:37 +00002322class SHLQBYIVecInst<ValueType vectype>:
2323 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2324 [(set (vectype VECREG:$rT),
2325 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002326
Scott Michel97872d32008-02-23 18:41:37 +00002327multiclass ShiftLeftQuadBytesImm
2328{
2329 def v16i8: SHLQBYIVecInst<v16i8>;
2330 def v8i16: SHLQBYIVecInst<v8i16>;
2331 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002332 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002333 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002334 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002335 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2336 [(set GPRC:$rT,
2337 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2338}
Scott Michel438be252007-12-17 22:32:34 +00002339
Scott Michel97872d32008-02-23 18:41:37 +00002340defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002341
Scott Michel97872d32008-02-23 18:41:37 +00002342//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2343// Rotate halfword:
2344//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2345class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2346 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2347 RotateShift, pattern>;
2348
2349class ROTHVecInst<ValueType vectype>:
2350 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2351 [(set (vectype VECREG:$rT),
2352 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2353
2354class ROTHRegInst<RegisterClass rclass>:
2355 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2356 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2357
2358multiclass RotateLeftHalfword
2359{
2360 def v8i16: ROTHVecInst<v8i16>;
2361 def r16: ROTHRegInst<R16C>;
2362}
2363
2364defm ROTH: RotateLeftHalfword;
2365
2366def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2367 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2368
2369//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2370// Rotate halfword, immediate:
2371//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2372class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2373 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2374 RotateShift, pattern>;
2375
2376class ROTHIVecInst<ValueType vectype>:
2377 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2378 [(set (vectype VECREG:$rT),
2379 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2380
2381multiclass RotateLeftHalfwordImm
2382{
2383 def v8i16: ROTHIVecInst<v8i16>;
2384 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2385 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2386 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2387 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2388}
2389
2390defm ROTHI: RotateLeftHalfwordImm;
2391
2392def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002393 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002394
Scott Michel97872d32008-02-23 18:41:37 +00002395//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2396// Rotate word:
2397//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002398
Scott Michel97872d32008-02-23 18:41:37 +00002399class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2400 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2401 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002402
Scott Michel97872d32008-02-23 18:41:37 +00002403class ROTVecInst<ValueType vectype>:
2404 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2405 [(set (vectype VECREG:$rT),
2406 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002407
Scott Michel97872d32008-02-23 18:41:37 +00002408class ROTRegInst<RegisterClass rclass>:
2409 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2410 [(set rclass:$rT,
2411 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002412
Scott Michel97872d32008-02-23 18:41:37 +00002413multiclass RotateLeftWord
2414{
2415 def v4i32: ROTVecInst<v4i32>;
2416 def r32: ROTRegInst<R32C>;
2417}
2418
2419defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002420
Scott Michel438be252007-12-17 22:32:34 +00002421// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2422// 32-bit register
2423def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002424 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2425 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002426
2427def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2428 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2429
2430def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2431 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2432
2433def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002434 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2435 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002436
2437def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2438 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2439
2440def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2441 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2442
Scott Michel97872d32008-02-23 18:41:37 +00002443//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2444// Rotate word, immediate
2445//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002446
Scott Michel97872d32008-02-23 18:41:37 +00002447class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2448 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2449 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002450
Scott Michel97872d32008-02-23 18:41:37 +00002451class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2452 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2453 [(set (vectype VECREG:$rT),
2454 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002455
Scott Michel97872d32008-02-23 18:41:37 +00002456class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2457 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2458 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002459
Scott Michel97872d32008-02-23 18:41:37 +00002460multiclass RotateLeftWordImm
2461{
2462 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2463 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2464 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002465
Scott Michel97872d32008-02-23 18:41:37 +00002466 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2467 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2468 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2469}
Scott Michel438be252007-12-17 22:32:34 +00002470
Scott Michel97872d32008-02-23 18:41:37 +00002471defm ROTI : RotateLeftWordImm;
2472
2473//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2474// Rotate quad by byte (count)
2475//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2476
2477class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2478 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2479 RotateShift, pattern>;
2480
2481class ROTQBYVecInst<ValueType vectype>:
2482 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2483 [(set (vectype VECREG:$rT),
2484 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2485
2486multiclass RotateQuadLeftByBytes
2487{
2488 def v16i8: ROTQBYVecInst<v16i8>;
2489 def v8i16: ROTQBYVecInst<v8i16>;
2490 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002491 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002492 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002493 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002494}
2495
2496defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002497
Scott Michel97872d32008-02-23 18:41:37 +00002498//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2499// Rotate quad by byte (count), immediate
2500//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2501
2502class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2503 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2504 RotateShift, pattern>;
2505
2506class ROTQBYIVecInst<ValueType vectype>:
2507 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2508 [(set (vectype VECREG:$rT),
2509 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2510
2511multiclass RotateQuadByBytesImm
2512{
2513 def v16i8: ROTQBYIVecInst<v16i8>;
2514 def v8i16: ROTQBYIVecInst<v8i16>;
2515 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002516 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002517 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002518 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002519}
2520
2521defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002522
Scott Michel8b6b4202007-12-04 22:35:58 +00002523// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002524class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2525 RI7Form<0b00110011100, OOL, IOL,
2526 "rotqbybi\t$rT, $rA, $shift",
2527 RotateShift, pattern>;
2528
2529class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2530 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2531 [(set (vectype VECREG:$rT),
2532 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2533
2534multiclass RotateQuadByBytesByBitshift {
2535 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2536 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2537 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2538 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2539}
2540
2541defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002542
Scott Michel97872d32008-02-23 18:41:37 +00002543//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002544// See ROTQBY note above.
2545//
2546// Assume that the user of this instruction knows to shift the rotate count
2547// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002548//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002549
Scott Michel97872d32008-02-23 18:41:37 +00002550class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2551 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2552 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002553
Scott Michel97872d32008-02-23 18:41:37 +00002554class ROTQBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002555 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002556 [/* no pattern yet */]>;
2557
2558class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002559 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002560 [/* no pattern yet */]>;
2561
2562multiclass RotateQuadByBitCount
2563{
2564 def v16i8: ROTQBIVecInst<v16i8>;
2565 def v8i16: ROTQBIVecInst<v8i16>;
2566 def v4i32: ROTQBIVecInst<v4i32>;
2567 def v2i64: ROTQBIVecInst<v2i64>;
2568
2569 def r128: ROTQBIRegInst<GPRC>;
2570 def r64: ROTQBIRegInst<R64C>;
2571}
2572
2573defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002574
Scott Michel97872d32008-02-23 18:41:37 +00002575class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2576 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2577 RotateShift, pattern>;
2578
2579class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2580 PatLeaf pred>:
2581 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2582 [/* no pattern yet */]>;
2583
2584class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2585 PatLeaf pred>:
2586 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2587 [/* no pattern yet */]>;
2588
2589multiclass RotateQuadByBitCountImm
2590{
2591 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2592 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2593 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2594 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2595
2596 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2597 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2598}
2599
2600defm ROTQBII : RotateQuadByBitCountImm;
2601
2602//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002603// ROTHM v8i16 form:
2604// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2605// so this only matches a synthetically generated/lowered code
2606// fragment.
2607// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002608//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002609
Scott Michel97872d32008-02-23 18:41:37 +00002610class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2611 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2612 RotateShift, pattern>;
2613
2614def ROTHMv8i16:
2615 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2616 [/* see patterns below - $rB must be negated */]>;
2617
2618def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002619 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2620
Scott Michel97872d32008-02-23 18:41:37 +00002621def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002622 (ROTHMv8i16 VECREG:$rA,
2623 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2624
Scott Michel97872d32008-02-23 18:41:37 +00002625def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002626 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002627 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002628
2629// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2630// Note: This instruction doesn't match a pattern because rB must be negated
2631// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002632
Scott Michel8b6b4202007-12-04 22:35:58 +00002633def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002634 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2635 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002636
2637def : Pat<(srl R16C:$rA, R32C:$rB),
2638 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2639
2640def : Pat<(srl R16C:$rA, R16C:$rB),
2641 (ROTHMr16 R16C:$rA,
2642 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2643
Scott Michel438be252007-12-17 22:32:34 +00002644def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002645 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002646 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002647
2648// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2649// that the immediate can be complemented, so that the user doesn't have to
2650// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002651
Scott Michel97872d32008-02-23 18:41:37 +00002652class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2653 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2654 RotateShift, pattern>;
2655
2656def ROTHMIv8i16:
2657 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2658 [/* no pattern */]>;
2659
2660def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2661 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2662
2663def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002664 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002665
Scott Michel97872d32008-02-23 18:41:37 +00002666def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002667 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002668
2669def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002670 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2671 [/* no pattern */]>;
2672
2673def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2674 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002675
2676def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2677 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2678
Scott Michel438be252007-12-17 22:32:34 +00002679def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2680 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2681
Scott Michel8b6b4202007-12-04 22:35:58 +00002682// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002683class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2684 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2685 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002686
Scott Michel97872d32008-02-23 18:41:37 +00002687def ROTMv4i32:
2688 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2689 [/* see patterns below - $rB must be negated */]>;
2690
2691def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002692 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2693
Scott Michel97872d32008-02-23 18:41:37 +00002694def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002695 (ROTMv4i32 VECREG:$rA,
2696 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2697
Scott Michel97872d32008-02-23 18:41:37 +00002698def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002699 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002700 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002701
2702def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002703 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2704 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002705
2706def : Pat<(srl R32C:$rA, R32C:$rB),
2707 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2708
2709def : Pat<(srl R32C:$rA, R16C:$rB),
2710 (ROTMr32 R32C:$rA,
2711 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2712
Scott Michel438be252007-12-17 22:32:34 +00002713def : Pat<(srl R32C:$rA, R8C:$rB),
2714 (ROTMr32 R32C:$rA,
2715 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2716
Scott Michel8b6b4202007-12-04 22:35:58 +00002717// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2718def ROTMIv4i32:
2719 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2720 "rotmi\t$rT, $rA, $val", RotateShift,
2721 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002722 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002723
Scott Michel97872d32008-02-23 18:41:37 +00002724def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002725 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002726
Scott Michel97872d32008-02-23 18:41:37 +00002727def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002728 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002729
2730// ROTMI r32 form: know how to complement the immediate value.
2731def ROTMIr32:
2732 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2733 "rotmi\t$rT, $rA, $val", RotateShift,
2734 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2735
2736def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2737 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2738
Scott Michel438be252007-12-17 22:32:34 +00002739def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2740 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2741
Scott Michel97872d32008-02-23 18:41:37 +00002742//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel2ef773a2009-01-06 03:36:14 +00002743// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel8b6b4202007-12-04 22:35:58 +00002744// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002745// that the user knew to negate $rB.
Scott Michel97872d32008-02-23 18:41:37 +00002746//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002747
Scott Michel97872d32008-02-23 18:41:37 +00002748class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2749 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2750 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002751
Scott Michel97872d32008-02-23 18:41:37 +00002752class ROTQMBYVecInst<ValueType vectype>:
2753 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2754 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002755
Scott Michel97872d32008-02-23 18:41:37 +00002756class ROTQMBYRegInst<RegisterClass rclass>:
2757 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00002758 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002759
Scott Michel97872d32008-02-23 18:41:37 +00002760multiclass RotateQuadBytes
2761{
2762 def v16i8: ROTQMBYVecInst<v16i8>;
2763 def v8i16: ROTQMBYVecInst<v8i16>;
2764 def v4i32: ROTQMBYVecInst<v4i32>;
2765 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002766
Scott Michel97872d32008-02-23 18:41:37 +00002767 def r128: ROTQMBYRegInst<GPRC>;
2768 def r64: ROTQMBYRegInst<R64C>;
2769}
2770
2771defm ROTQMBY : RotateQuadBytes;
2772
Scott Michel97872d32008-02-23 18:41:37 +00002773class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2774 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2775 RotateShift, pattern>;
2776
2777class ROTQMBYIVecInst<ValueType vectype>:
2778 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002779 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002780
Scott Michel2ef773a2009-01-06 03:36:14 +00002781class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2782 PatLeaf pred>:
Scott Michel97872d32008-02-23 18:41:37 +00002783 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002784 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002785
Scott Michel2ef773a2009-01-06 03:36:14 +00002786// 128-bit zero extension form:
2787class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2788 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2789 [/* no pattern */]>;
2790
Scott Michel97872d32008-02-23 18:41:37 +00002791multiclass RotateQuadBytesImm
2792{
2793 def v16i8: ROTQMBYIVecInst<v16i8>;
2794 def v8i16: ROTQMBYIVecInst<v8i16>;
2795 def v4i32: ROTQMBYIVecInst<v4i32>;
2796 def v2i64: ROTQMBYIVecInst<v2i64>;
2797
2798 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2799 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Michel2ef773a2009-01-06 03:36:14 +00002800
2801 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2802 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2803 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2804 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michel97872d32008-02-23 18:41:37 +00002805}
2806
2807defm ROTQMBYI : RotateQuadBytesImm;
2808
Scott Michel97872d32008-02-23 18:41:37 +00002809//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2810// Rotate right and mask by bit count
2811//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2812
2813class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2814 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2815 RotateShift, pattern>;
2816
2817class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002818 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2819 [/* no pattern, */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002820
2821multiclass RotateMaskQuadByBitCount
2822{
2823 def v16i8: ROTQMBYBIVecInst<v16i8>;
2824 def v8i16: ROTQMBYBIVecInst<v8i16>;
2825 def v4i32: ROTQMBYBIVecInst<v4i32>;
2826 def v2i64: ROTQMBYBIVecInst<v2i64>;
2827}
2828
2829defm ROTQMBYBI: RotateMaskQuadByBitCount;
2830
2831//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2832// Rotate quad and mask by bits
2833// Note that the rotate amount has to be negated
2834//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2835
2836class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2837 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2838 RotateShift, pattern>;
2839
2840class ROTQMBIVecInst<ValueType vectype>:
2841 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2842 [/* no pattern */]>;
2843
2844class ROTQMBIRegInst<RegisterClass rclass>:
2845 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2846 [/* no pattern */]>;
2847
2848multiclass RotateMaskQuadByBits
2849{
2850 def v16i8: ROTQMBIVecInst<v16i8>;
2851 def v8i16: ROTQMBIVecInst<v8i16>;
2852 def v4i32: ROTQMBIVecInst<v4i32>;
2853 def v2i64: ROTQMBIVecInst<v2i64>;
2854
2855 def r128: ROTQMBIRegInst<GPRC>;
2856 def r64: ROTQMBIRegInst<R64C>;
2857}
2858
2859defm ROTQMBI: RotateMaskQuadByBits;
2860
Scott Michel97872d32008-02-23 18:41:37 +00002861//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2862// Rotate quad and mask by bits, immediate
2863//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2864
2865class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2866 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2867 RotateShift, pattern>;
2868
2869class ROTQMBIIVecInst<ValueType vectype>:
2870 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002871 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002872
2873class ROTQMBIIRegInst<RegisterClass rclass>:
2874 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002875 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002876
2877multiclass RotateMaskQuadByBitsImm
2878{
2879 def v16i8: ROTQMBIIVecInst<v16i8>;
2880 def v8i16: ROTQMBIIVecInst<v8i16>;
2881 def v4i32: ROTQMBIIVecInst<v4i32>;
2882 def v2i64: ROTQMBIIVecInst<v2i64>;
2883
2884 def r128: ROTQMBIIRegInst<GPRC>;
2885 def r64: ROTQMBIIRegInst<R64C>;
2886}
2887
2888defm ROTQMBII: RotateMaskQuadByBitsImm;
2889
2890//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2891//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002892
2893def ROTMAHv8i16:
2894 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2895 "rotmah\t$rT, $rA, $rB", RotateShift,
2896 [/* see patterns below - $rB must be negated */]>;
2897
Scott Michel97872d32008-02-23 18:41:37 +00002898def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002899 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2900
Scott Michel97872d32008-02-23 18:41:37 +00002901def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002902 (ROTMAHv8i16 VECREG:$rA,
2903 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2904
Scott Michel97872d32008-02-23 18:41:37 +00002905def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002906 (ROTMAHv8i16 VECREG:$rA,
2907 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2908
Scott Michel8b6b4202007-12-04 22:35:58 +00002909def ROTMAHr16:
2910 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2911 "rotmah\t$rT, $rA, $rB", RotateShift,
2912 [/* see patterns below - $rB must be negated */]>;
2913
2914def : Pat<(sra R16C:$rA, R32C:$rB),
2915 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2916
2917def : Pat<(sra R16C:$rA, R16C:$rB),
2918 (ROTMAHr16 R16C:$rA,
2919 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2920
Scott Michel438be252007-12-17 22:32:34 +00002921def : Pat<(sra R16C:$rA, R8C:$rB),
2922 (ROTMAHr16 R16C:$rA,
2923 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2924
Scott Michel8b6b4202007-12-04 22:35:58 +00002925def ROTMAHIv8i16:
2926 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2927 "rotmahi\t$rT, $rA, $val", RotateShift,
2928 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002929 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002930
Scott Michel97872d32008-02-23 18:41:37 +00002931def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002932 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2933
Scott Michel97872d32008-02-23 18:41:37 +00002934def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002935 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2936
Scott Michel8b6b4202007-12-04 22:35:58 +00002937def ROTMAHIr16:
2938 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2939 "rotmahi\t$rT, $rA, $val", RotateShift,
2940 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2941
2942def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2943 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2944
Scott Michel438be252007-12-17 22:32:34 +00002945def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2946 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2947
Scott Michel8b6b4202007-12-04 22:35:58 +00002948def ROTMAv4i32:
2949 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2950 "rotma\t$rT, $rA, $rB", RotateShift,
2951 [/* see patterns below - $rB must be negated */]>;
2952
Scott Michel97872d32008-02-23 18:41:37 +00002953def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002954 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2955
Scott Michel97872d32008-02-23 18:41:37 +00002956def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002957 (ROTMAv4i32 (v4i32 VECREG:$rA),
2958 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2959
Scott Michel97872d32008-02-23 18:41:37 +00002960def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002961 (ROTMAv4i32 (v4i32 VECREG:$rA),
2962 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2963
Scott Michel8b6b4202007-12-04 22:35:58 +00002964def ROTMAr32:
2965 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2966 "rotma\t$rT, $rA, $rB", RotateShift,
2967 [/* see patterns below - $rB must be negated */]>;
2968
2969def : Pat<(sra R32C:$rA, R32C:$rB),
2970 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2971
2972def : Pat<(sra R32C:$rA, R16C:$rB),
2973 (ROTMAr32 R32C:$rA,
2974 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2975
Scott Michel438be252007-12-17 22:32:34 +00002976def : Pat<(sra R32C:$rA, R8C:$rB),
2977 (ROTMAr32 R32C:$rA,
2978 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2979
Scott Michel67224b22008-06-02 22:18:03 +00002980class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2981 RRForm<0b01011110000, OOL, IOL,
2982 "rotmai\t$rT, $rA, $val",
2983 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002984
Scott Michel67224b22008-06-02 22:18:03 +00002985class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2986 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2987 [(set (vectype VECREG:$rT),
2988 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002989
Scott Michel67224b22008-06-02 22:18:03 +00002990class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2991 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2992 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002993
Scott Michel67224b22008-06-02 22:18:03 +00002994multiclass RotateMaskAlgebraicImm {
2995 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2996 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2997 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2998 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2999}
Scott Michel8b6b4202007-12-04 22:35:58 +00003000
Scott Michel67224b22008-06-02 22:18:03 +00003001defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00003002
Scott Michel8b6b4202007-12-04 22:35:58 +00003003//===----------------------------------------------------------------------===//
3004// Branch and conditionals:
3005//===----------------------------------------------------------------------===//
3006
3007let isTerminator = 1, isBarrier = 1 in {
3008 // Halt If Equal (r32 preferred slot only, no vector form)
3009 def HEQr32:
3010 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3011 "heq\t$rA, $rB", BranchResolv,
3012 [/* no pattern to match */]>;
3013
3014 def HEQIr32 :
3015 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3016 "heqi\t$rA, $val", BranchResolv,
3017 [/* no pattern to match */]>;
3018
3019 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3020 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3021 def HGTr32:
3022 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3023 "hgt\t$rA, $rB", BranchResolv,
3024 [/* no pattern to match */]>;
3025
Scott Michel06eabde2008-12-27 04:51:36 +00003026 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00003027 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3028 "hgti\t$rA, $val", BranchResolv,
3029 [/* no pattern to match */]>;
3030
3031 def HLGTr32:
3032 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3033 "hlgt\t$rA, $rB", BranchResolv,
3034 [/* no pattern to match */]>;
3035
3036 def HLGTIr32:
3037 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3038 "hlgti\t$rA, $val", BranchResolv,
3039 [/* no pattern to match */]>;
3040}
3041
Scott Michel06eabde2008-12-27 04:51:36 +00003042//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3043// Comparison operators for i8, i16 and i32:
3044//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003045
Scott Michel97872d32008-02-23 18:41:37 +00003046class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3047 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3048 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003049
Scott Michel97872d32008-02-23 18:41:37 +00003050multiclass CmpEqualByte
3051{
3052 def v16i8 :
3053 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3054 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3055 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00003056
Scott Michel97872d32008-02-23 18:41:37 +00003057 def r8 :
3058 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3059 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3060}
Scott Michel8b6b4202007-12-04 22:35:58 +00003061
Scott Michel97872d32008-02-23 18:41:37 +00003062class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3063 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3064 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003065
Scott Michel97872d32008-02-23 18:41:37 +00003066multiclass CmpEqualByteImm
3067{
3068 def v16i8 :
3069 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3070 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3071 v16i8SExt8Imm:$val))]>;
3072 def r8:
3073 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3074 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3075}
Scott Michel8b6b4202007-12-04 22:35:58 +00003076
Scott Michel97872d32008-02-23 18:41:37 +00003077class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3078 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3079 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003080
Scott Michel97872d32008-02-23 18:41:37 +00003081multiclass CmpEqualHalfword
3082{
3083 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3084 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3085 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003086
Scott Michel97872d32008-02-23 18:41:37 +00003087 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3088 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3089}
Scott Michel8b6b4202007-12-04 22:35:58 +00003090
Scott Michel97872d32008-02-23 18:41:37 +00003091class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3092 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3093 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003094
Scott Michel97872d32008-02-23 18:41:37 +00003095multiclass CmpEqualHalfwordImm
3096{
3097 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3098 [(set (v8i16 VECREG:$rT),
3099 (seteq (v8i16 VECREG:$rA),
3100 (v8i16 v8i16SExt10Imm:$val)))]>;
3101 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3102 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3103}
Scott Michel8b6b4202007-12-04 22:35:58 +00003104
Scott Michel97872d32008-02-23 18:41:37 +00003105class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3106 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3107 ByteOp, pattern>;
3108
3109multiclass CmpEqualWord
3110{
3111 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3112 [(set (v4i32 VECREG:$rT),
3113 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3114
3115 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3116 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3117}
3118
3119class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3120 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3121 ByteOp, pattern>;
3122
3123multiclass CmpEqualWordImm
3124{
3125 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3126 [(set (v4i32 VECREG:$rT),
3127 (seteq (v4i32 VECREG:$rA),
3128 (v4i32 v4i32SExt16Imm:$val)))]>;
3129
3130 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3131 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3132}
3133
3134class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3135 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3136 ByteOp, pattern>;
3137
3138multiclass CmpGtrByte
3139{
3140 def v16i8 :
3141 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3142 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3143 (v8i16 VECREG:$rB)))]>;
3144
3145 def r8 :
3146 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3147 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3148}
3149
3150class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3151 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3152 ByteOp, pattern>;
3153
3154multiclass CmpGtrByteImm
3155{
3156 def v16i8 :
3157 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3158 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3159 v16i8SExt8Imm:$val))]>;
3160 def r8:
3161 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003162 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003163}
3164
3165class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3166 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3167 ByteOp, pattern>;
3168
3169multiclass CmpGtrHalfword
3170{
3171 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3172 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3173 (v8i16 VECREG:$rB)))]>;
3174
3175 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3176 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3177}
3178
3179class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3180 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3181 ByteOp, pattern>;
3182
3183multiclass CmpGtrHalfwordImm
3184{
3185 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3186 [(set (v8i16 VECREG:$rT),
3187 (setgt (v8i16 VECREG:$rA),
3188 (v8i16 v8i16SExt10Imm:$val)))]>;
3189 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3190 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3191}
3192
3193class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3194 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3195 ByteOp, pattern>;
3196
3197multiclass CmpGtrWord
3198{
3199 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3200 [(set (v4i32 VECREG:$rT),
3201 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3202
3203 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3204 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3205}
3206
3207class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3208 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3209 ByteOp, pattern>;
3210
3211multiclass CmpGtrWordImm
3212{
3213 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3214 [(set (v4i32 VECREG:$rT),
3215 (setgt (v4i32 VECREG:$rA),
3216 (v4i32 v4i32SExt16Imm:$val)))]>;
3217
3218 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3219 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003220
3221 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3222 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3223 [(set (v4i32 VECREG:$rT),
3224 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3225 (v4i32 v4i32SExt16Imm:$val)))]>;
3226
3227 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
3228 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00003229}
3230
3231class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003232 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003233 ByteOp, pattern>;
3234
3235multiclass CmpLGtrByte
3236{
3237 def v16i8 :
3238 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3239 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3240 (v8i16 VECREG:$rB)))]>;
3241
3242 def r8 :
3243 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3244 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3245}
3246
3247class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003248 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003249 ByteOp, pattern>;
3250
3251multiclass CmpLGtrByteImm
3252{
3253 def v16i8 :
3254 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3255 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3256 v16i8SExt8Imm:$val))]>;
3257 def r8:
3258 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3259 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3260}
3261
3262class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003263 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003264 ByteOp, pattern>;
3265
3266multiclass CmpLGtrHalfword
3267{
3268 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3269 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3270 (v8i16 VECREG:$rB)))]>;
3271
3272 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3273 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3274}
3275
3276class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003277 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003278 ByteOp, pattern>;
3279
3280multiclass CmpLGtrHalfwordImm
3281{
3282 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3283 [(set (v8i16 VECREG:$rT),
3284 (setugt (v8i16 VECREG:$rA),
3285 (v8i16 v8i16SExt10Imm:$val)))]>;
3286 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3287 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3288}
3289
3290class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003291 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003292 ByteOp, pattern>;
3293
3294multiclass CmpLGtrWord
3295{
3296 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3297 [(set (v4i32 VECREG:$rT),
3298 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3299
3300 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3301 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3302}
3303
3304class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003305 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003306 ByteOp, pattern>;
3307
3308multiclass CmpLGtrWordImm
3309{
3310 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3311 [(set (v4i32 VECREG:$rT),
3312 (setugt (v4i32 VECREG:$rA),
3313 (v4i32 v4i32SExt16Imm:$val)))]>;
3314
3315 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003316 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003317}
3318
3319defm CEQB : CmpEqualByte;
3320defm CEQBI : CmpEqualByteImm;
3321defm CEQH : CmpEqualHalfword;
3322defm CEQHI : CmpEqualHalfwordImm;
3323defm CEQ : CmpEqualWord;
3324defm CEQI : CmpEqualWordImm;
3325defm CGTB : CmpGtrByte;
3326defm CGTBI : CmpGtrByteImm;
3327defm CGTH : CmpGtrHalfword;
3328defm CGTHI : CmpGtrHalfwordImm;
3329defm CGT : CmpGtrWord;
3330defm CGTI : CmpGtrWordImm;
3331defm CLGTB : CmpLGtrByte;
3332defm CLGTBI : CmpLGtrByteImm;
3333defm CLGTH : CmpLGtrHalfword;
3334defm CLGTHI : CmpLGtrHalfwordImm;
3335defm CLGT : CmpLGtrWord;
3336defm CLGTI : CmpLGtrWordImm;
3337
Scott Michel53ab7792008-03-10 16:58:52 +00003338//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003339// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3340// define a pattern to generate the right code, as a binary operator
3341// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003342//
Scott Michel06eabde2008-12-27 04:51:36 +00003343// Notes:
3344// 1. This only matches the setcc set of conditionals. Special pattern
3345// matching is used for select conditionals.
3346//
3347// 2. The "DAG" versions of these classes is almost exclusively used for
3348// i64 comparisons. See the tblgen fundamentals documentation for what
3349// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3350// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003351//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003352
Scott Michel53ab7792008-03-10 16:58:52 +00003353class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3354 SPUInstr xorinst, SPUInstr cmpare>:
3355 Pat<(cond rclass:$rA, rclass:$rB),
3356 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3357
3358class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3359 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3360 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3361 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3362
Scott Michel06eabde2008-12-27 04:51:36 +00003363def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003364def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3365
Scott Michel06eabde2008-12-27 04:51:36 +00003366def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003367def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3368
3369def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3370def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003371
3372class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3373 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3374 Pat<(cond rclass:$rA, rclass:$rB),
3375 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3376 (cmpOp2 rclass:$rA, rclass:$rB))>;
3377
3378class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3379 ValueType immtype,
3380 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3381 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3382 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3383 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3384
Scott Michel53ab7792008-03-10 16:58:52 +00003385def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3386def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3387def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3388def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3389def : Pat<(setle R8C:$rA, R8C:$rB),
3390 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3391def : Pat<(setle R8C:$rA, immU8:$imm),
3392 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003393
Scott Michel53ab7792008-03-10 16:58:52 +00003394def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3395def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3396 ORr16, CGTHIr16, CEQHIr16>;
3397def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3398def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3399def : Pat<(setle R16C:$rA, R16C:$rB),
3400 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3401def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3402 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003403
Scott Michel53ab7792008-03-10 16:58:52 +00003404def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3405def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3406 ORr32, CGTIr32, CEQIr32>;
3407def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3408def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3409def : Pat<(setle R32C:$rA, R32C:$rB),
3410 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3411def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3412 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003413
Scott Michel53ab7792008-03-10 16:58:52 +00003414def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3415def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3416def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3417def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3418def : Pat<(setule R8C:$rA, R8C:$rB),
3419 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3420def : Pat<(setule R8C:$rA, immU8:$imm),
3421 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003422
Scott Michel53ab7792008-03-10 16:58:52 +00003423def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3424def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3425 ORr16, CLGTHIr16, CEQHIr16>;
3426def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3427def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3428 CLGTHIr16, CEQHIr16>;
3429def : Pat<(setule R16C:$rA, R16C:$rB),
3430 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003431def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003432 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003433
Scott Michel53ab7792008-03-10 16:58:52 +00003434def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003435def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003436 ORr32, CLGTIr32, CEQIr32>;
3437def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003438def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003439def : Pat<(setule R32C:$rA, R32C:$rB),
3440 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3441def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3442 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003443
Scott Michel53ab7792008-03-10 16:58:52 +00003444//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3445// select conditional patterns:
3446//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3447
3448class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3449 SPUInstr selinstr, SPUInstr cmpare>:
3450 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3451 rclass:$rTrue, rclass:$rFalse),
3452 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003453 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003454
3455class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3456 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3457 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003458 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003459 (selinstr rclass:$rTrue, rclass:$rFalse,
3460 (cmpare rclass:$rA, immpred:$imm))>;
3461
3462def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3463def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3464def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3465def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3466def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3467def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3468
3469def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3470def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3471def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3472def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3473def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3474def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3475
3476def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3477def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3478def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3479def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3480def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3481def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3482
3483class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3484 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3485 SPUInstr cmpOp2>:
3486 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003487 rclass:$rTrue, rclass:$rFalse),
3488 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003489 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3490 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3491
3492class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3493 ValueType inttype,
3494 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3495 SPUInstr cmpOp2>:
3496 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003497 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003498 (selinstr rclass:$rFalse, rclass:$rTrue,
3499 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3500 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3501
3502def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3503def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3504 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3505
3506def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3507def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3508 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3509
3510def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3511def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3512 SELBr32, ORr32, CGTIr32, CEQIr32>;
3513
3514def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3515def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3516 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3517
3518def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3519def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3520 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3521
3522def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3523def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3524 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003525
3526//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003527
3528let isCall = 1,
3529 // All calls clobber the non-callee-saved registers:
3530 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3531 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3532 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3533 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3534 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3535 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3536 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3537 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3538 // All of these instructions use $lr (aka $0)
3539 Uses = [R0] in {
3540 // Branch relative and set link: Used if we actually know that the target
3541 // is within [-32768, 32767] bytes of the target
3542 def BRSL:
3543 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3544 "brsl\t$$lr, $func",
3545 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3546
3547 // Branch absolute and set link: Used if we actually know that the target
3548 // is an absolute address
3549 def BRASL:
3550 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3551 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003552 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003553
3554 // Branch indirect and set link if external data. These instructions are not
3555 // actually generated, matched by an intrinsic:
3556 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3557 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3558 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3559 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3560
3561 // Branch indirect and set link. This is the "X-form" address version of a
3562 // function call
3563 def BISL:
3564 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3565}
3566
Scott Michelae5cbf52008-12-29 03:23:36 +00003567// Support calls to external symbols:
3568def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3569 (BRSL texternalsym:$func)>;
3570
3571def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3572 (BRASL texternalsym:$func)>;
3573
Scott Michel8b6b4202007-12-04 22:35:58 +00003574// Unconditional branches:
3575let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3576 def BR :
3577 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3578 "br\t$dest",
3579 [(br bb:$dest)]>;
3580
3581 // Unconditional, absolute address branch
3582 def BRA:
3583 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3584 "bra\t$dest",
3585 [/* no pattern */]>;
3586
3587 // Indirect branch
3588 def BI:
3589 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3590
Scott Michele0168c12009-01-05 01:34:35 +00003591 // Conditional branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003592 class BRNZInst<dag IOL, list<dag> pattern>:
3593 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3594 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003595
Scott Michel06eabde2008-12-27 04:51:36 +00003596 class BRNZRegInst<RegisterClass rclass>:
3597 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3598 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003599
Scott Michel06eabde2008-12-27 04:51:36 +00003600 class BRNZVecInst<ValueType vectype>:
3601 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3602 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003603
Scott Michel06eabde2008-12-27 04:51:36 +00003604 multiclass BranchNotZero {
3605 def v4i32 : BRNZVecInst<v4i32>;
3606 def r32 : BRNZRegInst<R32C>;
3607 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003608
Scott Michel06eabde2008-12-27 04:51:36 +00003609 defm BRNZ : BranchNotZero;
3610
3611 class BRZInst<dag IOL, list<dag> pattern>:
3612 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3613 BranchResolv, pattern>;
3614
3615 class BRZRegInst<RegisterClass rclass>:
3616 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3617
3618 class BRZVecInst<ValueType vectype>:
3619 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3620
3621 multiclass BranchZero {
3622 def v4i32: BRZVecInst<v4i32>;
3623 def r32: BRZRegInst<R32C>;
3624 }
3625
3626 defm BRZ: BranchZero;
3627
3628 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3629 // be useful:
3630 /*
3631 class BINZInst<dag IOL, list<dag> pattern>:
3632 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3633
3634 class BINZRegInst<RegisterClass rclass>:
3635 BINZInst<(ins rclass:$rA, brtarget:$dest),
3636 [(brcond rclass:$rA, R32C:$dest)]>;
3637
3638 class BINZVecInst<ValueType vectype>:
3639 BINZInst<(ins VECREG:$rA, R32C:$dest),
3640 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3641
3642 multiclass BranchNotZeroIndirect {
3643 def v4i32: BINZVecInst<v4i32>;
3644 def r32: BINZRegInst<R32C>;
3645 }
3646
3647 defm BINZ: BranchNotZeroIndirect;
3648
3649 class BIZInst<dag IOL, list<dag> pattern>:
3650 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3651
3652 class BIZRegInst<RegisterClass rclass>:
3653 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3654
3655 class BIZVecInst<ValueType vectype>:
3656 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3657
3658 multiclass BranchZeroIndirect {
3659 def v4i32: BIZVecInst<v4i32>;
3660 def r32: BIZRegInst<R32C>;
3661 }
3662
3663 defm BIZ: BranchZeroIndirect;
3664 */
3665
3666 class BRHNZInst<dag IOL, list<dag> pattern>:
3667 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3668 pattern>;
3669
3670 class BRHNZRegInst<RegisterClass rclass>:
3671 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3672 [(brcond rclass:$rCond, bb:$dest)]>;
3673
3674 class BRHNZVecInst<ValueType vectype>:
3675 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3676
3677 multiclass BranchNotZeroHalfword {
3678 def v8i16: BRHNZVecInst<v8i16>;
3679 def r16: BRHNZRegInst<R16C>;
3680 }
3681
3682 defm BRHNZ: BranchNotZeroHalfword;
3683
3684 class BRHZInst<dag IOL, list<dag> pattern>:
3685 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3686 pattern>;
3687
3688 class BRHZRegInst<RegisterClass rclass>:
3689 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3690
3691 class BRHZVecInst<ValueType vectype>:
3692 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3693
3694 multiclass BranchZeroHalfword {
3695 def v8i16: BRHZVecInst<v8i16>;
3696 def r16: BRHZRegInst<R16C>;
3697 }
3698
3699 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003700}
3701
Scott Michel394e26d2008-01-17 20:38:41 +00003702//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003703// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003704//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003705
Scott Michel06eabde2008-12-27 04:51:36 +00003706def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3707 (BRHZr16 R16C:$rA, bb:$dest)>;
3708def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3709 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003710
Scott Michel06eabde2008-12-27 04:51:36 +00003711def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3712 (BRZr32 R32C:$rA, bb:$dest)>;
3713def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3714 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003715
Scott Michel97872d32008-02-23 18:41:37 +00003716multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3717{
3718 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3719 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003720
Scott Michel97872d32008-02-23 18:41:37 +00003721 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3722 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3723
3724 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3725 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3726
3727 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3728 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3729}
3730
Scott Michele0168c12009-01-05 01:34:35 +00003731defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3732defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003733
3734multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3735{
3736 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3737 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3738
3739 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3740 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3741
3742 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3743 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3744
3745 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3746 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3747}
3748
Scott Michel06eabde2008-12-27 04:51:36 +00003749defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3750defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003751
3752multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3753 SPUInstr orinst32, SPUInstr brinst32>
3754{
3755 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3756 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3757 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3758 bb:$dest)>;
3759
3760 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3761 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3762 (CEQHr16 R16C:$rA, R16:$rB)),
3763 bb:$dest)>;
3764
3765 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3766 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3767 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3768 bb:$dest)>;
3769
3770 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3771 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3772 (CEQr32 R32C:$rA, R32C:$rB)),
3773 bb:$dest)>;
3774}
3775
Scott Michel06eabde2008-12-27 04:51:36 +00003776defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3777defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003778
3779multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3780{
3781 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3782 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3783
3784 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3785 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3786
3787 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3788 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3789
3790 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3791 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3792}
3793
Scott Michel06eabde2008-12-27 04:51:36 +00003794defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3795defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003796
3797multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3798 SPUInstr orinst32, SPUInstr brinst32>
3799{
3800 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3801 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3802 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3803 bb:$dest)>;
3804
3805 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3806 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3807 (CEQHr16 R16C:$rA, R16:$rB)),
3808 bb:$dest)>;
3809
3810 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3811 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3812 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3813 bb:$dest)>;
3814
3815 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3816 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3817 (CEQr32 R32C:$rA, R32C:$rB)),
3818 bb:$dest)>;
3819}
3820
Scott Michel06eabde2008-12-27 04:51:36 +00003821defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3822defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003823
Scott Michel8b6b4202007-12-04 22:35:58 +00003824let isTerminator = 1, isBarrier = 1 in {
3825 let isReturn = 1 in {
3826 def RET:
3827 RETForm<"bi\t$$lr", [(retflag)]>;
3828 }
3829}
3830
3831//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003832// Single precision floating point instructions
3833//===----------------------------------------------------------------------===//
3834
Scott Michel61895fe2008-12-10 00:15:19 +00003835class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3836 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003837 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003838
Scott Michel61895fe2008-12-10 00:15:19 +00003839class FAVecInst<ValueType vectype>:
3840 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3841 [(set (vectype VECREG:$rT),
Scott Michel4d07fb72008-12-30 23:28:25 +00003842 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003843
Scott Michel61895fe2008-12-10 00:15:19 +00003844multiclass SFPAdd
3845{
3846 def v4f32: FAVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003847 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3848 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003849}
Scott Michel8b6b4202007-12-04 22:35:58 +00003850
Scott Michel61895fe2008-12-10 00:15:19 +00003851defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003852
Scott Michel61895fe2008-12-10 00:15:19 +00003853class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3854 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003855 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003856
Scott Michel61895fe2008-12-10 00:15:19 +00003857class FSVecInst<ValueType vectype>:
3858 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00003859 [(set (vectype VECREG:$rT),
3860 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003861
3862multiclass SFPSub
3863{
3864 def v4f32: FSVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003865 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3866 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003867}
3868
3869defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003870
3871// Floating point reciprocal estimate
Scott Michel8b6b4202007-12-04 22:35:58 +00003872
Scott Michel4d07fb72008-12-30 23:28:25 +00003873class FRESTInst<dag OOL, dag IOL>:
3874 RRForm_1<0b00110111000, OOL, IOL,
3875 "frest\t$rT, $rA", SPrecFP,
3876 [/* no pattern */]>;
3877
3878def FRESTv4f32 :
3879 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3880
3881def FRESTf32 :
3882 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003883
3884// Floating point interpolate (used in conjunction with reciprocal estimate)
3885def FIv4f32 :
3886 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3887 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003888 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003889
3890def FIf32 :
3891 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3892 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003893 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003894
Scott Michel33d73eb2008-11-21 02:56:16 +00003895//--------------------------------------------------------------------------
3896// Basic single precision floating point comparisons:
3897//
3898// Note: There is no support on SPU for single precision NaN. Consequently,
3899// ordered and unordered comparisons are the same.
3900//--------------------------------------------------------------------------
3901
Scott Michel8b6b4202007-12-04 22:35:58 +00003902def FCEQf32 :
3903 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3904 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003905 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3906
3907def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3908 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003909
3910def FCMEQf32 :
3911 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3912 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003913 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3914
3915def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3916 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003917
3918def FCGTf32 :
3919 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3920 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003921 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3922
3923def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3924 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003925
3926def FCMGTf32 :
3927 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3928 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003929 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3930
3931def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3932 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3933
3934//--------------------------------------------------------------------------
3935// Single precision floating point comparisons and SETCC equivalents:
3936//--------------------------------------------------------------------------
3937
3938def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3939def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3940
3941def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3942def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3943
3944def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3945def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3946
3947def : Pat<(setule R32FP:$rA, R32FP:$rB),
3948 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3949def : Pat<(setole R32FP:$rA, R32FP:$rB),
3950 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003951
3952// FP Status and Control Register Write
3953// Why isn't rT a don't care in the ISA?
3954// Should we create a special RRForm_3 for this guy and zero out the rT?
3955def FSCRWf32 :
3956 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3957 "fscrwr\t$rA", SPrecFP,
3958 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3959
3960// FP Status and Control Register Read
3961def FSCRRf32 :
3962 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3963 "fscrrd\t$rT", SPrecFP,
3964 [/* This instruction requires an intrinsic */]>;
3965
3966// llvm instruction space
3967// How do these map onto cell instructions?
3968// fdiv rA rB
3969// frest rC rB # c = 1/b (both lines)
3970// fi rC rB rC
3971// fm rD rA rC # d = a * 1/b
3972// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3973// fma rB rB rC rD # b = b * c + d
3974// = -(d *b -a) * c + d
3975// = a * c - c ( a *b *c - a)
3976
3977// fcopysign (???)
3978
3979// Library calls:
3980// These llvm instructions will actually map to library calls.
3981// All that's needed, then, is to check that the appropriate library is
3982// imported and do a brsl to the proper function name.
3983// frem # fmod(x, y): x - (x/y) * y
3984// (Note: fmod(double, double), fmodf(float,float)
3985// fsqrt?
3986// fsin?
3987// fcos?
3988// Unimplemented SPU instruction space
3989// floating reciprocal absolute square root estimate (frsqest)
3990
3991// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00003992// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00003993// status and control register read
3994
3995//--------------------------------------
3996// Floating point multiply instructions
3997//--------------------------------------
3998
3999def FMv4f32:
4000 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4001 "fm\t$rT, $rA, $rB", SPrecFP,
4002 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
4003 (v4f32 VECREG:$rB)))]>;
4004
4005def FMf32 :
4006 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4007 "fm\t$rT, $rA, $rB", SPrecFP,
4008 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
4009
4010// Floating point multiply and add
4011// e.g. d = c + (a * b)
4012def FMAv4f32:
4013 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4014 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4015 [(set (v4f32 VECREG:$rT),
4016 (fadd (v4f32 VECREG:$rC),
4017 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
4018
4019def FMAf32:
4020 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4021 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4022 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4023
4024// FP multiply and subtract
4025// Subtracts value in rC from product
4026// res = a * b - c
4027def FMSv4f32 :
4028 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4029 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4030 [(set (v4f32 VECREG:$rT),
4031 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
4032 (v4f32 VECREG:$rC)))]>;
4033
4034def FMSf32 :
4035 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4036 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4037 [(set R32FP:$rT,
4038 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
4039
4040// Floating Negative Mulitply and Subtract
4041// Subtracts product from value in rC
4042// res = fneg(fms a b c)
4043// = - (a * b - c)
4044// = c - a * b
4045// NOTE: subtraction order
4046// fsub a b = a - b
Scott Michel06eabde2008-12-27 04:51:36 +00004047// fs a b = b - a?
Scott Michel8b6b4202007-12-04 22:35:58 +00004048def FNMSf32 :
4049 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4050 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4051 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4052
4053def FNMSv4f32 :
4054 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4055 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004056 [(set (v4f32 VECREG:$rT),
4057 (fsub (v4f32 VECREG:$rC),
4058 (fmul (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004059 (v4f32 VECREG:$rB))))]>;
4060
4061//--------------------------------------
4062// Floating Point Conversions
4063// Signed conversions:
4064def CSiFv4f32:
4065 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4066 "csflt\t$rT, $rA, 0", SPrecFP,
4067 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4068
Scott Michel06eabde2008-12-27 04:51:36 +00004069// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00004070def CSiFf32 :
4071 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4072 "csflt\t$rT, $rA, 0", SPrecFP,
4073 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4074
4075// Convert unsigned into to float
4076def CUiFv4f32 :
4077 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4078 "cuflt\t$rT, $rA, 0", SPrecFP,
4079 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4080
4081def CUiFf32 :
4082 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4083 "cuflt\t$rT, $rA, 0", SPrecFP,
4084 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4085
Scott Michel06eabde2008-12-27 04:51:36 +00004086// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004087// Assume that scale = 0
4088
4089def CFUiv4f32 :
4090 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4091 "cfltu\t$rT, $rA, 0", SPrecFP,
4092 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4093
4094def CFUif32 :
4095 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4096 "cfltu\t$rT, $rA, 0", SPrecFP,
4097 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4098
Scott Michel06eabde2008-12-27 04:51:36 +00004099// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004100// Assume that scale = 0
4101
4102def CFSiv4f32 :
4103 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4104 "cflts\t$rT, $rA, 0", SPrecFP,
4105 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4106
4107def CFSif32 :
4108 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4109 "cflts\t$rT, $rA, 0", SPrecFP,
4110 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4111
4112//===----------------------------------------------------------------------==//
4113// Single<->Double precision conversions
4114//===----------------------------------------------------------------------==//
4115
4116// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4117// v4f32, output is v2f64--which goes in the name?)
4118
4119// Floating point extend single to double
4120// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4121// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4122// are ignored).
4123def FESDvec :
4124 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4125 "fesd\t$rT, $rA", SPrecFP,
4126 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4127
4128def FESDf32 :
4129 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4130 "fesd\t$rT, $rA", SPrecFP,
4131 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4132
4133// Floating point round double to single
4134//def FRDSvec :
4135// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4136// "frds\t$rT, $rA,", SPrecFP,
4137// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4138
4139def FRDSf64 :
4140 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4141 "frds\t$rT, $rA", SPrecFP,
4142 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4143
4144//ToDo include anyextend?
4145
4146//===----------------------------------------------------------------------==//
4147// Double precision floating point instructions
4148//===----------------------------------------------------------------------==//
4149def FAf64 :
4150 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4151 "dfa\t$rT, $rA, $rB", DPrecFP,
4152 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4153
4154def FAv2f64 :
4155 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4156 "dfa\t$rT, $rA, $rB", DPrecFP,
4157 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4158
4159def FSf64 :
4160 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4161 "dfs\t$rT, $rA, $rB", DPrecFP,
4162 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4163
4164def FSv2f64 :
4165 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4166 "dfs\t$rT, $rA, $rB", DPrecFP,
4167 [(set (v2f64 VECREG:$rT),
4168 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4169
4170def FMf64 :
4171 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4172 "dfm\t$rT, $rA, $rB", DPrecFP,
4173 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4174
4175def FMv2f64:
4176 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4177 "dfm\t$rT, $rA, $rB", DPrecFP,
4178 [(set (v2f64 VECREG:$rT),
4179 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4180
4181def FMAf64:
4182 RRForm<0b00111010110, (outs R64FP:$rT),
4183 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4184 "dfma\t$rT, $rA, $rB", DPrecFP,
4185 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4186 RegConstraint<"$rC = $rT">,
4187 NoEncode<"$rC">;
4188
4189def FMAv2f64:
4190 RRForm<0b00111010110, (outs VECREG:$rT),
4191 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4192 "dfma\t$rT, $rA, $rB", DPrecFP,
4193 [(set (v2f64 VECREG:$rT),
4194 (fadd (v2f64 VECREG:$rC),
4195 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4196 RegConstraint<"$rC = $rT">,
4197 NoEncode<"$rC">;
4198
4199def FMSf64 :
4200 RRForm<0b10111010110, (outs R64FP:$rT),
4201 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4202 "dfms\t$rT, $rA, $rB", DPrecFP,
4203 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4204 RegConstraint<"$rC = $rT">,
4205 NoEncode<"$rC">;
4206
4207def FMSv2f64 :
4208 RRForm<0b10111010110, (outs VECREG:$rT),
4209 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4210 "dfms\t$rT, $rA, $rB", DPrecFP,
4211 [(set (v2f64 VECREG:$rT),
4212 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4213 (v2f64 VECREG:$rC)))]>;
4214
4215// FNMS: - (a * b - c)
4216// - (a * b) + c => c - (a * b)
4217def FNMSf64 :
4218 RRForm<0b01111010110, (outs R64FP:$rT),
4219 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4220 "dfnms\t$rT, $rA, $rB", DPrecFP,
4221 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4222 RegConstraint<"$rC = $rT">,
4223 NoEncode<"$rC">;
4224
4225def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4226 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4227
4228def FNMSv2f64 :
4229 RRForm<0b01111010110, (outs VECREG:$rT),
4230 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4231 "dfnms\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004232 [(set (v2f64 VECREG:$rT),
4233 (fsub (v2f64 VECREG:$rC),
4234 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004235 (v2f64 VECREG:$rB))))]>,
4236 RegConstraint<"$rC = $rT">,
4237 NoEncode<"$rC">;
4238
4239def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4240 (v2f64 VECREG:$rC))),
4241 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4242
4243// - (a * b + c)
4244// - (a * b) - c
4245def FNMAf64 :
4246 RRForm<0b11111010110, (outs R64FP:$rT),
4247 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4248 "dfnma\t$rT, $rA, $rB", DPrecFP,
4249 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4250 RegConstraint<"$rC = $rT">,
4251 NoEncode<"$rC">;
4252
4253def FNMAv2f64 :
4254 RRForm<0b11111010110, (outs VECREG:$rT),
4255 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4256 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004257 [(set (v2f64 VECREG:$rT),
4258 (fneg (fadd (v2f64 VECREG:$rC),
4259 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004260 (v2f64 VECREG:$rB)))))]>,
4261 RegConstraint<"$rC = $rT">,
4262 NoEncode<"$rC">;
4263
4264//===----------------------------------------------------------------------==//
4265// Floating point negation and absolute value
4266//===----------------------------------------------------------------------==//
4267
4268def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00004269 (XORfnegvec (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004270 (v4f32 (ILHUv4i32 0x8000)))>;
4271
4272def : Pat<(fneg R32FP:$rA),
4273 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4274
4275def : Pat<(fneg (v2f64 VECREG:$rA)),
4276 (XORfnegvec (v2f64 VECREG:$rA),
4277 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4278
4279def : Pat<(fneg R64FP:$rA),
4280 (XORfneg64 R64FP:$rA,
4281 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4282
4283// Floating point absolute value
4284
4285def : Pat<(fabs R32FP:$rA),
4286 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4287
4288def : Pat<(fabs (v4f32 VECREG:$rA)),
4289 (ANDfabsvec (v4f32 VECREG:$rA),
4290 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4291
4292def : Pat<(fabs R64FP:$rA),
4293 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4294
4295def : Pat<(fabs (v2f64 VECREG:$rA)),
4296 (ANDfabsvec (v2f64 VECREG:$rA),
4297 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4298
4299//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004300// Hint for branch instructions:
4301//===----------------------------------------------------------------------===//
4302
4303/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4304
4305//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004306// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4307// in the odd pipeline)
4308//===----------------------------------------------------------------------===//
4309
Scott Michel97872d32008-02-23 18:41:37 +00004310def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004311 let Pattern = [];
4312
4313 let Inst{0-10} = 0b10000000010;
4314 let Inst{11-17} = 0;
4315 let Inst{18-24} = 0;
4316 let Inst{25-31} = 0;
4317}
4318
Scott Michel97872d32008-02-23 18:41:37 +00004319def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004320 let Pattern = [];
4321
4322 let Inst{0-10} = 0b10000000000;
4323 let Inst{11-17} = 0;
4324 let Inst{18-24} = 0;
4325 let Inst{25-31} = 0;
4326}
4327
4328//===----------------------------------------------------------------------===//
4329// Bit conversions (type conversions between vector/packed types)
4330// NOTE: Promotions are handled using the XS* instructions. Truncation
4331// is not handled.
4332//===----------------------------------------------------------------------===//
4333def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4334def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4335def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4336def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4337def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4338
4339def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4340def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4341def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4342def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4343def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4344
4345def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4346def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4347def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4348def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4349def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4350
4351def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4352def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4353def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4354def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4355def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4356
4357def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4358def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4359def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4360def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4361def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4362
4363def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4364def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4365def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4366def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4367def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4368
4369def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00004370def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004371
4372//===----------------------------------------------------------------------===//
4373// Instruction patterns:
4374//===----------------------------------------------------------------------===//
4375
4376// General 32-bit constants:
4377def : Pat<(i32 imm:$imm),
4378 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4379
4380// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004381def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004382 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4383
4384// General constant 32-bit vectors
4385def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004386 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4387 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004388
Scott Michel438be252007-12-17 22:32:34 +00004389// 8-bit constants
4390def : Pat<(i8 imm:$imm),
4391 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004392
4393//===----------------------------------------------------------------------===//
4394// Call instruction patterns:
4395//===----------------------------------------------------------------------===//
4396// Return void
4397def : Pat<(ret),
4398 (RET)>;
4399
4400//===----------------------------------------------------------------------===//
4401// Zero/Any/Sign extensions
4402//===----------------------------------------------------------------------===//
4403
Scott Michel8b6b4202007-12-04 22:35:58 +00004404// sext 8->32: Sign extend bytes to words
4405def : Pat<(sext_inreg R32C:$rSrc, i8),
4406 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4407
Scott Michel438be252007-12-17 22:32:34 +00004408def : Pat<(i32 (sext R8C:$rSrc)),
4409 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4410
Scott Michel2ef773a2009-01-06 03:36:14 +00004411// sext 8->64: Sign extend bytes to double word
4412def : Pat<(sext_inreg R64C:$rSrc, i8),
4413 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4414
4415def : Pat<(i64 (sext R8C:$rSrc)),
4416 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4417
Scott Michel438be252007-12-17 22:32:34 +00004418// zext 8->16: Zero extend bytes to halfwords
4419def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004420 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004421
Scott Michel438be252007-12-17 22:32:34 +00004422// zext 8->32: Zero extend bytes to words
4423def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004424 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004425
Scott Michel2ef773a2009-01-06 03:36:14 +00004426// zext 8->64: Zero extend bytes to double words
4427def : Pat<(i64 (zext R8C:$rSrc)),
4428 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4429 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4430 0x4),
4431 (ILv4i32 0x0),
4432 (FSMBIv4i32 0x0f0f)))>;
4433
4434// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004435def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004436 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004437
Scott Michel2ef773a2009-01-06 03:36:14 +00004438// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004439def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004440 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004441
Scott Michel2ef773a2009-01-06 03:36:14 +00004442// sext 16->64: Sign extend halfword to double word
4443def : Pat<(sext_inreg R64C:$rSrc, i16),
4444 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4445
4446def : Pat<(sext R16C:$rSrc),
4447 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4448
Scott Michel97872d32008-02-23 18:41:37 +00004449// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004450def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004451 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004452
4453def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004454 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004455
4456def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004457 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004458
4459def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004460 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004461
4462// anyext 16->32: Extend 16->32 bits, irrespective of sign
4463def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004464 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004465
4466//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004467// Truncates:
4468// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4469// above are custom lowered.
4470//===----------------------------------------------------------------------===//
4471
4472def : Pat<(i8 (trunc GPRC:$src)),
4473 (ORi8_v16i8
4474 (SHUFBgprc GPRC:$src, GPRC:$src,
4475 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4476
4477def : Pat<(i8 (trunc R64C:$src)),
4478 (ORi8_v16i8
4479 (SHUFBv2i64_m32
4480 (ORv2i64_i64 R64C:$src),
4481 (ORv2i64_i64 R64C:$src),
4482 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4483
4484def : Pat<(i8 (trunc R32C:$src)),
4485 (ORi8_v16i8
4486 (SHUFBv4i32_m32
4487 (ORv4i32_i32 R32C:$src),
4488 (ORv4i32_i32 R32C:$src),
4489 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4490
4491def : Pat<(i8 (trunc R16C:$src)),
4492 (ORi8_v16i8
4493 (SHUFBv4i32_m32
4494 (ORv8i16_i16 R16C:$src),
4495 (ORv8i16_i16 R16C:$src),
4496 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4497
4498def : Pat<(i16 (trunc GPRC:$src)),
4499 (ORi16_v8i16
4500 (SHUFBgprc GPRC:$src, GPRC:$src,
4501 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4502
4503def : Pat<(i16 (trunc R64C:$src)),
4504 (ORi16_v8i16
4505 (SHUFBv2i64_m32
4506 (ORv2i64_i64 R64C:$src),
4507 (ORv2i64_i64 R64C:$src),
4508 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4509
4510def : Pat<(i16 (trunc R32C:$src)),
4511 (ORi16_v8i16
4512 (SHUFBv4i32_m32
4513 (ORv4i32_i32 R32C:$src),
4514 (ORv4i32_i32 R32C:$src),
4515 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4516
4517def : Pat<(i32 (trunc GPRC:$src)),
4518 (ORi32_v4i32
4519 (SHUFBgprc GPRC:$src, GPRC:$src,
4520 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4521
4522def : Pat<(i32 (trunc R64C:$src)),
4523 (ORi32_v4i32
4524 (SHUFBv2i64_m32
4525 (ORv2i64_i64 R64C:$src),
4526 (ORv2i64_i64 R64C:$src),
4527 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4528
4529//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004530// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004531// low parts in order to load them into a register.
4532//===----------------------------------------------------------------------===//
4533
Scott Michelf9f42e62008-01-29 02:16:57 +00004534def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4535def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4536def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4537def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4538
4539def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4540 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004541 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004542
Scott Michelf9f42e62008-01-29 02:16:57 +00004543def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4544 (SPUlo texternalsym:$in, 0)),
4545 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4546
4547def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4548 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004549 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004550
Scott Michelf9f42e62008-01-29 02:16:57 +00004551def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4552 (SPUlo tconstpool:$in, 0)),
4553 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4554
4555def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4556 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4557
4558def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4559 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4560
4561def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4562 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4563
4564def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4565 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004566
Scott Michel8b6b4202007-12-04 22:35:58 +00004567// Instrinsics:
4568include "CellSDKIntrinsics.td"
Scott Michel4d07fb72008-12-30 23:28:25 +00004569// Various math operator instruction sequences
4570include "SPUMathInstr.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004571// 64-bit "instructions"/support
4572include "SPU64InstrInfo.td"
Scott Michel2ef773a2009-01-06 03:36:14 +00004573// 128-bit "instructions"/support
4574include "SPU128InstrInfo.td"