blob: a2650f12e24fe91cf1982fd116ff035aa7959107 [file] [log] [blame]
Rafael Espindola6ee1e082012-11-21 16:56:33 +00001//===- HexagonOperands.td - Hexagon immediate processing -*- tablegen -*-===//
Tony Linthicumb4b54152011-12-12 21:14:40 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illnois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Jyotsna Verma81081b12012-11-21 19:53:42 +000010// Immediate operands.
11
12let PrintMethod = "printImmOperand" in {
13 // f32Ext type is used to identify constant extended floating point immediates.
14 def f32Ext : Operand<f32>;
15 def s32Imm : Operand<i32>;
16 def s26_6Imm : Operand<i32>;
17 def s16Imm : Operand<i32>;
18 def s12Imm : Operand<i32>;
19 def s11Imm : Operand<i32>;
20 def s11_0Imm : Operand<i32>;
21 def s11_1Imm : Operand<i32>;
22 def s11_2Imm : Operand<i32>;
23 def s11_3Imm : Operand<i32>;
24 def s10Imm : Operand<i32>;
25 def s9Imm : Operand<i32>;
26 def m9Imm : Operand<i32>;
27 def s8Imm : Operand<i32>;
28 def s8Imm64 : Operand<i64>;
29 def s6Imm : Operand<i32>;
30 def s4Imm : Operand<i32>;
31 def s4_0Imm : Operand<i32>;
32 def s4_1Imm : Operand<i32>;
33 def s4_2Imm : Operand<i32>;
34 def s4_3Imm : Operand<i32>;
35 def u64Imm : Operand<i64>;
36 def u32Imm : Operand<i32>;
37 def u26_6Imm : Operand<i32>;
38 def u16Imm : Operand<i32>;
39 def u16_0Imm : Operand<i32>;
40 def u16_1Imm : Operand<i32>;
41 def u16_2Imm : Operand<i32>;
42 def u11_3Imm : Operand<i32>;
43 def u10Imm : Operand<i32>;
44 def u9Imm : Operand<i32>;
45 def u8Imm : Operand<i32>;
46 def u7Imm : Operand<i32>;
47 def u6Imm : Operand<i32>;
48 def u6_0Imm : Operand<i32>;
49 def u6_1Imm : Operand<i32>;
50 def u6_2Imm : Operand<i32>;
51 def u6_3Imm : Operand<i32>;
52 def u5Imm : Operand<i32>;
53 def u4Imm : Operand<i32>;
54 def u3Imm : Operand<i32>;
55 def u2Imm : Operand<i32>;
56 def u1Imm : Operand<i32>;
57 def n8Imm : Operand<i32>;
58 def m6Imm : Operand<i32>;
Tony Linthicumb4b54152011-12-12 21:14:40 +000059}
60
Jyotsna Verma81081b12012-11-21 19:53:42 +000061let PrintMethod = "printNOneImmOperand" in
62def nOneImm : Operand<i32>;
Sirish Pandeab7955b2012-02-15 18:52:27 +000063
Tony Linthicumb4b54152011-12-12 21:14:40 +000064//
65// Immediate predicates
66//
67def s32ImmPred : PatLeaf<(i32 imm), [{
68 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
69 // field.
70 int64_t v = (int64_t)N->getSExtValue();
71 return isInt<32>(v);
72}]>;
73
74def s32_24ImmPred : PatLeaf<(i32 imm), [{
75 // s32_24ImmPred predicate - True if the immediate fits in a 32-bit sign
76 // extended field that is a multiple of 0x1000000.
77 int64_t v = (int64_t)N->getSExtValue();
78 return isShiftedInt<32,24>(v);
79}]>;
80
81def s32_16s8ImmPred : PatLeaf<(i32 imm), [{
82 // s32_16s8ImmPred predicate - True if the immediate fits in a 32-bit sign
83 // extended field that is a multiple of 0x10000.
84 int64_t v = (int64_t)N->getSExtValue();
85 return isShiftedInt<24,16>(v);
86}]>;
87
Jyotsna Vermab546d5a2012-11-21 20:05:09 +000088def s26_6ImmPred : PatLeaf<(i32 imm), [{
89 // immS26_6 predicate - True if the immediate fits in a 32-bit sign extended
90 // field.
91 int64_t v = (int64_t)N->getSExtValue();
92 return isShiftedInt<26,6>(v);
93}]>;
94
95
Tony Linthicumb4b54152011-12-12 21:14:40 +000096def s16ImmPred : PatLeaf<(i32 imm), [{
97 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
98 // field.
99 int64_t v = (int64_t)N->getSExtValue();
100 return isInt<16>(v);
101}]>;
102
103
104def s13ImmPred : PatLeaf<(i32 imm), [{
105 // immS13 predicate - True if the immediate fits in a 13-bit sign extended
106 // field.
107 int64_t v = (int64_t)N->getSExtValue();
108 return isInt<13>(v);
109}]>;
110
111
112def s12ImmPred : PatLeaf<(i32 imm), [{
113 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
114 // field.
115 int64_t v = (int64_t)N->getSExtValue();
116 return isInt<12>(v);
117}]>;
118
119def s11_0ImmPred : PatLeaf<(i32 imm), [{
120 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
121 // field.
122 int64_t v = (int64_t)N->getSExtValue();
123 return isInt<11>(v);
124}]>;
125
126
127def s11_1ImmPred : PatLeaf<(i32 imm), [{
128 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
129 // field.
130 int64_t v = (int64_t)N->getSExtValue();
131 return isShiftedInt<11,1>(v);
132}]>;
133
134
135def s11_2ImmPred : PatLeaf<(i32 imm), [{
136 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
137 // field.
138 int64_t v = (int64_t)N->getSExtValue();
139 return isShiftedInt<11,2>(v);
140}]>;
141
142
143def s11_3ImmPred : PatLeaf<(i32 imm), [{
144 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
145 // field.
146 int64_t v = (int64_t)N->getSExtValue();
147 return isShiftedInt<11,3>(v);
148}]>;
149
150
151def s10ImmPred : PatLeaf<(i32 imm), [{
152 // s10ImmPred predicate - True if the immediate fits in a 10-bit sign extended
153 // field.
154 int64_t v = (int64_t)N->getSExtValue();
155 return isInt<10>(v);
156}]>;
157
158
159def s9ImmPred : PatLeaf<(i32 imm), [{
160 // s9ImmPred predicate - True if the immediate fits in a 9-bit sign extended
161 // field.
162 int64_t v = (int64_t)N->getSExtValue();
163 return isInt<9>(v);
164}]>;
165
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000166def m9ImmPred : PatLeaf<(i32 imm), [{
167 // m9ImmPred predicate - True if the immediate fits in a 9-bit magnitude
168 // field. The range of m9 is -255 to 255.
169 int64_t v = (int64_t)N->getSExtValue();
170 return isInt<9>(v) && (v != -256);
171}]>;
Tony Linthicumb4b54152011-12-12 21:14:40 +0000172
173def s8ImmPred : PatLeaf<(i32 imm), [{
174 // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
175 // field.
176 int64_t v = (int64_t)N->getSExtValue();
177 return isInt<8>(v);
178}]>;
179
180
181def s8Imm64Pred : PatLeaf<(i64 imm), [{
182 // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
183 // field.
184 int64_t v = (int64_t)N->getSExtValue();
185 return isInt<8>(v);
186}]>;
187
188
189def s6ImmPred : PatLeaf<(i32 imm), [{
190 // s6ImmPred predicate - True if the immediate fits in a 6-bit sign extended
191 // field.
192 int64_t v = (int64_t)N->getSExtValue();
193 return isInt<6>(v);
194}]>;
195
196
197def s4_0ImmPred : PatLeaf<(i32 imm), [{
198 // s4_0ImmPred predicate - True if the immediate fits in a 4-bit sign extended
199 // field.
200 int64_t v = (int64_t)N->getSExtValue();
201 return isInt<4>(v);
202}]>;
203
204
205def s4_1ImmPred : PatLeaf<(i32 imm), [{
206 // s4_1ImmPred predicate - True if the immediate fits in a 4-bit sign extended
207 // field of 2.
208 int64_t v = (int64_t)N->getSExtValue();
209 return isShiftedInt<4,1>(v);
210}]>;
211
212
213def s4_2ImmPred : PatLeaf<(i32 imm), [{
214 // s4_2ImmPred predicate - True if the immediate fits in a 4-bit sign extended
215 // field that is a multiple of 4.
216 int64_t v = (int64_t)N->getSExtValue();
217 return isShiftedInt<4,2>(v);
218}]>;
219
220
221def s4_3ImmPred : PatLeaf<(i32 imm), [{
222 // s4_3ImmPred predicate - True if the immediate fits in a 4-bit sign extended
223 // field that is a multiple of 8.
224 int64_t v = (int64_t)N->getSExtValue();
225 return isShiftedInt<4,3>(v);
226}]>;
227
228
229def u64ImmPred : PatLeaf<(i64 imm), [{
230 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
231 // field.
Benjamin Kramerd9b0b022012-06-02 10:20:22 +0000232 // Adding "N ||" to suppress gcc unused warning.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000233 return (N || true);
234}]>;
235
236def u32ImmPred : PatLeaf<(i32 imm), [{
237 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
238 // field.
239 int64_t v = (int64_t)N->getSExtValue();
240 return isUInt<32>(v);
241}]>;
242
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000243def u26_6ImmPred : PatLeaf<(i32 imm), [{
244 // True if the immediate fits in a 32-bit field and is 6-bit aligned.
245 int64_t v = (int64_t)N->getSExtValue();
246 return isShiftedUInt<26,6>(v);
247}]>;
248
Tony Linthicumb4b54152011-12-12 21:14:40 +0000249def u16ImmPred : PatLeaf<(i32 imm), [{
250 // u16ImmPred predicate - True if the immediate fits in a 16-bit unsigned
251 // field.
252 int64_t v = (int64_t)N->getSExtValue();
253 return isUInt<16>(v);
254}]>;
255
256def u16_s8ImmPred : PatLeaf<(i32 imm), [{
257 // u16_s8ImmPred predicate - True if the immediate fits in a 16-bit sign
258 // extended s8 field.
259 int64_t v = (int64_t)N->getSExtValue();
260 return isShiftedUInt<16,8>(v);
261}]>;
262
263def u9ImmPred : PatLeaf<(i32 imm), [{
264 // u9ImmPred predicate - True if the immediate fits in a 9-bit unsigned
265 // field.
266 int64_t v = (int64_t)N->getSExtValue();
267 return isUInt<9>(v);
268}]>;
269
270
271def u8ImmPred : PatLeaf<(i32 imm), [{
272 // u8ImmPred predicate - True if the immediate fits in a 8-bit unsigned
273 // field.
274 int64_t v = (int64_t)N->getSExtValue();
275 return isUInt<8>(v);
276}]>;
277
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000278def u7StrictPosImmPred : ImmLeaf<i32, [{
279 // u7StrictPosImmPred predicate - True if the immediate fits in an 7-bit
280 // unsigned field and is strictly greater than 0.
281 return isUInt<7>(Imm) && Imm > 0;
282}]>;
283
Tony Linthicumb4b54152011-12-12 21:14:40 +0000284def u7ImmPred : PatLeaf<(i32 imm), [{
285 // u7ImmPred predicate - True if the immediate fits in a 8-bit unsigned
286 // field.
287 int64_t v = (int64_t)N->getSExtValue();
288 return isUInt<7>(v);
289}]>;
290
291
292def u6ImmPred : PatLeaf<(i32 imm), [{
293 // u6ImmPred predicate - True if the immediate fits in a 6-bit unsigned
294 // field.
295 int64_t v = (int64_t)N->getSExtValue();
296 return isUInt<6>(v);
297}]>;
298
299def u6_0ImmPred : PatLeaf<(i32 imm), [{
300 // u6_0ImmPred predicate - True if the immediate fits in a 6-bit unsigned
301 // field. Same as u6ImmPred.
302 int64_t v = (int64_t)N->getSExtValue();
303 return isUInt<6>(v);
304}]>;
305
306def u6_1ImmPred : PatLeaf<(i32 imm), [{
307 // u6_1ImmPred predicate - True if the immediate fits in a 6-bit unsigned
308 // field that is 1 bit alinged - multiple of 2.
309 int64_t v = (int64_t)N->getSExtValue();
310 return isShiftedUInt<6,1>(v);
311}]>;
312
313def u6_2ImmPred : PatLeaf<(i32 imm), [{
314 // u6_2ImmPred predicate - True if the immediate fits in a 6-bit unsigned
315 // field that is 2 bits alinged - multiple of 4.
316 int64_t v = (int64_t)N->getSExtValue();
317 return isShiftedUInt<6,2>(v);
318}]>;
319
320def u6_3ImmPred : PatLeaf<(i32 imm), [{
321 // u6_3ImmPred predicate - True if the immediate fits in a 6-bit unsigned
322 // field that is 3 bits alinged - multiple of 8.
323 int64_t v = (int64_t)N->getSExtValue();
324 return isShiftedUInt<6,3>(v);
325}]>;
326
327def u5ImmPred : PatLeaf<(i32 imm), [{
328 // u5ImmPred predicate - True if the immediate fits in a 5-bit unsigned
329 // field.
330 int64_t v = (int64_t)N->getSExtValue();
331 return isUInt<5>(v);
332}]>;
333
334
335def u3ImmPred : PatLeaf<(i32 imm), [{
336 // u3ImmPred predicate - True if the immediate fits in a 3-bit unsigned
337 // field.
338 int64_t v = (int64_t)N->getSExtValue();
339 return isUInt<3>(v);
340}]>;
341
342
343def u2ImmPred : PatLeaf<(i32 imm), [{
344 // u2ImmPred predicate - True if the immediate fits in a 2-bit unsigned
345 // field.
346 int64_t v = (int64_t)N->getSExtValue();
347 return isUInt<2>(v);
348}]>;
349
350
351def u1ImmPred : PatLeaf<(i1 imm), [{
352 // u1ImmPred predicate - True if the immediate fits in a 1-bit unsigned
353 // field.
354 int64_t v = (int64_t)N->getSExtValue();
355 return isUInt<1>(v);
356}]>;
357
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000358def m5BImmPred : PatLeaf<(i32 imm), [{
359 // m5BImmPred predicate - True if the (char) number is in range -1 .. -31
360 // and will fit in a 5 bit field when made positive, for use in memops.
361 // this is specific to the zero extending of a negative by CombineInstr
362 int8_t v = (int8_t)N->getSExtValue();
363 return (-31 <= v && v <= -1);
364}]>;
365
366def m5HImmPred : PatLeaf<(i32 imm), [{
367 // m5HImmPred predicate - True if the (short) number is in range -1 .. -31
368 // and will fit in a 5 bit field when made positive, for use in memops.
369 // this is specific to the zero extending of a negative by CombineInstr
370 int16_t v = (int16_t)N->getSExtValue();
371 return (-31 <= v && v <= -1);
372}]>;
373
374def m5ImmPred : PatLeaf<(i32 imm), [{
375 // m5ImmPred predicate - True if the number is in range -1 .. -31
376 // and will fit in a 5 bit field when made positive, for use in memops.
Tony Linthicumb4b54152011-12-12 21:14:40 +0000377 int64_t v = (int64_t)N->getSExtValue();
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000378 return (-31 <= v && v <= -1);
Tony Linthicumb4b54152011-12-12 21:14:40 +0000379}]>;
380
381//InN means negative integers in [-(2^N - 1), 0]
382def n8ImmPred : PatLeaf<(i32 imm), [{
Evandro Menezese5041e62012-04-12 17:55:53 +0000383 // n8ImmPred predicate - True if the immediate fits in a 8-bit signed
Tony Linthicumb4b54152011-12-12 21:14:40 +0000384 // field.
385 int64_t v = (int64_t)N->getSExtValue();
386 return (-255 <= v && v <= 0);
387}]>;
Sirish Pandeab7955b2012-02-15 18:52:27 +0000388
389def nOneImmPred : PatLeaf<(i32 imm), [{
390 // nOneImmPred predicate - True if the immediate is -1.
391 int64_t v = (int64_t)N->getSExtValue();
392 return (-1 == v);
393}]>;
394
Jyotsna Vermab546d5a2012-11-21 20:05:09 +0000395def Set5ImmPred : PatLeaf<(i32 imm), [{
396 // Set5ImmPred predicate - True if the number is in the series of values.
397 // [ 2^0, 2^1, ... 2^31 ]
398 // For use in setbit immediate.
399 uint32_t v = (int32_t)N->getSExtValue();
400 // Constrain to 32 bits, and then check for single bit.
401 return ImmIsSingleBit(v);
402}]>;
403
404def Clr5ImmPred : PatLeaf<(i32 imm), [{
405 // Clr5ImmPred predicate - True if the number is in the series of
406 // bit negated values.
407 // [ 2^0, 2^1, ... 2^31 ]
408 // For use in clrbit immediate.
409 // Note: we are bit NOTing the value.
410 uint32_t v = ~ (int32_t)N->getSExtValue();
411 // Constrain to 32 bits, and then check for single bit.
412 return ImmIsSingleBit(v);
413}]>;
414
415def SetClr5ImmPred : PatLeaf<(i32 imm), [{
416 // predicate - True if the immediate is in range 0..31.
417 int32_t v = (int32_t)N->getSExtValue();
418 return (v >= 0 && v <= 31);
419}]>;
420
421def Set4ImmPred : PatLeaf<(i32 imm), [{
422 // Set4ImmPred predicate - True if the number is in the series of values:
423 // [ 2^0, 2^1, ... 2^15 ].
424 // For use in setbit immediate.
425 uint16_t v = (int16_t)N->getSExtValue();
426 // Constrain to 16 bits, and then check for single bit.
427 return ImmIsSingleBit(v);
428}]>;
429
430def Clr4ImmPred : PatLeaf<(i32 imm), [{
431 // Clr4ImmPred predicate - True if the number is in the series of
432 // bit negated values:
433 // [ 2^0, 2^1, ... 2^15 ].
434 // For use in setbit and clrbit immediate.
435 uint16_t v = ~ (int16_t)N->getSExtValue();
436 // Constrain to 16 bits, and then check for single bit.
437 return ImmIsSingleBit(v);
438}]>;
439
440def SetClr4ImmPred : PatLeaf<(i32 imm), [{
441 // predicate - True if the immediate is in the range 0..15.
442 int16_t v = (int16_t)N->getSExtValue();
443 return (v >= 0 && v <= 15);
444}]>;
445
446def Set3ImmPred : PatLeaf<(i32 imm), [{
447 // Set4ImmPred predicate - True if the number is in the series of values:
448 // [ 2^0, 2^1, ... 2^7 ].
449 // For use in setbit immediate.
450 uint8_t v = (int8_t)N->getSExtValue();
451 // Constrain to 8 bits, and then check for single bit.
452 return ImmIsSingleBit(v);
453}]>;
454
455def Clr3ImmPred : PatLeaf<(i32 imm), [{
456 // Clr4ImmPred predicate - True if the number is in the series of
457 // bit negated values:
458 // [ 2^0, 2^1, ... 2^7 ].
459 // For use in setbit and clrbit immediate.
460 uint8_t v = ~ (int8_t)N->getSExtValue();
461 // Constrain to 8 bits, and then check for single bit.
462 return ImmIsSingleBit(v);
463}]>;
464
465def SetClr3ImmPred : PatLeaf<(i32 imm), [{
466 // predicate - True if the immediat is in the range 0..7.
467 int8_t v = (int8_t)N->getSExtValue();
468 return (v >= 0 && v <= 7);
469}]>;