blob: 250a57dd128d79d373632e85c2739e68d47561b1 [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
Scott Michelc899a122009-01-26 22:33:37 +000037def DWARF_LOC : Pseudo<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
38 ".loc $file, $line, $col",
39 [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +000040
41//===----------------------------------------------------------------------===//
42// Loads:
43// NB: The ordering is actually important, since the instruction selection
44// will try each of the instructions in sequence, i.e., the D-form first with
45// the 10-bit displacement, then the A-form with the 16 bit displacement, and
46// finally the X-form with the register-register.
47//===----------------------------------------------------------------------===//
48
Dan Gohman5574cc72008-12-03 18:15:48 +000049let canFoldAsLoad = 1 in {
Scott Michelf9f42e62008-01-29 02:16:57 +000050 class LoadDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +000051 : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000052 "lqd\t$rT, $src",
53 LoadStore,
54 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
55 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000056
Scott Michelf9f42e62008-01-29 02:16:57 +000057 class LoadDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +000058 : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +000059 "lqd\t$rT, $src",
60 LoadStore,
61 [(set rclass:$rT, (load dform_addr:$src))]>
62 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000063
Scott Michelf9f42e62008-01-29 02:16:57 +000064 multiclass LoadDForms
65 {
66 def v16i8: LoadDFormVec<v16i8>;
67 def v8i16: LoadDFormVec<v8i16>;
68 def v4i32: LoadDFormVec<v4i32>;
69 def v2i64: LoadDFormVec<v2i64>;
70 def v4f32: LoadDFormVec<v4f32>;
71 def v2f64: LoadDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000072
Scott Michel70741542009-01-06 23:10:38 +000073 def v2i32: LoadDFormVec<v2i32>;
74
Scott Michelf9f42e62008-01-29 02:16:57 +000075 def r128: LoadDForm<GPRC>;
76 def r64: LoadDForm<R64C>;
77 def r32: LoadDForm<R32C>;
78 def f32: LoadDForm<R32FP>;
79 def f64: LoadDForm<R64FP>;
80 def r16: LoadDForm<R16C>;
81 def r8: LoadDForm<R8C>;
82 }
Scott Michel8b6b4202007-12-04 22:35:58 +000083
Scott Michelf9f42e62008-01-29 02:16:57 +000084 class LoadAFormVec<ValueType vectype>
85 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
86 "lqa\t$rT, $src",
87 LoadStore,
88 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
89 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000090
Scott Michelf9f42e62008-01-29 02:16:57 +000091 class LoadAForm<RegisterClass rclass>
92 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
93 "lqa\t$rT, $src",
94 LoadStore,
95 [(set rclass:$rT, (load aform_addr:$src))]>
96 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000097
Scott Michelf9f42e62008-01-29 02:16:57 +000098 multiclass LoadAForms
99 {
100 def v16i8: LoadAFormVec<v16i8>;
101 def v8i16: LoadAFormVec<v8i16>;
102 def v4i32: LoadAFormVec<v4i32>;
103 def v2i64: LoadAFormVec<v2i64>;
104 def v4f32: LoadAFormVec<v4f32>;
105 def v2f64: LoadAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000106
Scott Michel70741542009-01-06 23:10:38 +0000107 def v2i32: LoadAFormVec<v2i32>;
108
Scott Michelf9f42e62008-01-29 02:16:57 +0000109 def r128: LoadAForm<GPRC>;
110 def r64: LoadAForm<R64C>;
111 def r32: LoadAForm<R32C>;
112 def f32: LoadAForm<R32FP>;
113 def f64: LoadAForm<R64FP>;
114 def r16: LoadAForm<R16C>;
115 def r8: LoadAForm<R8C>;
116 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000117
Scott Michelf9f42e62008-01-29 02:16:57 +0000118 class LoadXFormVec<ValueType vectype>
119 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
120 "lqx\t$rT, $src",
121 LoadStore,
122 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
123 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000124
Scott Michelf9f42e62008-01-29 02:16:57 +0000125 class LoadXForm<RegisterClass rclass>
126 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
127 "lqx\t$rT, $src",
128 LoadStore,
129 [(set rclass:$rT, (load xform_addr:$src))]>
130 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000131
Scott Michelf9f42e62008-01-29 02:16:57 +0000132 multiclass LoadXForms
133 {
134 def v16i8: LoadXFormVec<v16i8>;
135 def v8i16: LoadXFormVec<v8i16>;
136 def v4i32: LoadXFormVec<v4i32>;
137 def v2i64: LoadXFormVec<v2i64>;
138 def v4f32: LoadXFormVec<v4f32>;
139 def v2f64: LoadXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000140
Scott Michel70741542009-01-06 23:10:38 +0000141 def v2i32: LoadXFormVec<v2i32>;
142
Scott Michelf9f42e62008-01-29 02:16:57 +0000143 def r128: LoadXForm<GPRC>;
144 def r64: LoadXForm<R64C>;
145 def r32: LoadXForm<R32C>;
146 def f32: LoadXForm<R32FP>;
147 def f64: LoadXForm<R64FP>;
148 def r16: LoadXForm<R16C>;
149 def r8: LoadXForm<R8C>;
150 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000151
Scott Michelf9f42e62008-01-29 02:16:57 +0000152 defm LQA : LoadAForms;
153 defm LQD : LoadDForms;
154 defm LQX : LoadXForms;
Scott Michel438be252007-12-17 22:32:34 +0000155
Scott Michel8b6b4202007-12-04 22:35:58 +0000156/* Load quadword, PC relative: Not much use at this point in time.
Scott Michelf9f42e62008-01-29 02:16:57 +0000157 Might be of use later for relocatable code. It's effectively the
158 same as LQA, but uses PC-relative addressing.
Scott Michel8b6b4202007-12-04 22:35:58 +0000159 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
160 "lqr\t$rT, $disp", LoadStore,
161 [(set VECREG:$rT, (load iaddr:$disp))]>;
162 */
Scott Michel8b6b4202007-12-04 22:35:58 +0000163}
164
165//===----------------------------------------------------------------------===//
166// Stores:
167//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +0000168class StoreDFormVec<ValueType vectype>
Scott Michel06eabde2008-12-27 04:51:36 +0000169 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000170 "stqd\t$rT, $src",
171 LoadStore,
172 [(store (vectype VECREG:$rT), dform_addr:$src)]>
173{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000174
Scott Michelf9f42e62008-01-29 02:16:57 +0000175class StoreDForm<RegisterClass rclass>
Scott Michel06eabde2008-12-27 04:51:36 +0000176 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michelf9f42e62008-01-29 02:16:57 +0000177 "stqd\t$rT, $src",
178 LoadStore,
179 [(store rclass:$rT, dform_addr:$src)]>
180{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000181
Scott Michelf9f42e62008-01-29 02:16:57 +0000182multiclass StoreDForms
183{
184 def v16i8: StoreDFormVec<v16i8>;
185 def v8i16: StoreDFormVec<v8i16>;
186 def v4i32: StoreDFormVec<v4i32>;
187 def v2i64: StoreDFormVec<v2i64>;
188 def v4f32: StoreDFormVec<v4f32>;
189 def v2f64: StoreDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000190
Scott Michel70741542009-01-06 23:10:38 +0000191 def v2i32: StoreDFormVec<v2i32>;
192
Scott Michelf9f42e62008-01-29 02:16:57 +0000193 def r128: StoreDForm<GPRC>;
194 def r64: StoreDForm<R64C>;
195 def r32: StoreDForm<R32C>;
196 def f32: StoreDForm<R32FP>;
197 def f64: StoreDForm<R64FP>;
198 def r16: StoreDForm<R16C>;
199 def r8: StoreDForm<R8C>;
200}
Scott Michel8b6b4202007-12-04 22:35:58 +0000201
Scott Michelf9f42e62008-01-29 02:16:57 +0000202class StoreAFormVec<ValueType vectype>
203 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000204 "stqa\t$rT, $src",
205 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000206 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000207
Scott Michelf9f42e62008-01-29 02:16:57 +0000208class StoreAForm<RegisterClass rclass>
209 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000210 "stqa\t$rT, $src",
211 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000212 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000213
Scott Michelf9f42e62008-01-29 02:16:57 +0000214multiclass StoreAForms
215{
216 def v16i8: StoreAFormVec<v16i8>;
217 def v8i16: StoreAFormVec<v8i16>;
218 def v4i32: StoreAFormVec<v4i32>;
219 def v2i64: StoreAFormVec<v2i64>;
220 def v4f32: StoreAFormVec<v4f32>;
221 def v2f64: StoreAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000222
Scott Michel70741542009-01-06 23:10:38 +0000223 def v2i32: StoreAFormVec<v2i32>;
224
Scott Michelf9f42e62008-01-29 02:16:57 +0000225 def r128: StoreAForm<GPRC>;
226 def r64: StoreAForm<R64C>;
227 def r32: StoreAForm<R32C>;
228 def f32: StoreAForm<R32FP>;
229 def f64: StoreAForm<R64FP>;
230 def r16: StoreAForm<R16C>;
231 def r8: StoreAForm<R8C>;
232}
Scott Michel8b6b4202007-12-04 22:35:58 +0000233
Scott Michelf9f42e62008-01-29 02:16:57 +0000234class StoreXFormVec<ValueType vectype>
235 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000236 "stqx\t$rT, $src",
237 LoadStore,
238 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000239{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000240
Scott Michelf9f42e62008-01-29 02:16:57 +0000241class StoreXForm<RegisterClass rclass>
242 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000243 "stqx\t$rT, $src",
244 LoadStore,
245 [(store rclass:$rT, xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000246{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000247
Scott Michelf9f42e62008-01-29 02:16:57 +0000248multiclass StoreXForms
249{
250 def v16i8: StoreXFormVec<v16i8>;
251 def v8i16: StoreXFormVec<v8i16>;
252 def v4i32: StoreXFormVec<v4i32>;
253 def v2i64: StoreXFormVec<v2i64>;
254 def v4f32: StoreXFormVec<v4f32>;
255 def v2f64: StoreXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000256
Scott Michel70741542009-01-06 23:10:38 +0000257 def v2i32: StoreXFormVec<v2i32>;
258
Scott Michelf9f42e62008-01-29 02:16:57 +0000259 def r128: StoreXForm<GPRC>;
260 def r64: StoreXForm<R64C>;
261 def r32: StoreXForm<R32C>;
262 def f32: StoreXForm<R32FP>;
263 def f64: StoreXForm<R64FP>;
264 def r16: StoreXForm<R16C>;
265 def r8: StoreXForm<R8C>;
266}
Scott Michel8b6b4202007-12-04 22:35:58 +0000267
Scott Michelf9f42e62008-01-29 02:16:57 +0000268defm STQD : StoreDForms;
269defm STQA : StoreAForms;
270defm STQX : StoreXForms;
Scott Michel8b6b4202007-12-04 22:35:58 +0000271
272/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michelf9f42e62008-01-29 02:16:57 +0000273 be useful for relocatable code.
Chris Lattneref8d6082008-01-06 06:44:58 +0000274def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
275 "stqr\t$rT, $disp", LoadStore,
276 [(store VECREG:$rT, iaddr:$disp)]>;
277*/
Scott Michel8b6b4202007-12-04 22:35:58 +0000278
279//===----------------------------------------------------------------------===//
280// Generate Controls for Insertion:
281//===----------------------------------------------------------------------===//
282
Scott Michel06eabde2008-12-27 04:51:36 +0000283def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000284 "cbd\t$rT, $src", ShuffleOp,
285 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000286
Scott Michel0718cd82008-12-01 17:56:02 +0000287def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000288 "cbx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000289 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000290
Scott Michel06eabde2008-12-27 04:51:36 +0000291def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000292 "chd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000293 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000294
Scott Michel0718cd82008-12-01 17:56:02 +0000295def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000296 "chx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000297 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000298
Scott Michel06eabde2008-12-27 04:51:36 +0000299def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000300 "cwd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000301 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000302
Scott Michel0718cd82008-12-01 17:56:02 +0000303def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000304 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000305 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000306
Scott Michel06eabde2008-12-27 04:51:36 +0000307def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000308 "cwd\t$rT, $src", ShuffleOp,
309 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
310
311def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000312 "cwx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000313 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000314
Scott Michel06eabde2008-12-27 04:51:36 +0000315def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000316 "cdd\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000317 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000318
Scott Michel0718cd82008-12-01 17:56:02 +0000319def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel8b6b4202007-12-04 22:35:58 +0000320 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000321 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000322
Scott Michel06eabde2008-12-27 04:51:36 +0000323def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel0718cd82008-12-01 17:56:02 +0000324 "cdd\t$rT, $src", ShuffleOp,
325 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
326
327def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michelbc5fbc12008-04-30 00:30:08 +0000328 "cdx\t$rT, $src", ShuffleOp,
Scott Michel56a125e2008-11-22 23:50:42 +0000329 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000330
Scott Michel8b6b4202007-12-04 22:35:58 +0000331//===----------------------------------------------------------------------===//
332// Constant formation:
333//===----------------------------------------------------------------------===//
334
335def ILHv8i16:
336 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
337 "ilh\t$rT, $val", ImmLoad,
338 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
339
340def ILHr16:
341 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
342 "ilh\t$rT, $val", ImmLoad,
343 [(set R16C:$rT, immSExt16:$val)]>;
344
Scott Michel438be252007-12-17 22:32:34 +0000345// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
346// the right constant")
347def ILHr8:
348 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
349 "ilh\t$rT, $val", ImmLoad,
350 [(set R8C:$rT, immSExt8:$val)]>;
351
Scott Michel8b6b4202007-12-04 22:35:58 +0000352// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000353
Scott Michel6baba072008-03-05 23:02:02 +0000354class ILInst<dag OOL, dag IOL, list<dag> pattern>:
355 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
356 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000357
Scott Michel6baba072008-03-05 23:02:02 +0000358class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
359 ILInst<(outs VECREG:$rT), (ins immtype:$val),
360 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000361
Scott Michel6baba072008-03-05 23:02:02 +0000362class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
363 ILInst<(outs rclass:$rT), (ins immtype:$val),
364 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000365
Scott Michel6baba072008-03-05 23:02:02 +0000366multiclass ImmediateLoad
367{
368 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
369 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000370
Scott Michel6baba072008-03-05 23:02:02 +0000371 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000372
Scott Michel6baba072008-03-05 23:02:02 +0000373 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
374 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
375 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
376 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
377}
Scott Michel8b6b4202007-12-04 22:35:58 +0000378
Scott Michel6baba072008-03-05 23:02:02 +0000379defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000380
Scott Michel6baba072008-03-05 23:02:02 +0000381class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
382 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
383 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000384
Scott Michel6baba072008-03-05 23:02:02 +0000385class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
386 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
387 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
388
389class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
390 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
391 [(set rclass:$rT, xform:$val)]>;
392
393multiclass ImmLoadHalfwordUpper
394{
395 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000396 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000397
398 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000399 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000400
401 // Loads the high portion of an address
402 def hi: ILHURegInst<R32C, symbolHi, hi16>;
403
404 // Used in custom lowering constant SFP loads:
405 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
406}
407
408defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000409
410// Immediate load address (can also be used to load 18-bit unsigned constants,
411// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000412
Scott Michel97872d32008-02-23 18:41:37 +0000413class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
414 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
415 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000416
Scott Michel6baba072008-03-05 23:02:02 +0000417class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
418 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
419 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
420
421class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
422 ILAInst<(outs rclass:$rT), (ins immtype:$val),
423 [(set rclass:$rT, xform:$val)]>;
424
Scott Michel97872d32008-02-23 18:41:37 +0000425multiclass ImmLoadAddress
426{
Scott Michel6baba072008-03-05 23:02:02 +0000427 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
428 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000429
Scott Michel6baba072008-03-05 23:02:02 +0000430 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
431 def r32: ILARegInst<R32C, u18imm, imm18>;
432 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
433 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000434
Scott Michel06eabde2008-12-27 04:51:36 +0000435 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michel6baba072008-03-05 23:02:02 +0000436 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000437
Scott Michel97872d32008-02-23 18:41:37 +0000438 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
439 [/* no pattern */]>;
440}
441
442defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000443
444// Immediate OR, Halfword Lower: The "other" part of loading large constants
445// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
446// Note that these are really two operand instructions, but they're encoded
447// as three operands with the first two arguments tied-to each other.
448
Scott Michel6baba072008-03-05 23:02:02 +0000449class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
450 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
451 ImmLoad, pattern>,
452 RegConstraint<"$rS = $rT">,
453 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000454
Scott Michel6baba072008-03-05 23:02:02 +0000455class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
456 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
457 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000458
Scott Michel6baba072008-03-05 23:02:02 +0000459class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
460 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
461 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000462
Scott Michel6baba072008-03-05 23:02:02 +0000463multiclass ImmOrHalfwordLower
464{
465 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000466 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000467
468 def r32: IOHLRegInst<R32C, i32imm>;
469 def f32: IOHLRegInst<R32FP, f32imm>;
470
471 def lo: IOHLRegInst<R32C, symbolLo>;
472}
473
474defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000475
Scott Michel8b6b4202007-12-04 22:35:58 +0000476// Form select mask for bytes using immediate, used in conjunction with the
477// SELB instruction:
478
Scott Michel6baba072008-03-05 23:02:02 +0000479class FSMBIVec<ValueType vectype>:
480 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
481 "fsmbi\t$rT, $val",
482 SelectOp,
Scott Michel67224b22008-06-02 22:18:03 +0000483 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000484
Scott Michel97872d32008-02-23 18:41:37 +0000485multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000486{
487 def v16i8: FSMBIVec<v16i8>;
488 def v8i16: FSMBIVec<v8i16>;
489 def v4i32: FSMBIVec<v4i32>;
490 def v2i64: FSMBIVec<v2i64>;
491}
Scott Michel8b6b4202007-12-04 22:35:58 +0000492
Scott Michel97872d32008-02-23 18:41:37 +0000493defm FSMBI : FormSelectMaskBytesImm;
494
495// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michel06eabde2008-12-27 04:51:36 +0000496class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
497 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
498 pattern>;
499
500class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
501 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
502 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
503
504class FSMBVecInst<ValueType vectype>:
505 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
506 [(set (vectype VECREG:$rT),
507 (SPUselmask (vectype VECREG:$rA)))]>;
508
509multiclass FormSelectMaskBits {
510 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
511 def v16i8: FSMBVecInst<v16i8>;
512}
513
514defm FSMB: FormSelectMaskBits;
Scott Michel97872d32008-02-23 18:41:37 +0000515
516// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
517// only 8-bits wide (even though it's input as 16-bits here)
Scott Michel06eabde2008-12-27 04:51:36 +0000518
519class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
520 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
521 pattern>;
522
523class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
524 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
525 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
526
527class FSMHVecInst<ValueType vectype>:
528 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
529 [(set (vectype VECREG:$rT),
530 (SPUselmask (vectype VECREG:$rA)))]>;
531
532multiclass FormSelectMaskHalfword {
533 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
534 def v8i16: FSMHVecInst<v8i16>;
535}
536
537defm FSMH: FormSelectMaskHalfword;
Scott Michel97872d32008-02-23 18:41:37 +0000538
539// fsm: Form select mask for words. Like the other fsm* instructions,
540// only the lower 4 bits of $rA are significant.
Scott Michel06eabde2008-12-27 04:51:36 +0000541
542class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
543 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
544 pattern>;
545
546class FSMRegInst<ValueType vectype, RegisterClass rclass>:
547 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
548 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
549
550class FSMVecInst<ValueType vectype>:
551 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
552 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel67224b22008-06-02 22:18:03 +0000553
554multiclass FormSelectMaskWord {
Scott Michel06eabde2008-12-27 04:51:36 +0000555 def v4i32: FSMVecInst<v4i32>;
556
557 def r32 : FSMRegInst<v4i32, R32C>;
558 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000559}
560
561defm FSM : FormSelectMaskWord;
562
563// Special case when used for i64 math operations
564multiclass FormSelectMaskWord64 {
Scott Michel06eabde2008-12-27 04:51:36 +0000565 def r32 : FSMRegInst<v2i64, R32C>;
566 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel67224b22008-06-02 22:18:03 +0000567}
568
569defm FSM64 : FormSelectMaskWord64;
Scott Michel8b6b4202007-12-04 22:35:58 +0000570
571//===----------------------------------------------------------------------===//
572// Integer and Logical Operations:
573//===----------------------------------------------------------------------===//
574
575def AHv8i16:
576 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
577 "ah\t$rT, $rA, $rB", IntegerOp,
578 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
579
580def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
581 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
582
Scott Michel8b6b4202007-12-04 22:35:58 +0000583def AHr16:
584 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
585 "ah\t$rT, $rA, $rB", IntegerOp,
586 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
587
588def AHIvec:
589 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
590 "ahi\t$rT, $rA, $val", IntegerOp,
591 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
592 v8i16SExt10Imm:$val))]>;
593
Scott Michel97872d32008-02-23 18:41:37 +0000594def AHIr16:
595 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
596 "ahi\t$rT, $rA, $val", IntegerOp,
Scott Michel4d07fb72008-12-30 23:28:25 +0000597 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
598
599// v4i32, i32 add instruction:
Scott Michel8b6b4202007-12-04 22:35:58 +0000600
Scott Michelae5cbf52008-12-29 03:23:36 +0000601class AInst<dag OOL, dag IOL, list<dag> pattern>:
602 RRForm<0b00000011000, OOL, IOL,
603 "a\t$rT, $rA, $rB", IntegerOp,
604 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000605
Scott Michelae5cbf52008-12-29 03:23:36 +0000606class AVecInst<ValueType vectype>:
607 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
608 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
609 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000610
Scott Michelae5cbf52008-12-29 03:23:36 +0000611class ARegInst<RegisterClass rclass>:
612 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
613 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
614
615multiclass AddInstruction {
616 def v4i32: AVecInst<v4i32>;
617 def v16i8: AVecInst<v16i8>;
618
619 def r32: ARegInst<R32C>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000620}
Scott Michel8b6b4202007-12-04 22:35:58 +0000621
Scott Michelae5cbf52008-12-29 03:23:36 +0000622defm A : AddInstruction;
Scott Michel438be252007-12-17 22:32:34 +0000623
Scott Michel4d07fb72008-12-30 23:28:25 +0000624class AIInst<dag OOL, dag IOL, list<dag> pattern>:
625 RI10Form<0b00111000, OOL, IOL,
pingbakb8913342009-01-26 03:37:41 +0000626 "ai\t$rT, $rA, $val", IntegerOp,
627 pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000628
Scott Michel4d07fb72008-12-30 23:28:25 +0000629class AIVecInst<ValueType vectype, PatLeaf immpred>:
630 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
pingbakb8913342009-01-26 03:37:41 +0000631 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000632
633class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
634 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
pingbakb8913342009-01-26 03:37:41 +0000635 [/* no pattern */]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000636
637class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
638 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +0000639 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000640
641// This is used to add epsilons to floating point numbers in the f32 fdiv code:
642class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
643 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +0000644 [/* no pattern */]>;
Scott Michel4d07fb72008-12-30 23:28:25 +0000645
646multiclass AddImmediate {
647 def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
648
649 def r32: AIRegInst<R32C, i32ImmSExt10>;
650
651 def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
652 def f32: AIFPInst<R32FP, i32ImmSExt10>;
653}
654
655defm AI : AddImmediate;
Scott Michel8b6b4202007-12-04 22:35:58 +0000656
Scott Michel438be252007-12-17 22:32:34 +0000657def SFHvec:
658 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
659 "sfh\t$rT, $rA, $rB", IntegerOp,
660 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
661 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000662
Scott Michel438be252007-12-17 22:32:34 +0000663def SFHr16:
664 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
665 "sfh\t$rT, $rA, $rB", IntegerOp,
666 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000667
668def SFHIvec:
669 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
670 "sfhi\t$rT, $rA, $val", IntegerOp,
671 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
672 (v8i16 VECREG:$rA)))]>;
673
674def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
675 "sfhi\t$rT, $rA, $val", IntegerOp,
676 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
677
678def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
679 (ins VECREG:$rA, VECREG:$rB),
680 "sf\t$rT, $rA, $rB", IntegerOp,
681 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
682
683def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
684 "sf\t$rT, $rA, $rB", IntegerOp,
685 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
686
687def SFIvec:
688 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
689 "sfi\t$rT, $rA, $val", IntegerOp,
690 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
691 (v4i32 VECREG:$rA)))]>;
692
693def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
694 (ins R32C:$rA, s10imm_i32:$val),
695 "sfi\t$rT, $rA, $val", IntegerOp,
696 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
697
698// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000699class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
700 RRForm<0b00000010110, OOL, IOL,
701 "addx\t$rT, $rA, $rB",
702 IntegerOp, pattern>;
703
704class ADDXVecInst<ValueType vectype>:
705 ADDXInst<(outs VECREG:$rT),
706 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000707 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000708 RegConstraint<"$rCarry = $rT">,
709 NoEncode<"$rCarry">;
710
Scott Michel67224b22008-06-02 22:18:03 +0000711class ADDXRegInst<RegisterClass rclass>:
712 ADDXInst<(outs rclass:$rT),
713 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000714 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000715 RegConstraint<"$rCarry = $rT">,
716 NoEncode<"$rCarry">;
717
Scott Michel67224b22008-06-02 22:18:03 +0000718multiclass AddExtended {
719 def v2i64 : ADDXVecInst<v2i64>;
720 def v4i32 : ADDXVecInst<v4i32>;
721 def r64 : ADDXRegInst<R64C>;
722 def r32 : ADDXRegInst<R32C>;
723}
724
725defm ADDX : AddExtended;
726
727// CG: Generate carry for add
728class CGInst<dag OOL, dag IOL, list<dag> pattern>:
729 RRForm<0b01000011000, OOL, IOL,
730 "cg\t$rT, $rA, $rB",
731 IntegerOp, pattern>;
732
733class CGVecInst<ValueType vectype>:
734 CGInst<(outs VECREG:$rT),
735 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000736 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000737
738class CGRegInst<RegisterClass rclass>:
739 CGInst<(outs rclass:$rT),
740 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000741 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000742
743multiclass CarryGenerate {
744 def v2i64 : CGVecInst<v2i64>;
745 def v4i32 : CGVecInst<v4i32>;
746 def r64 : CGRegInst<R64C>;
747 def r32 : CGRegInst<R32C>;
748}
749
750defm CG : CarryGenerate;
751
752// SFX: Subract from, extended. This is used in conjunction with BG to subtract
753// with carry (borrow, in this case)
754class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
755 RRForm<0b10000010110, OOL, IOL,
756 "sfx\t$rT, $rA, $rB",
757 IntegerOp, pattern>;
758
759class SFXVecInst<ValueType vectype>:
760 SFXInst<(outs VECREG:$rT),
761 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000762 [/* no pattern */]>,
Scott Michel8b6b4202007-12-04 22:35:58 +0000763 RegConstraint<"$rCarry = $rT">,
764 NoEncode<"$rCarry">;
765
Scott Michel67224b22008-06-02 22:18:03 +0000766class SFXRegInst<RegisterClass rclass>:
767 SFXInst<(outs rclass:$rT),
768 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel750b93f2009-01-15 04:41:47 +0000769 [/* no pattern */]>,
Scott Michel67224b22008-06-02 22:18:03 +0000770 RegConstraint<"$rCarry = $rT">,
771 NoEncode<"$rCarry">;
772
773multiclass SubtractExtended {
774 def v2i64 : SFXVecInst<v2i64>;
775 def v4i32 : SFXVecInst<v4i32>;
776 def r64 : SFXRegInst<R64C>;
777 def r32 : SFXRegInst<R32C>;
778}
779
780defm SFX : SubtractExtended;
781
Scott Michel8b6b4202007-12-04 22:35:58 +0000782// BG: only available in vector form, doesn't match a pattern.
Scott Michel67224b22008-06-02 22:18:03 +0000783class BGInst<dag OOL, dag IOL, list<dag> pattern>:
784 RRForm<0b01000010000, OOL, IOL,
785 "bg\t$rT, $rA, $rB",
786 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000787
Scott Michel67224b22008-06-02 22:18:03 +0000788class BGVecInst<ValueType vectype>:
789 BGInst<(outs VECREG:$rT),
790 (ins VECREG:$rA, VECREG:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000791 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000792
793class BGRegInst<RegisterClass rclass>:
794 BGInst<(outs rclass:$rT),
795 (ins rclass:$rA, rclass:$rB),
Scott Michel750b93f2009-01-15 04:41:47 +0000796 [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +0000797
798multiclass BorrowGenerate {
799 def v4i32 : BGVecInst<v4i32>;
800 def v2i64 : BGVecInst<v2i64>;
801 def r64 : BGRegInst<R64C>;
802 def r32 : BGRegInst<R32C>;
803}
804
805defm BG : BorrowGenerate;
806
807// BGX: Borrow generate, extended.
Scott Michel8b6b4202007-12-04 22:35:58 +0000808def BGXvec:
809 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michel06eabde2008-12-27 04:51:36 +0000810 VECREG:$rCarry),
Scott Michel8b6b4202007-12-04 22:35:58 +0000811 "bgx\t$rT, $rA, $rB", IntegerOp,
812 []>,
813 RegConstraint<"$rCarry = $rT">,
814 NoEncode<"$rCarry">;
815
816// Halfword multiply variants:
817// N.B: These can be used to build up larger quantities (16x16 -> 32)
818
819def MPYv8i16:
820 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
821 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000822 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000823
824def MPYr16:
825 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
826 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
827 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
828
Scott Michelae5cbf52008-12-29 03:23:36 +0000829// Unsigned 16-bit multiply:
830
831class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
832 RRForm<0b00110011110, OOL, IOL,
833 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
834 pattern>;
835
Scott Michel8b6b4202007-12-04 22:35:58 +0000836def MPYUv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000837 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000838 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000839
840def MPYUr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000841 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
842 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000843
844def MPYUr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000845 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000846 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000847
Scott Michelae5cbf52008-12-29 03:23:36 +0000848// mpyi: multiply 16 x s10imm -> 32 result.
849
850class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
851 RI10Form<0b00101110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000852 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michelae5cbf52008-12-29 03:23:36 +0000853 pattern>;
854
855def MPYIvec:
856 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
857 [(set (v8i16 VECREG:$rT),
858 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000859
860def MPYIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000861 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
862 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000863
864// mpyui: same issues as other multiplies, plus, this doesn't match a
865// pattern... but may be used during target DAG selection or lowering
Scott Michelae5cbf52008-12-29 03:23:36 +0000866
867class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
868 RI10Form<0b10101110, OOL, IOL,
869 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
870 pattern>;
871
Scott Michel8b6b4202007-12-04 22:35:58 +0000872def MPYUIvec:
Scott Michelae5cbf52008-12-29 03:23:36 +0000873 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
874 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000875
876def MPYUIr16:
Scott Michelae5cbf52008-12-29 03:23:36 +0000877 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
878 []>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000879
880// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michelae5cbf52008-12-29 03:23:36 +0000881class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
882 RRRForm<0b0011, OOL, IOL,
883 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
884 pattern>;
885
Scott Michel750b93f2009-01-15 04:41:47 +0000886def MPYAv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000887 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
888 [(set (v4i32 VECREG:$rT),
889 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
890 (v8i16 VECREG:$rB)))),
891 (v4i32 VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000892
893def MPYAr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000894 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
895 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
896 R32C:$rC))]>;
897
898def MPYAr32_sext:
899 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
900 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
901 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000902
903def MPYAr32_sextinreg:
Scott Michelae5cbf52008-12-29 03:23:36 +0000904 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
905 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
906 (sext_inreg R32C:$rB, i16)),
907 R32C:$rC))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000908
909// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michelae5cbf52008-12-29 03:23:36 +0000910class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
911 RRForm<0b10100011110, OOL, IOL,
912 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
913 pattern>;
914
Scott Michel8b6b4202007-12-04 22:35:58 +0000915def MPYHv4i32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000916 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000917 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000918
919def MPYHr32:
Scott Michelae5cbf52008-12-29 03:23:36 +0000920 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +0000921 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000922
923// mpys: multiply high and shift right (returns the top half of
924// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000925
Scott Michel4d07fb72008-12-30 23:28:25 +0000926class MPYSInst<dag OOL, dag IOL>:
927 RRForm<0b11100011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000928 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000929 [/* no pattern */]>;
930
Scott Michel750b93f2009-01-15 04:41:47 +0000931def MPYSv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000932 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
933
934def MPYSr16:
935 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000936
937// mpyhh: multiply high-high (returns the 32-bit result from multiplying
938// the top 16 bits of the $rA, $rB)
Scott Michel4d07fb72008-12-30 23:28:25 +0000939
940class MPYHHInst<dag OOL, dag IOL>:
941 RRForm<0b01100011110, OOL, IOL,
942 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
943 [/* no pattern */]>;
944
Scott Michel8b6b4202007-12-04 22:35:58 +0000945def MPYHHv8i16:
Scott Michel4d07fb72008-12-30 23:28:25 +0000946 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000947
948def MPYHHr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000949 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000950
951// mpyhha: Multiply high-high, add to $rT:
Scott Michel8b6b4202007-12-04 22:35:58 +0000952
Scott Michel4d07fb72008-12-30 23:28:25 +0000953class MPYHHAInst<dag OOL, dag IOL>:
954 RRForm<0b01100010110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000955 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000956 [/* no pattern */]>;
957
958def MPYHHAvec:
959 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
960
961def MPYHHAr32:
962 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000963
Scott Michel750b93f2009-01-15 04:41:47 +0000964// mpyhhu: Multiply high-high, unsigned, e.g.:
965//
966// +-------+-------+ +-------+-------+ +---------+
967// | a0 . a1 | x | b0 . b1 | = | a0 x b0 |
968// +-------+-------+ +-------+-------+ +---------+
969//
970// where a0, b0 are the upper 16 bits of the 32-bit word
Scott Michel8b6b4202007-12-04 22:35:58 +0000971
Scott Michel4d07fb72008-12-30 23:28:25 +0000972class MPYHHUInst<dag OOL, dag IOL>:
973 RRForm<0b01110011110, OOL, IOL,
Scott Michel8b6b4202007-12-04 22:35:58 +0000974 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel4d07fb72008-12-30 23:28:25 +0000975 [/* no pattern */]>;
976
Scott Michel750b93f2009-01-15 04:41:47 +0000977def MPYHHUv4i32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000978 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
979
980def MPYHHUr32:
981 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000982
983// mpyhhau: Multiply high-high, unsigned
Scott Michel4d07fb72008-12-30 23:28:25 +0000984
985class MPYHHAUInst<dag OOL, dag IOL>:
986 RRForm<0b01110010110, OOL, IOL,
987 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
988 [/* no pattern */]>;
989
Scott Michel8b6b4202007-12-04 22:35:58 +0000990def MPYHHAUvec:
Scott Michel4d07fb72008-12-30 23:28:25 +0000991 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
992
Scott Michel8b6b4202007-12-04 22:35:58 +0000993def MPYHHAUr32:
Scott Michel4d07fb72008-12-30 23:28:25 +0000994 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michelae5cbf52008-12-29 03:23:36 +0000995
996//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +0000997// clz: Count leading zeroes
Scott Michelae5cbf52008-12-29 03:23:36 +0000998//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel06eabde2008-12-27 04:51:36 +0000999class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
1000 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
1001 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001002
Scott Michel06eabde2008-12-27 04:51:36 +00001003class CLZRegInst<RegisterClass rclass>:
1004 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel4d07fb72008-12-30 23:28:25 +00001005 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001006
1007class CLZVecInst<ValueType vectype>:
1008 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1009 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1010
1011multiclass CountLeadingZeroes {
1012 def v4i32 : CLZVecInst<v4i32>;
1013 def r32 : CLZRegInst<R32C>;
1014}
1015
1016defm CLZ : CountLeadingZeroes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001017
1018// cntb: Count ones in bytes (aka "population count")
Scott Michel06eabde2008-12-27 04:51:36 +00001019//
Scott Michel8b6b4202007-12-04 22:35:58 +00001020// NOTE: This instruction is really a vector instruction, but the custom
1021// lowering code uses it in unorthodox ways to support CTPOP for other
1022// data types!
Scott Michel06eabde2008-12-27 04:51:36 +00001023
Scott Michel8b6b4202007-12-04 22:35:58 +00001024def CNTBv16i8:
1025 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1026 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001027 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001028
1029def CNTBv8i16 :
1030 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1031 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001032 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001033
1034def CNTBv4i32 :
1035 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1036 "cntb\t$rT, $rA", IntegerOp,
Scott Michel67224b22008-06-02 22:18:03 +00001037 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001038
Scott Michel06eabde2008-12-27 04:51:36 +00001039// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1040// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1041// slots 1-3.
1042//
1043// Note: This instruction "pairs" with the fsmb instruction for all of the
1044// various types defined here.
1045//
1046// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1047// a vector or register.
1048
1049class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1050 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1051
1052class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1053 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001054 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001055
1056class GBBVecInst<ValueType vectype>:
1057 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001058 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001059
1060multiclass GatherBitsFromBytes {
1061 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1062 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1063 def v16i8: GBBVecInst<v16i8>;
1064}
1065
1066defm GBB: GatherBitsFromBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001067
1068// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001069// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1070// and slots 1-3 also set to 0.
1071//
1072// See notes for GBBInst, above.
1073
1074class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1075 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1076 pattern>;
1077
1078class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1079 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001080 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001081
1082class GBHVecInst<ValueType vectype>:
1083 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001084 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001085
1086multiclass GatherBitsHalfword {
1087 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1088 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1089 def v8i16: GBHVecInst<v8i16>;
1090}
1091
1092defm GBH: GatherBitsHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001093
1094// gb: Gather all low order bits from each word in $rA into a single
Scott Michel06eabde2008-12-27 04:51:36 +00001095// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1096// as well as slots 1-3.
1097//
1098// See notes for gbb, above.
1099
1100class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1101 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1102 pattern>;
1103
1104class GBRegInst<RegisterClass rclass, ValueType vectype>:
1105 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001106 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001107
1108class GBVecInst<ValueType vectype>:
1109 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel70741542009-01-06 23:10:38 +00001110 [/* no pattern */]>;
Scott Michel06eabde2008-12-27 04:51:36 +00001111
1112multiclass GatherBitsWord {
1113 def v4i32_r32: GBRegInst<R32C, v4i32>;
1114 def v4i32_r16: GBRegInst<R16C, v4i32>;
1115 def v4i32: GBVecInst<v4i32>;
1116}
1117
1118defm GB: GatherBitsWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001119
1120// avgb: average bytes
1121def AVGB:
1122 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1123 "avgb\t$rT, $rA, $rB", ByteOp,
1124 []>;
1125
1126// absdb: absolute difference of bytes
1127def ABSDB:
1128 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1129 "absdb\t$rT, $rA, $rB", ByteOp,
1130 []>;
1131
1132// sumb: sum bytes into halfwords
1133def SUMB:
1134 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1135 "sumb\t$rT, $rA, $rB", ByteOp,
1136 []>;
1137
1138// Sign extension operations:
Scott Michel67224b22008-06-02 22:18:03 +00001139class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1140 RRForm_1<0b01101101010, OOL, IOL,
1141 "xsbh\t$rDst, $rSrc",
1142 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001143
Scott Michel67224b22008-06-02 22:18:03 +00001144class XSBHVecInst<ValueType vectype>:
1145 XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1146 [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001147
Scott Michel2ef773a2009-01-06 03:36:14 +00001148class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel67224b22008-06-02 22:18:03 +00001149 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Michel2ef773a2009-01-06 03:36:14 +00001150 pattern>;
Scott Michel67224b22008-06-02 22:18:03 +00001151
1152multiclass ExtendByteHalfword {
Scott Michel2ef773a2009-01-06 03:36:14 +00001153 def v16i8: XSBHVecInst<v8i16>;
1154 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1155 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1156 def r16: XSBHInRegInst<R16C,
1157 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel67224b22008-06-02 22:18:03 +00001158
1159 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1160 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1161 // pattern below). Intentionally doesn't match a pattern because we want the
1162 // sext 8->32 pattern to do the work for us, namely because we need the extra
1163 // XSHWr32.
Scott Michel2ef773a2009-01-06 03:36:14 +00001164 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1165
1166 // Same as the 32-bit version, but for i64
1167 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel67224b22008-06-02 22:18:03 +00001168}
1169
1170defm XSBH : ExtendByteHalfword;
1171
Scott Michel8b6b4202007-12-04 22:35:58 +00001172// Sign extend halfwords to words:
Scott Michel8b6b4202007-12-04 22:35:58 +00001173
Scott Michel2ef773a2009-01-06 03:36:14 +00001174class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1175 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1176 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001177
Scott Michel2ef773a2009-01-06 03:36:14 +00001178class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1179 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1180 [(set (out_vectype VECREG:$rDest),
1181 (sext (in_vectype VECREG:$rSrc)))]>;
1182
1183class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1184 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1185 pattern>;
1186
1187class XSHWRegInst<RegisterClass rclass>:
1188 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1189 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1190
1191multiclass ExtendHalfwordWord {
1192 def v4i32: XSHWVecInst<v4i32, v8i16>;
1193
1194 def r16: XSHWRegInst<R32C>;
1195
1196 def r32: XSHWInRegInst<R32C,
1197 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1198 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1199}
1200
1201defm XSHW : ExtendHalfwordWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001202
Scott Michele0168c12009-01-05 01:34:35 +00001203// Sign-extend words to doublewords (32->64 bits)
Scott Michel8b6b4202007-12-04 22:35:58 +00001204
Scott Michele0168c12009-01-05 01:34:35 +00001205class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel2ef773a2009-01-06 03:36:14 +00001206 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1207 IntegerOp, pattern>;
Scott Michele0168c12009-01-05 01:34:35 +00001208
1209class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1210 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1211 [(set (out_vectype VECREG:$rDst),
1212 (sext (out_vectype VECREG:$rSrc)))]>;
1213
1214class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1215 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1216 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1217
1218multiclass ExtendWordToDoubleWord {
1219 def v2i64: XSWDVecInst<v4i32, v2i64>;
1220 def r64: XSWDRegInst<R32C, R64C>;
1221
1222 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1223 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1224}
Scott Michel8b6b4202007-12-04 22:35:58 +00001225
Scott Michele0168c12009-01-05 01:34:35 +00001226defm XSWD : ExtendWordToDoubleWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001227
1228// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +00001229
Scott Michel97872d32008-02-23 18:41:37 +00001230class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1231 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1232 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001233
Scott Michel97872d32008-02-23 18:41:37 +00001234class ANDVecInst<ValueType vectype>:
1235 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1236 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1237 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001238
Scott Michel6baba072008-03-05 23:02:02 +00001239class ANDRegInst<RegisterClass rclass>:
1240 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1241 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1242
Scott Michel97872d32008-02-23 18:41:37 +00001243multiclass BitwiseAnd
1244{
1245 def v16i8: ANDVecInst<v16i8>;
1246 def v8i16: ANDVecInst<v8i16>;
1247 def v4i32: ANDVecInst<v4i32>;
1248 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001249
Scott Michel6baba072008-03-05 23:02:02 +00001250 def r128: ANDRegInst<GPRC>;
1251 def r64: ANDRegInst<R64C>;
1252 def r32: ANDRegInst<R32C>;
1253 def r16: ANDRegInst<R16C>;
1254 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001255
Scott Michel97872d32008-02-23 18:41:37 +00001256 //===---------------------------------------------
1257 // Special instructions to perform the fabs instruction
1258 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1259 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001260
pingbak2f387e82009-01-26 03:31:40 +00001261 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1262 [/* Intentionally does not match a pattern */]>;
1263
Scott Michel97872d32008-02-23 18:41:37 +00001264 // Could use v4i32, but won't for clarity
1265 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1266 [/* Intentionally does not match a pattern */]>;
1267
1268 //===---------------------------------------------
1269
1270 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1271 // quantities -- see 16->32 zext pattern.
1272 //
1273 // This pattern is somewhat artificial, since it might match some
1274 // compiler generated pattern but it is unlikely to do so.
1275
1276 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1277 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1278}
1279
1280defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +00001281
1282// N.B.: vnot_conv is one of those special target selection pattern fragments,
1283// in which we expect there to be a bit_convert on the constant. Bear in mind
1284// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1285// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +00001286
Scott Michel97872d32008-02-23 18:41:37 +00001287class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1288 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1289 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001290
Scott Michel97872d32008-02-23 18:41:37 +00001291class ANDCVecInst<ValueType vectype>:
1292 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1293 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1294 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001295
Scott Michel97872d32008-02-23 18:41:37 +00001296class ANDCRegInst<RegisterClass rclass>:
1297 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1298 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001299
Scott Michel97872d32008-02-23 18:41:37 +00001300multiclass AndComplement
1301{
1302 def v16i8: ANDCVecInst<v16i8>;
1303 def v8i16: ANDCVecInst<v8i16>;
1304 def v4i32: ANDCVecInst<v4i32>;
1305 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001306
Scott Michel97872d32008-02-23 18:41:37 +00001307 def r128: ANDCRegInst<GPRC>;
1308 def r64: ANDCRegInst<R64C>;
1309 def r32: ANDCRegInst<R32C>;
1310 def r16: ANDCRegInst<R16C>;
1311 def r8: ANDCRegInst<R8C>;
1312}
Scott Michel438be252007-12-17 22:32:34 +00001313
Scott Michel97872d32008-02-23 18:41:37 +00001314defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001315
Scott Michel97872d32008-02-23 18:41:37 +00001316class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1317 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001318 ByteOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001319
Scott Michel97872d32008-02-23 18:41:37 +00001320multiclass AndByteImm
1321{
1322 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1323 [(set (v16i8 VECREG:$rT),
1324 (and (v16i8 VECREG:$rA),
1325 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001326
Scott Michel97872d32008-02-23 18:41:37 +00001327 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1328 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1329}
Scott Michel438be252007-12-17 22:32:34 +00001330
Scott Michel97872d32008-02-23 18:41:37 +00001331defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001332
Scott Michel97872d32008-02-23 18:41:37 +00001333class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1334 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michel61895fe2008-12-10 00:15:19 +00001335 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001336
Scott Michel97872d32008-02-23 18:41:37 +00001337multiclass AndHalfwordImm
1338{
1339 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1340 [(set (v8i16 VECREG:$rT),
1341 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001342
Scott Michel97872d32008-02-23 18:41:37 +00001343 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1344 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001345
Scott Michel97872d32008-02-23 18:41:37 +00001346 // Zero-extend i8 to i16:
1347 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1348 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1349}
Scott Michel8b6b4202007-12-04 22:35:58 +00001350
Scott Michel97872d32008-02-23 18:41:37 +00001351defm ANDHI : AndHalfwordImm;
1352
1353class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1354 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1355 IntegerOp, pattern>;
1356
1357multiclass AndWordImm
1358{
1359 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1360 [(set (v4i32 VECREG:$rT),
1361 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1362
1363 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1364 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1365
1366 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1367 // pattern below.
1368 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1369 [(set R32C:$rT,
1370 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1371
1372 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1373 // zext 16->32 pattern below.
1374 //
1375 // Note that this pattern is somewhat artificial, since it might match
1376 // something the compiler generates but is unlikely to occur in practice.
1377 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1378 [(set R32C:$rT,
1379 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1380}
1381
1382defm ANDI : AndWordImm;
1383
1384//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001385// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001386//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1387
Scott Michel8b6b4202007-12-04 22:35:58 +00001388// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001389class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1390 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1391 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001392
Scott Michel97872d32008-02-23 18:41:37 +00001393class ORVecInst<ValueType vectype>:
1394 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1395 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1396 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001397
Scott Michel97872d32008-02-23 18:41:37 +00001398class ORRegInst<RegisterClass rclass>:
1399 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1400 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001401
Scott Michel06eabde2008-12-27 04:51:36 +00001402// ORCvtForm: OR conversion form
1403//
1404// This is used to "convert" the preferred slot to its vector equivalent, as
1405// well as convert a vector back to its preferred slot.
1406//
1407// These are effectively no-ops, but need to exist for proper type conversion
1408// and type coercion.
1409
Scott Michel8c67fa42009-01-21 04:58:48 +00001410class ORCvtForm<dag OOL, dag IOL, list<dag> pattern = [/* no pattern */]>
Scott Michel06eabde2008-12-27 04:51:36 +00001411 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1412 bits<7> RA;
1413 bits<7> RT;
1414
Scott Michel8c67fa42009-01-21 04:58:48 +00001415 let Pattern = pattern;
Scott Michel06eabde2008-12-27 04:51:36 +00001416
1417 let Inst{0-10} = 0b10000010000;
1418 let Inst{11-17} = RA;
1419 let Inst{18-24} = RA;
1420 let Inst{25-31} = RT;
1421}
1422
Scott Michel97872d32008-02-23 18:41:37 +00001423class ORPromoteScalar<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001424 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001425
Scott Michel97872d32008-02-23 18:41:37 +00001426class ORExtractElt<RegisterClass rclass>:
Scott Michel06eabde2008-12-27 04:51:36 +00001427 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1428
Scott Michel8c67fa42009-01-21 04:58:48 +00001429/* class ORCvtRegGPRC<RegisterClass rclass>:
1430 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>; */
Scott Michel06eabde2008-12-27 04:51:36 +00001431
Scott Michel8c67fa42009-01-21 04:58:48 +00001432/* class ORCvtVecGPRC:
1433 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>; */
Scott Michel06eabde2008-12-27 04:51:36 +00001434
Scott Michel8c67fa42009-01-21 04:58:48 +00001435/* class ORCvtGPRCReg<RegisterClass rclass>:
1436 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>; */
Scott Michel2ef773a2009-01-06 03:36:14 +00001437
Scott Michel8c67fa42009-01-21 04:58:48 +00001438class ORCvtFormR32Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1439 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001440
Scott Michel8c67fa42009-01-21 04:58:48 +00001441class ORCvtFormRegR32<RegisterClass rclass, list<dag> pattern = [ ]>:
1442 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001443
Scott Michel8c67fa42009-01-21 04:58:48 +00001444class ORCvtFormR64Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1445 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA), pattern>;
Scott Michel2ef773a2009-01-06 03:36:14 +00001446
Scott Michel8c67fa42009-01-21 04:58:48 +00001447class ORCvtFormRegR64<RegisterClass rclass, list<dag> pattern = [ ]>:
1448 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA), pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00001449
Scott Michel8c67fa42009-01-21 04:58:48 +00001450/* class ORCvtGPRCVec:
1451 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>; */
Scott Michel8b6b4202007-12-04 22:35:58 +00001452
Scott Michel97872d32008-02-23 18:41:37 +00001453multiclass BitwiseOr
1454{
1455 def v16i8: ORVecInst<v16i8>;
1456 def v8i16: ORVecInst<v8i16>;
1457 def v4i32: ORVecInst<v4i32>;
1458 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001459
Scott Michel97872d32008-02-23 18:41:37 +00001460 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1461 [(set (v4f32 VECREG:$rT),
1462 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1463 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001464
Scott Michel97872d32008-02-23 18:41:37 +00001465 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel06eabde2008-12-27 04:51:36 +00001466 [(set (v2f64 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00001467 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1468 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001469
Scott Michel8c67fa42009-01-21 04:58:48 +00001470 def r128: ORRegInst<GPRC>;
1471 def r64: ORRegInst<R64C>;
1472 def r32: ORRegInst<R32C>;
1473 def r16: ORRegInst<R16C>;
1474 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001475
Scott Michel97872d32008-02-23 18:41:37 +00001476 // OR instructions used to copy f32 and f64 registers.
1477 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1478 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001479
Scott Michel97872d32008-02-23 18:41:37 +00001480 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1481 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001482
Scott Michel4d07fb72008-12-30 23:28:25 +00001483 // scalar->vector promotion, prefslot2vec:
Scott Michel97872d32008-02-23 18:41:37 +00001484 def v16i8_i8: ORPromoteScalar<R8C>;
1485 def v8i16_i16: ORPromoteScalar<R16C>;
1486 def v4i32_i32: ORPromoteScalar<R32C>;
1487 def v2i64_i64: ORPromoteScalar<R64C>;
1488 def v4f32_f32: ORPromoteScalar<R32FP>;
1489 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001490
Scott Michel4d07fb72008-12-30 23:28:25 +00001491 // vector->scalar demotion, vec2prefslot:
Scott Michel97872d32008-02-23 18:41:37 +00001492 def i8_v16i8: ORExtractElt<R8C>;
1493 def i16_v8i16: ORExtractElt<R16C>;
1494 def i32_v4i32: ORExtractElt<R32C>;
1495 def i64_v2i64: ORExtractElt<R64C>;
1496 def f32_v4f32: ORExtractElt<R32FP>;
1497 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001498
Scott Michel8c67fa42009-01-21 04:58:48 +00001499/*
Scott Michel06eabde2008-12-27 04:51:36 +00001500 // Conversion from GPRC to register
1501 def i128_r64: ORCvtRegGPRC<R64C>;
1502 def i128_f64: ORCvtRegGPRC<R64FP>;
1503 def i128_r32: ORCvtRegGPRC<R32C>;
1504 def i128_f32: ORCvtRegGPRC<R32FP>;
1505 def i128_r16: ORCvtRegGPRC<R16C>;
1506 def i128_r8: ORCvtRegGPRC<R8C>;
1507
1508 // Conversion from GPRC to vector
1509 def i128_vec: ORCvtVecGPRC;
1510
1511 // Conversion from register to GPRC
1512 def r64_i128: ORCvtGPRCReg<R64C>;
1513 def f64_i128: ORCvtGPRCReg<R64FP>;
1514 def r32_i128: ORCvtGPRCReg<R32C>;
1515 def f32_i128: ORCvtGPRCReg<R32FP>;
1516 def r16_i128: ORCvtGPRCReg<R16C>;
1517 def r8_i128: ORCvtGPRCReg<R8C>;
1518
1519 // Conversion from vector to GPRC
1520 def vec_i128: ORCvtGPRCVec;
Scott Michel8c67fa42009-01-21 04:58:48 +00001521*/
1522/*
Scott Michel2ef773a2009-01-06 03:36:14 +00001523 // Conversion from register to R32C:
1524 def r16_r32: ORCvtFormRegR32<R16C>;
1525 def r8_r32: ORCvtFormRegR32<R8C>;
1526
1527 // Conversion from R32C to register
1528 def r32_r16: ORCvtFormR32Reg<R16C>;
1529 def r32_r8: ORCvtFormR32Reg<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001530*/
pingbak2f387e82009-01-26 03:31:40 +00001531
1532 // Conversion to register from R64C:
1533 def r32_r64: ORCvtFormR64Reg<R32C>;
1534 // def r16_r64: ORCvtFormR64Reg<R16C>;
1535 // def r8_r64: ORCvtFormR64Reg<R8C>;
1536
1537 // Conversion to R64C from register
1538 def r64_r32: ORCvtFormRegR64<R32C>;
1539 // def r64_r16: ORCvtFormRegR64<R16C>;
1540 // def r64_r8: ORCvtFormRegR64<R8C>;
Scott Michel8c67fa42009-01-21 04:58:48 +00001541
1542 // bitconvert patterns:
1543 def r32_f32: ORCvtFormR32Reg<R32FP,
1544 [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1545 def f32_r32: ORCvtFormRegR32<R32FP,
1546 [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1547
1548 def r64_f64: ORCvtFormR64Reg<R64FP,
1549 [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1550 def f64_r64: ORCvtFormRegR64<R64FP,
1551 [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +00001552}
Scott Michel438be252007-12-17 22:32:34 +00001553
Scott Michel97872d32008-02-23 18:41:37 +00001554defm OR : BitwiseOr;
1555
Scott Michel06eabde2008-12-27 04:51:36 +00001556// scalar->vector promotion patterns (preferred slot to vector):
1557def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1558 (ORv16i8_i8 R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001559
Scott Michel06eabde2008-12-27 04:51:36 +00001560def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1561 (ORv8i16_i16 R16C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001562
Scott Michel06eabde2008-12-27 04:51:36 +00001563def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1564 (ORv4i32_i32 R32C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001565
Scott Michel06eabde2008-12-27 04:51:36 +00001566def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1567 (ORv2i64_i64 R64C:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001568
Scott Michel06eabde2008-12-27 04:51:36 +00001569def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1570 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001571
Scott Michel06eabde2008-12-27 04:51:36 +00001572def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1573 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001574
Scott Michel06eabde2008-12-27 04:51:36 +00001575// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1576// known as converting the vector back to its preferred slot
Scott Michel438be252007-12-17 22:32:34 +00001577
Scott Michelc630c412008-11-24 17:11:17 +00001578def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001579 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001580
Scott Michelc630c412008-11-24 17:11:17 +00001581def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001582 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001583
Scott Michelc630c412008-11-24 17:11:17 +00001584def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001585 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001586
Scott Michelc630c412008-11-24 17:11:17 +00001587def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001588 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001589
Scott Michelc630c412008-11-24 17:11:17 +00001590def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001591 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001592
Scott Michelc630c412008-11-24 17:11:17 +00001593def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00001594 (ORf64_v2f64 VECREG:$rA)>;
1595
1596// Load Register: This is an assembler alias for a bitwise OR of a register
1597// against itself. It's here because it brings some clarity to assembly
1598// language output.
1599
1600let hasCtrlDep = 1 in {
1601 class LRInst<dag OOL, dag IOL>
1602 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1603 bits<7> RA;
1604 bits<7> RT;
1605
1606 let Pattern = [/*no pattern*/];
1607
1608 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1609 let Inst{11-17} = RA;
1610 let Inst{18-24} = RA;
1611 let Inst{25-31} = RT;
1612 }
1613
1614 class LRVecInst<ValueType vectype>:
1615 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1616
1617 class LRRegInst<RegisterClass rclass>:
1618 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1619
1620 multiclass LoadRegister {
1621 def v2i64: LRVecInst<v2i64>;
1622 def v2f64: LRVecInst<v2f64>;
1623 def v4i32: LRVecInst<v4i32>;
1624 def v4f32: LRVecInst<v4f32>;
1625 def v8i16: LRVecInst<v8i16>;
1626 def v16i8: LRVecInst<v16i8>;
1627
1628 def r128: LRRegInst<GPRC>;
1629 def r64: LRRegInst<R64C>;
1630 def f64: LRRegInst<R64FP>;
1631 def r32: LRRegInst<R32C>;
1632 def f32: LRRegInst<R32FP>;
1633 def r16: LRRegInst<R16C>;
1634 def r8: LRRegInst<R8C>;
1635 }
1636
1637 defm LR: LoadRegister;
1638}
Scott Michel8b6b4202007-12-04 22:35:58 +00001639
Scott Michel97872d32008-02-23 18:41:37 +00001640// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001641
Scott Michel97872d32008-02-23 18:41:37 +00001642class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1643 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1644 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001645
Scott Michel97872d32008-02-23 18:41:37 +00001646class ORCVecInst<ValueType vectype>:
1647 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1648 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1649 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001650
Scott Michel97872d32008-02-23 18:41:37 +00001651class ORCRegInst<RegisterClass rclass>:
1652 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1653 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001654
Scott Michel97872d32008-02-23 18:41:37 +00001655multiclass BitwiseOrComplement
1656{
1657 def v16i8: ORCVecInst<v16i8>;
1658 def v8i16: ORCVecInst<v8i16>;
1659 def v4i32: ORCVecInst<v4i32>;
1660 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001661
Scott Michel97872d32008-02-23 18:41:37 +00001662 def r64: ORCRegInst<R64C>;
1663 def r32: ORCRegInst<R32C>;
1664 def r16: ORCRegInst<R16C>;
1665 def r8: ORCRegInst<R8C>;
1666}
1667
1668defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001669
Scott Michel8b6b4202007-12-04 22:35:58 +00001670// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001671class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1672 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1673 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001674
Scott Michel97872d32008-02-23 18:41:37 +00001675class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1676 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1677 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1678 (vectype immpred:$val)))]>;
1679
1680multiclass BitwiseOrByteImm
1681{
1682 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1683
1684 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1685 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1686}
1687
1688defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001689
Scott Michel8b6b4202007-12-04 22:35:58 +00001690// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001691class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1692 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1693 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001694
Scott Michel97872d32008-02-23 18:41:37 +00001695class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1696 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1697 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1698 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001699
Scott Michel97872d32008-02-23 18:41:37 +00001700multiclass BitwiseOrHalfwordImm
1701{
1702 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1703
1704 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1705 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1706
1707 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1708 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1709 [(set R16C:$rT, (or (anyext R8C:$rA),
1710 i16ImmSExt10:$val))]>;
1711}
1712
1713defm ORHI : BitwiseOrHalfwordImm;
1714
1715class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1716 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1717 IntegerOp, pattern>;
1718
1719class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1720 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1721 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1722 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001723
1724// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001725multiclass BitwiseOrImm
1726{
1727 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001728
Scott Michel97872d32008-02-23 18:41:37 +00001729 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1730 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001731
Scott Michel97872d32008-02-23 18:41:37 +00001732 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1733 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1734 // infra "anyext 16->32" pattern.)
1735 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1736 [(set R32C:$rT, (or (anyext R16C:$rA),
1737 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001738
Scott Michel97872d32008-02-23 18:41:37 +00001739 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1740 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1741 // infra "anyext 16->32" pattern.)
1742 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1743 [(set R32C:$rT, (or (anyext R8C:$rA),
1744 i32ImmSExt10:$val))]>;
1745}
Scott Michel8b6b4202007-12-04 22:35:58 +00001746
Scott Michel97872d32008-02-23 18:41:37 +00001747defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001748
Scott Michel8b6b4202007-12-04 22:35:58 +00001749// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1750// $rT[0], slots 1-3 are zeroed.
1751//
Scott Michel438be252007-12-17 22:32:34 +00001752// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001753def ORXv4i32:
1754 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1755 "orx\t$rT, $rA, $rB", IntegerOp,
1756 []>;
1757
Scott Michel438be252007-12-17 22:32:34 +00001758// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001759
Scott Michel6baba072008-03-05 23:02:02 +00001760class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1761 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1762 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001763
Scott Michel6baba072008-03-05 23:02:02 +00001764class XORVecInst<ValueType vectype>:
1765 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1766 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1767 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001768
Scott Michel6baba072008-03-05 23:02:02 +00001769class XORRegInst<RegisterClass rclass>:
1770 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1771 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1772
1773multiclass BitwiseExclusiveOr
1774{
1775 def v16i8: XORVecInst<v16i8>;
1776 def v8i16: XORVecInst<v8i16>;
1777 def v4i32: XORVecInst<v4i32>;
1778 def v2i64: XORVecInst<v2i64>;
1779
1780 def r128: XORRegInst<GPRC>;
1781 def r64: XORRegInst<R64C>;
1782 def r32: XORRegInst<R32C>;
1783 def r16: XORRegInst<R16C>;
1784 def r8: XORRegInst<R8C>;
1785
1786 // Special forms for floating point instructions.
1787 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1788
1789 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1790 [/* no pattern */]>;
1791
1792 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1793 [/* no pattern */]>;
1794
1795 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1796 [/* no pattern, see fneg{32,64} */]>;
1797}
1798
1799defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001800
1801//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001802
Scott Michel97872d32008-02-23 18:41:37 +00001803class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1804 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1805 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001806
Scott Michel97872d32008-02-23 18:41:37 +00001807multiclass XorByteImm
1808{
1809 def v16i8:
1810 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1811 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1812
1813 def r8:
1814 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1815 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1816}
1817
1818defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001819
Scott Michel8b6b4202007-12-04 22:35:58 +00001820def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001821 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001822 "xorhi\t$rT, $rA, $val", IntegerOp,
1823 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1824 v8i16SExt10Imm:$val))]>;
1825
1826def XORHIr16:
1827 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1828 "xorhi\t$rT, $rA, $val", IntegerOp,
1829 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1830
1831def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001832 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001833 "xori\t$rT, $rA, $val", IntegerOp,
1834 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1835 v4i32SExt10Imm:$val))]>;
1836
1837def XORIr32:
1838 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1839 "xori\t$rT, $rA, $val", IntegerOp,
1840 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1841
1842// NAND:
1843def NANDv16i8:
1844 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1845 "nand\t$rT, $rA, $rB", IntegerOp,
1846 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1847 (v16i8 VECREG:$rB))))]>;
1848
1849def NANDv8i16:
1850 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1851 "nand\t$rT, $rA, $rB", IntegerOp,
1852 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1853 (v8i16 VECREG:$rB))))]>;
1854
1855def NANDv4i32:
1856 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1857 "nand\t$rT, $rA, $rB", IntegerOp,
1858 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1859 (v4i32 VECREG:$rB))))]>;
1860
1861def NANDr32:
1862 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1863 "nand\t$rT, $rA, $rB", IntegerOp,
1864 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1865
1866def NANDr16:
1867 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1868 "nand\t$rT, $rA, $rB", IntegerOp,
1869 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1870
Scott Michel438be252007-12-17 22:32:34 +00001871def NANDr8:
1872 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1873 "nand\t$rT, $rA, $rB", IntegerOp,
1874 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1875
Scott Michel8b6b4202007-12-04 22:35:58 +00001876// NOR:
1877def NORv16i8:
1878 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1879 "nor\t$rT, $rA, $rB", IntegerOp,
1880 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1881 (v16i8 VECREG:$rB))))]>;
1882
1883def NORv8i16:
1884 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1885 "nor\t$rT, $rA, $rB", IntegerOp,
1886 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1887 (v8i16 VECREG:$rB))))]>;
1888
1889def NORv4i32:
1890 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1891 "nor\t$rT, $rA, $rB", IntegerOp,
1892 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1893 (v4i32 VECREG:$rB))))]>;
1894
1895def NORr32:
1896 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1897 "nor\t$rT, $rA, $rB", IntegerOp,
1898 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1899
1900def NORr16:
1901 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1902 "nor\t$rT, $rA, $rB", IntegerOp,
1903 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1904
Scott Michel438be252007-12-17 22:32:34 +00001905def NORr8:
1906 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1907 "nor\t$rT, $rA, $rB", IntegerOp,
1908 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1909
Scott Michel8b6b4202007-12-04 22:35:58 +00001910// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001911class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1912 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1913 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001914
pingbak2f387e82009-01-26 03:31:40 +00001915class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michel6baba072008-03-05 23:02:02 +00001916 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1917 [(set (vectype VECREG:$rT),
1918 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
pingbak2f387e82009-01-26 03:31:40 +00001919 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michel6baba072008-03-05 23:02:02 +00001920 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001921
Scott Michel4d07fb72008-12-30 23:28:25 +00001922class SELBVecVCondInst<ValueType vectype>:
1923 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1924 [(set (vectype VECREG:$rT),
1925 (select (vectype VECREG:$rC),
1926 (vectype VECREG:$rB),
1927 (vectype VECREG:$rA)))]>;
1928
Scott Michel06eabde2008-12-27 04:51:36 +00001929class SELBVecCondInst<ValueType vectype>:
1930 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1931 [(set (vectype VECREG:$rT),
1932 (select R32C:$rC,
1933 (vectype VECREG:$rB),
1934 (vectype VECREG:$rA)))]>;
1935
Scott Michel6baba072008-03-05 23:02:02 +00001936class SELBRegInst<RegisterClass rclass>:
1937 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1938 [(set rclass:$rT,
Scott Michelae5cbf52008-12-29 03:23:36 +00001939 (or (and rclass:$rB, rclass:$rC),
1940 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001941
Scott Michel06eabde2008-12-27 04:51:36 +00001942class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1943 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1944 [(set rclass:$rT,
1945 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1946
Scott Michel6baba072008-03-05 23:02:02 +00001947multiclass SelectBits
1948{
1949 def v16i8: SELBVecInst<v16i8>;
1950 def v8i16: SELBVecInst<v8i16>;
1951 def v4i32: SELBVecInst<v4i32>;
pingbak2f387e82009-01-26 03:31:40 +00001952 def v2i64: SELBVecInst<v2i64, vnot_conv>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001953
Scott Michel6baba072008-03-05 23:02:02 +00001954 def r128: SELBRegInst<GPRC>;
1955 def r64: SELBRegInst<R64C>;
1956 def r32: SELBRegInst<R32C>;
1957 def r16: SELBRegInst<R16C>;
1958 def r8: SELBRegInst<R8C>;
Scott Michel06eabde2008-12-27 04:51:36 +00001959
1960 def v16i8_cond: SELBVecCondInst<v16i8>;
1961 def v8i16_cond: SELBVecCondInst<v8i16>;
1962 def v4i32_cond: SELBVecCondInst<v4i32>;
1963 def v2i64_cond: SELBVecCondInst<v2i64>;
1964
Scott Michel4d07fb72008-12-30 23:28:25 +00001965 def v16i8_vcond: SELBVecCondInst<v16i8>;
1966 def v8i16_vcond: SELBVecCondInst<v8i16>;
1967 def v4i32_vcond: SELBVecCondInst<v4i32>;
1968 def v2i64_vcond: SELBVecCondInst<v2i64>;
1969
1970 def v4f32_cond:
pingbakb8913342009-01-26 03:37:41 +00001971 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1972 [(set (v4f32 VECREG:$rT),
1973 (select (v4i32 VECREG:$rC),
1974 (v4f32 VECREG:$rB),
1975 (v4f32 VECREG:$rA)))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001976
Scott Michel8c67fa42009-01-21 04:58:48 +00001977 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michel06eabde2008-12-27 04:51:36 +00001978 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel4d07fb72008-12-30 23:28:25 +00001979 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michel06eabde2008-12-27 04:51:36 +00001980 def r16_cond: SELBRegCondInst<R16C, R16C>;
1981 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michel6baba072008-03-05 23:02:02 +00001982}
Scott Michel8b6b4202007-12-04 22:35:58 +00001983
Scott Michel6baba072008-03-05 23:02:02 +00001984defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001985
Scott Michel56a125e2008-11-22 23:50:42 +00001986class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michel6baba072008-03-05 23:02:02 +00001987 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1988 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001989
Scott Michel56a125e2008-11-22 23:50:42 +00001990def : SPUselbPatVec<v16i8, SELBv16i8>;
1991def : SPUselbPatVec<v8i16, SELBv8i16>;
1992def : SPUselbPatVec<v4i32, SELBv4i32>;
1993def : SPUselbPatVec<v2i64, SELBv2i64>;
1994
1995class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1996 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1997 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1998
1999def : SPUselbPatReg<R8C, SELBr8>;
2000def : SPUselbPatReg<R16C, SELBr16>;
2001def : SPUselbPatReg<R32C, SELBr32>;
2002def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002003
Scott Michel6baba072008-03-05 23:02:02 +00002004// EQV: Equivalence (1 for each same bit, otherwise 0)
2005//
2006// Note: There are a lot of ways to match this bit operator and these patterns
2007// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00002008
Scott Michel6baba072008-03-05 23:02:02 +00002009class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2010 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2011 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002012
Scott Michel6baba072008-03-05 23:02:02 +00002013class EQVVecInst<ValueType vectype>:
2014 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2015 [(set (vectype VECREG:$rT),
2016 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2017 (and (vnot (vectype VECREG:$rA)),
2018 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002019
Scott Michel6baba072008-03-05 23:02:02 +00002020class EQVRegInst<RegisterClass rclass>:
2021 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2022 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2023 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002024
Scott Michel6baba072008-03-05 23:02:02 +00002025class EQVVecPattern1<ValueType vectype>:
2026 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2027 [(set (vectype VECREG:$rT),
2028 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002029
Scott Michel6baba072008-03-05 23:02:02 +00002030class EQVRegPattern1<RegisterClass rclass>:
2031 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2032 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002033
Scott Michel6baba072008-03-05 23:02:02 +00002034class EQVVecPattern2<ValueType vectype>:
2035 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2036 [(set (vectype VECREG:$rT),
2037 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2038 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002039
Scott Michel6baba072008-03-05 23:02:02 +00002040class EQVRegPattern2<RegisterClass rclass>:
2041 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2042 [(set rclass:$rT,
2043 (or (and rclass:$rA, rclass:$rB),
2044 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002045
Scott Michel6baba072008-03-05 23:02:02 +00002046class EQVVecPattern3<ValueType vectype>:
2047 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2048 [(set (vectype VECREG:$rT),
2049 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002050
Scott Michel6baba072008-03-05 23:02:02 +00002051class EQVRegPattern3<RegisterClass rclass>:
2052 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2053 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002054
Scott Michel6baba072008-03-05 23:02:02 +00002055multiclass BitEquivalence
2056{
2057 def v16i8: EQVVecInst<v16i8>;
2058 def v8i16: EQVVecInst<v8i16>;
2059 def v4i32: EQVVecInst<v4i32>;
2060 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002061
Scott Michel6baba072008-03-05 23:02:02 +00002062 def v16i8_1: EQVVecPattern1<v16i8>;
2063 def v8i16_1: EQVVecPattern1<v8i16>;
2064 def v4i32_1: EQVVecPattern1<v4i32>;
2065 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002066
Scott Michel6baba072008-03-05 23:02:02 +00002067 def v16i8_2: EQVVecPattern2<v16i8>;
2068 def v8i16_2: EQVVecPattern2<v8i16>;
2069 def v4i32_2: EQVVecPattern2<v4i32>;
2070 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002071
Scott Michel6baba072008-03-05 23:02:02 +00002072 def v16i8_3: EQVVecPattern3<v16i8>;
2073 def v8i16_3: EQVVecPattern3<v8i16>;
2074 def v4i32_3: EQVVecPattern3<v4i32>;
2075 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002076
Scott Michel6baba072008-03-05 23:02:02 +00002077 def r128: EQVRegInst<GPRC>;
2078 def r64: EQVRegInst<R64C>;
2079 def r32: EQVRegInst<R32C>;
2080 def r16: EQVRegInst<R16C>;
2081 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002082
Scott Michel6baba072008-03-05 23:02:02 +00002083 def r128_1: EQVRegPattern1<GPRC>;
2084 def r64_1: EQVRegPattern1<R64C>;
2085 def r32_1: EQVRegPattern1<R32C>;
2086 def r16_1: EQVRegPattern1<R16C>;
2087 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002088
Scott Michel6baba072008-03-05 23:02:02 +00002089 def r128_2: EQVRegPattern2<GPRC>;
2090 def r64_2: EQVRegPattern2<R64C>;
2091 def r32_2: EQVRegPattern2<R32C>;
2092 def r16_2: EQVRegPattern2<R16C>;
2093 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002094
Scott Michel6baba072008-03-05 23:02:02 +00002095 def r128_3: EQVRegPattern3<GPRC>;
2096 def r64_3: EQVRegPattern3<R64C>;
2097 def r32_3: EQVRegPattern3<R32C>;
2098 def r16_3: EQVRegPattern3<R16C>;
2099 def r8_3: EQVRegPattern3<R8C>;
2100}
Scott Michel438be252007-12-17 22:32:34 +00002101
Scott Michel6baba072008-03-05 23:02:02 +00002102defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00002103
2104//===----------------------------------------------------------------------===//
2105// Vector shuffle...
2106//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002107// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2108// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2109// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2110// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00002111//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002112
Scott Michel97872d32008-02-23 18:41:37 +00002113class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2114 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2115 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002116
Scott Michel0718cd82008-12-01 17:56:02 +00002117class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michel97872d32008-02-23 18:41:37 +00002118 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel0718cd82008-12-01 17:56:02 +00002119 [(set (resultvec VECREG:$rT),
2120 (SPUshuffle (resultvec VECREG:$rA),
2121 (resultvec VECREG:$rB),
2122 (maskvec VECREG:$rC)))]>;
Scott Michel754d8662007-12-20 00:44:13 +00002123
Scott Michel06eabde2008-12-27 04:51:36 +00002124class SHUFBGPRCInst:
2125 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2126 [/* no pattern */]>;
2127
Scott Michel97872d32008-02-23 18:41:37 +00002128multiclass ShuffleBytes
2129{
Scott Michel0718cd82008-12-01 17:56:02 +00002130 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2131 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2132 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2133 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2134 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2135 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2136 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2137 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002138
Scott Michel0718cd82008-12-01 17:56:02 +00002139 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2140 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2141
2142 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2143 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michel06eabde2008-12-27 04:51:36 +00002144
2145 def gprc : SHUFBGPRCInst;
Scott Michel97872d32008-02-23 18:41:37 +00002146}
2147
2148defm SHUFB : ShuffleBytes;
2149
Scott Michel8b6b4202007-12-04 22:35:58 +00002150//===----------------------------------------------------------------------===//
2151// Shift and rotate group:
2152//===----------------------------------------------------------------------===//
2153
Scott Michel97872d32008-02-23 18:41:37 +00002154class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2155 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2156 RotateShift, pattern>;
2157
2158class SHLHVecInst<ValueType vectype>:
2159 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2160 [(set (vectype VECREG:$rT),
2161 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002162
Scott Michel97872d32008-02-23 18:41:37 +00002163multiclass ShiftLeftHalfword
2164{
2165 def v8i16: SHLHVecInst<v8i16>;
2166 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2167 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2168 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2169 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2170}
Scott Michel8b6b4202007-12-04 22:35:58 +00002171
Scott Michel97872d32008-02-23 18:41:37 +00002172defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00002173
Scott Michel97872d32008-02-23 18:41:37 +00002174//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00002175
Scott Michel97872d32008-02-23 18:41:37 +00002176class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2177 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2178 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002179
Scott Michel97872d32008-02-23 18:41:37 +00002180class SHLHIVecInst<ValueType vectype>:
2181 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2182 [(set (vectype VECREG:$rT),
2183 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002184
Scott Michel97872d32008-02-23 18:41:37 +00002185multiclass ShiftLeftHalfwordImm
2186{
2187 def v8i16: SHLHIVecInst<v8i16>;
2188 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2189 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2190}
2191
2192defm SHLHI : ShiftLeftHalfwordImm;
2193
2194def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2195 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2196
2197def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002198 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002199
Scott Michel97872d32008-02-23 18:41:37 +00002200//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002201
Scott Michel97872d32008-02-23 18:41:37 +00002202class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2203 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2204 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002205
Scott Michel97872d32008-02-23 18:41:37 +00002206multiclass ShiftLeftWord
2207{
2208 def v4i32:
2209 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2210 [(set (v4i32 VECREG:$rT),
2211 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2212 def r32:
2213 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2214 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2215}
Scott Michel8b6b4202007-12-04 22:35:58 +00002216
Scott Michel97872d32008-02-23 18:41:37 +00002217defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00002218
Scott Michel97872d32008-02-23 18:41:37 +00002219//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002220
Scott Michel97872d32008-02-23 18:41:37 +00002221class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2222 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2223 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002224
Scott Michel97872d32008-02-23 18:41:37 +00002225multiclass ShiftLeftWordImm
2226{
2227 def v4i32:
2228 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2229 [(set (v4i32 VECREG:$rT),
2230 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002231
Scott Michel97872d32008-02-23 18:41:37 +00002232 def r32:
2233 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2234 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2235}
Scott Michel8b6b4202007-12-04 22:35:58 +00002236
Scott Michel97872d32008-02-23 18:41:37 +00002237defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00002238
Scott Michel97872d32008-02-23 18:41:37 +00002239//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00002240// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2241// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00002242//
2243// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2244// of 7 bits is actually possible.
2245//
2246// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2247// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2248// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00002249
Scott Michel97872d32008-02-23 18:41:37 +00002250class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2251 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2252 RotateShift, pattern>;
2253
2254class SHLQBIVecInst<ValueType vectype>:
2255 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2256 [(set (vectype VECREG:$rT),
2257 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2258
Scott Michel8c67fa42009-01-21 04:58:48 +00002259class SHLQBIRegInst<RegisterClass rclass>:
2260 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2261 [/* no pattern */]>;
2262
Scott Michel97872d32008-02-23 18:41:37 +00002263multiclass ShiftLeftQuadByBits
2264{
2265 def v16i8: SHLQBIVecInst<v16i8>;
2266 def v8i16: SHLQBIVecInst<v8i16>;
2267 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002268 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002269 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002270 def v2f64: SHLQBIVecInst<v2f64>;
Scott Michel8c67fa42009-01-21 04:58:48 +00002271
2272 def r128: SHLQBIRegInst<GPRC>;
Scott Michel97872d32008-02-23 18:41:37 +00002273}
2274
2275defm SHLQBI : ShiftLeftQuadByBits;
2276
2277// See note above on SHLQBI. In this case, the predicate actually does then
2278// enforcement, whereas with SHLQBI, we have to "take it on faith."
2279class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2280 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2281 RotateShift, pattern>;
2282
2283class SHLQBIIVecInst<ValueType vectype>:
2284 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2285 [(set (vectype VECREG:$rT),
2286 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2287
2288multiclass ShiftLeftQuadByBitsImm
2289{
2290 def v16i8 : SHLQBIIVecInst<v16i8>;
2291 def v8i16 : SHLQBIIVecInst<v8i16>;
2292 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002293 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002294 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002295 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002296}
2297
2298defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002299
2300// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00002301// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00002302
Scott Michel97872d32008-02-23 18:41:37 +00002303class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michelfa888632008-11-25 00:23:16 +00002304 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002305 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002306
Scott Michel97872d32008-02-23 18:41:37 +00002307class SHLQBYVecInst<ValueType vectype>:
2308 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2309 [(set (vectype VECREG:$rT),
2310 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002311
Scott Michel97872d32008-02-23 18:41:37 +00002312multiclass ShiftLeftQuadBytes
2313{
2314 def v16i8: SHLQBYVecInst<v16i8>;
2315 def v8i16: SHLQBYVecInst<v8i16>;
2316 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002317 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002318 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002319 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002320 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2321 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2322}
Scott Michel8b6b4202007-12-04 22:35:58 +00002323
Scott Michel97872d32008-02-23 18:41:37 +00002324defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002325
Scott Michel97872d32008-02-23 18:41:37 +00002326class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2327 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2328 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00002329
Scott Michel97872d32008-02-23 18:41:37 +00002330class SHLQBYIVecInst<ValueType vectype>:
2331 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2332 [(set (vectype VECREG:$rT),
2333 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002334
Scott Michel97872d32008-02-23 18:41:37 +00002335multiclass ShiftLeftQuadBytesImm
2336{
2337 def v16i8: SHLQBYIVecInst<v16i8>;
2338 def v8i16: SHLQBYIVecInst<v8i16>;
2339 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel56a125e2008-11-22 23:50:42 +00002340 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002341 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel56a125e2008-11-22 23:50:42 +00002342 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002343 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2344 [(set GPRC:$rT,
2345 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2346}
Scott Michel438be252007-12-17 22:32:34 +00002347
Scott Michel97872d32008-02-23 18:41:37 +00002348defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00002349
Scott Michel8c67fa42009-01-21 04:58:48 +00002350class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2351 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2352 RotateShift, pattern>;
2353
2354class SHLQBYBIVecInst<ValueType vectype>:
2355 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2356 [/* no pattern */]>;
2357
2358class SHLQBYBIRegInst<RegisterClass rclass>:
2359 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2360 [/* no pattern */]>;
2361
2362multiclass ShiftLeftQuadBytesBitCount
2363{
2364 def v16i8: SHLQBYBIVecInst<v16i8>;
2365 def v8i16: SHLQBYBIVecInst<v8i16>;
2366 def v4i32: SHLQBYBIVecInst<v4i32>;
2367 def v4f32: SHLQBYBIVecInst<v4f32>;
2368 def v2i64: SHLQBYBIVecInst<v2i64>;
2369 def v2f64: SHLQBYBIVecInst<v2f64>;
2370
2371 def r128: SHLQBYBIRegInst<GPRC>;
2372}
2373
2374defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2375
Scott Michel97872d32008-02-23 18:41:37 +00002376//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2377// Rotate halfword:
2378//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2379class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2380 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2381 RotateShift, pattern>;
2382
2383class ROTHVecInst<ValueType vectype>:
2384 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2385 [(set (vectype VECREG:$rT),
2386 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2387
2388class ROTHRegInst<RegisterClass rclass>:
2389 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2390 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2391
2392multiclass RotateLeftHalfword
2393{
2394 def v8i16: ROTHVecInst<v8i16>;
2395 def r16: ROTHRegInst<R16C>;
2396}
2397
2398defm ROTH: RotateLeftHalfword;
2399
2400def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2401 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2402
2403//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2404// Rotate halfword, immediate:
2405//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2406class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2407 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2408 RotateShift, pattern>;
2409
2410class ROTHIVecInst<ValueType vectype>:
2411 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2412 [(set (vectype VECREG:$rT),
2413 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2414
2415multiclass RotateLeftHalfwordImm
2416{
2417 def v8i16: ROTHIVecInst<v8i16>;
2418 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2419 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2420 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2421 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2422}
2423
2424defm ROTHI: RotateLeftHalfwordImm;
2425
2426def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002427 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002428
Scott Michel97872d32008-02-23 18:41:37 +00002429//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2430// Rotate word:
2431//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002432
Scott Michel97872d32008-02-23 18:41:37 +00002433class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2434 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2435 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002436
Scott Michel97872d32008-02-23 18:41:37 +00002437class ROTVecInst<ValueType vectype>:
2438 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2439 [(set (vectype VECREG:$rT),
2440 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00002441
Scott Michel97872d32008-02-23 18:41:37 +00002442class ROTRegInst<RegisterClass rclass>:
2443 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2444 [(set rclass:$rT,
2445 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002446
Scott Michel97872d32008-02-23 18:41:37 +00002447multiclass RotateLeftWord
2448{
2449 def v4i32: ROTVecInst<v4i32>;
2450 def r32: ROTRegInst<R32C>;
2451}
2452
2453defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00002454
Scott Michel438be252007-12-17 22:32:34 +00002455// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2456// 32-bit register
2457def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002458 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2459 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002460
2461def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2462 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2463
2464def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2465 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2466
2467def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00002468 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2469 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00002470
2471def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2472 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2473
2474def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2475 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2476
Scott Michel97872d32008-02-23 18:41:37 +00002477//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2478// Rotate word, immediate
2479//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002480
Scott Michel97872d32008-02-23 18:41:37 +00002481class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2482 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2483 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002484
Scott Michel97872d32008-02-23 18:41:37 +00002485class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2486 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2487 [(set (vectype VECREG:$rT),
2488 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002489
Scott Michel97872d32008-02-23 18:41:37 +00002490class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2491 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2492 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002493
Scott Michel97872d32008-02-23 18:41:37 +00002494multiclass RotateLeftWordImm
2495{
2496 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2497 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2498 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002499
Scott Michel97872d32008-02-23 18:41:37 +00002500 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2501 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2502 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2503}
Scott Michel438be252007-12-17 22:32:34 +00002504
Scott Michel97872d32008-02-23 18:41:37 +00002505defm ROTI : RotateLeftWordImm;
2506
2507//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2508// Rotate quad by byte (count)
2509//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2510
2511class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2512 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2513 RotateShift, pattern>;
2514
2515class ROTQBYVecInst<ValueType vectype>:
2516 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2517 [(set (vectype VECREG:$rT),
2518 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2519
2520multiclass RotateQuadLeftByBytes
2521{
2522 def v16i8: ROTQBYVecInst<v16i8>;
2523 def v8i16: ROTQBYVecInst<v8i16>;
2524 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002525 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002526 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002527 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002528}
2529
2530defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002531
Scott Michel97872d32008-02-23 18:41:37 +00002532//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2533// Rotate quad by byte (count), immediate
2534//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2535
2536class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2537 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2538 RotateShift, pattern>;
2539
2540class ROTQBYIVecInst<ValueType vectype>:
2541 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2542 [(set (vectype VECREG:$rT),
2543 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2544
2545multiclass RotateQuadByBytesImm
2546{
2547 def v16i8: ROTQBYIVecInst<v16i8>;
2548 def v8i16: ROTQBYIVecInst<v8i16>;
2549 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michele2641a12008-12-04 21:01:44 +00002550 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michel97872d32008-02-23 18:41:37 +00002551 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michele2641a12008-12-04 21:01:44 +00002552 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michel97872d32008-02-23 18:41:37 +00002553}
2554
2555defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002556
Scott Michel8b6b4202007-12-04 22:35:58 +00002557// See ROTQBY note above.
Scott Michel67224b22008-06-02 22:18:03 +00002558class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2559 RI7Form<0b00110011100, OOL, IOL,
2560 "rotqbybi\t$rT, $rA, $shift",
2561 RotateShift, pattern>;
2562
2563class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2564 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2565 [(set (vectype VECREG:$rT),
2566 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2567
2568multiclass RotateQuadByBytesByBitshift {
2569 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2570 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2571 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2572 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2573}
2574
2575defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel8b6b4202007-12-04 22:35:58 +00002576
Scott Michel97872d32008-02-23 18:41:37 +00002577//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002578// See ROTQBY note above.
2579//
2580// Assume that the user of this instruction knows to shift the rotate count
2581// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002582//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002583
Scott Michel97872d32008-02-23 18:41:37 +00002584class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2585 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2586 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002587
Scott Michel97872d32008-02-23 18:41:37 +00002588class ROTQBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002589 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002590 [/* no pattern yet */]>;
2591
2592class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002593 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002594 [/* no pattern yet */]>;
2595
2596multiclass RotateQuadByBitCount
2597{
2598 def v16i8: ROTQBIVecInst<v16i8>;
2599 def v8i16: ROTQBIVecInst<v8i16>;
2600 def v4i32: ROTQBIVecInst<v4i32>;
2601 def v2i64: ROTQBIVecInst<v2i64>;
2602
2603 def r128: ROTQBIRegInst<GPRC>;
2604 def r64: ROTQBIRegInst<R64C>;
2605}
2606
2607defm ROTQBI: RotateQuadByBitCount;
Scott Michel06eabde2008-12-27 04:51:36 +00002608
Scott Michel97872d32008-02-23 18:41:37 +00002609class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2610 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2611 RotateShift, pattern>;
2612
2613class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2614 PatLeaf pred>:
2615 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2616 [/* no pattern yet */]>;
2617
2618class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2619 PatLeaf pred>:
2620 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2621 [/* no pattern yet */]>;
2622
2623multiclass RotateQuadByBitCountImm
2624{
2625 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2626 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2627 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2628 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2629
2630 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2631 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2632}
2633
2634defm ROTQBII : RotateQuadByBitCountImm;
2635
2636//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002637// ROTHM v8i16 form:
2638// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2639// so this only matches a synthetically generated/lowered code
2640// fragment.
2641// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002642//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002643
Scott Michel97872d32008-02-23 18:41:37 +00002644class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2645 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2646 RotateShift, pattern>;
2647
2648def ROTHMv8i16:
2649 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2650 [/* see patterns below - $rB must be negated */]>;
2651
2652def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002653 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2654
Scott Michel97872d32008-02-23 18:41:37 +00002655def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002656 (ROTHMv8i16 VECREG:$rA,
2657 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2658
Scott Michel97872d32008-02-23 18:41:37 +00002659def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002660 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002661 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002662
2663// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2664// Note: This instruction doesn't match a pattern because rB must be negated
2665// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002666
Scott Michel8b6b4202007-12-04 22:35:58 +00002667def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002668 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2669 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002670
2671def : Pat<(srl R16C:$rA, R32C:$rB),
2672 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2673
2674def : Pat<(srl R16C:$rA, R16C:$rB),
2675 (ROTHMr16 R16C:$rA,
2676 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2677
Scott Michel438be252007-12-17 22:32:34 +00002678def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002679 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002680 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002681
2682// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2683// that the immediate can be complemented, so that the user doesn't have to
2684// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002685
Scott Michel97872d32008-02-23 18:41:37 +00002686class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2687 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2688 RotateShift, pattern>;
2689
2690def ROTHMIv8i16:
2691 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2692 [/* no pattern */]>;
2693
2694def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2695 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2696
2697def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002698 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002699
Scott Michel97872d32008-02-23 18:41:37 +00002700def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002701 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002702
2703def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002704 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2705 [/* no pattern */]>;
2706
2707def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2708 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002709
2710def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2711 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2712
Scott Michel438be252007-12-17 22:32:34 +00002713def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2714 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2715
Scott Michel8b6b4202007-12-04 22:35:58 +00002716// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002717class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2718 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2719 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002720
Scott Michel97872d32008-02-23 18:41:37 +00002721def ROTMv4i32:
2722 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2723 [/* see patterns below - $rB must be negated */]>;
2724
2725def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002726 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2727
Scott Michel97872d32008-02-23 18:41:37 +00002728def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002729 (ROTMv4i32 VECREG:$rA,
2730 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2731
Scott Michel97872d32008-02-23 18:41:37 +00002732def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002733 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002734 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002735
2736def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002737 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2738 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002739
2740def : Pat<(srl R32C:$rA, R32C:$rB),
2741 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2742
2743def : Pat<(srl R32C:$rA, R16C:$rB),
2744 (ROTMr32 R32C:$rA,
2745 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2746
Scott Michel438be252007-12-17 22:32:34 +00002747def : Pat<(srl R32C:$rA, R8C:$rB),
2748 (ROTMr32 R32C:$rA,
2749 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2750
Scott Michel8b6b4202007-12-04 22:35:58 +00002751// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2752def ROTMIv4i32:
2753 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2754 "rotmi\t$rT, $rA, $val", RotateShift,
2755 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002756 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002757
Scott Michel97872d32008-02-23 18:41:37 +00002758def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002759 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel06eabde2008-12-27 04:51:36 +00002760
Scott Michel97872d32008-02-23 18:41:37 +00002761def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002762 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002763
2764// ROTMI r32 form: know how to complement the immediate value.
2765def ROTMIr32:
2766 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2767 "rotmi\t$rT, $rA, $val", RotateShift,
2768 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2769
2770def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2771 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2772
Scott Michel438be252007-12-17 22:32:34 +00002773def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2774 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2775
Scott Michel97872d32008-02-23 18:41:37 +00002776//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel2ef773a2009-01-06 03:36:14 +00002777// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel8b6b4202007-12-04 22:35:58 +00002778// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002779// that the user knew to negate $rB.
Scott Michel97872d32008-02-23 18:41:37 +00002780//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002781
Scott Michel97872d32008-02-23 18:41:37 +00002782class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2783 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2784 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002785
Scott Michel97872d32008-02-23 18:41:37 +00002786class ROTQMBYVecInst<ValueType vectype>:
2787 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2788 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002789
Scott Michel97872d32008-02-23 18:41:37 +00002790class ROTQMBYRegInst<RegisterClass rclass>:
2791 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00002792 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002793
Scott Michel97872d32008-02-23 18:41:37 +00002794multiclass RotateQuadBytes
2795{
2796 def v16i8: ROTQMBYVecInst<v16i8>;
2797 def v8i16: ROTQMBYVecInst<v8i16>;
2798 def v4i32: ROTQMBYVecInst<v4i32>;
2799 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002800
Scott Michel97872d32008-02-23 18:41:37 +00002801 def r128: ROTQMBYRegInst<GPRC>;
2802 def r64: ROTQMBYRegInst<R64C>;
2803}
2804
2805defm ROTQMBY : RotateQuadBytes;
2806
Scott Michel97872d32008-02-23 18:41:37 +00002807class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2808 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2809 RotateShift, pattern>;
2810
2811class ROTQMBYIVecInst<ValueType vectype>:
2812 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002813 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002814
Scott Michel2ef773a2009-01-06 03:36:14 +00002815class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2816 PatLeaf pred>:
Scott Michel97872d32008-02-23 18:41:37 +00002817 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002818 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002819
Scott Michel2ef773a2009-01-06 03:36:14 +00002820// 128-bit zero extension form:
2821class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2822 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2823 [/* no pattern */]>;
2824
Scott Michel97872d32008-02-23 18:41:37 +00002825multiclass RotateQuadBytesImm
2826{
2827 def v16i8: ROTQMBYIVecInst<v16i8>;
2828 def v8i16: ROTQMBYIVecInst<v8i16>;
2829 def v4i32: ROTQMBYIVecInst<v4i32>;
2830 def v2i64: ROTQMBYIVecInst<v2i64>;
2831
2832 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2833 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Michel2ef773a2009-01-06 03:36:14 +00002834
2835 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2836 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2837 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2838 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michel97872d32008-02-23 18:41:37 +00002839}
2840
2841defm ROTQMBYI : RotateQuadBytesImm;
2842
Scott Michel97872d32008-02-23 18:41:37 +00002843//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2844// Rotate right and mask by bit count
2845//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2846
2847class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2848 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2849 RotateShift, pattern>;
2850
2851class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel4d07fb72008-12-30 23:28:25 +00002852 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2853 [/* no pattern, */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002854
2855multiclass RotateMaskQuadByBitCount
2856{
2857 def v16i8: ROTQMBYBIVecInst<v16i8>;
2858 def v8i16: ROTQMBYBIVecInst<v8i16>;
2859 def v4i32: ROTQMBYBIVecInst<v4i32>;
2860 def v2i64: ROTQMBYBIVecInst<v2i64>;
2861}
2862
2863defm ROTQMBYBI: RotateMaskQuadByBitCount;
2864
2865//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2866// Rotate quad and mask by bits
2867// Note that the rotate amount has to be negated
2868//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2869
2870class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2871 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2872 RotateShift, pattern>;
2873
2874class ROTQMBIVecInst<ValueType vectype>:
2875 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2876 [/* no pattern */]>;
2877
2878class ROTQMBIRegInst<RegisterClass rclass>:
2879 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2880 [/* no pattern */]>;
2881
2882multiclass RotateMaskQuadByBits
2883{
2884 def v16i8: ROTQMBIVecInst<v16i8>;
2885 def v8i16: ROTQMBIVecInst<v8i16>;
2886 def v4i32: ROTQMBIVecInst<v4i32>;
2887 def v2i64: ROTQMBIVecInst<v2i64>;
2888
2889 def r128: ROTQMBIRegInst<GPRC>;
2890 def r64: ROTQMBIRegInst<R64C>;
2891}
2892
2893defm ROTQMBI: RotateMaskQuadByBits;
2894
Scott Michel97872d32008-02-23 18:41:37 +00002895//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2896// Rotate quad and mask by bits, immediate
2897//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2898
2899class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2900 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2901 RotateShift, pattern>;
2902
2903class ROTQMBIIVecInst<ValueType vectype>:
2904 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002905 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002906
2907class ROTQMBIIRegInst<RegisterClass rclass>:
2908 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel4d07fb72008-12-30 23:28:25 +00002909 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00002910
2911multiclass RotateMaskQuadByBitsImm
2912{
2913 def v16i8: ROTQMBIIVecInst<v16i8>;
2914 def v8i16: ROTQMBIIVecInst<v8i16>;
2915 def v4i32: ROTQMBIIVecInst<v4i32>;
2916 def v2i64: ROTQMBIIVecInst<v2i64>;
2917
2918 def r128: ROTQMBIIRegInst<GPRC>;
2919 def r64: ROTQMBIIRegInst<R64C>;
2920}
2921
2922defm ROTQMBII: RotateMaskQuadByBitsImm;
2923
2924//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2925//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002926
2927def ROTMAHv8i16:
2928 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2929 "rotmah\t$rT, $rA, $rB", RotateShift,
2930 [/* see patterns below - $rB must be negated */]>;
2931
Scott Michel97872d32008-02-23 18:41:37 +00002932def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002933 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2934
Scott Michel97872d32008-02-23 18:41:37 +00002935def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002936 (ROTMAHv8i16 VECREG:$rA,
2937 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2938
Scott Michel97872d32008-02-23 18:41:37 +00002939def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002940 (ROTMAHv8i16 VECREG:$rA,
2941 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2942
Scott Michel8b6b4202007-12-04 22:35:58 +00002943def ROTMAHr16:
2944 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2945 "rotmah\t$rT, $rA, $rB", RotateShift,
2946 [/* see patterns below - $rB must be negated */]>;
2947
2948def : Pat<(sra R16C:$rA, R32C:$rB),
2949 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2950
2951def : Pat<(sra R16C:$rA, R16C:$rB),
2952 (ROTMAHr16 R16C:$rA,
2953 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2954
Scott Michel438be252007-12-17 22:32:34 +00002955def : Pat<(sra R16C:$rA, R8C:$rB),
2956 (ROTMAHr16 R16C:$rA,
2957 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2958
Scott Michel8b6b4202007-12-04 22:35:58 +00002959def ROTMAHIv8i16:
2960 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2961 "rotmahi\t$rT, $rA, $val", RotateShift,
2962 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002963 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002964
Scott Michel97872d32008-02-23 18:41:37 +00002965def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002966 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2967
Scott Michel97872d32008-02-23 18:41:37 +00002968def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002969 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2970
Scott Michel8b6b4202007-12-04 22:35:58 +00002971def ROTMAHIr16:
2972 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2973 "rotmahi\t$rT, $rA, $val", RotateShift,
2974 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2975
2976def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2977 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2978
Scott Michel438be252007-12-17 22:32:34 +00002979def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2980 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2981
Scott Michel8b6b4202007-12-04 22:35:58 +00002982def ROTMAv4i32:
2983 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2984 "rotma\t$rT, $rA, $rB", RotateShift,
2985 [/* see patterns below - $rB must be negated */]>;
2986
Scott Michel97872d32008-02-23 18:41:37 +00002987def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002988 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2989
Scott Michel97872d32008-02-23 18:41:37 +00002990def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002991 (ROTMAv4i32 (v4i32 VECREG:$rA),
2992 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2993
Scott Michel97872d32008-02-23 18:41:37 +00002994def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002995 (ROTMAv4i32 (v4i32 VECREG:$rA),
2996 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2997
Scott Michel8b6b4202007-12-04 22:35:58 +00002998def ROTMAr32:
2999 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3000 "rotma\t$rT, $rA, $rB", RotateShift,
3001 [/* see patterns below - $rB must be negated */]>;
3002
3003def : Pat<(sra R32C:$rA, R32C:$rB),
3004 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
3005
3006def : Pat<(sra R32C:$rA, R16C:$rB),
3007 (ROTMAr32 R32C:$rA,
3008 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3009
Scott Michel438be252007-12-17 22:32:34 +00003010def : Pat<(sra R32C:$rA, R8C:$rB),
3011 (ROTMAr32 R32C:$rA,
3012 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3013
Scott Michel67224b22008-06-02 22:18:03 +00003014class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
3015 RRForm<0b01011110000, OOL, IOL,
3016 "rotmai\t$rT, $rA, $val",
3017 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003018
Scott Michel67224b22008-06-02 22:18:03 +00003019class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3020 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3021 [(set (vectype VECREG:$rT),
3022 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003023
Scott Michel67224b22008-06-02 22:18:03 +00003024class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3025 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3026 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003027
Scott Michel67224b22008-06-02 22:18:03 +00003028multiclass RotateMaskAlgebraicImm {
3029 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3030 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3031 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3032 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3033}
Scott Michel8b6b4202007-12-04 22:35:58 +00003034
Scott Michel67224b22008-06-02 22:18:03 +00003035defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel438be252007-12-17 22:32:34 +00003036
Scott Michel8b6b4202007-12-04 22:35:58 +00003037//===----------------------------------------------------------------------===//
3038// Branch and conditionals:
3039//===----------------------------------------------------------------------===//
3040
3041let isTerminator = 1, isBarrier = 1 in {
3042 // Halt If Equal (r32 preferred slot only, no vector form)
3043 def HEQr32:
3044 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3045 "heq\t$rA, $rB", BranchResolv,
3046 [/* no pattern to match */]>;
3047
3048 def HEQIr32 :
3049 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3050 "heqi\t$rA, $val", BranchResolv,
3051 [/* no pattern to match */]>;
3052
3053 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3054 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3055 def HGTr32:
3056 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3057 "hgt\t$rA, $rB", BranchResolv,
3058 [/* no pattern to match */]>;
3059
Scott Michel06eabde2008-12-27 04:51:36 +00003060 def HGTIr32:
Scott Michel8b6b4202007-12-04 22:35:58 +00003061 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3062 "hgti\t$rA, $val", BranchResolv,
3063 [/* no pattern to match */]>;
3064
3065 def HLGTr32:
3066 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3067 "hlgt\t$rA, $rB", BranchResolv,
3068 [/* no pattern to match */]>;
3069
3070 def HLGTIr32:
3071 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3072 "hlgti\t$rA, $val", BranchResolv,
3073 [/* no pattern to match */]>;
3074}
3075
Scott Michel06eabde2008-12-27 04:51:36 +00003076//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3077// Comparison operators for i8, i16 and i32:
3078//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003079
Scott Michel97872d32008-02-23 18:41:37 +00003080class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3081 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3082 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003083
Scott Michel97872d32008-02-23 18:41:37 +00003084multiclass CmpEqualByte
3085{
3086 def v16i8 :
3087 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3088 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3089 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00003090
Scott Michel97872d32008-02-23 18:41:37 +00003091 def r8 :
3092 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3093 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3094}
Scott Michel8b6b4202007-12-04 22:35:58 +00003095
Scott Michel97872d32008-02-23 18:41:37 +00003096class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3097 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3098 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003099
Scott Michel97872d32008-02-23 18:41:37 +00003100multiclass CmpEqualByteImm
3101{
3102 def v16i8 :
3103 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3104 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3105 v16i8SExt8Imm:$val))]>;
3106 def r8:
3107 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3108 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3109}
Scott Michel8b6b4202007-12-04 22:35:58 +00003110
Scott Michel97872d32008-02-23 18:41:37 +00003111class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3112 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3113 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003114
Scott Michel97872d32008-02-23 18:41:37 +00003115multiclass CmpEqualHalfword
3116{
3117 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3118 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3119 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003120
Scott Michel97872d32008-02-23 18:41:37 +00003121 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3122 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3123}
Scott Michel8b6b4202007-12-04 22:35:58 +00003124
Scott Michel97872d32008-02-23 18:41:37 +00003125class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3126 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3127 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003128
Scott Michel97872d32008-02-23 18:41:37 +00003129multiclass CmpEqualHalfwordImm
3130{
3131 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3132 [(set (v8i16 VECREG:$rT),
3133 (seteq (v8i16 VECREG:$rA),
3134 (v8i16 v8i16SExt10Imm:$val)))]>;
3135 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3136 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3137}
Scott Michel8b6b4202007-12-04 22:35:58 +00003138
Scott Michel97872d32008-02-23 18:41:37 +00003139class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3140 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3141 ByteOp, pattern>;
3142
3143multiclass CmpEqualWord
3144{
3145 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3146 [(set (v4i32 VECREG:$rT),
3147 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3148
3149 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3150 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3151}
3152
3153class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3154 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3155 ByteOp, pattern>;
3156
3157multiclass CmpEqualWordImm
3158{
3159 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3160 [(set (v4i32 VECREG:$rT),
3161 (seteq (v4i32 VECREG:$rA),
3162 (v4i32 v4i32SExt16Imm:$val)))]>;
3163
3164 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3165 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3166}
3167
3168class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3169 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3170 ByteOp, pattern>;
3171
3172multiclass CmpGtrByte
3173{
3174 def v16i8 :
3175 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3176 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3177 (v8i16 VECREG:$rB)))]>;
3178
3179 def r8 :
3180 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3181 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3182}
3183
3184class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3185 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3186 ByteOp, pattern>;
3187
3188multiclass CmpGtrByteImm
3189{
3190 def v16i8 :
3191 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3192 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3193 v16i8SExt8Imm:$val))]>;
3194 def r8:
3195 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00003196 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003197}
3198
3199class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3200 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3201 ByteOp, pattern>;
3202
3203multiclass CmpGtrHalfword
3204{
3205 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3206 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3207 (v8i16 VECREG:$rB)))]>;
3208
3209 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3210 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3211}
3212
3213class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3214 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3215 ByteOp, pattern>;
3216
3217multiclass CmpGtrHalfwordImm
3218{
3219 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3220 [(set (v8i16 VECREG:$rT),
3221 (setgt (v8i16 VECREG:$rA),
3222 (v8i16 v8i16SExt10Imm:$val)))]>;
3223 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3224 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3225}
3226
3227class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3228 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3229 ByteOp, pattern>;
3230
3231multiclass CmpGtrWord
3232{
3233 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3234 [(set (v4i32 VECREG:$rT),
3235 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3236
3237 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3238 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3239}
3240
3241class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3242 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3243 ByteOp, pattern>;
3244
3245multiclass CmpGtrWordImm
3246{
3247 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3248 [(set (v4i32 VECREG:$rT),
3249 (setgt (v4i32 VECREG:$rA),
3250 (v4i32 v4i32SExt16Imm:$val)))]>;
3251
3252 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3253 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003254
3255 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3256 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3257 [(set (v4i32 VECREG:$rT),
3258 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3259 (v4i32 v4i32SExt16Imm:$val)))]>;
3260
3261 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
pingbakb8913342009-01-26 03:37:41 +00003262 [/* no pattern */]>;
Scott Michel97872d32008-02-23 18:41:37 +00003263}
3264
3265class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003266 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003267 ByteOp, pattern>;
3268
3269multiclass CmpLGtrByte
3270{
3271 def v16i8 :
3272 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3273 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3274 (v8i16 VECREG:$rB)))]>;
3275
3276 def r8 :
3277 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3278 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3279}
3280
3281class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003282 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003283 ByteOp, pattern>;
3284
3285multiclass CmpLGtrByteImm
3286{
3287 def v16i8 :
3288 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3289 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3290 v16i8SExt8Imm:$val))]>;
3291 def r8:
3292 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3293 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3294}
3295
3296class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003297 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003298 ByteOp, pattern>;
3299
3300multiclass CmpLGtrHalfword
3301{
3302 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3303 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3304 (v8i16 VECREG:$rB)))]>;
3305
3306 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3307 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3308}
3309
3310class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003311 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003312 ByteOp, pattern>;
3313
3314multiclass CmpLGtrHalfwordImm
3315{
3316 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3317 [(set (v8i16 VECREG:$rT),
3318 (setugt (v8i16 VECREG:$rA),
3319 (v8i16 v8i16SExt10Imm:$val)))]>;
3320 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3321 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3322}
3323
3324class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003325 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00003326 ByteOp, pattern>;
3327
3328multiclass CmpLGtrWord
3329{
3330 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3331 [(set (v4i32 VECREG:$rT),
3332 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3333
3334 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3335 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3336}
3337
3338class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00003339 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00003340 ByteOp, pattern>;
3341
3342multiclass CmpLGtrWordImm
3343{
3344 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3345 [(set (v4i32 VECREG:$rT),
3346 (setugt (v4i32 VECREG:$rA),
3347 (v4i32 v4i32SExt16Imm:$val)))]>;
3348
3349 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00003350 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00003351}
3352
3353defm CEQB : CmpEqualByte;
3354defm CEQBI : CmpEqualByteImm;
3355defm CEQH : CmpEqualHalfword;
3356defm CEQHI : CmpEqualHalfwordImm;
3357defm CEQ : CmpEqualWord;
3358defm CEQI : CmpEqualWordImm;
3359defm CGTB : CmpGtrByte;
3360defm CGTBI : CmpGtrByteImm;
3361defm CGTH : CmpGtrHalfword;
3362defm CGTHI : CmpGtrHalfwordImm;
3363defm CGT : CmpGtrWord;
3364defm CGTI : CmpGtrWordImm;
3365defm CLGTB : CmpLGtrByte;
3366defm CLGTBI : CmpLGtrByteImm;
3367defm CLGTH : CmpLGtrHalfword;
3368defm CLGTHI : CmpLGtrHalfwordImm;
3369defm CLGT : CmpLGtrWord;
3370defm CLGTI : CmpLGtrWordImm;
3371
Scott Michel53ab7792008-03-10 16:58:52 +00003372//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003373// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3374// define a pattern to generate the right code, as a binary operator
3375// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00003376//
Scott Michel06eabde2008-12-27 04:51:36 +00003377// Notes:
3378// 1. This only matches the setcc set of conditionals. Special pattern
3379// matching is used for select conditionals.
3380//
3381// 2. The "DAG" versions of these classes is almost exclusively used for
3382// i64 comparisons. See the tblgen fundamentals documentation for what
3383// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3384// class for where ResultInstrs originates.
Scott Michel53ab7792008-03-10 16:58:52 +00003385//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00003386
Scott Michel53ab7792008-03-10 16:58:52 +00003387class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3388 SPUInstr xorinst, SPUInstr cmpare>:
3389 Pat<(cond rclass:$rA, rclass:$rB),
3390 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3391
3392class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3393 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3394 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3395 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3396
Scott Michel06eabde2008-12-27 04:51:36 +00003397def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel53ab7792008-03-10 16:58:52 +00003398def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3399
Scott Michel06eabde2008-12-27 04:51:36 +00003400def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel53ab7792008-03-10 16:58:52 +00003401def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3402
3403def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3404def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003405
3406class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3407 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3408 Pat<(cond rclass:$rA, rclass:$rB),
3409 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3410 (cmpOp2 rclass:$rA, rclass:$rB))>;
3411
3412class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3413 ValueType immtype,
3414 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3415 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3416 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3417 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3418
Scott Michel53ab7792008-03-10 16:58:52 +00003419def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3420def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3421def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3422def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3423def : Pat<(setle R8C:$rA, R8C:$rB),
3424 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3425def : Pat<(setle R8C:$rA, immU8:$imm),
3426 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003427
Scott Michel53ab7792008-03-10 16:58:52 +00003428def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3429def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3430 ORr16, CGTHIr16, CEQHIr16>;
3431def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3432def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3433def : Pat<(setle R16C:$rA, R16C:$rB),
3434 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3435def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3436 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003437
Scott Michel53ab7792008-03-10 16:58:52 +00003438def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3439def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3440 ORr32, CGTIr32, CEQIr32>;
3441def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3442def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3443def : Pat<(setle R32C:$rA, R32C:$rB),
3444 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3445def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3446 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003447
Scott Michel53ab7792008-03-10 16:58:52 +00003448def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3449def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3450def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3451def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3452def : Pat<(setule R8C:$rA, R8C:$rB),
3453 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3454def : Pat<(setule R8C:$rA, immU8:$imm),
3455 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003456
Scott Michel53ab7792008-03-10 16:58:52 +00003457def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3458def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3459 ORr16, CLGTHIr16, CEQHIr16>;
3460def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3461def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3462 CLGTHIr16, CEQHIr16>;
3463def : Pat<(setule R16C:$rA, R16C:$rB),
3464 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00003465def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00003466 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003467
Scott Michel53ab7792008-03-10 16:58:52 +00003468def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003469def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00003470 ORr32, CLGTIr32, CEQIr32>;
3471def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00003472def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00003473def : Pat<(setule R32C:$rA, R32C:$rB),
3474 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3475def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3476 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00003477
Scott Michel53ab7792008-03-10 16:58:52 +00003478//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3479// select conditional patterns:
3480//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3481
3482class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3483 SPUInstr selinstr, SPUInstr cmpare>:
3484 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3485 rclass:$rTrue, rclass:$rFalse),
3486 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendling8f6608b2008-07-22 08:50:44 +00003487 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel53ab7792008-03-10 16:58:52 +00003488
3489class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3490 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3491 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003492 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003493 (selinstr rclass:$rTrue, rclass:$rFalse,
3494 (cmpare rclass:$rA, immpred:$imm))>;
3495
3496def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3497def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3498def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3499def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3500def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3501def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3502
3503def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3504def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3505def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3506def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3507def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3508def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3509
3510def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3511def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3512def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3513def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3514def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3515def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3516
3517class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3518 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3519 SPUInstr cmpOp2>:
3520 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michel06eabde2008-12-27 04:51:36 +00003521 rclass:$rTrue, rclass:$rFalse),
3522 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel53ab7792008-03-10 16:58:52 +00003523 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3524 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3525
3526class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3527 ValueType inttype,
3528 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3529 SPUInstr cmpOp2>:
3530 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendling8f6608b2008-07-22 08:50:44 +00003531 rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00003532 (selinstr rclass:$rFalse, rclass:$rTrue,
3533 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3534 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3535
3536def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3537def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3538 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3539
3540def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3541def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3542 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3543
3544def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3545def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3546 SELBr32, ORr32, CGTIr32, CEQIr32>;
3547
3548def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3549def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3550 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3551
3552def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3553def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3554 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3555
3556def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3557def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3558 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003559
3560//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003561
3562let isCall = 1,
3563 // All calls clobber the non-callee-saved registers:
3564 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3565 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3566 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3567 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3568 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3569 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3570 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3571 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3572 // All of these instructions use $lr (aka $0)
3573 Uses = [R0] in {
3574 // Branch relative and set link: Used if we actually know that the target
3575 // is within [-32768, 32767] bytes of the target
3576 def BRSL:
3577 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3578 "brsl\t$$lr, $func",
3579 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3580
3581 // Branch absolute and set link: Used if we actually know that the target
3582 // is an absolute address
3583 def BRASL:
3584 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3585 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003586 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003587
3588 // Branch indirect and set link if external data. These instructions are not
3589 // actually generated, matched by an intrinsic:
3590 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3591 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3592 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3593 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3594
3595 // Branch indirect and set link. This is the "X-form" address version of a
3596 // function call
3597 def BISL:
3598 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3599}
3600
Scott Michelae5cbf52008-12-29 03:23:36 +00003601// Support calls to external symbols:
3602def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3603 (BRSL texternalsym:$func)>;
3604
3605def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3606 (BRASL texternalsym:$func)>;
3607
Scott Michel8b6b4202007-12-04 22:35:58 +00003608// Unconditional branches:
3609let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3610 def BR :
3611 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3612 "br\t$dest",
3613 [(br bb:$dest)]>;
3614
3615 // Unconditional, absolute address branch
3616 def BRA:
3617 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3618 "bra\t$dest",
3619 [/* no pattern */]>;
3620
3621 // Indirect branch
3622 def BI:
3623 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3624
Scott Michele0168c12009-01-05 01:34:35 +00003625 // Conditional branches:
Scott Michel06eabde2008-12-27 04:51:36 +00003626 class BRNZInst<dag IOL, list<dag> pattern>:
3627 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3628 BranchResolv, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003629
Scott Michel06eabde2008-12-27 04:51:36 +00003630 class BRNZRegInst<RegisterClass rclass>:
3631 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3632 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003633
Scott Michel06eabde2008-12-27 04:51:36 +00003634 class BRNZVecInst<ValueType vectype>:
3635 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3636 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003637
Scott Michel06eabde2008-12-27 04:51:36 +00003638 multiclass BranchNotZero {
3639 def v4i32 : BRNZVecInst<v4i32>;
3640 def r32 : BRNZRegInst<R32C>;
3641 }
Scott Michel8b6b4202007-12-04 22:35:58 +00003642
Scott Michel06eabde2008-12-27 04:51:36 +00003643 defm BRNZ : BranchNotZero;
3644
3645 class BRZInst<dag IOL, list<dag> pattern>:
3646 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3647 BranchResolv, pattern>;
3648
3649 class BRZRegInst<RegisterClass rclass>:
3650 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3651
3652 class BRZVecInst<ValueType vectype>:
3653 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3654
3655 multiclass BranchZero {
3656 def v4i32: BRZVecInst<v4i32>;
3657 def r32: BRZRegInst<R32C>;
3658 }
3659
3660 defm BRZ: BranchZero;
3661
3662 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3663 // be useful:
3664 /*
3665 class BINZInst<dag IOL, list<dag> pattern>:
3666 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3667
3668 class BINZRegInst<RegisterClass rclass>:
3669 BINZInst<(ins rclass:$rA, brtarget:$dest),
3670 [(brcond rclass:$rA, R32C:$dest)]>;
3671
3672 class BINZVecInst<ValueType vectype>:
3673 BINZInst<(ins VECREG:$rA, R32C:$dest),
3674 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3675
3676 multiclass BranchNotZeroIndirect {
3677 def v4i32: BINZVecInst<v4i32>;
3678 def r32: BINZRegInst<R32C>;
3679 }
3680
3681 defm BINZ: BranchNotZeroIndirect;
3682
3683 class BIZInst<dag IOL, list<dag> pattern>:
3684 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3685
3686 class BIZRegInst<RegisterClass rclass>:
3687 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3688
3689 class BIZVecInst<ValueType vectype>:
3690 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3691
3692 multiclass BranchZeroIndirect {
3693 def v4i32: BIZVecInst<v4i32>;
3694 def r32: BIZRegInst<R32C>;
3695 }
3696
3697 defm BIZ: BranchZeroIndirect;
3698 */
3699
3700 class BRHNZInst<dag IOL, list<dag> pattern>:
3701 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3702 pattern>;
3703
3704 class BRHNZRegInst<RegisterClass rclass>:
3705 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3706 [(brcond rclass:$rCond, bb:$dest)]>;
3707
3708 class BRHNZVecInst<ValueType vectype>:
3709 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3710
3711 multiclass BranchNotZeroHalfword {
3712 def v8i16: BRHNZVecInst<v8i16>;
3713 def r16: BRHNZRegInst<R16C>;
3714 }
3715
3716 defm BRHNZ: BranchNotZeroHalfword;
3717
3718 class BRHZInst<dag IOL, list<dag> pattern>:
3719 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3720 pattern>;
3721
3722 class BRHZRegInst<RegisterClass rclass>:
3723 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3724
3725 class BRHZVecInst<ValueType vectype>:
3726 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3727
3728 multiclass BranchZeroHalfword {
3729 def v8i16: BRHZVecInst<v8i16>;
3730 def r16: BRHZRegInst<R16C>;
3731 }
3732
3733 defm BRHZ: BranchZeroHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00003734}
3735
Scott Michel394e26d2008-01-17 20:38:41 +00003736//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003737// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003738//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003739
Scott Michel06eabde2008-12-27 04:51:36 +00003740def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3741 (BRHZr16 R16C:$rA, bb:$dest)>;
3742def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3743 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003744
Scott Michel06eabde2008-12-27 04:51:36 +00003745def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3746 (BRZr32 R32C:$rA, bb:$dest)>;
3747def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3748 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003749
Scott Michel97872d32008-02-23 18:41:37 +00003750multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3751{
3752 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3753 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003754
Scott Michel97872d32008-02-23 18:41:37 +00003755 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3756 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3757
3758 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3759 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3760
3761 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3762 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3763}
3764
Scott Michele0168c12009-01-05 01:34:35 +00003765defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3766defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003767
3768multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3769{
3770 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3771 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3772
3773 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3774 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3775
3776 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3777 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3778
3779 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3780 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3781}
3782
Scott Michel06eabde2008-12-27 04:51:36 +00003783defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3784defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003785
3786multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3787 SPUInstr orinst32, SPUInstr brinst32>
3788{
3789 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3790 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3791 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3792 bb:$dest)>;
3793
3794 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3795 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3796 (CEQHr16 R16C:$rA, R16:$rB)),
3797 bb:$dest)>;
3798
3799 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3800 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3801 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3802 bb:$dest)>;
3803
3804 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3805 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3806 (CEQr32 R32C:$rA, R32C:$rB)),
3807 bb:$dest)>;
3808}
3809
Scott Michel06eabde2008-12-27 04:51:36 +00003810defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3811defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003812
3813multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3814{
3815 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3816 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3817
3818 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3819 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3820
3821 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3822 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3823
3824 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3825 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3826}
3827
Scott Michel06eabde2008-12-27 04:51:36 +00003828defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3829defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003830
3831multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3832 SPUInstr orinst32, SPUInstr brinst32>
3833{
3834 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3835 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3836 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3837 bb:$dest)>;
3838
3839 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3840 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3841 (CEQHr16 R16C:$rA, R16:$rB)),
3842 bb:$dest)>;
3843
3844 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3845 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3846 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3847 bb:$dest)>;
3848
3849 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3850 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3851 (CEQr32 R32C:$rA, R32C:$rB)),
3852 bb:$dest)>;
3853}
3854
Scott Michel06eabde2008-12-27 04:51:36 +00003855defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3856defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003857
Scott Michel8b6b4202007-12-04 22:35:58 +00003858let isTerminator = 1, isBarrier = 1 in {
3859 let isReturn = 1 in {
3860 def RET:
3861 RETForm<"bi\t$$lr", [(retflag)]>;
3862 }
3863}
3864
3865//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003866// Single precision floating point instructions
3867//===----------------------------------------------------------------------===//
3868
Scott Michel61895fe2008-12-10 00:15:19 +00003869class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3870 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003871 SPrecFP, pattern>;
Scott Michel06eabde2008-12-27 04:51:36 +00003872
Scott Michel61895fe2008-12-10 00:15:19 +00003873class FAVecInst<ValueType vectype>:
3874 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3875 [(set (vectype VECREG:$rT),
Scott Michel4d07fb72008-12-30 23:28:25 +00003876 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel06eabde2008-12-27 04:51:36 +00003877
Scott Michel61895fe2008-12-10 00:15:19 +00003878multiclass SFPAdd
3879{
3880 def v4f32: FAVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003881 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3882 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003883}
Scott Michel8b6b4202007-12-04 22:35:58 +00003884
Scott Michel61895fe2008-12-10 00:15:19 +00003885defm FA : SFPAdd;
Scott Michel8b6b4202007-12-04 22:35:58 +00003886
Scott Michel61895fe2008-12-10 00:15:19 +00003887class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3888 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel4d07fb72008-12-30 23:28:25 +00003889 SPrecFP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003890
Scott Michel61895fe2008-12-10 00:15:19 +00003891class FSVecInst<ValueType vectype>:
3892 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel4d07fb72008-12-30 23:28:25 +00003893 [(set (vectype VECREG:$rT),
3894 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003895
3896multiclass SFPSub
3897{
3898 def v4f32: FSVecInst<v4f32>;
Scott Michel4d07fb72008-12-30 23:28:25 +00003899 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3900 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michel61895fe2008-12-10 00:15:19 +00003901}
3902
3903defm FS : SFPSub;
Scott Michel8b6b4202007-12-04 22:35:58 +00003904
3905// Floating point reciprocal estimate
Scott Michel8b6b4202007-12-04 22:35:58 +00003906
Scott Michel4d07fb72008-12-30 23:28:25 +00003907class FRESTInst<dag OOL, dag IOL>:
3908 RRForm_1<0b00110111000, OOL, IOL,
3909 "frest\t$rT, $rA", SPrecFP,
3910 [/* no pattern */]>;
3911
3912def FRESTv4f32 :
3913 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3914
3915def FRESTf32 :
3916 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003917
3918// Floating point interpolate (used in conjunction with reciprocal estimate)
3919def FIv4f32 :
3920 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3921 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003922 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003923
3924def FIf32 :
3925 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3926 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel4d07fb72008-12-30 23:28:25 +00003927 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003928
Scott Michel33d73eb2008-11-21 02:56:16 +00003929//--------------------------------------------------------------------------
3930// Basic single precision floating point comparisons:
3931//
3932// Note: There is no support on SPU for single precision NaN. Consequently,
3933// ordered and unordered comparisons are the same.
3934//--------------------------------------------------------------------------
3935
Scott Michel8b6b4202007-12-04 22:35:58 +00003936def FCEQf32 :
3937 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3938 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003939 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3940
3941def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3942 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003943
3944def FCMEQf32 :
3945 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3946 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003947 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3948
3949def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3950 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003951
3952def FCGTf32 :
3953 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3954 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003955 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3956
3957def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3958 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003959
3960def FCMGTf32 :
3961 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3962 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel33d73eb2008-11-21 02:56:16 +00003963 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3964
3965def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3966 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3967
3968//--------------------------------------------------------------------------
3969// Single precision floating point comparisons and SETCC equivalents:
3970//--------------------------------------------------------------------------
3971
3972def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3973def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3974
3975def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3976def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3977
3978def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3979def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3980
3981def : Pat<(setule R32FP:$rA, R32FP:$rB),
3982 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3983def : Pat<(setole R32FP:$rA, R32FP:$rB),
3984 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003985
3986// FP Status and Control Register Write
3987// Why isn't rT a don't care in the ISA?
3988// Should we create a special RRForm_3 for this guy and zero out the rT?
3989def FSCRWf32 :
3990 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3991 "fscrwr\t$rA", SPrecFP,
3992 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3993
3994// FP Status and Control Register Read
3995def FSCRRf32 :
3996 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3997 "fscrrd\t$rT", SPrecFP,
3998 [/* This instruction requires an intrinsic */]>;
3999
4000// llvm instruction space
4001// How do these map onto cell instructions?
4002// fdiv rA rB
4003// frest rC rB # c = 1/b (both lines)
4004// fi rC rB rC
4005// fm rD rA rC # d = a * 1/b
4006// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4007// fma rB rB rC rD # b = b * c + d
4008// = -(d *b -a) * c + d
4009// = a * c - c ( a *b *c - a)
4010
4011// fcopysign (???)
4012
4013// Library calls:
4014// These llvm instructions will actually map to library calls.
4015// All that's needed, then, is to check that the appropriate library is
4016// imported and do a brsl to the proper function name.
4017// frem # fmod(x, y): x - (x/y) * y
4018// (Note: fmod(double, double), fmodf(float,float)
4019// fsqrt?
4020// fsin?
4021// fcos?
4022// Unimplemented SPU instruction space
4023// floating reciprocal absolute square root estimate (frsqest)
4024
4025// The following are probably just intrinsics
Scott Michel06eabde2008-12-27 04:51:36 +00004026// status and control register write
Scott Michel8b6b4202007-12-04 22:35:58 +00004027// status and control register read
4028
4029//--------------------------------------
4030// Floating point multiply instructions
4031//--------------------------------------
4032
4033def FMv4f32:
4034 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4035 "fm\t$rT, $rA, $rB", SPrecFP,
4036 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
4037 (v4f32 VECREG:$rB)))]>;
4038
4039def FMf32 :
4040 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4041 "fm\t$rT, $rA, $rB", SPrecFP,
4042 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
4043
4044// Floating point multiply and add
4045// e.g. d = c + (a * b)
4046def FMAv4f32:
4047 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4048 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4049 [(set (v4f32 VECREG:$rT),
4050 (fadd (v4f32 VECREG:$rC),
4051 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
4052
4053def FMAf32:
4054 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4055 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4056 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4057
4058// FP multiply and subtract
4059// Subtracts value in rC from product
4060// res = a * b - c
4061def FMSv4f32 :
4062 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4063 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4064 [(set (v4f32 VECREG:$rT),
4065 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
4066 (v4f32 VECREG:$rC)))]>;
4067
4068def FMSf32 :
4069 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4070 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4071 [(set R32FP:$rT,
4072 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
4073
4074// Floating Negative Mulitply and Subtract
4075// Subtracts product from value in rC
4076// res = fneg(fms a b c)
4077// = - (a * b - c)
4078// = c - a * b
4079// NOTE: subtraction order
4080// fsub a b = a - b
Scott Michel06eabde2008-12-27 04:51:36 +00004081// fs a b = b - a?
Scott Michel8b6b4202007-12-04 22:35:58 +00004082def FNMSf32 :
4083 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4084 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4085 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4086
4087def FNMSv4f32 :
4088 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4089 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004090 [(set (v4f32 VECREG:$rT),
4091 (fsub (v4f32 VECREG:$rC),
4092 (fmul (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004093 (v4f32 VECREG:$rB))))]>;
4094
4095//--------------------------------------
4096// Floating Point Conversions
4097// Signed conversions:
4098def CSiFv4f32:
4099 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4100 "csflt\t$rT, $rA, 0", SPrecFP,
4101 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4102
Scott Michel06eabde2008-12-27 04:51:36 +00004103// Convert signed integer to floating point
Scott Michel8b6b4202007-12-04 22:35:58 +00004104def CSiFf32 :
4105 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4106 "csflt\t$rT, $rA, 0", SPrecFP,
4107 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4108
4109// Convert unsigned into to float
4110def CUiFv4f32 :
4111 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4112 "cuflt\t$rT, $rA, 0", SPrecFP,
4113 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4114
4115def CUiFf32 :
4116 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4117 "cuflt\t$rT, $rA, 0", SPrecFP,
4118 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4119
Scott Michel06eabde2008-12-27 04:51:36 +00004120// Convert float to unsigned int
Scott Michel8b6b4202007-12-04 22:35:58 +00004121// Assume that scale = 0
4122
4123def CFUiv4f32 :
4124 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4125 "cfltu\t$rT, $rA, 0", SPrecFP,
4126 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4127
4128def CFUif32 :
4129 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4130 "cfltu\t$rT, $rA, 0", SPrecFP,
4131 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4132
Scott Michel06eabde2008-12-27 04:51:36 +00004133// Convert float to signed int
Scott Michel8b6b4202007-12-04 22:35:58 +00004134// Assume that scale = 0
4135
4136def CFSiv4f32 :
4137 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4138 "cflts\t$rT, $rA, 0", SPrecFP,
4139 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4140
4141def CFSif32 :
4142 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4143 "cflts\t$rT, $rA, 0", SPrecFP,
4144 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4145
4146//===----------------------------------------------------------------------==//
4147// Single<->Double precision conversions
4148//===----------------------------------------------------------------------==//
4149
4150// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4151// v4f32, output is v2f64--which goes in the name?)
4152
4153// Floating point extend single to double
4154// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4155// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4156// are ignored).
4157def FESDvec :
4158 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4159 "fesd\t$rT, $rA", SPrecFP,
4160 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4161
4162def FESDf32 :
4163 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4164 "fesd\t$rT, $rA", SPrecFP,
4165 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4166
4167// Floating point round double to single
4168//def FRDSvec :
4169// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4170// "frds\t$rT, $rA,", SPrecFP,
4171// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4172
4173def FRDSf64 :
4174 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4175 "frds\t$rT, $rA", SPrecFP,
4176 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4177
4178//ToDo include anyextend?
4179
4180//===----------------------------------------------------------------------==//
4181// Double precision floating point instructions
4182//===----------------------------------------------------------------------==//
4183def FAf64 :
4184 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4185 "dfa\t$rT, $rA, $rB", DPrecFP,
4186 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4187
4188def FAv2f64 :
4189 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4190 "dfa\t$rT, $rA, $rB", DPrecFP,
4191 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4192
4193def FSf64 :
4194 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4195 "dfs\t$rT, $rA, $rB", DPrecFP,
4196 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4197
4198def FSv2f64 :
4199 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4200 "dfs\t$rT, $rA, $rB", DPrecFP,
4201 [(set (v2f64 VECREG:$rT),
4202 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4203
4204def FMf64 :
4205 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4206 "dfm\t$rT, $rA, $rB", DPrecFP,
4207 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4208
4209def FMv2f64:
4210 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4211 "dfm\t$rT, $rA, $rB", DPrecFP,
4212 [(set (v2f64 VECREG:$rT),
4213 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4214
4215def FMAf64:
4216 RRForm<0b00111010110, (outs R64FP:$rT),
4217 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4218 "dfma\t$rT, $rA, $rB", DPrecFP,
4219 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4220 RegConstraint<"$rC = $rT">,
4221 NoEncode<"$rC">;
4222
4223def FMAv2f64:
4224 RRForm<0b00111010110, (outs VECREG:$rT),
4225 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4226 "dfma\t$rT, $rA, $rB", DPrecFP,
4227 [(set (v2f64 VECREG:$rT),
4228 (fadd (v2f64 VECREG:$rC),
4229 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4230 RegConstraint<"$rC = $rT">,
4231 NoEncode<"$rC">;
4232
4233def FMSf64 :
4234 RRForm<0b10111010110, (outs R64FP:$rT),
4235 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4236 "dfms\t$rT, $rA, $rB", DPrecFP,
4237 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4238 RegConstraint<"$rC = $rT">,
4239 NoEncode<"$rC">;
4240
4241def FMSv2f64 :
4242 RRForm<0b10111010110, (outs VECREG:$rT),
4243 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4244 "dfms\t$rT, $rA, $rB", DPrecFP,
4245 [(set (v2f64 VECREG:$rT),
4246 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4247 (v2f64 VECREG:$rC)))]>;
4248
4249// FNMS: - (a * b - c)
4250// - (a * b) + c => c - (a * b)
4251def FNMSf64 :
4252 RRForm<0b01111010110, (outs R64FP:$rT),
4253 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4254 "dfnms\t$rT, $rA, $rB", DPrecFP,
4255 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4256 RegConstraint<"$rC = $rT">,
4257 NoEncode<"$rC">;
4258
4259def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
4260 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
4261
4262def FNMSv2f64 :
4263 RRForm<0b01111010110, (outs VECREG:$rT),
4264 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4265 "dfnms\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004266 [(set (v2f64 VECREG:$rT),
4267 (fsub (v2f64 VECREG:$rC),
4268 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004269 (v2f64 VECREG:$rB))))]>,
4270 RegConstraint<"$rC = $rT">,
4271 NoEncode<"$rC">;
4272
4273def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4274 (v2f64 VECREG:$rC))),
4275 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
4276
4277// - (a * b + c)
4278// - (a * b) - c
4279def FNMAf64 :
4280 RRForm<0b11111010110, (outs R64FP:$rT),
4281 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4282 "dfnma\t$rT, $rA, $rB", DPrecFP,
4283 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4284 RegConstraint<"$rC = $rT">,
4285 NoEncode<"$rC">;
4286
4287def FNMAv2f64 :
4288 RRForm<0b11111010110, (outs VECREG:$rT),
4289 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4290 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michel06eabde2008-12-27 04:51:36 +00004291 [(set (v2f64 VECREG:$rT),
4292 (fneg (fadd (v2f64 VECREG:$rC),
4293 (fmul (v2f64 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004294 (v2f64 VECREG:$rB)))))]>,
4295 RegConstraint<"$rC = $rT">,
4296 NoEncode<"$rC">;
4297
4298//===----------------------------------------------------------------------==//
4299// Floating point negation and absolute value
4300//===----------------------------------------------------------------------==//
4301
4302def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michel06eabde2008-12-27 04:51:36 +00004303 (XORfnegvec (v4f32 VECREG:$rA),
Scott Michel8b6b4202007-12-04 22:35:58 +00004304 (v4f32 (ILHUv4i32 0x8000)))>;
4305
4306def : Pat<(fneg R32FP:$rA),
4307 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4308
4309def : Pat<(fneg (v2f64 VECREG:$rA)),
4310 (XORfnegvec (v2f64 VECREG:$rA),
4311 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
4312
4313def : Pat<(fneg R64FP:$rA),
4314 (XORfneg64 R64FP:$rA,
4315 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
4316
4317// Floating point absolute value
4318
4319def : Pat<(fabs R32FP:$rA),
4320 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4321
4322def : Pat<(fabs (v4f32 VECREG:$rA)),
4323 (ANDfabsvec (v4f32 VECREG:$rA),
4324 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4325
pingbak2f387e82009-01-26 03:31:40 +00004326def : Pat<(fabs R64FP:$rA),
4327 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
4328
4329def : Pat<(fabs (v2f64 VECREG:$rA)),
4330 (ANDfabsvec (v2f64 VECREG:$rA),
4331 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
4332
Scott Michel8b6b4202007-12-04 22:35:58 +00004333//===----------------------------------------------------------------------===//
Scott Michel61895fe2008-12-10 00:15:19 +00004334// Hint for branch instructions:
4335//===----------------------------------------------------------------------===//
4336
4337/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4338
4339//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00004340// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4341// in the odd pipeline)
4342//===----------------------------------------------------------------------===//
4343
Scott Michel97872d32008-02-23 18:41:37 +00004344def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004345 let Pattern = [];
4346
4347 let Inst{0-10} = 0b10000000010;
4348 let Inst{11-17} = 0;
4349 let Inst{18-24} = 0;
4350 let Inst{25-31} = 0;
4351}
4352
Scott Michel97872d32008-02-23 18:41:37 +00004353def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00004354 let Pattern = [];
4355
4356 let Inst{0-10} = 0b10000000000;
4357 let Inst{11-17} = 0;
4358 let Inst{18-24} = 0;
4359 let Inst{25-31} = 0;
4360}
4361
4362//===----------------------------------------------------------------------===//
4363// Bit conversions (type conversions between vector/packed types)
4364// NOTE: Promotions are handled using the XS* instructions. Truncation
4365// is not handled.
4366//===----------------------------------------------------------------------===//
4367def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4368def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4369def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4370def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4371def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4372
4373def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4374def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4375def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4376def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4377def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4378
4379def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4380def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4381def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4382def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4383def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4384
4385def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4386def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4387def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4388def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4389def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4390
4391def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4392def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4393def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4394def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4395def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4396
4397def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4398def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4399def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4400def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4401def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4402
4403def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00004404def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004405
4406//===----------------------------------------------------------------------===//
4407// Instruction patterns:
4408//===----------------------------------------------------------------------===//
4409
4410// General 32-bit constants:
4411def : Pat<(i32 imm:$imm),
4412 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4413
4414// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00004415def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00004416 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4417
4418// General constant 32-bit vectors
4419def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00004420 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4421 (LO16_vec v4i32Imm:$imm))>;
Scott Michel06eabde2008-12-27 04:51:36 +00004422
Scott Michel438be252007-12-17 22:32:34 +00004423// 8-bit constants
4424def : Pat<(i8 imm:$imm),
4425 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004426
4427//===----------------------------------------------------------------------===//
4428// Call instruction patterns:
4429//===----------------------------------------------------------------------===//
4430// Return void
4431def : Pat<(ret),
4432 (RET)>;
4433
4434//===----------------------------------------------------------------------===//
4435// Zero/Any/Sign extensions
4436//===----------------------------------------------------------------------===//
4437
Scott Michel8b6b4202007-12-04 22:35:58 +00004438// sext 8->32: Sign extend bytes to words
4439def : Pat<(sext_inreg R32C:$rSrc, i8),
4440 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4441
Scott Michel438be252007-12-17 22:32:34 +00004442def : Pat<(i32 (sext R8C:$rSrc)),
4443 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4444
Scott Michel2ef773a2009-01-06 03:36:14 +00004445// sext 8->64: Sign extend bytes to double word
4446def : Pat<(sext_inreg R64C:$rSrc, i8),
4447 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4448
4449def : Pat<(i64 (sext R8C:$rSrc)),
4450 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4451
Scott Michel438be252007-12-17 22:32:34 +00004452// zext 8->16: Zero extend bytes to halfwords
4453def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004454 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004455
Scott Michel438be252007-12-17 22:32:34 +00004456// zext 8->32: Zero extend bytes to words
4457def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004458 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00004459
Scott Michel2ef773a2009-01-06 03:36:14 +00004460// zext 8->64: Zero extend bytes to double words
4461def : Pat<(i64 (zext R8C:$rSrc)),
4462 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4463 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4464 0x4),
4465 (ILv4i32 0x0),
4466 (FSMBIv4i32 0x0f0f)))>;
4467
4468// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004469def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004470 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004471
Scott Michel2ef773a2009-01-06 03:36:14 +00004472// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel438be252007-12-17 22:32:34 +00004473def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004474 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00004475
Scott Michel2ef773a2009-01-06 03:36:14 +00004476// sext 16->64: Sign extend halfword to double word
4477def : Pat<(sext_inreg R64C:$rSrc, i16),
4478 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4479
4480def : Pat<(sext R16C:$rSrc),
4481 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4482
Scott Michel97872d32008-02-23 18:41:37 +00004483// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00004484def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004485 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004486
4487def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00004488 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004489
4490def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00004491 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004492
4493def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00004494 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004495
4496// anyext 16->32: Extend 16->32 bits, irrespective of sign
4497def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00004498 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004499
4500//===----------------------------------------------------------------------===//
Scott Michel06eabde2008-12-27 04:51:36 +00004501// Truncates:
4502// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4503// above are custom lowered.
4504//===----------------------------------------------------------------------===//
4505
4506def : Pat<(i8 (trunc GPRC:$src)),
4507 (ORi8_v16i8
4508 (SHUFBgprc GPRC:$src, GPRC:$src,
4509 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4510
4511def : Pat<(i8 (trunc R64C:$src)),
4512 (ORi8_v16i8
4513 (SHUFBv2i64_m32
4514 (ORv2i64_i64 R64C:$src),
4515 (ORv2i64_i64 R64C:$src),
4516 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4517
4518def : Pat<(i8 (trunc R32C:$src)),
4519 (ORi8_v16i8
4520 (SHUFBv4i32_m32
4521 (ORv4i32_i32 R32C:$src),
4522 (ORv4i32_i32 R32C:$src),
4523 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4524
4525def : Pat<(i8 (trunc R16C:$src)),
4526 (ORi8_v16i8
4527 (SHUFBv4i32_m32
4528 (ORv8i16_i16 R16C:$src),
4529 (ORv8i16_i16 R16C:$src),
4530 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4531
4532def : Pat<(i16 (trunc GPRC:$src)),
4533 (ORi16_v8i16
4534 (SHUFBgprc GPRC:$src, GPRC:$src,
4535 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4536
4537def : Pat<(i16 (trunc R64C:$src)),
4538 (ORi16_v8i16
4539 (SHUFBv2i64_m32
4540 (ORv2i64_i64 R64C:$src),
4541 (ORv2i64_i64 R64C:$src),
4542 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4543
4544def : Pat<(i16 (trunc R32C:$src)),
4545 (ORi16_v8i16
4546 (SHUFBv4i32_m32
4547 (ORv4i32_i32 R32C:$src),
4548 (ORv4i32_i32 R32C:$src),
4549 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4550
4551def : Pat<(i32 (trunc GPRC:$src)),
4552 (ORi32_v4i32
4553 (SHUFBgprc GPRC:$src, GPRC:$src,
4554 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4555
4556def : Pat<(i32 (trunc R64C:$src)),
4557 (ORi32_v4i32
4558 (SHUFBv2i64_m32
4559 (ORv2i64_i64 R64C:$src),
4560 (ORv2i64_i64 R64C:$src),
4561 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4562
4563//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00004564// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00004565// low parts in order to load them into a register.
4566//===----------------------------------------------------------------------===//
4567
Scott Michelf9f42e62008-01-29 02:16:57 +00004568def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4569def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4570def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4571def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4572
4573def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4574 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004575 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004576
Scott Michelf9f42e62008-01-29 02:16:57 +00004577def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4578 (SPUlo texternalsym:$in, 0)),
4579 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4580
4581def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4582 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00004583 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00004584
Scott Michelf9f42e62008-01-29 02:16:57 +00004585def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4586 (SPUlo tconstpool:$in, 0)),
4587 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4588
4589def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4590 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4591
4592def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4593 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4594
4595def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4596 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4597
4598def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4599 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00004600
Scott Michel8b6b4202007-12-04 22:35:58 +00004601// Instrinsics:
4602include "CellSDKIntrinsics.td"
Scott Michel4d07fb72008-12-30 23:28:25 +00004603// Various math operator instruction sequences
4604include "SPUMathInstr.td"
Scott Michel06eabde2008-12-27 04:51:36 +00004605// 64-bit "instructions"/support
4606include "SPU64InstrInfo.td"
Scott Michel2ef773a2009-01-06 03:36:14 +00004607// 128-bit "instructions"/support
4608include "SPU128InstrInfo.td"