1 //===- LanaiInstrFormats.td - Lanai Instruction Formats ----*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 class InstLanai<dag outs, dag ins, string asmstr, list<dag> pattern>
12 field bits<32> SoftFail = 0;
15 let Namespace = "Lanai";
16 let DecoderNamespace = "Lanai";
19 let Inst{31 - 28} = Opcode;
21 dag OutOperandList = outs;
22 dag InOperandList = ins;
23 let AsmString = asmstr;
24 let Pattern = pattern;
27 //------------------------------------------------------------------------------
28 // Register Immediate (RI)
29 //------------------------------------------------------------------------------
31 // -----------------------------------------------------------------
32 // |0.A.A.A| . . . . | . . . . |F.H| . . . . . . . . . . . . . . . |
33 // -----------------------------------------------------------------
34 // opcode Rd Rs1 constant (16)
37 // Rd <- Rs1 op constant
39 // Except for shift instructions, `H' determines whether the constant
40 // is in the high (1) or low (0) word. The other halfword is 0x0000,
41 // except for the `AND' instruction (`AAA' = 100), for which the other
42 // halfword is 0xFFFF, and shifts (`AAA' = 111), for which the constant is
45 // `F' determines whether the instruction modifies (1) or does not
46 // modify (0) the program flags.
48 // `AAA' specifies the operation: `add' (000), `addc' (001), `sub'
49 // (010), `subb' (011), `and' (100), `or' (101), `xor' (110), or `shift'
50 // (111). For the shift, `H' specifies a logical (0) or arithmetic (1)
51 // shift. The amount and direction of the shift are determined by the
52 // sign extended constant interpreted as a two's complement number. The
53 // shift operation is defined only for the range of:
54 // 31 ... 0 -1 ... -31
59 // If and only if the `F' bit is 1, RI instructions modify the
60 // condition bits, `Z' (Zero), `N' (Negative), `V' (oVerflow), and `C'
61 // (Carry), according to the result. If the flags are updated, they are
62 // updated as follows:
64 // is set if the result is zero and cleared otherwise.
67 // is set to the most significant bit of the result.
70 // For arithmetic instructions (`add', `addc', `sub', `subb') `V' is
71 // set if the sign (most significant) bits of the input operands are
72 // the same but different from the sign bit of the result and cleared
73 // otherwise. For other RI instructions, `V' is cleared.
76 // For arithmetic instructions, `C' is set/cleared if there is/is_not
77 // a carry generated out of the most significant when performing the
78 // twos-complement addition (`sub(a,b) == a + ~b + 1', `subb(a,b) ==
79 // a + ~b + `C''). For left shifts, `C' is set to the least
80 // significant bit discarded by the shift operation. For all other
81 // operations, `C' is cleared.
83 // A Jump is accomplished by `Rd' being `pc', and it has one shadow.
85 // The all-0s word is the instruction `R0 <- R0 + 0', which is a no-op.
86 class InstRI<bits<3> op, dag outs, dag ins, string asmstr,
88 : InstLanai<outs, ins, asmstr, pattern>, Sched<[WriteALU]> {
89 let Itinerary = IIC_ALU;
97 let Opcode{2 - 0} = op;
98 let Inst{27 - 23} = Rd;
99 let Inst{22 - 18} = Rs1;
102 let Inst{15 - 0} = imm16;
105 //------------------------------------------------------------------------------
106 // Register Register (RR)
107 //------------------------------------------------------------------------------
109 // -----------------------------------------------------------------
110 // |1.1.0.0| . . . . | . . . . |F.I| . . . . |B.B.B|J.J.J.J.J|D.D.D|
111 // -----------------------------------------------------------------
112 // opcode Rd Rs1 Rs2 \ operation /
115 // `Rd <- Rs1 op Rs2' iff condition DDDI is true.
117 // `DDDI' is as described for the BR instruction.
119 // `F' determines whether the instruction modifies (1) or does not
120 // modify (0) the program flags.
122 // `BBB' determines the operation: `add' (000), `addc' (001), `sub'
123 // (010), `subb' (011), `and' (100), `or' (101), `xor' (110), or "special"
124 // (111). The `JJJJJ' field is irrelevant except for special.
126 // `JJJJJ' determines which special operation is performed. `10---'
127 // is a logical shift, and `11---' is an arithmetic shift, and ‘00000` is
128 // the SELECT operation. The amount and direction of the shift are
129 // determined by the contents of `Rs2' interpreted as a two's complement
130 // number (in the same way as shifts in the Register-Immediate
131 // instructions in *Note RI::). For the SELECT operation, Rd gets Rs1 if
132 // condition DDDI is true, Rs2 otherwise. All other `JJJJJ' combinations
133 // are reserved for instructions that may be defined in the future.
135 // If the `F' bit is 1, RR instructions modify the condition bits, `Z'
136 // (Zero), `N' (Negative), `V' (oVerflow), and `C' (Carry), according to
137 // the result. All RR instructions modify the `Z', `N', and `V' flags.
138 // Except for arithmetic instructions (`add', `addc', `sub', `subb'), `V'
139 // is cleared. Only arithmetic instructions and shifts modify `C'. Right
142 // DDDI is as described in the table for the BR instruction and only used for
143 // the select instruction.
145 // A Jump is accomplished by `Rd' being `pc', and it has one shadow.
146 class InstRR<bits<3> op, dag outs, dag ins, string asmstr,
148 : InstLanai<outs, ins, asmstr, pattern>, Sched<[WriteALU]> {
149 let Itinerary = IIC_ALU;
158 let Inst{27 - 23} = Rd;
159 let Inst{22 - 18} = Rs1;
161 let Inst{16} = DDDI{0};
162 let Inst{15 - 11} = Rs2;
163 let Inst{10 - 8} = op;
164 let Inst{7 - 3} = JJJJJ;
165 let Inst{2 - 0} = DDDI{3 - 1};
168 //------------------------------------------------------------------------------
169 // Register Memory (RM)
170 //------------------------------------------------------------------------------
172 // -----------------------------------------------------------------
173 // |1.0.0.S| . . . . | . . . . |P.Q| . . . . . . . . . . . . . . . |
174 // -----------------------------------------------------------------
175 // opcode Rd Rs1 constant (16)
178 // Rd <- Memory(ea) (Load) see below for the
179 // Memory(ea) <- Rd (Store) definition of ea.
181 // `S' determines whether the instruction is a Load (0) or a Store (1).
182 // Loads appear in Rd one cycle after this instruction executes. If the
183 // following instruction reads Rd, that instruction will be delayed by 1
187 // -- ------------------------------------------
189 // 01 ea = Rs1, Rs1 <- Rs1 + constant
190 // 10 ea = Rs1 + constant
191 // 11 ea = Rs1 + constant, Rs1 <- Rs1 + constant
193 // The constant is sign-extended for this instruction.
195 // A Jump is accomplished by `Rd' being `pc', and it has *two* delay slots.
196 class InstRM<bit S, dag outs, dag ins, string asmstr, list<dag> pattern>
197 : InstLanai<outs, ins, asmstr, pattern> {
203 // Dummy variables to allow multiclass definition of RM and RRM
207 let Opcode{3 - 1} = 0b100;
209 let Inst{27 - 23} = Rd;
210 let Inst{22 - 18} = Rs1;
213 let Inst{15 - 0} = imm16;
215 let PostEncoderMethod = "adjustPqBitsRmAndRrm";
218 //------------------------------------------------------------------------------
219 // Register Register Memory (RRM)
220 //------------------------------------------------------------------------------
222 // -----------------------------------------------------------------
223 // |1.0.1.S| . . . . | . . . . |P.Q| . . . . |B.B.B|J.J.J.J.J|Y.L.E|
224 // -----------------------------------------------------------------
225 // opcode Rd Rs1 Rs2 \ operation /
228 // Rd <- Memory(ea) (Load) see below for the
229 // Memory(ea) <- Rd (Store) definition of ea.
231 // The RRM instruction is identical to the RM (*note RM::.) instruction
234 // 1. `Rs1 + constant' is replaced with `Rs1 op Rs2', where `op' is
235 // determined in the same way as in the RR instruction (*note RR::.)
238 // 2. part-word memory accesses are allowed as specified below.
240 // If `BBB' != 111 (i.e.: For all but shift operations):
241 // If `YLE' = 01- => fuLl-word memory access
242 // If `YLE' = 00- => half-word memory access
243 // If `YLE' = 10- => bYte memory access
244 // If `YLE' = --1 => loads are zEro extended
245 // If `YLE' = --0 => loads are sign extended
247 // If `BBB' = 111 (For shift operations):
248 // fullword memory access are performed.
250 // All part-word loads write the least significant part of the
251 // destination register with the higher-order bits zero- or sign-extended.
252 // All part-word stores store the least significant part-word of the
253 // source register in the destination memory location.
255 // A Jump is accomplished by `Rd' being `pc', and it has *two* delay slots.
256 class InstRRM<bit S, dag outs, dag ins, string asmstr,
258 : InstLanai<outs, ins, asmstr, pattern> {
269 let Opcode{3 - 1} = 0b101;
271 let Inst{27 - 23} = Rd;
272 let Inst{22 - 18} = Rs1;
275 let Inst{15 - 11} = Rs2;
276 let Inst{10 - 8} = BBB;
277 let Inst{7 - 3} = JJJJJ;
278 let Inst{2 - 1} = YL;
281 let PostEncoderMethod = "adjustPqBitsRmAndRrm";
284 //------------------------------------------------------------------------------
285 // Conditional Branch (BR)
286 //------------------------------------------------------------------------------
288 // -----------------------------------------------------------------
289 // |1.1.1.0|D.D.D| . . . . . . . . . . . . . . . . . . . . . . |0.I|
290 // -----------------------------------------------------------------
291 // opcode condition constant (23)
294 // if (condition) { `pc' <- 4*(zero-extended constant) }
296 // The BR instruction is an absolute branch.
297 // The constant is scaled as shown by its position in the instruction word such
298 // that it specifies word-aligned addresses in the range [0,2^25-4]
300 // The `DDDI' field selects the condition that causes the branch to be taken.
301 // (the `I' (Invert sense) bit inverts the sense of the condition):
303 // DDDI logical function [code, used for...]
304 // ---- -------------------------------------- ------------------------
307 // 0010 C AND Z' [HI, high]
308 // 0011 C' OR Z [LS, low or same]
309 // 0100 C' [CC, carry cleared]
310 // 0101 C [CS, carry set]
311 // 0110 Z' [NE, not equal]
312 // 0111 Z [EQ, equal]
313 // 1000 V' [VC, oVerflow cleared]
314 // 1001 V [VS, oVerflow set]
315 // 1010 N' [PL, plus]
316 // 1011 N [MI, minus]
317 // 1100 (N AND V) OR (N' AND V') [GE, greater than or equal]
318 // 1101 (N AND V') OR (N' AND V) [LT, less than]
319 // 1110 (N AND V AND Z') OR (N' AND V' AND Z') [GT, greater than]
320 // 1111 (Z) OR (N AND V') OR (N' AND V) [LE, less than or equal]
322 // If the branch is not taken, the BR instruction is a no-op. If the branch is
323 // taken, the processor starts executing instructions at the branch target
324 // address *after* the processor has executed one more instruction. That is,
325 // the branch has one “branch delay slot”. Be very careful if you find yourself
326 // wanting to put a branch in a branch delays slot!
327 class InstBR<dag outs, dag ins, string asmstr, list<dag> pattern>
328 : InstLanai<outs, ins, asmstr, pattern> {
329 let Itinerary = IIC_ALU;
334 let Inst{27 - 25} = DDDI{3 - 1};
335 let Inst{24 - 0} = addr;
336 // These instructions overwrite the last two address bits (which are assumed
337 // and ensured to be 0).
339 let Inst{0} = DDDI{0};
342 //------------------------------------------------------------------------------
343 // Conditional Branch Relative (BRR)
344 //------------------------------------------------------------------------------
346 // -----------------------------------------------------------------
347 // |1.1.1.0|D.D.D|1|-| . . . . |-.-| . . . . . . . . . . . . . |1.I|
348 // -----------------------------------------------------------------
349 // opcode condition Rs1 constant (14)
351 // if (condition) { ‘pc’ <- Rs1 + 4*sign-extended constant) }
353 // BRR behaves like BR, except the branch target address is a 16-bit PC relative
355 class InstBRR<dag outs, dag ins, string asmstr, list<dag> pattern>
356 : InstLanai<outs, ins, asmstr, pattern> {
362 let Inst{27 - 25} = DDDI{3 - 1};
364 let Inst{22 - 18} = Rs1;
365 let Inst{17 - 16} = 0;
366 let Inst{15 - 0} = imm16;
367 // Overwrite last two bits which have to be zero
369 let Inst{0} = DDDI{0};
371 // Set don't cares to zero
375 //------------------------------------------------------------------------------
376 // Conditional Set (SCC)
377 //------------------------------------------------------------------------------
379 // -----------------------------------------------------------------
380 // |1.1.1.0|D.D.D|0.-| . . . . |-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-|1.I|
381 // -----------------------------------------------------------------
382 // opcode condition Rs1
385 // Rs1 <- logical function result
387 // SCC sets dst_reg to the boolean result of computing the logical function
388 // specified by DDDI, as described in the table for the BR instruction.
389 class InstSCC<dag outs, dag ins, string asmstr,
391 : InstLanai<outs, ins, asmstr, pattern> {
392 let Itinerary = IIC_ALU;
393 bits<5> Rs1; // dst_reg in documentation
397 let Inst{27 - 25} = DDDI{3 - 1};
399 let Inst{22 - 18} = Rs1;
401 let Inst{0} = DDDI{0};
403 // Set don't cares to zero
405 let Inst{17 - 2} = 0;
408 //------------------------------------------------------------------------------
409 // Special Load/Store (SLS)
410 //------------------------------------------------------------------------------
413 // -----------------------------------------------------------------
414 // |1.1.1.1| . . . . | . . . . |0.S| . . . . . . . . . . . . . . . |
415 // -----------------------------------------------------------------
416 // opcode Rd addr 5msb's address 16 lsb's
419 // If S = 0 (LOAD): Rd <- Memory(address);
420 // If S = 1 (STORE): Memory(address) <- Rd
422 // The timing is the same as for RM (*note RM::.) and RRM (*note
423 // RRM::.) instructions. The two low-order bits of the 21-bit address are
424 // ignored. The address is zero extended. Fullword memory accesses are
426 class InstSLS<bit S, dag outs, dag ins, string asmstr, list<dag> pattern>
427 : InstLanai<outs, ins, asmstr, pattern> {
433 let Inst{27 - 23} = Rd;
434 let Inst{22 - 18} = msb;
437 let Inst{15 - 0} = lsb;
440 //------------------------------------------------------------------------------
441 // Special Load Immediate (SLI)
442 //------------------------------------------------------------------------------
444 // -----------------------------------------------------------------
445 // |1.1.1.1| . . . . | . . . . |1.0| . . . . . . . . . . . . . . . |
446 // -----------------------------------------------------------------
447 // opcode Rd const 5msb's constant 16 lsb's
452 // The 21-bit constant is zero-extended. The timing is the same as the
453 // RM instruction (*note RM::.).
454 class InstSLI<dag outs, dag ins, string asmstr, list<dag> pattern>
455 : InstLanai<outs, ins, asmstr, pattern> {
461 let Inst{27 - 23} = Rd;
462 let Inst{22 - 18} = msb;
465 let Inst{15 - 0} = lsb;
468 //------------------------------------------------------------------------------
469 // Special Part-Word Load/Store (SPLS)
470 //------------------------------------------------------------------------------
472 // -----------------------------------------------------------------
473 // |1.1.1.1| . . . . | . . . . |1.1.0.Y.S.E.P.Q| . . . . . . . . . |
474 // -----------------------------------------------------------------
475 // opcode Rd Rs1 constant (10)
478 // If `YS' = 11 (bYte Store):
479 // Memory(ea) <- (least significant byte of Rr)
480 // If `YS' = 01 (halfword Store):
481 // Memory(ea) <- (least significant half-word of Rr)
482 // If `YS' = 10 (bYte load): Rr <- Memory(ea)
483 // If `YS' = 00 (halfword load): Rr <- Memory(ea)
484 // [Note: here ea is determined as in the RM instruction. ]
485 // If `SE' = 01 then the value is zEro extended
486 // before being loaded into Rd.
487 // If `SE' = 00 then the value is sign extended
488 // before being loaded into Rd.
490 // `P' and `Q' are used to determine `ea' as in the RM instruction. The
491 // constant is sign extended. The timing is the same as the RM and RRM
492 // instructions. *Note RM:: and *Note RRM::.
494 // All part-word loads write the part-word into the least significant
495 // part of the destination register, with the higher-order bits zero- or
496 // sign-extended. All part-word stores store the least significant
497 // part-word of the source register into the destination memory location.
498 class InstSPLS<dag outs, dag ins, string asmstr,
500 : InstLanai<outs, ins, asmstr, pattern> {
512 let Inst{27 - 23} = Rd;
513 let Inst{22 - 18} = Rs1;
514 let Inst{17 - 15} = 0b110;
520 let Inst{9 - 0} = imm10;
522 let PostEncoderMethod = "adjustPqBitsSpls";
525 //------------------------------------------------------------------------------
526 // Special instructions (popc, leadz, trailz)
527 //------------------------------------------------------------------------------
529 // -----------------------------------------------------------------
530 // |1.1.0.1| Rd | Rs1 |F.-| . . . . | . . | . . . . | OP |
531 // -----------------------------------------------------------------
534 // Rd <- Perform action encoded in OP on Rs1
536 // 0b001 POPC Population count;
537 // 0b010 LEADZ Count number of leading zeros;
538 // 0b011 TRAILZ Count number of trailing zeros;
539 class InstSpecial<bits<3> op, dag outs, dag ins, string asmstr,
540 list<dag> pattern> : InstLanai<outs, ins, asmstr,
541 pattern>, Sched<[WriteALU]> {
542 let Itinerary = IIC_ALU;
548 let Inst{27 - 23} = Rd;
549 let Inst{22 - 18} = Rs1;
551 let Inst{16 - 3} = 0;
552 let Inst{2 - 0} = op;
555 // Pseudo instructions
556 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
557 : InstLanai<outs, ins, asmstr, pattern> {
558 let Inst{15 - 0} = 0;