blob: 4f3abc98758a329ab91b794ab2320a57ae7515b3 [file] [log] [blame]
Chris Lattner158e1f52006-02-05 05:50:24 +00001//===- SparcInstrInfo.td - Target Description for Sparc Target ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner158e1f52006-02-05 05:50:24 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Sparc instructions in TableGen format.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Instruction format superclass
16//===----------------------------------------------------------------------===//
17
18include "SparcInstrFormats.td"
19
20//===----------------------------------------------------------------------===//
21// Feature predicates.
22//===----------------------------------------------------------------------===//
23
24// HasV9 - This predicate is true when the target processor supports V9
25// instructions. Note that the machine may be running in 32-bit mode.
26def HasV9 : Predicate<"Subtarget.isV9()">;
27
28// HasNoV9 - This predicate is true when the target doesn't have V9
29// instructions. Use of this is just a hack for the isel not having proper
30// costs for V8 instructions that are more expensive than their V9 ones.
31def HasNoV9 : Predicate<"!Subtarget.isV9()">;
32
33// HasVIS - This is true when the target processor has VIS extensions.
34def HasVIS : Predicate<"Subtarget.isVIS()">;
35
36// UseDeprecatedInsts - This predicate is true when the target processor is a
37// V8, or when it is V9 but the V8 deprecated instructions are efficient enough
38// to use when appropriate. In either of these cases, the instruction selector
39// will pick deprecated instructions.
40def UseDeprecatedInsts : Predicate<"Subtarget.useDeprecatedV8Instructions()">;
41
42//===----------------------------------------------------------------------===//
43// Instruction Pattern Stuff
44//===----------------------------------------------------------------------===//
45
Jakob Stoklund Olesenf02b4a62010-08-17 18:17:12 +000046def simm11 : PatLeaf<(imm), [{ return isInt<11>(N->getSExtValue()); }]>;
Chris Lattner158e1f52006-02-05 05:50:24 +000047
Jakob Stoklund Olesenf02b4a62010-08-17 18:17:12 +000048def simm13 : PatLeaf<(imm), [{ return isInt<13>(N->getSExtValue()); }]>;
Chris Lattner158e1f52006-02-05 05:50:24 +000049
50def LO10 : SDNodeXForm<imm, [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000051 return CurDAG->getTargetConstant((unsigned)N->getZExtValue() & 1023,
Owen Anderson9f944592009-08-11 20:47:22 +000052 MVT::i32);
Chris Lattner158e1f52006-02-05 05:50:24 +000053}]>;
54
55def HI22 : SDNodeXForm<imm, [{
56 // Transformation function: shift the immediate value down into the low bits.
Owen Anderson9f944592009-08-11 20:47:22 +000057 return CurDAG->getTargetConstant((unsigned)N->getZExtValue() >> 10, MVT::i32);
Chris Lattner158e1f52006-02-05 05:50:24 +000058}]>;
59
60def SETHIimm : PatLeaf<(imm), [{
Dan Gohmaneffb8942008-09-12 16:56:44 +000061 return (((unsigned)N->getZExtValue() >> 10) << 10) ==
62 (unsigned)N->getZExtValue();
Chris Lattner158e1f52006-02-05 05:50:24 +000063}], HI22>;
64
65// Addressing modes.
Evan Cheng577ef762006-10-11 21:03:53 +000066def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
67def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [frameindex], []>;
Chris Lattner158e1f52006-02-05 05:50:24 +000068
69// Address operands
70def MEMrr : Operand<i32> {
71 let PrintMethod = "printMemOperand";
Chris Lattner158e1f52006-02-05 05:50:24 +000072 let MIOperandInfo = (ops IntRegs, IntRegs);
73}
74def MEMri : Operand<i32> {
75 let PrintMethod = "printMemOperand";
Chris Lattner158e1f52006-02-05 05:50:24 +000076 let MIOperandInfo = (ops IntRegs, i32imm);
77}
78
79// Branch targets have OtherVT type.
80def brtarget : Operand<OtherVT>;
81def calltarget : Operand<i32>;
82
83// Operand for printing out a condition code.
84let PrintMethod = "printCCOperand" in
85 def CCOp : Operand<i32>;
86
87def SDTSPcmpfcc :
Chris Lattner0c4dea42006-02-10 06:58:25 +000088SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
Chris Lattner158e1f52006-02-05 05:50:24 +000089def SDTSPbrcc :
Chris Lattner0c4dea42006-02-10 06:58:25 +000090SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
Chris Lattner158e1f52006-02-05 05:50:24 +000091def SDTSPselectcc :
Chris Lattner0c4dea42006-02-10 06:58:25 +000092SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
Chris Lattner158e1f52006-02-05 05:50:24 +000093def SDTSPFTOI :
94SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
95def SDTSPITOF :
96SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
97
Chris Lattner2a0a3b42010-12-23 18:28:41 +000098def SPcmpicc : SDNode<"SPISD::CMPICC", SDTIntBinOp, [SDNPOutGlue]>;
99def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutGlue]>;
100def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
101def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000102
103def SPhi : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
104def SPlo : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
105
106def SPftoi : SDNode<"SPISD::FTOI", SDTSPFTOI>;
107def SPitof : SDNode<"SPISD::ITOF", SDTSPITOF>;
108
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000109def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInGlue]>;
110def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInGlue]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000111
Venkatraman Govindaraju71425082009-08-26 04:50:17 +0000112// These are target-independent nodes, but have target-specific formats.
Bill Wendling77b13af2007-11-13 09:19:02 +0000113def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
114def SDT_SPCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>,
115 SDTCisVT<1, i32> ]>;
Bill Wendlingf359fed2007-11-13 00:44:25 +0000116
Bill Wendling77b13af2007-11-13 09:19:02 +0000117def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000118 [SDNPHasChain, SDNPOutGlue]>;
Bill Wendling77b13af2007-11-13 09:19:02 +0000119def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeqEnd,
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000120 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000121
122def SDT_SPCall : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
123def call : SDNode<"SPISD::CALL", SDT_SPCall,
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000124 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000125
Dan Gohmaneac0c962008-03-13 23:07:40 +0000126def retflag : SDNode<"SPISD::RET_FLAG", SDTNone,
Chris Lattner2a0a3b42010-12-23 18:28:41 +0000127 [SDNPHasChain, SDNPOptInGlue]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000128
Chris Lattner840c7002009-09-15 17:46:24 +0000129def getPCX : Operand<i32> {
130 let PrintMethod = "printGetPCX";
131}
132
Chris Lattner158e1f52006-02-05 05:50:24 +0000133//===----------------------------------------------------------------------===//
134// SPARC Flag Conditions
135//===----------------------------------------------------------------------===//
136
137// Note that these values must be kept in sync with the CCOp::CondCode enum
138// values.
139class ICC_VAL<int N> : PatLeaf<(i32 N)>;
140def ICC_NE : ICC_VAL< 9>; // Not Equal
141def ICC_E : ICC_VAL< 1>; // Equal
142def ICC_G : ICC_VAL<10>; // Greater
143def ICC_LE : ICC_VAL< 2>; // Less or Equal
144def ICC_GE : ICC_VAL<11>; // Greater or Equal
145def ICC_L : ICC_VAL< 3>; // Less
146def ICC_GU : ICC_VAL<12>; // Greater Unsigned
147def ICC_LEU : ICC_VAL< 4>; // Less or Equal Unsigned
148def ICC_CC : ICC_VAL<13>; // Carry Clear/Great or Equal Unsigned
149def ICC_CS : ICC_VAL< 5>; // Carry Set/Less Unsigned
150def ICC_POS : ICC_VAL<14>; // Positive
151def ICC_NEG : ICC_VAL< 6>; // Negative
152def ICC_VC : ICC_VAL<15>; // Overflow Clear
153def ICC_VS : ICC_VAL< 7>; // Overflow Set
154
155class FCC_VAL<int N> : PatLeaf<(i32 N)>;
156def FCC_U : FCC_VAL<23>; // Unordered
157def FCC_G : FCC_VAL<22>; // Greater
158def FCC_UG : FCC_VAL<21>; // Unordered or Greater
159def FCC_L : FCC_VAL<20>; // Less
160def FCC_UL : FCC_VAL<19>; // Unordered or Less
161def FCC_LG : FCC_VAL<18>; // Less or Greater
162def FCC_NE : FCC_VAL<17>; // Not Equal
163def FCC_E : FCC_VAL<25>; // Equal
164def FCC_UE : FCC_VAL<24>; // Unordered or Equal
165def FCC_GE : FCC_VAL<25>; // Greater or Equal
166def FCC_UGE : FCC_VAL<26>; // Unordered or Greater or Equal
167def FCC_LE : FCC_VAL<27>; // Less or Equal
168def FCC_ULE : FCC_VAL<28>; // Unordered or Less or Equal
169def FCC_O : FCC_VAL<29>; // Ordered
170
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000171//===----------------------------------------------------------------------===//
172// Instruction Class Templates
173//===----------------------------------------------------------------------===//
174
175/// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
176multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode> {
177 def rr : F3_1<2, Op3Val,
Evan Cheng94b5a802007-07-19 01:14:50 +0000178 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000179 !strconcat(OpcStr, " $b, $c, $dst"),
180 [(set IntRegs:$dst, (OpNode IntRegs:$b, IntRegs:$c))]>;
181 def ri : F3_2<2, Op3Val,
Evan Cheng94b5a802007-07-19 01:14:50 +0000182 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000183 !strconcat(OpcStr, " $b, $c, $dst"),
184 [(set IntRegs:$dst, (OpNode IntRegs:$b, simm13:$c))]>;
185}
186
187/// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
188/// pattern.
189multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
190 def rr : F3_1<2, Op3Val,
Evan Cheng94b5a802007-07-19 01:14:50 +0000191 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000192 !strconcat(OpcStr, " $b, $c, $dst"), []>;
193 def ri : F3_2<2, Op3Val,
Evan Cheng94b5a802007-07-19 01:14:50 +0000194 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000195 !strconcat(OpcStr, " $b, $c, $dst"), []>;
196}
Chris Lattner158e1f52006-02-05 05:50:24 +0000197
198//===----------------------------------------------------------------------===//
199// Instructions
200//===----------------------------------------------------------------------===//
201
202// Pseudo instructions.
Evan Cheng94b5a802007-07-19 01:14:50 +0000203class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
204 : InstSP<outs, ins, asmstr, pattern>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000205
Chris Lattner840c7002009-09-15 17:46:24 +0000206// GETPCX for PIC
207let Defs = [O7], Uses = [O7] in {
208 def GETPCX : Pseudo<(outs getPCX:$getpcseq), (ins), "$getpcseq", [] >;
209}
210
Evan Cheng3e18e502007-09-11 19:55:27 +0000211let Defs = [O6], Uses = [O6] in {
Evan Cheng94b5a802007-07-19 01:14:50 +0000212def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
Chris Lattner158e1f52006-02-05 05:50:24 +0000213 "!ADJCALLSTACKDOWN $amt",
Chris Lattner27539552008-10-11 22:08:30 +0000214 [(callseq_start timm:$amt)]>;
Bill Wendlingf359fed2007-11-13 00:44:25 +0000215def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
216 "!ADJCALLSTACKUP $amt1",
Chris Lattner27539552008-10-11 22:08:30 +0000217 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000218}
Evan Cheng6e683812007-12-12 23:12:09 +0000219
Chris Lattner158e1f52006-02-05 05:50:24 +0000220// FpMOVD/FpNEGD/FpABSD - These are lowered to single-precision ops by the
221// fpmover pass.
Chris Lattner747cf602006-02-21 18:04:32 +0000222let Predicates = [HasNoV9] in { // Only emit these in V8 mode.
Evan Cheng94b5a802007-07-19 01:14:50 +0000223 def FpMOVD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000224 "!FpMOVD $src, $dst", []>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000225 def FpNEGD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000226 "!FpNEGD $src, $dst",
227 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000228 def FpABSD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000229 "!FpABSD $src, $dst",
230 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
231}
232
Dan Gohman453d64c2009-10-29 18:10:34 +0000233// SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded after
234// instruction selection into a branch sequence. This has to handle all
235// permutations of selection between i32/f32/f64 on ICC and FCC.
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000236let Uses = [ICC],
237 usesCustomInserter = 1 in { // Expanded after instruction selection.
Chris Lattner158e1f52006-02-05 05:50:24 +0000238 def SELECT_CC_Int_ICC
Evan Cheng94b5a802007-07-19 01:14:50 +0000239 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
Chris Lattner158e1f52006-02-05 05:50:24 +0000240 "; SELECT_CC_Int_ICC PSEUDO!",
241 [(set IntRegs:$dst, (SPselecticc IntRegs:$T, IntRegs:$F,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000242 imm:$Cond))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000243 def SELECT_CC_Int_FCC
Evan Cheng94b5a802007-07-19 01:14:50 +0000244 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
Chris Lattner158e1f52006-02-05 05:50:24 +0000245 "; SELECT_CC_Int_FCC PSEUDO!",
246 [(set IntRegs:$dst, (SPselectfcc IntRegs:$T, IntRegs:$F,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000247 imm:$Cond))]>;
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000248}
249
250let usesCustomInserter = 1, Uses = [FCC] in {
Chris Lattner158e1f52006-02-05 05:50:24 +0000251 def SELECT_CC_FP_ICC
Evan Cheng94b5a802007-07-19 01:14:50 +0000252 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
Chris Lattner158e1f52006-02-05 05:50:24 +0000253 "; SELECT_CC_FP_ICC PSEUDO!",
254 [(set FPRegs:$dst, (SPselecticc FPRegs:$T, FPRegs:$F,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000255 imm:$Cond))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000256 def SELECT_CC_FP_FCC
Evan Cheng94b5a802007-07-19 01:14:50 +0000257 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
Chris Lattner158e1f52006-02-05 05:50:24 +0000258 "; SELECT_CC_FP_FCC PSEUDO!",
259 [(set FPRegs:$dst, (SPselectfcc FPRegs:$T, FPRegs:$F,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000260 imm:$Cond))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000261 def SELECT_CC_DFP_ICC
Evan Cheng94b5a802007-07-19 01:14:50 +0000262 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
Chris Lattner158e1f52006-02-05 05:50:24 +0000263 "; SELECT_CC_DFP_ICC PSEUDO!",
264 [(set DFPRegs:$dst, (SPselecticc DFPRegs:$T, DFPRegs:$F,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000265 imm:$Cond))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000266 def SELECT_CC_DFP_FCC
Evan Cheng94b5a802007-07-19 01:14:50 +0000267 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
Chris Lattner158e1f52006-02-05 05:50:24 +0000268 "; SELECT_CC_DFP_FCC PSEUDO!",
269 [(set DFPRegs:$dst, (SPselectfcc DFPRegs:$T, DFPRegs:$F,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000270 imm:$Cond))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000271}
272
273
274// Section A.3 - Synthetic Instructions, p. 85
275// special cases of JMPL:
Dan Gohman9fd22f682009-11-11 18:11:07 +0000276let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, isBarrier = 1 in {
Chris Lattner158e1f52006-02-05 05:50:24 +0000277 let rd = O7.Num, rs1 = G0.Num, simm13 = 8 in
Evan Cheng94b5a802007-07-19 01:14:50 +0000278 def RETL: F3_2<2, 0b111000, (outs), (ins), "retl", [(retflag)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000279}
280
281// Section B.1 - Load Integer Instructions, p. 90
282def LDSBrr : F3_1<3, 0b001001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000283 (outs IntRegs:$dst), (ins MEMrr:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000284 "ldsb [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000285 [(set IntRegs:$dst, (sextloadi8 ADDRrr:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000286def LDSBri : F3_2<3, 0b001001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000287 (outs IntRegs:$dst), (ins MEMri:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000288 "ldsb [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000289 [(set IntRegs:$dst, (sextloadi8 ADDRri:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000290def LDSHrr : F3_1<3, 0b001010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000291 (outs IntRegs:$dst), (ins MEMrr:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000292 "ldsh [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000293 [(set IntRegs:$dst, (sextloadi16 ADDRrr:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000294def LDSHri : F3_2<3, 0b001010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000295 (outs IntRegs:$dst), (ins MEMri:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000296 "ldsh [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000297 [(set IntRegs:$dst, (sextloadi16 ADDRri:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000298def LDUBrr : F3_1<3, 0b000001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000299 (outs IntRegs:$dst), (ins MEMrr:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000300 "ldub [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000301 [(set IntRegs:$dst, (zextloadi8 ADDRrr:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000302def LDUBri : F3_2<3, 0b000001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000303 (outs IntRegs:$dst), (ins MEMri:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000304 "ldub [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000305 [(set IntRegs:$dst, (zextloadi8 ADDRri:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000306def LDUHrr : F3_1<3, 0b000010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000307 (outs IntRegs:$dst), (ins MEMrr:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000308 "lduh [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000309 [(set IntRegs:$dst, (zextloadi16 ADDRrr:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000310def LDUHri : F3_2<3, 0b000010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000311 (outs IntRegs:$dst), (ins MEMri:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000312 "lduh [$addr], $dst",
Evan Chenge71fe34d2006-10-09 20:57:25 +0000313 [(set IntRegs:$dst, (zextloadi16 ADDRri:$addr))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000314def LDrr : F3_1<3, 0b000000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000315 (outs IntRegs:$dst), (ins MEMrr:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000316 "ld [$addr], $dst",
317 [(set IntRegs:$dst, (load ADDRrr:$addr))]>;
318def LDri : F3_2<3, 0b000000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000319 (outs IntRegs:$dst), (ins MEMri:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000320 "ld [$addr], $dst",
321 [(set IntRegs:$dst, (load ADDRri:$addr))]>;
322
323// Section B.2 - Load Floating-point Instructions, p. 92
324def LDFrr : F3_1<3, 0b100000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000325 (outs FPRegs:$dst), (ins MEMrr:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000326 "ld [$addr], $dst",
327 [(set FPRegs:$dst, (load ADDRrr:$addr))]>;
328def LDFri : F3_2<3, 0b100000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000329 (outs FPRegs:$dst), (ins MEMri:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000330 "ld [$addr], $dst",
331 [(set FPRegs:$dst, (load ADDRri:$addr))]>;
332def LDDFrr : F3_1<3, 0b100011,
Evan Cheng94b5a802007-07-19 01:14:50 +0000333 (outs DFPRegs:$dst), (ins MEMrr:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000334 "ldd [$addr], $dst",
335 [(set DFPRegs:$dst, (load ADDRrr:$addr))]>;
336def LDDFri : F3_2<3, 0b100011,
Evan Cheng94b5a802007-07-19 01:14:50 +0000337 (outs DFPRegs:$dst), (ins MEMri:$addr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000338 "ldd [$addr], $dst",
339 [(set DFPRegs:$dst, (load ADDRri:$addr))]>;
340
341// Section B.4 - Store Integer Instructions, p. 95
342def STBrr : F3_1<3, 0b000101,
Evan Cheng94b5a802007-07-19 01:14:50 +0000343 (outs), (ins MEMrr:$addr, IntRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000344 "stb $src, [$addr]",
Evan Chengab51cf22006-10-13 21:14:26 +0000345 [(truncstorei8 IntRegs:$src, ADDRrr:$addr)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000346def STBri : F3_2<3, 0b000101,
Evan Cheng94b5a802007-07-19 01:14:50 +0000347 (outs), (ins MEMri:$addr, IntRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000348 "stb $src, [$addr]",
Evan Chengab51cf22006-10-13 21:14:26 +0000349 [(truncstorei8 IntRegs:$src, ADDRri:$addr)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000350def STHrr : F3_1<3, 0b000110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000351 (outs), (ins MEMrr:$addr, IntRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000352 "sth $src, [$addr]",
Evan Chengab51cf22006-10-13 21:14:26 +0000353 [(truncstorei16 IntRegs:$src, ADDRrr:$addr)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000354def STHri : F3_2<3, 0b000110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000355 (outs), (ins MEMri:$addr, IntRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000356 "sth $src, [$addr]",
Evan Chengab51cf22006-10-13 21:14:26 +0000357 [(truncstorei16 IntRegs:$src, ADDRri:$addr)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000358def STrr : F3_1<3, 0b000100,
Evan Cheng94b5a802007-07-19 01:14:50 +0000359 (outs), (ins MEMrr:$addr, IntRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000360 "st $src, [$addr]",
361 [(store IntRegs:$src, ADDRrr:$addr)]>;
362def STri : F3_2<3, 0b000100,
Evan Cheng94b5a802007-07-19 01:14:50 +0000363 (outs), (ins MEMri:$addr, IntRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000364 "st $src, [$addr]",
365 [(store IntRegs:$src, ADDRri:$addr)]>;
366
367// Section B.5 - Store Floating-point Instructions, p. 97
368def STFrr : F3_1<3, 0b100100,
Evan Cheng94b5a802007-07-19 01:14:50 +0000369 (outs), (ins MEMrr:$addr, FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000370 "st $src, [$addr]",
371 [(store FPRegs:$src, ADDRrr:$addr)]>;
372def STFri : F3_2<3, 0b100100,
Evan Cheng94b5a802007-07-19 01:14:50 +0000373 (outs), (ins MEMri:$addr, FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000374 "st $src, [$addr]",
375 [(store FPRegs:$src, ADDRri:$addr)]>;
376def STDFrr : F3_1<3, 0b100111,
Evan Cheng94b5a802007-07-19 01:14:50 +0000377 (outs), (ins MEMrr:$addr, DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000378 "std $src, [$addr]",
379 [(store DFPRegs:$src, ADDRrr:$addr)]>;
380def STDFri : F3_2<3, 0b100111,
Evan Cheng94b5a802007-07-19 01:14:50 +0000381 (outs), (ins MEMri:$addr, DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000382 "std $src, [$addr]",
383 [(store DFPRegs:$src, ADDRri:$addr)]>;
384
385// Section B.9 - SETHI Instruction, p. 104
386def SETHIi: F2_1<0b100,
Evan Cheng94b5a802007-07-19 01:14:50 +0000387 (outs IntRegs:$dst), (ins i32imm:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000388 "sethi $src, $dst",
389 [(set IntRegs:$dst, SETHIimm:$src)]>;
390
391// Section B.10 - NOP Instruction, p. 105
392// (It's a special case of SETHI)
393let rd = 0, imm22 = 0 in
Evan Cheng94b5a802007-07-19 01:14:50 +0000394 def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000395
396// Section B.11 - Logical Instructions, p. 106
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000397defm AND : F3_12<"and", 0b000001, and>;
398
Chris Lattner158e1f52006-02-05 05:50:24 +0000399def ANDNrr : F3_1<2, 0b000101,
Evan Cheng94b5a802007-07-19 01:14:50 +0000400 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Chris Lattner158e1f52006-02-05 05:50:24 +0000401 "andn $b, $c, $dst",
402 [(set IntRegs:$dst, (and IntRegs:$b, (not IntRegs:$c)))]>;
403def ANDNri : F3_2<2, 0b000101,
Evan Cheng94b5a802007-07-19 01:14:50 +0000404 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Chris Lattner158e1f52006-02-05 05:50:24 +0000405 "andn $b, $c, $dst", []>;
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000406
407defm OR : F3_12<"or", 0b000010, or>;
408
Chris Lattner158e1f52006-02-05 05:50:24 +0000409def ORNrr : F3_1<2, 0b000110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000410 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Chris Lattner158e1f52006-02-05 05:50:24 +0000411 "orn $b, $c, $dst",
412 [(set IntRegs:$dst, (or IntRegs:$b, (not IntRegs:$c)))]>;
413def ORNri : F3_2<2, 0b000110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000414 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Chris Lattner158e1f52006-02-05 05:50:24 +0000415 "orn $b, $c, $dst", []>;
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000416defm XOR : F3_12<"xor", 0b000011, xor>;
417
Chris Lattner158e1f52006-02-05 05:50:24 +0000418def XNORrr : F3_1<2, 0b000111,
Evan Cheng94b5a802007-07-19 01:14:50 +0000419 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Chris Lattner158e1f52006-02-05 05:50:24 +0000420 "xnor $b, $c, $dst",
421 [(set IntRegs:$dst, (not (xor IntRegs:$b, IntRegs:$c)))]>;
422def XNORri : F3_2<2, 0b000111,
Evan Cheng94b5a802007-07-19 01:14:50 +0000423 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Chris Lattner158e1f52006-02-05 05:50:24 +0000424 "xnor $b, $c, $dst", []>;
425
426// Section B.12 - Shift Instructions, p. 107
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000427defm SLL : F3_12<"sll", 0b100101, shl>;
428defm SRL : F3_12<"srl", 0b100110, srl>;
429defm SRA : F3_12<"sra", 0b100111, sra>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000430
431// Section B.13 - Add Instructions, p. 108
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000432defm ADD : F3_12<"add", 0b000000, add>;
Chris Lattnerfcb8a3a2006-02-10 07:35:42 +0000433
434// "LEA" forms of add (patterns to make tblgen happy)
435def LEA_ADDri : F3_2<2, 0b000000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000436 (outs IntRegs:$dst), (ins MEMri:$addr),
Chris Lattnerfcb8a3a2006-02-10 07:35:42 +0000437 "add ${addr:arith}, $dst",
438 [(set IntRegs:$dst, ADDRri:$addr)]>;
Chris Lattner840c7002009-09-15 17:46:24 +0000439
440let Defs = [ICC] in
441 defm ADDCC : F3_12<"addcc", 0b010000, addc>;
442
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000443defm ADDX : F3_12<"addx", 0b001000, adde>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000444
445// Section B.15 - Subtract Instructions, p. 110
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000446defm SUB : F3_12 <"sub" , 0b000100, sub>;
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000447let Uses = [ICC] in
448 defm SUBX : F3_12 <"subx" , 0b001100, sube>;
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000449
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000450let Defs = [ICC] in
Chris Lattner840c7002009-09-15 17:46:24 +0000451 defm SUBCC : F3_12 <"subcc", 0b010100, SPcmpicc>;
452
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000453let Uses = [ICC], Defs = [ICC] in
Chris Lattner840c7002009-09-15 17:46:24 +0000454 def SUBXCCrr: F3_1<2, 0b011100,
455 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
456 "subxcc $b, $c, $dst", []>;
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000457
Chris Lattner158e1f52006-02-05 05:50:24 +0000458
459// Section B.18 - Multiply Instructions, p. 113
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000460let Defs = [Y] in {
461 defm UMUL : F3_12np<"umul", 0b001010>;
462 defm SMUL : F3_12 <"smul", 0b001011, mul>;
463}
Chris Lattnerc75d5b02006-02-09 05:06:36 +0000464
Chris Lattner158e1f52006-02-05 05:50:24 +0000465// Section B.19 - Divide Instructions, p. 115
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000466let Defs = [Y] in {
467 defm UDIV : F3_12np<"udiv", 0b001110>;
468 defm SDIV : F3_12np<"sdiv", 0b001111>;
469}
Chris Lattner158e1f52006-02-05 05:50:24 +0000470
471// Section B.20 - SAVE and RESTORE, p. 117
Chris Lattnerbad9d2e2006-09-01 22:28:02 +0000472defm SAVE : F3_12np<"save" , 0b111100>;
473defm RESTORE : F3_12np<"restore", 0b111101>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000474
475// Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
476
477// conditional branch class:
Evan Cheng94b5a802007-07-19 01:14:50 +0000478class BranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
479 : F2_2<cc, 0b010, (outs), ins, asmstr, pattern> {
Chris Lattner158e1f52006-02-05 05:50:24 +0000480 let isBranch = 1;
481 let isTerminator = 1;
482 let hasDelaySlot = 1;
Chris Lattner158e1f52006-02-05 05:50:24 +0000483}
484
485let isBarrier = 1 in
Evan Cheng94b5a802007-07-19 01:14:50 +0000486 def BA : BranchSP<0b1000, (ins brtarget:$dst),
Chris Lattner158e1f52006-02-05 05:50:24 +0000487 "ba $dst",
488 [(br bb:$dst)]>;
Chris Lattner840c7002009-09-15 17:46:24 +0000489
Chris Lattner158e1f52006-02-05 05:50:24 +0000490// FIXME: the encoding for the JIT should look at the condition field.
Chris Lattner840c7002009-09-15 17:46:24 +0000491let Uses = [ICC] in
492 def BCOND : BranchSP<0, (ins brtarget:$dst, CCOp:$cc),
493 "b$cc $dst",
494 [(SPbricc bb:$dst, imm:$cc)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000495
496
497// Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
498
499// floating-point conditional branch class:
Evan Cheng94b5a802007-07-19 01:14:50 +0000500class FPBranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
501 : F2_2<cc, 0b110, (outs), ins, asmstr, pattern> {
Chris Lattner158e1f52006-02-05 05:50:24 +0000502 let isBranch = 1;
503 let isTerminator = 1;
504 let hasDelaySlot = 1;
Chris Lattner158e1f52006-02-05 05:50:24 +0000505}
506
507// FIXME: the encoding for the JIT should look at the condition field.
Chris Lattner840c7002009-09-15 17:46:24 +0000508let Uses = [FCC] in
509 def FBCOND : FPBranchSP<0, (ins brtarget:$dst, CCOp:$cc),
510 "fb$cc $dst",
511 [(SPbrfcc bb:$dst, imm:$cc)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000512
513
514// Section B.24 - Call and Link Instruction, p. 125
515// This is the only Format 1 instruction
516let Uses = [O0, O1, O2, O3, O4, O5],
Evan Chengac1591b2007-07-21 00:34:19 +0000517 hasDelaySlot = 1, isCall = 1,
Chris Lattner158e1f52006-02-05 05:50:24 +0000518 Defs = [O0, O1, O2, O3, O4, O5, O7, G1, G2, G3, G4, G5, G6, G7,
519 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15] in {
Evan Cheng94b5a802007-07-19 01:14:50 +0000520 def CALL : InstSP<(outs), (ins calltarget:$dst),
Chris Lattner158e1f52006-02-05 05:50:24 +0000521 "call $dst", []> {
522 bits<30> disp;
523 let op = 1;
524 let Inst{29-0} = disp;
525 }
526
527 // indirect calls
528 def JMPLrr : F3_1<2, 0b111000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000529 (outs), (ins MEMrr:$ptr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000530 "call $ptr",
Chris Lattner8e9b8952010-03-18 23:57:57 +0000531 [(call ADDRrr:$ptr)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000532 def JMPLri : F3_2<2, 0b111000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000533 (outs), (ins MEMri:$ptr),
Chris Lattner158e1f52006-02-05 05:50:24 +0000534 "call $ptr",
Chris Lattner8e9b8952010-03-18 23:57:57 +0000535 [(call ADDRri:$ptr)]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000536}
537
538// Section B.28 - Read State Register Instructions
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000539let Uses = [Y] in
540 def RDY : F3_1<2, 0b101000,
541 (outs IntRegs:$dst), (ins),
542 "rd %y, $dst", []>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000543
544// Section B.29 - Write State Register Instructions
Venkatraman Govindaraju2f155032010-12-28 20:39:17 +0000545let Defs = [Y] in {
546 def WRYrr : F3_1<2, 0b110000,
547 (outs), (ins IntRegs:$b, IntRegs:$c),
548 "wr $b, $c, %y", []>;
549 def WRYri : F3_2<2, 0b110000,
550 (outs), (ins IntRegs:$b, i32imm:$c),
551 "wr $b, $c, %y", []>;
552}
Chris Lattner158e1f52006-02-05 05:50:24 +0000553// Convert Integer to Floating-point Instructions, p. 141
554def FITOS : F3_3<2, 0b110100, 0b011000100,
Evan Cheng94b5a802007-07-19 01:14:50 +0000555 (outs FPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000556 "fitos $src, $dst",
557 [(set FPRegs:$dst, (SPitof FPRegs:$src))]>;
558def FITOD : F3_3<2, 0b110100, 0b011001000,
Evan Cheng94b5a802007-07-19 01:14:50 +0000559 (outs DFPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000560 "fitod $src, $dst",
561 [(set DFPRegs:$dst, (SPitof FPRegs:$src))]>;
562
563// Convert Floating-point to Integer Instructions, p. 142
564def FSTOI : F3_3<2, 0b110100, 0b011010001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000565 (outs FPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000566 "fstoi $src, $dst",
567 [(set FPRegs:$dst, (SPftoi FPRegs:$src))]>;
568def FDTOI : F3_3<2, 0b110100, 0b011010010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000569 (outs FPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000570 "fdtoi $src, $dst",
571 [(set FPRegs:$dst, (SPftoi DFPRegs:$src))]>;
572
573// Convert between Floating-point Formats Instructions, p. 143
574def FSTOD : F3_3<2, 0b110100, 0b011001001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000575 (outs DFPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000576 "fstod $src, $dst",
577 [(set DFPRegs:$dst, (fextend FPRegs:$src))]>;
578def FDTOS : F3_3<2, 0b110100, 0b011000110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000579 (outs FPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000580 "fdtos $src, $dst",
581 [(set FPRegs:$dst, (fround DFPRegs:$src))]>;
582
583// Floating-point Move Instructions, p. 144
584def FMOVS : F3_3<2, 0b110100, 0b000000001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000585 (outs FPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000586 "fmovs $src, $dst", []>;
587def FNEGS : F3_3<2, 0b110100, 0b000000101,
Evan Cheng94b5a802007-07-19 01:14:50 +0000588 (outs FPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000589 "fnegs $src, $dst",
590 [(set FPRegs:$dst, (fneg FPRegs:$src))]>;
591def FABSS : F3_3<2, 0b110100, 0b000001001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000592 (outs FPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000593 "fabss $src, $dst",
594 [(set FPRegs:$dst, (fabs FPRegs:$src))]>;
595
596
597// Floating-point Square Root Instructions, p.145
598def FSQRTS : F3_3<2, 0b110100, 0b000101001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000599 (outs FPRegs:$dst), (ins FPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000600 "fsqrts $src, $dst",
601 [(set FPRegs:$dst, (fsqrt FPRegs:$src))]>;
602def FSQRTD : F3_3<2, 0b110100, 0b000101010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000603 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000604 "fsqrtd $src, $dst",
605 [(set DFPRegs:$dst, (fsqrt DFPRegs:$src))]>;
606
607
608
609// Floating-point Add and Subtract Instructions, p. 146
610def FADDS : F3_3<2, 0b110100, 0b001000001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000611 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000612 "fadds $src1, $src2, $dst",
613 [(set FPRegs:$dst, (fadd FPRegs:$src1, FPRegs:$src2))]>;
614def FADDD : F3_3<2, 0b110100, 0b001000010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000615 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000616 "faddd $src1, $src2, $dst",
617 [(set DFPRegs:$dst, (fadd DFPRegs:$src1, DFPRegs:$src2))]>;
618def FSUBS : F3_3<2, 0b110100, 0b001000101,
Evan Cheng94b5a802007-07-19 01:14:50 +0000619 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000620 "fsubs $src1, $src2, $dst",
621 [(set FPRegs:$dst, (fsub FPRegs:$src1, FPRegs:$src2))]>;
622def FSUBD : F3_3<2, 0b110100, 0b001000110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000623 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000624 "fsubd $src1, $src2, $dst",
625 [(set DFPRegs:$dst, (fsub DFPRegs:$src1, DFPRegs:$src2))]>;
626
627// Floating-point Multiply and Divide Instructions, p. 147
628def FMULS : F3_3<2, 0b110100, 0b001001001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000629 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000630 "fmuls $src1, $src2, $dst",
631 [(set FPRegs:$dst, (fmul FPRegs:$src1, FPRegs:$src2))]>;
632def FMULD : F3_3<2, 0b110100, 0b001001010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000633 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000634 "fmuld $src1, $src2, $dst",
635 [(set DFPRegs:$dst, (fmul DFPRegs:$src1, DFPRegs:$src2))]>;
636def FSMULD : F3_3<2, 0b110100, 0b001101001,
Evan Cheng94b5a802007-07-19 01:14:50 +0000637 (outs DFPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000638 "fsmuld $src1, $src2, $dst",
639 [(set DFPRegs:$dst, (fmul (fextend FPRegs:$src1),
640 (fextend FPRegs:$src2)))]>;
641def FDIVS : F3_3<2, 0b110100, 0b001001101,
Evan Cheng94b5a802007-07-19 01:14:50 +0000642 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000643 "fdivs $src1, $src2, $dst",
644 [(set FPRegs:$dst, (fdiv FPRegs:$src1, FPRegs:$src2))]>;
645def FDIVD : F3_3<2, 0b110100, 0b001001110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000646 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Chris Lattner158e1f52006-02-05 05:50:24 +0000647 "fdivd $src1, $src2, $dst",
648 [(set DFPRegs:$dst, (fdiv DFPRegs:$src1, DFPRegs:$src2))]>;
649
650// Floating-point Compare Instructions, p. 148
651// Note: the 2nd template arg is different for these guys.
652// Note 2: the result of a FCMP is not available until the 2nd cycle
653// after the instr is retired, but there is no interlock. This behavior
654// is modelled with a forced noop after the instruction.
Chris Lattner840c7002009-09-15 17:46:24 +0000655let Defs = [FCC] in {
656 def FCMPS : F3_3<2, 0b110101, 0b001010001,
657 (outs), (ins FPRegs:$src1, FPRegs:$src2),
658 "fcmps $src1, $src2\n\tnop",
659 [(SPcmpfcc FPRegs:$src1, FPRegs:$src2)]>;
660 def FCMPD : F3_3<2, 0b110101, 0b001010010,
661 (outs), (ins DFPRegs:$src1, DFPRegs:$src2),
662 "fcmpd $src1, $src2\n\tnop",
663 [(SPcmpfcc DFPRegs:$src1, DFPRegs:$src2)]>;
664}
Chris Lattner158e1f52006-02-05 05:50:24 +0000665
666//===----------------------------------------------------------------------===//
667// V9 Instructions
668//===----------------------------------------------------------------------===//
669
670// V9 Conditional Moves.
Eric Christopherd7a73562010-06-21 20:22:35 +0000671let Predicates = [HasV9], Constraints = "$T = $dst" in {
Chris Lattner158e1f52006-02-05 05:50:24 +0000672 // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
673 // FIXME: Add instruction encodings for the JIT some day.
674 def MOVICCrr
Evan Cheng94b5a802007-07-19 01:14:50 +0000675 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000676 "mov$cc %icc, $F, $dst",
677 [(set IntRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000678 (SPselecticc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000679 def MOVICCri
Evan Cheng94b5a802007-07-19 01:14:50 +0000680 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000681 "mov$cc %icc, $F, $dst",
682 [(set IntRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000683 (SPselecticc simm11:$F, IntRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000684
685 def MOVFCCrr
Evan Cheng94b5a802007-07-19 01:14:50 +0000686 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000687 "mov$cc %fcc0, $F, $dst",
688 [(set IntRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000689 (SPselectfcc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000690 def MOVFCCri
Evan Cheng94b5a802007-07-19 01:14:50 +0000691 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000692 "mov$cc %fcc0, $F, $dst",
693 [(set IntRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000694 (SPselectfcc simm11:$F, IntRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000695
696 def FMOVS_ICC
Evan Cheng94b5a802007-07-19 01:14:50 +0000697 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000698 "fmovs$cc %icc, $F, $dst",
699 [(set FPRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000700 (SPselecticc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000701 def FMOVD_ICC
Evan Cheng94b5a802007-07-19 01:14:50 +0000702 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000703 "fmovd$cc %icc, $F, $dst",
704 [(set DFPRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000705 (SPselecticc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000706 def FMOVS_FCC
Evan Cheng94b5a802007-07-19 01:14:50 +0000707 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000708 "fmovs$cc %fcc0, $F, $dst",
709 [(set FPRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000710 (SPselectfcc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000711 def FMOVD_FCC
Evan Cheng94b5a802007-07-19 01:14:50 +0000712 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
Chris Lattner158e1f52006-02-05 05:50:24 +0000713 "fmovd$cc %fcc0, $F, $dst",
714 [(set DFPRegs:$dst,
Chris Lattner0c4dea42006-02-10 06:58:25 +0000715 (SPselectfcc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000716
717}
718
719// Floating-Point Move Instructions, p. 164 of the V9 manual.
720let Predicates = [HasV9] in {
721 def FMOVD : F3_3<2, 0b110100, 0b000000010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000722 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000723 "fmovd $src, $dst", []>;
724 def FNEGD : F3_3<2, 0b110100, 0b000000110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000725 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000726 "fnegd $src, $dst",
727 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
728 def FABSD : F3_3<2, 0b110100, 0b000001010,
Evan Cheng94b5a802007-07-19 01:14:50 +0000729 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000730 "fabsd $src, $dst",
731 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
732}
733
734// POPCrr - This does a ctpop of a 64-bit register. As such, we have to clear
735// the top 32-bits before using it. To do this clearing, we use a SLLri X,0.
736def POPCrr : F3_1<2, 0b101110,
Evan Cheng94b5a802007-07-19 01:14:50 +0000737 (outs IntRegs:$dst), (ins IntRegs:$src),
Chris Lattner158e1f52006-02-05 05:50:24 +0000738 "popc $src, $dst", []>, Requires<[HasV9]>;
739def : Pat<(ctpop IntRegs:$src),
740 (POPCrr (SLLri IntRegs:$src, 0))>;
741
742//===----------------------------------------------------------------------===//
743// Non-Instruction Patterns
744//===----------------------------------------------------------------------===//
745
746// Small immediates.
747def : Pat<(i32 simm13:$val),
748 (ORri G0, imm:$val)>;
749// Arbitrary immediates.
750def : Pat<(i32 imm:$val),
751 (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
752
Nate Begeman5965bd12006-02-17 05:43:56 +0000753// subc
754def : Pat<(subc IntRegs:$b, IntRegs:$c),
755 (SUBCCrr IntRegs:$b, IntRegs:$c)>;
756def : Pat<(subc IntRegs:$b, simm13:$val),
757 (SUBCCri IntRegs:$b, imm:$val)>;
758
Chris Lattner158e1f52006-02-05 05:50:24 +0000759// Global addresses, constant pool entries
760def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
761def : Pat<(SPlo tglobaladdr:$in), (ORri G0, tglobaladdr:$in)>;
762def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
763def : Pat<(SPlo tconstpool:$in), (ORri G0, tconstpool:$in)>;
764
765// Add reg, lo. This is used when taking the addr of a global/constpool entry.
766def : Pat<(add IntRegs:$r, (SPlo tglobaladdr:$in)),
767 (ADDri IntRegs:$r, tglobaladdr:$in)>;
768def : Pat<(add IntRegs:$r, (SPlo tconstpool:$in)),
769 (ADDri IntRegs:$r, tconstpool:$in)>;
770
Chris Lattner158e1f52006-02-05 05:50:24 +0000771// Calls:
772def : Pat<(call tglobaladdr:$dst),
773 (CALL tglobaladdr:$dst)>;
Chris Lattnerfcb8a3a2006-02-10 07:35:42 +0000774def : Pat<(call texternalsym:$dst),
775 (CALL texternalsym:$dst)>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000776
Chris Lattner158e1f52006-02-05 05:50:24 +0000777// Map integer extload's to zextloads.
Evan Chenge71fe34d2006-10-09 20:57:25 +0000778def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
779def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
780def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
781def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
782def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
783def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
Chris Lattner158e1f52006-02-05 05:50:24 +0000784
785// zextload bool -> zextload byte
Evan Chenge71fe34d2006-10-09 20:57:25 +0000786def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
787def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;