blob: 6a0fde398b8a8c0d058ff5caad06b88f1a1021d0 [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,
Scott Michel4d07fb72008-12-30 23:28:25 +0000586 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
587
588// v4i32, i32 add instruction:
Scott Michel8b6b4202007-12-04 22:35:58 +0000589
Scott Michelae5cbf52008-12-29 03:23:36 +0000590class AInst<dag OOL, dag IOL, list<dag> pattern>:
591 RRForm<0b00000011000, OOL, IOL,
592 "a\t$rT, $rA, $rB", IntegerOp,
593 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000594
Scott Michelae5cbf52008-12-29 03:23:36 +0000595class AVecInst<ValueType vectype>:
596 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
597 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
598 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000599
Scott Michelae5cbf52008-12-29 03:23:36 +0000600class ARegInst<RegisterClass rclass>:
601 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
602 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
603
604multiclass AddInstruction {
605 def v4i32: AVecInst<v4i32>;
606 def v16i8: AVecInst<v16i8>;
607
608 def r32: ARegInst<R32C>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000609}
Scott Michel8b6b4202007-12-04 22:35:58 +0000610
Scott Michelae5cbf52008-12-29 03:23:36 +0000611defm A : AddInstruction;
Scott Michel438be252007-12-17 22:32:34 +0000612
Scott Michel4d07fb72008-12-30 23:28:25 +0000613class AIInst<dag OOL, dag IOL, list<dag> pattern>:
614 RI10Form<0b00111000, OOL, IOL,
615 "ai\t$rT, $rA, $val", IntegerOp,
616 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000617
Scott Michel4d07fb72008-12-30 23:28:25 +0000618class AIVecInst<ValueType vectype, PatLeaf immpred>:
619 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
620 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
621
622class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
623 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
624 [/* no pattern */]>;
625
626class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
627 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
628 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
629
630// This is used to add epsilons to floating point numbers in the f32 fdiv code:
631class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
632 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
633 [/* no pattern */]>;
634
635multiclass AddImmediate {
636 def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
637
638 def r32: AIRegInst<R32C, i32ImmSExt10>;
639
640 def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
641 def f32: AIFPInst<R32FP, i32ImmSExt10>;
642}
643
644defm AI : AddImmediate;
Scott Michel8b6b4202007-12-04 22:35:58 +0000645
Scott Michel438be252007-12-17 22:32:34 +0000646def SFHvec:
647 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
648 "sfh\t$rT, $rA, $rB", IntegerOp,
649 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
650 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000651
Scott Michel438be252007-12-17 22:32:34 +0000652def SFHr16:
653 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
654 "sfh\t$rT, $rA, $rB", IntegerOp,
655 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000656
657def SFHIvec:
658 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
659 "sfhi\t$rT, $rA, $val", IntegerOp,
660 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
661 (v8i16 VECREG:$rA)))]>;
662
663def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
664 "sfhi\t$rT, $rA, $val", IntegerOp,
665 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
666
667def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
668 (ins VECREG:$rA, VECREG:$rB),
669 "sf\t$rT, $rA, $rB", IntegerOp,
670 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
671
672def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
673 "sf\t$rT, $rA, $rB", IntegerOp,
674 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
675
676def SFIvec:
677 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
678 "sfi\t$rT, $rA, $val", IntegerOp,
679 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
680 (v4i32 VECREG:$rA)))]>;
681
682def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
683 (ins R32C:$rA, s10imm_i32:$val),
684 "sfi\t$rT, $rA, $val", IntegerOp,
685 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
686
687// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000688class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
689 RRForm<0b00000010110, OOL, IOL,
690 "addx\t$rT, $rA, $rB",
691 IntegerOp, pattern>;
692
693class ADDXVecInst<ValueType vectype>:
694 ADDXInst<(outs VECREG:$rT),
695 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
696 [(set (vectype VECREG:$rT),
697 (SPUaddx (vectype VECREG:$rA), (vectype VECREG:$rB),
698 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000699 RegConstraint<"$rCarry = $rT">,
700 NoEncode<"$rCarry">;
701
Scott Michel67224b22008-06-02 22:18:03 +0000702class ADDXRegInst<RegisterClass rclass>:
703 ADDXInst<(outs rclass:$rT),
704 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
705 [(set rclass:$rT,
706 (SPUaddx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000707 RegConstraint<"$rCarry = $rT">,
708 NoEncode<"$rCarry">;
709
Scott Michel67224b22008-06-02 22:18:03 +0000710multiclass AddExtended {
711 def v2i64 : ADDXVecInst<v2i64>;
712 def v4i32 : ADDXVecInst<v4i32>;
713 def r64 : ADDXRegInst<R64C>;
714 def r32 : ADDXRegInst<R32C>;
715}
716
717defm ADDX : AddExtended;
718
719// CG: Generate carry for add
720class CGInst<dag OOL, dag IOL, list<dag> pattern>:
721 RRForm<0b01000011000, OOL, IOL,
722 "cg\t$rT, $rA, $rB",
723 IntegerOp, pattern>;
724
725class CGVecInst<ValueType vectype>:
726 CGInst<(outs VECREG:$rT),
727 (ins VECREG:$rA, VECREG:$rB),
728 [(set (vectype VECREG:$rT),
729 (SPUcarry_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
730
731class CGRegInst<RegisterClass rclass>:
732 CGInst<(outs rclass:$rT),
733 (ins rclass:$rA, rclass:$rB),
734 [(set rclass:$rT,
735 (SPUcarry_gen rclass:$rA, rclass:$rB))]>;
736
737multiclass CarryGenerate {
738 def v2i64 : CGVecInst<v2i64>;
739 def v4i32 : CGVecInst<v4i32>;
740 def r64 : CGRegInst<R64C>;
741 def r32 : CGRegInst<R32C>;
742}
743
744defm CG : CarryGenerate;
745
746// SFX: Subract from, extended. This is used in conjunction with BG to subtract
747// with carry (borrow, in this case)
748class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
749 RRForm<0b10000010110, OOL, IOL,
750 "sfx\t$rT, $rA, $rB",
751 IntegerOp, pattern>;
752
753class SFXVecInst<ValueType vectype>:
754 SFXInst<(outs VECREG:$rT),
755 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
756 [(set (vectype VECREG:$rT),
757 (SPUsubx (vectype VECREG:$rA), (vectype VECREG:$rB),
758 (vectype VECREG:$rCarry)))]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000759 RegConstraint<"$rCarry = $rT">,
760 NoEncode<"$rCarry">;
761
Scott Michel67224b22008-06-02 22:18:03 +0000762class SFXRegInst<RegisterClass rclass>:
763 SFXInst<(outs rclass:$rT),
764 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
765 [(set rclass:$rT,
766 (SPUsubx rclass:$rA, rclass:$rB, rclass:$rCarry))]>,
767 RegConstraint<"$rCarry = $rT">,
768 NoEncode<"$rCarry">;
769
770multiclass SubtractExtended {
771 def v2i64 : SFXVecInst<v2i64>;
772 def v4i32 : SFXVecInst<v4i32>;
773 def r64 : SFXRegInst<R64C>;
774 def r32 : SFXRegInst<R32C>;
775}
776
777defm SFX : SubtractExtended;
778
Scott Michel8b6b4202007-12-04 22:35:58 +0000779// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000780class BGInst<dag OOL, dag IOL, list<dag> pattern>:
781 RRForm<0b01000010000, OOL, IOL,
782 "bg\t$rT, $rA, $rB",
783 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000784
Scott Michel67224b22008-06-02 22:18:03 +0000785class BGVecInst<ValueType vectype>:
786 BGInst<(outs VECREG:$rT),
787 (ins VECREG:$rA, VECREG:$rB),
788 [(set (vectype VECREG:$rT),
789 (SPUborrow_gen (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
790
791class BGRegInst<RegisterClass rclass>:
792 BGInst<(outs rclass:$rT),
793 (ins rclass:$rA, rclass:$rB),
794 [(set rclass:$rT,
795 (SPUborrow_gen rclass:$rA, rclass:$rB))]>;
796
797multiclass BorrowGenerate {
798 def v4i32 : BGVecInst<v4i32>;
799 def v2i64 : BGVecInst<v2i64>;
800 def r64 : BGRegInst<R64C>;
801 def r32 : BGRegInst<R32C>;
802}
803
804defm BG : BorrowGenerate;
805
806// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000807def BGXvec:
808 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000809 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000810 "bgx\t$rT, $rA, $rB", IntegerOp,
811 []>,
812 RegConstraint<"$rCarry = $rT">,
813 NoEncode<"$rCarry">;
814
815// Halfword multiply variants:
816// N.B: These can be used to build up larger quantities (16x16 -> 32)
817
818def MPYv8i16:
819 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
820 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000821 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000822
823def MPYr16:
824 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
825 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
826 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
827
Scott Michelae5cbf52008-12-29 03:23:36 +0000828// Unsigned 16-bit multiply:
829
830class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
831 RRForm<0b00110011110, OOL, IOL,
832 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
833 pattern>;
834
Scott Michel8b6b4202007-12-04 22:35:58 +0000835def MPYUv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000836 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000837 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000838
839def MPYUr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000840 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
841 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000842
843def MPYUr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000844 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000845 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000846
Scott Michelae5cbf52008-12-29 03:23:36 +0000847// mpyi: multiply 16 x s10imm -> 32 result.
848
849class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
850 RI10Form<0b00101110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000851 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000852 pattern>;
853
854def MPYIvec:
855 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
856 [(set (v8i16 VECREG:$rT),
857 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000858
859def MPYIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000860 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
861 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000862
863// mpyui: same issues as other multiplies, plus, this doesn't match a
864// pattern... but may be used during target DAG selection or lowering
Scott Michelae5cbf52008-12-29 03:23:36 +0000865
866class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
867 RI10Form<0b10101110, OOL, IOL,
868 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
869 pattern>;
870
Scott Michel8b6b4202007-12-04 22:35:58 +0000871def MPYUIvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000872 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
873 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000874
875def MPYUIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000876 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
877 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000878
879// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michelae5cbf52008-12-29 03:23:36 +0000880class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
881 RRRForm<0b0011, OOL, IOL,
882 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
883 pattern>;
884
Scott Michel8b6b4202007-12-04 22:35:58 +0000885def MPYAvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000886 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
887 [(set (v4i32 VECREG:$rT),
888 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
889 (v8i16 VECREG:$rB)))),
890 (v4i32 VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000891
892def MPYAr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000893 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
894 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
895 R32C:$rC))]>;
896
897def MPYAr32_sext:
898 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
899 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
900 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000901
902def MPYAr32_sextinreg:
Scott Michelae5cbf52008-12-29 03:23:36 +0000903 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
904 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
905 (sext_inreg R32C:$rB, i16)),
906 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000907
908// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michelae5cbf52008-12-29 03:23:36 +0000909class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
910 RRForm<0b10100011110, OOL, IOL,
911 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
912 pattern>;
913
Scott Michel8b6b4202007-12-04 22:35:58 +0000914def MPYHv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000915 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000916 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000917
918def MPYHr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000919 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000920 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000921
922// mpys: multiply high and shift right (returns the top half of
923// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000924
Scott Michel4d07fb72008-12-30 23:28:25 +0000925class MPYSInst<dag OOL, dag IOL>:
926 RRForm<0b11100011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000927 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000928 [/* no pattern */]>;
929
930def MPYSvec:
931 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
932
933def MPYSr16:
934 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000935
936// mpyhh: multiply high-high (returns the 32-bit result from multiplying
937// the top 16 bits of the $rA, $rB)
Scott Michel4d07fb72008-12-30 23:28:25 +0000938
939class MPYHHInst<dag OOL, dag IOL>:
940 RRForm<0b01100011110, OOL, IOL,
941 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
942 [/* no pattern */]>;
943
Scott Michel8b6b4202007-12-04 22:35:58 +0000944def MPYHHv8i16:
Scott Michel4d07fb72008-12-30 23:28:25 +0000945 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000946
947def MPYHHr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000948 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000949
950// mpyhha: Multiply high-high, add to $rT:
Scott Michel8b6b4202007-12-04 22:35:58 +0000951
Scott Michel4d07fb72008-12-30 23:28:25 +0000952class MPYHHAInst<dag OOL, dag IOL>:
953 RRForm<0b01100010110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000954 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000955 [/* no pattern */]>;
956
957def MPYHHAvec:
958 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
959
960def MPYHHAr32:
961 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000962
963// mpyhhu: Multiply high-high, unsigned
Scott Michel8b6b4202007-12-04 22:35:58 +0000964
Scott Michel4d07fb72008-12-30 23:28:25 +0000965class MPYHHUInst<dag OOL, dag IOL>:
966 RRForm<0b01110011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000967 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000968 [/* no pattern */]>;
969
970def MPYHHUvec:
971 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
972
973def MPYHHUr32:
974 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000975
976// mpyhhau: Multiply high-high, unsigned
Scott Michel4d07fb72008-12-30 23:28:25 +0000977
978class MPYHHAUInst<dag OOL, dag IOL>:
979 RRForm<0b01110010110, OOL, IOL,
980 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
981 [/* no pattern */]>;
982
Scott Michel8b6b4202007-12-04 22:35:58 +0000983def MPYHHAUvec:
Scott Michel4d07fb72008-12-30 23:28:25 +0000984 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
985
Scott Michel8b6b4202007-12-04 22:35:58 +0000986def MPYHHAUr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000987 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000988
989//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +0000990// clz: Count leading zeroes
Scott Michelae5cbf52008-12-29 03:23:36 +0000991//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel06eabde2008-12-27 04:51:36 +0000992class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
993 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
994 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000995
Scott Michel06eabde2008-12-27 04:51:36 +0000996class CLZRegInst<RegisterClass rclass>:
997 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel4d07fb72008-12-30 23:28:25 +0000998 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michel06eabde2008-12-27 04:51:36 +0000999
1000class CLZVecInst<ValueType vectype>:
1001 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1002 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1003
1004multiclass CountLeadingZeroes {
1005 def v4i32 : CLZVecInst<v4i32>;
1006 def r32 : CLZRegInst<R32C>;
1007}
1008
1009defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001010
1011// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +00001012//
Scott Michel8b6b4202007-12-04 22:35:58 +00001013// NOTE: This instruction is really a vector instruction, but the custom
1014// lowering code uses it in unorthodox ways to support CTPOP for other
1015// data types!
Scott Michel06eabde2008-12-27 04:51:36 +00001016
Scott Michel8b6b4202007-12-04 22:35:58 +00001017def CNTBv16i8:
1018 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1019 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001020 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001021
1022def CNTBv8i16 :
1023 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1024 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001025 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001026
1027def CNTBv4i32 :
1028 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1029 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001030 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001031
Scott Michel06eabde2008-12-27 04:51:36 +00001032// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1033// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1034// slots 1-3.
1035//
1036// Note: This instruction "pairs" with the fsmb instruction for all of the
1037// various types defined here.
1038//
1039// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1040// a vector or register.
1041
1042class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1043 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1044
1045class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1046 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
1047 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1048
1049class GBBVecInst<ValueType vectype>:
1050 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1051 [(set (vectype VECREG:$rT), (SPUgatherbits (vectype VECREG:$rA)))]>;
1052
1053multiclass GatherBitsFromBytes {
1054 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1055 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1056 def v16i8: GBBVecInst<v16i8>;
1057}
1058
1059defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001060
1061// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001062// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1063// and slots 1-3 also set to 0.
1064//
1065// See notes for GBBInst, above.
1066
1067class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1068 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1069 pattern>;
1070
1071class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1072 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
1073 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1074
1075class GBHVecInst<ValueType vectype>:
1076 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
1077 [(set (vectype VECREG:$rT),
1078 (SPUgatherbits (vectype VECREG:$rA)))]>;
1079
1080multiclass GatherBitsHalfword {
1081 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1082 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1083 def v8i16: GBHVecInst<v8i16>;
1084}
1085
1086defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001087
1088// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001089// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1090// as well as slots 1-3.
1091//
1092// See notes for gbb, above.
1093
1094class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1095 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1096 pattern>;
1097
1098class GBRegInst<RegisterClass rclass, ValueType vectype>:
1099 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
1100 [(set rclass:$rT, (SPUgatherbits (vectype VECREG:$rA)))]>;
1101
1102class GBVecInst<ValueType vectype>:
1103 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1104 [(set (vectype VECREG:$rT),
1105 (SPUgatherbits (vectype VECREG:$rA)))]>;
1106
1107multiclass GatherBitsWord {
1108 def v4i32_r32: GBRegInst<R32C, v4i32>;
1109 def v4i32_r16: GBRegInst<R16C, v4i32>;
1110 def v4i32: GBVecInst<v4i32>;
1111}
1112
1113defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001114
1115// avgb: average bytes
1116def AVGB:
1117 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1118 "avgb\t$rT, $rA, $rB", ByteOp,
1119 []>;
1120
1121// absdb: absolute difference of bytes
1122def ABSDB:
1123 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1124 "absdb\t$rT, $rA, $rB", ByteOp,
1125 []>;
1126
1127// sumb: sum bytes into halfwords
1128def SUMB:
1129 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1130 "sumb\t$rT, $rA, $rB", ByteOp,
1131 []>;
1132
1133// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001134class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1135 RRForm_1<0b01101101010, OOL, IOL,
1136 "xsbh\t$rDst, $rSrc",
1137 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001138
Scott Michel67224b22008-06-02 22:18:03 +00001139class XSBHVecInst<ValueType vectype>:
1140 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1141 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001142
Scott Michel2ef773a2009-01-06 03:36:14 +00001143class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel67224b22008-06-02 22:18:03 +00001144 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Michel2ef773a2009-01-06 03:36:14 +00001145 pattern>;
Scott Michel67224b22008-06-02 22:18:03 +00001146
1147multiclass ExtendByteHalfword {
Scott Michel2ef773a2009-01-06 03:36:14 +00001148 def v16i8: XSBHVecInst<v8i16>;
1149 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1150 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1151 def r16: XSBHInRegInst<R16C,
1152 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001153
1154 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1155 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1156 // pattern below). Intentionally doesn't match a pattern because we want the
1157 // sext 8->32 pattern to do the work for us, namely because we need the extra
1158 // XSHWr32.
Scott Michel2ef773a2009-01-06 03:36:14 +00001159 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1160
1161 // Same as the 32-bit version, but for i64
1162 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +00001163}
1164
1165defm XSBH : ExtendByteHalfword;
1166
Scott Michel8b6b4202007-12-04 22:35:58 +00001167// Sign extend halfwords to words:
Scott Michel8b6b4202007-12-04 22:35:58 +00001168
Scott Michel2ef773a2009-01-06 03:36:14 +00001169class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1170 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1171 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001172
Scott Michel2ef773a2009-01-06 03:36:14 +00001173class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1174 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1175 [(set (out_vectype VECREG:$rDest),
1176 (sext (in_vectype VECREG:$rSrc)))]>;
1177
1178class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1179 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1180 pattern>;
1181
1182class XSHWRegInst<RegisterClass rclass>:
1183 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1184 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1185
1186multiclass ExtendHalfwordWord {
1187 def v4i32: XSHWVecInst<v4i32, v8i16>;
1188
1189 def r16: XSHWRegInst<R32C>;
1190
1191 def r32: XSHWInRegInst<R32C,
1192 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1193 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1194}
1195
1196defm XSHW : ExtendHalfwordWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001197
Scott Michele0168c12009-01-05 01:34:35 +00001198// Sign-extend words to doublewords (32->64 bits)
Scott Michel8b6b4202007-12-04 22:35:58 +00001199
Scott Michele0168c12009-01-05 01:34:35 +00001200class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel2ef773a2009-01-06 03:36:14 +00001201 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1202 IntegerOp, pattern>;
Scott Michele0168c12009-01-05 01:34:35 +00001203
1204class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1205 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1206 [(set (out_vectype VECREG:$rDst),
1207 (sext (out_vectype VECREG:$rSrc)))]>;
1208
1209class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1210 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1211 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1212
1213multiclass ExtendWordToDoubleWord {
1214 def v2i64: XSWDVecInst<v4i32, v2i64>;
1215 def r64: XSWDRegInst<R32C, R64C>;
1216
1217 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1218 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1219}
Scott Michel8b6b4202007-12-04 22:35:58 +00001220
Scott Michele0168c12009-01-05 01:34:35 +00001221defm XSWD : ExtendWordToDoubleWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001222
1223// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001224
Scott Michel97872d32008-02-23 18:41:37 +00001225class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1226 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1227 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001228
Scott Michel97872d32008-02-23 18:41:37 +00001229class ANDVecInst<ValueType vectype>:
1230 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1231 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1232 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001233
Scott Michel6baba072008-03-05 23:02:02 +00001234class ANDRegInst<RegisterClass rclass>:
1235 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1236 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1237
Scott Michel97872d32008-02-23 18:41:37 +00001238multiclass BitwiseAnd
1239{
1240 def v16i8: ANDVecInst<v16i8>;
1241 def v8i16: ANDVecInst<v8i16>;
1242 def v4i32: ANDVecInst<v4i32>;
1243 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001244
Scott Michel6baba072008-03-05 23:02:02 +00001245 def r128: ANDRegInst<GPRC>;
1246 def r64: ANDRegInst<R64C>;
1247 def r32: ANDRegInst<R32C>;
1248 def r16: ANDRegInst<R16C>;
1249 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001250
Scott Michel97872d32008-02-23 18:41:37 +00001251 //===---------------------------------------------
1252 // Special instructions to perform the fabs instruction
1253 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1254 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001255
Scott Michel97872d32008-02-23 18:41:37 +00001256 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1257 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001258
Scott Michel97872d32008-02-23 18:41:37 +00001259 // Could use v4i32, but won't for clarity
1260 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1261 [/* Intentionally does not match a pattern */]>;
1262
1263 //===---------------------------------------------
1264
1265 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1266 // quantities -- see 16->32 zext pattern.
1267 //
1268 // This pattern is somewhat artificial, since it might match some
1269 // compiler generated pattern but it is unlikely to do so.
1270
1271 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1272 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1273}
1274
1275defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001276
1277// N.B.: vnot_conv is one of those special target selection pattern fragments,
1278// in which we expect there to be a bit_convert on the constant. Bear in mind
1279// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1280// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001281
Scott Michel97872d32008-02-23 18:41:37 +00001282class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1283 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1284 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001285
Scott Michel97872d32008-02-23 18:41:37 +00001286class ANDCVecInst<ValueType vectype>:
1287 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1288 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1289 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001290
Scott Michel97872d32008-02-23 18:41:37 +00001291class ANDCRegInst<RegisterClass rclass>:
1292 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1293 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001294
Scott Michel97872d32008-02-23 18:41:37 +00001295multiclass AndComplement
1296{
1297 def v16i8: ANDCVecInst<v16i8>;
1298 def v8i16: ANDCVecInst<v8i16>;
1299 def v4i32: ANDCVecInst<v4i32>;
1300 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001301
Scott Michel97872d32008-02-23 18:41:37 +00001302 def r128: ANDCRegInst<GPRC>;
1303 def r64: ANDCRegInst<R64C>;
1304 def r32: ANDCRegInst<R32C>;
1305 def r16: ANDCRegInst<R16C>;
1306 def r8: ANDCRegInst<R8C>;
1307}
Scott Michel438be252007-12-17 22:32:34 +00001308
Scott Michel97872d32008-02-23 18:41:37 +00001309defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001310
Scott Michel97872d32008-02-23 18:41:37 +00001311class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1312 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001313 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001314
Scott Michel97872d32008-02-23 18:41:37 +00001315multiclass AndByteImm
1316{
1317 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1318 [(set (v16i8 VECREG:$rT),
1319 (and (v16i8 VECREG:$rA),
1320 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001321
Scott Michel97872d32008-02-23 18:41:37 +00001322 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1323 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1324}
Scott Michel438be252007-12-17 22:32:34 +00001325
Scott Michel97872d32008-02-23 18:41:37 +00001326defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001327
Scott Michel97872d32008-02-23 18:41:37 +00001328class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1329 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001330 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001331
Scott Michel97872d32008-02-23 18:41:37 +00001332multiclass AndHalfwordImm
1333{
1334 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1335 [(set (v8i16 VECREG:$rT),
1336 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001337
Scott Michel97872d32008-02-23 18:41:37 +00001338 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1339 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001340
Scott Michel97872d32008-02-23 18:41:37 +00001341 // Zero-extend i8 to i16:
1342 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1343 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1344}
Scott Michel8b6b4202007-12-04 22:35:58 +00001345
Scott Michel97872d32008-02-23 18:41:37 +00001346defm ANDHI : AndHalfwordImm;
1347
1348class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1349 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1350 IntegerOp, pattern>;
1351
1352multiclass AndWordImm
1353{
1354 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1355 [(set (v4i32 VECREG:$rT),
1356 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1357
1358 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1359 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1360
1361 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1362 // pattern below.
1363 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1364 [(set R32C:$rT,
1365 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1366
1367 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1368 // zext 16->32 pattern below.
1369 //
1370 // Note that this pattern is somewhat artificial, since it might match
1371 // something the compiler generates but is unlikely to occur in practice.
1372 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1373 [(set R32C:$rT,
1374 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1375}
1376
1377defm ANDI : AndWordImm;
1378
1379//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001380// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001381//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1382
Scott Michel8b6b4202007-12-04 22:35:58 +00001383// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001384class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1385 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1386 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001387
Scott Michel97872d32008-02-23 18:41:37 +00001388class ORVecInst<ValueType vectype>:
1389 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1390 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1391 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001392
Scott Michel97872d32008-02-23 18:41:37 +00001393class ORRegInst<RegisterClass rclass>:
1394 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1395 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001396
Scott Michel06eabde2008-12-27 04:51:36 +00001397// ORCvtForm: OR conversion form
1398//
1399// This is used to "convert" the preferred slot to its vector equivalent, as
1400// well as convert a vector back to its preferred slot.
1401//
1402// These are effectively no-ops, but need to exist for proper type conversion
1403// and type coercion.
1404
1405class ORCvtForm<dag OOL, dag IOL>
1406 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1407 bits<7> RA;
1408 bits<7> RT;
1409
1410 let Pattern = [/* no pattern */];
1411
1412 let Inst{0-10} = 0b10000010000;
1413 let Inst{11-17} = RA;
1414 let Inst{18-24} = RA;
1415 let Inst{25-31} = RT;
1416}
1417
Scott Michel97872d32008-02-23 18:41:37 +00001418class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001419 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001420
Scott Michel97872d32008-02-23 18:41:37 +00001421class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001422 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1423
1424class ORCvtRegGPRC<RegisterClass rclass>:
1425 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>;
1426
1427class ORCvtVecGPRC:
1428 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
1429
1430class ORCvtGPRCReg<RegisterClass rclass>:
1431 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001432
1433class ORCvtFormR32Reg<RegisterClass rclass>:
1434 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA)>;
1435
1436class ORCvtFormRegR32<RegisterClass rclass>:
1437 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA)>;
1438
1439class ORCvtFormR64Reg<RegisterClass rclass>:
1440 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA)>;
1441
1442class ORCvtFormRegR64<RegisterClass rclass>:
1443 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA)>;
Scott Michel06eabde2008-12-27 04:51:36 +00001444
1445class ORCvtGPRCVec:
1446 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001447
Scott Michel97872d32008-02-23 18:41:37 +00001448multiclass BitwiseOr
1449{
1450 def v16i8: ORVecInst<v16i8>;
1451 def v8i16: ORVecInst<v8i16>;
1452 def v4i32: ORVecInst<v4i32>;
1453 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001454
Scott Michel97872d32008-02-23 18:41:37 +00001455 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1456 [(set (v4f32 VECREG:$rT),
1457 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1458 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001459
Scott Michel97872d32008-02-23 18:41:37 +00001460 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001461 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001462 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1463 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001464
Scott Michel97872d32008-02-23 18:41:37 +00001465 def r64: ORRegInst<R64C>;
1466 def r32: ORRegInst<R32C>;
1467 def r16: ORRegInst<R16C>;
1468 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001469
Scott Michel97872d32008-02-23 18:41:37 +00001470 // OR instructions used to copy f32 and f64 registers.
1471 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1472 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001473
Scott Michel97872d32008-02-23 18:41:37 +00001474 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1475 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001476
Scott Michel4d07fb72008-12-30 23:28:25 +00001477 // scalar->vector promotion, prefslot2vec:
Scott Michel97872d32008-02-23 18:41:37 +00001478 def v16i8_i8: ORPromoteScalar<R8C>;
1479 def v8i16_i16: ORPromoteScalar<R16C>;
1480 def v4i32_i32: ORPromoteScalar<R32C>;
1481 def v2i64_i64: ORPromoteScalar<R64C>;
1482 def v4f32_f32: ORPromoteScalar<R32FP>;
1483 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001484
Scott Michel4d07fb72008-12-30 23:28:25 +00001485 // vector->scalar demotion, vec2prefslot:
Scott Michel97872d32008-02-23 18:41:37 +00001486 def i8_v16i8: ORExtractElt<R8C>;
1487 def i16_v8i16: ORExtractElt<R16C>;
1488 def i32_v4i32: ORExtractElt<R32C>;
1489 def i64_v2i64: ORExtractElt<R64C>;
1490 def f32_v4f32: ORExtractElt<R32FP>;
1491 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001492
1493 // Conversion from GPRC to register
1494 def i128_r64: ORCvtRegGPRC<R64C>;
1495 def i128_f64: ORCvtRegGPRC<R64FP>;
1496 def i128_r32: ORCvtRegGPRC<R32C>;
1497 def i128_f32: ORCvtRegGPRC<R32FP>;
1498 def i128_r16: ORCvtRegGPRC<R16C>;
1499 def i128_r8: ORCvtRegGPRC<R8C>;
1500
1501 // Conversion from GPRC to vector
1502 def i128_vec: ORCvtVecGPRC;
1503
1504 // Conversion from register to GPRC
1505 def r64_i128: ORCvtGPRCReg<R64C>;
1506 def f64_i128: ORCvtGPRCReg<R64FP>;
1507 def r32_i128: ORCvtGPRCReg<R32C>;
1508 def f32_i128: ORCvtGPRCReg<R32FP>;
1509 def r16_i128: ORCvtGPRCReg<R16C>;
1510 def r8_i128: ORCvtGPRCReg<R8C>;
1511
1512 // Conversion from vector to GPRC
1513 def vec_i128: ORCvtGPRCVec;
Scott Michel2ef773a2009-01-06 03:36:14 +00001514
1515 // Conversion from register to R32C:
1516 def r16_r32: ORCvtFormRegR32<R16C>;
1517 def r8_r32: ORCvtFormRegR32<R8C>;
1518
1519 // Conversion from R32C to register
1520 def r32_r16: ORCvtFormR32Reg<R16C>;
1521 def r32_r8: ORCvtFormR32Reg<R8C>;
1522
1523 // Conversion from register to R64C:
1524 def r32_r64: ORCvtFormR64Reg<R32C>;
1525 def r16_r64: ORCvtFormR64Reg<R16C>;
1526 def r8_r64: ORCvtFormR64Reg<R8C>;
1527
1528 // Conversion from R64C to register
1529 def r64_r32: ORCvtFormRegR64<R32C>;
1530 def r64_r16: ORCvtFormRegR64<R16C>;
1531 def r64_r8: ORCvtFormRegR64<R8C>;
Scott Michel97872d32008-02-23 18:41:37 +00001532}
Scott Michel438be252007-12-17 22:32:34 +00001533
Scott Michel97872d32008-02-23 18:41:37 +00001534defm OR : BitwiseOr;
1535
Scott Michel06eabde2008-12-27 04:51:36 +00001536// scalar->vector promotion patterns (preferred slot to vector):
1537def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1538 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001539
Scott Michel06eabde2008-12-27 04:51:36 +00001540def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1541 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001542
Scott Michel06eabde2008-12-27 04:51:36 +00001543def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1544 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001545
Scott Michel06eabde2008-12-27 04:51:36 +00001546def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1547 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001548
Scott Michel06eabde2008-12-27 04:51:36 +00001549def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1550 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001551
Scott Michel06eabde2008-12-27 04:51:36 +00001552def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1553 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001554
Scott Michel06eabde2008-12-27 04:51:36 +00001555// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1556// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001557
Scott Michelc630c412008-11-24 17:11:17 +00001558def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001559 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001560
Scott Michelc630c412008-11-24 17:11:17 +00001561def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001562 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001563
Scott Michelc630c412008-11-24 17:11:17 +00001564def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001565 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001566
Scott Michelc630c412008-11-24 17:11:17 +00001567def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001568 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001569
Scott Michelc630c412008-11-24 17:11:17 +00001570def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001571 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001572
Scott Michelc630c412008-11-24 17:11:17 +00001573def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001574 (ORf64_v2f64 VECREG:$rA)>;
1575
1576// Load Register: This is an assembler alias for a bitwise OR of a register
1577// against itself. It's here because it brings some clarity to assembly
1578// language output.
1579
1580let hasCtrlDep = 1 in {
1581 class LRInst<dag OOL, dag IOL>
1582 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1583 bits<7> RA;
1584 bits<7> RT;
1585
1586 let Pattern = [/*no pattern*/];
1587
1588 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1589 let Inst{11-17} = RA;
1590 let Inst{18-24} = RA;
1591 let Inst{25-31} = RT;
1592 }
1593
1594 class LRVecInst<ValueType vectype>:
1595 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1596
1597 class LRRegInst<RegisterClass rclass>:
1598 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1599
1600 multiclass LoadRegister {
1601 def v2i64: LRVecInst<v2i64>;
1602 def v2f64: LRVecInst<v2f64>;
1603 def v4i32: LRVecInst<v4i32>;
1604 def v4f32: LRVecInst<v4f32>;
1605 def v8i16: LRVecInst<v8i16>;
1606 def v16i8: LRVecInst<v16i8>;
1607
1608 def r128: LRRegInst<GPRC>;
1609 def r64: LRRegInst<R64C>;
1610 def f64: LRRegInst<R64FP>;
1611 def r32: LRRegInst<R32C>;
1612 def f32: LRRegInst<R32FP>;
1613 def r16: LRRegInst<R16C>;
1614 def r8: LRRegInst<R8C>;
1615 }
1616
1617 defm LR: LoadRegister;
1618}
Scott Michel8b6b4202007-12-04 22:35:58 +00001619
Scott Michel97872d32008-02-23 18:41:37 +00001620// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001621
Scott Michel97872d32008-02-23 18:41:37 +00001622class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1623 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1624 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001625
Scott Michel97872d32008-02-23 18:41:37 +00001626class ORCVecInst<ValueType vectype>:
1627 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1628 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1629 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001630
Scott Michel97872d32008-02-23 18:41:37 +00001631class ORCRegInst<RegisterClass rclass>:
1632 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1633 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001634
Scott Michel97872d32008-02-23 18:41:37 +00001635multiclass BitwiseOrComplement
1636{
1637 def v16i8: ORCVecInst<v16i8>;
1638 def v8i16: ORCVecInst<v8i16>;
1639 def v4i32: ORCVecInst<v4i32>;
1640 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001641
Scott Michel97872d32008-02-23 18:41:37 +00001642 def r64: ORCRegInst<R64C>;
1643 def r32: ORCRegInst<R32C>;
1644 def r16: ORCRegInst<R16C>;
1645 def r8: ORCRegInst<R8C>;
1646}
1647
1648defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001649
Scott Michel8b6b4202007-12-04 22:35:58 +00001650// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001651class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1652 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1653 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001654
Scott Michel97872d32008-02-23 18:41:37 +00001655class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1656 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1657 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1658 (vectype immpred:$val)))]>;
1659
1660multiclass BitwiseOrByteImm
1661{
1662 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1663
1664 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1665 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1666}
1667
1668defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001669
Scott Michel8b6b4202007-12-04 22:35:58 +00001670// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001671class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1672 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1673 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001674
Scott Michel97872d32008-02-23 18:41:37 +00001675class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1676 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1677 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1678 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001679
Scott Michel97872d32008-02-23 18:41:37 +00001680multiclass BitwiseOrHalfwordImm
1681{
1682 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1683
1684 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1685 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1686
1687 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1688 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1689 [(set R16C:$rT, (or (anyext R8C:$rA),
1690 i16ImmSExt10:$val))]>;
1691}
1692
1693defm ORHI : BitwiseOrHalfwordImm;
1694
1695class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1696 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1697 IntegerOp, pattern>;
1698
1699class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1700 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1701 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1702 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001703
1704// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001705multiclass BitwiseOrImm
1706{
1707 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001708
Scott Michel97872d32008-02-23 18:41:37 +00001709 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1710 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001711
Scott Michel97872d32008-02-23 18:41:37 +00001712 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1713 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1714 // infra "anyext 16->32" pattern.)
1715 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1716 [(set R32C:$rT, (or (anyext R16C:$rA),
1717 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001718
Scott Michel97872d32008-02-23 18:41:37 +00001719 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1720 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1721 // infra "anyext 16->32" pattern.)
1722 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1723 [(set R32C:$rT, (or (anyext R8C:$rA),
1724 i32ImmSExt10:$val))]>;
1725}
Scott Michel8b6b4202007-12-04 22:35:58 +00001726
Scott Michel97872d32008-02-23 18:41:37 +00001727defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001728
Scott Michel8b6b4202007-12-04 22:35:58 +00001729// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1730// $rT[0], slots 1-3 are zeroed.
1731//
Scott Michel438be252007-12-17 22:32:34 +00001732// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001733def ORXv4i32:
1734 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1735 "orx\t$rT, $rA, $rB", IntegerOp,
1736 []>;
1737
Scott Michel438be252007-12-17 22:32:34 +00001738// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001739
Scott Michel6baba072008-03-05 23:02:02 +00001740class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1741 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1742 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001743
Scott Michel6baba072008-03-05 23:02:02 +00001744class XORVecInst<ValueType vectype>:
1745 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1746 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1747 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001748
Scott Michel6baba072008-03-05 23:02:02 +00001749class XORRegInst<RegisterClass rclass>:
1750 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1751 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1752
1753multiclass BitwiseExclusiveOr
1754{
1755 def v16i8: XORVecInst<v16i8>;
1756 def v8i16: XORVecInst<v8i16>;
1757 def v4i32: XORVecInst<v4i32>;
1758 def v2i64: XORVecInst<v2i64>;
1759
1760 def r128: XORRegInst<GPRC>;
1761 def r64: XORRegInst<R64C>;
1762 def r32: XORRegInst<R32C>;
1763 def r16: XORRegInst<R16C>;
1764 def r8: XORRegInst<R8C>;
1765
1766 // Special forms for floating point instructions.
1767 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1768
1769 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1770 [/* no pattern */]>;
1771
1772 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1773 [/* no pattern */]>;
1774
1775 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1776 [/* no pattern, see fneg{32,64} */]>;
1777}
1778
1779defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001780
1781//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001782
Scott Michel97872d32008-02-23 18:41:37 +00001783class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1784 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1785 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001786
Scott Michel97872d32008-02-23 18:41:37 +00001787multiclass XorByteImm
1788{
1789 def v16i8:
1790 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1791 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1792
1793 def r8:
1794 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1795 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1796}
1797
1798defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001799
Scott Michel8b6b4202007-12-04 22:35:58 +00001800def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001801 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001802 "xorhi\t$rT, $rA, $val", IntegerOp,
1803 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1804 v8i16SExt10Imm:$val))]>;
1805
1806def XORHIr16:
1807 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1808 "xorhi\t$rT, $rA, $val", IntegerOp,
1809 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1810
1811def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001812 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001813 "xori\t$rT, $rA, $val", IntegerOp,
1814 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1815 v4i32SExt10Imm:$val))]>;
1816
1817def XORIr32:
1818 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1819 "xori\t$rT, $rA, $val", IntegerOp,
1820 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1821
1822// NAND:
1823def NANDv16i8:
1824 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1825 "nand\t$rT, $rA, $rB", IntegerOp,
1826 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1827 (v16i8 VECREG:$rB))))]>;
1828
1829def NANDv8i16:
1830 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1831 "nand\t$rT, $rA, $rB", IntegerOp,
1832 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1833 (v8i16 VECREG:$rB))))]>;
1834
1835def NANDv4i32:
1836 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1837 "nand\t$rT, $rA, $rB", IntegerOp,
1838 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1839 (v4i32 VECREG:$rB))))]>;
1840
1841def NANDr32:
1842 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1843 "nand\t$rT, $rA, $rB", IntegerOp,
1844 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1845
1846def NANDr16:
1847 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1848 "nand\t$rT, $rA, $rB", IntegerOp,
1849 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1850
Scott Michel438be252007-12-17 22:32:34 +00001851def NANDr8:
1852 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1853 "nand\t$rT, $rA, $rB", IntegerOp,
1854 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1855
Scott Michel8b6b4202007-12-04 22:35:58 +00001856// NOR:
1857def NORv16i8:
1858 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1859 "nor\t$rT, $rA, $rB", IntegerOp,
1860 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1861 (v16i8 VECREG:$rB))))]>;
1862
1863def NORv8i16:
1864 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1865 "nor\t$rT, $rA, $rB", IntegerOp,
1866 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1867 (v8i16 VECREG:$rB))))]>;
1868
1869def NORv4i32:
1870 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1871 "nor\t$rT, $rA, $rB", IntegerOp,
1872 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1873 (v4i32 VECREG:$rB))))]>;
1874
1875def NORr32:
1876 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1877 "nor\t$rT, $rA, $rB", IntegerOp,
1878 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1879
1880def NORr16:
1881 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1882 "nor\t$rT, $rA, $rB", IntegerOp,
1883 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1884
Scott Michel438be252007-12-17 22:32:34 +00001885def NORr8:
1886 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1887 "nor\t$rT, $rA, $rB", IntegerOp,
1888 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1889
Scott Michel8b6b4202007-12-04 22:35:58 +00001890// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001891class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1892 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1893 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001894
Scott Michel6baba072008-03-05 23:02:02 +00001895class SELBVecInst<ValueType vectype>:
1896 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1897 [(set (vectype VECREG:$rT),
1898 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1899 (and (vnot (vectype VECREG:$rC)),
1900 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001901
Scott Michel4d07fb72008-12-30 23:28:25 +00001902class SELBVecVCondInst<ValueType vectype>:
1903 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1904 [(set (vectype VECREG:$rT),
1905 (select (vectype VECREG:$rC),
1906 (vectype VECREG:$rB),
1907 (vectype VECREG:$rA)))]>;
1908
Scott Michel06eabde2008-12-27 04:51:36 +00001909class SELBVecCondInst<ValueType vectype>:
1910 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1911 [(set (vectype VECREG:$rT),
1912 (select R32C:$rC,
1913 (vectype VECREG:$rB),
1914 (vectype VECREG:$rA)))]>;
1915
Scott Michel6baba072008-03-05 23:02:02 +00001916class SELBRegInst<RegisterClass rclass>:
1917 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1918 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001919 (or (and rclass:$rB, rclass:$rC),
1920 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001921
Scott Michel06eabde2008-12-27 04:51:36 +00001922class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1923 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1924 [(set rclass:$rT,
1925 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1926
Scott Michel6baba072008-03-05 23:02:02 +00001927multiclass SelectBits
1928{
1929 def v16i8: SELBVecInst<v16i8>;
1930 def v8i16: SELBVecInst<v8i16>;
1931 def v4i32: SELBVecInst<v4i32>;
1932 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001933
Scott Michel6baba072008-03-05 23:02:02 +00001934 def r128: SELBRegInst<GPRC>;
1935 def r64: SELBRegInst<R64C>;
1936 def r32: SELBRegInst<R32C>;
1937 def r16: SELBRegInst<R16C>;
1938 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001939
1940 def v16i8_cond: SELBVecCondInst<v16i8>;
1941 def v8i16_cond: SELBVecCondInst<v8i16>;
1942 def v4i32_cond: SELBVecCondInst<v4i32>;
1943 def v2i64_cond: SELBVecCondInst<v2i64>;
1944
Scott Michel4d07fb72008-12-30 23:28:25 +00001945 def v16i8_vcond: SELBVecCondInst<v16i8>;
1946 def v8i16_vcond: SELBVecCondInst<v8i16>;
1947 def v4i32_vcond: SELBVecCondInst<v4i32>;
1948 def v2i64_vcond: SELBVecCondInst<v2i64>;
1949
1950 def v4f32_cond:
1951 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1952 [(set (v4f32 VECREG:$rT),
1953 (select (v4i32 VECREG:$rC),
1954 (v4f32 VECREG:$rB),
1955 (v4f32 VECREG:$rA)))]>;
1956
Scott Michel06eabde2008-12-27 04:51:36 +00001957 // SELBr64_cond is defined further down, look for i64 comparisons
1958 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001959 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001960 def r16_cond: SELBRegCondInst<R16C, R16C>;
1961 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001962}
Scott Michel8b6b4202007-12-04 22:35:58 +00001963
Scott Michel6baba072008-03-05 23:02:02 +00001964defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001965
Scott Michel56a125e2008-11-22 23:50:42 +00001966class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001967 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1968 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001969
Scott Michel56a125e2008-11-22 23:50:42 +00001970def : SPUselbPatVec<v16i8, SELBv16i8>;
1971def : SPUselbPatVec<v8i16, SELBv8i16>;
1972def : SPUselbPatVec<v4i32, SELBv4i32>;
1973def : SPUselbPatVec<v2i64, SELBv2i64>;
1974
1975class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1976 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1977 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1978
1979def : SPUselbPatReg<R8C, SELBr8>;
1980def : SPUselbPatReg<R16C, SELBr16>;
1981def : SPUselbPatReg<R32C, SELBr32>;
1982def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001983
Scott Michel6baba072008-03-05 23:02:02 +00001984// EQV: Equivalence (1 for each same bit, otherwise 0)
1985//
1986// Note: There are a lot of ways to match this bit operator and these patterns
1987// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001988
Scott Michel6baba072008-03-05 23:02:02 +00001989class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1990 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1991 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001992
Scott Michel6baba072008-03-05 23:02:02 +00001993class EQVVecInst<ValueType vectype>:
1994 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1995 [(set (vectype VECREG:$rT),
1996 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1997 (and (vnot (vectype VECREG:$rA)),
1998 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001999
Scott Michel6baba072008-03-05 23:02:02 +00002000class EQVRegInst<RegisterClass rclass>:
2001 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2002 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2003 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002004
Scott Michel6baba072008-03-05 23:02:02 +00002005class EQVVecPattern1<ValueType vectype>:
2006 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2007 [(set (vectype VECREG:$rT),
2008 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002009
Scott Michel6baba072008-03-05 23:02:02 +00002010class EQVRegPattern1<RegisterClass rclass>:
2011 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2012 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002013
Scott Michel6baba072008-03-05 23:02:02 +00002014class EQVVecPattern2<ValueType vectype>:
2015 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2016 [(set (vectype VECREG:$rT),
2017 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2018 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002019
Scott Michel6baba072008-03-05 23:02:02 +00002020class EQVRegPattern2<RegisterClass rclass>:
2021 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2022 [(set rclass:$rT,
2023 (or (and rclass:$rA, rclass:$rB),
2024 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002025
Scott Michel6baba072008-03-05 23:02:02 +00002026class EQVVecPattern3<ValueType vectype>:
2027 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2028 [(set (vectype VECREG:$rT),
2029 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002030
Scott Michel6baba072008-03-05 23:02:02 +00002031class EQVRegPattern3<RegisterClass rclass>:
2032 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2033 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002034
Scott Michel6baba072008-03-05 23:02:02 +00002035multiclass BitEquivalence
2036{
2037 def v16i8: EQVVecInst<v16i8>;
2038 def v8i16: EQVVecInst<v8i16>;
2039 def v4i32: EQVVecInst<v4i32>;
2040 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002041
Scott Michel6baba072008-03-05 23:02:02 +00002042 def v16i8_1: EQVVecPattern1<v16i8>;
2043 def v8i16_1: EQVVecPattern1<v8i16>;
2044 def v4i32_1: EQVVecPattern1<v4i32>;
2045 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002046
Scott Michel6baba072008-03-05 23:02:02 +00002047 def v16i8_2: EQVVecPattern2<v16i8>;
2048 def v8i16_2: EQVVecPattern2<v8i16>;
2049 def v4i32_2: EQVVecPattern2<v4i32>;
2050 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002051
Scott Michel6baba072008-03-05 23:02:02 +00002052 def v16i8_3: EQVVecPattern3<v16i8>;
2053 def v8i16_3: EQVVecPattern3<v8i16>;
2054 def v4i32_3: EQVVecPattern3<v4i32>;
2055 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002056
Scott Michel6baba072008-03-05 23:02:02 +00002057 def r128: EQVRegInst<GPRC>;
2058 def r64: EQVRegInst<R64C>;
2059 def r32: EQVRegInst<R32C>;
2060 def r16: EQVRegInst<R16C>;
2061 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002062
Scott Michel6baba072008-03-05 23:02:02 +00002063 def r128_1: EQVRegPattern1<GPRC>;
2064 def r64_1: EQVRegPattern1<R64C>;
2065 def r32_1: EQVRegPattern1<R32C>;
2066 def r16_1: EQVRegPattern1<R16C>;
2067 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002068
Scott Michel6baba072008-03-05 23:02:02 +00002069 def r128_2: EQVRegPattern2<GPRC>;
2070 def r64_2: EQVRegPattern2<R64C>;
2071 def r32_2: EQVRegPattern2<R32C>;
2072 def r16_2: EQVRegPattern2<R16C>;
2073 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002074
Scott Michel6baba072008-03-05 23:02:02 +00002075 def r128_3: EQVRegPattern3<GPRC>;
2076 def r64_3: EQVRegPattern3<R64C>;
2077 def r32_3: EQVRegPattern3<R32C>;
2078 def r16_3: EQVRegPattern3<R16C>;
2079 def r8_3: EQVRegPattern3<R8C>;
2080}
Scott Michel438be252007-12-17 22:32:34 +00002081
Scott Michel6baba072008-03-05 23:02:02 +00002082defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00002083
2084//===----------------------------------------------------------------------===//
2085// Vector shuffle...
2086//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002087// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2088// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2089// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2090// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002091//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002092
Scott Michel97872d32008-02-23 18:41:37 +00002093class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2094 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2095 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002096
Scott Michel0718cd82008-12-01 17:56:02 +00002097class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002098 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002099 [(set (resultvec VECREG:$rT),
2100 (SPUshuffle (resultvec VECREG:$rA),
2101 (resultvec VECREG:$rB),
2102 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002103
Scott Michel06eabde2008-12-27 04:51:36 +00002104class SHUFBGPRCInst:
2105 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2106 [/* no pattern */]>;
2107
Scott Michel97872d32008-02-23 18:41:37 +00002108multiclass ShuffleBytes
2109{
Scott Michel0718cd82008-12-01 17:56:02 +00002110 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2111 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2112 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2113 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2114 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2115 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2116 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2117 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002118
Scott Michel0718cd82008-12-01 17:56:02 +00002119 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2120 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2121
2122 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2123 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002124
2125 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002126}
2127
2128defm SHUFB : ShuffleBytes;
2129
Scott Michel8b6b4202007-12-04 22:35:58 +00002130//===----------------------------------------------------------------------===//
2131// Shift and rotate group:
2132//===----------------------------------------------------------------------===//
2133
Scott Michel97872d32008-02-23 18:41:37 +00002134class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2135 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2136 RotateShift, pattern>;
2137
2138class SHLHVecInst<ValueType vectype>:
2139 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2140 [(set (vectype VECREG:$rT),
2141 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002142
2143// $rB gets promoted to 32-bit register type when confronted with
2144// this llvm assembly code:
2145//
2146// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
2147// %A = shl i16 %arg1, %arg2
2148// ret i16 %A
2149// }
Scott Michel8b6b4202007-12-04 22:35:58 +00002150
Scott Michel97872d32008-02-23 18:41:37 +00002151multiclass ShiftLeftHalfword
2152{
2153 def v8i16: SHLHVecInst<v8i16>;
2154 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2155 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2156 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2157 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2158}
Scott Michel8b6b4202007-12-04 22:35:58 +00002159
Scott Michel97872d32008-02-23 18:41:37 +00002160defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002161
Scott Michel97872d32008-02-23 18:41:37 +00002162//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002163
Scott Michel97872d32008-02-23 18:41:37 +00002164class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2165 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2166 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002167
Scott Michel97872d32008-02-23 18:41:37 +00002168class SHLHIVecInst<ValueType vectype>:
2169 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2170 [(set (vectype VECREG:$rT),
2171 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002172
Scott Michel97872d32008-02-23 18:41:37 +00002173multiclass ShiftLeftHalfwordImm
2174{
2175 def v8i16: SHLHIVecInst<v8i16>;
2176 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2177 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2178}
2179
2180defm SHLHI : ShiftLeftHalfwordImm;
2181
2182def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2183 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2184
2185def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002186 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002187
Scott Michel97872d32008-02-23 18:41:37 +00002188//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002189
Scott Michel97872d32008-02-23 18:41:37 +00002190class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2191 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2192 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002193
Scott Michel97872d32008-02-23 18:41:37 +00002194multiclass ShiftLeftWord
2195{
2196 def v4i32:
2197 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2198 [(set (v4i32 VECREG:$rT),
2199 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2200 def r32:
2201 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2202 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2203}
Scott Michel8b6b4202007-12-04 22:35:58 +00002204
Scott Michel97872d32008-02-23 18:41:37 +00002205defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002206
Scott Michel97872d32008-02-23 18:41:37 +00002207//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002208
Scott Michel97872d32008-02-23 18:41:37 +00002209class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2210 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2211 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002212
Scott Michel97872d32008-02-23 18:41:37 +00002213multiclass ShiftLeftWordImm
2214{
2215 def v4i32:
2216 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2217 [(set (v4i32 VECREG:$rT),
2218 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002219
Scott Michel97872d32008-02-23 18:41:37 +00002220 def r32:
2221 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2222 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2223}
Scott Michel8b6b4202007-12-04 22:35:58 +00002224
Scott Michel97872d32008-02-23 18:41:37 +00002225defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002226
Scott Michel97872d32008-02-23 18:41:37 +00002227//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002228// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2229// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002230//
2231// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2232// of 7 bits is actually possible.
2233//
2234// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2235// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2236// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002237
Scott Michel97872d32008-02-23 18:41:37 +00002238class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2239 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2240 RotateShift, pattern>;
2241
2242class SHLQBIVecInst<ValueType vectype>:
2243 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2244 [(set (vectype VECREG:$rT),
2245 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2246
2247multiclass ShiftLeftQuadByBits
2248{
2249 def v16i8: SHLQBIVecInst<v16i8>;
2250 def v8i16: SHLQBIVecInst<v8i16>;
2251 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002252 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002253 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002254 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002255}
2256
2257defm SHLQBI : ShiftLeftQuadByBits;
2258
2259// See note above on SHLQBI. In this case, the predicate actually does then
2260// enforcement, whereas with SHLQBI, we have to "take it on faith."
2261class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2262 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2263 RotateShift, pattern>;
2264
2265class SHLQBIIVecInst<ValueType vectype>:
2266 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2267 [(set (vectype VECREG:$rT),
2268 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2269
2270multiclass ShiftLeftQuadByBitsImm
2271{
2272 def v16i8 : SHLQBIIVecInst<v16i8>;
2273 def v8i16 : SHLQBIIVecInst<v8i16>;
2274 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002275 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002276 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002277 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002278}
2279
2280defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002281
2282// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002283// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002284
Scott Michel97872d32008-02-23 18:41:37 +00002285class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002286 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002287 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002288
Scott Michel97872d32008-02-23 18:41:37 +00002289class SHLQBYVecInst<ValueType vectype>:
2290 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2291 [(set (vectype VECREG:$rT),
2292 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002293
Scott Michel97872d32008-02-23 18:41:37 +00002294multiclass ShiftLeftQuadBytes
2295{
2296 def v16i8: SHLQBYVecInst<v16i8>;
2297 def v8i16: SHLQBYVecInst<v8i16>;
2298 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002299 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002300 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002301 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002302 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2303 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2304}
Scott Michel8b6b4202007-12-04 22:35:58 +00002305
Scott Michel97872d32008-02-23 18:41:37 +00002306defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002307
Scott Michel97872d32008-02-23 18:41:37 +00002308class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2309 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2310 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002311
Scott Michel97872d32008-02-23 18:41:37 +00002312class SHLQBYIVecInst<ValueType vectype>:
2313 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2314 [(set (vectype VECREG:$rT),
2315 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002316
Scott Michel97872d32008-02-23 18:41:37 +00002317multiclass ShiftLeftQuadBytesImm
2318{
2319 def v16i8: SHLQBYIVecInst<v16i8>;
2320 def v8i16: SHLQBYIVecInst<v8i16>;
2321 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002322 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002323 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002324 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002325 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2326 [(set GPRC:$rT,
2327 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2328}
Scott Michel438be252007-12-17 22:32:34 +00002329
Scott Michel97872d32008-02-23 18:41:37 +00002330defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002331
Scott Michel97872d32008-02-23 18:41:37 +00002332//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2333// Rotate halfword:
2334//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2335class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2336 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2337 RotateShift, pattern>;
2338
2339class ROTHVecInst<ValueType vectype>:
2340 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2341 [(set (vectype VECREG:$rT),
2342 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2343
2344class ROTHRegInst<RegisterClass rclass>:
2345 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2346 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2347
2348multiclass RotateLeftHalfword
2349{
2350 def v8i16: ROTHVecInst<v8i16>;
2351 def r16: ROTHRegInst<R16C>;
2352}
2353
2354defm ROTH: RotateLeftHalfword;
2355
2356def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2357 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2358
2359//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2360// Rotate halfword, immediate:
2361//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2362class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2363 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2364 RotateShift, pattern>;
2365
2366class ROTHIVecInst<ValueType vectype>:
2367 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2368 [(set (vectype VECREG:$rT),
2369 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2370
2371multiclass RotateLeftHalfwordImm
2372{
2373 def v8i16: ROTHIVecInst<v8i16>;
2374 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2375 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2376 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2377 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2378}
2379
2380defm ROTHI: RotateLeftHalfwordImm;
2381
2382def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002383 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002384
Scott Michel97872d32008-02-23 18:41:37 +00002385//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2386// Rotate word:
2387//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002388
Scott Michel97872d32008-02-23 18:41:37 +00002389class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2390 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2391 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002392
Scott Michel97872d32008-02-23 18:41:37 +00002393class ROTVecInst<ValueType vectype>:
2394 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2395 [(set (vectype VECREG:$rT),
2396 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002397
Scott Michel97872d32008-02-23 18:41:37 +00002398class ROTRegInst<RegisterClass rclass>:
2399 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2400 [(set rclass:$rT,
2401 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002402
Scott Michel97872d32008-02-23 18:41:37 +00002403multiclass RotateLeftWord
2404{
2405 def v4i32: ROTVecInst<v4i32>;
2406 def r32: ROTRegInst<R32C>;
2407}
2408
2409defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002410
Scott Michel438be252007-12-17 22:32:34 +00002411// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2412// 32-bit register
2413def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002414 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2415 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002416
2417def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2418 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2419
2420def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2421 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2422
2423def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002424 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2425 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002426
2427def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2428 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2429
2430def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2431 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2432
Scott Michel97872d32008-02-23 18:41:37 +00002433//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2434// Rotate word, immediate
2435//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002436
Scott Michel97872d32008-02-23 18:41:37 +00002437class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2438 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2439 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002440
Scott Michel97872d32008-02-23 18:41:37 +00002441class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2442 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2443 [(set (vectype VECREG:$rT),
2444 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002445
Scott Michel97872d32008-02-23 18:41:37 +00002446class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2447 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2448 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002449
Scott Michel97872d32008-02-23 18:41:37 +00002450multiclass RotateLeftWordImm
2451{
2452 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2453 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2454 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002455
Scott Michel97872d32008-02-23 18:41:37 +00002456 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2457 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2458 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2459}
Scott Michel438be252007-12-17 22:32:34 +00002460
Scott Michel97872d32008-02-23 18:41:37 +00002461defm ROTI : RotateLeftWordImm;
2462
2463//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2464// Rotate quad by byte (count)
2465//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2466
2467class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2468 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2469 RotateShift, pattern>;
2470
2471class ROTQBYVecInst<ValueType vectype>:
2472 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2473 [(set (vectype VECREG:$rT),
2474 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2475
2476multiclass RotateQuadLeftByBytes
2477{
2478 def v16i8: ROTQBYVecInst<v16i8>;
2479 def v8i16: ROTQBYVecInst<v8i16>;
2480 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002481 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002482 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002483 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002484}
2485
2486defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002487
Scott Michel97872d32008-02-23 18:41:37 +00002488//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2489// Rotate quad by byte (count), immediate
2490//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2491
2492class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2493 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2494 RotateShift, pattern>;
2495
2496class ROTQBYIVecInst<ValueType vectype>:
2497 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2498 [(set (vectype VECREG:$rT),
2499 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2500
2501multiclass RotateQuadByBytesImm
2502{
2503 def v16i8: ROTQBYIVecInst<v16i8>;
2504 def v8i16: ROTQBYIVecInst<v8i16>;
2505 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002506 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002507 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002508 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002509}
2510
2511defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002512
Scott Michel8b6b4202007-12-04 22:35:58 +00002513// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002514class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2515 RI7Form<0b00110011100, OOL, IOL,
2516 "rotqbybi\t$rT, $rA, $shift",
2517 RotateShift, pattern>;
2518
2519class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2520 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2521 [(set (vectype VECREG:$rT),
2522 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2523
2524multiclass RotateQuadByBytesByBitshift {
2525 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2526 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2527 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2528 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2529}
2530
2531defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002532
Scott Michel97872d32008-02-23 18:41:37 +00002533//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002534// See ROTQBY note above.
2535//
2536// Assume that the user of this instruction knows to shift the rotate count
2537// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002538//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002539
Scott Michel97872d32008-02-23 18:41:37 +00002540class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2541 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2542 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002543
Scott Michel97872d32008-02-23 18:41:37 +00002544class ROTQBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002545 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002546 [/* no pattern yet */]>;
2547
2548class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002549 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002550 [/* no pattern yet */]>;
2551
2552multiclass RotateQuadByBitCount
2553{
2554 def v16i8: ROTQBIVecInst<v16i8>;
2555 def v8i16: ROTQBIVecInst<v8i16>;
2556 def v4i32: ROTQBIVecInst<v4i32>;
2557 def v2i64: ROTQBIVecInst<v2i64>;
2558
2559 def r128: ROTQBIRegInst<GPRC>;
2560 def r64: ROTQBIRegInst<R64C>;
2561}
2562
2563defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002564
Scott Michel97872d32008-02-23 18:41:37 +00002565class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2566 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2567 RotateShift, pattern>;
2568
2569class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2570 PatLeaf pred>:
2571 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2572 [/* no pattern yet */]>;
2573
2574class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2575 PatLeaf pred>:
2576 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2577 [/* no pattern yet */]>;
2578
2579multiclass RotateQuadByBitCountImm
2580{
2581 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2582 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2583 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2584 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2585
2586 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2587 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2588}
2589
2590defm ROTQBII : RotateQuadByBitCountImm;
2591
2592//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002593// ROTHM v8i16 form:
2594// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2595// so this only matches a synthetically generated/lowered code
2596// fragment.
2597// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002598//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002599
Scott Michel97872d32008-02-23 18:41:37 +00002600class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2601 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2602 RotateShift, pattern>;
2603
2604def ROTHMv8i16:
2605 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2606 [/* see patterns below - $rB must be negated */]>;
2607
2608def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002609 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2610
Scott Michel97872d32008-02-23 18:41:37 +00002611def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002612 (ROTHMv8i16 VECREG:$rA,
2613 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2614
Scott Michel97872d32008-02-23 18:41:37 +00002615def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002616 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002617 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002618
2619// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2620// Note: This instruction doesn't match a pattern because rB must be negated
2621// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002622
Scott Michel8b6b4202007-12-04 22:35:58 +00002623def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002624 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2625 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002626
2627def : Pat<(srl R16C:$rA, R32C:$rB),
2628 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2629
2630def : Pat<(srl R16C:$rA, R16C:$rB),
2631 (ROTHMr16 R16C:$rA,
2632 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2633
Scott Michel438be252007-12-17 22:32:34 +00002634def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002635 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002636 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002637
2638// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2639// that the immediate can be complemented, so that the user doesn't have to
2640// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002641
Scott Michel97872d32008-02-23 18:41:37 +00002642class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2643 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2644 RotateShift, pattern>;
2645
2646def ROTHMIv8i16:
2647 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2648 [/* no pattern */]>;
2649
2650def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2651 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2652
2653def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002654 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002655
Scott Michel97872d32008-02-23 18:41:37 +00002656def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002657 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002658
2659def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002660 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2661 [/* no pattern */]>;
2662
2663def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2664 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002665
2666def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2667 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2668
Scott Michel438be252007-12-17 22:32:34 +00002669def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2670 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2671
Scott Michel8b6b4202007-12-04 22:35:58 +00002672// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002673class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2674 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2675 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002676
Scott Michel97872d32008-02-23 18:41:37 +00002677def ROTMv4i32:
2678 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2679 [/* see patterns below - $rB must be negated */]>;
2680
2681def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002682 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2683
Scott Michel97872d32008-02-23 18:41:37 +00002684def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002685 (ROTMv4i32 VECREG:$rA,
2686 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2687
Scott Michel97872d32008-02-23 18:41:37 +00002688def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002689 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002690 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002691
2692def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002693 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2694 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002695
2696def : Pat<(srl R32C:$rA, R32C:$rB),
2697 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2698
2699def : Pat<(srl R32C:$rA, R16C:$rB),
2700 (ROTMr32 R32C:$rA,
2701 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2702
Scott Michel438be252007-12-17 22:32:34 +00002703def : Pat<(srl R32C:$rA, R8C:$rB),
2704 (ROTMr32 R32C:$rA,
2705 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2706
Scott Michel8b6b4202007-12-04 22:35:58 +00002707// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2708def ROTMIv4i32:
2709 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2710 "rotmi\t$rT, $rA, $val", RotateShift,
2711 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002712 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002713
Scott Michel97872d32008-02-23 18:41:37 +00002714def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002715 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002716
Scott Michel97872d32008-02-23 18:41:37 +00002717def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002718 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002719
2720// ROTMI r32 form: know how to complement the immediate value.
2721def ROTMIr32:
2722 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2723 "rotmi\t$rT, $rA, $val", RotateShift,
2724 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2725
2726def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2727 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2728
Scott Michel438be252007-12-17 22:32:34 +00002729def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2730 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2731
Scott Michel97872d32008-02-23 18:41:37 +00002732//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel2ef773a2009-01-06 03:36:14 +00002733// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel8b6b4202007-12-04 22:35:58 +00002734// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002735// that the user knew to negate $rB.
Scott Michel97872d32008-02-23 18:41:37 +00002736//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002737
Scott Michel97872d32008-02-23 18:41:37 +00002738class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2739 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2740 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002741
Scott Michel97872d32008-02-23 18:41:37 +00002742class ROTQMBYVecInst<ValueType vectype>:
2743 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2744 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002745
Scott Michel97872d32008-02-23 18:41:37 +00002746class ROTQMBYRegInst<RegisterClass rclass>:
2747 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00002748 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002749
Scott Michel97872d32008-02-23 18:41:37 +00002750multiclass RotateQuadBytes
2751{
2752 def v16i8: ROTQMBYVecInst<v16i8>;
2753 def v8i16: ROTQMBYVecInst<v8i16>;
2754 def v4i32: ROTQMBYVecInst<v4i32>;
2755 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002756
Scott Michel97872d32008-02-23 18:41:37 +00002757 def r128: ROTQMBYRegInst<GPRC>;
2758 def r64: ROTQMBYRegInst<R64C>;
2759}
2760
2761defm ROTQMBY : RotateQuadBytes;
2762
Scott Michel97872d32008-02-23 18:41:37 +00002763class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2764 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2765 RotateShift, pattern>;
2766
2767class ROTQMBYIVecInst<ValueType vectype>:
2768 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002769 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002770
Scott Michel2ef773a2009-01-06 03:36:14 +00002771class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2772 PatLeaf pred>:
Scott Michel97872d32008-02-23 18:41:37 +00002773 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002774 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002775
Scott Michel2ef773a2009-01-06 03:36:14 +00002776// 128-bit zero extension form:
2777class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2778 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2779 [/* no pattern */]>;
2780
Scott Michel97872d32008-02-23 18:41:37 +00002781multiclass RotateQuadBytesImm
2782{
2783 def v16i8: ROTQMBYIVecInst<v16i8>;
2784 def v8i16: ROTQMBYIVecInst<v8i16>;
2785 def v4i32: ROTQMBYIVecInst<v4i32>;
2786 def v2i64: ROTQMBYIVecInst<v2i64>;
2787
2788 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2789 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Michel2ef773a2009-01-06 03:36:14 +00002790
2791 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2792 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2793 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2794 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michel97872d32008-02-23 18:41:37 +00002795}
2796
2797defm ROTQMBYI : RotateQuadBytesImm;
2798
Scott Michel97872d32008-02-23 18:41:37 +00002799//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2800// Rotate right and mask by bit count
2801//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2802
2803class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2804 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2805 RotateShift, pattern>;
2806
2807class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002808 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2809 [/* no pattern, */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002810
2811multiclass RotateMaskQuadByBitCount
2812{
2813 def v16i8: ROTQMBYBIVecInst<v16i8>;
2814 def v8i16: ROTQMBYBIVecInst<v8i16>;
2815 def v4i32: ROTQMBYBIVecInst<v4i32>;
2816 def v2i64: ROTQMBYBIVecInst<v2i64>;
2817}
2818
2819defm ROTQMBYBI: RotateMaskQuadByBitCount;
2820
2821//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2822// Rotate quad and mask by bits
2823// Note that the rotate amount has to be negated
2824//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2825
2826class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2827 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2828 RotateShift, pattern>;
2829
2830class ROTQMBIVecInst<ValueType vectype>:
2831 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2832 [/* no pattern */]>;
2833
2834class ROTQMBIRegInst<RegisterClass rclass>:
2835 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2836 [/* no pattern */]>;
2837
2838multiclass RotateMaskQuadByBits
2839{
2840 def v16i8: ROTQMBIVecInst<v16i8>;
2841 def v8i16: ROTQMBIVecInst<v8i16>;
2842 def v4i32: ROTQMBIVecInst<v4i32>;
2843 def v2i64: ROTQMBIVecInst<v2i64>;
2844
2845 def r128: ROTQMBIRegInst<GPRC>;
2846 def r64: ROTQMBIRegInst<R64C>;
2847}
2848
2849defm ROTQMBI: RotateMaskQuadByBits;
2850
Scott Michel97872d32008-02-23 18:41:37 +00002851//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2852// Rotate quad and mask by bits, immediate
2853//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2854
2855class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2856 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2857 RotateShift, pattern>;
2858
2859class ROTQMBIIVecInst<ValueType vectype>:
2860 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002861 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002862
2863class ROTQMBIIRegInst<RegisterClass rclass>:
2864 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002865 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002866
2867multiclass RotateMaskQuadByBitsImm
2868{
2869 def v16i8: ROTQMBIIVecInst<v16i8>;
2870 def v8i16: ROTQMBIIVecInst<v8i16>;
2871 def v4i32: ROTQMBIIVecInst<v4i32>;
2872 def v2i64: ROTQMBIIVecInst<v2i64>;
2873
2874 def r128: ROTQMBIIRegInst<GPRC>;
2875 def r64: ROTQMBIIRegInst<R64C>;
2876}
2877
2878defm ROTQMBII: RotateMaskQuadByBitsImm;
2879
2880//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2881//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002882
2883def ROTMAHv8i16:
2884 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2885 "rotmah\t$rT, $rA, $rB", RotateShift,
2886 [/* see patterns below - $rB must be negated */]>;
2887
Scott Michel97872d32008-02-23 18:41:37 +00002888def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002889 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2890
Scott Michel97872d32008-02-23 18:41:37 +00002891def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002892 (ROTMAHv8i16 VECREG:$rA,
2893 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2894
Scott Michel97872d32008-02-23 18:41:37 +00002895def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002896 (ROTMAHv8i16 VECREG:$rA,
2897 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2898
Scott Michel8b6b4202007-12-04 22:35:58 +00002899def ROTMAHr16:
2900 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2901 "rotmah\t$rT, $rA, $rB", RotateShift,
2902 [/* see patterns below - $rB must be negated */]>;
2903
2904def : Pat<(sra R16C:$rA, R32C:$rB),
2905 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2906
2907def : Pat<(sra R16C:$rA, R16C:$rB),
2908 (ROTMAHr16 R16C:$rA,
2909 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2910
Scott Michel438be252007-12-17 22:32:34 +00002911def : Pat<(sra R16C:$rA, R8C:$rB),
2912 (ROTMAHr16 R16C:$rA,
2913 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2914
Scott Michel8b6b4202007-12-04 22:35:58 +00002915def ROTMAHIv8i16:
2916 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2917 "rotmahi\t$rT, $rA, $val", RotateShift,
2918 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002919 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002920
Scott Michel97872d32008-02-23 18:41:37 +00002921def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002922 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2923
Scott Michel97872d32008-02-23 18:41:37 +00002924def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002925 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2926
Scott Michel8b6b4202007-12-04 22:35:58 +00002927def ROTMAHIr16:
2928 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2929 "rotmahi\t$rT, $rA, $val", RotateShift,
2930 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2931
2932def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2933 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2934
Scott Michel438be252007-12-17 22:32:34 +00002935def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2936 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2937
Scott Michel8b6b4202007-12-04 22:35:58 +00002938def ROTMAv4i32:
2939 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2940 "rotma\t$rT, $rA, $rB", RotateShift,
2941 [/* see patterns below - $rB must be negated */]>;
2942
Scott Michel97872d32008-02-23 18:41:37 +00002943def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002944 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2945
Scott Michel97872d32008-02-23 18:41:37 +00002946def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002947 (ROTMAv4i32 (v4i32 VECREG:$rA),
2948 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2949
Scott Michel97872d32008-02-23 18:41:37 +00002950def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002951 (ROTMAv4i32 (v4i32 VECREG:$rA),
2952 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2953
Scott Michel8b6b4202007-12-04 22:35:58 +00002954def ROTMAr32:
2955 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2956 "rotma\t$rT, $rA, $rB", RotateShift,
2957 [/* see patterns below - $rB must be negated */]>;
2958
2959def : Pat<(sra R32C:$rA, R32C:$rB),
2960 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2961
2962def : Pat<(sra R32C:$rA, R16C:$rB),
2963 (ROTMAr32 R32C:$rA,
2964 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2965
Scott Michel438be252007-12-17 22:32:34 +00002966def : Pat<(sra R32C:$rA, R8C:$rB),
2967 (ROTMAr32 R32C:$rA,
2968 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2969
Scott Michel67224b22008-06-02 22:18:03 +00002970class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2971 RRForm<0b01011110000, OOL, IOL,
2972 "rotmai\t$rT, $rA, $val",
2973 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002974
Scott Michel67224b22008-06-02 22:18:03 +00002975class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2976 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2977 [(set (vectype VECREG:$rT),
2978 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002979
Scott Michel67224b22008-06-02 22:18:03 +00002980class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2981 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2982 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002983
Scott Michel67224b22008-06-02 22:18:03 +00002984multiclass RotateMaskAlgebraicImm {
2985 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2986 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2987 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2988 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2989}
Scott Michel8b6b4202007-12-04 22:35:58 +00002990
Scott Michel67224b22008-06-02 22:18:03 +00002991defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00002992
Scott Michel8b6b4202007-12-04 22:35:58 +00002993//===----------------------------------------------------------------------===//
2994// Branch and conditionals:
2995//===----------------------------------------------------------------------===//
2996
2997let isTerminator = 1, isBarrier = 1 in {
2998 // Halt If Equal (r32 preferred slot only, no vector form)
2999 def HEQr32:
3000 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3001 "heq\t$rA, $rB", BranchResolv,
3002 [/* no pattern to match */]>;
3003
3004 def HEQIr32 :
3005 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3006 "heqi\t$rA, $val", BranchResolv,
3007 [/* no pattern to match */]>;
3008
3009 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3010 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3011 def HGTr32:
3012 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3013 "hgt\t$rA, $rB", BranchResolv,
3014 [/* no pattern to match */]>;
3015
Scott Michel06eabde2008-12-27 04:51:36 +00003016 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00003017 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3018 "hgti\t$rA, $val", BranchResolv,
3019 [/* no pattern to match */]>;
3020
3021 def HLGTr32:
3022 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3023 "hlgt\t$rA, $rB", BranchResolv,
3024 [/* no pattern to match */]>;
3025
3026 def HLGTIr32:
3027 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3028 "hlgti\t$rA, $val", BranchResolv,
3029 [/* no pattern to match */]>;
3030}
3031
Scott Michel06eabde2008-12-27 04:51:36 +00003032//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3033// Comparison operators for i8, i16 and i32:
3034//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003035
Scott Michel97872d32008-02-23 18:41:37 +00003036class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3037 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3038 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003039
Scott Michel97872d32008-02-23 18:41:37 +00003040multiclass CmpEqualByte
3041{
3042 def v16i8 :
3043 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3044 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3045 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00003046
Scott Michel97872d32008-02-23 18:41:37 +00003047 def r8 :
3048 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3049 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3050}
Scott Michel8b6b4202007-12-04 22:35:58 +00003051
Scott Michel97872d32008-02-23 18:41:37 +00003052class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3053 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3054 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003055
Scott Michel97872d32008-02-23 18:41:37 +00003056multiclass CmpEqualByteImm
3057{
3058 def v16i8 :
3059 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3060 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3061 v16i8SExt8Imm:$val))]>;
3062 def r8:
3063 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3064 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3065}
Scott Michel8b6b4202007-12-04 22:35:58 +00003066
Scott Michel97872d32008-02-23 18:41:37 +00003067class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3068 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3069 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003070
Scott Michel97872d32008-02-23 18:41:37 +00003071multiclass CmpEqualHalfword
3072{
3073 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3074 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3075 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003076
Scott Michel97872d32008-02-23 18:41:37 +00003077 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3078 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3079}
Scott Michel8b6b4202007-12-04 22:35:58 +00003080
Scott Michel97872d32008-02-23 18:41:37 +00003081class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3082 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3083 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003084
Scott Michel97872d32008-02-23 18:41:37 +00003085multiclass CmpEqualHalfwordImm
3086{
3087 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3088 [(set (v8i16 VECREG:$rT),
3089 (seteq (v8i16 VECREG:$rA),
3090 (v8i16 v8i16SExt10Imm:$val)))]>;
3091 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3092 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3093}
Scott Michel8b6b4202007-12-04 22:35:58 +00003094
Scott Michel97872d32008-02-23 18:41:37 +00003095class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3096 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3097 ByteOp, pattern>;
3098
3099multiclass CmpEqualWord
3100{
3101 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3102 [(set (v4i32 VECREG:$rT),
3103 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3104
3105 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3106 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3107}
3108
3109class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3110 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3111 ByteOp, pattern>;
3112
3113multiclass CmpEqualWordImm
3114{
3115 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3116 [(set (v4i32 VECREG:$rT),
3117 (seteq (v4i32 VECREG:$rA),
3118 (v4i32 v4i32SExt16Imm:$val)))]>;
3119
3120 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3121 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3122}
3123
3124class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3125 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3126 ByteOp, pattern>;
3127
3128multiclass CmpGtrByte
3129{
3130 def v16i8 :
3131 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3132 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3133 (v8i16 VECREG:$rB)))]>;
3134
3135 def r8 :
3136 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3137 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3138}
3139
3140class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3141 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3142 ByteOp, pattern>;
3143
3144multiclass CmpGtrByteImm
3145{
3146 def v16i8 :
3147 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3148 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3149 v16i8SExt8Imm:$val))]>;
3150 def r8:
3151 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003152 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003153}
3154
3155class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3156 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3157 ByteOp, pattern>;
3158
3159multiclass CmpGtrHalfword
3160{
3161 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3162 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3163 (v8i16 VECREG:$rB)))]>;
3164
3165 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3166 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3167}
3168
3169class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3170 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3171 ByteOp, pattern>;
3172
3173multiclass CmpGtrHalfwordImm
3174{
3175 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3176 [(set (v8i16 VECREG:$rT),
3177 (setgt (v8i16 VECREG:$rA),
3178 (v8i16 v8i16SExt10Imm:$val)))]>;
3179 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3180 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3181}
3182
3183class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3184 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3185 ByteOp, pattern>;
3186
3187multiclass CmpGtrWord
3188{
3189 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3190 [(set (v4i32 VECREG:$rT),
3191 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3192
3193 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3194 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3195}
3196
3197class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3198 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3199 ByteOp, pattern>;
3200
3201multiclass CmpGtrWordImm
3202{
3203 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3204 [(set (v4i32 VECREG:$rT),
3205 (setgt (v4i32 VECREG:$rA),
3206 (v4i32 v4i32SExt16Imm:$val)))]>;
3207
3208 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3209 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003210
3211 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3212 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3213 [(set (v4i32 VECREG:$rT),
3214 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3215 (v4i32 v4i32SExt16Imm:$val)))]>;
3216
3217 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
3218 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00003219}
3220
3221class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003222 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003223 ByteOp, pattern>;
3224
3225multiclass CmpLGtrByte
3226{
3227 def v16i8 :
3228 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3229 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3230 (v8i16 VECREG:$rB)))]>;
3231
3232 def r8 :
3233 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3234 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3235}
3236
3237class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003238 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003239 ByteOp, pattern>;
3240
3241multiclass CmpLGtrByteImm
3242{
3243 def v16i8 :
3244 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3245 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3246 v16i8SExt8Imm:$val))]>;
3247 def r8:
3248 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3249 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3250}
3251
3252class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003253 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003254 ByteOp, pattern>;
3255
3256multiclass CmpLGtrHalfword
3257{
3258 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3259 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3260 (v8i16 VECREG:$rB)))]>;
3261
3262 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3263 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3264}
3265
3266class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003267 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003268 ByteOp, pattern>;
3269
3270multiclass CmpLGtrHalfwordImm
3271{
3272 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3273 [(set (v8i16 VECREG:$rT),
3274 (setugt (v8i16 VECREG:$rA),
3275 (v8i16 v8i16SExt10Imm:$val)))]>;
3276 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3277 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3278}
3279
3280class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003281 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003282 ByteOp, pattern>;
3283
3284multiclass CmpLGtrWord
3285{
3286 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3287 [(set (v4i32 VECREG:$rT),
3288 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3289
3290 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3291 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3292}
3293
3294class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003295 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003296 ByteOp, pattern>;
3297
3298multiclass CmpLGtrWordImm
3299{
3300 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3301 [(set (v4i32 VECREG:$rT),
3302 (setugt (v4i32 VECREG:$rA),
3303 (v4i32 v4i32SExt16Imm:$val)))]>;
3304
3305 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003306 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003307}
3308
3309defm CEQB : CmpEqualByte;
3310defm CEQBI : CmpEqualByteImm;
3311defm CEQH : CmpEqualHalfword;
3312defm CEQHI : CmpEqualHalfwordImm;
3313defm CEQ : CmpEqualWord;
3314defm CEQI : CmpEqualWordImm;
3315defm CGTB : CmpGtrByte;
3316defm CGTBI : CmpGtrByteImm;
3317defm CGTH : CmpGtrHalfword;
3318defm CGTHI : CmpGtrHalfwordImm;
3319defm CGT : CmpGtrWord;
3320defm CGTI : CmpGtrWordImm;
3321defm CLGTB : CmpLGtrByte;
3322defm CLGTBI : CmpLGtrByteImm;
3323defm CLGTH : CmpLGtrHalfword;
3324defm CLGTHI : CmpLGtrHalfwordImm;
3325defm CLGT : CmpLGtrWord;
3326defm CLGTI : CmpLGtrWordImm;
3327
Scott Michel53ab7792008-03-10 16:58:52 +00003328//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003329// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3330// define a pattern to generate the right code, as a binary operator
3331// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003332//
Scott Michel06eabde2008-12-27 04:51:36 +00003333// Notes:
3334// 1. This only matches the setcc set of conditionals. Special pattern
3335// matching is used for select conditionals.
3336//
3337// 2. The "DAG" versions of these classes is almost exclusively used for
3338// i64 comparisons. See the tblgen fundamentals documentation for what
3339// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3340// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003341//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003342
Scott Michel53ab7792008-03-10 16:58:52 +00003343class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3344 SPUInstr xorinst, SPUInstr cmpare>:
3345 Pat<(cond rclass:$rA, rclass:$rB),
3346 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3347
3348class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3349 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3350 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3351 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3352
Scott Michel06eabde2008-12-27 04:51:36 +00003353def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003354def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3355
Scott Michel06eabde2008-12-27 04:51:36 +00003356def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003357def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3358
3359def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3360def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003361
3362class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3363 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3364 Pat<(cond rclass:$rA, rclass:$rB),
3365 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3366 (cmpOp2 rclass:$rA, rclass:$rB))>;
3367
3368class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3369 ValueType immtype,
3370 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3371 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3372 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3373 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3374
Scott Michel53ab7792008-03-10 16:58:52 +00003375def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3376def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3377def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3378def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3379def : Pat<(setle R8C:$rA, R8C:$rB),
3380 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3381def : Pat<(setle R8C:$rA, immU8:$imm),
3382 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003383
Scott Michel53ab7792008-03-10 16:58:52 +00003384def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3385def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3386 ORr16, CGTHIr16, CEQHIr16>;
3387def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3388def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3389def : Pat<(setle R16C:$rA, R16C:$rB),
3390 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3391def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3392 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003393
Scott Michel53ab7792008-03-10 16:58:52 +00003394def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3395def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3396 ORr32, CGTIr32, CEQIr32>;
3397def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3398def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3399def : Pat<(setle R32C:$rA, R32C:$rB),
3400 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3401def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3402 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003403
Scott Michel53ab7792008-03-10 16:58:52 +00003404def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3405def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3406def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3407def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3408def : Pat<(setule R8C:$rA, R8C:$rB),
3409 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3410def : Pat<(setule R8C:$rA, immU8:$imm),
3411 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003412
Scott Michel53ab7792008-03-10 16:58:52 +00003413def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3414def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3415 ORr16, CLGTHIr16, CEQHIr16>;
3416def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3417def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3418 CLGTHIr16, CEQHIr16>;
3419def : Pat<(setule R16C:$rA, R16C:$rB),
3420 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003421def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003422 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003423
Scott Michel53ab7792008-03-10 16:58:52 +00003424def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003425def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003426 ORr32, CLGTIr32, CEQIr32>;
3427def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003428def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003429def : Pat<(setule R32C:$rA, R32C:$rB),
3430 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3431def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3432 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003433
Scott Michel53ab7792008-03-10 16:58:52 +00003434//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3435// select conditional patterns:
3436//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3437
3438class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3439 SPUInstr selinstr, SPUInstr cmpare>:
3440 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3441 rclass:$rTrue, rclass:$rFalse),
3442 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003443 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003444
3445class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3446 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3447 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003448 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003449 (selinstr rclass:$rTrue, rclass:$rFalse,
3450 (cmpare rclass:$rA, immpred:$imm))>;
3451
3452def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3453def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3454def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3455def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3456def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3457def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3458
3459def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3460def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3461def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3462def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3463def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3464def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3465
3466def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3467def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3468def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3469def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3470def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3471def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3472
3473class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3474 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3475 SPUInstr cmpOp2>:
3476 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003477 rclass:$rTrue, rclass:$rFalse),
3478 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003479 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3480 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3481
3482class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3483 ValueType inttype,
3484 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3485 SPUInstr cmpOp2>:
3486 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003487 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003488 (selinstr rclass:$rFalse, rclass:$rTrue,
3489 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3490 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3491
3492def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3493def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3494 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3495
3496def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3497def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3498 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3499
3500def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3501def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3502 SELBr32, ORr32, CGTIr32, CEQIr32>;
3503
3504def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3505def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3506 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3507
3508def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3509def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3510 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3511
3512def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3513def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3514 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003515
3516//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003517
3518let isCall = 1,
3519 // All calls clobber the non-callee-saved registers:
3520 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3521 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3522 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3523 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3524 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3525 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3526 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3527 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3528 // All of these instructions use $lr (aka $0)
3529 Uses = [R0] in {
3530 // Branch relative and set link: Used if we actually know that the target
3531 // is within [-32768, 32767] bytes of the target
3532 def BRSL:
3533 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3534 "brsl\t$$lr, $func",
3535 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3536
3537 // Branch absolute and set link: Used if we actually know that the target
3538 // is an absolute address
3539 def BRASL:
3540 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3541 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003542 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003543
3544 // Branch indirect and set link if external data. These instructions are not
3545 // actually generated, matched by an intrinsic:
3546 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3547 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3548 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3549 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3550
3551 // Branch indirect and set link. This is the "X-form" address version of a
3552 // function call
3553 def BISL:
3554 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3555}
3556
Scott Michelae5cbf52008-12-29 03:23:36 +00003557// Support calls to external symbols:
3558def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3559 (BRSL texternalsym:$func)>;
3560
3561def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3562 (BRASL texternalsym:$func)>;
3563
Scott Michel8b6b4202007-12-04 22:35:58 +00003564// Unconditional branches:
3565let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3566 def BR :
3567 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3568 "br\t$dest",
3569 [(br bb:$dest)]>;
3570
3571 // Unconditional, absolute address branch
3572 def BRA:
3573 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3574 "bra\t$dest",
3575 [/* no pattern */]>;
3576
3577 // Indirect branch
3578 def BI:
3579 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3580
Scott Michele0168c12009-01-05 01:34:35 +00003581 // Conditional branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003582 class BRNZInst<dag IOL, list<dag> pattern>:
3583 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3584 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003585
Scott Michel06eabde2008-12-27 04:51:36 +00003586 class BRNZRegInst<RegisterClass rclass>:
3587 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3588 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003589
Scott Michel06eabde2008-12-27 04:51:36 +00003590 class BRNZVecInst<ValueType vectype>:
3591 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3592 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003593
Scott Michel06eabde2008-12-27 04:51:36 +00003594 multiclass BranchNotZero {
3595 def v4i32 : BRNZVecInst<v4i32>;
3596 def r32 : BRNZRegInst<R32C>;
3597 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003598
Scott Michel06eabde2008-12-27 04:51:36 +00003599 defm BRNZ : BranchNotZero;
3600
3601 class BRZInst<dag IOL, list<dag> pattern>:
3602 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3603 BranchResolv, pattern>;
3604
3605 class BRZRegInst<RegisterClass rclass>:
3606 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3607
3608 class BRZVecInst<ValueType vectype>:
3609 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3610
3611 multiclass BranchZero {
3612 def v4i32: BRZVecInst<v4i32>;
3613 def r32: BRZRegInst<R32C>;
3614 }
3615
3616 defm BRZ: BranchZero;
3617
3618 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3619 // be useful:
3620 /*
3621 class BINZInst<dag IOL, list<dag> pattern>:
3622 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3623
3624 class BINZRegInst<RegisterClass rclass>:
3625 BINZInst<(ins rclass:$rA, brtarget:$dest),
3626 [(brcond rclass:$rA, R32C:$dest)]>;
3627
3628 class BINZVecInst<ValueType vectype>:
3629 BINZInst<(ins VECREG:$rA, R32C:$dest),
3630 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3631
3632 multiclass BranchNotZeroIndirect {
3633 def v4i32: BINZVecInst<v4i32>;
3634 def r32: BINZRegInst<R32C>;
3635 }
3636
3637 defm BINZ: BranchNotZeroIndirect;
3638
3639 class BIZInst<dag IOL, list<dag> pattern>:
3640 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3641
3642 class BIZRegInst<RegisterClass rclass>:
3643 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3644
3645 class BIZVecInst<ValueType vectype>:
3646 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3647
3648 multiclass BranchZeroIndirect {
3649 def v4i32: BIZVecInst<v4i32>;
3650 def r32: BIZRegInst<R32C>;
3651 }
3652
3653 defm BIZ: BranchZeroIndirect;
3654 */
3655
3656 class BRHNZInst<dag IOL, list<dag> pattern>:
3657 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3658 pattern>;
3659
3660 class BRHNZRegInst<RegisterClass rclass>:
3661 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3662 [(brcond rclass:$rCond, bb:$dest)]>;
3663
3664 class BRHNZVecInst<ValueType vectype>:
3665 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3666
3667 multiclass BranchNotZeroHalfword {
3668 def v8i16: BRHNZVecInst<v8i16>;
3669 def r16: BRHNZRegInst<R16C>;
3670 }
3671
3672 defm BRHNZ: BranchNotZeroHalfword;
3673
3674 class BRHZInst<dag IOL, list<dag> pattern>:
3675 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3676 pattern>;
3677
3678 class BRHZRegInst<RegisterClass rclass>:
3679 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3680
3681 class BRHZVecInst<ValueType vectype>:
3682 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3683
3684 multiclass BranchZeroHalfword {
3685 def v8i16: BRHZVecInst<v8i16>;
3686 def r16: BRHZRegInst<R16C>;
3687 }
3688
3689 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003690}
3691
Scott Michel394e26d2008-01-17 20:38:41 +00003692//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003693// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003694//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003695
Scott Michel06eabde2008-12-27 04:51:36 +00003696def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3697 (BRHZr16 R16C:$rA, bb:$dest)>;
3698def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3699 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003700
Scott Michel06eabde2008-12-27 04:51:36 +00003701def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3702 (BRZr32 R32C:$rA, bb:$dest)>;
3703def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3704 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003705
Scott Michel97872d32008-02-23 18:41:37 +00003706multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3707{
3708 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3709 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003710
Scott Michel97872d32008-02-23 18:41:37 +00003711 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3712 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3713
3714 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3715 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3716
3717 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3718 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3719}
3720
Scott Michele0168c12009-01-05 01:34:35 +00003721defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3722defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003723
3724multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3725{
3726 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3727 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3728
3729 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3730 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3731
3732 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3733 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3734
3735 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3736 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3737}
3738
Scott Michel06eabde2008-12-27 04:51:36 +00003739defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3740defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003741
3742multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3743 SPUInstr orinst32, SPUInstr brinst32>
3744{
3745 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3746 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3747 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3748 bb:$dest)>;
3749
3750 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3751 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3752 (CEQHr16 R16C:$rA, R16:$rB)),
3753 bb:$dest)>;
3754
3755 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3756 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3757 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3758 bb:$dest)>;
3759
3760 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3761 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3762 (CEQr32 R32C:$rA, R32C:$rB)),
3763 bb:$dest)>;
3764}
3765
Scott Michel06eabde2008-12-27 04:51:36 +00003766defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3767defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003768
3769multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3770{
3771 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3772 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3773
3774 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3775 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3776
3777 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3778 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3779
3780 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3781 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3782}
3783
Scott Michel06eabde2008-12-27 04:51:36 +00003784defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3785defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003786
3787multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3788 SPUInstr orinst32, SPUInstr brinst32>
3789{
3790 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3791 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3792 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3793 bb:$dest)>;
3794
3795 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3796 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3797 (CEQHr16 R16C:$rA, R16:$rB)),
3798 bb:$dest)>;
3799
3800 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3801 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3802 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3803 bb:$dest)>;
3804
3805 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3806 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3807 (CEQr32 R32C:$rA, R32C:$rB)),
3808 bb:$dest)>;
3809}
3810
Scott Michel06eabde2008-12-27 04:51:36 +00003811defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3812defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003813
Scott Michel8b6b4202007-12-04 22:35:58 +00003814let isTerminator = 1, isBarrier = 1 in {
3815 let isReturn = 1 in {
3816 def RET:
3817 RETForm<"bi\t$$lr", [(retflag)]>;
3818 }
3819}
3820
3821//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003822// Single precision floating point instructions
3823//===----------------------------------------------------------------------===//
3824
Scott Michel61895fe2008-12-10 00:15:19 +00003825class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3826 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003827 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003828
Scott Michel61895fe2008-12-10 00:15:19 +00003829class FAVecInst<ValueType vectype>:
3830 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3831 [(set (vectype VECREG:$rT),
Scott Michel4d07fb72008-12-30 23:28:25 +00003832 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003833
Scott Michel61895fe2008-12-10 00:15:19 +00003834multiclass SFPAdd
3835{
3836 def v4f32: FAVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003837 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3838 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003839}
Scott Michel8b6b4202007-12-04 22:35:58 +00003840
Scott Michel61895fe2008-12-10 00:15:19 +00003841defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003842
Scott Michel61895fe2008-12-10 00:15:19 +00003843class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3844 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003845 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003846
Scott Michel61895fe2008-12-10 00:15:19 +00003847class FSVecInst<ValueType vectype>:
3848 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00003849 [(set (vectype VECREG:$rT),
3850 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003851
3852multiclass SFPSub
3853{
3854 def v4f32: FSVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003855 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3856 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003857}
3858
3859defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003860
3861// Floating point reciprocal estimate
Scott Michel8b6b4202007-12-04 22:35:58 +00003862
Scott Michel4d07fb72008-12-30 23:28:25 +00003863class FRESTInst<dag OOL, dag IOL>:
3864 RRForm_1<0b00110111000, OOL, IOL,
3865 "frest\t$rT, $rA", SPrecFP,
3866 [/* no pattern */]>;
3867
3868def FRESTv4f32 :
3869 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3870
3871def FRESTf32 :
3872 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003873
3874// Floating point interpolate (used in conjunction with reciprocal estimate)
3875def FIv4f32 :
3876 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3877 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003878 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003879
3880def FIf32 :
3881 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3882 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003883 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003884
Scott Michel33d73eb2008-11-21 02:56:16 +00003885//--------------------------------------------------------------------------
3886// Basic single precision floating point comparisons:
3887//
3888// Note: There is no support on SPU for single precision NaN. Consequently,
3889// ordered and unordered comparisons are the same.
3890//--------------------------------------------------------------------------
3891
Scott Michel8b6b4202007-12-04 22:35:58 +00003892def FCEQf32 :
3893 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3894 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003895 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3896
3897def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3898 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003899
3900def FCMEQf32 :
3901 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3902 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003903 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3904
3905def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3906 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003907
3908def FCGTf32 :
3909 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3910 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003911 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3912
3913def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3914 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003915
3916def FCMGTf32 :
3917 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3918 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003919 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3920
3921def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3922 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3923
3924//--------------------------------------------------------------------------
3925// Single precision floating point comparisons and SETCC equivalents:
3926//--------------------------------------------------------------------------
3927
3928def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3929def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3930
3931def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3932def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3933
3934def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3935def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3936
3937def : Pat<(setule R32FP:$rA, R32FP:$rB),
3938 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3939def : Pat<(setole R32FP:$rA, R32FP:$rB),
3940 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003941
3942// FP Status and Control Register Write
3943// Why isn't rT a don't care in the ISA?
3944// Should we create a special RRForm_3 for this guy and zero out the rT?
3945def FSCRWf32 :
3946 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3947 "fscrwr\t$rA", SPrecFP,
3948 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3949
3950// FP Status and Control Register Read
3951def FSCRRf32 :
3952 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3953 "fscrrd\t$rT", SPrecFP,
3954 [/* This instruction requires an intrinsic */]>;
3955
3956// llvm instruction space
3957// How do these map onto cell instructions?
3958// fdiv rA rB
3959// frest rC rB # c = 1/b (both lines)
3960// fi rC rB rC
3961// fm rD rA rC # d = a * 1/b
3962// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3963// fma rB rB rC rD # b = b * c + d
3964// = -(d *b -a) * c + d
3965// = a * c - c ( a *b *c - a)
3966
3967// fcopysign (???)
3968
3969// Library calls:
3970// These llvm instructions will actually map to library calls.
3971// All that's needed, then, is to check that the appropriate library is
3972// imported and do a brsl to the proper function name.
3973// frem # fmod(x, y): x - (x/y) * y
3974// (Note: fmod(double, double), fmodf(float,float)
3975// fsqrt?
3976// fsin?
3977// fcos?
3978// Unimplemented SPU instruction space
3979// floating reciprocal absolute square root estimate (frsqest)
3980
3981// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00003982// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00003983// status and control register read
3984
3985//--------------------------------------
3986// Floating point multiply instructions
3987//--------------------------------------
3988
3989def FMv4f32:
3990 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3991 "fm\t$rT, $rA, $rB", SPrecFP,
3992 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3993 (v4f32 VECREG:$rB)))]>;
3994
3995def FMf32 :
3996 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3997 "fm\t$rT, $rA, $rB", SPrecFP,
3998 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3999
4000// Floating point multiply and add
4001// e.g. d = c + (a * b)
4002def FMAv4f32:
4003 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4004 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4005 [(set (v4f32 VECREG:$rT),
4006 (fadd (v4f32 VECREG:$rC),
4007 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
4008
4009def FMAf32:
4010 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4011 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4012 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4013
4014// FP multiply and subtract
4015// Subtracts value in rC from product
4016// res = a * b - c
4017def FMSv4f32 :
4018 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4019 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4020 [(set (v4f32 VECREG:$rT),
4021 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
4022 (v4f32 VECREG:$rC)))]>;
4023
4024def FMSf32 :
4025 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4026 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4027 [(set R32FP:$rT,
4028 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
4029
4030// Floating Negative Mulitply and Subtract
4031// Subtracts product from value in rC
4032// res = fneg(fms a b c)
4033// = - (a * b - c)
4034// = c - a * b
4035// NOTE: subtraction order
4036// fsub a b = a - b
Scott Michel06eabde2008-12-27 04:51:36 +00004037// fs a b = b - a?
Scott Michel8b6b4202007-12-04 22:35:58 +00004038def FNMSf32 :
4039 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4040 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4041 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4042
4043def FNMSv4f32 :
4044 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4045 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004046 [(set (v4f32 VECREG:$rT),
4047 (fsub (v4f32 VECREG:$rC),
4048 (fmul (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004049 (v4f32 VECREG:$rB))))]>;
4050
4051//--------------------------------------
4052// Floating Point Conversions
4053// Signed conversions:
4054def CSiFv4f32:
4055 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4056 "csflt\t$rT, $rA, 0", SPrecFP,
4057 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4058
Scott Michel06eabde2008-12-27 04:51:36 +00004059// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00004060def CSiFf32 :
4061 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4062 "csflt\t$rT, $rA, 0", SPrecFP,
4063 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4064
4065// Convert unsigned into to float
4066def CUiFv4f32 :
4067 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4068 "cuflt\t$rT, $rA, 0", SPrecFP,
4069 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4070
4071def CUiFf32 :
4072 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4073 "cuflt\t$rT, $rA, 0", SPrecFP,
4074 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4075
Scott Michel06eabde2008-12-27 04:51:36 +00004076// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004077// Assume that scale = 0
4078
4079def CFUiv4f32 :
4080 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4081 "cfltu\t$rT, $rA, 0", SPrecFP,
4082 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4083
4084def CFUif32 :
4085 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4086 "cfltu\t$rT, $rA, 0", SPrecFP,
4087 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4088
Scott Michel06eabde2008-12-27 04:51:36 +00004089// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004090// Assume that scale = 0
4091
4092def CFSiv4f32 :
4093 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4094 "cflts\t$rT, $rA, 0", SPrecFP,
4095 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4096
4097def CFSif32 :
4098 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4099 "cflts\t$rT, $rA, 0", SPrecFP,
4100 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4101
4102//===----------------------------------------------------------------------==//
4103// Single<->Double precision conversions
4104//===----------------------------------------------------------------------==//
4105
4106// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4107// v4f32, output is v2f64--which goes in the name?)
4108
4109// Floating point extend single to double
4110// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4111// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4112// are ignored).
4113def FESDvec :
4114 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4115 "fesd\t$rT, $rA", SPrecFP,
4116 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4117
4118def FESDf32 :
4119 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4120 "fesd\t$rT, $rA", SPrecFP,
4121 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4122
4123// Floating point round double to single
4124//def FRDSvec :
4125// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4126// "frds\t$rT, $rA,", SPrecFP,
4127// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4128
4129def FRDSf64 :
4130 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4131 "frds\t$rT, $rA", SPrecFP,
4132 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4133
4134//ToDo include anyextend?
4135
4136//===----------------------------------------------------------------------==//
4137// Double precision floating point instructions
4138//===----------------------------------------------------------------------==//
4139def FAf64 :
4140 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4141 "dfa\t$rT, $rA, $rB", DPrecFP,
4142 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4143
4144def FAv2f64 :
4145 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4146 "dfa\t$rT, $rA, $rB", DPrecFP,
4147 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4148
4149def FSf64 :
4150 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4151 "dfs\t$rT, $rA, $rB", DPrecFP,
4152 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4153
4154def FSv2f64 :
4155 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4156 "dfs\t$rT, $rA, $rB", DPrecFP,
4157 [(set (v2f64 VECREG:$rT),
4158 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4159
4160def FMf64 :
4161 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4162 "dfm\t$rT, $rA, $rB", DPrecFP,
4163 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4164
4165def FMv2f64:
4166 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4167 "dfm\t$rT, $rA, $rB", DPrecFP,
4168 [(set (v2f64 VECREG:$rT),
4169 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4170
4171def FMAf64:
4172 RRForm<0b00111010110, (outs R64FP:$rT),
4173 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4174 "dfma\t$rT, $rA, $rB", DPrecFP,
4175 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4176 RegConstraint<"$rC = $rT">,
4177 NoEncode<"$rC">;
4178
4179def FMAv2f64:
4180 RRForm<0b00111010110, (outs VECREG:$rT),
4181 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4182 "dfma\t$rT, $rA, $rB", DPrecFP,
4183 [(set (v2f64 VECREG:$rT),
4184 (fadd (v2f64 VECREG:$rC),
4185 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4186 RegConstraint<"$rC = $rT">,
4187 NoEncode<"$rC">;
4188
4189def FMSf64 :
4190 RRForm<0b10111010110, (outs R64FP:$rT),
4191 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4192 "dfms\t$rT, $rA, $rB", DPrecFP,
4193 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4194 RegConstraint<"$rC = $rT">,
4195 NoEncode<"$rC">;
4196
4197def FMSv2f64 :
4198 RRForm<0b10111010110, (outs VECREG:$rT),
4199 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4200 "dfms\t$rT, $rA, $rB", DPrecFP,
4201 [(set (v2f64 VECREG:$rT),
4202 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4203 (v2f64 VECREG:$rC)))]>;
4204
4205// FNMS: - (a * b - c)
4206// - (a * b) + c => c - (a * b)
4207def FNMSf64 :
4208 RRForm<0b01111010110, (outs R64FP:$rT),
4209 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4210 "dfnms\t$rT, $rA, $rB", DPrecFP,
4211 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4212 RegConstraint<"$rC = $rT">,
4213 NoEncode<"$rC">;
4214
4215def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4216 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4217
4218def FNMSv2f64 :
4219 RRForm<0b01111010110, (outs VECREG:$rT),
4220 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4221 "dfnms\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004222 [(set (v2f64 VECREG:$rT),
4223 (fsub (v2f64 VECREG:$rC),
4224 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004225 (v2f64 VECREG:$rB))))]>,
4226 RegConstraint<"$rC = $rT">,
4227 NoEncode<"$rC">;
4228
4229def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4230 (v2f64 VECREG:$rC))),
4231 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4232
4233// - (a * b + c)
4234// - (a * b) - c
4235def FNMAf64 :
4236 RRForm<0b11111010110, (outs R64FP:$rT),
4237 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4238 "dfnma\t$rT, $rA, $rB", DPrecFP,
4239 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4240 RegConstraint<"$rC = $rT">,
4241 NoEncode<"$rC">;
4242
4243def FNMAv2f64 :
4244 RRForm<0b11111010110, (outs VECREG:$rT),
4245 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4246 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004247 [(set (v2f64 VECREG:$rT),
4248 (fneg (fadd (v2f64 VECREG:$rC),
4249 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004250 (v2f64 VECREG:$rB)))))]>,
4251 RegConstraint<"$rC = $rT">,
4252 NoEncode<"$rC">;
4253
4254//===----------------------------------------------------------------------==//
4255// Floating point negation and absolute value
4256//===----------------------------------------------------------------------==//
4257
4258def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00004259 (XORfnegvec (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004260 (v4f32 (ILHUv4i32 0x8000)))>;
4261
4262def : Pat<(fneg R32FP:$rA),
4263 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4264
4265def : Pat<(fneg (v2f64 VECREG:$rA)),
4266 (XORfnegvec (v2f64 VECREG:$rA),
4267 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4268
4269def : Pat<(fneg R64FP:$rA),
4270 (XORfneg64 R64FP:$rA,
4271 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4272
4273// Floating point absolute value
4274
4275def : Pat<(fabs R32FP:$rA),
4276 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4277
4278def : Pat<(fabs (v4f32 VECREG:$rA)),
4279 (ANDfabsvec (v4f32 VECREG:$rA),
4280 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4281
4282def : Pat<(fabs R64FP:$rA),
4283 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4284
4285def : Pat<(fabs (v2f64 VECREG:$rA)),
4286 (ANDfabsvec (v2f64 VECREG:$rA),
4287 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4288
4289//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004290// Hint for branch instructions:
4291//===----------------------------------------------------------------------===//
4292
4293/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4294
4295//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004296// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4297// in the odd pipeline)
4298//===----------------------------------------------------------------------===//
4299
Scott Michel97872d32008-02-23 18:41:37 +00004300def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004301 let Pattern = [];
4302
4303 let Inst{0-10} = 0b10000000010;
4304 let Inst{11-17} = 0;
4305 let Inst{18-24} = 0;
4306 let Inst{25-31} = 0;
4307}
4308
Scott Michel97872d32008-02-23 18:41:37 +00004309def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004310 let Pattern = [];
4311
4312 let Inst{0-10} = 0b10000000000;
4313 let Inst{11-17} = 0;
4314 let Inst{18-24} = 0;
4315 let Inst{25-31} = 0;
4316}
4317
4318//===----------------------------------------------------------------------===//
4319// Bit conversions (type conversions between vector/packed types)
4320// NOTE: Promotions are handled using the XS* instructions. Truncation
4321// is not handled.
4322//===----------------------------------------------------------------------===//
4323def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4324def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4325def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4326def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4327def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4328
4329def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4330def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4331def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4332def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4333def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4334
4335def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4336def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4337def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4338def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4339def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4340
4341def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4342def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4343def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4344def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4345def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4346
4347def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4348def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4349def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4350def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4351def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4352
4353def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4354def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4355def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4356def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4357def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4358
4359def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00004360def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004361
4362//===----------------------------------------------------------------------===//
4363// Instruction patterns:
4364//===----------------------------------------------------------------------===//
4365
4366// General 32-bit constants:
4367def : Pat<(i32 imm:$imm),
4368 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4369
4370// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004371def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004372 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4373
4374// General constant 32-bit vectors
4375def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004376 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4377 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004378
Scott Michel438be252007-12-17 22:32:34 +00004379// 8-bit constants
4380def : Pat<(i8 imm:$imm),
4381 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004382
4383//===----------------------------------------------------------------------===//
4384// Call instruction patterns:
4385//===----------------------------------------------------------------------===//
4386// Return void
4387def : Pat<(ret),
4388 (RET)>;
4389
4390//===----------------------------------------------------------------------===//
4391// Zero/Any/Sign extensions
4392//===----------------------------------------------------------------------===//
4393
Scott Michel8b6b4202007-12-04 22:35:58 +00004394// sext 8->32: Sign extend bytes to words
4395def : Pat<(sext_inreg R32C:$rSrc, i8),
4396 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4397
Scott Michel438be252007-12-17 22:32:34 +00004398def : Pat<(i32 (sext R8C:$rSrc)),
4399 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4400
Scott Michel2ef773a2009-01-06 03:36:14 +00004401// sext 8->64: Sign extend bytes to double word
4402def : Pat<(sext_inreg R64C:$rSrc, i8),
4403 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4404
4405def : Pat<(i64 (sext R8C:$rSrc)),
4406 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4407
Scott Michel438be252007-12-17 22:32:34 +00004408// zext 8->16: Zero extend bytes to halfwords
4409def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004410 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004411
Scott Michel438be252007-12-17 22:32:34 +00004412// zext 8->32: Zero extend bytes to words
4413def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004414 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004415
Scott Michel2ef773a2009-01-06 03:36:14 +00004416// zext 8->64: Zero extend bytes to double words
4417def : Pat<(i64 (zext R8C:$rSrc)),
4418 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4419 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4420 0x4),
4421 (ILv4i32 0x0),
4422 (FSMBIv4i32 0x0f0f)))>;
4423
4424// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004425def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004426 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004427
Scott Michel2ef773a2009-01-06 03:36:14 +00004428// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004429def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004430 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004431
Scott Michel2ef773a2009-01-06 03:36:14 +00004432// sext 16->64: Sign extend halfword to double word
4433def : Pat<(sext_inreg R64C:$rSrc, i16),
4434 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4435
4436def : Pat<(sext R16C:$rSrc),
4437 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4438
Scott Michel97872d32008-02-23 18:41:37 +00004439// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004440def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004441 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004442
4443def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004444 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004445
4446def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004447 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004448
4449def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004450 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004451
4452// anyext 16->32: Extend 16->32 bits, irrespective of sign
4453def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004454 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004455
4456//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004457// Truncates:
4458// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4459// above are custom lowered.
4460//===----------------------------------------------------------------------===//
4461
4462def : Pat<(i8 (trunc GPRC:$src)),
4463 (ORi8_v16i8
4464 (SHUFBgprc GPRC:$src, GPRC:$src,
4465 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4466
4467def : Pat<(i8 (trunc R64C:$src)),
4468 (ORi8_v16i8
4469 (SHUFBv2i64_m32
4470 (ORv2i64_i64 R64C:$src),
4471 (ORv2i64_i64 R64C:$src),
4472 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4473
4474def : Pat<(i8 (trunc R32C:$src)),
4475 (ORi8_v16i8
4476 (SHUFBv4i32_m32
4477 (ORv4i32_i32 R32C:$src),
4478 (ORv4i32_i32 R32C:$src),
4479 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4480
4481def : Pat<(i8 (trunc R16C:$src)),
4482 (ORi8_v16i8
4483 (SHUFBv4i32_m32
4484 (ORv8i16_i16 R16C:$src),
4485 (ORv8i16_i16 R16C:$src),
4486 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4487
4488def : Pat<(i16 (trunc GPRC:$src)),
4489 (ORi16_v8i16
4490 (SHUFBgprc GPRC:$src, GPRC:$src,
4491 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4492
4493def : Pat<(i16 (trunc R64C:$src)),
4494 (ORi16_v8i16
4495 (SHUFBv2i64_m32
4496 (ORv2i64_i64 R64C:$src),
4497 (ORv2i64_i64 R64C:$src),
4498 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4499
4500def : Pat<(i16 (trunc R32C:$src)),
4501 (ORi16_v8i16
4502 (SHUFBv4i32_m32
4503 (ORv4i32_i32 R32C:$src),
4504 (ORv4i32_i32 R32C:$src),
4505 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4506
4507def : Pat<(i32 (trunc GPRC:$src)),
4508 (ORi32_v4i32
4509 (SHUFBgprc GPRC:$src, GPRC:$src,
4510 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4511
4512def : Pat<(i32 (trunc R64C:$src)),
4513 (ORi32_v4i32
4514 (SHUFBv2i64_m32
4515 (ORv2i64_i64 R64C:$src),
4516 (ORv2i64_i64 R64C:$src),
4517 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4518
4519//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004520// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004521// low parts in order to load them into a register.
4522//===----------------------------------------------------------------------===//
4523
Scott Michelf9f42e62008-01-29 02:16:57 +00004524def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4525def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4526def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4527def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4528
4529def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4530 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004531 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004532
Scott Michelf9f42e62008-01-29 02:16:57 +00004533def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4534 (SPUlo texternalsym:$in, 0)),
4535 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4536
4537def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4538 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004539 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004540
Scott Michelf9f42e62008-01-29 02:16:57 +00004541def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4542 (SPUlo tconstpool:$in, 0)),
4543 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4544
4545def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4546 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4547
4548def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4549 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4550
4551def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4552 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4553
4554def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4555 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004556
Scott Michel8b6b4202007-12-04 22:35:58 +00004557// Instrinsics:
4558include "CellSDKIntrinsics.td"
Scott Michel4d07fb72008-12-30 23:28:25 +00004559// Various math operator instruction sequences
4560include "SPUMathInstr.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004561// 64-bit "instructions"/support
4562include "SPU64InstrInfo.td"
Scott Michel2ef773a2009-01-06 03:36:14 +00004563// 128-bit "instructions"/support
4564include "SPU128InstrInfo.td"