1 //===- HexagonOperands.td - Hexagon immediate processing -*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illnois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Immediate operands.
12 let 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>;
61 let PrintMethod = "printNOneImmOperand" in
62 def nOneImm : Operand<i32>;
65 // Immediate predicates
67 def s32ImmPred : PatLeaf<(i32 imm), [{
68 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
70 int64_t v = (int64_t)N->getSExtValue();
74 def 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);
81 def 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);
88 def s26_6ImmPred : PatLeaf<(i32 imm), [{
89 // immS26_6 predicate - True if the immediate fits in a 32-bit sign extended
91 int64_t v = (int64_t)N->getSExtValue();
92 return isShiftedInt<26,6>(v);
96 def s16ImmPred : PatLeaf<(i32 imm), [{
97 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
99 int64_t v = (int64_t)N->getSExtValue();
104 def s13ImmPred : PatLeaf<(i32 imm), [{
105 // immS13 predicate - True if the immediate fits in a 13-bit sign extended
107 int64_t v = (int64_t)N->getSExtValue();
112 def s12ImmPred : PatLeaf<(i32 imm), [{
113 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
115 int64_t v = (int64_t)N->getSExtValue();
119 def s11_0ImmPred : PatLeaf<(i32 imm), [{
120 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
122 int64_t v = (int64_t)N->getSExtValue();
127 def s11_1ImmPred : PatLeaf<(i32 imm), [{
128 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
130 int64_t v = (int64_t)N->getSExtValue();
131 return isShiftedInt<11,1>(v);
135 def s11_2ImmPred : PatLeaf<(i32 imm), [{
136 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
138 int64_t v = (int64_t)N->getSExtValue();
139 return isShiftedInt<11,2>(v);
143 def s11_3ImmPred : PatLeaf<(i32 imm), [{
144 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
146 int64_t v = (int64_t)N->getSExtValue();
147 return isShiftedInt<11,3>(v);
151 def s10ImmPred : PatLeaf<(i32 imm), [{
152 // s10ImmPred predicate - True if the immediate fits in a 10-bit sign extended
154 int64_t v = (int64_t)N->getSExtValue();
159 def s9ImmPred : PatLeaf<(i32 imm), [{
160 // s9ImmPred predicate - True if the immediate fits in a 9-bit sign extended
162 int64_t v = (int64_t)N->getSExtValue();
166 def 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);
173 def s8ImmPred : PatLeaf<(i32 imm), [{
174 // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
176 int64_t v = (int64_t)N->getSExtValue();
181 def s8Imm64Pred : PatLeaf<(i64 imm), [{
182 // s8ImmPred predicate - True if the immediate fits in a 8-bit sign extended
184 int64_t v = (int64_t)N->getSExtValue();
189 def s6ImmPred : PatLeaf<(i32 imm), [{
190 // s6ImmPred predicate - True if the immediate fits in a 6-bit sign extended
192 int64_t v = (int64_t)N->getSExtValue();
197 def s4_0ImmPred : PatLeaf<(i32 imm), [{
198 // s4_0ImmPred predicate - True if the immediate fits in a 4-bit sign extended
200 int64_t v = (int64_t)N->getSExtValue();
205 def s4_1ImmPred : PatLeaf<(i32 imm), [{
206 // s4_1ImmPred predicate - True if the immediate fits in a 4-bit sign extended
208 int64_t v = (int64_t)N->getSExtValue();
209 return isShiftedInt<4,1>(v);
213 def 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);
221 def 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);
229 def u64ImmPred : PatLeaf<(i64 imm), [{
230 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
232 // Adding "N ||" to suppress gcc unused warning.
236 def u32ImmPred : PatLeaf<(i32 imm), [{
237 // immS16 predicate - True if the immediate fits in a 16-bit sign extended
239 int64_t v = (int64_t)N->getSExtValue();
240 return isUInt<32>(v);
243 def 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);
249 def u16ImmPred : PatLeaf<(i32 imm), [{
250 // u16ImmPred predicate - True if the immediate fits in a 16-bit unsigned
252 int64_t v = (int64_t)N->getSExtValue();
253 return isUInt<16>(v);
256 def 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);
263 def u9ImmPred : PatLeaf<(i32 imm), [{
264 // u9ImmPred predicate - True if the immediate fits in a 9-bit unsigned
266 int64_t v = (int64_t)N->getSExtValue();
271 def u8ImmPred : PatLeaf<(i32 imm), [{
272 // u8ImmPred predicate - True if the immediate fits in a 8-bit unsigned
274 int64_t v = (int64_t)N->getSExtValue();
278 def 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;
284 def u7ImmPred : PatLeaf<(i32 imm), [{
285 // u7ImmPred predicate - True if the immediate fits in a 8-bit unsigned
287 int64_t v = (int64_t)N->getSExtValue();
292 def u6ImmPred : PatLeaf<(i32 imm), [{
293 // u6ImmPred predicate - True if the immediate fits in a 6-bit unsigned
295 int64_t v = (int64_t)N->getSExtValue();
299 def 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();
306 def 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);
313 def 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);
320 def 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);
327 def u5ImmPred : PatLeaf<(i32 imm), [{
328 // u5ImmPred predicate - True if the immediate fits in a 5-bit unsigned
330 int64_t v = (int64_t)N->getSExtValue();
335 def u3ImmPred : PatLeaf<(i32 imm), [{
336 // u3ImmPred predicate - True if the immediate fits in a 3-bit unsigned
338 int64_t v = (int64_t)N->getSExtValue();
343 def u2ImmPred : PatLeaf<(i32 imm), [{
344 // u2ImmPred predicate - True if the immediate fits in a 2-bit unsigned
346 int64_t v = (int64_t)N->getSExtValue();
351 def u1ImmPred : PatLeaf<(i1 imm), [{
352 // u1ImmPred predicate - True if the immediate fits in a 1-bit unsigned
354 int64_t v = (int64_t)N->getSExtValue();
358 def 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);
366 def 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);
374 def 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.
377 int64_t v = (int64_t)N->getSExtValue();
378 return (-31 <= v && v <= -1);
381 //InN means negative integers in [-(2^N - 1), 0]
382 def n8ImmPred : PatLeaf<(i32 imm), [{
383 // n8ImmPred predicate - True if the immediate fits in a 8-bit signed
385 int64_t v = (int64_t)N->getSExtValue();
386 return (-255 <= v && v <= 0);
389 def nOneImmPred : PatLeaf<(i32 imm), [{
390 // nOneImmPred predicate - True if the immediate is -1.
391 int64_t v = (int64_t)N->getSExtValue();
395 def 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);
404 def 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);
415 def 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);
421 def 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);
430 def 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);
440 def 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);
446 def 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);
455 def 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);
465 def 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);