blob: ff50294e4def678ab9a05a7203c0cbbed3fb597f [file] [log] [blame]
Misha Brukmane07c2aa2004-02-25 21:02:21 +00001//===- SparcV8Instrs.td - Target Description for SparcV8 Target -----------===//
Brian Gaekee785e532004-02-25 19:28:19 +00002//
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//
Misha Brukmane07c2aa2004-02-25 21:02:21 +000010// This file describes the SparcV8 instructions in TableGen format.
Brian Gaekee785e532004-02-25 19:28:19 +000011//
12//===----------------------------------------------------------------------===//
13
Misha Brukmane07c2aa2004-02-25 21:02:21 +000014//===----------------------------------------------------------------------===//
Misha Brukman23e6c1f2004-02-26 00:37:12 +000015// Instruction format superclass
Misha Brukmane07c2aa2004-02-25 21:02:21 +000016//===----------------------------------------------------------------------===//
17
18class 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?
Brian Gaekee785e532004-02-25 19:28:19 +000029}
30
Misha Brukmanc42077d2004-09-22 21:38:42 +000031include "SparcV8InstrFormats.td"
Brian Gaekee785e532004-02-25 19:28:19 +000032
Misha Brukman23e6c1f2004-02-26 00:37:12 +000033//===----------------------------------------------------------------------===//
34// Instructions
35//===----------------------------------------------------------------------===//
36
Chris Lattner275f6452004-02-28 19:37:18 +000037// Pseudo instructions.
Chris Lattner3ff57512005-12-16 06:02:58 +000038class PseudoInstV8<string nm, dag ops> : InstV8 {
Brian Gaeke7c4676f2004-07-16 10:32:10 +000039 let Name = nm;
Chris Lattner3ff57512005-12-16 06:02:58 +000040 dag OperandList = ops;
Chris Lattner275f6452004-02-28 19:37:18 +000041}
Chris Lattner3ff57512005-12-16 06:02:58 +000042def PHI : PseudoInstV8<"PHI", (ops variable_ops)>;
43def ADJCALLSTACKDOWN : PseudoInstV8<"ADJCALLSTACKDOWN", (ops variable_ops)>;
44def ADJCALLSTACKUP : PseudoInstV8<"ADJCALLSTACKUP", (ops variable_ops)>;
45def IMPLICIT_USE : PseudoInstV8<"IMPLICIT_USE", (ops variable_ops)>;
46def IMPLICIT_DEF : PseudoInstV8<"IMPLICIT_DEF", (ops variable_ops)>;
47def FpMOVD : PseudoInstV8<"FpMOVD", (ops)>; // pseudo 64-bit double move
Chris Lattner275f6452004-02-28 19:37:18 +000048
Brian Gaekea8056fa2004-03-06 05:32:13 +000049// Section A.3 - Synthetic Instructions, p. 85
Brian Gaekec3e97012004-05-08 04:21:32 +000050// special cases of JMPL:
Misha Brukman3df04c52004-10-14 22:32:49 +000051let isReturn = 1, isTerminator = 1, hasDelaySlot = 1 in {
52 let rd = I7.Num, rs1 = G0.Num, simm13 = 8 in
53 def RET : F3_2<2, 0b111000, "ret">;
54 let rd = O7.Num, rs1 = G0.Num, simm13 = 8 in
55 def RETL: F3_2<2, 0b111000, "retl">;
56}
Brian Gaekec3e97012004-05-08 04:21:32 +000057// CMP is a special case of SUBCC where destination is ignored, by setting it to
58// %g0 (hardwired zero).
59// FIXME: should keep track of the fact that it defs the integer condition codes
60let rd = 0 in
61 def CMPri: F3_2<2, 0b010100, "cmp">;
Brian Gaeke8542e082004-04-02 20:53:37 +000062
63// Section B.1 - Load Integer Instructions, p. 90
Brian Gaekee7f9e0b2004-06-24 07:36:59 +000064def LDSB: F3_2<3, 0b001001, "ldsb">;
65def LDSH: F3_2<3, 0b001010, "ldsh">;
66def LDUB: F3_2<3, 0b000001, "ldub">;
67def LDUH: F3_2<3, 0b000010, "lduh">;
68def LD : F3_2<3, 0b000000, "ld">;
69def LDD : F3_2<3, 0b000011, "ldd">;
Brian Gaeke8542e082004-04-02 20:53:37 +000070
Brian Gaeke562d5b02004-06-18 05:19:27 +000071// Section B.2 - Load Floating-point Instructions, p. 92
Brian Gaekee7f9e0b2004-06-24 07:36:59 +000072def LDFrr : F3_1<3, 0b100000, "ld">;
73def LDFri : F3_2<3, 0b100000, "ld">;
74def LDDFrr : F3_1<3, 0b100011, "ldd">;
75def LDDFri : F3_2<3, 0b100011, "ldd">;
76def LDFSRrr: F3_1<3, 0b100001, "ld">;
77def LDFSRri: F3_2<3, 0b100001, "ld">;
Brian Gaeke562d5b02004-06-18 05:19:27 +000078
Brian Gaeke8542e082004-04-02 20:53:37 +000079// Section B.4 - Store Integer Instructions, p. 95
Brian Gaekee7f9e0b2004-06-24 07:36:59 +000080def STB : F3_2<3, 0b000101, "stb">;
81def STH : F3_2<3, 0b000110, "sth">;
82def ST : F3_2<3, 0b000100, "st">;
83def STD : F3_2<3, 0b000111, "std">;
84
85// Section B.5 - Store Floating-point Instructions, p. 97
86def STFrr : F3_1<3, 0b100100, "st">;
87def STFri : F3_2<3, 0b100100, "st">;
88def STDFrr : F3_1<3, 0b100111, "std">;
89def STDFri : F3_2<3, 0b100111, "std">;
90def STFSRrr : F3_1<3, 0b100101, "st">;
91def STFSRri : F3_2<3, 0b100101, "st">;
92def STDFQrr : F3_1<3, 0b100110, "std">;
93def STDFQri : F3_2<3, 0b100110, "std">;
Misha Brukman23e6c1f2004-02-26 00:37:12 +000094
Brian Gaeke775158d2004-03-04 04:37:45 +000095// Section B.9 - SETHI Instruction, p. 104
Brian Gaekee8061732004-03-04 00:56:25 +000096def SETHIi: F2_1<0b100, "sethi">;
97
Brian Gaeke8542e082004-04-02 20:53:37 +000098// Section B.10 - NOP Instruction, p. 105
99// (It's a special case of SETHI)
Misha Brukmand36047d2004-10-14 22:33:32 +0000100let rd = 0, imm22 = 0 in
Brian Gaeke8542e082004-04-02 20:53:37 +0000101 def NOP : F2_1<0b100, "nop">;
102
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000103// Section B.11 - Logical Instructions, p. 106
Brian Gaeke82a47952004-11-23 06:39:37 +0000104def ANDrr : F3_1<2, 0b000001, "and">;
105def ANDri : F3_2<2, 0b000001, "and">;
106def ANDCCrr : F3_1<2, 0b010001, "andcc">;
107def ANDCCri : F3_2<2, 0b010001, "andcc">;
108def ANDNrr : F3_1<2, 0b000101, "andn">;
109def ANDNri : F3_2<2, 0b000101, "andn">;
110def ANDNCCrr: F3_1<2, 0b010101, "andncc">;
111def ANDNCCri: F3_2<2, 0b010101, "andncc">;
112def ORrr : F3_1<2, 0b000010, "or">;
113def ORri : F3_2<2, 0b000010, "or">;
114def ORCCrr : F3_1<2, 0b010010, "orcc">;
115def ORCCri : F3_2<2, 0b010010, "orcc">;
116def ORNrr : F3_1<2, 0b000110, "orn">;
117def ORNri : F3_2<2, 0b000110, "orn">;
118def ORNCCrr : F3_1<2, 0b010110, "orncc">;
119def ORNCCri : F3_2<2, 0b010110, "orncc">;
120def XORrr : F3_1<2, 0b000011, "xor">;
121def XORri : F3_2<2, 0b000011, "xor">;
122def XORCCrr : F3_1<2, 0b010011, "xorcc">;
123def XORCCri : F3_2<2, 0b010011, "xorcc">;
124def XNORrr : F3_1<2, 0b000111, "xnor">;
125def XNORri : F3_2<2, 0b000111, "xnor">;
126def XNORCCrr: F3_1<2, 0b010111, "xnorcc">;
127def XNORCCri: F3_2<2, 0b010111, "xnorcc">;
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000128
129// Section B.12 - Shift Instructions, p. 107
Chris Lattnera562efc2004-04-07 04:26:57 +0000130def SLLrr : F3_1<2, 0b100101, "sll">;
131def SLLri : F3_2<2, 0b100101, "sll">;
132def SRLrr : F3_1<2, 0b100110, "srl">;
133def SRLri : F3_2<2, 0b100110, "srl">;
134def SRArr : F3_1<2, 0b100111, "sra">;
135def SRAri : F3_2<2, 0b100111, "sra">;
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000136
137// Section B.13 - Add Instructions, p. 108
Brian Gaeke43518572004-11-21 07:13:17 +0000138def ADDrr : F3_1<2, 0b000000, "add">;
139def ADDri : F3_2<2, 0b000000, "add">;
140def ADDCCrr : F3_1<2, 0b010000, "addcc">;
141def ADDCCri : F3_2<2, 0b010000, "addcc">;
142def ADDXrr : F3_1<2, 0b001000, "addx">;
143def ADDXri : F3_2<2, 0b001000, "addx">;
144def ADDXCCrr: F3_1<2, 0b011000, "addxcc">;
145def ADDXCCri: F3_2<2, 0b011000, "addxcc">;
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000146
Brian Gaeke775158d2004-03-04 04:37:45 +0000147// Section B.15 - Subtract Instructions, p. 110
Chris Lattner61790472004-04-07 05:04:01 +0000148def SUBrr : F3_1<2, 0b000100, "sub">;
Brian Gaeke43518572004-11-21 07:13:17 +0000149def SUBri : F3_2<2, 0b000100, "sub">;
Chris Lattner61790472004-04-07 05:04:01 +0000150def SUBCCrr : F3_1<2, 0b010100, "subcc">;
Brian Gaekec3e97012004-05-08 04:21:32 +0000151def SUBCCri : F3_2<2, 0b010100, "subcc">;
Brian Gaeke43518572004-11-21 07:13:17 +0000152def SUBXrr : F3_1<2, 0b001100, "subx">;
153def SUBXri : F3_2<2, 0b001100, "subx">;
154def SUBXCCrr: F3_1<2, 0b011100, "subxcc">;
155def SUBXCCri: F3_2<2, 0b011100, "subxcc">;
Brian Gaeke775158d2004-03-04 04:37:45 +0000156
Brian Gaeke032f80f2004-03-16 22:37:13 +0000157// Section B.18 - Multiply Instructions, p. 113
Brian Gaekec2e5f362004-12-10 08:39:29 +0000158def UMULrr : F3_1<2, 0b001010, "umul">;
159def UMULri : F3_2<2, 0b001010, "umul">;
160def SMULrr : F3_1<2, 0b001011, "smul">;
161def SMULri : F3_2<2, 0b001011, "smul">;
162def UMULCCrr: F3_1<2, 0b011010, "umulcc">;
163def UMULCCri: F3_2<2, 0b011010, "umulcc">;
164def SMULCCrr: F3_1<2, 0b011011, "smulcc">;
165def SMULCCri: F3_2<2, 0b011011, "smulcc">;
Brian Gaeke032f80f2004-03-16 22:37:13 +0000166
Brian Gaekee88c9dc2004-04-07 04:01:00 +0000167// Section B.19 - Divide Instructions, p. 115
Chris Lattner22ede702004-04-07 04:06:46 +0000168def UDIVrr : F3_1<2, 0b001110, "udiv">;
169def UDIVri : F3_2<2, 0b001110, "udiv">;
170def SDIVrr : F3_1<2, 0b001111, "sdiv">;
171def SDIVri : F3_2<2, 0b001111, "sdiv">;
172def UDIVCCrr : F3_1<2, 0b011110, "udivcc">;
173def UDIVCCri : F3_2<2, 0b011110, "udivcc">;
174def SDIVCCrr : F3_1<2, 0b011111, "sdivcc">;
175def SDIVCCri : F3_2<2, 0b011111, "sdivcc">;
Brian Gaekee88c9dc2004-04-07 04:01:00 +0000176
Brian Gaekea8056fa2004-03-06 05:32:13 +0000177// Section B.20 - SAVE and RESTORE, p. 117
178def SAVErr : F3_1<2, 0b111100, "save">; // save r, r, r
179def SAVEri : F3_2<2, 0b111100, "save">; // save r, i, r
180def RESTORErr : F3_1<2, 0b111101, "restore">; // restore r, r, r
181def RESTOREri : F3_2<2, 0b111101, "restore">; // restore r, i, r
182
Brian Gaekec3e97012004-05-08 04:21:32 +0000183// Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
Brian Gaeke070bb4a2004-06-17 22:34:29 +0000184
185// conditional branch class:
186class BranchV8<bits<4> cc, string nm> : F2_2<cc, 0b010, nm> {
187 let isBranch = 1;
188 let isTerminator = 1;
Brian Gaeked7bf5012004-09-30 04:04:48 +0000189 let hasDelaySlot = 1;
Brian Gaeke070bb4a2004-06-17 22:34:29 +0000190}
Chris Lattner0f6eab32004-07-31 02:24:37 +0000191
192let isBarrier = 1 in
193 def BA : BranchV8<0b1000, "ba">;
Brian Gaeke070bb4a2004-06-17 22:34:29 +0000194def BN : BranchV8<0b0000, "bn">;
195def BNE : BranchV8<0b1001, "bne">;
196def BE : BranchV8<0b0001, "be">;
197def BG : BranchV8<0b1010, "bg">;
198def BLE : BranchV8<0b0010, "ble">;
199def BGE : BranchV8<0b1011, "bge">;
200def BL : BranchV8<0b0011, "bl">;
201def BGU : BranchV8<0b1100, "bgu">;
202def BLEU : BranchV8<0b0100, "bleu">;
203def BCC : BranchV8<0b1101, "bcc">;
204def BCS : BranchV8<0b0101, "bcs">;
Brian Gaekec3e97012004-05-08 04:21:32 +0000205
Brian Gaeke4185d032004-07-08 09:08:22 +0000206// Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
207
208// floating-point conditional branch class:
209class FPBranchV8<bits<4> cc, string nm> : F2_2<cc, 0b110, nm> {
210 let isBranch = 1;
211 let isTerminator = 1;
Brian Gaeked7bf5012004-09-30 04:04:48 +0000212 let hasDelaySlot = 1;
Brian Gaeke4185d032004-07-08 09:08:22 +0000213}
214
215def FBA : FPBranchV8<0b1000, "fba">;
216def FBN : FPBranchV8<0b0000, "fbn">;
217def FBU : FPBranchV8<0b0111, "fbu">;
218def FBG : FPBranchV8<0b0110, "fbg">;
219def FBUG : FPBranchV8<0b0101, "fbug">;
220def FBL : FPBranchV8<0b0100, "fbl">;
221def FBUL : FPBranchV8<0b0011, "fbul">;
222def FBLG : FPBranchV8<0b0010, "fblg">;
223def FBNE : FPBranchV8<0b0001, "fbne">;
224def FBE : FPBranchV8<0b1001, "fbe">;
225def FBUE : FPBranchV8<0b1010, "fbue">;
226def FBGE : FPBranchV8<0b1011, "fbge">;
227def FBUGE: FPBranchV8<0b1100, "fbuge">;
228def FBLE : FPBranchV8<0b1101, "fble">;
229def FBULE: FPBranchV8<0b1110, "fbule">;
230def FBO : FPBranchV8<0b1111, "fbo">;
231
Brian Gaekeb354b712004-11-16 07:32:09 +0000232
233
Brian Gaeke8542e082004-04-02 20:53:37 +0000234// Section B.24 - Call and Link Instruction, p. 125
Brian Gaekea8056fa2004-03-06 05:32:13 +0000235// This is the only Format 1 instruction
Brian Gaekeb354b712004-11-16 07:32:09 +0000236let Uses = [O0, O1, O2, O3, O4, O5], hasDelaySlot = 1, isCall = 1 in {
Brian Gaeked7bf5012004-09-30 04:04:48 +0000237 // pc-relative call:
Brian Gaekeb354b712004-11-16 07:32:09 +0000238 let Defs = [O0, O1, O2, O3, O4, O5, O7, G1, G2, G3, G4, G5, G6, G7,
239 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15] in
Brian Gaeke374b36d2004-09-29 20:45:05 +0000240 def CALL : InstV8 {
241 bits<30> disp;
242 let op = 1;
243 let Inst{29-0} = disp;
244 let Name = "call";
245 }
Brian Gaekeb354b712004-11-16 07:32:09 +0000246
247 // indirect call (O7 is an EXPLICIT def in indirect calls, so it cannot also
248 // be an implicit def):
249 let Defs = [O0, O1, O2, O3, O4, O5, G1, G2, G3, G4, G5, G6, G7,
250 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15] in
Brian Gaekef89cc652004-06-18 06:28:10 +0000251 def JMPLrr : F3_1<2, 0b111000, "jmpl">; // jmpl [rs1+rs2], rd
Brian Gaeke374b36d2004-09-29 20:45:05 +0000252}
Misha Brukman23e6c1f2004-02-26 00:37:12 +0000253
Chris Lattner22ede702004-04-07 04:06:46 +0000254// Section B.29 - Write State Register Instructions
255def WRrr : F3_1<2, 0b110000, "wr">; // wr rs1, rs2, rd
256def WRri : F3_2<2, 0b110000, "wr">; // wr rs1, imm, rd
Chris Lattner61790472004-04-07 05:04:01 +0000257
Brian Gaekec53105c2004-06-27 22:53:56 +0000258// Convert Integer to Floating-point Instructions, p. 141
259def FITOS : F3_3<2, 0b110100, 0b011000100, "fitos">;
Brian Gaeke22ad67d2004-09-29 19:59:07 +0000260def FITOD : F3_3<2, 0b110100, 0b011001000, "fitod">;
Brian Gaekec53105c2004-06-27 22:53:56 +0000261
Brian Gaeke59e12ed2004-10-14 19:39:35 +0000262// Convert Floating-point to Integer Instructions, p. 142
263def FSTOI : F3_3<2, 0b110100, 0b011010001, "fstoi">;
264def FDTOI : F3_3<2, 0b110100, 0b011010010, "fdtoi">;
265
Brian Gaeke57ff2e32004-06-24 21:22:09 +0000266// Convert between Floating-point Formats Instructions, p. 143
267def FSTOD : F3_3<2, 0b110100, 0b011001001, "fstod">;
268def FDTOS : F3_3<2, 0b110100, 0b011000110, "fdtos">;
269
Brian Gaekef89cc652004-06-18 06:28:10 +0000270// Floating-point Move Instructions, p. 144
271def FMOVS : F3_3<2, 0b110100, 0b000000001, "fmovs">;
272def FNEGS : F3_3<2, 0b110100, 0b000000101, "fnegs">;
273def FABSS : F3_3<2, 0b110100, 0b000001001, "fabss">;
274
Brian Gaekec53105c2004-06-27 22:53:56 +0000275// Floating-point Add and Subtract Instructions, p. 146
276def FADDS : F3_3<2, 0b110100, 0b001000001, "fadds">;
277def FADDD : F3_3<2, 0b110100, 0b001000010, "faddd">;
278def FSUBS : F3_3<2, 0b110100, 0b001000101, "fsubs">;
279def FSUBD : F3_3<2, 0b110100, 0b001000110, "fsubd">;
280
281// Floating-point Multiply and Divide Instructions, p. 147
282def FMULS : F3_3<2, 0b110100, 0b001001001, "fmuls">;
283def FMULD : F3_3<2, 0b110100, 0b001001010, "fmuld">;
284def FSMULD : F3_3<2, 0b110100, 0b001101001, "fsmuld">;
285def FDIVS : F3_3<2, 0b110100, 0b001001101, "fdivs">;
286def FDIVD : F3_3<2, 0b110100, 0b001001110, "fdivd">;
Brian Gaeke57ff2e32004-06-24 21:22:09 +0000287
Brian Gaeke4185d032004-07-08 09:08:22 +0000288// Floating-point Compare Instructions, p. 148
Brian Gaeked7bf5012004-09-30 04:04:48 +0000289// Note: the 2nd template arg is different for these guys.
290// Note 2: the result of a FCMP is not available until the 2nd cycle
291// after the instr is retired, but there is no interlock. This behavior
292// is modelled as a delay slot.
293let hasDelaySlot = 1 in {
294 def FCMPS : F3_3<2, 0b110101, 0b001010001, "fcmps">;
295 def FCMPD : F3_3<2, 0b110101, 0b001010010, "fcmpd">;
296 def FCMPES : F3_3<2, 0b110101, 0b001010101, "fcmpes">;
297 def FCMPED : F3_3<2, 0b110101, 0b001010110, "fcmped">;
298}
Brian Gaeke4185d032004-07-08 09:08:22 +0000299