1//===- XtensaOperands.td - Xtensa instruction operands -------*- tblgen-*--===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6// See https://llvm.org/LICENSE.txt for license information.
7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8//
9//===----------------------------------------------------------------------===//
10
11// Immediate operands with a shared generic render method.
12class ImmAsmOperand<string name> : AsmOperandClass {
13  let Name = name;
14  let RenderMethod = "addImmOperands";
15  let DiagnosticType = !strconcat("Invalid", name);
16}
17
18class Immediate<ValueType vt, code pred, string asmop>
19  : Operand<vt>, ImmLeaf<vt, pred> {
20  let PrintMethod = "print"#asmop;
21  let ParserMatchClass = !cast<AsmOperandClass>(asmop);
22}
23
24// imm8 predicate - Immediate in the range [-128,127]
25def Imm8_AsmOperand : ImmAsmOperand<"Imm8">;
26def imm8 : Immediate<i32, [{ return Imm >= -128 && Imm <= 127; }], "Imm8_AsmOperand"> {
27  let EncoderMethod = "getImm8OpValue";
28  let DecoderMethod = "decodeImm8Operand";
29}
30
31// imm8_sh8 predicate - Immediate in the range [-32768,32512] with (bits[7-0] == 0)
32// imm8 value left shifted by 8 bits
33def Imm8_sh8_AsmOperand : ImmAsmOperand<"Imm8_sh8">;
34def imm8_sh8 : Immediate<i32, [{ return Imm >= -32768 && Imm <= 32512 && ((Imm & 0xFF) == 0); }],
35                        "Imm8_sh8_AsmOperand"> {
36  let EncoderMethod = "getImm8_sh8OpValue";
37  let DecoderMethod = "decodeImm8_sh8Operand";
38}
39
40// imm12 predicate - Immediate in the range [-2048,2047]
41def Imm12_AsmOperand : ImmAsmOperand<"Imm12">;
42def imm12 : Immediate<i32, [{ return Imm >= -2048 && Imm <= 2047; }], "Imm12_AsmOperand"> {
43  let EncoderMethod = "getImm12OpValue";
44  let DecoderMethod = "decodeImm12Operand";
45}
46
47// imm12m predicate - Immediate for MOV operation
48def Imm12m_AsmOperand : ImmAsmOperand<"Imm12m">;
49def imm12m : Immediate<i32, [{ return Imm >= -2048 && Imm <= 2047; }], "Imm12m_AsmOperand"> {
50  let EncoderMethod = "getImm12OpValue";
51  let DecoderMethod = "decodeImm12Operand";
52}
53
54// uimm4 predicate - Immediate in the range [0,15]
55def Uimm4_AsmOperand : ImmAsmOperand<"Uimm4">;
56def uimm4 : Immediate<i32, [{ return Imm >= 0 && Imm <= 15; }], "Uimm4_AsmOperand"> {
57  let EncoderMethod = "getUimm4OpValue";
58  let DecoderMethod = "decodeUimm4Operand";
59}
60
61// uimm5 predicate - Immediate in the range [0,31]
62def Uimm5_AsmOperand : ImmAsmOperand<"Uimm5">;
63def uimm5 : Immediate<i32, [{ return Imm >= 0 && Imm <= 31; }], "Uimm5_AsmOperand"> {
64  let EncoderMethod = "getUimm5OpValue";
65  let DecoderMethod = "decodeUimm5Operand";
66}
67
68// imm1_16 predicate - Immediate in the range [1,16]
69def Imm1_16_AsmOperand : ImmAsmOperand<"Imm1_16">;
70def imm1_16 : Immediate<i32, [{ return Imm >= 1 && Imm <= 16; }], "Imm1_16_AsmOperand"> {
71  let EncoderMethod = "getImm1_16OpValue";
72  let DecoderMethod = "decodeImm1_16Operand";
73}
74
75// shimm1_31 predicate - Immediate in the range [1,31]
76def Shimm1_31_AsmOperand : ImmAsmOperand<"Shimm1_31">;
77def shimm1_31 : Immediate<i32, [{ return Imm >= 1 && Imm <= 31; }], "Shimm1_31_AsmOperand"> {
78  let EncoderMethod = "getShimm1_31OpValue";
79  let DecoderMethod = "decodeShimm1_31Operand";
80}
81
82// Memory offset 0..255 for 8-bit memory accesses
83def Offset8m8_AsmOperand : ImmAsmOperand<"Offset8m8">;
84def offset8m8 : Immediate<i32,
85    [{ return Imm >= 0 && Imm <= 255; }],
86    "Offset8m8_AsmOperand">;
87
88// Memory offset 0..510 for 16-bit memory accesses
89def Offset8m16_AsmOperand : ImmAsmOperand<"Offset8m16">;
90def offset8m16 : Immediate<i32,
91    [{ return Imm >= 0 && Imm <= 510 && (Imm & 0x1 == 0); }],
92    "Offset8m16_AsmOperand">;
93
94// Memory offset 0..1020 for 32-bit memory accesses
95def Offset8m32_AsmOperand : ImmAsmOperand<"Offset8m32">;
96def offset8m32 : Immediate<i32,
97    [{ return Imm >= 0 && Imm <= 1020 && (Imm & 0x3 == 0); }],
98    "Offset8m32_AsmOperand">;
99
100// Memory offset 0..60 for 32-bit memory accesses
101def Offset4m32_AsmOperand : ImmAsmOperand<"Offset4m32">;
102def offset4m32 : Immediate<i32,
103    [{ return Imm >= 0 && Imm <= 60 && (Imm & 0x3 == 0); }],
104    "Offset4m32_AsmOperand">;
105
106// b4const predicate - Branch Immediate 4-bit signed operand
107def B4const_AsmOperand: ImmAsmOperand<"B4const">;
108def b4const: Immediate<i32,
109  [{ switch (Imm) {
110        case -1: case 1: case 2: case 3:  case 4:
111        case 5:  case 6: case 7: case 8: case 10: case 12:
112        case 16: case 32: case 64: case 128: case 256: return 1;
113        default: return 0;
114     }
115  }],
116  "B4const_AsmOperand"> {
117  let EncoderMethod = "getB4constOpValue";
118  let DecoderMethod = "decodeB4constOperand";
119}
120
121// b4constu predicate - Branch Immediate 4-bit unsigned operand
122def B4constu_AsmOperand: ImmAsmOperand<"B4constu">;
123def b4constu: Immediate<i32,
124  [{ switch (Imm) {
125        case 32768: case 65536: case 2: case 3:  case 4:
126        case 5:  case 6: case 7: case 8: case 10: case 12:
127        case 16: case 32: case 64: case 128: case 256: return 1;
128        default: return 0;
129     }
130  }],
131  "B4constu_AsmOperand"> {
132  let EncoderMethod = "getB4constuOpValue";
133  let DecoderMethod = "decodeB4constuOperand";
134}
135//===----------------------------------------------------------------------===//
136// Memory address operands
137//===----------------------------------------------------------------------===//
138
139class mem<Operand offset> : Operand<i32> {
140  let MIOperandInfo = (ops AR, offset);
141  let EncoderMethod = "getMemRegEncoding";
142  let OperandType = "OPERAND_MEMORY";
143  let PrintMethod = "printMemOperand";
144}
145
146def mem8   : mem<offset8m8> {
147  let DecoderMethod = "decodeMem8Operand";
148}
149
150def mem16  : mem<offset8m16> {
151  let DecoderMethod = "decodeMem16Operand";
152}
153
154def mem32  : mem<offset8m32> {
155  let DecoderMethod = "decodeMem32Operand";
156}
157
158def mem32n : mem<offset4m32> {
159  let DecoderMethod = "decodeMem32nOperand";
160}
161
162//Add patterns for future use in stack addressing mode
163def addr_ish1 : ComplexPattern<iPTR, 2, "selectMemRegAddrISH1", [frameindex]>;
164def addr_ish2 : ComplexPattern<iPTR, 2, "selectMemRegAddrISH2", [frameindex]>;
165def addr_ish4 : ComplexPattern<iPTR, 2, "selectMemRegAddrISH4", [frameindex]>;
166
167//===----------------------------------------------------------------------===//
168// Symbolic address operands
169//===----------------------------------------------------------------------===//
170def XtensaPCRelTargetAsmOperand : AsmOperandClass {
171  let Name = "PCRelTarget";
172  let ParserMethod = "parsePCRelTarget";
173  let PredicateMethod = "isImm";
174  let RenderMethod = "addImmOperands";
175}
176
177def  pcrel32call : Operand<iPTR> {
178  let PrintMethod = "printCallOperand";
179  let EncoderMethod = "getCallEncoding";
180  let DecoderMethod = "decodeCallOperand";
181  let ParserMatchClass = XtensaPCRelTargetAsmOperand;
182}
183
184def brtarget : Operand<OtherVT> {
185  let PrintMethod = "printBranchTarget";
186  let EncoderMethod = "getBranchTargetEncoding";
187  let DecoderMethod = "decodeBranchOperand";
188  let ParserMatchClass = XtensaPCRelTargetAsmOperand;
189}
190
191def jumptarget : Operand<OtherVT> {
192  let PrintMethod = "printJumpTarget";
193  let EncoderMethod = "getJumpTargetEncoding";
194  let DecoderMethod = "decodeJumpOperand";
195  let ParserMatchClass = XtensaPCRelTargetAsmOperand;
196}
197
198def L32Rtarget : Operand<OtherVT> {
199  let PrintMethod = "printL32RTarget";
200  let EncoderMethod = "getL32RTargetEncoding";
201  let DecoderMethod = "decodeL32ROperand";
202  let ParserMatchClass = XtensaPCRelTargetAsmOperand;
203}
204