blob: 22ba93fed6a3e9cc5869a57d08e3aacf39ad9efa [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.
Brian Gaeke7c4676f2004-07-16 10:32:10 +000038class PseudoInstV8<string nm> : InstV8 {
39 let Name = nm;
Chris Lattner275f6452004-02-28 19:37:18 +000040}
Brian Gaeke7c4676f2004-07-16 10:32:10 +000041def PHI : PseudoInstV8<"PHI">;
42def ADJCALLSTACKDOWN : PseudoInstV8<"ADJCALLSTACKDOWN">;
43def ADJCALLSTACKUP : PseudoInstV8<"ADJCALLSTACKUP">;
44def IMPLICIT_USE : PseudoInstV8<"IMPLICIT_USE">;
45def IMPLICIT_DEF : PseudoInstV8<"IMPLICIT_DEF">;
Brian Gaekea036b532004-09-29 03:27:29 +000046def FpMOVD : PseudoInstV8<"FpMOVD">; // pseudo 64-bit double move
Chris Lattner275f6452004-02-28 19:37:18 +000047
Brian Gaekea8056fa2004-03-06 05:32:13 +000048// Section A.3 - Synthetic Instructions, p. 85
Brian Gaekec3e97012004-05-08 04:21:32 +000049// special cases of JMPL:
Misha Brukman3df04c52004-10-14 22:32:49 +000050let isReturn = 1, isTerminator = 1, hasDelaySlot = 1 in {
51 let rd = I7.Num, rs1 = G0.Num, simm13 = 8 in
52 def RET : F3_2<2, 0b111000, "ret">;
53 let rd = O7.Num, rs1 = G0.Num, simm13 = 8 in
54 def RETL: F3_2<2, 0b111000, "retl">;
55}
Brian Gaekec3e97012004-05-08 04:21:32 +000056// CMP is a special case of SUBCC where destination is ignored, by setting it to
57// %g0 (hardwired zero).
58// FIXME: should keep track of the fact that it defs the integer condition codes
59let rd = 0 in
60 def CMPri: F3_2<2, 0b010100, "cmp">;
Brian Gaeke8542e082004-04-02 20:53:37 +000061
62// Section B.1 - Load Integer Instructions, p. 90
Brian Gaekee7f9e0b2004-06-24 07:36:59 +000063def LDSB: F3_2<3, 0b001001, "ldsb">;
64def LDSH: F3_2<3, 0b001010, "ldsh">;
65def LDUB: F3_2<3, 0b000001, "ldub">;
66def LDUH: F3_2<3, 0b000010, "lduh">;
67def LD : F3_2<3, 0b000000, "ld">;
68def LDD : F3_2<3, 0b000011, "ldd">;
Brian Gaeke8542e082004-04-02 20:53:37 +000069
Brian Gaeke562d5b02004-06-18 05:19:27 +000070// Section B.2 - Load Floating-point Instructions, p. 92
Brian Gaekee7f9e0b2004-06-24 07:36:59 +000071def LDFrr : F3_1<3, 0b100000, "ld">;
72def LDFri : F3_2<3, 0b100000, "ld">;
73def LDDFrr : F3_1<3, 0b100011, "ldd">;
74def LDDFri : F3_2<3, 0b100011, "ldd">;
75def LDFSRrr: F3_1<3, 0b100001, "ld">;
76def LDFSRri: F3_2<3, 0b100001, "ld">;
Brian Gaeke562d5b02004-06-18 05:19:27 +000077
Brian Gaeke8542e082004-04-02 20:53:37 +000078// Section B.4 - Store Integer Instructions, p. 95
Brian Gaekee7f9e0b2004-06-24 07:36:59 +000079def STB : F3_2<3, 0b000101, "stb">;
80def STH : F3_2<3, 0b000110, "sth">;
81def ST : F3_2<3, 0b000100, "st">;
82def STD : F3_2<3, 0b000111, "std">;
83
84// Section B.5 - Store Floating-point Instructions, p. 97
85def STFrr : F3_1<3, 0b100100, "st">;
86def STFri : F3_2<3, 0b100100, "st">;
87def STDFrr : F3_1<3, 0b100111, "std">;
88def STDFri : F3_2<3, 0b100111, "std">;
89def STFSRrr : F3_1<3, 0b100101, "st">;
90def STFSRri : F3_2<3, 0b100101, "st">;
91def STDFQrr : F3_1<3, 0b100110, "std">;
92def STDFQri : F3_2<3, 0b100110, "std">;
Misha Brukman23e6c1f2004-02-26 00:37:12 +000093
Brian Gaeke775158d2004-03-04 04:37:45 +000094// Section B.9 - SETHI Instruction, p. 104
Brian Gaekee8061732004-03-04 00:56:25 +000095def SETHIi: F2_1<0b100, "sethi">;
96
Brian Gaeke8542e082004-04-02 20:53:37 +000097// Section B.10 - NOP Instruction, p. 105
98// (It's a special case of SETHI)
Misha Brukmand36047d2004-10-14 22:33:32 +000099let rd = 0, imm22 = 0 in
Brian Gaeke8542e082004-04-02 20:53:37 +0000100 def NOP : F2_1<0b100, "nop">;
101
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000102// Section B.11 - Logical Instructions, p. 106
Chris Lattner22ede702004-04-07 04:06:46 +0000103def ANDrr : F3_1<2, 0b000001, "and">;
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000104def ANDri : F3_2<2, 0b000001, "and">;
105def ORrr : F3_1<2, 0b000010, "or">;
Brian Gaekee8061732004-03-04 00:56:25 +0000106def ORri : F3_2<2, 0b000010, "or">;
Chris Lattner22ede702004-04-07 04:06:46 +0000107def XORrr : F3_1<2, 0b000011, "xor">;
108def XORri : F3_2<2, 0b000011, "xor">;
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000109
110// Section B.12 - Shift Instructions, p. 107
Chris Lattnera562efc2004-04-07 04:26:57 +0000111def SLLrr : F3_1<2, 0b100101, "sll">;
112def SLLri : F3_2<2, 0b100101, "sll">;
113def SRLrr : F3_1<2, 0b100110, "srl">;
114def SRLri : F3_2<2, 0b100110, "srl">;
115def SRArr : F3_1<2, 0b100111, "sra">;
116def SRAri : F3_2<2, 0b100111, "sra">;
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000117
118// Section B.13 - Add Instructions, p. 108
119def ADDrr : F3_1<2, 0b000000, "add">;
Brian Gaeke6b1d2fa2004-05-08 05:26:55 +0000120def ADDri : F3_2<2, 0b000000, "add">;
Brian Gaekebc1d27a2004-03-03 23:03:14 +0000121
Brian Gaeke775158d2004-03-04 04:37:45 +0000122// Section B.15 - Subtract Instructions, p. 110
Chris Lattner61790472004-04-07 05:04:01 +0000123def SUBrr : F3_1<2, 0b000100, "sub">;
124def SUBCCrr : F3_1<2, 0b010100, "subcc">;
Brian Gaekec3e97012004-05-08 04:21:32 +0000125def SUBCCri : F3_2<2, 0b010100, "subcc">;
Brian Gaeke775158d2004-03-04 04:37:45 +0000126
Brian Gaeke032f80f2004-03-16 22:37:13 +0000127// Section B.18 - Multiply Instructions, p. 113
128def UMULrr : F3_1<2, 0b001010, "umul">;
129def SMULrr : F3_1<2, 0b001011, "smul">;
130
Brian Gaekee88c9dc2004-04-07 04:01:00 +0000131// Section B.19 - Divide Instructions, p. 115
Chris Lattner22ede702004-04-07 04:06:46 +0000132def UDIVrr : F3_1<2, 0b001110, "udiv">;
133def UDIVri : F3_2<2, 0b001110, "udiv">;
134def SDIVrr : F3_1<2, 0b001111, "sdiv">;
135def SDIVri : F3_2<2, 0b001111, "sdiv">;
136def UDIVCCrr : F3_1<2, 0b011110, "udivcc">;
137def UDIVCCri : F3_2<2, 0b011110, "udivcc">;
138def SDIVCCrr : F3_1<2, 0b011111, "sdivcc">;
139def SDIVCCri : F3_2<2, 0b011111, "sdivcc">;
Brian Gaekee88c9dc2004-04-07 04:01:00 +0000140
Brian Gaekea8056fa2004-03-06 05:32:13 +0000141// Section B.20 - SAVE and RESTORE, p. 117
142def SAVErr : F3_1<2, 0b111100, "save">; // save r, r, r
143def SAVEri : F3_2<2, 0b111100, "save">; // save r, i, r
144def RESTORErr : F3_1<2, 0b111101, "restore">; // restore r, r, r
145def RESTOREri : F3_2<2, 0b111101, "restore">; // restore r, i, r
146
Brian Gaekec3e97012004-05-08 04:21:32 +0000147// Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
Brian Gaeke070bb4a2004-06-17 22:34:29 +0000148
149// conditional branch class:
150class BranchV8<bits<4> cc, string nm> : F2_2<cc, 0b010, nm> {
151 let isBranch = 1;
152 let isTerminator = 1;
Brian Gaeked7bf5012004-09-30 04:04:48 +0000153 let hasDelaySlot = 1;
Brian Gaeke070bb4a2004-06-17 22:34:29 +0000154}
Chris Lattner0f6eab32004-07-31 02:24:37 +0000155
156let isBarrier = 1 in
157 def BA : BranchV8<0b1000, "ba">;
Brian Gaeke070bb4a2004-06-17 22:34:29 +0000158def BN : BranchV8<0b0000, "bn">;
159def BNE : BranchV8<0b1001, "bne">;
160def BE : BranchV8<0b0001, "be">;
161def BG : BranchV8<0b1010, "bg">;
162def BLE : BranchV8<0b0010, "ble">;
163def BGE : BranchV8<0b1011, "bge">;
164def BL : BranchV8<0b0011, "bl">;
165def BGU : BranchV8<0b1100, "bgu">;
166def BLEU : BranchV8<0b0100, "bleu">;
167def BCC : BranchV8<0b1101, "bcc">;
168def BCS : BranchV8<0b0101, "bcs">;
Brian Gaekec3e97012004-05-08 04:21:32 +0000169
Brian Gaeke4185d032004-07-08 09:08:22 +0000170// Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
171
172// floating-point conditional branch class:
173class FPBranchV8<bits<4> cc, string nm> : F2_2<cc, 0b110, nm> {
174 let isBranch = 1;
175 let isTerminator = 1;
Brian Gaeked7bf5012004-09-30 04:04:48 +0000176 let hasDelaySlot = 1;
Brian Gaeke4185d032004-07-08 09:08:22 +0000177}
178
179def FBA : FPBranchV8<0b1000, "fba">;
180def FBN : FPBranchV8<0b0000, "fbn">;
181def FBU : FPBranchV8<0b0111, "fbu">;
182def FBG : FPBranchV8<0b0110, "fbg">;
183def FBUG : FPBranchV8<0b0101, "fbug">;
184def FBL : FPBranchV8<0b0100, "fbl">;
185def FBUL : FPBranchV8<0b0011, "fbul">;
186def FBLG : FPBranchV8<0b0010, "fblg">;
187def FBNE : FPBranchV8<0b0001, "fbne">;
188def FBE : FPBranchV8<0b1001, "fbe">;
189def FBUE : FPBranchV8<0b1010, "fbue">;
190def FBGE : FPBranchV8<0b1011, "fbge">;
191def FBUGE: FPBranchV8<0b1100, "fbuge">;
192def FBLE : FPBranchV8<0b1101, "fble">;
193def FBULE: FPBranchV8<0b1110, "fbule">;
194def FBO : FPBranchV8<0b1111, "fbo">;
195
Brian Gaeke8542e082004-04-02 20:53:37 +0000196// Section B.24 - Call and Link Instruction, p. 125
Brian Gaekea8056fa2004-03-06 05:32:13 +0000197// This is the only Format 1 instruction
Brian Gaekef28688e2004-11-15 05:56:53 +0000198let Uses = [O0, O1, O2, O3, O4, O5], Defs = [O0, O1, O2, O3, O4, O5, O7, G1, G2,
199G3, G4, G5, G6, G7],
Brian Gaeke9f0cecd2004-10-10 19:57:20 +0000200 hasDelaySlot = 1, isCall = 1 in {
Brian Gaeked7bf5012004-09-30 04:04:48 +0000201 // pc-relative call:
Brian Gaeke374b36d2004-09-29 20:45:05 +0000202 def CALL : InstV8 {
203 bits<30> disp;
204 let op = 1;
205 let Inst{29-0} = disp;
206 let Name = "call";
207 }
Brian Gaeked7bf5012004-09-30 04:04:48 +0000208 // indirect call:
Brian Gaekef89cc652004-06-18 06:28:10 +0000209 def JMPLrr : F3_1<2, 0b111000, "jmpl">; // jmpl [rs1+rs2], rd
Brian Gaeke374b36d2004-09-29 20:45:05 +0000210}
Misha Brukman23e6c1f2004-02-26 00:37:12 +0000211
Chris Lattner22ede702004-04-07 04:06:46 +0000212// Section B.29 - Write State Register Instructions
213def WRrr : F3_1<2, 0b110000, "wr">; // wr rs1, rs2, rd
214def WRri : F3_2<2, 0b110000, "wr">; // wr rs1, imm, rd
Chris Lattner61790472004-04-07 05:04:01 +0000215
Brian Gaekec53105c2004-06-27 22:53:56 +0000216// Convert Integer to Floating-point Instructions, p. 141
217def FITOS : F3_3<2, 0b110100, 0b011000100, "fitos">;
Brian Gaeke22ad67d2004-09-29 19:59:07 +0000218def FITOD : F3_3<2, 0b110100, 0b011001000, "fitod">;
Brian Gaekec53105c2004-06-27 22:53:56 +0000219
Brian Gaeke59e12ed2004-10-14 19:39:35 +0000220// Convert Floating-point to Integer Instructions, p. 142
221def FSTOI : F3_3<2, 0b110100, 0b011010001, "fstoi">;
222def FDTOI : F3_3<2, 0b110100, 0b011010010, "fdtoi">;
223
Brian Gaeke57ff2e32004-06-24 21:22:09 +0000224// Convert between Floating-point Formats Instructions, p. 143
225def FSTOD : F3_3<2, 0b110100, 0b011001001, "fstod">;
226def FDTOS : F3_3<2, 0b110100, 0b011000110, "fdtos">;
227
Brian Gaekef89cc652004-06-18 06:28:10 +0000228// Floating-point Move Instructions, p. 144
229def FMOVS : F3_3<2, 0b110100, 0b000000001, "fmovs">;
230def FNEGS : F3_3<2, 0b110100, 0b000000101, "fnegs">;
231def FABSS : F3_3<2, 0b110100, 0b000001001, "fabss">;
232
Brian Gaekec53105c2004-06-27 22:53:56 +0000233// Floating-point Add and Subtract Instructions, p. 146
234def FADDS : F3_3<2, 0b110100, 0b001000001, "fadds">;
235def FADDD : F3_3<2, 0b110100, 0b001000010, "faddd">;
236def FSUBS : F3_3<2, 0b110100, 0b001000101, "fsubs">;
237def FSUBD : F3_3<2, 0b110100, 0b001000110, "fsubd">;
238
239// Floating-point Multiply and Divide Instructions, p. 147
240def FMULS : F3_3<2, 0b110100, 0b001001001, "fmuls">;
241def FMULD : F3_3<2, 0b110100, 0b001001010, "fmuld">;
242def FSMULD : F3_3<2, 0b110100, 0b001101001, "fsmuld">;
243def FDIVS : F3_3<2, 0b110100, 0b001001101, "fdivs">;
244def FDIVD : F3_3<2, 0b110100, 0b001001110, "fdivd">;
Brian Gaeke57ff2e32004-06-24 21:22:09 +0000245
Brian Gaeke4185d032004-07-08 09:08:22 +0000246// Floating-point Compare Instructions, p. 148
Brian Gaeked7bf5012004-09-30 04:04:48 +0000247// Note: the 2nd template arg is different for these guys.
248// Note 2: the result of a FCMP is not available until the 2nd cycle
249// after the instr is retired, but there is no interlock. This behavior
250// is modelled as a delay slot.
251let hasDelaySlot = 1 in {
252 def FCMPS : F3_3<2, 0b110101, 0b001010001, "fcmps">;
253 def FCMPD : F3_3<2, 0b110101, 0b001010010, "fcmpd">;
254 def FCMPES : F3_3<2, 0b110101, 0b001010101, "fcmpes">;
255 def FCMPED : F3_3<2, 0b110101, 0b001010110, "fcmped">;
256}
Brian Gaeke4185d032004-07-08 09:08:22 +0000257