blob: 1ceaf1abda86b5c4b4dbb86ea3c61578165066e7 [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 Michel06eabde2008-12-27 04:51:36 +00001143class XSBHInRegInst<RegisterClass rclass>:
Scott Michel67224b22008-06-02 22:18:03 +00001144 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
1145 [(set rclass:$rDst, (sext_inreg rclass:$rSrc, i8))]>;
1146
1147multiclass ExtendByteHalfword {
1148 def v16i8: XSBHVecInst<v8i16>;
Scott Michel06eabde2008-12-27 04:51:36 +00001149 def r16: XSBHInRegInst<R16C>;
1150 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1151 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001152
1153 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1154 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1155 // pattern below). Intentionally doesn't match a pattern because we want the
1156 // sext 8->32 pattern to do the work for us, namely because we need the extra
1157 // XSHWr32.
Scott Michel06eabde2008-12-27 04:51:36 +00001158 def r32: XSBHInRegInst<R32C>;
Scott Michel67224b22008-06-02 22:18:03 +00001159}
1160
1161defm XSBH : ExtendByteHalfword;
1162
Scott Michel8b6b4202007-12-04 22:35:58 +00001163// Sign extend halfwords to words:
1164def XSHWvec:
1165 RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
1166 "xshw\t$rDest, $rSrc", IntegerOp,
1167 [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
1168
1169def XSHWr32:
1170 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
1171 "xshw\t$rDst, $rSrc", IntegerOp,
1172 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
1173
1174def XSHWr16:
1175 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
1176 "xshw\t$rDst, $rSrc", IntegerOp,
1177 [(set R32C:$rDst, (sext R16C:$rSrc))]>;
1178
Scott Michele0168c12009-01-05 01:34:35 +00001179// Sign-extend words to doublewords (32->64 bits)
Scott Michel8b6b4202007-12-04 22:35:58 +00001180
Scott Michele0168c12009-01-05 01:34:35 +00001181class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
1182 RRForm_1<0b01100101010, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +00001183 "xswd\t$rDst, $rSrc", IntegerOp,
Scott Michele0168c12009-01-05 01:34:35 +00001184 pattern>;
1185
1186class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1187 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1188 [(set (out_vectype VECREG:$rDst),
1189 (sext (out_vectype VECREG:$rSrc)))]>;
1190
1191class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1192 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1193 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1194
1195multiclass ExtendWordToDoubleWord {
1196 def v2i64: XSWDVecInst<v4i32, v2i64>;
1197 def r64: XSWDRegInst<R32C, R64C>;
1198
1199 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1200 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1201}
Scott Michel8b6b4202007-12-04 22:35:58 +00001202
Scott Michele0168c12009-01-05 01:34:35 +00001203defm XSWD : ExtendWordToDoubleWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001204
1205// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001206
Scott Michel97872d32008-02-23 18:41:37 +00001207class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1208 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1209 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001210
Scott Michel97872d32008-02-23 18:41:37 +00001211class ANDVecInst<ValueType vectype>:
1212 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1213 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1214 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001215
Scott Michel6baba072008-03-05 23:02:02 +00001216class ANDRegInst<RegisterClass rclass>:
1217 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1218 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1219
Scott Michel97872d32008-02-23 18:41:37 +00001220multiclass BitwiseAnd
1221{
1222 def v16i8: ANDVecInst<v16i8>;
1223 def v8i16: ANDVecInst<v8i16>;
1224 def v4i32: ANDVecInst<v4i32>;
1225 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001226
Scott Michel6baba072008-03-05 23:02:02 +00001227 def r128: ANDRegInst<GPRC>;
1228 def r64: ANDRegInst<R64C>;
1229 def r32: ANDRegInst<R32C>;
1230 def r16: ANDRegInst<R16C>;
1231 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001232
Scott Michel97872d32008-02-23 18:41:37 +00001233 //===---------------------------------------------
1234 // Special instructions to perform the fabs instruction
1235 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1236 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001237
Scott Michel97872d32008-02-23 18:41:37 +00001238 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1239 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001240
Scott Michel97872d32008-02-23 18:41:37 +00001241 // Could use v4i32, but won't for clarity
1242 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1243 [/* Intentionally does not match a pattern */]>;
1244
1245 //===---------------------------------------------
1246
1247 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1248 // quantities -- see 16->32 zext pattern.
1249 //
1250 // This pattern is somewhat artificial, since it might match some
1251 // compiler generated pattern but it is unlikely to do so.
1252
1253 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1254 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1255}
1256
1257defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001258
1259// N.B.: vnot_conv is one of those special target selection pattern fragments,
1260// in which we expect there to be a bit_convert on the constant. Bear in mind
1261// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1262// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001263
Scott Michel97872d32008-02-23 18:41:37 +00001264class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1265 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1266 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001267
Scott Michel97872d32008-02-23 18:41:37 +00001268class ANDCVecInst<ValueType vectype>:
1269 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1270 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1271 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001272
Scott Michel97872d32008-02-23 18:41:37 +00001273class ANDCRegInst<RegisterClass rclass>:
1274 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1275 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001276
Scott Michel97872d32008-02-23 18:41:37 +00001277multiclass AndComplement
1278{
1279 def v16i8: ANDCVecInst<v16i8>;
1280 def v8i16: ANDCVecInst<v8i16>;
1281 def v4i32: ANDCVecInst<v4i32>;
1282 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001283
Scott Michel97872d32008-02-23 18:41:37 +00001284 def r128: ANDCRegInst<GPRC>;
1285 def r64: ANDCRegInst<R64C>;
1286 def r32: ANDCRegInst<R32C>;
1287 def r16: ANDCRegInst<R16C>;
1288 def r8: ANDCRegInst<R8C>;
1289}
Scott Michel438be252007-12-17 22:32:34 +00001290
Scott Michel97872d32008-02-23 18:41:37 +00001291defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001292
Scott Michel97872d32008-02-23 18:41:37 +00001293class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1294 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001295 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001296
Scott Michel97872d32008-02-23 18:41:37 +00001297multiclass AndByteImm
1298{
1299 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1300 [(set (v16i8 VECREG:$rT),
1301 (and (v16i8 VECREG:$rA),
1302 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001303
Scott Michel97872d32008-02-23 18:41:37 +00001304 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1305 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1306}
Scott Michel438be252007-12-17 22:32:34 +00001307
Scott Michel97872d32008-02-23 18:41:37 +00001308defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001309
Scott Michel97872d32008-02-23 18:41:37 +00001310class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1311 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001312 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001313
Scott Michel97872d32008-02-23 18:41:37 +00001314multiclass AndHalfwordImm
1315{
1316 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1317 [(set (v8i16 VECREG:$rT),
1318 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001319
Scott Michel97872d32008-02-23 18:41:37 +00001320 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1321 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001322
Scott Michel97872d32008-02-23 18:41:37 +00001323 // Zero-extend i8 to i16:
1324 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1325 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1326}
Scott Michel8b6b4202007-12-04 22:35:58 +00001327
Scott Michel97872d32008-02-23 18:41:37 +00001328defm ANDHI : AndHalfwordImm;
1329
1330class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1331 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1332 IntegerOp, pattern>;
1333
1334multiclass AndWordImm
1335{
1336 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1337 [(set (v4i32 VECREG:$rT),
1338 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1339
1340 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1341 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1342
1343 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1344 // pattern below.
1345 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1346 [(set R32C:$rT,
1347 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1348
1349 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1350 // zext 16->32 pattern below.
1351 //
1352 // Note that this pattern is somewhat artificial, since it might match
1353 // something the compiler generates but is unlikely to occur in practice.
1354 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1355 [(set R32C:$rT,
1356 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1357}
1358
1359defm ANDI : AndWordImm;
1360
1361//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001362// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001363//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1364
Scott Michel8b6b4202007-12-04 22:35:58 +00001365// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001366class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1367 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1368 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001369
Scott Michel97872d32008-02-23 18:41:37 +00001370class ORVecInst<ValueType vectype>:
1371 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1372 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1373 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001374
Scott Michel97872d32008-02-23 18:41:37 +00001375class ORRegInst<RegisterClass rclass>:
1376 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1377 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001378
Scott Michel06eabde2008-12-27 04:51:36 +00001379// ORCvtForm: OR conversion form
1380//
1381// This is used to "convert" the preferred slot to its vector equivalent, as
1382// well as convert a vector back to its preferred slot.
1383//
1384// These are effectively no-ops, but need to exist for proper type conversion
1385// and type coercion.
1386
1387class ORCvtForm<dag OOL, dag IOL>
1388 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1389 bits<7> RA;
1390 bits<7> RT;
1391
1392 let Pattern = [/* no pattern */];
1393
1394 let Inst{0-10} = 0b10000010000;
1395 let Inst{11-17} = RA;
1396 let Inst{18-24} = RA;
1397 let Inst{25-31} = RT;
1398}
1399
Scott Michel97872d32008-02-23 18:41:37 +00001400class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001401 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001402
Scott Michel97872d32008-02-23 18:41:37 +00001403class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001404 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1405
1406class ORCvtRegGPRC<RegisterClass rclass>:
1407 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>;
1408
1409class ORCvtVecGPRC:
1410 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
1411
1412class ORCvtGPRCReg<RegisterClass rclass>:
1413 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>;
1414
1415class ORCvtGPRCVec:
1416 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001417
Scott Michel97872d32008-02-23 18:41:37 +00001418multiclass BitwiseOr
1419{
1420 def v16i8: ORVecInst<v16i8>;
1421 def v8i16: ORVecInst<v8i16>;
1422 def v4i32: ORVecInst<v4i32>;
1423 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001424
Scott Michel97872d32008-02-23 18:41:37 +00001425 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1426 [(set (v4f32 VECREG:$rT),
1427 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1428 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001429
Scott Michel97872d32008-02-23 18:41:37 +00001430 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001431 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001432 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1433 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001434
Scott Michel97872d32008-02-23 18:41:37 +00001435 def r64: ORRegInst<R64C>;
1436 def r32: ORRegInst<R32C>;
1437 def r16: ORRegInst<R16C>;
1438 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001439
Scott Michel97872d32008-02-23 18:41:37 +00001440 // OR instructions used to copy f32 and f64 registers.
1441 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1442 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001443
Scott Michel97872d32008-02-23 18:41:37 +00001444 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1445 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001446
Scott Michel4d07fb72008-12-30 23:28:25 +00001447 // scalar->vector promotion, prefslot2vec:
Scott Michel97872d32008-02-23 18:41:37 +00001448 def v16i8_i8: ORPromoteScalar<R8C>;
1449 def v8i16_i16: ORPromoteScalar<R16C>;
1450 def v4i32_i32: ORPromoteScalar<R32C>;
1451 def v2i64_i64: ORPromoteScalar<R64C>;
1452 def v4f32_f32: ORPromoteScalar<R32FP>;
1453 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001454
Scott Michel4d07fb72008-12-30 23:28:25 +00001455 // vector->scalar demotion, vec2prefslot:
Scott Michel97872d32008-02-23 18:41:37 +00001456 def i8_v16i8: ORExtractElt<R8C>;
1457 def i16_v8i16: ORExtractElt<R16C>;
1458 def i32_v4i32: ORExtractElt<R32C>;
1459 def i64_v2i64: ORExtractElt<R64C>;
1460 def f32_v4f32: ORExtractElt<R32FP>;
1461 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001462
1463 // Conversion from GPRC to register
1464 def i128_r64: ORCvtRegGPRC<R64C>;
1465 def i128_f64: ORCvtRegGPRC<R64FP>;
1466 def i128_r32: ORCvtRegGPRC<R32C>;
1467 def i128_f32: ORCvtRegGPRC<R32FP>;
1468 def i128_r16: ORCvtRegGPRC<R16C>;
1469 def i128_r8: ORCvtRegGPRC<R8C>;
1470
1471 // Conversion from GPRC to vector
1472 def i128_vec: ORCvtVecGPRC;
1473
1474 // Conversion from register to GPRC
1475 def r64_i128: ORCvtGPRCReg<R64C>;
1476 def f64_i128: ORCvtGPRCReg<R64FP>;
1477 def r32_i128: ORCvtGPRCReg<R32C>;
1478 def f32_i128: ORCvtGPRCReg<R32FP>;
1479 def r16_i128: ORCvtGPRCReg<R16C>;
1480 def r8_i128: ORCvtGPRCReg<R8C>;
1481
1482 // Conversion from vector to GPRC
1483 def vec_i128: ORCvtGPRCVec;
Scott Michel97872d32008-02-23 18:41:37 +00001484}
Scott Michel438be252007-12-17 22:32:34 +00001485
Scott Michel97872d32008-02-23 18:41:37 +00001486defm OR : BitwiseOr;
1487
Scott Michel06eabde2008-12-27 04:51:36 +00001488// scalar->vector promotion patterns (preferred slot to vector):
1489def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1490 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001491
Scott Michel06eabde2008-12-27 04:51:36 +00001492def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1493 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001494
Scott Michel06eabde2008-12-27 04:51:36 +00001495def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1496 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001497
Scott Michel06eabde2008-12-27 04:51:36 +00001498def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1499 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001500
Scott Michel06eabde2008-12-27 04:51:36 +00001501def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1502 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001503
Scott Michel06eabde2008-12-27 04:51:36 +00001504def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1505 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001506
Scott Michel06eabde2008-12-27 04:51:36 +00001507// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1508// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001509
Scott Michelc630c412008-11-24 17:11:17 +00001510def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001511 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001512
Scott Michelc630c412008-11-24 17:11:17 +00001513def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001514 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001515
Scott Michelc630c412008-11-24 17:11:17 +00001516def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001517 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001518
Scott Michelc630c412008-11-24 17:11:17 +00001519def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001520 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001521
Scott Michelc630c412008-11-24 17:11:17 +00001522def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001523 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001524
Scott Michelc630c412008-11-24 17:11:17 +00001525def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001526 (ORf64_v2f64 VECREG:$rA)>;
1527
1528// Load Register: This is an assembler alias for a bitwise OR of a register
1529// against itself. It's here because it brings some clarity to assembly
1530// language output.
1531
1532let hasCtrlDep = 1 in {
1533 class LRInst<dag OOL, dag IOL>
1534 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1535 bits<7> RA;
1536 bits<7> RT;
1537
1538 let Pattern = [/*no pattern*/];
1539
1540 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1541 let Inst{11-17} = RA;
1542 let Inst{18-24} = RA;
1543 let Inst{25-31} = RT;
1544 }
1545
1546 class LRVecInst<ValueType vectype>:
1547 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1548
1549 class LRRegInst<RegisterClass rclass>:
1550 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1551
1552 multiclass LoadRegister {
1553 def v2i64: LRVecInst<v2i64>;
1554 def v2f64: LRVecInst<v2f64>;
1555 def v4i32: LRVecInst<v4i32>;
1556 def v4f32: LRVecInst<v4f32>;
1557 def v8i16: LRVecInst<v8i16>;
1558 def v16i8: LRVecInst<v16i8>;
1559
1560 def r128: LRRegInst<GPRC>;
1561 def r64: LRRegInst<R64C>;
1562 def f64: LRRegInst<R64FP>;
1563 def r32: LRRegInst<R32C>;
1564 def f32: LRRegInst<R32FP>;
1565 def r16: LRRegInst<R16C>;
1566 def r8: LRRegInst<R8C>;
1567 }
1568
1569 defm LR: LoadRegister;
1570}
Scott Michel8b6b4202007-12-04 22:35:58 +00001571
Scott Michel97872d32008-02-23 18:41:37 +00001572// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001573
Scott Michel97872d32008-02-23 18:41:37 +00001574class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1575 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1576 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001577
Scott Michel97872d32008-02-23 18:41:37 +00001578class ORCVecInst<ValueType vectype>:
1579 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1580 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1581 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001582
Scott Michel97872d32008-02-23 18:41:37 +00001583class ORCRegInst<RegisterClass rclass>:
1584 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1585 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001586
Scott Michel97872d32008-02-23 18:41:37 +00001587multiclass BitwiseOrComplement
1588{
1589 def v16i8: ORCVecInst<v16i8>;
1590 def v8i16: ORCVecInst<v8i16>;
1591 def v4i32: ORCVecInst<v4i32>;
1592 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001593
Scott Michel97872d32008-02-23 18:41:37 +00001594 def r64: ORCRegInst<R64C>;
1595 def r32: ORCRegInst<R32C>;
1596 def r16: ORCRegInst<R16C>;
1597 def r8: ORCRegInst<R8C>;
1598}
1599
1600defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001601
Scott Michel8b6b4202007-12-04 22:35:58 +00001602// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001603class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1604 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1605 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001606
Scott Michel97872d32008-02-23 18:41:37 +00001607class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1608 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1609 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1610 (vectype immpred:$val)))]>;
1611
1612multiclass BitwiseOrByteImm
1613{
1614 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1615
1616 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1617 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1618}
1619
1620defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001621
Scott Michel8b6b4202007-12-04 22:35:58 +00001622// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001623class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1624 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1625 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001626
Scott Michel97872d32008-02-23 18:41:37 +00001627class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1628 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1629 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1630 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001631
Scott Michel97872d32008-02-23 18:41:37 +00001632multiclass BitwiseOrHalfwordImm
1633{
1634 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1635
1636 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1637 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1638
1639 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1640 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1641 [(set R16C:$rT, (or (anyext R8C:$rA),
1642 i16ImmSExt10:$val))]>;
1643}
1644
1645defm ORHI : BitwiseOrHalfwordImm;
1646
1647class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1648 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1649 IntegerOp, pattern>;
1650
1651class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1652 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1653 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1654 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001655
1656// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001657multiclass BitwiseOrImm
1658{
1659 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001660
Scott Michel97872d32008-02-23 18:41:37 +00001661 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1662 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001663
Scott Michel97872d32008-02-23 18:41:37 +00001664 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1665 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1666 // infra "anyext 16->32" pattern.)
1667 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1668 [(set R32C:$rT, (or (anyext R16C:$rA),
1669 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001670
Scott Michel97872d32008-02-23 18:41:37 +00001671 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1672 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1673 // infra "anyext 16->32" pattern.)
1674 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1675 [(set R32C:$rT, (or (anyext R8C:$rA),
1676 i32ImmSExt10:$val))]>;
1677}
Scott Michel8b6b4202007-12-04 22:35:58 +00001678
Scott Michel97872d32008-02-23 18:41:37 +00001679defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001680
Scott Michel8b6b4202007-12-04 22:35:58 +00001681// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1682// $rT[0], slots 1-3 are zeroed.
1683//
Scott Michel438be252007-12-17 22:32:34 +00001684// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001685def ORXv4i32:
1686 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1687 "orx\t$rT, $rA, $rB", IntegerOp,
1688 []>;
1689
Scott Michel438be252007-12-17 22:32:34 +00001690// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001691
Scott Michel6baba072008-03-05 23:02:02 +00001692class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1693 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1694 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001695
Scott Michel6baba072008-03-05 23:02:02 +00001696class XORVecInst<ValueType vectype>:
1697 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1698 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1699 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001700
Scott Michel6baba072008-03-05 23:02:02 +00001701class XORRegInst<RegisterClass rclass>:
1702 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1703 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1704
1705multiclass BitwiseExclusiveOr
1706{
1707 def v16i8: XORVecInst<v16i8>;
1708 def v8i16: XORVecInst<v8i16>;
1709 def v4i32: XORVecInst<v4i32>;
1710 def v2i64: XORVecInst<v2i64>;
1711
1712 def r128: XORRegInst<GPRC>;
1713 def r64: XORRegInst<R64C>;
1714 def r32: XORRegInst<R32C>;
1715 def r16: XORRegInst<R16C>;
1716 def r8: XORRegInst<R8C>;
1717
1718 // Special forms for floating point instructions.
1719 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1720
1721 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1722 [/* no pattern */]>;
1723
1724 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1725 [/* no pattern */]>;
1726
1727 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1728 [/* no pattern, see fneg{32,64} */]>;
1729}
1730
1731defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001732
1733//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001734
Scott Michel97872d32008-02-23 18:41:37 +00001735class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1736 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1737 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001738
Scott Michel97872d32008-02-23 18:41:37 +00001739multiclass XorByteImm
1740{
1741 def v16i8:
1742 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1743 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1744
1745 def r8:
1746 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1747 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1748}
1749
1750defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001751
Scott Michel8b6b4202007-12-04 22:35:58 +00001752def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001753 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001754 "xorhi\t$rT, $rA, $val", IntegerOp,
1755 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1756 v8i16SExt10Imm:$val))]>;
1757
1758def XORHIr16:
1759 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1760 "xorhi\t$rT, $rA, $val", IntegerOp,
1761 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1762
1763def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001764 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001765 "xori\t$rT, $rA, $val", IntegerOp,
1766 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1767 v4i32SExt10Imm:$val))]>;
1768
1769def XORIr32:
1770 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1771 "xori\t$rT, $rA, $val", IntegerOp,
1772 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1773
1774// NAND:
1775def NANDv16i8:
1776 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1777 "nand\t$rT, $rA, $rB", IntegerOp,
1778 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1779 (v16i8 VECREG:$rB))))]>;
1780
1781def NANDv8i16:
1782 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1783 "nand\t$rT, $rA, $rB", IntegerOp,
1784 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1785 (v8i16 VECREG:$rB))))]>;
1786
1787def NANDv4i32:
1788 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1789 "nand\t$rT, $rA, $rB", IntegerOp,
1790 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1791 (v4i32 VECREG:$rB))))]>;
1792
1793def NANDr32:
1794 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1795 "nand\t$rT, $rA, $rB", IntegerOp,
1796 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1797
1798def NANDr16:
1799 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1800 "nand\t$rT, $rA, $rB", IntegerOp,
1801 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1802
Scott Michel438be252007-12-17 22:32:34 +00001803def NANDr8:
1804 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1805 "nand\t$rT, $rA, $rB", IntegerOp,
1806 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1807
Scott Michel8b6b4202007-12-04 22:35:58 +00001808// NOR:
1809def NORv16i8:
1810 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1811 "nor\t$rT, $rA, $rB", IntegerOp,
1812 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1813 (v16i8 VECREG:$rB))))]>;
1814
1815def NORv8i16:
1816 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1817 "nor\t$rT, $rA, $rB", IntegerOp,
1818 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1819 (v8i16 VECREG:$rB))))]>;
1820
1821def NORv4i32:
1822 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1823 "nor\t$rT, $rA, $rB", IntegerOp,
1824 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1825 (v4i32 VECREG:$rB))))]>;
1826
1827def NORr32:
1828 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1829 "nor\t$rT, $rA, $rB", IntegerOp,
1830 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1831
1832def NORr16:
1833 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1834 "nor\t$rT, $rA, $rB", IntegerOp,
1835 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1836
Scott Michel438be252007-12-17 22:32:34 +00001837def NORr8:
1838 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1839 "nor\t$rT, $rA, $rB", IntegerOp,
1840 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1841
Scott Michel8b6b4202007-12-04 22:35:58 +00001842// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001843class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1844 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1845 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001846
Scott Michel6baba072008-03-05 23:02:02 +00001847class SELBVecInst<ValueType vectype>:
1848 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1849 [(set (vectype VECREG:$rT),
1850 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1851 (and (vnot (vectype VECREG:$rC)),
1852 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001853
Scott Michel4d07fb72008-12-30 23:28:25 +00001854class SELBVecVCondInst<ValueType vectype>:
1855 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1856 [(set (vectype VECREG:$rT),
1857 (select (vectype VECREG:$rC),
1858 (vectype VECREG:$rB),
1859 (vectype VECREG:$rA)))]>;
1860
Scott Michel06eabde2008-12-27 04:51:36 +00001861class SELBVecCondInst<ValueType vectype>:
1862 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1863 [(set (vectype VECREG:$rT),
1864 (select R32C:$rC,
1865 (vectype VECREG:$rB),
1866 (vectype VECREG:$rA)))]>;
1867
Scott Michel6baba072008-03-05 23:02:02 +00001868class SELBRegInst<RegisterClass rclass>:
1869 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1870 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001871 (or (and rclass:$rB, rclass:$rC),
1872 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001873
Scott Michel06eabde2008-12-27 04:51:36 +00001874class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1875 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1876 [(set rclass:$rT,
1877 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1878
Scott Michel6baba072008-03-05 23:02:02 +00001879multiclass SelectBits
1880{
1881 def v16i8: SELBVecInst<v16i8>;
1882 def v8i16: SELBVecInst<v8i16>;
1883 def v4i32: SELBVecInst<v4i32>;
1884 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001885
Scott Michel6baba072008-03-05 23:02:02 +00001886 def r128: SELBRegInst<GPRC>;
1887 def r64: SELBRegInst<R64C>;
1888 def r32: SELBRegInst<R32C>;
1889 def r16: SELBRegInst<R16C>;
1890 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001891
1892 def v16i8_cond: SELBVecCondInst<v16i8>;
1893 def v8i16_cond: SELBVecCondInst<v8i16>;
1894 def v4i32_cond: SELBVecCondInst<v4i32>;
1895 def v2i64_cond: SELBVecCondInst<v2i64>;
1896
Scott Michel4d07fb72008-12-30 23:28:25 +00001897 def v16i8_vcond: SELBVecCondInst<v16i8>;
1898 def v8i16_vcond: SELBVecCondInst<v8i16>;
1899 def v4i32_vcond: SELBVecCondInst<v4i32>;
1900 def v2i64_vcond: SELBVecCondInst<v2i64>;
1901
1902 def v4f32_cond:
1903 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1904 [(set (v4f32 VECREG:$rT),
1905 (select (v4i32 VECREG:$rC),
1906 (v4f32 VECREG:$rB),
1907 (v4f32 VECREG:$rA)))]>;
1908
Scott Michel06eabde2008-12-27 04:51:36 +00001909 // SELBr64_cond is defined further down, look for i64 comparisons
1910 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001911 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001912 def r16_cond: SELBRegCondInst<R16C, R16C>;
1913 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001914}
Scott Michel8b6b4202007-12-04 22:35:58 +00001915
Scott Michel6baba072008-03-05 23:02:02 +00001916defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001917
Scott Michel56a125e2008-11-22 23:50:42 +00001918class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001919 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1920 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001921
Scott Michel56a125e2008-11-22 23:50:42 +00001922def : SPUselbPatVec<v16i8, SELBv16i8>;
1923def : SPUselbPatVec<v8i16, SELBv8i16>;
1924def : SPUselbPatVec<v4i32, SELBv4i32>;
1925def : SPUselbPatVec<v2i64, SELBv2i64>;
1926
1927class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1928 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1929 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1930
1931def : SPUselbPatReg<R8C, SELBr8>;
1932def : SPUselbPatReg<R16C, SELBr16>;
1933def : SPUselbPatReg<R32C, SELBr32>;
1934def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001935
Scott Michel6baba072008-03-05 23:02:02 +00001936// EQV: Equivalence (1 for each same bit, otherwise 0)
1937//
1938// Note: There are a lot of ways to match this bit operator and these patterns
1939// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001940
Scott Michel6baba072008-03-05 23:02:02 +00001941class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1942 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1943 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001944
Scott Michel6baba072008-03-05 23:02:02 +00001945class EQVVecInst<ValueType vectype>:
1946 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1947 [(set (vectype VECREG:$rT),
1948 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1949 (and (vnot (vectype VECREG:$rA)),
1950 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001951
Scott Michel6baba072008-03-05 23:02:02 +00001952class EQVRegInst<RegisterClass rclass>:
1953 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1954 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1955 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001956
Scott Michel6baba072008-03-05 23:02:02 +00001957class EQVVecPattern1<ValueType vectype>:
1958 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1959 [(set (vectype VECREG:$rT),
1960 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001961
Scott Michel6baba072008-03-05 23:02:02 +00001962class EQVRegPattern1<RegisterClass rclass>:
1963 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1964 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001965
Scott Michel6baba072008-03-05 23:02:02 +00001966class EQVVecPattern2<ValueType vectype>:
1967 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1968 [(set (vectype VECREG:$rT),
1969 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1970 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001971
Scott Michel6baba072008-03-05 23:02:02 +00001972class EQVRegPattern2<RegisterClass rclass>:
1973 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1974 [(set rclass:$rT,
1975 (or (and rclass:$rA, rclass:$rB),
1976 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001977
Scott Michel6baba072008-03-05 23:02:02 +00001978class EQVVecPattern3<ValueType vectype>:
1979 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1980 [(set (vectype VECREG:$rT),
1981 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001982
Scott Michel6baba072008-03-05 23:02:02 +00001983class EQVRegPattern3<RegisterClass rclass>:
1984 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1985 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001986
Scott Michel6baba072008-03-05 23:02:02 +00001987multiclass BitEquivalence
1988{
1989 def v16i8: EQVVecInst<v16i8>;
1990 def v8i16: EQVVecInst<v8i16>;
1991 def v4i32: EQVVecInst<v4i32>;
1992 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001993
Scott Michel6baba072008-03-05 23:02:02 +00001994 def v16i8_1: EQVVecPattern1<v16i8>;
1995 def v8i16_1: EQVVecPattern1<v8i16>;
1996 def v4i32_1: EQVVecPattern1<v4i32>;
1997 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001998
Scott Michel6baba072008-03-05 23:02:02 +00001999 def v16i8_2: EQVVecPattern2<v16i8>;
2000 def v8i16_2: EQVVecPattern2<v8i16>;
2001 def v4i32_2: EQVVecPattern2<v4i32>;
2002 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002003
Scott Michel6baba072008-03-05 23:02:02 +00002004 def v16i8_3: EQVVecPattern3<v16i8>;
2005 def v8i16_3: EQVVecPattern3<v8i16>;
2006 def v4i32_3: EQVVecPattern3<v4i32>;
2007 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002008
Scott Michel6baba072008-03-05 23:02:02 +00002009 def r128: EQVRegInst<GPRC>;
2010 def r64: EQVRegInst<R64C>;
2011 def r32: EQVRegInst<R32C>;
2012 def r16: EQVRegInst<R16C>;
2013 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002014
Scott Michel6baba072008-03-05 23:02:02 +00002015 def r128_1: EQVRegPattern1<GPRC>;
2016 def r64_1: EQVRegPattern1<R64C>;
2017 def r32_1: EQVRegPattern1<R32C>;
2018 def r16_1: EQVRegPattern1<R16C>;
2019 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002020
Scott Michel6baba072008-03-05 23:02:02 +00002021 def r128_2: EQVRegPattern2<GPRC>;
2022 def r64_2: EQVRegPattern2<R64C>;
2023 def r32_2: EQVRegPattern2<R32C>;
2024 def r16_2: EQVRegPattern2<R16C>;
2025 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002026
Scott Michel6baba072008-03-05 23:02:02 +00002027 def r128_3: EQVRegPattern3<GPRC>;
2028 def r64_3: EQVRegPattern3<R64C>;
2029 def r32_3: EQVRegPattern3<R32C>;
2030 def r16_3: EQVRegPattern3<R16C>;
2031 def r8_3: EQVRegPattern3<R8C>;
2032}
Scott Michel438be252007-12-17 22:32:34 +00002033
Scott Michel6baba072008-03-05 23:02:02 +00002034defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00002035
2036//===----------------------------------------------------------------------===//
2037// Vector shuffle...
2038//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002039// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2040// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2041// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2042// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002043//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002044
Scott Michel97872d32008-02-23 18:41:37 +00002045class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2046 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2047 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002048
Scott Michel0718cd82008-12-01 17:56:02 +00002049class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002050 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002051 [(set (resultvec VECREG:$rT),
2052 (SPUshuffle (resultvec VECREG:$rA),
2053 (resultvec VECREG:$rB),
2054 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002055
Scott Michel06eabde2008-12-27 04:51:36 +00002056class SHUFBGPRCInst:
2057 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2058 [/* no pattern */]>;
2059
Scott Michel97872d32008-02-23 18:41:37 +00002060multiclass ShuffleBytes
2061{
Scott Michel0718cd82008-12-01 17:56:02 +00002062 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2063 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2064 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2065 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2066 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2067 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2068 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2069 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002070
Scott Michel0718cd82008-12-01 17:56:02 +00002071 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2072 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2073
2074 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2075 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002076
2077 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002078}
2079
2080defm SHUFB : ShuffleBytes;
2081
Scott Michel8b6b4202007-12-04 22:35:58 +00002082//===----------------------------------------------------------------------===//
2083// Shift and rotate group:
2084//===----------------------------------------------------------------------===//
2085
Scott Michel97872d32008-02-23 18:41:37 +00002086class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2087 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2088 RotateShift, pattern>;
2089
2090class SHLHVecInst<ValueType vectype>:
2091 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2092 [(set (vectype VECREG:$rT),
2093 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002094
2095// $rB gets promoted to 32-bit register type when confronted with
2096// this llvm assembly code:
2097//
2098// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
2099// %A = shl i16 %arg1, %arg2
2100// ret i16 %A
2101// }
Scott Michel8b6b4202007-12-04 22:35:58 +00002102
Scott Michel97872d32008-02-23 18:41:37 +00002103multiclass ShiftLeftHalfword
2104{
2105 def v8i16: SHLHVecInst<v8i16>;
2106 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2107 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2108 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2109 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2110}
Scott Michel8b6b4202007-12-04 22:35:58 +00002111
Scott Michel97872d32008-02-23 18:41:37 +00002112defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002113
Scott Michel97872d32008-02-23 18:41:37 +00002114//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002115
Scott Michel97872d32008-02-23 18:41:37 +00002116class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2117 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2118 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002119
Scott Michel97872d32008-02-23 18:41:37 +00002120class SHLHIVecInst<ValueType vectype>:
2121 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2122 [(set (vectype VECREG:$rT),
2123 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002124
Scott Michel97872d32008-02-23 18:41:37 +00002125multiclass ShiftLeftHalfwordImm
2126{
2127 def v8i16: SHLHIVecInst<v8i16>;
2128 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2129 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2130}
2131
2132defm SHLHI : ShiftLeftHalfwordImm;
2133
2134def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2135 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2136
2137def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002138 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002139
Scott Michel97872d32008-02-23 18:41:37 +00002140//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002141
Scott Michel97872d32008-02-23 18:41:37 +00002142class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2143 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2144 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002145
Scott Michel97872d32008-02-23 18:41:37 +00002146multiclass ShiftLeftWord
2147{
2148 def v4i32:
2149 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2150 [(set (v4i32 VECREG:$rT),
2151 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2152 def r32:
2153 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2154 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2155}
Scott Michel8b6b4202007-12-04 22:35:58 +00002156
Scott Michel97872d32008-02-23 18:41:37 +00002157defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002158
Scott Michel97872d32008-02-23 18:41:37 +00002159//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002160
Scott Michel97872d32008-02-23 18:41:37 +00002161class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2162 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2163 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002164
Scott Michel97872d32008-02-23 18:41:37 +00002165multiclass ShiftLeftWordImm
2166{
2167 def v4i32:
2168 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2169 [(set (v4i32 VECREG:$rT),
2170 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002171
Scott Michel97872d32008-02-23 18:41:37 +00002172 def r32:
2173 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2174 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2175}
Scott Michel8b6b4202007-12-04 22:35:58 +00002176
Scott Michel97872d32008-02-23 18:41:37 +00002177defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002178
Scott Michel97872d32008-02-23 18:41:37 +00002179//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002180// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2181// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002182//
2183// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2184// of 7 bits is actually possible.
2185//
2186// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2187// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2188// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002189
Scott Michel97872d32008-02-23 18:41:37 +00002190class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2191 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2192 RotateShift, pattern>;
2193
2194class SHLQBIVecInst<ValueType vectype>:
2195 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2196 [(set (vectype VECREG:$rT),
2197 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2198
2199multiclass ShiftLeftQuadByBits
2200{
2201 def v16i8: SHLQBIVecInst<v16i8>;
2202 def v8i16: SHLQBIVecInst<v8i16>;
2203 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002204 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002205 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002206 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002207}
2208
2209defm SHLQBI : ShiftLeftQuadByBits;
2210
2211// See note above on SHLQBI. In this case, the predicate actually does then
2212// enforcement, whereas with SHLQBI, we have to "take it on faith."
2213class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2214 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2215 RotateShift, pattern>;
2216
2217class SHLQBIIVecInst<ValueType vectype>:
2218 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2219 [(set (vectype VECREG:$rT),
2220 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2221
2222multiclass ShiftLeftQuadByBitsImm
2223{
2224 def v16i8 : SHLQBIIVecInst<v16i8>;
2225 def v8i16 : SHLQBIIVecInst<v8i16>;
2226 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002227 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002228 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002229 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002230}
2231
2232defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002233
2234// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002235// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002236
Scott Michel97872d32008-02-23 18:41:37 +00002237class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002238 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002239 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002240
Scott Michel97872d32008-02-23 18:41:37 +00002241class SHLQBYVecInst<ValueType vectype>:
2242 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2243 [(set (vectype VECREG:$rT),
2244 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002245
Scott Michel97872d32008-02-23 18:41:37 +00002246multiclass ShiftLeftQuadBytes
2247{
2248 def v16i8: SHLQBYVecInst<v16i8>;
2249 def v8i16: SHLQBYVecInst<v8i16>;
2250 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002251 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002252 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002253 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002254 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2255 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2256}
Scott Michel8b6b4202007-12-04 22:35:58 +00002257
Scott Michel97872d32008-02-23 18:41:37 +00002258defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002259
Scott Michel97872d32008-02-23 18:41:37 +00002260class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2261 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2262 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002263
Scott Michel97872d32008-02-23 18:41:37 +00002264class SHLQBYIVecInst<ValueType vectype>:
2265 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2266 [(set (vectype VECREG:$rT),
2267 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002268
Scott Michel97872d32008-02-23 18:41:37 +00002269multiclass ShiftLeftQuadBytesImm
2270{
2271 def v16i8: SHLQBYIVecInst<v16i8>;
2272 def v8i16: SHLQBYIVecInst<v8i16>;
2273 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002274 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002275 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002276 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002277 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2278 [(set GPRC:$rT,
2279 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2280}
Scott Michel438be252007-12-17 22:32:34 +00002281
Scott Michel97872d32008-02-23 18:41:37 +00002282defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002283
Scott Michel97872d32008-02-23 18:41:37 +00002284//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2285// Rotate halfword:
2286//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2287class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2288 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2289 RotateShift, pattern>;
2290
2291class ROTHVecInst<ValueType vectype>:
2292 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2293 [(set (vectype VECREG:$rT),
2294 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2295
2296class ROTHRegInst<RegisterClass rclass>:
2297 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2298 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2299
2300multiclass RotateLeftHalfword
2301{
2302 def v8i16: ROTHVecInst<v8i16>;
2303 def r16: ROTHRegInst<R16C>;
2304}
2305
2306defm ROTH: RotateLeftHalfword;
2307
2308def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2309 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2310
2311//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2312// Rotate halfword, immediate:
2313//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2314class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2315 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2316 RotateShift, pattern>;
2317
2318class ROTHIVecInst<ValueType vectype>:
2319 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2320 [(set (vectype VECREG:$rT),
2321 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2322
2323multiclass RotateLeftHalfwordImm
2324{
2325 def v8i16: ROTHIVecInst<v8i16>;
2326 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2327 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2328 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2329 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2330}
2331
2332defm ROTHI: RotateLeftHalfwordImm;
2333
2334def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002335 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002336
Scott Michel97872d32008-02-23 18:41:37 +00002337//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2338// Rotate word:
2339//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002340
Scott Michel97872d32008-02-23 18:41:37 +00002341class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2342 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2343 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002344
Scott Michel97872d32008-02-23 18:41:37 +00002345class ROTVecInst<ValueType vectype>:
2346 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2347 [(set (vectype VECREG:$rT),
2348 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002349
Scott Michel97872d32008-02-23 18:41:37 +00002350class ROTRegInst<RegisterClass rclass>:
2351 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2352 [(set rclass:$rT,
2353 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002354
Scott Michel97872d32008-02-23 18:41:37 +00002355multiclass RotateLeftWord
2356{
2357 def v4i32: ROTVecInst<v4i32>;
2358 def r32: ROTRegInst<R32C>;
2359}
2360
2361defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002362
Scott Michel438be252007-12-17 22:32:34 +00002363// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2364// 32-bit register
2365def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002366 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2367 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002368
2369def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2370 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2371
2372def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2373 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2374
2375def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002376 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2377 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002378
2379def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2380 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2381
2382def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2383 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2384
Scott Michel97872d32008-02-23 18:41:37 +00002385//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2386// Rotate word, immediate
2387//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002388
Scott Michel97872d32008-02-23 18:41:37 +00002389class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2390 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2391 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002392
Scott Michel97872d32008-02-23 18:41:37 +00002393class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2394 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2395 [(set (vectype VECREG:$rT),
2396 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002397
Scott Michel97872d32008-02-23 18:41:37 +00002398class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2399 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2400 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002401
Scott Michel97872d32008-02-23 18:41:37 +00002402multiclass RotateLeftWordImm
2403{
2404 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2405 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2406 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002407
Scott Michel97872d32008-02-23 18:41:37 +00002408 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2409 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2410 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2411}
Scott Michel438be252007-12-17 22:32:34 +00002412
Scott Michel97872d32008-02-23 18:41:37 +00002413defm ROTI : RotateLeftWordImm;
2414
2415//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2416// Rotate quad by byte (count)
2417//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2418
2419class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2420 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2421 RotateShift, pattern>;
2422
2423class ROTQBYVecInst<ValueType vectype>:
2424 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2425 [(set (vectype VECREG:$rT),
2426 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2427
2428multiclass RotateQuadLeftByBytes
2429{
2430 def v16i8: ROTQBYVecInst<v16i8>;
2431 def v8i16: ROTQBYVecInst<v8i16>;
2432 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002433 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002434 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002435 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002436}
2437
2438defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002439
Scott Michel97872d32008-02-23 18:41:37 +00002440//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2441// Rotate quad by byte (count), immediate
2442//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2443
2444class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2445 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2446 RotateShift, pattern>;
2447
2448class ROTQBYIVecInst<ValueType vectype>:
2449 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2450 [(set (vectype VECREG:$rT),
2451 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2452
2453multiclass RotateQuadByBytesImm
2454{
2455 def v16i8: ROTQBYIVecInst<v16i8>;
2456 def v8i16: ROTQBYIVecInst<v8i16>;
2457 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002458 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002459 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002460 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002461}
2462
2463defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002464
Scott Michel8b6b4202007-12-04 22:35:58 +00002465// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002466class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2467 RI7Form<0b00110011100, OOL, IOL,
2468 "rotqbybi\t$rT, $rA, $shift",
2469 RotateShift, pattern>;
2470
2471class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2472 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2473 [(set (vectype VECREG:$rT),
2474 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2475
2476multiclass RotateQuadByBytesByBitshift {
2477 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2478 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2479 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2480 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2481}
2482
2483defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002484
Scott Michel97872d32008-02-23 18:41:37 +00002485//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002486// See ROTQBY note above.
2487//
2488// Assume that the user of this instruction knows to shift the rotate count
2489// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002490//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002491
Scott Michel97872d32008-02-23 18:41:37 +00002492class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2493 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2494 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002495
Scott Michel97872d32008-02-23 18:41:37 +00002496class ROTQBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002497 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002498 [/* no pattern yet */]>;
2499
2500class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002501 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002502 [/* no pattern yet */]>;
2503
2504multiclass RotateQuadByBitCount
2505{
2506 def v16i8: ROTQBIVecInst<v16i8>;
2507 def v8i16: ROTQBIVecInst<v8i16>;
2508 def v4i32: ROTQBIVecInst<v4i32>;
2509 def v2i64: ROTQBIVecInst<v2i64>;
2510
2511 def r128: ROTQBIRegInst<GPRC>;
2512 def r64: ROTQBIRegInst<R64C>;
2513}
2514
2515defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002516
Scott Michel97872d32008-02-23 18:41:37 +00002517class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2518 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2519 RotateShift, pattern>;
2520
2521class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2522 PatLeaf pred>:
2523 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2524 [/* no pattern yet */]>;
2525
2526class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2527 PatLeaf pred>:
2528 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2529 [/* no pattern yet */]>;
2530
2531multiclass RotateQuadByBitCountImm
2532{
2533 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2534 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2535 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2536 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2537
2538 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2539 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2540}
2541
2542defm ROTQBII : RotateQuadByBitCountImm;
2543
2544//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002545// ROTHM v8i16 form:
2546// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2547// so this only matches a synthetically generated/lowered code
2548// fragment.
2549// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002550//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002551
Scott Michel97872d32008-02-23 18:41:37 +00002552class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2553 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2554 RotateShift, pattern>;
2555
2556def ROTHMv8i16:
2557 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2558 [/* see patterns below - $rB must be negated */]>;
2559
2560def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002561 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2562
Scott Michel97872d32008-02-23 18:41:37 +00002563def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002564 (ROTHMv8i16 VECREG:$rA,
2565 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2566
Scott Michel97872d32008-02-23 18:41:37 +00002567def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002568 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002569 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002570
2571// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2572// Note: This instruction doesn't match a pattern because rB must be negated
2573// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002574
Scott Michel8b6b4202007-12-04 22:35:58 +00002575def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002576 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2577 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002578
2579def : Pat<(srl R16C:$rA, R32C:$rB),
2580 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2581
2582def : Pat<(srl R16C:$rA, R16C:$rB),
2583 (ROTHMr16 R16C:$rA,
2584 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2585
Scott Michel438be252007-12-17 22:32:34 +00002586def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002587 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002588 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002589
2590// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2591// that the immediate can be complemented, so that the user doesn't have to
2592// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002593
Scott Michel97872d32008-02-23 18:41:37 +00002594class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2595 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2596 RotateShift, pattern>;
2597
2598def ROTHMIv8i16:
2599 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2600 [/* no pattern */]>;
2601
2602def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2603 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2604
2605def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002606 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002607
Scott Michel97872d32008-02-23 18:41:37 +00002608def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002609 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002610
2611def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002612 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2613 [/* no pattern */]>;
2614
2615def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2616 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002617
2618def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2619 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2620
Scott Michel438be252007-12-17 22:32:34 +00002621def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2622 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2623
Scott Michel8b6b4202007-12-04 22:35:58 +00002624// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002625class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2626 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2627 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002628
Scott Michel97872d32008-02-23 18:41:37 +00002629def ROTMv4i32:
2630 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2631 [/* see patterns below - $rB must be negated */]>;
2632
2633def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002634 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2635
Scott Michel97872d32008-02-23 18:41:37 +00002636def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002637 (ROTMv4i32 VECREG:$rA,
2638 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2639
Scott Michel97872d32008-02-23 18:41:37 +00002640def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002641 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002642 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002643
2644def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002645 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2646 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002647
2648def : Pat<(srl R32C:$rA, R32C:$rB),
2649 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2650
2651def : Pat<(srl R32C:$rA, R16C:$rB),
2652 (ROTMr32 R32C:$rA,
2653 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2654
Scott Michel438be252007-12-17 22:32:34 +00002655def : Pat<(srl R32C:$rA, R8C:$rB),
2656 (ROTMr32 R32C:$rA,
2657 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2658
Scott Michel8b6b4202007-12-04 22:35:58 +00002659// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2660def ROTMIv4i32:
2661 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2662 "rotmi\t$rT, $rA, $val", RotateShift,
2663 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002664 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002665
Scott Michel97872d32008-02-23 18:41:37 +00002666def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002667 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002668
Scott Michel97872d32008-02-23 18:41:37 +00002669def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002670 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002671
2672// ROTMI r32 form: know how to complement the immediate value.
2673def ROTMIr32:
2674 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2675 "rotmi\t$rT, $rA, $val", RotateShift,
2676 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2677
2678def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2679 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2680
Scott Michel438be252007-12-17 22:32:34 +00002681def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2682 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2683
Scott Michel97872d32008-02-23 18:41:37 +00002684//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002685// ROTQMBYvec: This is a vector form merely so that when used in an
2686// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002687// that the user knew to negate $rB.
Scott Michel97872d32008-02-23 18:41:37 +00002688//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002689
Scott Michel97872d32008-02-23 18:41:37 +00002690class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2691 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2692 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002693
Scott Michel97872d32008-02-23 18:41:37 +00002694class ROTQMBYVecInst<ValueType vectype>:
2695 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2696 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002697
Scott Michel97872d32008-02-23 18:41:37 +00002698class ROTQMBYRegInst<RegisterClass rclass>:
2699 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00002700 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002701
Scott Michel97872d32008-02-23 18:41:37 +00002702multiclass RotateQuadBytes
2703{
2704 def v16i8: ROTQMBYVecInst<v16i8>;
2705 def v8i16: ROTQMBYVecInst<v8i16>;
2706 def v4i32: ROTQMBYVecInst<v4i32>;
2707 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002708
Scott Michel97872d32008-02-23 18:41:37 +00002709 def r128: ROTQMBYRegInst<GPRC>;
2710 def r64: ROTQMBYRegInst<R64C>;
2711}
2712
2713defm ROTQMBY : RotateQuadBytes;
2714
Scott Michel97872d32008-02-23 18:41:37 +00002715class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2716 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2717 RotateShift, pattern>;
2718
2719class ROTQMBYIVecInst<ValueType vectype>:
2720 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002721 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002722
2723class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2724 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002725 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002726
2727multiclass RotateQuadBytesImm
2728{
2729 def v16i8: ROTQMBYIVecInst<v16i8>;
2730 def v8i16: ROTQMBYIVecInst<v8i16>;
2731 def v4i32: ROTQMBYIVecInst<v4i32>;
2732 def v2i64: ROTQMBYIVecInst<v2i64>;
2733
2734 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2735 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2736}
2737
2738defm ROTQMBYI : RotateQuadBytesImm;
2739
Scott Michel97872d32008-02-23 18:41:37 +00002740//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2741// Rotate right and mask by bit count
2742//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2743
2744class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2745 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2746 RotateShift, pattern>;
2747
2748class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002749 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2750 [/* no pattern, */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002751
2752multiclass RotateMaskQuadByBitCount
2753{
2754 def v16i8: ROTQMBYBIVecInst<v16i8>;
2755 def v8i16: ROTQMBYBIVecInst<v8i16>;
2756 def v4i32: ROTQMBYBIVecInst<v4i32>;
2757 def v2i64: ROTQMBYBIVecInst<v2i64>;
2758}
2759
2760defm ROTQMBYBI: RotateMaskQuadByBitCount;
2761
2762//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2763// Rotate quad and mask by bits
2764// Note that the rotate amount has to be negated
2765//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2766
2767class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2768 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2769 RotateShift, pattern>;
2770
2771class ROTQMBIVecInst<ValueType vectype>:
2772 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2773 [/* no pattern */]>;
2774
2775class ROTQMBIRegInst<RegisterClass rclass>:
2776 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2777 [/* no pattern */]>;
2778
2779multiclass RotateMaskQuadByBits
2780{
2781 def v16i8: ROTQMBIVecInst<v16i8>;
2782 def v8i16: ROTQMBIVecInst<v8i16>;
2783 def v4i32: ROTQMBIVecInst<v4i32>;
2784 def v2i64: ROTQMBIVecInst<v2i64>;
2785
2786 def r128: ROTQMBIRegInst<GPRC>;
2787 def r64: ROTQMBIRegInst<R64C>;
2788}
2789
2790defm ROTQMBI: RotateMaskQuadByBits;
2791
Scott Michel97872d32008-02-23 18:41:37 +00002792//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2793// Rotate quad and mask by bits, immediate
2794//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2795
2796class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2797 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2798 RotateShift, pattern>;
2799
2800class ROTQMBIIVecInst<ValueType vectype>:
2801 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002802 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002803
2804class ROTQMBIIRegInst<RegisterClass rclass>:
2805 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002806 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002807
2808multiclass RotateMaskQuadByBitsImm
2809{
2810 def v16i8: ROTQMBIIVecInst<v16i8>;
2811 def v8i16: ROTQMBIIVecInst<v8i16>;
2812 def v4i32: ROTQMBIIVecInst<v4i32>;
2813 def v2i64: ROTQMBIIVecInst<v2i64>;
2814
2815 def r128: ROTQMBIIRegInst<GPRC>;
2816 def r64: ROTQMBIIRegInst<R64C>;
2817}
2818
2819defm ROTQMBII: RotateMaskQuadByBitsImm;
2820
2821//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2822//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002823
2824def ROTMAHv8i16:
2825 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2826 "rotmah\t$rT, $rA, $rB", RotateShift,
2827 [/* see patterns below - $rB must be negated */]>;
2828
Scott Michel97872d32008-02-23 18:41:37 +00002829def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002830 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2831
Scott Michel97872d32008-02-23 18:41:37 +00002832def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002833 (ROTMAHv8i16 VECREG:$rA,
2834 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2835
Scott Michel97872d32008-02-23 18:41:37 +00002836def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002837 (ROTMAHv8i16 VECREG:$rA,
2838 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2839
Scott Michel8b6b4202007-12-04 22:35:58 +00002840def ROTMAHr16:
2841 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2842 "rotmah\t$rT, $rA, $rB", RotateShift,
2843 [/* see patterns below - $rB must be negated */]>;
2844
2845def : Pat<(sra R16C:$rA, R32C:$rB),
2846 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2847
2848def : Pat<(sra R16C:$rA, R16C:$rB),
2849 (ROTMAHr16 R16C:$rA,
2850 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2851
Scott Michel438be252007-12-17 22:32:34 +00002852def : Pat<(sra R16C:$rA, R8C:$rB),
2853 (ROTMAHr16 R16C:$rA,
2854 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2855
Scott Michel8b6b4202007-12-04 22:35:58 +00002856def ROTMAHIv8i16:
2857 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2858 "rotmahi\t$rT, $rA, $val", RotateShift,
2859 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002860 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002861
Scott Michel97872d32008-02-23 18:41:37 +00002862def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002863 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2864
Scott Michel97872d32008-02-23 18:41:37 +00002865def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002866 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2867
Scott Michel8b6b4202007-12-04 22:35:58 +00002868def ROTMAHIr16:
2869 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2870 "rotmahi\t$rT, $rA, $val", RotateShift,
2871 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2872
2873def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2874 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2875
Scott Michel438be252007-12-17 22:32:34 +00002876def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2877 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2878
Scott Michel8b6b4202007-12-04 22:35:58 +00002879def ROTMAv4i32:
2880 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2881 "rotma\t$rT, $rA, $rB", RotateShift,
2882 [/* see patterns below - $rB must be negated */]>;
2883
Scott Michel97872d32008-02-23 18:41:37 +00002884def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002885 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2886
Scott Michel97872d32008-02-23 18:41:37 +00002887def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002888 (ROTMAv4i32 (v4i32 VECREG:$rA),
2889 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2890
Scott Michel97872d32008-02-23 18:41:37 +00002891def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002892 (ROTMAv4i32 (v4i32 VECREG:$rA),
2893 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2894
Scott Michel8b6b4202007-12-04 22:35:58 +00002895def ROTMAr32:
2896 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2897 "rotma\t$rT, $rA, $rB", RotateShift,
2898 [/* see patterns below - $rB must be negated */]>;
2899
2900def : Pat<(sra R32C:$rA, R32C:$rB),
2901 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2902
2903def : Pat<(sra R32C:$rA, R16C:$rB),
2904 (ROTMAr32 R32C:$rA,
2905 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2906
Scott Michel438be252007-12-17 22:32:34 +00002907def : Pat<(sra R32C:$rA, R8C:$rB),
2908 (ROTMAr32 R32C:$rA,
2909 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2910
Scott Michel67224b22008-06-02 22:18:03 +00002911class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
2912 RRForm<0b01011110000, OOL, IOL,
2913 "rotmai\t$rT, $rA, $val",
2914 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002915
Scott Michel67224b22008-06-02 22:18:03 +00002916class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
2917 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
2918 [(set (vectype VECREG:$rT),
2919 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002920
Scott Michel67224b22008-06-02 22:18:03 +00002921class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
2922 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
2923 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002924
Scott Michel67224b22008-06-02 22:18:03 +00002925multiclass RotateMaskAlgebraicImm {
2926 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
2927 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
2928 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
2929 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
2930}
Scott Michel8b6b4202007-12-04 22:35:58 +00002931
Scott Michel67224b22008-06-02 22:18:03 +00002932defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00002933
Scott Michel8b6b4202007-12-04 22:35:58 +00002934//===----------------------------------------------------------------------===//
2935// Branch and conditionals:
2936//===----------------------------------------------------------------------===//
2937
2938let isTerminator = 1, isBarrier = 1 in {
2939 // Halt If Equal (r32 preferred slot only, no vector form)
2940 def HEQr32:
2941 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2942 "heq\t$rA, $rB", BranchResolv,
2943 [/* no pattern to match */]>;
2944
2945 def HEQIr32 :
2946 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2947 "heqi\t$rA, $val", BranchResolv,
2948 [/* no pattern to match */]>;
2949
2950 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2951 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2952 def HGTr32:
2953 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2954 "hgt\t$rA, $rB", BranchResolv,
2955 [/* no pattern to match */]>;
2956
Scott Michel06eabde2008-12-27 04:51:36 +00002957 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00002958 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2959 "hgti\t$rA, $val", BranchResolv,
2960 [/* no pattern to match */]>;
2961
2962 def HLGTr32:
2963 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2964 "hlgt\t$rA, $rB", BranchResolv,
2965 [/* no pattern to match */]>;
2966
2967 def HLGTIr32:
2968 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2969 "hlgti\t$rA, $val", BranchResolv,
2970 [/* no pattern to match */]>;
2971}
2972
Scott Michel06eabde2008-12-27 04:51:36 +00002973//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2974// Comparison operators for i8, i16 and i32:
2975//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002976
Scott Michel97872d32008-02-23 18:41:37 +00002977class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2978 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2979 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002980
Scott Michel97872d32008-02-23 18:41:37 +00002981multiclass CmpEqualByte
2982{
2983 def v16i8 :
2984 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2985 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2986 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002987
Scott Michel97872d32008-02-23 18:41:37 +00002988 def r8 :
2989 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2990 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2991}
Scott Michel8b6b4202007-12-04 22:35:58 +00002992
Scott Michel97872d32008-02-23 18:41:37 +00002993class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2994 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2995 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002996
Scott Michel97872d32008-02-23 18:41:37 +00002997multiclass CmpEqualByteImm
2998{
2999 def v16i8 :
3000 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3001 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3002 v16i8SExt8Imm:$val))]>;
3003 def r8:
3004 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3005 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3006}
Scott Michel8b6b4202007-12-04 22:35:58 +00003007
Scott Michel97872d32008-02-23 18:41:37 +00003008class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3009 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3010 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003011
Scott Michel97872d32008-02-23 18:41:37 +00003012multiclass CmpEqualHalfword
3013{
3014 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3015 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3016 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003017
Scott Michel97872d32008-02-23 18:41:37 +00003018 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3019 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3020}
Scott Michel8b6b4202007-12-04 22:35:58 +00003021
Scott Michel97872d32008-02-23 18:41:37 +00003022class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3023 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3024 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003025
Scott Michel97872d32008-02-23 18:41:37 +00003026multiclass CmpEqualHalfwordImm
3027{
3028 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3029 [(set (v8i16 VECREG:$rT),
3030 (seteq (v8i16 VECREG:$rA),
3031 (v8i16 v8i16SExt10Imm:$val)))]>;
3032 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3033 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3034}
Scott Michel8b6b4202007-12-04 22:35:58 +00003035
Scott Michel97872d32008-02-23 18:41:37 +00003036class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3037 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3038 ByteOp, pattern>;
3039
3040multiclass CmpEqualWord
3041{
3042 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3043 [(set (v4i32 VECREG:$rT),
3044 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3045
3046 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3047 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3048}
3049
3050class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3051 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3052 ByteOp, pattern>;
3053
3054multiclass CmpEqualWordImm
3055{
3056 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3057 [(set (v4i32 VECREG:$rT),
3058 (seteq (v4i32 VECREG:$rA),
3059 (v4i32 v4i32SExt16Imm:$val)))]>;
3060
3061 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3062 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3063}
3064
3065class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3066 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3067 ByteOp, pattern>;
3068
3069multiclass CmpGtrByte
3070{
3071 def v16i8 :
3072 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3073 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3074 (v8i16 VECREG:$rB)))]>;
3075
3076 def r8 :
3077 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3078 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3079}
3080
3081class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3082 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3083 ByteOp, pattern>;
3084
3085multiclass CmpGtrByteImm
3086{
3087 def v16i8 :
3088 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3089 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3090 v16i8SExt8Imm:$val))]>;
3091 def r8:
3092 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003093 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003094}
3095
3096class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3097 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3098 ByteOp, pattern>;
3099
3100multiclass CmpGtrHalfword
3101{
3102 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3103 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3104 (v8i16 VECREG:$rB)))]>;
3105
3106 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3107 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3108}
3109
3110class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3111 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3112 ByteOp, pattern>;
3113
3114multiclass CmpGtrHalfwordImm
3115{
3116 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3117 [(set (v8i16 VECREG:$rT),
3118 (setgt (v8i16 VECREG:$rA),
3119 (v8i16 v8i16SExt10Imm:$val)))]>;
3120 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3121 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3122}
3123
3124class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3125 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3126 ByteOp, pattern>;
3127
3128multiclass CmpGtrWord
3129{
3130 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3131 [(set (v4i32 VECREG:$rT),
3132 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3133
3134 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3135 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3136}
3137
3138class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3139 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3140 ByteOp, pattern>;
3141
3142multiclass CmpGtrWordImm
3143{
3144 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3145 [(set (v4i32 VECREG:$rT),
3146 (setgt (v4i32 VECREG:$rA),
3147 (v4i32 v4i32SExt16Imm:$val)))]>;
3148
3149 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3150 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003151
3152 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3153 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3154 [(set (v4i32 VECREG:$rT),
3155 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3156 (v4i32 v4i32SExt16Imm:$val)))]>;
3157
3158 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
3159 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00003160}
3161
3162class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003163 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003164 ByteOp, pattern>;
3165
3166multiclass CmpLGtrByte
3167{
3168 def v16i8 :
3169 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3170 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3171 (v8i16 VECREG:$rB)))]>;
3172
3173 def r8 :
3174 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3175 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3176}
3177
3178class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003179 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003180 ByteOp, pattern>;
3181
3182multiclass CmpLGtrByteImm
3183{
3184 def v16i8 :
3185 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3186 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3187 v16i8SExt8Imm:$val))]>;
3188 def r8:
3189 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3190 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3191}
3192
3193class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003194 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003195 ByteOp, pattern>;
3196
3197multiclass CmpLGtrHalfword
3198{
3199 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3200 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3201 (v8i16 VECREG:$rB)))]>;
3202
3203 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3204 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3205}
3206
3207class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003208 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003209 ByteOp, pattern>;
3210
3211multiclass CmpLGtrHalfwordImm
3212{
3213 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3214 [(set (v8i16 VECREG:$rT),
3215 (setugt (v8i16 VECREG:$rA),
3216 (v8i16 v8i16SExt10Imm:$val)))]>;
3217 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3218 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3219}
3220
3221class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003222 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003223 ByteOp, pattern>;
3224
3225multiclass CmpLGtrWord
3226{
3227 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3228 [(set (v4i32 VECREG:$rT),
3229 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3230
3231 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3232 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3233}
3234
3235class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003236 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003237 ByteOp, pattern>;
3238
3239multiclass CmpLGtrWordImm
3240{
3241 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3242 [(set (v4i32 VECREG:$rT),
3243 (setugt (v4i32 VECREG:$rA),
3244 (v4i32 v4i32SExt16Imm:$val)))]>;
3245
3246 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003247 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003248}
3249
3250defm CEQB : CmpEqualByte;
3251defm CEQBI : CmpEqualByteImm;
3252defm CEQH : CmpEqualHalfword;
3253defm CEQHI : CmpEqualHalfwordImm;
3254defm CEQ : CmpEqualWord;
3255defm CEQI : CmpEqualWordImm;
3256defm CGTB : CmpGtrByte;
3257defm CGTBI : CmpGtrByteImm;
3258defm CGTH : CmpGtrHalfword;
3259defm CGTHI : CmpGtrHalfwordImm;
3260defm CGT : CmpGtrWord;
3261defm CGTI : CmpGtrWordImm;
3262defm CLGTB : CmpLGtrByte;
3263defm CLGTBI : CmpLGtrByteImm;
3264defm CLGTH : CmpLGtrHalfword;
3265defm CLGTHI : CmpLGtrHalfwordImm;
3266defm CLGT : CmpLGtrWord;
3267defm CLGTI : CmpLGtrWordImm;
3268
Scott Michel53ab7792008-03-10 16:58:52 +00003269//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003270// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3271// define a pattern to generate the right code, as a binary operator
3272// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003273//
Scott Michel06eabde2008-12-27 04:51:36 +00003274// Notes:
3275// 1. This only matches the setcc set of conditionals. Special pattern
3276// matching is used for select conditionals.
3277//
3278// 2. The "DAG" versions of these classes is almost exclusively used for
3279// i64 comparisons. See the tblgen fundamentals documentation for what
3280// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3281// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003282//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003283
Scott Michel53ab7792008-03-10 16:58:52 +00003284class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3285 SPUInstr xorinst, SPUInstr cmpare>:
3286 Pat<(cond rclass:$rA, rclass:$rB),
3287 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3288
3289class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3290 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3291 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3292 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3293
Scott Michel06eabde2008-12-27 04:51:36 +00003294def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003295def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3296
Scott Michel06eabde2008-12-27 04:51:36 +00003297def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003298def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3299
3300def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3301def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003302
3303class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3304 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3305 Pat<(cond rclass:$rA, rclass:$rB),
3306 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3307 (cmpOp2 rclass:$rA, rclass:$rB))>;
3308
3309class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3310 ValueType immtype,
3311 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3312 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3313 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3314 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3315
Scott Michel53ab7792008-03-10 16:58:52 +00003316def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3317def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3318def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3319def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3320def : Pat<(setle R8C:$rA, R8C:$rB),
3321 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3322def : Pat<(setle R8C:$rA, immU8:$imm),
3323 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003324
Scott Michel53ab7792008-03-10 16:58:52 +00003325def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3326def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3327 ORr16, CGTHIr16, CEQHIr16>;
3328def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3329def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3330def : Pat<(setle R16C:$rA, R16C:$rB),
3331 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3332def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3333 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003334
Scott Michel53ab7792008-03-10 16:58:52 +00003335def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3336def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3337 ORr32, CGTIr32, CEQIr32>;
3338def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3339def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3340def : Pat<(setle R32C:$rA, R32C:$rB),
3341 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3342def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3343 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003344
Scott Michel53ab7792008-03-10 16:58:52 +00003345def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3346def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3347def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3348def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3349def : Pat<(setule R8C:$rA, R8C:$rB),
3350 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3351def : Pat<(setule R8C:$rA, immU8:$imm),
3352 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003353
Scott Michel53ab7792008-03-10 16:58:52 +00003354def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3355def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3356 ORr16, CLGTHIr16, CEQHIr16>;
3357def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3358def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3359 CLGTHIr16, CEQHIr16>;
3360def : Pat<(setule R16C:$rA, R16C:$rB),
3361 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003362def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003363 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003364
Scott Michel53ab7792008-03-10 16:58:52 +00003365def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003366def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003367 ORr32, CLGTIr32, CEQIr32>;
3368def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003369def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003370def : Pat<(setule R32C:$rA, R32C:$rB),
3371 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3372def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3373 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003374
Scott Michel53ab7792008-03-10 16:58:52 +00003375//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3376// select conditional patterns:
3377//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3378
3379class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3380 SPUInstr selinstr, SPUInstr cmpare>:
3381 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3382 rclass:$rTrue, rclass:$rFalse),
3383 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003384 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003385
3386class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3387 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3388 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003389 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003390 (selinstr rclass:$rTrue, rclass:$rFalse,
3391 (cmpare rclass:$rA, immpred:$imm))>;
3392
3393def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3394def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3395def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3396def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3397def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3398def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3399
3400def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3401def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3402def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3403def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3404def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3405def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3406
3407def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3408def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3409def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3410def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3411def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3412def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3413
3414class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3415 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3416 SPUInstr cmpOp2>:
3417 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003418 rclass:$rTrue, rclass:$rFalse),
3419 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003420 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3421 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3422
3423class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3424 ValueType inttype,
3425 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3426 SPUInstr cmpOp2>:
3427 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003428 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003429 (selinstr rclass:$rFalse, rclass:$rTrue,
3430 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3431 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3432
3433def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3434def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3435 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3436
3437def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3438def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3439 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3440
3441def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3442def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3443 SELBr32, ORr32, CGTIr32, CEQIr32>;
3444
3445def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3446def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3447 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3448
3449def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3450def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3451 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3452
3453def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3454def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3455 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003456
3457//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003458
3459let isCall = 1,
3460 // All calls clobber the non-callee-saved registers:
3461 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3462 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3463 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3464 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3465 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3466 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3467 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3468 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3469 // All of these instructions use $lr (aka $0)
3470 Uses = [R0] in {
3471 // Branch relative and set link: Used if we actually know that the target
3472 // is within [-32768, 32767] bytes of the target
3473 def BRSL:
3474 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3475 "brsl\t$$lr, $func",
3476 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3477
3478 // Branch absolute and set link: Used if we actually know that the target
3479 // is an absolute address
3480 def BRASL:
3481 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3482 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003483 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003484
3485 // Branch indirect and set link if external data. These instructions are not
3486 // actually generated, matched by an intrinsic:
3487 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3488 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3489 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3490 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3491
3492 // Branch indirect and set link. This is the "X-form" address version of a
3493 // function call
3494 def BISL:
3495 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3496}
3497
Scott Michelae5cbf52008-12-29 03:23:36 +00003498// Support calls to external symbols:
3499def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3500 (BRSL texternalsym:$func)>;
3501
3502def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3503 (BRASL texternalsym:$func)>;
3504
Scott Michel8b6b4202007-12-04 22:35:58 +00003505// Unconditional branches:
3506let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3507 def BR :
3508 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3509 "br\t$dest",
3510 [(br bb:$dest)]>;
3511
3512 // Unconditional, absolute address branch
3513 def BRA:
3514 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3515 "bra\t$dest",
3516 [/* no pattern */]>;
3517
3518 // Indirect branch
3519 def BI:
3520 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3521
Scott Michele0168c12009-01-05 01:34:35 +00003522 // Conditional branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003523 class BRNZInst<dag IOL, list<dag> pattern>:
3524 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3525 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003526
Scott Michel06eabde2008-12-27 04:51:36 +00003527 class BRNZRegInst<RegisterClass rclass>:
3528 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3529 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003530
Scott Michel06eabde2008-12-27 04:51:36 +00003531 class BRNZVecInst<ValueType vectype>:
3532 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3533 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003534
Scott Michel06eabde2008-12-27 04:51:36 +00003535 multiclass BranchNotZero {
3536 def v4i32 : BRNZVecInst<v4i32>;
3537 def r32 : BRNZRegInst<R32C>;
3538 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003539
Scott Michel06eabde2008-12-27 04:51:36 +00003540 defm BRNZ : BranchNotZero;
3541
3542 class BRZInst<dag IOL, list<dag> pattern>:
3543 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3544 BranchResolv, pattern>;
3545
3546 class BRZRegInst<RegisterClass rclass>:
3547 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3548
3549 class BRZVecInst<ValueType vectype>:
3550 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3551
3552 multiclass BranchZero {
3553 def v4i32: BRZVecInst<v4i32>;
3554 def r32: BRZRegInst<R32C>;
3555 }
3556
3557 defm BRZ: BranchZero;
3558
3559 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3560 // be useful:
3561 /*
3562 class BINZInst<dag IOL, list<dag> pattern>:
3563 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3564
3565 class BINZRegInst<RegisterClass rclass>:
3566 BINZInst<(ins rclass:$rA, brtarget:$dest),
3567 [(brcond rclass:$rA, R32C:$dest)]>;
3568
3569 class BINZVecInst<ValueType vectype>:
3570 BINZInst<(ins VECREG:$rA, R32C:$dest),
3571 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3572
3573 multiclass BranchNotZeroIndirect {
3574 def v4i32: BINZVecInst<v4i32>;
3575 def r32: BINZRegInst<R32C>;
3576 }
3577
3578 defm BINZ: BranchNotZeroIndirect;
3579
3580 class BIZInst<dag IOL, list<dag> pattern>:
3581 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3582
3583 class BIZRegInst<RegisterClass rclass>:
3584 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3585
3586 class BIZVecInst<ValueType vectype>:
3587 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3588
3589 multiclass BranchZeroIndirect {
3590 def v4i32: BIZVecInst<v4i32>;
3591 def r32: BIZRegInst<R32C>;
3592 }
3593
3594 defm BIZ: BranchZeroIndirect;
3595 */
3596
3597 class BRHNZInst<dag IOL, list<dag> pattern>:
3598 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3599 pattern>;
3600
3601 class BRHNZRegInst<RegisterClass rclass>:
3602 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3603 [(brcond rclass:$rCond, bb:$dest)]>;
3604
3605 class BRHNZVecInst<ValueType vectype>:
3606 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3607
3608 multiclass BranchNotZeroHalfword {
3609 def v8i16: BRHNZVecInst<v8i16>;
3610 def r16: BRHNZRegInst<R16C>;
3611 }
3612
3613 defm BRHNZ: BranchNotZeroHalfword;
3614
3615 class BRHZInst<dag IOL, list<dag> pattern>:
3616 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3617 pattern>;
3618
3619 class BRHZRegInst<RegisterClass rclass>:
3620 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3621
3622 class BRHZVecInst<ValueType vectype>:
3623 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3624
3625 multiclass BranchZeroHalfword {
3626 def v8i16: BRHZVecInst<v8i16>;
3627 def r16: BRHZRegInst<R16C>;
3628 }
3629
3630 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003631}
3632
Scott Michel394e26d2008-01-17 20:38:41 +00003633//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003634// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003635//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003636
Scott Michel06eabde2008-12-27 04:51:36 +00003637def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3638 (BRHZr16 R16C:$rA, bb:$dest)>;
3639def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3640 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003641
Scott Michel06eabde2008-12-27 04:51:36 +00003642def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3643 (BRZr32 R32C:$rA, bb:$dest)>;
3644def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3645 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003646
Scott Michel97872d32008-02-23 18:41:37 +00003647multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3648{
3649 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3650 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003651
Scott Michel97872d32008-02-23 18:41:37 +00003652 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3653 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3654
3655 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3656 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3657
3658 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3659 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3660}
3661
Scott Michele0168c12009-01-05 01:34:35 +00003662defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3663defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003664
3665multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3666{
3667 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3668 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3669
3670 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3671 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3672
3673 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3674 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3675
3676 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3677 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3678}
3679
Scott Michel06eabde2008-12-27 04:51:36 +00003680defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3681defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003682
3683multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3684 SPUInstr orinst32, SPUInstr brinst32>
3685{
3686 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3687 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3688 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3689 bb:$dest)>;
3690
3691 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3692 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3693 (CEQHr16 R16C:$rA, R16:$rB)),
3694 bb:$dest)>;
3695
3696 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3697 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3698 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3699 bb:$dest)>;
3700
3701 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3702 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3703 (CEQr32 R32C:$rA, R32C:$rB)),
3704 bb:$dest)>;
3705}
3706
Scott Michel06eabde2008-12-27 04:51:36 +00003707defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3708defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003709
3710multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3711{
3712 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3713 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3714
3715 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3716 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3717
3718 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3719 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3720
3721 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3722 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3723}
3724
Scott Michel06eabde2008-12-27 04:51:36 +00003725defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3726defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003727
3728multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3729 SPUInstr orinst32, SPUInstr brinst32>
3730{
3731 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3732 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3733 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3734 bb:$dest)>;
3735
3736 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3737 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3738 (CEQHr16 R16C:$rA, R16:$rB)),
3739 bb:$dest)>;
3740
3741 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3742 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3743 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3744 bb:$dest)>;
3745
3746 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3747 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3748 (CEQr32 R32C:$rA, R32C:$rB)),
3749 bb:$dest)>;
3750}
3751
Scott Michel06eabde2008-12-27 04:51:36 +00003752defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3753defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003754
Scott Michel8b6b4202007-12-04 22:35:58 +00003755let isTerminator = 1, isBarrier = 1 in {
3756 let isReturn = 1 in {
3757 def RET:
3758 RETForm<"bi\t$$lr", [(retflag)]>;
3759 }
3760}
3761
3762//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003763// Single precision floating point instructions
3764//===----------------------------------------------------------------------===//
3765
Scott Michel61895fe2008-12-10 00:15:19 +00003766class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3767 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003768 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003769
Scott Michel61895fe2008-12-10 00:15:19 +00003770class FAVecInst<ValueType vectype>:
3771 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3772 [(set (vectype VECREG:$rT),
Scott Michel4d07fb72008-12-30 23:28:25 +00003773 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003774
Scott Michel61895fe2008-12-10 00:15:19 +00003775multiclass SFPAdd
3776{
3777 def v4f32: FAVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003778 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3779 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003780}
Scott Michel8b6b4202007-12-04 22:35:58 +00003781
Scott Michel61895fe2008-12-10 00:15:19 +00003782defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003783
Scott Michel61895fe2008-12-10 00:15:19 +00003784class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3785 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003786 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003787
Scott Michel61895fe2008-12-10 00:15:19 +00003788class FSVecInst<ValueType vectype>:
3789 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00003790 [(set (vectype VECREG:$rT),
3791 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003792
3793multiclass SFPSub
3794{
3795 def v4f32: FSVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003796 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3797 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003798}
3799
3800defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003801
3802// Floating point reciprocal estimate
Scott Michel8b6b4202007-12-04 22:35:58 +00003803
Scott Michel4d07fb72008-12-30 23:28:25 +00003804class FRESTInst<dag OOL, dag IOL>:
3805 RRForm_1<0b00110111000, OOL, IOL,
3806 "frest\t$rT, $rA", SPrecFP,
3807 [/* no pattern */]>;
3808
3809def FRESTv4f32 :
3810 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3811
3812def FRESTf32 :
3813 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003814
3815// Floating point interpolate (used in conjunction with reciprocal estimate)
3816def FIv4f32 :
3817 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3818 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003819 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003820
3821def FIf32 :
3822 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3823 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003824 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003825
Scott Michel33d73eb2008-11-21 02:56:16 +00003826//--------------------------------------------------------------------------
3827// Basic single precision floating point comparisons:
3828//
3829// Note: There is no support on SPU for single precision NaN. Consequently,
3830// ordered and unordered comparisons are the same.
3831//--------------------------------------------------------------------------
3832
Scott Michel8b6b4202007-12-04 22:35:58 +00003833def FCEQf32 :
3834 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3835 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003836 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3837
3838def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3839 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003840
3841def FCMEQf32 :
3842 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3843 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003844 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3845
3846def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3847 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003848
3849def FCGTf32 :
3850 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3851 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003852 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3853
3854def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3855 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003856
3857def FCMGTf32 :
3858 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3859 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003860 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3861
3862def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3863 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3864
3865//--------------------------------------------------------------------------
3866// Single precision floating point comparisons and SETCC equivalents:
3867//--------------------------------------------------------------------------
3868
3869def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3870def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3871
3872def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3873def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3874
3875def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3876def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3877
3878def : Pat<(setule R32FP:$rA, R32FP:$rB),
3879 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3880def : Pat<(setole R32FP:$rA, R32FP:$rB),
3881 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003882
3883// FP Status and Control Register Write
3884// Why isn't rT a don't care in the ISA?
3885// Should we create a special RRForm_3 for this guy and zero out the rT?
3886def FSCRWf32 :
3887 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3888 "fscrwr\t$rA", SPrecFP,
3889 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3890
3891// FP Status and Control Register Read
3892def FSCRRf32 :
3893 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3894 "fscrrd\t$rT", SPrecFP,
3895 [/* This instruction requires an intrinsic */]>;
3896
3897// llvm instruction space
3898// How do these map onto cell instructions?
3899// fdiv rA rB
3900// frest rC rB # c = 1/b (both lines)
3901// fi rC rB rC
3902// fm rD rA rC # d = a * 1/b
3903// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3904// fma rB rB rC rD # b = b * c + d
3905// = -(d *b -a) * c + d
3906// = a * c - c ( a *b *c - a)
3907
3908// fcopysign (???)
3909
3910// Library calls:
3911// These llvm instructions will actually map to library calls.
3912// All that's needed, then, is to check that the appropriate library is
3913// imported and do a brsl to the proper function name.
3914// frem # fmod(x, y): x - (x/y) * y
3915// (Note: fmod(double, double), fmodf(float,float)
3916// fsqrt?
3917// fsin?
3918// fcos?
3919// Unimplemented SPU instruction space
3920// floating reciprocal absolute square root estimate (frsqest)
3921
3922// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00003923// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00003924// status and control register read
3925
3926//--------------------------------------
3927// Floating point multiply instructions
3928//--------------------------------------
3929
3930def FMv4f32:
3931 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3932 "fm\t$rT, $rA, $rB", SPrecFP,
3933 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3934 (v4f32 VECREG:$rB)))]>;
3935
3936def FMf32 :
3937 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3938 "fm\t$rT, $rA, $rB", SPrecFP,
3939 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3940
3941// Floating point multiply and add
3942// e.g. d = c + (a * b)
3943def FMAv4f32:
3944 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3945 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3946 [(set (v4f32 VECREG:$rT),
3947 (fadd (v4f32 VECREG:$rC),
3948 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3949
3950def FMAf32:
3951 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3952 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3953 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3954
3955// FP multiply and subtract
3956// Subtracts value in rC from product
3957// res = a * b - c
3958def FMSv4f32 :
3959 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3960 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3961 [(set (v4f32 VECREG:$rT),
3962 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3963 (v4f32 VECREG:$rC)))]>;
3964
3965def FMSf32 :
3966 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3967 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3968 [(set R32FP:$rT,
3969 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3970
3971// Floating Negative Mulitply and Subtract
3972// Subtracts product from value in rC
3973// res = fneg(fms a b c)
3974// = - (a * b - c)
3975// = c - a * b
3976// NOTE: subtraction order
3977// fsub a b = a - b
Scott Michel06eabde2008-12-27 04:51:36 +00003978// fs a b = b - a?
Scott Michel8b6b4202007-12-04 22:35:58 +00003979def FNMSf32 :
3980 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3981 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3982 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3983
3984def FNMSv4f32 :
3985 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3986 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00003987 [(set (v4f32 VECREG:$rT),
3988 (fsub (v4f32 VECREG:$rC),
3989 (fmul (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00003990 (v4f32 VECREG:$rB))))]>;
3991
3992//--------------------------------------
3993// Floating Point Conversions
3994// Signed conversions:
3995def CSiFv4f32:
3996 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3997 "csflt\t$rT, $rA, 0", SPrecFP,
3998 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3999
Scott Michel06eabde2008-12-27 04:51:36 +00004000// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00004001def CSiFf32 :
4002 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4003 "csflt\t$rT, $rA, 0", SPrecFP,
4004 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4005
4006// Convert unsigned into to float
4007def CUiFv4f32 :
4008 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4009 "cuflt\t$rT, $rA, 0", SPrecFP,
4010 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4011
4012def CUiFf32 :
4013 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4014 "cuflt\t$rT, $rA, 0", SPrecFP,
4015 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4016
Scott Michel06eabde2008-12-27 04:51:36 +00004017// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004018// Assume that scale = 0
4019
4020def CFUiv4f32 :
4021 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4022 "cfltu\t$rT, $rA, 0", SPrecFP,
4023 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4024
4025def CFUif32 :
4026 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4027 "cfltu\t$rT, $rA, 0", SPrecFP,
4028 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4029
Scott Michel06eabde2008-12-27 04:51:36 +00004030// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004031// Assume that scale = 0
4032
4033def CFSiv4f32 :
4034 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4035 "cflts\t$rT, $rA, 0", SPrecFP,
4036 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4037
4038def CFSif32 :
4039 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4040 "cflts\t$rT, $rA, 0", SPrecFP,
4041 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4042
4043//===----------------------------------------------------------------------==//
4044// Single<->Double precision conversions
4045//===----------------------------------------------------------------------==//
4046
4047// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4048// v4f32, output is v2f64--which goes in the name?)
4049
4050// Floating point extend single to double
4051// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4052// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4053// are ignored).
4054def FESDvec :
4055 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4056 "fesd\t$rT, $rA", SPrecFP,
4057 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4058
4059def FESDf32 :
4060 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4061 "fesd\t$rT, $rA", SPrecFP,
4062 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4063
4064// Floating point round double to single
4065//def FRDSvec :
4066// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4067// "frds\t$rT, $rA,", SPrecFP,
4068// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4069
4070def FRDSf64 :
4071 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4072 "frds\t$rT, $rA", SPrecFP,
4073 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4074
4075//ToDo include anyextend?
4076
4077//===----------------------------------------------------------------------==//
4078// Double precision floating point instructions
4079//===----------------------------------------------------------------------==//
4080def FAf64 :
4081 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4082 "dfa\t$rT, $rA, $rB", DPrecFP,
4083 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4084
4085def FAv2f64 :
4086 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4087 "dfa\t$rT, $rA, $rB", DPrecFP,
4088 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4089
4090def FSf64 :
4091 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4092 "dfs\t$rT, $rA, $rB", DPrecFP,
4093 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4094
4095def FSv2f64 :
4096 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4097 "dfs\t$rT, $rA, $rB", DPrecFP,
4098 [(set (v2f64 VECREG:$rT),
4099 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4100
4101def FMf64 :
4102 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4103 "dfm\t$rT, $rA, $rB", DPrecFP,
4104 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4105
4106def FMv2f64:
4107 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4108 "dfm\t$rT, $rA, $rB", DPrecFP,
4109 [(set (v2f64 VECREG:$rT),
4110 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4111
4112def FMAf64:
4113 RRForm<0b00111010110, (outs R64FP:$rT),
4114 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4115 "dfma\t$rT, $rA, $rB", DPrecFP,
4116 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4117 RegConstraint<"$rC = $rT">,
4118 NoEncode<"$rC">;
4119
4120def FMAv2f64:
4121 RRForm<0b00111010110, (outs VECREG:$rT),
4122 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4123 "dfma\t$rT, $rA, $rB", DPrecFP,
4124 [(set (v2f64 VECREG:$rT),
4125 (fadd (v2f64 VECREG:$rC),
4126 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4127 RegConstraint<"$rC = $rT">,
4128 NoEncode<"$rC">;
4129
4130def FMSf64 :
4131 RRForm<0b10111010110, (outs R64FP:$rT),
4132 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4133 "dfms\t$rT, $rA, $rB", DPrecFP,
4134 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4135 RegConstraint<"$rC = $rT">,
4136 NoEncode<"$rC">;
4137
4138def FMSv2f64 :
4139 RRForm<0b10111010110, (outs VECREG:$rT),
4140 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4141 "dfms\t$rT, $rA, $rB", DPrecFP,
4142 [(set (v2f64 VECREG:$rT),
4143 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4144 (v2f64 VECREG:$rC)))]>;
4145
4146// FNMS: - (a * b - c)
4147// - (a * b) + c => c - (a * b)
4148def FNMSf64 :
4149 RRForm<0b01111010110, (outs R64FP:$rT),
4150 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4151 "dfnms\t$rT, $rA, $rB", DPrecFP,
4152 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4153 RegConstraint<"$rC = $rT">,
4154 NoEncode<"$rC">;
4155
4156def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4157 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4158
4159def FNMSv2f64 :
4160 RRForm<0b01111010110, (outs VECREG:$rT),
4161 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4162 "dfnms\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004163 [(set (v2f64 VECREG:$rT),
4164 (fsub (v2f64 VECREG:$rC),
4165 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004166 (v2f64 VECREG:$rB))))]>,
4167 RegConstraint<"$rC = $rT">,
4168 NoEncode<"$rC">;
4169
4170def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4171 (v2f64 VECREG:$rC))),
4172 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4173
4174// - (a * b + c)
4175// - (a * b) - c
4176def FNMAf64 :
4177 RRForm<0b11111010110, (outs R64FP:$rT),
4178 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4179 "dfnma\t$rT, $rA, $rB", DPrecFP,
4180 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4181 RegConstraint<"$rC = $rT">,
4182 NoEncode<"$rC">;
4183
4184def FNMAv2f64 :
4185 RRForm<0b11111010110, (outs VECREG:$rT),
4186 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4187 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004188 [(set (v2f64 VECREG:$rT),
4189 (fneg (fadd (v2f64 VECREG:$rC),
4190 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004191 (v2f64 VECREG:$rB)))))]>,
4192 RegConstraint<"$rC = $rT">,
4193 NoEncode<"$rC">;
4194
4195//===----------------------------------------------------------------------==//
4196// Floating point negation and absolute value
4197//===----------------------------------------------------------------------==//
4198
4199def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00004200 (XORfnegvec (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004201 (v4f32 (ILHUv4i32 0x8000)))>;
4202
4203def : Pat<(fneg R32FP:$rA),
4204 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4205
4206def : Pat<(fneg (v2f64 VECREG:$rA)),
4207 (XORfnegvec (v2f64 VECREG:$rA),
4208 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4209
4210def : Pat<(fneg R64FP:$rA),
4211 (XORfneg64 R64FP:$rA,
4212 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4213
4214// Floating point absolute value
4215
4216def : Pat<(fabs R32FP:$rA),
4217 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4218
4219def : Pat<(fabs (v4f32 VECREG:$rA)),
4220 (ANDfabsvec (v4f32 VECREG:$rA),
4221 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4222
4223def : Pat<(fabs R64FP:$rA),
4224 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4225
4226def : Pat<(fabs (v2f64 VECREG:$rA)),
4227 (ANDfabsvec (v2f64 VECREG:$rA),
4228 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4229
4230//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004231// Hint for branch instructions:
4232//===----------------------------------------------------------------------===//
4233
4234/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4235
4236//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004237// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4238// in the odd pipeline)
4239//===----------------------------------------------------------------------===//
4240
Scott Michel97872d32008-02-23 18:41:37 +00004241def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004242 let Pattern = [];
4243
4244 let Inst{0-10} = 0b10000000010;
4245 let Inst{11-17} = 0;
4246 let Inst{18-24} = 0;
4247 let Inst{25-31} = 0;
4248}
4249
Scott Michel97872d32008-02-23 18:41:37 +00004250def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004251 let Pattern = [];
4252
4253 let Inst{0-10} = 0b10000000000;
4254 let Inst{11-17} = 0;
4255 let Inst{18-24} = 0;
4256 let Inst{25-31} = 0;
4257}
4258
4259//===----------------------------------------------------------------------===//
4260// Bit conversions (type conversions between vector/packed types)
4261// NOTE: Promotions are handled using the XS* instructions. Truncation
4262// is not handled.
4263//===----------------------------------------------------------------------===//
4264def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4265def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4266def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4267def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4268def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4269
4270def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4271def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4272def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4273def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4274def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4275
4276def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4277def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4278def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4279def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4280def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4281
4282def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4283def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4284def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4285def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4286def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4287
4288def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4289def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4290def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4291def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4292def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4293
4294def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4295def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4296def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4297def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4298def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4299
4300def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00004301def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004302
4303//===----------------------------------------------------------------------===//
4304// Instruction patterns:
4305//===----------------------------------------------------------------------===//
4306
4307// General 32-bit constants:
4308def : Pat<(i32 imm:$imm),
4309 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4310
4311// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004312def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004313 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4314
4315// General constant 32-bit vectors
4316def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004317 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4318 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004319
Scott Michel438be252007-12-17 22:32:34 +00004320// 8-bit constants
4321def : Pat<(i8 imm:$imm),
4322 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004323
4324//===----------------------------------------------------------------------===//
4325// Call instruction patterns:
4326//===----------------------------------------------------------------------===//
4327// Return void
4328def : Pat<(ret),
4329 (RET)>;
4330
4331//===----------------------------------------------------------------------===//
4332// Zero/Any/Sign extensions
4333//===----------------------------------------------------------------------===//
4334
Scott Michel8b6b4202007-12-04 22:35:58 +00004335// sext 8->32: Sign extend bytes to words
4336def : Pat<(sext_inreg R32C:$rSrc, i8),
4337 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4338
Scott Michel438be252007-12-17 22:32:34 +00004339def : Pat<(i32 (sext R8C:$rSrc)),
4340 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4341
Scott Michel438be252007-12-17 22:32:34 +00004342// zext 8->16: Zero extend bytes to halfwords
4343def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004344 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004345
Scott Michel438be252007-12-17 22:32:34 +00004346// zext 8->32: Zero extend bytes to words
4347def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004348 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004349
4350// anyext 8->16: Extend 8->16 bits, irrespective of sign
4351def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004352 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004353
4354// anyext 8->32: Extend 8->32 bits, irrespective of sign
4355def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004356 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004357
Scott Michel97872d32008-02-23 18:41:37 +00004358// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004359def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004360 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004361
4362def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004363 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004364
4365def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004366 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004367
4368def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004369 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004370
4371// anyext 16->32: Extend 16->32 bits, irrespective of sign
4372def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004373 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004374
4375//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004376// Truncates:
4377// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4378// above are custom lowered.
4379//===----------------------------------------------------------------------===//
4380
4381def : Pat<(i8 (trunc GPRC:$src)),
4382 (ORi8_v16i8
4383 (SHUFBgprc GPRC:$src, GPRC:$src,
4384 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4385
4386def : Pat<(i8 (trunc R64C:$src)),
4387 (ORi8_v16i8
4388 (SHUFBv2i64_m32
4389 (ORv2i64_i64 R64C:$src),
4390 (ORv2i64_i64 R64C:$src),
4391 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4392
4393def : Pat<(i8 (trunc R32C:$src)),
4394 (ORi8_v16i8
4395 (SHUFBv4i32_m32
4396 (ORv4i32_i32 R32C:$src),
4397 (ORv4i32_i32 R32C:$src),
4398 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4399
4400def : Pat<(i8 (trunc R16C:$src)),
4401 (ORi8_v16i8
4402 (SHUFBv4i32_m32
4403 (ORv8i16_i16 R16C:$src),
4404 (ORv8i16_i16 R16C:$src),
4405 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4406
4407def : Pat<(i16 (trunc GPRC:$src)),
4408 (ORi16_v8i16
4409 (SHUFBgprc GPRC:$src, GPRC:$src,
4410 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4411
4412def : Pat<(i16 (trunc R64C:$src)),
4413 (ORi16_v8i16
4414 (SHUFBv2i64_m32
4415 (ORv2i64_i64 R64C:$src),
4416 (ORv2i64_i64 R64C:$src),
4417 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4418
4419def : Pat<(i16 (trunc R32C:$src)),
4420 (ORi16_v8i16
4421 (SHUFBv4i32_m32
4422 (ORv4i32_i32 R32C:$src),
4423 (ORv4i32_i32 R32C:$src),
4424 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4425
4426def : Pat<(i32 (trunc GPRC:$src)),
4427 (ORi32_v4i32
4428 (SHUFBgprc GPRC:$src, GPRC:$src,
4429 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4430
4431def : Pat<(i32 (trunc R64C:$src)),
4432 (ORi32_v4i32
4433 (SHUFBv2i64_m32
4434 (ORv2i64_i64 R64C:$src),
4435 (ORv2i64_i64 R64C:$src),
4436 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4437
4438//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004439// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004440// low parts in order to load them into a register.
4441//===----------------------------------------------------------------------===//
4442
Scott Michelf9f42e62008-01-29 02:16:57 +00004443def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4444def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4445def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4446def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4447
4448def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4449 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004450 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004451
Scott Michelf9f42e62008-01-29 02:16:57 +00004452def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4453 (SPUlo texternalsym:$in, 0)),
4454 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4455
4456def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4457 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004458 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004459
Scott Michelf9f42e62008-01-29 02:16:57 +00004460def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4461 (SPUlo tconstpool:$in, 0)),
4462 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4463
Scott Michel4d07fb72008-12-30 23:28:25 +00004464/*
Scott Michelbc5fbc12008-04-30 00:30:08 +00004465def : Pat<(SPUindirect R32C:$sp, i32ImmSExt10:$imm),
4466 (AIr32 R32C:$sp, i32ImmSExt10:$imm)>;
4467
4468def : Pat<(SPUindirect R32C:$sp, imm:$imm),
4469 (Ar32 R32C:$sp,
4470 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm)))>;
Scott Michel4d07fb72008-12-30 23:28:25 +00004471 */
Scott Michelbc5fbc12008-04-30 00:30:08 +00004472
Scott Michelf9f42e62008-01-29 02:16:57 +00004473def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4474 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4475
4476def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4477 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4478
4479def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4480 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4481
4482def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4483 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004484
Scott Michel8b6b4202007-12-04 22:35:58 +00004485// Instrinsics:
4486include "CellSDKIntrinsics.td"
Scott Michel4d07fb72008-12-30 23:28:25 +00004487// Various math operator instruction sequences
4488include "SPUMathInstr.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004489// 64-bit "instructions"/support
4490include "SPU64InstrInfo.td"