summaryrefslogtreecommitdiff
path: root/gnu/llvm/lib/Target/Nios2/Nios2InstrFormats.td
blob: 79868be48a488b9f97e8abd5f43283ae3f71d14f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//===-- Nios2InstrFormats.td - Nios2 Instruction Formats ---*- tablegen -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

//===----------------------------------------------------------------------===//
//  Describe NIOS2 instructions format
//
//
//===----------------------------------------------------------------------===//

// Format specifies the encoding used by the instruction.  This is part of the
// ad-hoc solution used to emit machine instruction encodings by our machine
// code emitter.
class Format<bits<3> val> {
  bits<3> Value = val;
}

def Pseudo : Format<0>;
def FrmI : Format<1>;
def FrmR : Format<2>;
def FrmJ : Format<3>;
def FrmOther : Format<4>; // Instruction w/ a custom format

// Generic Nios2 Format
class Nios2Inst<dag outs, dag ins, string asmstr, list<dag> pattern, Format f>
    : Instruction {
  field bits<32> Inst;
  Format Form = f;

  let Namespace = "Nios2";

  let Size = 4;

  bits<6> Opcode = 0;

  // Bottom 6 bits are the 'opcode' field
  let Inst{5 - 0} = Opcode;

  let OutOperandList = outs;
  let InOperandList = ins;

  let AsmString = asmstr;
  let Pattern = pattern;

  //
  // Attributes specific to Nios2 instructions:
  //
  bits<3> FormBits = Form.Value;

  // TSFlags layout should be kept in sync with Nios2InstrInfo.h.
  let TSFlags{2 - 0} = FormBits;

  let DecoderNamespace = "Nios2";
}

// Nios2 Instruction Format
class InstSE<dag outs, dag ins, string asmstr, list<dag> pattern, Format f>
    : Nios2Inst<outs, ins, asmstr, pattern, f> {
}

//===----------------------------------------------------------------------===//
// Format I instruction class in Nios2 : <|A|B|immediate|opcode|>
//===----------------------------------------------------------------------===//

class FI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern>
    : InstSE<outs, ins, asmstr, pattern, FrmI> {
  bits<5> rA;
  bits<5> rB;
  bits<16> imm;

  let Opcode = op;

  let Inst{31 - 27} = rA;
  let Inst{26 - 22} = rB;
  let Inst{21 - 6} = imm;
}

//===----------------------------------------------------------------------===//
// Format R instruction : <|A|B|C|opx|imm|opcode|>
//===----------------------------------------------------------------------===//

class FR<bits<6> opx, dag outs, dag ins, string asmstr, list<dag> pattern>
    : InstSE<outs, ins, asmstr, pattern, FrmR> {
  bits<5> rA;
  bits<5> rB;
  bits<5> rC;
  bits<5> imm = 0;

  // opcode is always 0x3a for R instr.
  let Opcode = 0x3a;

  let Inst{31 - 27} = rA;
  let Inst{26 - 22} = rB;
  let Inst{21 - 17} = rC;
  // opx stands for opcode extension
  let Inst{16 - 11} = opx;
  // optional 5-bit immediate value
  let Inst{10 - 6}  = imm;
}

//===----------------------------------------------------------------------===//
// Format J instruction class in Nios2 : <|address|opcode|>
//===----------------------------------------------------------------------===//

class FJ<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern>
    : InstSE<outs, ins, asmstr, pattern, FrmJ> {
  bits<26> addr;

  let Opcode = op;

  let Inst{31 - 6} = addr;
}