blob: 1abbc0a5c043220a209b4907e53b956e656cd620 [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 Michelf9f42e62008-01-29 02:16:57 +000074 def r128: LoadDForm<GPRC>;
75 def r64: LoadDForm<R64C>;
76 def r32: LoadDForm<R32C>;
77 def f32: LoadDForm<R32FP>;
78 def f64: LoadDForm<R64FP>;
79 def r16: LoadDForm<R16C>;
80 def r8: LoadDForm<R8C>;
81 }
Scott Michel8b6b4202007-12-04 22:35:58 +000082
Scott Michelf9f42e62008-01-29 02:16:57 +000083 class LoadAFormVec<ValueType vectype>
84 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
85 "lqa\t$rT, $src",
86 LoadStore,
87 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
88 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000089
Scott Michelf9f42e62008-01-29 02:16:57 +000090 class LoadAForm<RegisterClass rclass>
91 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
92 "lqa\t$rT, $src",
93 LoadStore,
94 [(set rclass:$rT, (load aform_addr:$src))]>
95 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000096
Scott Michelf9f42e62008-01-29 02:16:57 +000097 multiclass LoadAForms
98 {
99 def v16i8: LoadAFormVec<v16i8>;
100 def v8i16: LoadAFormVec<v8i16>;
101 def v4i32: LoadAFormVec<v4i32>;
102 def v2i64: LoadAFormVec<v2i64>;
103 def v4f32: LoadAFormVec<v4f32>;
104 def v2f64: LoadAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000105
Scott Michelf9f42e62008-01-29 02:16:57 +0000106 def r128: LoadAForm<GPRC>;
107 def r64: LoadAForm<R64C>;
108 def r32: LoadAForm<R32C>;
109 def f32: LoadAForm<R32FP>;
110 def f64: LoadAForm<R64FP>;
111 def r16: LoadAForm<R16C>;
112 def r8: LoadAForm<R8C>;
113 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000114
Scott Michelf9f42e62008-01-29 02:16:57 +0000115 class LoadXFormVec<ValueType vectype>
116 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
117 "lqx\t$rT, $src",
118 LoadStore,
119 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
120 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000121
Scott Michelf9f42e62008-01-29 02:16:57 +0000122 class LoadXForm<RegisterClass rclass>
123 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
124 "lqx\t$rT, $src",
125 LoadStore,
126 [(set rclass:$rT, (load xform_addr:$src))]>
127 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000128
Scott Michelf9f42e62008-01-29 02:16:57 +0000129 multiclass LoadXForms
130 {
131 def v16i8: LoadXFormVec<v16i8>;
132 def v8i16: LoadXFormVec<v8i16>;
133 def v4i32: LoadXFormVec<v4i32>;
134 def v2i64: LoadXFormVec<v2i64>;
135 def v4f32: LoadXFormVec<v4f32>;
136 def v2f64: LoadXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000137
Scott Michelf9f42e62008-01-29 02:16:57 +0000138 def r128: LoadXForm<GPRC>;
139 def r64: LoadXForm<R64C>;
140 def r32: LoadXForm<R32C>;
141 def f32: LoadXForm<R32FP>;
142 def f64: LoadXForm<R64FP>;
143 def r16: LoadXForm<R16C>;
144 def r8: LoadXForm<R8C>;
145 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000146
Scott Michelf9f42e62008-01-29 02:16:57 +0000147 defm LQA : LoadAForms;
148 defm LQD : LoadDForms;
149 defm LQX : LoadXForms;
Scott Michel438be252007-12-17 22:32:34 +0000150
Scott Michel8b6b4202007-12-04 22:35:58 +0000151/* Load quadword, PC relative: Not much use at this point in time.
Scott Michelf9f42e62008-01-29 02:16:57 +0000152 Might be of use later for relocatable code. It's effectively the
153 same as LQA, but uses PC-relative addressing.
Scott Michel8b6b4202007-12-04 22:35:58 +0000154 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
155 "lqr\t$rT, $disp", LoadStore,
156 [(set VECREG:$rT, (load iaddr:$disp))]>;
157 */
Scott Michel8b6b4202007-12-04 22:35:58 +0000158}
159
160//===----------------------------------------------------------------------===//
161// Stores:
162//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +0000163class StoreDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +0000164 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000165 "stqd\t$rT, $src",
166 LoadStore,
167 [(store (vectype VECREG:$rT), dform_addr:$src)]>
168{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000169
Scott Michelf9f42e62008-01-29 02:16:57 +0000170class StoreDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +0000171 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000172 "stqd\t$rT, $src",
173 LoadStore,
174 [(store rclass:$rT, dform_addr:$src)]>
175{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000176
Scott Michelf9f42e62008-01-29 02:16:57 +0000177multiclass StoreDForms
178{
179 def v16i8: StoreDFormVec<v16i8>;
180 def v8i16: StoreDFormVec<v8i16>;
181 def v4i32: StoreDFormVec<v4i32>;
182 def v2i64: StoreDFormVec<v2i64>;
183 def v4f32: StoreDFormVec<v4f32>;
184 def v2f64: StoreDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000185
Scott Michelf9f42e62008-01-29 02:16:57 +0000186 def r128: StoreDForm<GPRC>;
187 def r64: StoreDForm<R64C>;
188 def r32: StoreDForm<R32C>;
189 def f32: StoreDForm<R32FP>;
190 def f64: StoreDForm<R64FP>;
191 def r16: StoreDForm<R16C>;
192 def r8: StoreDForm<R8C>;
193}
Scott Michel8b6b4202007-12-04 22:35:58 +0000194
Scott Michelf9f42e62008-01-29 02:16:57 +0000195class StoreAFormVec<ValueType vectype>
196 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000197 "stqa\t$rT, $src",
198 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000199 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000200
Scott Michelf9f42e62008-01-29 02:16:57 +0000201class StoreAForm<RegisterClass rclass>
202 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000203 "stqa\t$rT, $src",
204 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000205 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000206
Scott Michelf9f42e62008-01-29 02:16:57 +0000207multiclass StoreAForms
208{
209 def v16i8: StoreAFormVec<v16i8>;
210 def v8i16: StoreAFormVec<v8i16>;
211 def v4i32: StoreAFormVec<v4i32>;
212 def v2i64: StoreAFormVec<v2i64>;
213 def v4f32: StoreAFormVec<v4f32>;
214 def v2f64: StoreAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000215
Scott Michelf9f42e62008-01-29 02:16:57 +0000216 def r128: StoreAForm<GPRC>;
217 def r64: StoreAForm<R64C>;
218 def r32: StoreAForm<R32C>;
219 def f32: StoreAForm<R32FP>;
220 def f64: StoreAForm<R64FP>;
221 def r16: StoreAForm<R16C>;
222 def r8: StoreAForm<R8C>;
223}
Scott Michel8b6b4202007-12-04 22:35:58 +0000224
Scott Michelf9f42e62008-01-29 02:16:57 +0000225class StoreXFormVec<ValueType vectype>
226 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000227 "stqx\t$rT, $src",
228 LoadStore,
229 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000230{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000231
Scott Michelf9f42e62008-01-29 02:16:57 +0000232class StoreXForm<RegisterClass rclass>
233 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000234 "stqx\t$rT, $src",
235 LoadStore,
236 [(store rclass:$rT, xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000237{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000238
Scott Michelf9f42e62008-01-29 02:16:57 +0000239multiclass StoreXForms
240{
241 def v16i8: StoreXFormVec<v16i8>;
242 def v8i16: StoreXFormVec<v8i16>;
243 def v4i32: StoreXFormVec<v4i32>;
244 def v2i64: StoreXFormVec<v2i64>;
245 def v4f32: StoreXFormVec<v4f32>;
246 def v2f64: StoreXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000247
Scott Michelf9f42e62008-01-29 02:16:57 +0000248 def r128: StoreXForm<GPRC>;
249 def r64: StoreXForm<R64C>;
250 def r32: StoreXForm<R32C>;
251 def f32: StoreXForm<R32FP>;
252 def f64: StoreXForm<R64FP>;
253 def r16: StoreXForm<R16C>;
254 def r8: StoreXForm<R8C>;
255}
Scott Michel8b6b4202007-12-04 22:35:58 +0000256
Scott Michelf9f42e62008-01-29 02:16:57 +0000257defm STQD : StoreDForms;
258defm STQA : StoreAForms;
259defm STQX : StoreXForms;
Scott Michel8b6b4202007-12-04 22:35:58 +0000260
261/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michelf9f42e62008-01-29 02:16:57 +0000262 be useful for relocatable code.
Chris Lattneref8d6082008-01-06 06:44:58 +0000263def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
264 "stqr\t$rT, $disp", LoadStore,
265 [(store VECREG:$rT, iaddr:$disp)]>;
266*/
Scott Michel8b6b4202007-12-04 22:35:58 +0000267
268//===----------------------------------------------------------------------===//
269// Generate Controls for Insertion:
270//===----------------------------------------------------------------------===//
271
Scott Michel06eabde2008-12-27 04:51:36 +0000272def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000273 "cbd\t$rT, $src", ShuffleOp,
274 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000275
Scott Michel0718cd82008-12-01 17:56:02 +0000276def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000277 "cbx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000278 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000279
Scott Michel06eabde2008-12-27 04:51:36 +0000280def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000281 "chd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000282 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000283
Scott Michel0718cd82008-12-01 17:56:02 +0000284def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000285 "chx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000286 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000287
Scott Michel06eabde2008-12-27 04:51:36 +0000288def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000289 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000290 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000291
Scott Michel0718cd82008-12-01 17:56:02 +0000292def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000293 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000294 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000295
Scott Michel06eabde2008-12-27 04:51:36 +0000296def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000297 "cwd\t$rT, $src", ShuffleOp,
298 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
299
300def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000301 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000302 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000303
Scott Michel06eabde2008-12-27 04:51:36 +0000304def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000305 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000306 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000307
Scott Michel0718cd82008-12-01 17:56:02 +0000308def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000309 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000310 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000311
Scott Michel06eabde2008-12-27 04:51:36 +0000312def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000313 "cdd\t$rT, $src", ShuffleOp,
314 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
315
316def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000317 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000318 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000319
Scott Michel8b6b4202007-12-04 22:35:58 +0000320//===----------------------------------------------------------------------===//
321// Constant formation:
322//===----------------------------------------------------------------------===//
323
324def ILHv8i16:
325 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
326 "ilh\t$rT, $val", ImmLoad,
327 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
328
329def ILHr16:
330 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
331 "ilh\t$rT, $val", ImmLoad,
332 [(set R16C:$rT, immSExt16:$val)]>;
333
Scott Michel438be252007-12-17 22:32:34 +0000334// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
335// the right constant")
336def ILHr8:
337 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
338 "ilh\t$rT, $val", ImmLoad,
339 [(set R8C:$rT, immSExt8:$val)]>;
340
Scott Michel8b6b4202007-12-04 22:35:58 +0000341// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000342
Scott Michel6baba072008-03-05 23:02:02 +0000343class ILInst<dag OOL, dag IOL, list<dag> pattern>:
344 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
345 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000346
Scott Michel6baba072008-03-05 23:02:02 +0000347class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
348 ILInst<(outs VECREG:$rT), (ins immtype:$val),
349 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000350
Scott Michel6baba072008-03-05 23:02:02 +0000351class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
352 ILInst<(outs rclass:$rT), (ins immtype:$val),
353 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000354
Scott Michel6baba072008-03-05 23:02:02 +0000355multiclass ImmediateLoad
356{
357 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
358 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000359
Scott Michel6baba072008-03-05 23:02:02 +0000360 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000361
Scott Michel6baba072008-03-05 23:02:02 +0000362 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
363 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
364 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
365 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
366}
Scott Michel8b6b4202007-12-04 22:35:58 +0000367
Scott Michel6baba072008-03-05 23:02:02 +0000368defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000369
Scott Michel6baba072008-03-05 23:02:02 +0000370class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
371 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
372 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000373
Scott Michel6baba072008-03-05 23:02:02 +0000374class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
375 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
376 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
377
378class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
379 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
380 [(set rclass:$rT, xform:$val)]>;
381
382multiclass ImmLoadHalfwordUpper
383{
384 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000385 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000386
387 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000388 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000389
390 // Loads the high portion of an address
391 def hi: ILHURegInst<R32C, symbolHi, hi16>;
392
393 // Used in custom lowering constant SFP loads:
394 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
395}
396
397defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000398
399// Immediate load address (can also be used to load 18-bit unsigned constants,
400// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000401
Scott Michel97872d32008-02-23 18:41:37 +0000402class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
403 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
404 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000405
Scott Michel6baba072008-03-05 23:02:02 +0000406class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
407 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
408 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
409
410class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
411 ILAInst<(outs rclass:$rT), (ins immtype:$val),
412 [(set rclass:$rT, xform:$val)]>;
413
Scott Michel97872d32008-02-23 18:41:37 +0000414multiclass ImmLoadAddress
415{
Scott Michel6baba072008-03-05 23:02:02 +0000416 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
417 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000418
Scott Michel6baba072008-03-05 23:02:02 +0000419 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
420 def r32: ILARegInst<R32C, u18imm, imm18>;
421 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
422 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000423
Scott Michel06eabde2008-12-27 04:51:36 +0000424 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michel6baba072008-03-05 23:02:02 +0000425 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000426
Scott Michel97872d32008-02-23 18:41:37 +0000427 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
428 [/* no pattern */]>;
429}
430
431defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000432
433// Immediate OR, Halfword Lower: The "other" part of loading large constants
434// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
435// Note that these are really two operand instructions, but they're encoded
436// as three operands with the first two arguments tied-to each other.
437
Scott Michel6baba072008-03-05 23:02:02 +0000438class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
439 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
440 ImmLoad, pattern>,
441 RegConstraint<"$rS = $rT">,
442 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000443
Scott Michel6baba072008-03-05 23:02:02 +0000444class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
445 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
446 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000447
Scott Michel6baba072008-03-05 23:02:02 +0000448class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
449 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
450 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000451
Scott Michel6baba072008-03-05 23:02:02 +0000452multiclass ImmOrHalfwordLower
453{
454 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000455 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000456
457 def r32: IOHLRegInst<R32C, i32imm>;
458 def f32: IOHLRegInst<R32FP, f32imm>;
459
460 def lo: IOHLRegInst<R32C, symbolLo>;
461}
462
463defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000464
Scott Michel8b6b4202007-12-04 22:35:58 +0000465// Form select mask for bytes using immediate, used in conjunction with the
466// SELB instruction:
467
Scott Michel6baba072008-03-05 23:02:02 +0000468class FSMBIVec<ValueType vectype>:
469 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
470 "fsmbi\t$rT, $val",
471 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000472 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000473
Scott Michel97872d32008-02-23 18:41:37 +0000474multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000475{
476 def v16i8: FSMBIVec<v16i8>;
477 def v8i16: FSMBIVec<v8i16>;
478 def v4i32: FSMBIVec<v4i32>;
479 def v2i64: FSMBIVec<v2i64>;
480}
Scott Michel8b6b4202007-12-04 22:35:58 +0000481
Scott Michel97872d32008-02-23 18:41:37 +0000482defm FSMBI : FormSelectMaskBytesImm;
483
484// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michel06eabde2008-12-27 04:51:36 +0000485class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
486 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
487 pattern>;
488
489class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
490 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
491 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
492
493class FSMBVecInst<ValueType vectype>:
494 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
495 [(set (vectype VECREG:$rT),
496 (SPUselmask (vectype VECREG:$rA)))]>;
497
498multiclass FormSelectMaskBits {
499 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
500 def v16i8: FSMBVecInst<v16i8>;
501}
502
503defm FSMB: FormSelectMaskBits;
Scott Michel97872d32008-02-23 18:41:37 +0000504
505// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
506// only 8-bits wide (even though it's input as 16-bits here)
Scott Michel06eabde2008-12-27 04:51:36 +0000507
508class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
509 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
510 pattern>;
511
512class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
513 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
514 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
515
516class FSMHVecInst<ValueType vectype>:
517 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
518 [(set (vectype VECREG:$rT),
519 (SPUselmask (vectype VECREG:$rA)))]>;
520
521multiclass FormSelectMaskHalfword {
522 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
523 def v8i16: FSMHVecInst<v8i16>;
524}
525
526defm FSMH: FormSelectMaskHalfword;
Scott Michel97872d32008-02-23 18:41:37 +0000527
528// fsm: Form select mask for words. Like the other fsm* instructions,
529// only the lower 4 bits of $rA are significant.
Scott Michel06eabde2008-12-27 04:51:36 +0000530
531class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
532 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
533 pattern>;
534
535class FSMRegInst<ValueType vectype, RegisterClass rclass>:
536 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
537 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
538
539class FSMVecInst<ValueType vectype>:
540 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
541 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel67224b22008-06-02 22:18:03 +0000542
543multiclass FormSelectMaskWord {
Scott Michel06eabde2008-12-27 04:51:36 +0000544 def v4i32: FSMVecInst<v4i32>;
545
546 def r32 : FSMRegInst<v4i32, R32C>;
547 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000548}
549
550defm FSM : FormSelectMaskWord;
551
552// Special case when used for i64 math operations
553multiclass FormSelectMaskWord64 {
Scott Michel06eabde2008-12-27 04:51:36 +0000554 def r32 : FSMRegInst<v2i64, R32C>;
555 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000556}
557
558defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000559
560//===----------------------------------------------------------------------===//
561// Integer and Logical Operations:
562//===----------------------------------------------------------------------===//
563
564def AHv8i16:
565 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
566 "ah\t$rT, $rA, $rB", IntegerOp,
567 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
568
569def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
570 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
571
Scott Michel8b6b4202007-12-04 22:35:58 +0000572def AHr16:
573 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
574 "ah\t$rT, $rA, $rB", IntegerOp,
575 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
576
577def AHIvec:
578 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
579 "ahi\t$rT, $rA, $val", IntegerOp,
580 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
581 v8i16SExt10Imm:$val))]>;
582
Scott Michel97872d32008-02-23 18:41:37 +0000583def AHIr16:
584 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
585 "ahi\t$rT, $rA, $val", IntegerOp,
586 [(set R16C:$rT, (add R16C:$rA, v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000587
Scott Michelae5cbf52008-12-29 03:23:36 +0000588class AInst<dag OOL, dag IOL, list<dag> pattern>:
589 RRForm<0b00000011000, OOL, IOL,
590 "a\t$rT, $rA, $rB", IntegerOp,
591 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000592
Scott Michelae5cbf52008-12-29 03:23:36 +0000593class AVecInst<ValueType vectype>:
594 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
595 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
596 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000597
Scott Michelae5cbf52008-12-29 03:23:36 +0000598class ARegInst<RegisterClass rclass>:
599 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
600 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
601
602multiclass AddInstruction {
603 def v4i32: AVecInst<v4i32>;
604 def v16i8: AVecInst<v16i8>;
605
606 def r32: ARegInst<R32C>;
607 def r8: AInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB), [/* no pattern */]>;
608}
Scott Michel8b6b4202007-12-04 22:35:58 +0000609
Scott Michelae5cbf52008-12-29 03:23:36 +0000610defm A : AddInstruction;
Scott Michel438be252007-12-17 22:32:34 +0000611
Scott Michel8b6b4202007-12-04 22:35:58 +0000612def AIvec:
613 RI10Form<0b00111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
614 "ai\t$rT, $rA, $val", IntegerOp,
615 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA),
616 v4i32SExt10Imm:$val))]>;
617
Scott Michel438be252007-12-17 22:32:34 +0000618def AIr32:
619 RI10Form<0b00111000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
620 "ai\t$rT, $rA, $val", IntegerOp,
621 [(set R32C:$rT, (add R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000622
Scott Michel438be252007-12-17 22:32:34 +0000623def SFHvec:
624 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
625 "sfh\t$rT, $rA, $rB", IntegerOp,
626 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
627 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000628
Scott Michel438be252007-12-17 22:32:34 +0000629def SFHr16:
630 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
631 "sfh\t$rT, $rA, $rB", IntegerOp,
632 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000633
634def SFHIvec:
635 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
636 "sfhi\t$rT, $rA, $val", IntegerOp,
637 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
638 (v8i16 VECREG:$rA)))]>;
639
640def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
641 "sfhi\t$rT, $rA, $val", IntegerOp,
642 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
643
644def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
645 (ins VECREG:$rA, VECREG:$rB),
646 "sf\t$rT, $rA, $rB", IntegerOp,
647 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
648
649def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
650 "sf\t$rT, $rA, $rB", IntegerOp,
651 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
652
653def SFIvec:
654 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
655 "sfi\t$rT, $rA, $val", IntegerOp,
656 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
657 (v4i32 VECREG:$rA)))]>;
658
659def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
660 (ins R32C:$rA, s10imm_i32:$val),
661 "sfi\t$rT, $rA, $val", IntegerOp,
662 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
663
664// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000665class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
666 RRForm<0b00000010110, OOL, IOL,
667 "addx\t$rT, $rA, $rB",
668 IntegerOp, pattern>;
669
670class ADDXVecInst<ValueType vectype>:
671 ADDXInst<(outs VECREG:$rT),
672 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
673 [(set (vectype VECREG:$rT),
674 (SPUaddx (vectype VECREG:$rA), (vectype VECREG:$rB),
675 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000676 RegConstraint<"$rCarry = $rT">,
677 NoEncode<"$rCarry">;
678
Scott Michel67224b22008-06-02 22:18:03 +0000679class ADDXRegInst<RegisterClass rclass>:
680 ADDXInst<(outs rclass:$rT),
681 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
682 [(set rclass:$rT,
683 (SPUaddx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000684 RegConstraint<"$rCarry = $rT">,
685 NoEncode<"$rCarry">;
686
Scott Michel67224b22008-06-02 22:18:03 +0000687multiclass AddExtended {
688 def v2i64 : ADDXVecInst<v2i64>;
689 def v4i32 : ADDXVecInst<v4i32>;
690 def r64 : ADDXRegInst<R64C>;
691 def r32 : ADDXRegInst<R32C>;
692}
693
694defm ADDX : AddExtended;
695
696// CG: Generate carry for add
697class CGInst<dag OOL, dag IOL, list<dag> pattern>:
698 RRForm<0b01000011000, OOL, IOL,
699 "cg\t$rT, $rA, $rB",
700 IntegerOp, pattern>;
701
702class CGVecInst<ValueType vectype>:
703 CGInst<(outs VECREG:$rT),
704 (ins VECREG:$rA, VECREG:$rB),
705 [(set (vectype VECREG:$rT),
706 (SPUcarry_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
707
708class CGRegInst<RegisterClass rclass>:
709 CGInst<(outs rclass:$rT),
710 (ins rclass:$rA, rclass:$rB),
711 [(set rclass:$rT,
712 (SPUcarry_gen rclass:$rA, rclass:$rB))]>;
713
714multiclass CarryGenerate {
715 def v2i64 : CGVecInst<v2i64>;
716 def v4i32 : CGVecInst<v4i32>;
717 def r64 : CGRegInst<R64C>;
718 def r32 : CGRegInst<R32C>;
719}
720
721defm CG : CarryGenerate;
722
723// SFX: Subract from, extended. This is used in conjunction with BG to subtract
724// with carry (borrow, in this case)
725class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
726 RRForm<0b10000010110, OOL, IOL,
727 "sfx\t$rT, $rA, $rB",
728 IntegerOp, pattern>;
729
730class SFXVecInst<ValueType vectype>:
731 SFXInst<(outs VECREG:$rT),
732 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
733 [(set (vectype VECREG:$rT),
734 (SPUsubx (vectype VECREG:$rA), (vectype VECREG:$rB),
735 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000736 RegConstraint<"$rCarry = $rT">,
737 NoEncode<"$rCarry">;
738
Scott Michel67224b22008-06-02 22:18:03 +0000739class SFXRegInst<RegisterClass rclass>:
740 SFXInst<(outs rclass:$rT),
741 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
742 [(set rclass:$rT,
743 (SPUsubx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
744 RegConstraint<"$rCarry = $rT">,
745 NoEncode<"$rCarry">;
746
747multiclass SubtractExtended {
748 def v2i64 : SFXVecInst<v2i64>;
749 def v4i32 : SFXVecInst<v4i32>;
750 def r64 : SFXRegInst<R64C>;
751 def r32 : SFXRegInst<R32C>;
752}
753
754defm SFX : SubtractExtended;
755
Scott Michel8b6b4202007-12-04 22:35:58 +0000756// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000757class BGInst<dag OOL, dag IOL, list<dag> pattern>:
758 RRForm<0b01000010000, OOL, IOL,
759 "bg\t$rT, $rA, $rB",
760 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000761
Scott Michel67224b22008-06-02 22:18:03 +0000762class BGVecInst<ValueType vectype>:
763 BGInst<(outs VECREG:$rT),
764 (ins VECREG:$rA, VECREG:$rB),
765 [(set (vectype VECREG:$rT),
766 (SPUborrow_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
767
768class BGRegInst<RegisterClass rclass>:
769 BGInst<(outs rclass:$rT),
770 (ins rclass:$rA, rclass:$rB),
771 [(set rclass:$rT,
772 (SPUborrow_gen rclass:$rA, rclass:$rB))]>;
773
774multiclass BorrowGenerate {
775 def v4i32 : BGVecInst<v4i32>;
776 def v2i64 : BGVecInst<v2i64>;
777 def r64 : BGRegInst<R64C>;
778 def r32 : BGRegInst<R32C>;
779}
780
781defm BG : BorrowGenerate;
782
783// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000784def BGXvec:
785 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000786 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000787 "bgx\t$rT, $rA, $rB", IntegerOp,
788 []>,
789 RegConstraint<"$rCarry = $rT">,
790 NoEncode<"$rCarry">;
791
792// Halfword multiply variants:
793// N.B: These can be used to build up larger quantities (16x16 -> 32)
794
795def MPYv8i16:
796 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
797 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000798 [(set (v8i16 VECREG:$rT), (SPUmpy_vec (v8i16 VECREG:$rA),
799 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000800
801def MPYr16:
802 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
803 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
804 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
805
Scott Michelae5cbf52008-12-29 03:23:36 +0000806// Unsigned 16-bit multiply:
807
808class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
809 RRForm<0b00110011110, OOL, IOL,
810 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
811 pattern>;
812
Scott Michel8b6b4202007-12-04 22:35:58 +0000813def MPYUv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000814 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
815 [(set (v4i32 VECREG:$rT),
816 (SPUmpyu_vec (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000817
818def MPYUr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000819 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
820 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000821
822def MPYUr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000823 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
824 [(set R32C:$rT, (SPUmpyu_int R32C:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000825
Scott Michelae5cbf52008-12-29 03:23:36 +0000826// mpyi: multiply 16 x s10imm -> 32 result.
827
828class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
829 RI10Form<0b00101110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000830 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000831 pattern>;
832
833def MPYIvec:
834 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
835 [(set (v8i16 VECREG:$rT),
836 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000837
838def MPYIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000839 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
840 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000841
842// mpyui: same issues as other multiplies, plus, this doesn't match a
843// pattern... but may be used during target DAG selection or lowering
Scott Michelae5cbf52008-12-29 03:23:36 +0000844
845class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
846 RI10Form<0b10101110, OOL, IOL,
847 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
848 pattern>;
849
Scott Michel8b6b4202007-12-04 22:35:58 +0000850def MPYUIvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000851 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
852 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000853
854def MPYUIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000855 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
856 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000857
858// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michelae5cbf52008-12-29 03:23:36 +0000859class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
860 RRRForm<0b0011, OOL, IOL,
861 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
862 pattern>;
863
Scott Michel8b6b4202007-12-04 22:35:58 +0000864def MPYAvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000865 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
866 [(set (v4i32 VECREG:$rT),
867 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
868 (v8i16 VECREG:$rB)))),
869 (v4i32 VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000870
871def MPYAr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000872 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
873 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
874 R32C:$rC))]>;
875
876def MPYAr32_sext:
877 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
878 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
879 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000880
881def MPYAr32_sextinreg:
Scott Michelae5cbf52008-12-29 03:23:36 +0000882 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
883 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
884 (sext_inreg R32C:$rB, i16)),
885 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000886
887// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michelae5cbf52008-12-29 03:23:36 +0000888class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
889 RRForm<0b10100011110, OOL, IOL,
890 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
891 pattern>;
892
Scott Michel8b6b4202007-12-04 22:35:58 +0000893def MPYHv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000894 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
895 [(set (v4i32 VECREG:$rT),
896 (SPUmpyh_vec (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000897
898def MPYHr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000899 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
900 [(set R32C:$rT, (SPUmpyh_int R32C:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000901
902// mpys: multiply high and shift right (returns the top half of
903// a 16-bit multiply, sign extended to 32 bits.)
904def MPYSvec:
905 RRForm<0b11100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
906 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
907 []>;
908
909def MPYSr16:
910 RRForm<0b11100011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
911 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
912 []>;
913
914// mpyhh: multiply high-high (returns the 32-bit result from multiplying
915// the top 16 bits of the $rA, $rB)
916def MPYHHv8i16:
917 RRForm<0b01100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
918 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
919 [(set (v8i16 VECREG:$rT),
Scott Michelae5cbf52008-12-29 03:23:36 +0000920 (SPUmpyhh_vec (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000921
922def MPYHHr32:
923 RRForm<0b01100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
924 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
925 []>;
926
927// mpyhha: Multiply high-high, add to $rT:
928def MPYHHAvec:
929 RRForm<0b01100010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
930 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
931 []>;
932
933def MPYHHAr32:
934 RRForm<0b01100010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
935 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
936 []>;
937
938// mpyhhu: Multiply high-high, unsigned
939def MPYHHUvec:
940 RRForm<0b01110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
941 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
942 []>;
943
944def MPYHHUr32:
945 RRForm<0b01110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
946 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
947 []>;
948
949// mpyhhau: Multiply high-high, unsigned
950def MPYHHAUvec:
951 RRForm<0b01110010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
952 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
953 []>;
954
955def MPYHHAUr32:
956 RRForm<0b01110010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
957 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
958 []>;
959
Scott Michelae5cbf52008-12-29 03:23:36 +0000960//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
961// v4i32, i32 multiply instruction sequence:
962//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
963def MPYv4i32:
964 Pat<(mul (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)),
965 (Av4i32
966 (Av4i32 (MPYHv4i32 VECREG:$rA, VECREG:$rB),
967 (MPYHv4i32 VECREG:$rB, VECREG:$rA)),
968 (MPYUv4i32 VECREG:$rA, VECREG:$rB))>;
969
970def MPYi32:
971 Pat<(mul R32C:$rA, R32C:$rB),
972 (Ar32
973 (Ar32 (MPYHr32 R32C:$rA, R32C:$rB),
974 (MPYHr32 R32C:$rB, R32C:$rA)),
975 (MPYUr32 R32C:$rA, R32C:$rB))>;
976
977//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +0000978// clz: Count leading zeroes
Scott Michelae5cbf52008-12-29 03:23:36 +0000979//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel06eabde2008-12-27 04:51:36 +0000980class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
981 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
982 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000983
Scott Michel06eabde2008-12-27 04:51:36 +0000984class CLZRegInst<RegisterClass rclass>:
985 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
986 [(set rclass:$rT, (ctlz rclass:$rA))]>;
987
988class CLZVecInst<ValueType vectype>:
989 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
990 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
991
992multiclass CountLeadingZeroes {
993 def v4i32 : CLZVecInst<v4i32>;
994 def r32 : CLZRegInst<R32C>;
995}
996
997defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +0000998
999// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +00001000//
Scott Michel8b6b4202007-12-04 22:35:58 +00001001// NOTE: This instruction is really a vector instruction, but the custom
1002// lowering code uses it in unorthodox ways to support CTPOP for other
1003// data types!
Scott Michel06eabde2008-12-27 04:51:36 +00001004
Scott Michel8b6b4202007-12-04 22:35:58 +00001005def CNTBv16i8:
1006 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1007 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001008 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001009
1010def CNTBv8i16 :
1011 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1012 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001013 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001014
1015def CNTBv4i32 :
1016 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1017 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001018 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001019
Scott Michel06eabde2008-12-27 04:51:36 +00001020// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1021// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1022// slots 1-3.
1023//
1024// Note: This instruction "pairs" with the fsmb instruction for all of the
1025// various types defined here.
1026//
1027// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1028// a vector or register.
1029
1030class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1031 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1032
1033class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1034 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
1035 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1036
1037class GBBVecInst<ValueType vectype>:
1038 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1039 [(set (vectype VECREG:$rT), (SPUgatherbits (vectype VECREG:$rA)))]>;
1040
1041multiclass GatherBitsFromBytes {
1042 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1043 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1044 def v16i8: GBBVecInst<v16i8>;
1045}
1046
1047defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001048
1049// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001050// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1051// and slots 1-3 also set to 0.
1052//
1053// See notes for GBBInst, above.
1054
1055class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1056 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1057 pattern>;
1058
1059class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1060 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
1061 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1062
1063class GBHVecInst<ValueType vectype>:
1064 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
1065 [(set (vectype VECREG:$rT),
1066 (SPUgatherbits (vectype VECREG:$rA)))]>;
1067
1068multiclass GatherBitsHalfword {
1069 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1070 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1071 def v8i16: GBHVecInst<v8i16>;
1072}
1073
1074defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001075
1076// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001077// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1078// as well as slots 1-3.
1079//
1080// See notes for gbb, above.
1081
1082class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1083 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1084 pattern>;
1085
1086class GBRegInst<RegisterClass rclass, ValueType vectype>:
1087 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
1088 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1089
1090class GBVecInst<ValueType vectype>:
1091 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1092 [(set (vectype VECREG:$rT),
1093 (SPUgatherbits (vectype VECREG:$rA)))]>;
1094
1095multiclass GatherBitsWord {
1096 def v4i32_r32: GBRegInst<R32C, v4i32>;
1097 def v4i32_r16: GBRegInst<R16C, v4i32>;
1098 def v4i32: GBVecInst<v4i32>;
1099}
1100
1101defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001102
1103// avgb: average bytes
1104def AVGB:
1105 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1106 "avgb\t$rT, $rA, $rB", ByteOp,
1107 []>;
1108
1109// absdb: absolute difference of bytes
1110def ABSDB:
1111 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1112 "absdb\t$rT, $rA, $rB", ByteOp,
1113 []>;
1114
1115// sumb: sum bytes into halfwords
1116def SUMB:
1117 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1118 "sumb\t$rT, $rA, $rB", ByteOp,
1119 []>;
1120
1121// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001122class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1123 RRForm_1<0b01101101010, OOL, IOL,
1124 "xsbh\t$rDst, $rSrc",
1125 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001126
Scott Michel67224b22008-06-02 22:18:03 +00001127class XSBHVecInst<ValueType vectype>:
1128 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1129 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001130
Scott Michel06eabde2008-12-27 04:51:36 +00001131class XSBHInRegInst<RegisterClass rclass>:
Scott Michel67224b22008-06-02 22:18:03 +00001132 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
1133 [(set rclass:$rDst, (sext_inreg rclass:$rSrc, i8))]>;
1134
1135multiclass ExtendByteHalfword {
1136 def v16i8: XSBHVecInst<v8i16>;
Scott Michel06eabde2008-12-27 04:51:36 +00001137 def r16: XSBHInRegInst<R16C>;
1138 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1139 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001140
1141 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1142 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1143 // pattern below). Intentionally doesn't match a pattern because we want the
1144 // sext 8->32 pattern to do the work for us, namely because we need the extra
1145 // XSHWr32.
Scott Michel06eabde2008-12-27 04:51:36 +00001146 def r32: XSBHInRegInst<R32C>;
Scott Michel67224b22008-06-02 22:18:03 +00001147}
1148
1149defm XSBH : ExtendByteHalfword;
1150
Scott Michel8b6b4202007-12-04 22:35:58 +00001151// Sign extend halfwords to words:
1152def XSHWvec:
1153 RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
1154 "xshw\t$rDest, $rSrc", IntegerOp,
1155 [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
1156
1157def XSHWr32:
1158 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
1159 "xshw\t$rDst, $rSrc", IntegerOp,
1160 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
1161
1162def XSHWr16:
1163 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
1164 "xshw\t$rDst, $rSrc", IntegerOp,
1165 [(set R32C:$rDst, (sext R16C:$rSrc))]>;
1166
1167def XSWDvec:
1168 RRForm_1<0b01100101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
1169 "xswd\t$rDst, $rSrc", IntegerOp,
1170 [(set (v2i64 VECREG:$rDst), (sext (v4i32 VECREG:$rSrc)))]>;
1171
1172def XSWDr64:
1173 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R64C:$rSrc),
1174 "xswd\t$rDst, $rSrc", IntegerOp,
1175 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1176
1177def XSWDr32:
1178 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R32C:$rSrc),
1179 "xswd\t$rDst, $rSrc", IntegerOp,
1180 [(set R64C:$rDst, (SPUsext32_to_64 R32C:$rSrc))]>;
1181
1182def : Pat<(sext R32C:$inp),
1183 (XSWDr32 R32C:$inp)>;
1184
1185// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001186
Scott Michel97872d32008-02-23 18:41:37 +00001187class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1188 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1189 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001190
Scott Michel97872d32008-02-23 18:41:37 +00001191class ANDVecInst<ValueType vectype>:
1192 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1193 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1194 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001195
Scott Michel6baba072008-03-05 23:02:02 +00001196class ANDRegInst<RegisterClass rclass>:
1197 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1198 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1199
Scott Michel97872d32008-02-23 18:41:37 +00001200multiclass BitwiseAnd
1201{
1202 def v16i8: ANDVecInst<v16i8>;
1203 def v8i16: ANDVecInst<v8i16>;
1204 def v4i32: ANDVecInst<v4i32>;
1205 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001206
Scott Michel6baba072008-03-05 23:02:02 +00001207 def r128: ANDRegInst<GPRC>;
1208 def r64: ANDRegInst<R64C>;
1209 def r32: ANDRegInst<R32C>;
1210 def r16: ANDRegInst<R16C>;
1211 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001212
Scott Michel97872d32008-02-23 18:41:37 +00001213 //===---------------------------------------------
1214 // Special instructions to perform the fabs instruction
1215 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1216 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001217
Scott Michel97872d32008-02-23 18:41:37 +00001218 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1219 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001220
Scott Michel97872d32008-02-23 18:41:37 +00001221 // Could use v4i32, but won't for clarity
1222 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1223 [/* Intentionally does not match a pattern */]>;
1224
1225 //===---------------------------------------------
1226
1227 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1228 // quantities -- see 16->32 zext pattern.
1229 //
1230 // This pattern is somewhat artificial, since it might match some
1231 // compiler generated pattern but it is unlikely to do so.
1232
1233 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1234 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1235}
1236
1237defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001238
1239// N.B.: vnot_conv is one of those special target selection pattern fragments,
1240// in which we expect there to be a bit_convert on the constant. Bear in mind
1241// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1242// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001243
Scott Michel97872d32008-02-23 18:41:37 +00001244class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1245 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1246 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001247
Scott Michel97872d32008-02-23 18:41:37 +00001248class ANDCVecInst<ValueType vectype>:
1249 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1250 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1251 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001252
Scott Michel97872d32008-02-23 18:41:37 +00001253class ANDCRegInst<RegisterClass rclass>:
1254 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1255 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001256
Scott Michel97872d32008-02-23 18:41:37 +00001257multiclass AndComplement
1258{
1259 def v16i8: ANDCVecInst<v16i8>;
1260 def v8i16: ANDCVecInst<v8i16>;
1261 def v4i32: ANDCVecInst<v4i32>;
1262 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001263
Scott Michel97872d32008-02-23 18:41:37 +00001264 def r128: ANDCRegInst<GPRC>;
1265 def r64: ANDCRegInst<R64C>;
1266 def r32: ANDCRegInst<R32C>;
1267 def r16: ANDCRegInst<R16C>;
1268 def r8: ANDCRegInst<R8C>;
1269}
Scott Michel438be252007-12-17 22:32:34 +00001270
Scott Michel97872d32008-02-23 18:41:37 +00001271defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001272
Scott Michel97872d32008-02-23 18:41:37 +00001273class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1274 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001275 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001276
Scott Michel97872d32008-02-23 18:41:37 +00001277multiclass AndByteImm
1278{
1279 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1280 [(set (v16i8 VECREG:$rT),
1281 (and (v16i8 VECREG:$rA),
1282 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001283
Scott Michel97872d32008-02-23 18:41:37 +00001284 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1285 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1286}
Scott Michel438be252007-12-17 22:32:34 +00001287
Scott Michel97872d32008-02-23 18:41:37 +00001288defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001289
Scott Michel97872d32008-02-23 18:41:37 +00001290class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1291 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001292 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001293
Scott Michel97872d32008-02-23 18:41:37 +00001294multiclass AndHalfwordImm
1295{
1296 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1297 [(set (v8i16 VECREG:$rT),
1298 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001299
Scott Michel97872d32008-02-23 18:41:37 +00001300 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1301 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001302
Scott Michel97872d32008-02-23 18:41:37 +00001303 // Zero-extend i8 to i16:
1304 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1305 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1306}
Scott Michel8b6b4202007-12-04 22:35:58 +00001307
Scott Michel97872d32008-02-23 18:41:37 +00001308defm ANDHI : AndHalfwordImm;
1309
1310class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1311 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1312 IntegerOp, pattern>;
1313
1314multiclass AndWordImm
1315{
1316 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1317 [(set (v4i32 VECREG:$rT),
1318 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1319
1320 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1321 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1322
1323 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1324 // pattern below.
1325 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1326 [(set R32C:$rT,
1327 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1328
1329 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1330 // zext 16->32 pattern below.
1331 //
1332 // Note that this pattern is somewhat artificial, since it might match
1333 // something the compiler generates but is unlikely to occur in practice.
1334 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1335 [(set R32C:$rT,
1336 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1337}
1338
1339defm ANDI : AndWordImm;
1340
1341//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001342// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001343//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1344
Scott Michel8b6b4202007-12-04 22:35:58 +00001345// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001346class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1347 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1348 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001349
Scott Michel97872d32008-02-23 18:41:37 +00001350class ORVecInst<ValueType vectype>:
1351 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1352 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1353 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001354
Scott Michel97872d32008-02-23 18:41:37 +00001355class ORRegInst<RegisterClass rclass>:
1356 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1357 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001358
Scott Michel06eabde2008-12-27 04:51:36 +00001359// ORCvtForm: OR conversion form
1360//
1361// This is used to "convert" the preferred slot to its vector equivalent, as
1362// well as convert a vector back to its preferred slot.
1363//
1364// These are effectively no-ops, but need to exist for proper type conversion
1365// and type coercion.
1366
1367class ORCvtForm<dag OOL, dag IOL>
1368 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1369 bits<7> RA;
1370 bits<7> RT;
1371
1372 let Pattern = [/* no pattern */];
1373
1374 let Inst{0-10} = 0b10000010000;
1375 let Inst{11-17} = RA;
1376 let Inst{18-24} = RA;
1377 let Inst{25-31} = RT;
1378}
1379
Scott Michel97872d32008-02-23 18:41:37 +00001380class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001381 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001382
Scott Michel97872d32008-02-23 18:41:37 +00001383class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001384 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1385
1386class ORCvtRegGPRC<RegisterClass rclass>:
1387 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>;
1388
1389class ORCvtVecGPRC:
1390 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
1391
1392class ORCvtGPRCReg<RegisterClass rclass>:
1393 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>;
1394
1395class ORCvtGPRCVec:
1396 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001397
Scott Michel97872d32008-02-23 18:41:37 +00001398multiclass BitwiseOr
1399{
1400 def v16i8: ORVecInst<v16i8>;
1401 def v8i16: ORVecInst<v8i16>;
1402 def v4i32: ORVecInst<v4i32>;
1403 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001404
Scott Michel97872d32008-02-23 18:41:37 +00001405 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1406 [(set (v4f32 VECREG:$rT),
1407 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1408 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001409
Scott Michel97872d32008-02-23 18:41:37 +00001410 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001411 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001412 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1413 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001414
Scott Michel97872d32008-02-23 18:41:37 +00001415 def r64: ORRegInst<R64C>;
1416 def r32: ORRegInst<R32C>;
1417 def r16: ORRegInst<R16C>;
1418 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001419
Scott Michel97872d32008-02-23 18:41:37 +00001420 // OR instructions used to copy f32 and f64 registers.
1421 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1422 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001423
Scott Michel97872d32008-02-23 18:41:37 +00001424 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1425 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001426
Scott Michel97872d32008-02-23 18:41:37 +00001427 // scalar->vector promotion:
1428 def v16i8_i8: ORPromoteScalar<R8C>;
1429 def v8i16_i16: ORPromoteScalar<R16C>;
1430 def v4i32_i32: ORPromoteScalar<R32C>;
1431 def v2i64_i64: ORPromoteScalar<R64C>;
1432 def v4f32_f32: ORPromoteScalar<R32FP>;
1433 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001434
Scott Michel97872d32008-02-23 18:41:37 +00001435 // extract element 0:
1436 def i8_v16i8: ORExtractElt<R8C>;
1437 def i16_v8i16: ORExtractElt<R16C>;
1438 def i32_v4i32: ORExtractElt<R32C>;
1439 def i64_v2i64: ORExtractElt<R64C>;
1440 def f32_v4f32: ORExtractElt<R32FP>;
1441 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001442
1443 // Conversion from GPRC to register
1444 def i128_r64: ORCvtRegGPRC<R64C>;
1445 def i128_f64: ORCvtRegGPRC<R64FP>;
1446 def i128_r32: ORCvtRegGPRC<R32C>;
1447 def i128_f32: ORCvtRegGPRC<R32FP>;
1448 def i128_r16: ORCvtRegGPRC<R16C>;
1449 def i128_r8: ORCvtRegGPRC<R8C>;
1450
1451 // Conversion from GPRC to vector
1452 def i128_vec: ORCvtVecGPRC;
1453
1454 // Conversion from register to GPRC
1455 def r64_i128: ORCvtGPRCReg<R64C>;
1456 def f64_i128: ORCvtGPRCReg<R64FP>;
1457 def r32_i128: ORCvtGPRCReg<R32C>;
1458 def f32_i128: ORCvtGPRCReg<R32FP>;
1459 def r16_i128: ORCvtGPRCReg<R16C>;
1460 def r8_i128: ORCvtGPRCReg<R8C>;
1461
1462 // Conversion from vector to GPRC
1463 def vec_i128: ORCvtGPRCVec;
Scott Michel97872d32008-02-23 18:41:37 +00001464}
Scott Michel438be252007-12-17 22:32:34 +00001465
Scott Michel97872d32008-02-23 18:41:37 +00001466defm OR : BitwiseOr;
1467
Scott Michel06eabde2008-12-27 04:51:36 +00001468// scalar->vector promotion patterns (preferred slot to vector):
1469def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1470 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001471
Scott Michel06eabde2008-12-27 04:51:36 +00001472def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1473 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001474
Scott Michel06eabde2008-12-27 04:51:36 +00001475def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1476 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001477
Scott Michel06eabde2008-12-27 04:51:36 +00001478def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1479 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001480
Scott Michel06eabde2008-12-27 04:51:36 +00001481def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1482 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001483
Scott Michel06eabde2008-12-27 04:51:36 +00001484def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1485 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001486
Scott Michel06eabde2008-12-27 04:51:36 +00001487// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1488// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001489
Scott Michelc630c412008-11-24 17:11:17 +00001490def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001491 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001492
Scott Michelc630c412008-11-24 17:11:17 +00001493def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001494 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001495
Scott Michelc630c412008-11-24 17:11:17 +00001496def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001497 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001498
Scott Michelc630c412008-11-24 17:11:17 +00001499def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001500 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001501
Scott Michelc630c412008-11-24 17:11:17 +00001502def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001503 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001504
Scott Michelc630c412008-11-24 17:11:17 +00001505def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001506 (ORf64_v2f64 VECREG:$rA)>;
1507
1508// Load Register: This is an assembler alias for a bitwise OR of a register
1509// against itself. It's here because it brings some clarity to assembly
1510// language output.
1511
1512let hasCtrlDep = 1 in {
1513 class LRInst<dag OOL, dag IOL>
1514 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1515 bits<7> RA;
1516 bits<7> RT;
1517
1518 let Pattern = [/*no pattern*/];
1519
1520 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1521 let Inst{11-17} = RA;
1522 let Inst{18-24} = RA;
1523 let Inst{25-31} = RT;
1524 }
1525
1526 class LRVecInst<ValueType vectype>:
1527 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1528
1529 class LRRegInst<RegisterClass rclass>:
1530 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1531
1532 multiclass LoadRegister {
1533 def v2i64: LRVecInst<v2i64>;
1534 def v2f64: LRVecInst<v2f64>;
1535 def v4i32: LRVecInst<v4i32>;
1536 def v4f32: LRVecInst<v4f32>;
1537 def v8i16: LRVecInst<v8i16>;
1538 def v16i8: LRVecInst<v16i8>;
1539
1540 def r128: LRRegInst<GPRC>;
1541 def r64: LRRegInst<R64C>;
1542 def f64: LRRegInst<R64FP>;
1543 def r32: LRRegInst<R32C>;
1544 def f32: LRRegInst<R32FP>;
1545 def r16: LRRegInst<R16C>;
1546 def r8: LRRegInst<R8C>;
1547 }
1548
1549 defm LR: LoadRegister;
1550}
Scott Michel8b6b4202007-12-04 22:35:58 +00001551
Scott Michel97872d32008-02-23 18:41:37 +00001552// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001553
Scott Michel97872d32008-02-23 18:41:37 +00001554class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1555 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1556 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001557
Scott Michel97872d32008-02-23 18:41:37 +00001558class ORCVecInst<ValueType vectype>:
1559 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1560 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1561 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001562
Scott Michel97872d32008-02-23 18:41:37 +00001563class ORCRegInst<RegisterClass rclass>:
1564 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1565 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001566
Scott Michel97872d32008-02-23 18:41:37 +00001567multiclass BitwiseOrComplement
1568{
1569 def v16i8: ORCVecInst<v16i8>;
1570 def v8i16: ORCVecInst<v8i16>;
1571 def v4i32: ORCVecInst<v4i32>;
1572 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001573
Scott Michel97872d32008-02-23 18:41:37 +00001574 def r64: ORCRegInst<R64C>;
1575 def r32: ORCRegInst<R32C>;
1576 def r16: ORCRegInst<R16C>;
1577 def r8: ORCRegInst<R8C>;
1578}
1579
1580defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001581
Scott Michel8b6b4202007-12-04 22:35:58 +00001582// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001583class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1584 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1585 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001586
Scott Michel97872d32008-02-23 18:41:37 +00001587class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1588 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1589 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1590 (vectype immpred:$val)))]>;
1591
1592multiclass BitwiseOrByteImm
1593{
1594 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1595
1596 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1597 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1598}
1599
1600defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001601
Scott Michel8b6b4202007-12-04 22:35:58 +00001602// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001603class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1604 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1605 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001606
Scott Michel97872d32008-02-23 18:41:37 +00001607class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1608 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1609 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1610 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001611
Scott Michel97872d32008-02-23 18:41:37 +00001612multiclass BitwiseOrHalfwordImm
1613{
1614 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1615
1616 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1617 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1618
1619 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1620 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1621 [(set R16C:$rT, (or (anyext R8C:$rA),
1622 i16ImmSExt10:$val))]>;
1623}
1624
1625defm ORHI : BitwiseOrHalfwordImm;
1626
1627class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1628 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1629 IntegerOp, pattern>;
1630
1631class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1632 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1633 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1634 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001635
1636// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001637multiclass BitwiseOrImm
1638{
1639 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001640
Scott Michel97872d32008-02-23 18:41:37 +00001641 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1642 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001643
Scott Michel97872d32008-02-23 18:41:37 +00001644 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1645 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1646 // infra "anyext 16->32" pattern.)
1647 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1648 [(set R32C:$rT, (or (anyext R16C:$rA),
1649 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001650
Scott Michel97872d32008-02-23 18:41:37 +00001651 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1652 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1653 // infra "anyext 16->32" pattern.)
1654 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1655 [(set R32C:$rT, (or (anyext R8C:$rA),
1656 i32ImmSExt10:$val))]>;
1657}
Scott Michel8b6b4202007-12-04 22:35:58 +00001658
Scott Michel97872d32008-02-23 18:41:37 +00001659defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001660
Scott Michel8b6b4202007-12-04 22:35:58 +00001661// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1662// $rT[0], slots 1-3 are zeroed.
1663//
Scott Michel438be252007-12-17 22:32:34 +00001664// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001665def ORXv4i32:
1666 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1667 "orx\t$rT, $rA, $rB", IntegerOp,
1668 []>;
1669
Scott Michel438be252007-12-17 22:32:34 +00001670// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001671
Scott Michel6baba072008-03-05 23:02:02 +00001672class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1673 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1674 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001675
Scott Michel6baba072008-03-05 23:02:02 +00001676class XORVecInst<ValueType vectype>:
1677 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1678 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1679 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001680
Scott Michel6baba072008-03-05 23:02:02 +00001681class XORRegInst<RegisterClass rclass>:
1682 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1683 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1684
1685multiclass BitwiseExclusiveOr
1686{
1687 def v16i8: XORVecInst<v16i8>;
1688 def v8i16: XORVecInst<v8i16>;
1689 def v4i32: XORVecInst<v4i32>;
1690 def v2i64: XORVecInst<v2i64>;
1691
1692 def r128: XORRegInst<GPRC>;
1693 def r64: XORRegInst<R64C>;
1694 def r32: XORRegInst<R32C>;
1695 def r16: XORRegInst<R16C>;
1696 def r8: XORRegInst<R8C>;
1697
1698 // Special forms for floating point instructions.
1699 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1700
1701 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1702 [/* no pattern */]>;
1703
1704 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1705 [/* no pattern */]>;
1706
1707 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1708 [/* no pattern, see fneg{32,64} */]>;
1709}
1710
1711defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001712
1713//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001714
Scott Michel97872d32008-02-23 18:41:37 +00001715class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1716 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1717 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001718
Scott Michel97872d32008-02-23 18:41:37 +00001719multiclass XorByteImm
1720{
1721 def v16i8:
1722 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1723 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1724
1725 def r8:
1726 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1727 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1728}
1729
1730defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001731
Scott Michel8b6b4202007-12-04 22:35:58 +00001732def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001733 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001734 "xorhi\t$rT, $rA, $val", IntegerOp,
1735 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1736 v8i16SExt10Imm:$val))]>;
1737
1738def XORHIr16:
1739 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1740 "xorhi\t$rT, $rA, $val", IntegerOp,
1741 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1742
1743def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001744 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001745 "xori\t$rT, $rA, $val", IntegerOp,
1746 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1747 v4i32SExt10Imm:$val))]>;
1748
1749def XORIr32:
1750 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1751 "xori\t$rT, $rA, $val", IntegerOp,
1752 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1753
1754// NAND:
1755def NANDv16i8:
1756 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1757 "nand\t$rT, $rA, $rB", IntegerOp,
1758 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1759 (v16i8 VECREG:$rB))))]>;
1760
1761def NANDv8i16:
1762 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1763 "nand\t$rT, $rA, $rB", IntegerOp,
1764 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1765 (v8i16 VECREG:$rB))))]>;
1766
1767def NANDv4i32:
1768 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1769 "nand\t$rT, $rA, $rB", IntegerOp,
1770 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1771 (v4i32 VECREG:$rB))))]>;
1772
1773def NANDr32:
1774 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1775 "nand\t$rT, $rA, $rB", IntegerOp,
1776 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1777
1778def NANDr16:
1779 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1780 "nand\t$rT, $rA, $rB", IntegerOp,
1781 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1782
Scott Michel438be252007-12-17 22:32:34 +00001783def NANDr8:
1784 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1785 "nand\t$rT, $rA, $rB", IntegerOp,
1786 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1787
Scott Michel8b6b4202007-12-04 22:35:58 +00001788// NOR:
1789def NORv16i8:
1790 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1791 "nor\t$rT, $rA, $rB", IntegerOp,
1792 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1793 (v16i8 VECREG:$rB))))]>;
1794
1795def NORv8i16:
1796 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1797 "nor\t$rT, $rA, $rB", IntegerOp,
1798 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1799 (v8i16 VECREG:$rB))))]>;
1800
1801def NORv4i32:
1802 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1803 "nor\t$rT, $rA, $rB", IntegerOp,
1804 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1805 (v4i32 VECREG:$rB))))]>;
1806
1807def NORr32:
1808 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1809 "nor\t$rT, $rA, $rB", IntegerOp,
1810 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1811
1812def NORr16:
1813 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1814 "nor\t$rT, $rA, $rB", IntegerOp,
1815 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1816
Scott Michel438be252007-12-17 22:32:34 +00001817def NORr8:
1818 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1819 "nor\t$rT, $rA, $rB", IntegerOp,
1820 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1821
Scott Michel8b6b4202007-12-04 22:35:58 +00001822// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001823class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1824 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1825 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001826
Scott Michel6baba072008-03-05 23:02:02 +00001827class SELBVecInst<ValueType vectype>:
1828 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1829 [(set (vectype VECREG:$rT),
1830 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1831 (and (vnot (vectype VECREG:$rC)),
1832 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001833
Scott Michel06eabde2008-12-27 04:51:36 +00001834class SELBVecCondInst<ValueType vectype>:
1835 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1836 [(set (vectype VECREG:$rT),
1837 (select R32C:$rC,
1838 (vectype VECREG:$rB),
1839 (vectype VECREG:$rA)))]>;
1840
Scott Michel6baba072008-03-05 23:02:02 +00001841class SELBRegInst<RegisterClass rclass>:
1842 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1843 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001844 (or (and rclass:$rB, rclass:$rC),
1845 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001846
Scott Michel06eabde2008-12-27 04:51:36 +00001847class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1848 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1849 [(set rclass:$rT,
1850 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1851
Scott Michel6baba072008-03-05 23:02:02 +00001852multiclass SelectBits
1853{
1854 def v16i8: SELBVecInst<v16i8>;
1855 def v8i16: SELBVecInst<v8i16>;
1856 def v4i32: SELBVecInst<v4i32>;
1857 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001858
Scott Michel6baba072008-03-05 23:02:02 +00001859 def r128: SELBRegInst<GPRC>;
1860 def r64: SELBRegInst<R64C>;
1861 def r32: SELBRegInst<R32C>;
1862 def r16: SELBRegInst<R16C>;
1863 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001864
1865 def v16i8_cond: SELBVecCondInst<v16i8>;
1866 def v8i16_cond: SELBVecCondInst<v8i16>;
1867 def v4i32_cond: SELBVecCondInst<v4i32>;
1868 def v2i64_cond: SELBVecCondInst<v2i64>;
1869
1870 // SELBr64_cond is defined further down, look for i64 comparisons
1871 def r32_cond: SELBRegCondInst<R32C, R32C>;
1872 def r16_cond: SELBRegCondInst<R16C, R16C>;
1873 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001874}
Scott Michel8b6b4202007-12-04 22:35:58 +00001875
Scott Michel6baba072008-03-05 23:02:02 +00001876defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001877
Scott Michel56a125e2008-11-22 23:50:42 +00001878class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001879 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1880 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001881
Scott Michel56a125e2008-11-22 23:50:42 +00001882def : SPUselbPatVec<v16i8, SELBv16i8>;
1883def : SPUselbPatVec<v8i16, SELBv8i16>;
1884def : SPUselbPatVec<v4i32, SELBv4i32>;
1885def : SPUselbPatVec<v2i64, SELBv2i64>;
1886
1887class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1888 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1889 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1890
1891def : SPUselbPatReg<R8C, SELBr8>;
1892def : SPUselbPatReg<R16C, SELBr16>;
1893def : SPUselbPatReg<R32C, SELBr32>;
1894def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001895
Scott Michel6baba072008-03-05 23:02:02 +00001896// EQV: Equivalence (1 for each same bit, otherwise 0)
1897//
1898// Note: There are a lot of ways to match this bit operator and these patterns
1899// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001900
Scott Michel6baba072008-03-05 23:02:02 +00001901class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1902 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1903 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001904
Scott Michel6baba072008-03-05 23:02:02 +00001905class EQVVecInst<ValueType vectype>:
1906 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1907 [(set (vectype VECREG:$rT),
1908 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1909 (and (vnot (vectype VECREG:$rA)),
1910 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001911
Scott Michel6baba072008-03-05 23:02:02 +00001912class EQVRegInst<RegisterClass rclass>:
1913 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1914 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1915 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001916
Scott Michel6baba072008-03-05 23:02:02 +00001917class EQVVecPattern1<ValueType vectype>:
1918 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1919 [(set (vectype VECREG:$rT),
1920 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001921
Scott Michel6baba072008-03-05 23:02:02 +00001922class EQVRegPattern1<RegisterClass rclass>:
1923 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1924 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001925
Scott Michel6baba072008-03-05 23:02:02 +00001926class EQVVecPattern2<ValueType vectype>:
1927 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1928 [(set (vectype VECREG:$rT),
1929 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1930 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001931
Scott Michel6baba072008-03-05 23:02:02 +00001932class EQVRegPattern2<RegisterClass rclass>:
1933 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1934 [(set rclass:$rT,
1935 (or (and rclass:$rA, rclass:$rB),
1936 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001937
Scott Michel6baba072008-03-05 23:02:02 +00001938class EQVVecPattern3<ValueType vectype>:
1939 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1940 [(set (vectype VECREG:$rT),
1941 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001942
Scott Michel6baba072008-03-05 23:02:02 +00001943class EQVRegPattern3<RegisterClass rclass>:
1944 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1945 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001946
Scott Michel6baba072008-03-05 23:02:02 +00001947multiclass BitEquivalence
1948{
1949 def v16i8: EQVVecInst<v16i8>;
1950 def v8i16: EQVVecInst<v8i16>;
1951 def v4i32: EQVVecInst<v4i32>;
1952 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001953
Scott Michel6baba072008-03-05 23:02:02 +00001954 def v16i8_1: EQVVecPattern1<v16i8>;
1955 def v8i16_1: EQVVecPattern1<v8i16>;
1956 def v4i32_1: EQVVecPattern1<v4i32>;
1957 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001958
Scott Michel6baba072008-03-05 23:02:02 +00001959 def v16i8_2: EQVVecPattern2<v16i8>;
1960 def v8i16_2: EQVVecPattern2<v8i16>;
1961 def v4i32_2: EQVVecPattern2<v4i32>;
1962 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001963
Scott Michel6baba072008-03-05 23:02:02 +00001964 def v16i8_3: EQVVecPattern3<v16i8>;
1965 def v8i16_3: EQVVecPattern3<v8i16>;
1966 def v4i32_3: EQVVecPattern3<v4i32>;
1967 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001968
Scott Michel6baba072008-03-05 23:02:02 +00001969 def r128: EQVRegInst<GPRC>;
1970 def r64: EQVRegInst<R64C>;
1971 def r32: EQVRegInst<R32C>;
1972 def r16: EQVRegInst<R16C>;
1973 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001974
Scott Michel6baba072008-03-05 23:02:02 +00001975 def r128_1: EQVRegPattern1<GPRC>;
1976 def r64_1: EQVRegPattern1<R64C>;
1977 def r32_1: EQVRegPattern1<R32C>;
1978 def r16_1: EQVRegPattern1<R16C>;
1979 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001980
Scott Michel6baba072008-03-05 23:02:02 +00001981 def r128_2: EQVRegPattern2<GPRC>;
1982 def r64_2: EQVRegPattern2<R64C>;
1983 def r32_2: EQVRegPattern2<R32C>;
1984 def r16_2: EQVRegPattern2<R16C>;
1985 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001986
Scott Michel6baba072008-03-05 23:02:02 +00001987 def r128_3: EQVRegPattern3<GPRC>;
1988 def r64_3: EQVRegPattern3<R64C>;
1989 def r32_3: EQVRegPattern3<R32C>;
1990 def r16_3: EQVRegPattern3<R16C>;
1991 def r8_3: EQVRegPattern3<R8C>;
1992}
Scott Michel438be252007-12-17 22:32:34 +00001993
Scott Michel6baba072008-03-05 23:02:02 +00001994defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00001995
1996//===----------------------------------------------------------------------===//
1997// Vector shuffle...
1998//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001999// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2000// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2001// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2002// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002003//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002004
Scott Michel97872d32008-02-23 18:41:37 +00002005class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2006 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2007 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002008
Scott Michel0718cd82008-12-01 17:56:02 +00002009class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002010 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002011 [(set (resultvec VECREG:$rT),
2012 (SPUshuffle (resultvec VECREG:$rA),
2013 (resultvec VECREG:$rB),
2014 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002015
Scott Michel06eabde2008-12-27 04:51:36 +00002016class SHUFBGPRCInst:
2017 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2018 [/* no pattern */]>;
2019
Scott Michel97872d32008-02-23 18:41:37 +00002020multiclass ShuffleBytes
2021{
Scott Michel0718cd82008-12-01 17:56:02 +00002022 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2023 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2024 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2025 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2026 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2027 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2028 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2029 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002030
Scott Michel0718cd82008-12-01 17:56:02 +00002031 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2032 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2033
2034 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2035 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002036
2037 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002038}
2039
2040defm SHUFB : ShuffleBytes;
2041
Scott Michel8b6b4202007-12-04 22:35:58 +00002042//===----------------------------------------------------------------------===//
2043// Shift and rotate group:
2044//===----------------------------------------------------------------------===//
2045
Scott Michel97872d32008-02-23 18:41:37 +00002046class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2047 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2048 RotateShift, pattern>;
2049
2050class SHLHVecInst<ValueType vectype>:
2051 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2052 [(set (vectype VECREG:$rT),
2053 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002054
2055// $rB gets promoted to 32-bit register type when confronted with
2056// this llvm assembly code:
2057//
2058// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
2059// %A = shl i16 %arg1, %arg2
2060// ret i16 %A
2061// }
Scott Michel8b6b4202007-12-04 22:35:58 +00002062
Scott Michel97872d32008-02-23 18:41:37 +00002063multiclass ShiftLeftHalfword
2064{
2065 def v8i16: SHLHVecInst<v8i16>;
2066 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2067 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2068 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2069 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2070}
Scott Michel8b6b4202007-12-04 22:35:58 +00002071
Scott Michel97872d32008-02-23 18:41:37 +00002072defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002073
Scott Michel97872d32008-02-23 18:41:37 +00002074//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002075
Scott Michel97872d32008-02-23 18:41:37 +00002076class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2077 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2078 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002079
Scott Michel97872d32008-02-23 18:41:37 +00002080class SHLHIVecInst<ValueType vectype>:
2081 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2082 [(set (vectype VECREG:$rT),
2083 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002084
Scott Michel97872d32008-02-23 18:41:37 +00002085multiclass ShiftLeftHalfwordImm
2086{
2087 def v8i16: SHLHIVecInst<v8i16>;
2088 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2089 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2090}
2091
2092defm SHLHI : ShiftLeftHalfwordImm;
2093
2094def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2095 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2096
2097def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002098 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002099
Scott Michel97872d32008-02-23 18:41:37 +00002100//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002101
Scott Michel97872d32008-02-23 18:41:37 +00002102class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2103 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2104 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002105
Scott Michel97872d32008-02-23 18:41:37 +00002106multiclass ShiftLeftWord
2107{
2108 def v4i32:
2109 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2110 [(set (v4i32 VECREG:$rT),
2111 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2112 def r32:
2113 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2114 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2115}
Scott Michel8b6b4202007-12-04 22:35:58 +00002116
Scott Michel97872d32008-02-23 18:41:37 +00002117defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002118
Scott Michel97872d32008-02-23 18:41:37 +00002119//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002120
Scott Michel97872d32008-02-23 18:41:37 +00002121class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2122 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2123 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002124
Scott Michel97872d32008-02-23 18:41:37 +00002125multiclass ShiftLeftWordImm
2126{
2127 def v4i32:
2128 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2129 [(set (v4i32 VECREG:$rT),
2130 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002131
Scott Michel97872d32008-02-23 18:41:37 +00002132 def r32:
2133 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2134 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2135}
Scott Michel8b6b4202007-12-04 22:35:58 +00002136
Scott Michel97872d32008-02-23 18:41:37 +00002137defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002138
Scott Michel97872d32008-02-23 18:41:37 +00002139//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002140// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2141// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002142//
2143// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2144// of 7 bits is actually possible.
2145//
2146// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2147// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2148// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002149
Scott Michel97872d32008-02-23 18:41:37 +00002150class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2151 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2152 RotateShift, pattern>;
2153
2154class SHLQBIVecInst<ValueType vectype>:
2155 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2156 [(set (vectype VECREG:$rT),
2157 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2158
2159multiclass ShiftLeftQuadByBits
2160{
2161 def v16i8: SHLQBIVecInst<v16i8>;
2162 def v8i16: SHLQBIVecInst<v8i16>;
2163 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002164 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002165 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002166 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002167}
2168
2169defm SHLQBI : ShiftLeftQuadByBits;
2170
2171// See note above on SHLQBI. In this case, the predicate actually does then
2172// enforcement, whereas with SHLQBI, we have to "take it on faith."
2173class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2174 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2175 RotateShift, pattern>;
2176
2177class SHLQBIIVecInst<ValueType vectype>:
2178 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2179 [(set (vectype VECREG:$rT),
2180 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2181
2182multiclass ShiftLeftQuadByBitsImm
2183{
2184 def v16i8 : SHLQBIIVecInst<v16i8>;
2185 def v8i16 : SHLQBIIVecInst<v8i16>;
2186 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002187 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002188 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002189 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002190}
2191
2192defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002193
2194// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002195// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002196
Scott Michel97872d32008-02-23 18:41:37 +00002197class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002198 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002199 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002200
Scott Michel97872d32008-02-23 18:41:37 +00002201class SHLQBYVecInst<ValueType vectype>:
2202 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2203 [(set (vectype VECREG:$rT),
2204 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002205
Scott Michel97872d32008-02-23 18:41:37 +00002206multiclass ShiftLeftQuadBytes
2207{
2208 def v16i8: SHLQBYVecInst<v16i8>;
2209 def v8i16: SHLQBYVecInst<v8i16>;
2210 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002211 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002212 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002213 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002214 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2215 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2216}
Scott Michel8b6b4202007-12-04 22:35:58 +00002217
Scott Michel97872d32008-02-23 18:41:37 +00002218defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002219
Scott Michel97872d32008-02-23 18:41:37 +00002220class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2221 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2222 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002223
Scott Michel97872d32008-02-23 18:41:37 +00002224class SHLQBYIVecInst<ValueType vectype>:
2225 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2226 [(set (vectype VECREG:$rT),
2227 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002228
Scott Michel97872d32008-02-23 18:41:37 +00002229multiclass ShiftLeftQuadBytesImm
2230{
2231 def v16i8: SHLQBYIVecInst<v16i8>;
2232 def v8i16: SHLQBYIVecInst<v8i16>;
2233 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002234 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002235 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002236 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002237 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2238 [(set GPRC:$rT,
2239 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2240}
Scott Michel438be252007-12-17 22:32:34 +00002241
Scott Michel97872d32008-02-23 18:41:37 +00002242defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002243
Scott Michel97872d32008-02-23 18:41:37 +00002244//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2245// Rotate halfword:
2246//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2247class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2248 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2249 RotateShift, pattern>;
2250
2251class ROTHVecInst<ValueType vectype>:
2252 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2253 [(set (vectype VECREG:$rT),
2254 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2255
2256class ROTHRegInst<RegisterClass rclass>:
2257 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2258 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2259
2260multiclass RotateLeftHalfword
2261{
2262 def v8i16: ROTHVecInst<v8i16>;
2263 def r16: ROTHRegInst<R16C>;
2264}
2265
2266defm ROTH: RotateLeftHalfword;
2267
2268def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2269 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2270
2271//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2272// Rotate halfword, immediate:
2273//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2274class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2275 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2276 RotateShift, pattern>;
2277
2278class ROTHIVecInst<ValueType vectype>:
2279 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2280 [(set (vectype VECREG:$rT),
2281 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2282
2283multiclass RotateLeftHalfwordImm
2284{
2285 def v8i16: ROTHIVecInst<v8i16>;
2286 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2287 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2288 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2289 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2290}
2291
2292defm ROTHI: RotateLeftHalfwordImm;
2293
2294def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002295 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002296
Scott Michel97872d32008-02-23 18:41:37 +00002297//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2298// Rotate word:
2299//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002300
Scott Michel97872d32008-02-23 18:41:37 +00002301class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2302 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2303 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002304
Scott Michel97872d32008-02-23 18:41:37 +00002305class ROTVecInst<ValueType vectype>:
2306 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2307 [(set (vectype VECREG:$rT),
2308 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002309
Scott Michel97872d32008-02-23 18:41:37 +00002310class ROTRegInst<RegisterClass rclass>:
2311 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2312 [(set rclass:$rT,
2313 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002314
Scott Michel97872d32008-02-23 18:41:37 +00002315multiclass RotateLeftWord
2316{
2317 def v4i32: ROTVecInst<v4i32>;
2318 def r32: ROTRegInst<R32C>;
2319}
2320
2321defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002322
Scott Michel438be252007-12-17 22:32:34 +00002323// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2324// 32-bit register
2325def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002326 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2327 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002328
2329def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2330 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2331
2332def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2333 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2334
2335def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002336 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2337 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002338
2339def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2340 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2341
2342def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2343 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2344
Scott Michel97872d32008-02-23 18:41:37 +00002345//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2346// Rotate word, immediate
2347//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002348
Scott Michel97872d32008-02-23 18:41:37 +00002349class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2350 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2351 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002352
Scott Michel97872d32008-02-23 18:41:37 +00002353class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2354 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2355 [(set (vectype VECREG:$rT),
2356 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002357
Scott Michel97872d32008-02-23 18:41:37 +00002358class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2359 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2360 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002361
Scott Michel97872d32008-02-23 18:41:37 +00002362multiclass RotateLeftWordImm
2363{
2364 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2365 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2366 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002367
Scott Michel97872d32008-02-23 18:41:37 +00002368 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2369 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2370 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2371}
Scott Michel438be252007-12-17 22:32:34 +00002372
Scott Michel97872d32008-02-23 18:41:37 +00002373defm ROTI : RotateLeftWordImm;
2374
2375//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2376// Rotate quad by byte (count)
2377//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2378
2379class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2380 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2381 RotateShift, pattern>;
2382
2383class ROTQBYVecInst<ValueType vectype>:
2384 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2385 [(set (vectype VECREG:$rT),
2386 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2387
2388multiclass RotateQuadLeftByBytes
2389{
2390 def v16i8: ROTQBYVecInst<v16i8>;
2391 def v8i16: ROTQBYVecInst<v8i16>;
2392 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002393 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002394 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002395 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002396}
2397
2398defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002399
Scott Michel97872d32008-02-23 18:41:37 +00002400//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2401// Rotate quad by byte (count), immediate
2402//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2403
2404class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2405 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2406 RotateShift, pattern>;
2407
2408class ROTQBYIVecInst<ValueType vectype>:
2409 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2410 [(set (vectype VECREG:$rT),
2411 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2412
2413multiclass RotateQuadByBytesImm
2414{
2415 def v16i8: ROTQBYIVecInst<v16i8>;
2416 def v8i16: ROTQBYIVecInst<v8i16>;
2417 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002418 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002419 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002420 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002421}
2422
2423defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002424
Scott Michel8b6b4202007-12-04 22:35:58 +00002425// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002426class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2427 RI7Form<0b00110011100, OOL, IOL,
2428 "rotqbybi\t$rT, $rA, $shift",
2429 RotateShift, pattern>;
2430
2431class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2432 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2433 [(set (vectype VECREG:$rT),
2434 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2435
2436multiclass RotateQuadByBytesByBitshift {
2437 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2438 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2439 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2440 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2441}
2442
2443defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002444
Scott Michel97872d32008-02-23 18:41:37 +00002445//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002446// See ROTQBY note above.
2447//
2448// Assume that the user of this instruction knows to shift the rotate count
2449// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002450//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002451
Scott Michel97872d32008-02-23 18:41:37 +00002452class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2453 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2454 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002455
Scott Michel97872d32008-02-23 18:41:37 +00002456class ROTQBIVecInst<ValueType vectype>:
2457 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2458 [/* no pattern yet */]>;
2459
2460class ROTQBIRegInst<RegisterClass rclass>:
2461 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2462 [/* no pattern yet */]>;
2463
2464multiclass RotateQuadByBitCount
2465{
2466 def v16i8: ROTQBIVecInst<v16i8>;
2467 def v8i16: ROTQBIVecInst<v8i16>;
2468 def v4i32: ROTQBIVecInst<v4i32>;
2469 def v2i64: ROTQBIVecInst<v2i64>;
2470
2471 def r128: ROTQBIRegInst<GPRC>;
2472 def r64: ROTQBIRegInst<R64C>;
2473}
2474
2475defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002476
Scott Michel97872d32008-02-23 18:41:37 +00002477class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2478 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2479 RotateShift, pattern>;
2480
2481class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2482 PatLeaf pred>:
2483 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2484 [/* no pattern yet */]>;
2485
2486class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2487 PatLeaf pred>:
2488 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2489 [/* no pattern yet */]>;
2490
2491multiclass RotateQuadByBitCountImm
2492{
2493 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2494 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2495 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2496 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2497
2498 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2499 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2500}
2501
2502defm ROTQBII : RotateQuadByBitCountImm;
2503
2504//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002505// ROTHM v8i16 form:
2506// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2507// so this only matches a synthetically generated/lowered code
2508// fragment.
2509// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002510//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002511
Scott Michel97872d32008-02-23 18:41:37 +00002512class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2513 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2514 RotateShift, pattern>;
2515
2516def ROTHMv8i16:
2517 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2518 [/* see patterns below - $rB must be negated */]>;
2519
2520def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002521 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2522
Scott Michel97872d32008-02-23 18:41:37 +00002523def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002524 (ROTHMv8i16 VECREG:$rA,
2525 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2526
Scott Michel97872d32008-02-23 18:41:37 +00002527def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002528 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002529 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002530
2531// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2532// Note: This instruction doesn't match a pattern because rB must be negated
2533// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002534
Scott Michel8b6b4202007-12-04 22:35:58 +00002535def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002536 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2537 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002538
2539def : Pat<(srl R16C:$rA, R32C:$rB),
2540 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2541
2542def : Pat<(srl R16C:$rA, R16C:$rB),
2543 (ROTHMr16 R16C:$rA,
2544 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2545
Scott Michel438be252007-12-17 22:32:34 +00002546def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002547 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002548 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002549
2550// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2551// that the immediate can be complemented, so that the user doesn't have to
2552// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002553
Scott Michel97872d32008-02-23 18:41:37 +00002554class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2555 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2556 RotateShift, pattern>;
2557
2558def ROTHMIv8i16:
2559 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2560 [/* no pattern */]>;
2561
2562def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2563 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2564
2565def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002566 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002567
Scott Michel97872d32008-02-23 18:41:37 +00002568def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002569 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002570
2571def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002572 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2573 [/* no pattern */]>;
2574
2575def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2576 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002577
2578def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2579 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2580
Scott Michel438be252007-12-17 22:32:34 +00002581def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2582 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2583
Scott Michel8b6b4202007-12-04 22:35:58 +00002584// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002585class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2586 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2587 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002588
Scott Michel97872d32008-02-23 18:41:37 +00002589def ROTMv4i32:
2590 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2591 [/* see patterns below - $rB must be negated */]>;
2592
2593def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002594 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2595
Scott Michel97872d32008-02-23 18:41:37 +00002596def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002597 (ROTMv4i32 VECREG:$rA,
2598 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2599
Scott Michel97872d32008-02-23 18:41:37 +00002600def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002601 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002602 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002603
2604def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002605 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2606 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002607
2608def : Pat<(srl R32C:$rA, R32C:$rB),
2609 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2610
2611def : Pat<(srl R32C:$rA, R16C:$rB),
2612 (ROTMr32 R32C:$rA,
2613 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2614
Scott Michel438be252007-12-17 22:32:34 +00002615def : Pat<(srl R32C:$rA, R8C:$rB),
2616 (ROTMr32 R32C:$rA,
2617 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2618
Scott Michel8b6b4202007-12-04 22:35:58 +00002619// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2620def ROTMIv4i32:
2621 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2622 "rotmi\t$rT, $rA, $val", RotateShift,
2623 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002624 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002625
Scott Michel97872d32008-02-23 18:41:37 +00002626def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002627 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002628
Scott Michel97872d32008-02-23 18:41:37 +00002629def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002630 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002631
2632// ROTMI r32 form: know how to complement the immediate value.
2633def ROTMIr32:
2634 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2635 "rotmi\t$rT, $rA, $val", RotateShift,
2636 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2637
2638def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2639 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2640
Scott Michel438be252007-12-17 22:32:34 +00002641def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2642 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2643
Scott Michel97872d32008-02-23 18:41:37 +00002644//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002645// ROTQMBYvec: This is a vector form merely so that when used in an
2646// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002647// that the user knew to negate $rB.
2648//
2649// Using the SPUrotquad_rz_bytes target-specific DAG node, the patterns
2650// ensure that $rB is negated.
2651//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002652
Scott Michel97872d32008-02-23 18:41:37 +00002653class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2654 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2655 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002656
Scott Michel97872d32008-02-23 18:41:37 +00002657class ROTQMBYVecInst<ValueType vectype>:
2658 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2659 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002660
Scott Michel97872d32008-02-23 18:41:37 +00002661class ROTQMBYRegInst<RegisterClass rclass>:
2662 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2663 [(set rclass:$rT,
2664 (SPUrotquad_rz_bytes rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002665
Scott Michel97872d32008-02-23 18:41:37 +00002666multiclass RotateQuadBytes
2667{
2668 def v16i8: ROTQMBYVecInst<v16i8>;
2669 def v8i16: ROTQMBYVecInst<v8i16>;
2670 def v4i32: ROTQMBYVecInst<v4i32>;
2671 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002672
Scott Michel97872d32008-02-23 18:41:37 +00002673 def r128: ROTQMBYRegInst<GPRC>;
2674 def r64: ROTQMBYRegInst<R64C>;
2675}
2676
2677defm ROTQMBY : RotateQuadBytes;
2678
2679def : Pat<(SPUrotquad_rz_bytes (v16i8 VECREG:$rA), R32C:$rB),
2680 (ROTQMBYv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2681def : Pat<(SPUrotquad_rz_bytes (v8i16 VECREG:$rA), R32C:$rB),
2682 (ROTQMBYv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2683def : Pat<(SPUrotquad_rz_bytes (v4i32 VECREG:$rA), R32C:$rB),
2684 (ROTQMBYv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2685def : Pat<(SPUrotquad_rz_bytes (v2i64 VECREG:$rA), R32C:$rB),
2686 (ROTQMBYv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2687def : Pat<(SPUrotquad_rz_bytes GPRC:$rA, R32C:$rB),
2688 (ROTQMBYr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2689def : Pat<(SPUrotquad_rz_bytes R64C:$rA, R32C:$rB),
2690 (ROTQMBYr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2691
2692class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2693 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2694 RotateShift, pattern>;
2695
2696class ROTQMBYIVecInst<ValueType vectype>:
2697 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2698 [(set (vectype VECREG:$rT),
2699 (SPUrotquad_rz_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2700
2701class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2702 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2703 [(set rclass:$rT,
2704 (SPUrotquad_rz_bytes rclass:$rA, (inttype pred:$val)))]>;
2705
2706multiclass RotateQuadBytesImm
2707{
2708 def v16i8: ROTQMBYIVecInst<v16i8>;
2709 def v8i16: ROTQMBYIVecInst<v8i16>;
2710 def v4i32: ROTQMBYIVecInst<v4i32>;
2711 def v2i64: ROTQMBYIVecInst<v2i64>;
2712
2713 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2714 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2715}
2716
2717defm ROTQMBYI : RotateQuadBytesImm;
2718
Scott Michel97872d32008-02-23 18:41:37 +00002719//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2720// Rotate right and mask by bit count
2721//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2722
2723class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2724 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2725 RotateShift, pattern>;
2726
2727class ROTQMBYBIVecInst<ValueType vectype>:
2728 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2729 [/* no pattern, intrinsic? */]>;
2730
2731multiclass RotateMaskQuadByBitCount
2732{
2733 def v16i8: ROTQMBYBIVecInst<v16i8>;
2734 def v8i16: ROTQMBYBIVecInst<v8i16>;
2735 def v4i32: ROTQMBYBIVecInst<v4i32>;
2736 def v2i64: ROTQMBYBIVecInst<v2i64>;
2737}
2738
2739defm ROTQMBYBI: RotateMaskQuadByBitCount;
2740
2741//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2742// Rotate quad and mask by bits
2743// Note that the rotate amount has to be negated
2744//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2745
2746class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2747 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2748 RotateShift, pattern>;
2749
2750class ROTQMBIVecInst<ValueType vectype>:
2751 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2752 [/* no pattern */]>;
2753
2754class ROTQMBIRegInst<RegisterClass rclass>:
2755 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2756 [/* no pattern */]>;
2757
2758multiclass RotateMaskQuadByBits
2759{
2760 def v16i8: ROTQMBIVecInst<v16i8>;
2761 def v8i16: ROTQMBIVecInst<v8i16>;
2762 def v4i32: ROTQMBIVecInst<v4i32>;
2763 def v2i64: ROTQMBIVecInst<v2i64>;
2764
2765 def r128: ROTQMBIRegInst<GPRC>;
2766 def r64: ROTQMBIRegInst<R64C>;
2767}
2768
2769defm ROTQMBI: RotateMaskQuadByBits;
2770
2771def : Pat<(SPUrotquad_rz_bits (v16i8 VECREG:$rA), R32C:$rB),
2772 (ROTQMBIv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2773def : Pat<(SPUrotquad_rz_bits (v8i16 VECREG:$rA), R32C:$rB),
2774 (ROTQMBIv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2775def : Pat<(SPUrotquad_rz_bits (v4i32 VECREG:$rA), R32C:$rB),
2776 (ROTQMBIv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2777def : Pat<(SPUrotquad_rz_bits (v2i64 VECREG:$rA), R32C:$rB),
2778 (ROTQMBIv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2779def : Pat<(SPUrotquad_rz_bits GPRC:$rA, R32C:$rB),
2780 (ROTQMBIr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2781def : Pat<(SPUrotquad_rz_bits R64C:$rA, R32C:$rB),
2782 (ROTQMBIr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2783
2784//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2785// Rotate quad and mask by bits, immediate
2786//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2787
2788class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2789 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2790 RotateShift, pattern>;
2791
2792class ROTQMBIIVecInst<ValueType vectype>:
2793 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2794 [(set (vectype VECREG:$rT),
2795 (SPUrotquad_rz_bits (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2796
2797class ROTQMBIIRegInst<RegisterClass rclass>:
2798 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2799 [(set rclass:$rT,
2800 (SPUrotquad_rz_bits rclass:$rA, (i32 uimm7:$val)))]>;
2801
2802multiclass RotateMaskQuadByBitsImm
2803{
2804 def v16i8: ROTQMBIIVecInst<v16i8>;
2805 def v8i16: ROTQMBIIVecInst<v8i16>;
2806 def v4i32: ROTQMBIIVecInst<v4i32>;
2807 def v2i64: ROTQMBIIVecInst<v2i64>;
2808
2809 def r128: ROTQMBIIRegInst<GPRC>;
2810 def r64: ROTQMBIIRegInst<R64C>;
2811}
2812
2813defm ROTQMBII: RotateMaskQuadByBitsImm;
2814
2815//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2816//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002817
2818def ROTMAHv8i16:
2819 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2820 "rotmah\t$rT, $rA, $rB", RotateShift,
2821 [/* see patterns below - $rB must be negated */]>;
2822
Scott Michel97872d32008-02-23 18:41:37 +00002823def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002824 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2825
Scott Michel97872d32008-02-23 18:41:37 +00002826def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002827 (ROTMAHv8i16 VECREG:$rA,
2828 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2829
Scott Michel97872d32008-02-23 18:41:37 +00002830def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002831 (ROTMAHv8i16 VECREG:$rA,
2832 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2833
Scott Michel8b6b4202007-12-04 22:35:58 +00002834def ROTMAHr16:
2835 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2836 "rotmah\t$rT, $rA, $rB", RotateShift,
2837 [/* see patterns below - $rB must be negated */]>;
2838
2839def : Pat<(sra R16C:$rA, R32C:$rB),
2840 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2841
2842def : Pat<(sra R16C:$rA, R16C:$rB),
2843 (ROTMAHr16 R16C:$rA,
2844 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2845
Scott Michel438be252007-12-17 22:32:34 +00002846def : Pat<(sra R16C:$rA, R8C:$rB),
2847 (ROTMAHr16 R16C:$rA,
2848 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2849
Scott Michel8b6b4202007-12-04 22:35:58 +00002850def ROTMAHIv8i16:
2851 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2852 "rotmahi\t$rT, $rA, $val", RotateShift,
2853 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002854 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002855
Scott Michel97872d32008-02-23 18:41:37 +00002856def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002857 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2858
Scott Michel97872d32008-02-23 18:41:37 +00002859def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002860 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2861
Scott Michel8b6b4202007-12-04 22:35:58 +00002862def ROTMAHIr16:
2863 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2864 "rotmahi\t$rT, $rA, $val", RotateShift,
2865 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2866
2867def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2868 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2869
Scott Michel438be252007-12-17 22:32:34 +00002870def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2871 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2872
Scott Michel8b6b4202007-12-04 22:35:58 +00002873def ROTMAv4i32:
2874 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2875 "rotma\t$rT, $rA, $rB", RotateShift,
2876 [/* see patterns below - $rB must be negated */]>;
2877
Scott Michel97872d32008-02-23 18:41:37 +00002878def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002879 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2880
Scott Michel97872d32008-02-23 18:41:37 +00002881def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002882 (ROTMAv4i32 (v4i32 VECREG:$rA),
2883 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2884
Scott Michel97872d32008-02-23 18:41:37 +00002885def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002886 (ROTMAv4i32 (v4i32 VECREG:$rA),
2887 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2888
Scott Michel8b6b4202007-12-04 22:35:58 +00002889def ROTMAr32:
2890 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2891 "rotma\t$rT, $rA, $rB", RotateShift,
2892 [/* see patterns below - $rB must be negated */]>;
2893
2894def : Pat<(sra R32C:$rA, R32C:$rB),
2895 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2896
2897def : Pat<(sra R32C:$rA, R16C:$rB),
2898 (ROTMAr32 R32C:$rA,
2899 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2900
Scott Michel438be252007-12-17 22:32:34 +00002901def : Pat<(sra R32C:$rA, R8C:$rB),
2902 (ROTMAr32 R32C:$rA,
2903 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2904
Scott Michel67224b22008-06-02 22:18:03 +00002905class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2906 RRForm<0b01011110000, OOL, IOL,
2907 "rotmai\t$rT, $rA, $val",
2908 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002909
Scott Michel67224b22008-06-02 22:18:03 +00002910class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2911 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2912 [(set (vectype VECREG:$rT),
2913 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002914
Scott Michel67224b22008-06-02 22:18:03 +00002915class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2916 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2917 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002918
Scott Michel67224b22008-06-02 22:18:03 +00002919multiclass RotateMaskAlgebraicImm {
2920 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2921 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2922 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2923 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2924}
Scott Michel8b6b4202007-12-04 22:35:58 +00002925
Scott Michel67224b22008-06-02 22:18:03 +00002926defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00002927
Scott Michel8b6b4202007-12-04 22:35:58 +00002928//===----------------------------------------------------------------------===//
2929// Branch and conditionals:
2930//===----------------------------------------------------------------------===//
2931
2932let isTerminator = 1, isBarrier = 1 in {
2933 // Halt If Equal (r32 preferred slot only, no vector form)
2934 def HEQr32:
2935 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2936 "heq\t$rA, $rB", BranchResolv,
2937 [/* no pattern to match */]>;
2938
2939 def HEQIr32 :
2940 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2941 "heqi\t$rA, $val", BranchResolv,
2942 [/* no pattern to match */]>;
2943
2944 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2945 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2946 def HGTr32:
2947 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2948 "hgt\t$rA, $rB", BranchResolv,
2949 [/* no pattern to match */]>;
2950
Scott Michel06eabde2008-12-27 04:51:36 +00002951 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00002952 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2953 "hgti\t$rA, $val", BranchResolv,
2954 [/* no pattern to match */]>;
2955
2956 def HLGTr32:
2957 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2958 "hlgt\t$rA, $rB", BranchResolv,
2959 [/* no pattern to match */]>;
2960
2961 def HLGTIr32:
2962 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2963 "hlgti\t$rA, $val", BranchResolv,
2964 [/* no pattern to match */]>;
2965}
2966
Scott Michel06eabde2008-12-27 04:51:36 +00002967//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2968// Comparison operators for i8, i16 and i32:
2969//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002970
Scott Michel97872d32008-02-23 18:41:37 +00002971class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2972 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2973 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002974
Scott Michel97872d32008-02-23 18:41:37 +00002975multiclass CmpEqualByte
2976{
2977 def v16i8 :
2978 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2979 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2980 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002981
Scott Michel97872d32008-02-23 18:41:37 +00002982 def r8 :
2983 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2984 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2985}
Scott Michel8b6b4202007-12-04 22:35:58 +00002986
Scott Michel97872d32008-02-23 18:41:37 +00002987class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2988 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2989 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002990
Scott Michel97872d32008-02-23 18:41:37 +00002991multiclass CmpEqualByteImm
2992{
2993 def v16i8 :
2994 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2995 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2996 v16i8SExt8Imm:$val))]>;
2997 def r8:
2998 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2999 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3000}
Scott Michel8b6b4202007-12-04 22:35:58 +00003001
Scott Michel97872d32008-02-23 18:41:37 +00003002class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3003 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3004 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003005
Scott Michel97872d32008-02-23 18:41:37 +00003006multiclass CmpEqualHalfword
3007{
3008 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3009 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3010 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003011
Scott Michel97872d32008-02-23 18:41:37 +00003012 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3013 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3014}
Scott Michel8b6b4202007-12-04 22:35:58 +00003015
Scott Michel97872d32008-02-23 18:41:37 +00003016class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3017 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3018 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003019
Scott Michel97872d32008-02-23 18:41:37 +00003020multiclass CmpEqualHalfwordImm
3021{
3022 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3023 [(set (v8i16 VECREG:$rT),
3024 (seteq (v8i16 VECREG:$rA),
3025 (v8i16 v8i16SExt10Imm:$val)))]>;
3026 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3027 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3028}
Scott Michel8b6b4202007-12-04 22:35:58 +00003029
Scott Michel97872d32008-02-23 18:41:37 +00003030class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3031 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3032 ByteOp, pattern>;
3033
3034multiclass CmpEqualWord
3035{
3036 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3037 [(set (v4i32 VECREG:$rT),
3038 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3039
3040 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3041 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3042}
3043
3044class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3045 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3046 ByteOp, pattern>;
3047
3048multiclass CmpEqualWordImm
3049{
3050 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3051 [(set (v4i32 VECREG:$rT),
3052 (seteq (v4i32 VECREG:$rA),
3053 (v4i32 v4i32SExt16Imm:$val)))]>;
3054
3055 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3056 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3057}
3058
3059class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3060 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3061 ByteOp, pattern>;
3062
3063multiclass CmpGtrByte
3064{
3065 def v16i8 :
3066 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3067 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3068 (v8i16 VECREG:$rB)))]>;
3069
3070 def r8 :
3071 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3072 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3073}
3074
3075class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3076 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3077 ByteOp, pattern>;
3078
3079multiclass CmpGtrByteImm
3080{
3081 def v16i8 :
3082 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3083 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3084 v16i8SExt8Imm:$val))]>;
3085 def r8:
3086 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003087 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003088}
3089
3090class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3091 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3092 ByteOp, pattern>;
3093
3094multiclass CmpGtrHalfword
3095{
3096 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3097 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3098 (v8i16 VECREG:$rB)))]>;
3099
3100 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3101 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3102}
3103
3104class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3105 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3106 ByteOp, pattern>;
3107
3108multiclass CmpGtrHalfwordImm
3109{
3110 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3111 [(set (v8i16 VECREG:$rT),
3112 (setgt (v8i16 VECREG:$rA),
3113 (v8i16 v8i16SExt10Imm:$val)))]>;
3114 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3115 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3116}
3117
3118class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3119 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3120 ByteOp, pattern>;
3121
3122multiclass CmpGtrWord
3123{
3124 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3125 [(set (v4i32 VECREG:$rT),
3126 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3127
3128 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3129 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3130}
3131
3132class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3133 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3134 ByteOp, pattern>;
3135
3136multiclass CmpGtrWordImm
3137{
3138 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3139 [(set (v4i32 VECREG:$rT),
3140 (setgt (v4i32 VECREG:$rA),
3141 (v4i32 v4i32SExt16Imm:$val)))]>;
3142
3143 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3144 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
3145}
3146
3147class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003148 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003149 ByteOp, pattern>;
3150
3151multiclass CmpLGtrByte
3152{
3153 def v16i8 :
3154 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3155 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3156 (v8i16 VECREG:$rB)))]>;
3157
3158 def r8 :
3159 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3160 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3161}
3162
3163class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003164 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003165 ByteOp, pattern>;
3166
3167multiclass CmpLGtrByteImm
3168{
3169 def v16i8 :
3170 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3171 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3172 v16i8SExt8Imm:$val))]>;
3173 def r8:
3174 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3175 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3176}
3177
3178class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003179 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003180 ByteOp, pattern>;
3181
3182multiclass CmpLGtrHalfword
3183{
3184 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3185 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3186 (v8i16 VECREG:$rB)))]>;
3187
3188 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3189 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3190}
3191
3192class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003193 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003194 ByteOp, pattern>;
3195
3196multiclass CmpLGtrHalfwordImm
3197{
3198 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3199 [(set (v8i16 VECREG:$rT),
3200 (setugt (v8i16 VECREG:$rA),
3201 (v8i16 v8i16SExt10Imm:$val)))]>;
3202 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3203 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3204}
3205
3206class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003207 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003208 ByteOp, pattern>;
3209
3210multiclass CmpLGtrWord
3211{
3212 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3213 [(set (v4i32 VECREG:$rT),
3214 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3215
3216 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3217 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3218}
3219
3220class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003221 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003222 ByteOp, pattern>;
3223
3224multiclass CmpLGtrWordImm
3225{
3226 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3227 [(set (v4i32 VECREG:$rT),
3228 (setugt (v4i32 VECREG:$rA),
3229 (v4i32 v4i32SExt16Imm:$val)))]>;
3230
3231 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003232 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003233}
3234
3235defm CEQB : CmpEqualByte;
3236defm CEQBI : CmpEqualByteImm;
3237defm CEQH : CmpEqualHalfword;
3238defm CEQHI : CmpEqualHalfwordImm;
3239defm CEQ : CmpEqualWord;
3240defm CEQI : CmpEqualWordImm;
3241defm CGTB : CmpGtrByte;
3242defm CGTBI : CmpGtrByteImm;
3243defm CGTH : CmpGtrHalfword;
3244defm CGTHI : CmpGtrHalfwordImm;
3245defm CGT : CmpGtrWord;
3246defm CGTI : CmpGtrWordImm;
3247defm CLGTB : CmpLGtrByte;
3248defm CLGTBI : CmpLGtrByteImm;
3249defm CLGTH : CmpLGtrHalfword;
3250defm CLGTHI : CmpLGtrHalfwordImm;
3251defm CLGT : CmpLGtrWord;
3252defm CLGTI : CmpLGtrWordImm;
3253
Scott Michel53ab7792008-03-10 16:58:52 +00003254//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003255// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3256// define a pattern to generate the right code, as a binary operator
3257// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003258//
Scott Michel06eabde2008-12-27 04:51:36 +00003259// Notes:
3260// 1. This only matches the setcc set of conditionals. Special pattern
3261// matching is used for select conditionals.
3262//
3263// 2. The "DAG" versions of these classes is almost exclusively used for
3264// i64 comparisons. See the tblgen fundamentals documentation for what
3265// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3266// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003267//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003268
Scott Michel53ab7792008-03-10 16:58:52 +00003269class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3270 SPUInstr xorinst, SPUInstr cmpare>:
3271 Pat<(cond rclass:$rA, rclass:$rB),
3272 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3273
3274class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3275 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3276 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3277 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3278
Scott Michel06eabde2008-12-27 04:51:36 +00003279def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003280def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3281
Scott Michel06eabde2008-12-27 04:51:36 +00003282def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003283def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3284
3285def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3286def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003287
3288class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3289 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3290 Pat<(cond rclass:$rA, rclass:$rB),
3291 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3292 (cmpOp2 rclass:$rA, rclass:$rB))>;
3293
3294class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3295 ValueType immtype,
3296 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3297 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3298 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3299 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3300
Scott Michel53ab7792008-03-10 16:58:52 +00003301def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3302def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3303def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3304def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3305def : Pat<(setle R8C:$rA, R8C:$rB),
3306 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3307def : Pat<(setle R8C:$rA, immU8:$imm),
3308 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003309
Scott Michel53ab7792008-03-10 16:58:52 +00003310def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3311def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3312 ORr16, CGTHIr16, CEQHIr16>;
3313def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3314def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3315def : Pat<(setle R16C:$rA, R16C:$rB),
3316 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3317def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3318 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003319
Scott Michel53ab7792008-03-10 16:58:52 +00003320def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3321def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3322 ORr32, CGTIr32, CEQIr32>;
3323def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3324def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3325def : Pat<(setle R32C:$rA, R32C:$rB),
3326 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3327def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3328 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003329
Scott Michel53ab7792008-03-10 16:58:52 +00003330def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3331def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3332def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3333def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3334def : Pat<(setule R8C:$rA, R8C:$rB),
3335 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3336def : Pat<(setule R8C:$rA, immU8:$imm),
3337 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003338
Scott Michel53ab7792008-03-10 16:58:52 +00003339def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3340def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3341 ORr16, CLGTHIr16, CEQHIr16>;
3342def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3343def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3344 CLGTHIr16, CEQHIr16>;
3345def : Pat<(setule R16C:$rA, R16C:$rB),
3346 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003347def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003348 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003349
Scott Michel53ab7792008-03-10 16:58:52 +00003350def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003351def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003352 ORr32, CLGTIr32, CEQIr32>;
3353def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003354def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003355def : Pat<(setule R32C:$rA, R32C:$rB),
3356 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3357def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3358 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003359
Scott Michel53ab7792008-03-10 16:58:52 +00003360//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3361// select conditional patterns:
3362//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3363
3364class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3365 SPUInstr selinstr, SPUInstr cmpare>:
3366 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3367 rclass:$rTrue, rclass:$rFalse),
3368 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003369 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003370
3371class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3372 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3373 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003374 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003375 (selinstr rclass:$rTrue, rclass:$rFalse,
3376 (cmpare rclass:$rA, immpred:$imm))>;
3377
3378def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3379def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3380def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3381def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3382def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3383def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3384
3385def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3386def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3387def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3388def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3389def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3390def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3391
3392def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3393def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3394def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3395def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3396def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3397def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3398
3399class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3400 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3401 SPUInstr cmpOp2>:
3402 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003403 rclass:$rTrue, rclass:$rFalse),
3404 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003405 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3406 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3407
3408class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3409 ValueType inttype,
3410 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3411 SPUInstr cmpOp2>:
3412 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003413 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003414 (selinstr rclass:$rFalse, rclass:$rTrue,
3415 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3416 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3417
3418def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3419def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3420 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3421
3422def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3423def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3424 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3425
3426def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3427def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3428 SELBr32, ORr32, CGTIr32, CEQIr32>;
3429
3430def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3431def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3432 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3433
3434def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3435def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3436 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3437
3438def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3439def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3440 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003441
3442//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003443
3444let isCall = 1,
3445 // All calls clobber the non-callee-saved registers:
3446 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3447 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3448 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3449 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3450 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3451 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3452 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3453 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3454 // All of these instructions use $lr (aka $0)
3455 Uses = [R0] in {
3456 // Branch relative and set link: Used if we actually know that the target
3457 // is within [-32768, 32767] bytes of the target
3458 def BRSL:
3459 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3460 "brsl\t$$lr, $func",
3461 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3462
3463 // Branch absolute and set link: Used if we actually know that the target
3464 // is an absolute address
3465 def BRASL:
3466 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3467 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003468 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003469
3470 // Branch indirect and set link if external data. These instructions are not
3471 // actually generated, matched by an intrinsic:
3472 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3473 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3474 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3475 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3476
3477 // Branch indirect and set link. This is the "X-form" address version of a
3478 // function call
3479 def BISL:
3480 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3481}
3482
Scott Michelae5cbf52008-12-29 03:23:36 +00003483// Support calls to external symbols:
3484def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3485 (BRSL texternalsym:$func)>;
3486
3487def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3488 (BRASL texternalsym:$func)>;
3489
Scott Michel8b6b4202007-12-04 22:35:58 +00003490// Unconditional branches:
3491let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3492 def BR :
3493 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3494 "br\t$dest",
3495 [(br bb:$dest)]>;
3496
3497 // Unconditional, absolute address branch
3498 def BRA:
3499 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3500 "bra\t$dest",
3501 [/* no pattern */]>;
3502
3503 // Indirect branch
3504 def BI:
3505 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3506
3507 // Various branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003508 class BRNZInst<dag IOL, list<dag> pattern>:
3509 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3510 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003511
Scott Michel06eabde2008-12-27 04:51:36 +00003512 class BRNZRegInst<RegisterClass rclass>:
3513 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3514 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003515
Scott Michel06eabde2008-12-27 04:51:36 +00003516 class BRNZVecInst<ValueType vectype>:
3517 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3518 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003519
Scott Michel06eabde2008-12-27 04:51:36 +00003520 multiclass BranchNotZero {
3521 def v4i32 : BRNZVecInst<v4i32>;
3522 def r32 : BRNZRegInst<R32C>;
3523 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003524
Scott Michel06eabde2008-12-27 04:51:36 +00003525 defm BRNZ : BranchNotZero;
3526
3527 class BRZInst<dag IOL, list<dag> pattern>:
3528 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3529 BranchResolv, pattern>;
3530
3531 class BRZRegInst<RegisterClass rclass>:
3532 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3533
3534 class BRZVecInst<ValueType vectype>:
3535 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3536
3537 multiclass BranchZero {
3538 def v4i32: BRZVecInst<v4i32>;
3539 def r32: BRZRegInst<R32C>;
3540 }
3541
3542 defm BRZ: BranchZero;
3543
3544 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3545 // be useful:
3546 /*
3547 class BINZInst<dag IOL, list<dag> pattern>:
3548 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3549
3550 class BINZRegInst<RegisterClass rclass>:
3551 BINZInst<(ins rclass:$rA, brtarget:$dest),
3552 [(brcond rclass:$rA, R32C:$dest)]>;
3553
3554 class BINZVecInst<ValueType vectype>:
3555 BINZInst<(ins VECREG:$rA, R32C:$dest),
3556 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3557
3558 multiclass BranchNotZeroIndirect {
3559 def v4i32: BINZVecInst<v4i32>;
3560 def r32: BINZRegInst<R32C>;
3561 }
3562
3563 defm BINZ: BranchNotZeroIndirect;
3564
3565 class BIZInst<dag IOL, list<dag> pattern>:
3566 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3567
3568 class BIZRegInst<RegisterClass rclass>:
3569 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3570
3571 class BIZVecInst<ValueType vectype>:
3572 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3573
3574 multiclass BranchZeroIndirect {
3575 def v4i32: BIZVecInst<v4i32>;
3576 def r32: BIZRegInst<R32C>;
3577 }
3578
3579 defm BIZ: BranchZeroIndirect;
3580 */
3581
3582 class BRHNZInst<dag IOL, list<dag> pattern>:
3583 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3584 pattern>;
3585
3586 class BRHNZRegInst<RegisterClass rclass>:
3587 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3588 [(brcond rclass:$rCond, bb:$dest)]>;
3589
3590 class BRHNZVecInst<ValueType vectype>:
3591 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3592
3593 multiclass BranchNotZeroHalfword {
3594 def v8i16: BRHNZVecInst<v8i16>;
3595 def r16: BRHNZRegInst<R16C>;
3596 }
3597
3598 defm BRHNZ: BranchNotZeroHalfword;
3599
3600 class BRHZInst<dag IOL, list<dag> pattern>:
3601 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3602 pattern>;
3603
3604 class BRHZRegInst<RegisterClass rclass>:
3605 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3606
3607 class BRHZVecInst<ValueType vectype>:
3608 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3609
3610 multiclass BranchZeroHalfword {
3611 def v8i16: BRHZVecInst<v8i16>;
3612 def r16: BRHZRegInst<R16C>;
3613 }
3614
3615 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003616}
3617
Scott Michel394e26d2008-01-17 20:38:41 +00003618//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003619// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003620//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003621
Scott Michel06eabde2008-12-27 04:51:36 +00003622def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3623 (BRHZr16 R16C:$rA, bb:$dest)>;
3624def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3625 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003626
Scott Michel06eabde2008-12-27 04:51:36 +00003627def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3628 (BRZr32 R32C:$rA, bb:$dest)>;
3629def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3630 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003631
Scott Michel97872d32008-02-23 18:41:37 +00003632multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3633{
3634 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3635 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003636
Scott Michel97872d32008-02-23 18:41:37 +00003637 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3638 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3639
3640 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3641 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3642
3643 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3644 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3645}
3646
Scott Michel06eabde2008-12-27 04:51:36 +00003647defm BRCONDeq : BranchCondEQ<seteq, BRHZr16, BRZr32>;
3648defm BRCONDne : BranchCondEQ<setne, BRHNZr16, BRNZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003649
3650multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3651{
3652 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3653 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3654
3655 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3656 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3657
3658 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3659 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3660
3661 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3662 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3663}
3664
Scott Michel06eabde2008-12-27 04:51:36 +00003665defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3666defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003667
3668multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3669 SPUInstr orinst32, SPUInstr brinst32>
3670{
3671 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3672 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3673 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3674 bb:$dest)>;
3675
3676 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3677 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3678 (CEQHr16 R16C:$rA, R16:$rB)),
3679 bb:$dest)>;
3680
3681 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3682 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3683 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3684 bb:$dest)>;
3685
3686 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3687 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3688 (CEQr32 R32C:$rA, R32C:$rB)),
3689 bb:$dest)>;
3690}
3691
Scott Michel06eabde2008-12-27 04:51:36 +00003692defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3693defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003694
3695multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3696{
3697 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3698 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3699
3700 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3701 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3702
3703 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3704 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3705
3706 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3707 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3708}
3709
Scott Michel06eabde2008-12-27 04:51:36 +00003710defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3711defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003712
3713multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3714 SPUInstr orinst32, SPUInstr brinst32>
3715{
3716 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3717 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3718 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3719 bb:$dest)>;
3720
3721 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3722 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3723 (CEQHr16 R16C:$rA, R16:$rB)),
3724 bb:$dest)>;
3725
3726 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3727 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3728 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3729 bb:$dest)>;
3730
3731 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3732 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3733 (CEQr32 R32C:$rA, R32C:$rB)),
3734 bb:$dest)>;
3735}
3736
Scott Michel06eabde2008-12-27 04:51:36 +00003737defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3738defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003739
Scott Michel8b6b4202007-12-04 22:35:58 +00003740let isTerminator = 1, isBarrier = 1 in {
3741 let isReturn = 1 in {
3742 def RET:
3743 RETForm<"bi\t$$lr", [(retflag)]>;
3744 }
3745}
3746
3747//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003748// Single precision floating point instructions
3749//===----------------------------------------------------------------------===//
3750
Scott Michel61895fe2008-12-10 00:15:19 +00003751class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3752 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
3753 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003754
Scott Michel61895fe2008-12-10 00:15:19 +00003755class FAVecInst<ValueType vectype>:
3756 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3757 [(set (vectype VECREG:$rT),
3758 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003759
Scott Michel61895fe2008-12-10 00:15:19 +00003760multiclass SFPAdd
3761{
3762 def v4f32: FAVecInst<v4f32>;
3763 def r32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3764 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3765}
Scott Michel8b6b4202007-12-04 22:35:58 +00003766
Scott Michel61895fe2008-12-10 00:15:19 +00003767defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003768
Scott Michel61895fe2008-12-10 00:15:19 +00003769class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3770 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
3771 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003772
Scott Michel61895fe2008-12-10 00:15:19 +00003773class FSVecInst<ValueType vectype>:
3774 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3775 [(set (vectype VECREG:$rT),
3776 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
3777
3778multiclass SFPSub
3779{
3780 def v4f32: FSVecInst<v4f32>;
3781 def r32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3782 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3783}
3784
3785defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003786
3787// Floating point reciprocal estimate
3788def FREv4f32 :
3789 RRForm_1<0b00011101100, (outs VECREG:$rT), (ins VECREG:$rA),
3790 "frest\t$rT, $rA", SPrecFP,
3791 [(set (v4f32 VECREG:$rT), (SPUreciprocalEst (v4f32 VECREG:$rA)))]>;
3792
3793def FREf32 :
3794 RRForm_1<0b00011101100, (outs R32FP:$rT), (ins R32FP:$rA),
3795 "frest\t$rT, $rA", SPrecFP,
3796 [(set R32FP:$rT, (SPUreciprocalEst R32FP:$rA))]>;
3797
3798// Floating point interpolate (used in conjunction with reciprocal estimate)
3799def FIv4f32 :
3800 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3801 "fi\t$rT, $rA, $rB", SPrecFP,
3802 [(set (v4f32 VECREG:$rT), (SPUinterpolate (v4f32 VECREG:$rA),
3803 (v4f32 VECREG:$rB)))]>;
3804
3805def FIf32 :
3806 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3807 "fi\t$rT, $rA, $rB", SPrecFP,
3808 [(set R32FP:$rT, (SPUinterpolate R32FP:$rA, R32FP:$rB))]>;
3809
Scott Michel33d73eb2008-11-21 02:56:16 +00003810//--------------------------------------------------------------------------
3811// Basic single precision floating point comparisons:
3812//
3813// Note: There is no support on SPU for single precision NaN. Consequently,
3814// ordered and unordered comparisons are the same.
3815//--------------------------------------------------------------------------
3816
Scott Michel8b6b4202007-12-04 22:35:58 +00003817def FCEQf32 :
3818 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3819 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003820 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3821
3822def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3823 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003824
3825def FCMEQf32 :
3826 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3827 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003828 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3829
3830def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3831 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003832
3833def FCGTf32 :
3834 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3835 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003836 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3837
3838def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3839 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003840
3841def FCMGTf32 :
3842 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3843 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003844 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3845
3846def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3847 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3848
3849//--------------------------------------------------------------------------
3850// Single precision floating point comparisons and SETCC equivalents:
3851//--------------------------------------------------------------------------
3852
3853def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3854def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3855
3856def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3857def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3858
3859def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3860def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3861
3862def : Pat<(setule R32FP:$rA, R32FP:$rB),
3863 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3864def : Pat<(setole R32FP:$rA, R32FP:$rB),
3865 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003866
3867// FP Status and Control Register Write
3868// Why isn't rT a don't care in the ISA?
3869// Should we create a special RRForm_3 for this guy and zero out the rT?
3870def FSCRWf32 :
3871 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3872 "fscrwr\t$rA", SPrecFP,
3873 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3874
3875// FP Status and Control Register Read
3876def FSCRRf32 :
3877 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3878 "fscrrd\t$rT", SPrecFP,
3879 [/* This instruction requires an intrinsic */]>;
3880
3881// llvm instruction space
3882// How do these map onto cell instructions?
3883// fdiv rA rB
3884// frest rC rB # c = 1/b (both lines)
3885// fi rC rB rC
3886// fm rD rA rC # d = a * 1/b
3887// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3888// fma rB rB rC rD # b = b * c + d
3889// = -(d *b -a) * c + d
3890// = a * c - c ( a *b *c - a)
3891
3892// fcopysign (???)
3893
3894// Library calls:
3895// These llvm instructions will actually map to library calls.
3896// All that's needed, then, is to check that the appropriate library is
3897// imported and do a brsl to the proper function name.
3898// frem # fmod(x, y): x - (x/y) * y
3899// (Note: fmod(double, double), fmodf(float,float)
3900// fsqrt?
3901// fsin?
3902// fcos?
3903// Unimplemented SPU instruction space
3904// floating reciprocal absolute square root estimate (frsqest)
3905
3906// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00003907// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00003908// status and control register read
3909
3910//--------------------------------------
3911// Floating point multiply instructions
3912//--------------------------------------
3913
3914def FMv4f32:
3915 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3916 "fm\t$rT, $rA, $rB", SPrecFP,
3917 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3918 (v4f32 VECREG:$rB)))]>;
3919
3920def FMf32 :
3921 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3922 "fm\t$rT, $rA, $rB", SPrecFP,
3923 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3924
3925// Floating point multiply and add
3926// e.g. d = c + (a * b)
3927def FMAv4f32:
3928 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3929 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3930 [(set (v4f32 VECREG:$rT),
3931 (fadd (v4f32 VECREG:$rC),
3932 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3933
3934def FMAf32:
3935 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3936 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3937 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3938
3939// FP multiply and subtract
3940// Subtracts value in rC from product
3941// res = a * b - c
3942def FMSv4f32 :
3943 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3944 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3945 [(set (v4f32 VECREG:$rT),
3946 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3947 (v4f32 VECREG:$rC)))]>;
3948
3949def FMSf32 :
3950 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3951 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3952 [(set R32FP:$rT,
3953 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3954
3955// Floating Negative Mulitply and Subtract
3956// Subtracts product from value in rC
3957// res = fneg(fms a b c)
3958// = - (a * b - c)
3959// = c - a * b
3960// NOTE: subtraction order
3961// fsub a b = a - b
Scott Michel06eabde2008-12-27 04:51:36 +00003962// fs a b = b - a?
Scott Michel8b6b4202007-12-04 22:35:58 +00003963def FNMSf32 :
3964 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3965 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3966 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3967
3968def FNMSv4f32 :
3969 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3970 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00003971 [(set (v4f32 VECREG:$rT),
3972 (fsub (v4f32 VECREG:$rC),
3973 (fmul (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00003974 (v4f32 VECREG:$rB))))]>;
3975
3976//--------------------------------------
3977// Floating Point Conversions
3978// Signed conversions:
3979def CSiFv4f32:
3980 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3981 "csflt\t$rT, $rA, 0", SPrecFP,
3982 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3983
Scott Michel06eabde2008-12-27 04:51:36 +00003984// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00003985def CSiFf32 :
3986 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3987 "csflt\t$rT, $rA, 0", SPrecFP,
3988 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3989
3990// Convert unsigned into to float
3991def CUiFv4f32 :
3992 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3993 "cuflt\t$rT, $rA, 0", SPrecFP,
3994 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3995
3996def CUiFf32 :
3997 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3998 "cuflt\t$rT, $rA, 0", SPrecFP,
3999 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4000
Scott Michel06eabde2008-12-27 04:51:36 +00004001// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004002// Assume that scale = 0
4003
4004def CFUiv4f32 :
4005 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4006 "cfltu\t$rT, $rA, 0", SPrecFP,
4007 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4008
4009def CFUif32 :
4010 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4011 "cfltu\t$rT, $rA, 0", SPrecFP,
4012 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4013
Scott Michel06eabde2008-12-27 04:51:36 +00004014// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004015// Assume that scale = 0
4016
4017def CFSiv4f32 :
4018 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4019 "cflts\t$rT, $rA, 0", SPrecFP,
4020 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4021
4022def CFSif32 :
4023 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4024 "cflts\t$rT, $rA, 0", SPrecFP,
4025 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4026
4027//===----------------------------------------------------------------------==//
4028// Single<->Double precision conversions
4029//===----------------------------------------------------------------------==//
4030
4031// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4032// v4f32, output is v2f64--which goes in the name?)
4033
4034// Floating point extend single to double
4035// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4036// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4037// are ignored).
4038def FESDvec :
4039 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4040 "fesd\t$rT, $rA", SPrecFP,
4041 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4042
4043def FESDf32 :
4044 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4045 "fesd\t$rT, $rA", SPrecFP,
4046 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4047
4048// Floating point round double to single
4049//def FRDSvec :
4050// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4051// "frds\t$rT, $rA,", SPrecFP,
4052// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4053
4054def FRDSf64 :
4055 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4056 "frds\t$rT, $rA", SPrecFP,
4057 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4058
4059//ToDo include anyextend?
4060
4061//===----------------------------------------------------------------------==//
4062// Double precision floating point instructions
4063//===----------------------------------------------------------------------==//
4064def FAf64 :
4065 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4066 "dfa\t$rT, $rA, $rB", DPrecFP,
4067 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4068
4069def FAv2f64 :
4070 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4071 "dfa\t$rT, $rA, $rB", DPrecFP,
4072 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4073
4074def FSf64 :
4075 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4076 "dfs\t$rT, $rA, $rB", DPrecFP,
4077 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4078
4079def FSv2f64 :
4080 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4081 "dfs\t$rT, $rA, $rB", DPrecFP,
4082 [(set (v2f64 VECREG:$rT),
4083 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4084
4085def FMf64 :
4086 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4087 "dfm\t$rT, $rA, $rB", DPrecFP,
4088 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4089
4090def FMv2f64:
4091 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4092 "dfm\t$rT, $rA, $rB", DPrecFP,
4093 [(set (v2f64 VECREG:$rT),
4094 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4095
4096def FMAf64:
4097 RRForm<0b00111010110, (outs R64FP:$rT),
4098 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4099 "dfma\t$rT, $rA, $rB", DPrecFP,
4100 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4101 RegConstraint<"$rC = $rT">,
4102 NoEncode<"$rC">;
4103
4104def FMAv2f64:
4105 RRForm<0b00111010110, (outs VECREG:$rT),
4106 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4107 "dfma\t$rT, $rA, $rB", DPrecFP,
4108 [(set (v2f64 VECREG:$rT),
4109 (fadd (v2f64 VECREG:$rC),
4110 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4111 RegConstraint<"$rC = $rT">,
4112 NoEncode<"$rC">;
4113
4114def FMSf64 :
4115 RRForm<0b10111010110, (outs R64FP:$rT),
4116 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4117 "dfms\t$rT, $rA, $rB", DPrecFP,
4118 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4119 RegConstraint<"$rC = $rT">,
4120 NoEncode<"$rC">;
4121
4122def FMSv2f64 :
4123 RRForm<0b10111010110, (outs VECREG:$rT),
4124 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4125 "dfms\t$rT, $rA, $rB", DPrecFP,
4126 [(set (v2f64 VECREG:$rT),
4127 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4128 (v2f64 VECREG:$rC)))]>;
4129
4130// FNMS: - (a * b - c)
4131// - (a * b) + c => c - (a * b)
4132def FNMSf64 :
4133 RRForm<0b01111010110, (outs R64FP:$rT),
4134 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4135 "dfnms\t$rT, $rA, $rB", DPrecFP,
4136 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4137 RegConstraint<"$rC = $rT">,
4138 NoEncode<"$rC">;
4139
4140def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4141 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4142
4143def FNMSv2f64 :
4144 RRForm<0b01111010110, (outs VECREG:$rT),
4145 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4146 "dfnms\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004147 [(set (v2f64 VECREG:$rT),
4148 (fsub (v2f64 VECREG:$rC),
4149 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004150 (v2f64 VECREG:$rB))))]>,
4151 RegConstraint<"$rC = $rT">,
4152 NoEncode<"$rC">;
4153
4154def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4155 (v2f64 VECREG:$rC))),
4156 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4157
4158// - (a * b + c)
4159// - (a * b) - c
4160def FNMAf64 :
4161 RRForm<0b11111010110, (outs R64FP:$rT),
4162 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4163 "dfnma\t$rT, $rA, $rB", DPrecFP,
4164 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4165 RegConstraint<"$rC = $rT">,
4166 NoEncode<"$rC">;
4167
4168def FNMAv2f64 :
4169 RRForm<0b11111010110, (outs VECREG:$rT),
4170 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4171 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004172 [(set (v2f64 VECREG:$rT),
4173 (fneg (fadd (v2f64 VECREG:$rC),
4174 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004175 (v2f64 VECREG:$rB)))))]>,
4176 RegConstraint<"$rC = $rT">,
4177 NoEncode<"$rC">;
4178
4179//===----------------------------------------------------------------------==//
4180// Floating point negation and absolute value
4181//===----------------------------------------------------------------------==//
4182
4183def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00004184 (XORfnegvec (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004185 (v4f32 (ILHUv4i32 0x8000)))>;
4186
4187def : Pat<(fneg R32FP:$rA),
4188 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4189
4190def : Pat<(fneg (v2f64 VECREG:$rA)),
4191 (XORfnegvec (v2f64 VECREG:$rA),
4192 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4193
4194def : Pat<(fneg R64FP:$rA),
4195 (XORfneg64 R64FP:$rA,
4196 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4197
4198// Floating point absolute value
4199
4200def : Pat<(fabs R32FP:$rA),
4201 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4202
4203def : Pat<(fabs (v4f32 VECREG:$rA)),
4204 (ANDfabsvec (v4f32 VECREG:$rA),
4205 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4206
4207def : Pat<(fabs R64FP:$rA),
4208 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4209
4210def : Pat<(fabs (v2f64 VECREG:$rA)),
4211 (ANDfabsvec (v2f64 VECREG:$rA),
4212 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4213
4214//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004215// Hint for branch instructions:
4216//===----------------------------------------------------------------------===//
4217
4218/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4219
4220//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004221// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4222// in the odd pipeline)
4223//===----------------------------------------------------------------------===//
4224
Scott Michel97872d32008-02-23 18:41:37 +00004225def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004226 let Pattern = [];
4227
4228 let Inst{0-10} = 0b10000000010;
4229 let Inst{11-17} = 0;
4230 let Inst{18-24} = 0;
4231 let Inst{25-31} = 0;
4232}
4233
Scott Michel97872d32008-02-23 18:41:37 +00004234def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004235 let Pattern = [];
4236
4237 let Inst{0-10} = 0b10000000000;
4238 let Inst{11-17} = 0;
4239 let Inst{18-24} = 0;
4240 let Inst{25-31} = 0;
4241}
4242
4243//===----------------------------------------------------------------------===//
4244// Bit conversions (type conversions between vector/packed types)
4245// NOTE: Promotions are handled using the XS* instructions. Truncation
4246// is not handled.
4247//===----------------------------------------------------------------------===//
4248def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4249def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4250def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4251def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4252def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4253
4254def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4255def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4256def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4257def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4258def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4259
4260def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4261def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4262def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4263def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4264def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4265
4266def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4267def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4268def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4269def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4270def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4271
4272def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4273def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4274def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4275def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4276def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4277
4278def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4279def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4280def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4281def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4282def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4283
4284def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00004285def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004286
4287//===----------------------------------------------------------------------===//
4288// Instruction patterns:
4289//===----------------------------------------------------------------------===//
4290
4291// General 32-bit constants:
4292def : Pat<(i32 imm:$imm),
4293 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4294
4295// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004296def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004297 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4298
4299// General constant 32-bit vectors
4300def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004301 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4302 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004303
Scott Michel438be252007-12-17 22:32:34 +00004304// 8-bit constants
4305def : Pat<(i8 imm:$imm),
4306 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004307
4308//===----------------------------------------------------------------------===//
4309// Call instruction patterns:
4310//===----------------------------------------------------------------------===//
4311// Return void
4312def : Pat<(ret),
4313 (RET)>;
4314
4315//===----------------------------------------------------------------------===//
4316// Zero/Any/Sign extensions
4317//===----------------------------------------------------------------------===//
4318
Scott Michel8b6b4202007-12-04 22:35:58 +00004319// sext 8->32: Sign extend bytes to words
4320def : Pat<(sext_inreg R32C:$rSrc, i8),
4321 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4322
Scott Michel438be252007-12-17 22:32:34 +00004323def : Pat<(i32 (sext R8C:$rSrc)),
4324 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4325
Scott Michel438be252007-12-17 22:32:34 +00004326// zext 8->16: Zero extend bytes to halfwords
4327def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004328 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004329
Scott Michel438be252007-12-17 22:32:34 +00004330// zext 8->32: Zero extend bytes to words
4331def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004332 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004333
4334// anyext 8->16: Extend 8->16 bits, irrespective of sign
4335def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004336 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004337
4338// anyext 8->32: Extend 8->32 bits, irrespective of sign
4339def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004340 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004341
Scott Michel97872d32008-02-23 18:41:37 +00004342// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004343def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004344 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004345
4346def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004347 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004348
4349def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004350 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004351
4352def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004353 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004354
4355// anyext 16->32: Extend 16->32 bits, irrespective of sign
4356def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004357 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004358
4359//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004360// Truncates:
4361// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4362// above are custom lowered.
4363//===----------------------------------------------------------------------===//
4364
4365def : Pat<(i8 (trunc GPRC:$src)),
4366 (ORi8_v16i8
4367 (SHUFBgprc GPRC:$src, GPRC:$src,
4368 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4369
4370def : Pat<(i8 (trunc R64C:$src)),
4371 (ORi8_v16i8
4372 (SHUFBv2i64_m32
4373 (ORv2i64_i64 R64C:$src),
4374 (ORv2i64_i64 R64C:$src),
4375 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4376
4377def : Pat<(i8 (trunc R32C:$src)),
4378 (ORi8_v16i8
4379 (SHUFBv4i32_m32
4380 (ORv4i32_i32 R32C:$src),
4381 (ORv4i32_i32 R32C:$src),
4382 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4383
4384def : Pat<(i8 (trunc R16C:$src)),
4385 (ORi8_v16i8
4386 (SHUFBv4i32_m32
4387 (ORv8i16_i16 R16C:$src),
4388 (ORv8i16_i16 R16C:$src),
4389 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4390
4391def : Pat<(i16 (trunc GPRC:$src)),
4392 (ORi16_v8i16
4393 (SHUFBgprc GPRC:$src, GPRC:$src,
4394 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4395
4396def : Pat<(i16 (trunc R64C:$src)),
4397 (ORi16_v8i16
4398 (SHUFBv2i64_m32
4399 (ORv2i64_i64 R64C:$src),
4400 (ORv2i64_i64 R64C:$src),
4401 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4402
4403def : Pat<(i16 (trunc R32C:$src)),
4404 (ORi16_v8i16
4405 (SHUFBv4i32_m32
4406 (ORv4i32_i32 R32C:$src),
4407 (ORv4i32_i32 R32C:$src),
4408 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4409
4410def : Pat<(i32 (trunc GPRC:$src)),
4411 (ORi32_v4i32
4412 (SHUFBgprc GPRC:$src, GPRC:$src,
4413 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4414
4415def : Pat<(i32 (trunc R64C:$src)),
4416 (ORi32_v4i32
4417 (SHUFBv2i64_m32
4418 (ORv2i64_i64 R64C:$src),
4419 (ORv2i64_i64 R64C:$src),
4420 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4421
4422//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004423// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004424// low parts in order to load them into a register.
4425//===----------------------------------------------------------------------===//
4426
Scott Michelf9f42e62008-01-29 02:16:57 +00004427def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4428def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4429def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4430def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4431
4432def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4433 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004434 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004435
Scott Michelf9f42e62008-01-29 02:16:57 +00004436def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4437 (SPUlo texternalsym:$in, 0)),
4438 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4439
4440def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4441 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004442 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004443
Scott Michelf9f42e62008-01-29 02:16:57 +00004444def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4445 (SPUlo tconstpool:$in, 0)),
4446 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4447
Scott Michelbc5fbc12008-04-30 00:30:08 +00004448def : Pat<(SPUindirect R32C:$sp, i32ImmSExt10:$imm),
4449 (AIr32 R32C:$sp, i32ImmSExt10:$imm)>;
4450
4451def : Pat<(SPUindirect R32C:$sp, imm:$imm),
4452 (Ar32 R32C:$sp,
4453 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm)))>;
4454
Scott Michelf9f42e62008-01-29 02:16:57 +00004455def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4456 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4457
4458def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4459 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4460
4461def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4462 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4463
4464def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4465 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004466
Scott Michel8b6b4202007-12-04 22:35:58 +00004467// Instrinsics:
4468include "CellSDKIntrinsics.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004469// 64-bit "instructions"/support
4470include "SPU64InstrInfo.td"