c1b8d6e7971e19eeeccdbc806d3a5e0d90ecea28
[oota-llvm.git] / lib / Target / SparcV8 / SparcV8InstrInfo.td
1 //===- SparcV8Instrs.td - Target Description for SparcV8 Target -----------===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the SparcV8 instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 class InstV8 : Instruction {          // SparcV8 instruction baseline
19   field bits<32> Inst;
20
21   let Namespace = "V8";
22
23   bits<2> op;
24   let Inst{31-30} = op;               // Top two bits are the 'op' field
25
26   // Bit attributes specific to SparcV8 instructions
27   bit isPasi       = 0; // Does this instruction affect an alternate addr space?
28   bit isPrivileged = 0; // Is this a privileged instruction?
29 }
30
31 include "SparcV8InstrFormats.td"
32
33 //===----------------------------------------------------------------------===//
34 // Instructions
35 //===----------------------------------------------------------------------===//
36
37 // Pseudo instructions.
38 class PseudoInstV8<string nm> : InstV8  {
39   let Name = nm;
40 }
41 def PHI : PseudoInstV8<"PHI">;
42 def ADJCALLSTACKDOWN : PseudoInstV8<"ADJCALLSTACKDOWN">;
43 def ADJCALLSTACKUP : PseudoInstV8<"ADJCALLSTACKUP">;
44 def IMPLICIT_USE : PseudoInstV8<"IMPLICIT_USE">;
45 def IMPLICIT_DEF : PseudoInstV8<"IMPLICIT_DEF">;
46 def FpMOVD : PseudoInstV8<"FpMOVD">; // pseudo 64-bit double move
47
48 // Section A.3 - Synthetic Instructions, p. 85
49 // special cases of JMPL:
50 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, simm13 = 8 in
51   def RET : F3_2<2, 0b111000, "ret">;
52 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, simm13 = 8 in
53   def RETL: F3_2<2, 0b111000, "retl">;
54 // CMP is a special case of SUBCC where destination is ignored, by setting it to
55 // %g0 (hardwired zero).
56 // FIXME: should keep track of the fact that it defs the integer condition codes
57 let rd = 0 in
58   def CMPri: F3_2<2, 0b010100, "cmp">;
59
60 // Section B.1 - Load Integer Instructions, p. 90
61 def LDSB: F3_2<3, 0b001001, "ldsb">;
62 def LDSH: F3_2<3, 0b001010, "ldsh">;
63 def LDUB: F3_2<3, 0b000001, "ldub">;
64 def LDUH: F3_2<3, 0b000010, "lduh">;
65 def LD  : F3_2<3, 0b000000, "ld">;
66 def LDD : F3_2<3, 0b000011, "ldd">;
67
68 // Section B.2 - Load Floating-point Instructions, p. 92
69 def LDFrr  : F3_1<3, 0b100000, "ld">;
70 def LDFri  : F3_2<3, 0b100000, "ld">;
71 def LDDFrr : F3_1<3, 0b100011, "ldd">;
72 def LDDFri : F3_2<3, 0b100011, "ldd">;
73 def LDFSRrr: F3_1<3, 0b100001, "ld">;
74 def LDFSRri: F3_2<3, 0b100001, "ld">;
75
76 // Section B.4 - Store Integer Instructions, p. 95
77 def STB : F3_2<3, 0b000101, "stb">;
78 def STH : F3_2<3, 0b000110, "sth">;
79 def ST  : F3_2<3, 0b000100, "st">;
80 def STD : F3_2<3, 0b000111, "std">;
81
82 // Section B.5 - Store Floating-point Instructions, p. 97
83 def STFrr   : F3_1<3, 0b100100, "st">;
84 def STFri   : F3_2<3, 0b100100, "st">;
85 def STDFrr  : F3_1<3, 0b100111, "std">;
86 def STDFri  : F3_2<3, 0b100111, "std">;
87 def STFSRrr : F3_1<3, 0b100101, "st">;
88 def STFSRri : F3_2<3, 0b100101, "st">;
89 def STDFQrr : F3_1<3, 0b100110, "std">;
90 def STDFQri : F3_2<3, 0b100110, "std">;
91
92 // Section B.9 - SETHI Instruction, p. 104
93 def SETHIi: F2_1<0b100, "sethi">;
94
95 // Section B.10 - NOP Instruction, p. 105
96 // (It's a special case of SETHI)
97 let rd = 0, imm = 0 in
98   def NOP : F2_1<0b100, "nop">;
99
100 // Section B.11 - Logical Instructions, p. 106
101 def ANDrr : F3_1<2, 0b000001, "and">;
102 def ANDri : F3_2<2, 0b000001, "and">;
103 def ORrr  : F3_1<2, 0b000010, "or">;
104 def ORri  : F3_2<2, 0b000010, "or">;
105 def XORrr : F3_1<2, 0b000011, "xor">;
106 def XORri : F3_2<2, 0b000011, "xor">;
107
108 // Section B.12 - Shift Instructions, p. 107
109 def SLLrr : F3_1<2, 0b100101, "sll">;
110 def SLLri : F3_2<2, 0b100101, "sll">;
111 def SRLrr : F3_1<2, 0b100110, "srl">;
112 def SRLri : F3_2<2, 0b100110, "srl">;
113 def SRArr : F3_1<2, 0b100111, "sra">;
114 def SRAri : F3_2<2, 0b100111, "sra">;
115
116 // Section B.13 - Add Instructions, p. 108
117 def ADDrr : F3_1<2, 0b000000, "add">;
118 def ADDri : F3_2<2, 0b000000, "add">;
119
120 // Section B.15 - Subtract Instructions, p. 110
121 def SUBrr   : F3_1<2, 0b000100, "sub">;
122 def SUBCCrr : F3_1<2, 0b010100, "subcc">;
123 def SUBCCri : F3_2<2, 0b010100, "subcc">;
124
125 // Section B.18 - Multiply Instructions, p. 113
126 def UMULrr : F3_1<2, 0b001010, "umul">;
127 def SMULrr : F3_1<2, 0b001011, "smul">;
128
129 // Section B.19 - Divide Instructions, p. 115
130 def UDIVrr   : F3_1<2, 0b001110, "udiv">;
131 def UDIVri   : F3_2<2, 0b001110, "udiv">;
132 def SDIVrr   : F3_1<2, 0b001111, "sdiv">;
133 def SDIVri   : F3_2<2, 0b001111, "sdiv">;
134 def UDIVCCrr : F3_1<2, 0b011110, "udivcc">;
135 def UDIVCCri : F3_2<2, 0b011110, "udivcc">;
136 def SDIVCCrr : F3_1<2, 0b011111, "sdivcc">;
137 def SDIVCCri : F3_2<2, 0b011111, "sdivcc">;
138
139 // Section B.20 - SAVE and RESTORE, p. 117
140 def SAVErr    : F3_1<2, 0b111100, "save">;           // save    r, r, r
141 def SAVEri    : F3_2<2, 0b111100, "save">;           // save    r, i, r
142 def RESTORErr : F3_1<2, 0b111101, "restore">;        // restore r, r, r
143 def RESTOREri : F3_2<2, 0b111101, "restore">;        // restore r, i, r
144
145 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
146
147 // conditional branch class:
148 class BranchV8<bits<4> cc, string nm> : F2_2<cc, 0b010, nm> {
149   let isBranch = 1;
150   let isTerminator = 1;
151   let hasDelaySlot = 1;
152 }
153
154 let isBarrier = 1 in
155   def BA   : BranchV8<0b1000, "ba">;
156 def BN   : BranchV8<0b0000, "bn">;
157 def BNE  : BranchV8<0b1001, "bne">;
158 def BE   : BranchV8<0b0001, "be">;
159 def BG   : BranchV8<0b1010, "bg">;
160 def BLE  : BranchV8<0b0010, "ble">;
161 def BGE  : BranchV8<0b1011, "bge">;
162 def BL   : BranchV8<0b0011, "bl">;
163 def BGU  : BranchV8<0b1100, "bgu">;
164 def BLEU : BranchV8<0b0100, "bleu">;
165 def BCC  : BranchV8<0b1101, "bcc">;
166 def BCS  : BranchV8<0b0101, "bcs">;
167
168 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
169
170 // floating-point conditional branch class:
171 class FPBranchV8<bits<4> cc, string nm> : F2_2<cc, 0b110, nm> {
172   let isBranch = 1;
173   let isTerminator = 1;
174   let hasDelaySlot = 1;
175 }
176
177 def FBA  : FPBranchV8<0b1000, "fba">;
178 def FBN  : FPBranchV8<0b0000, "fbn">;
179 def FBU  : FPBranchV8<0b0111, "fbu">;
180 def FBG  : FPBranchV8<0b0110, "fbg">;
181 def FBUG : FPBranchV8<0b0101, "fbug">;
182 def FBL  : FPBranchV8<0b0100, "fbl">;
183 def FBUL : FPBranchV8<0b0011, "fbul">;
184 def FBLG : FPBranchV8<0b0010, "fblg">;
185 def FBNE : FPBranchV8<0b0001, "fbne">;
186 def FBE  : FPBranchV8<0b1001, "fbe">;
187 def FBUE : FPBranchV8<0b1010, "fbue">;
188 def FBGE : FPBranchV8<0b1011, "fbge">;
189 def FBUGE: FPBranchV8<0b1100, "fbuge">;
190 def FBLE : FPBranchV8<0b1101, "fble">;
191 def FBULE: FPBranchV8<0b1110, "fbule">;
192 def FBO  : FPBranchV8<0b1111, "fbo">;
193
194 // Section B.24 - Call and Link Instruction, p. 125
195 // This is the only Format 1 instruction
196 let Uses = [O0, O1, O2, O3, O4, O5], Defs = [O0, O1, O2, O3, O4, O5],
197     hasDelaySlot = 1, isCall = 1 in { 
198   // pc-relative call:
199   def CALL : InstV8 {
200     bits<30> disp;
201     let op = 1;
202     let Inst{29-0} = disp;
203     let Name = "call";
204   }
205   // indirect call:
206   def JMPLrr : F3_1<2, 0b111000, "jmpl">;              // jmpl [rs1+rs2], rd
207 }
208
209 // Section B.29 - Write State Register Instructions
210 def WRrr : F3_1<2, 0b110000, "wr">;                    // wr rs1, rs2, rd
211 def WRri : F3_2<2, 0b110000, "wr">;                    // wr rs1, imm, rd
212
213 // Convert Integer to Floating-point Instructions, p. 141
214 def FITOS : F3_3<2, 0b110100, 0b011000100, "fitos">;
215 def FITOD : F3_3<2, 0b110100, 0b011001000, "fitod">;
216
217 // Convert between Floating-point Formats Instructions, p. 143
218 def FSTOD : F3_3<2, 0b110100, 0b011001001, "fstod">;
219 def FDTOS : F3_3<2, 0b110100, 0b011000110, "fdtos">;
220
221 // Floating-point Move Instructions, p. 144
222 def FMOVS : F3_3<2, 0b110100, 0b000000001, "fmovs">;
223 def FNEGS : F3_3<2, 0b110100, 0b000000101, "fnegs">;
224 def FABSS : F3_3<2, 0b110100, 0b000001001, "fabss">;
225
226 // Floating-point Add and Subtract Instructions, p. 146
227 def FADDS  : F3_3<2, 0b110100, 0b001000001, "fadds">;
228 def FADDD  : F3_3<2, 0b110100, 0b001000010, "faddd">;
229 def FSUBS  : F3_3<2, 0b110100, 0b001000101, "fsubs">;
230 def FSUBD  : F3_3<2, 0b110100, 0b001000110, "fsubd">;
231
232 // Floating-point Multiply and Divide Instructions, p. 147
233 def FMULS  : F3_3<2, 0b110100, 0b001001001, "fmuls">;
234 def FMULD  : F3_3<2, 0b110100, 0b001001010, "fmuld">;
235 def FSMULD : F3_3<2, 0b110100, 0b001101001, "fsmuld">;
236 def FDIVS  : F3_3<2, 0b110100, 0b001001101, "fdivs">;
237 def FDIVD  : F3_3<2, 0b110100, 0b001001110, "fdivd">;
238
239 // Floating-point Compare Instructions, p. 148
240 // Note: the 2nd template arg is different for these guys.
241 // Note 2: the result of a FCMP is not available until the 2nd cycle
242 // after the instr is retired, but there is no interlock. This behavior
243 // is modelled as a delay slot.
244 let hasDelaySlot = 1 in {
245   def FCMPS  : F3_3<2, 0b110101, 0b001010001, "fcmps">;
246   def FCMPD  : F3_3<2, 0b110101, 0b001010010, "fcmpd">;
247   def FCMPES : F3_3<2, 0b110101, 0b001010101, "fcmpes">;
248   def FCMPED : F3_3<2, 0b110101, 0b001010110, "fcmped">;
249 }
250