blob: c41c191a5d88128fe31fcede29d61cb1b2ae1e43 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- SparcInstrInfo.td - Target Description for Sparc 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 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
46def simm11 : PatLeaf<(imm), [{
47 // simm11 predicate - True if the imm fits in a 11-bit sign extended field.
48 return (((int)N->getValue() << (32-11)) >> (32-11)) == (int)N->getValue();
49}]>;
50
51def simm13 : PatLeaf<(imm), [{
52 // simm13 predicate - True if the imm fits in a 13-bit sign extended field.
53 return (((int)N->getValue() << (32-13)) >> (32-13)) == (int)N->getValue();
54}]>;
55
56def LO10 : SDNodeXForm<imm, [{
57 return CurDAG->getTargetConstant((unsigned)N->getValue() & 1023, MVT::i32);
58}]>;
59
60def HI22 : SDNodeXForm<imm, [{
61 // Transformation function: shift the immediate value down into the low bits.
62 return CurDAG->getTargetConstant((unsigned)N->getValue() >> 10, MVT::i32);
63}]>;
64
65def SETHIimm : PatLeaf<(imm), [{
66 return (((unsigned)N->getValue() >> 10) << 10) == (unsigned)N->getValue();
67}], HI22>;
68
69// Addressing modes.
70def ADDRrr : ComplexPattern<i32, 2, "SelectADDRrr", [], []>;
71def ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [frameindex], []>;
72
73// Address operands
74def MEMrr : Operand<i32> {
75 let PrintMethod = "printMemOperand";
76 let MIOperandInfo = (ops IntRegs, IntRegs);
77}
78def MEMri : Operand<i32> {
79 let PrintMethod = "printMemOperand";
80 let MIOperandInfo = (ops IntRegs, i32imm);
81}
82
83// Branch targets have OtherVT type.
84def brtarget : Operand<OtherVT>;
85def calltarget : Operand<i32>;
86
87// Operand for printing out a condition code.
88let PrintMethod = "printCCOperand" in
89 def CCOp : Operand<i32>;
90
91def SDTSPcmpfcc :
92SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
93def SDTSPbrcc :
94SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
95def SDTSPselectcc :
96SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
97def SDTSPFTOI :
98SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
99def SDTSPITOF :
100SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
101
102def SPcmpicc : SDNode<"SPISD::CMPICC", SDTIntBinOp, [SDNPOutFlag]>;
103def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutFlag]>;
104def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInFlag]>;
105def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInFlag]>;
106
107def SPhi : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
108def SPlo : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
109
110def SPftoi : SDNode<"SPISD::FTOI", SDTSPFTOI>;
111def SPitof : SDNode<"SPISD::ITOF", SDTSPITOF>;
112
113def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInFlag]>;
114def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInFlag]>;
115
116// These are target-independent nodes, but have target-specific formats.
117def SDT_SPCallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, i32> ]>;
118def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeq,
119 [SDNPHasChain, SDNPOutFlag]>;
120def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeq,
121 [SDNPHasChain, SDNPOutFlag]>;
122
123def SDT_SPCall : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
124def call : SDNode<"SPISD::CALL", SDT_SPCall,
125 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
126
127def SDT_SPRetFlag : SDTypeProfile<0, 0, []>;
128def retflag : SDNode<"SPISD::RET_FLAG", SDT_SPRetFlag,
129 [SDNPHasChain, SDNPOptInFlag]>;
130
131//===----------------------------------------------------------------------===//
132// SPARC Flag Conditions
133//===----------------------------------------------------------------------===//
134
135// Note that these values must be kept in sync with the CCOp::CondCode enum
136// values.
137class ICC_VAL<int N> : PatLeaf<(i32 N)>;
138def ICC_NE : ICC_VAL< 9>; // Not Equal
139def ICC_E : ICC_VAL< 1>; // Equal
140def ICC_G : ICC_VAL<10>; // Greater
141def ICC_LE : ICC_VAL< 2>; // Less or Equal
142def ICC_GE : ICC_VAL<11>; // Greater or Equal
143def ICC_L : ICC_VAL< 3>; // Less
144def ICC_GU : ICC_VAL<12>; // Greater Unsigned
145def ICC_LEU : ICC_VAL< 4>; // Less or Equal Unsigned
146def ICC_CC : ICC_VAL<13>; // Carry Clear/Great or Equal Unsigned
147def ICC_CS : ICC_VAL< 5>; // Carry Set/Less Unsigned
148def ICC_POS : ICC_VAL<14>; // Positive
149def ICC_NEG : ICC_VAL< 6>; // Negative
150def ICC_VC : ICC_VAL<15>; // Overflow Clear
151def ICC_VS : ICC_VAL< 7>; // Overflow Set
152
153class FCC_VAL<int N> : PatLeaf<(i32 N)>;
154def FCC_U : FCC_VAL<23>; // Unordered
155def FCC_G : FCC_VAL<22>; // Greater
156def FCC_UG : FCC_VAL<21>; // Unordered or Greater
157def FCC_L : FCC_VAL<20>; // Less
158def FCC_UL : FCC_VAL<19>; // Unordered or Less
159def FCC_LG : FCC_VAL<18>; // Less or Greater
160def FCC_NE : FCC_VAL<17>; // Not Equal
161def FCC_E : FCC_VAL<25>; // Equal
162def FCC_UE : FCC_VAL<24>; // Unordered or Equal
163def FCC_GE : FCC_VAL<25>; // Greater or Equal
164def FCC_UGE : FCC_VAL<26>; // Unordered or Greater or Equal
165def FCC_LE : FCC_VAL<27>; // Less or Equal
166def FCC_ULE : FCC_VAL<28>; // Unordered or Less or Equal
167def FCC_O : FCC_VAL<29>; // Ordered
168
169//===----------------------------------------------------------------------===//
170// Instruction Class Templates
171//===----------------------------------------------------------------------===//
172
173/// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
174multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode> {
175 def rr : F3_1<2, Op3Val,
Evan Chengb783fa32007-07-19 01:14:50 +0000176 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000177 !strconcat(OpcStr, " $b, $c, $dst"),
178 [(set IntRegs:$dst, (OpNode IntRegs:$b, IntRegs:$c))]>;
179 def ri : F3_2<2, Op3Val,
Evan Chengb783fa32007-07-19 01:14:50 +0000180 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181 !strconcat(OpcStr, " $b, $c, $dst"),
182 [(set IntRegs:$dst, (OpNode IntRegs:$b, simm13:$c))]>;
183}
184
185/// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
186/// pattern.
187multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
188 def rr : F3_1<2, Op3Val,
Evan Chengb783fa32007-07-19 01:14:50 +0000189 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190 !strconcat(OpcStr, " $b, $c, $dst"), []>;
191 def ri : F3_2<2, Op3Val,
Evan Chengb783fa32007-07-19 01:14:50 +0000192 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193 !strconcat(OpcStr, " $b, $c, $dst"), []>;
194}
195
196//===----------------------------------------------------------------------===//
197// Instructions
198//===----------------------------------------------------------------------===//
199
200// Pseudo instructions.
Evan Chengb783fa32007-07-19 01:14:50 +0000201class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
202 : InstSP<outs, ins, asmstr, pattern>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000204let Defs = [O6], Uses = [O6] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000205def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206 "!ADJCALLSTACKDOWN $amt",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000207 [(callseq_start imm:$amt)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000208def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209 "!ADJCALLSTACKUP $amt",
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000210 [(callseq_end imm:$amt)]>;
211}
Evan Chengb783fa32007-07-19 01:14:50 +0000212def IMPLICIT_DEF_Int : Pseudo<(outs IntRegs:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213 "!IMPLICIT_DEF $dst",
214 [(set IntRegs:$dst, (undef))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000215def IMPLICIT_DEF_FP : Pseudo<(outs FPRegs:$dst), (ins), "!IMPLICIT_DEF $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216 [(set FPRegs:$dst, (undef))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000217def IMPLICIT_DEF_DFP : Pseudo<(outs DFPRegs:$dst), (ins), "!IMPLICIT_DEF $dst",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218 [(set DFPRegs:$dst, (undef))]>;
219
220// FpMOVD/FpNEGD/FpABSD - These are lowered to single-precision ops by the
221// fpmover pass.
222let Predicates = [HasNoV9] in { // Only emit these in V8 mode.
Evan Chengb783fa32007-07-19 01:14:50 +0000223 def FpMOVD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224 "!FpMOVD $src, $dst", []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000225 def FpNEGD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000226 "!FpNEGD $src, $dst",
227 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000228 def FpABSD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000229 "!FpABSD $src, $dst",
230 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
231}
232
233// SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded by the
234// scheduler into a branch sequence. This has to handle all permutations of
235// selection between i32/f32/f64 on ICC and FCC.
236let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
237 def SELECT_CC_Int_ICC
Evan Chengb783fa32007-07-19 01:14:50 +0000238 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000239 "; SELECT_CC_Int_ICC PSEUDO!",
240 [(set IntRegs:$dst, (SPselecticc IntRegs:$T, IntRegs:$F,
241 imm:$Cond))]>;
242 def SELECT_CC_Int_FCC
Evan Chengb783fa32007-07-19 01:14:50 +0000243 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244 "; SELECT_CC_Int_FCC PSEUDO!",
245 [(set IntRegs:$dst, (SPselectfcc IntRegs:$T, IntRegs:$F,
246 imm:$Cond))]>;
247 def SELECT_CC_FP_ICC
Evan Chengb783fa32007-07-19 01:14:50 +0000248 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000249 "; SELECT_CC_FP_ICC PSEUDO!",
250 [(set FPRegs:$dst, (SPselecticc FPRegs:$T, FPRegs:$F,
251 imm:$Cond))]>;
252 def SELECT_CC_FP_FCC
Evan Chengb783fa32007-07-19 01:14:50 +0000253 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 "; SELECT_CC_FP_FCC PSEUDO!",
255 [(set FPRegs:$dst, (SPselectfcc FPRegs:$T, FPRegs:$F,
256 imm:$Cond))]>;
257 def SELECT_CC_DFP_ICC
Evan Chengb783fa32007-07-19 01:14:50 +0000258 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 "; SELECT_CC_DFP_ICC PSEUDO!",
260 [(set DFPRegs:$dst, (SPselecticc DFPRegs:$T, DFPRegs:$F,
261 imm:$Cond))]>;
262 def SELECT_CC_DFP_FCC
Evan Chengb783fa32007-07-19 01:14:50 +0000263 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264 "; SELECT_CC_DFP_FCC PSEUDO!",
265 [(set DFPRegs:$dst, (SPselectfcc DFPRegs:$T, DFPRegs:$F,
266 imm:$Cond))]>;
267}
268
269
270// Section A.3 - Synthetic Instructions, p. 85
271// special cases of JMPL:
Evan Cheng37e7c752007-07-21 00:34:19 +0000272let isReturn = 1, isTerminator = 1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000273 let rd = O7.Num, rs1 = G0.Num, simm13 = 8 in
Evan Chengb783fa32007-07-19 01:14:50 +0000274 def RETL: F3_2<2, 0b111000, (outs), (ins), "retl", [(retflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000275}
276
277// Section B.1 - Load Integer Instructions, p. 90
278def LDSBrr : F3_1<3, 0b001001,
Evan Chengb783fa32007-07-19 01:14:50 +0000279 (outs IntRegs:$dst), (ins MEMrr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280 "ldsb [$addr], $dst",
281 [(set IntRegs:$dst, (sextloadi8 ADDRrr:$addr))]>;
282def LDSBri : F3_2<3, 0b001001,
Evan Chengb783fa32007-07-19 01:14:50 +0000283 (outs IntRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 "ldsb [$addr], $dst",
285 [(set IntRegs:$dst, (sextloadi8 ADDRri:$addr))]>;
286def LDSHrr : F3_1<3, 0b001010,
Evan Chengb783fa32007-07-19 01:14:50 +0000287 (outs IntRegs:$dst), (ins MEMrr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 "ldsh [$addr], $dst",
289 [(set IntRegs:$dst, (sextloadi16 ADDRrr:$addr))]>;
290def LDSHri : F3_2<3, 0b001010,
Evan Chengb783fa32007-07-19 01:14:50 +0000291 (outs IntRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 "ldsh [$addr], $dst",
293 [(set IntRegs:$dst, (sextloadi16 ADDRri:$addr))]>;
294def LDUBrr : F3_1<3, 0b000001,
Evan Chengb783fa32007-07-19 01:14:50 +0000295 (outs IntRegs:$dst), (ins MEMrr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296 "ldub [$addr], $dst",
297 [(set IntRegs:$dst, (zextloadi8 ADDRrr:$addr))]>;
298def LDUBri : F3_2<3, 0b000001,
Evan Chengb783fa32007-07-19 01:14:50 +0000299 (outs IntRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000300 "ldub [$addr], $dst",
301 [(set IntRegs:$dst, (zextloadi8 ADDRri:$addr))]>;
302def LDUHrr : F3_1<3, 0b000010,
Evan Chengb783fa32007-07-19 01:14:50 +0000303 (outs IntRegs:$dst), (ins MEMrr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304 "lduh [$addr], $dst",
305 [(set IntRegs:$dst, (zextloadi16 ADDRrr:$addr))]>;
306def LDUHri : F3_2<3, 0b000010,
Evan Chengb783fa32007-07-19 01:14:50 +0000307 (outs IntRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308 "lduh [$addr], $dst",
309 [(set IntRegs:$dst, (zextloadi16 ADDRri:$addr))]>;
310def LDrr : F3_1<3, 0b000000,
Evan Chengb783fa32007-07-19 01:14:50 +0000311 (outs IntRegs:$dst), (ins MEMrr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 "ld [$addr], $dst",
313 [(set IntRegs:$dst, (load ADDRrr:$addr))]>;
314def LDri : F3_2<3, 0b000000,
Evan Chengb783fa32007-07-19 01:14:50 +0000315 (outs IntRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316 "ld [$addr], $dst",
317 [(set IntRegs:$dst, (load ADDRri:$addr))]>;
318
319// Section B.2 - Load Floating-point Instructions, p. 92
320def LDFrr : F3_1<3, 0b100000,
Evan Chengb783fa32007-07-19 01:14:50 +0000321 (outs FPRegs:$dst), (ins MEMrr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322 "ld [$addr], $dst",
323 [(set FPRegs:$dst, (load ADDRrr:$addr))]>;
324def LDFri : F3_2<3, 0b100000,
Evan Chengb783fa32007-07-19 01:14:50 +0000325 (outs FPRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326 "ld [$addr], $dst",
327 [(set FPRegs:$dst, (load ADDRri:$addr))]>;
328def LDDFrr : F3_1<3, 0b100011,
Evan Chengb783fa32007-07-19 01:14:50 +0000329 (outs DFPRegs:$dst), (ins MEMrr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330 "ldd [$addr], $dst",
331 [(set DFPRegs:$dst, (load ADDRrr:$addr))]>;
332def LDDFri : F3_2<3, 0b100011,
Evan Chengb783fa32007-07-19 01:14:50 +0000333 (outs DFPRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 "ldd [$addr], $dst",
335 [(set DFPRegs:$dst, (load ADDRri:$addr))]>;
336
337// Section B.4 - Store Integer Instructions, p. 95
338def STBrr : F3_1<3, 0b000101,
Evan Chengb783fa32007-07-19 01:14:50 +0000339 (outs), (ins MEMrr:$addr, IntRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 "stb $src, [$addr]",
341 [(truncstorei8 IntRegs:$src, ADDRrr:$addr)]>;
342def STBri : F3_2<3, 0b000101,
Evan Chengb783fa32007-07-19 01:14:50 +0000343 (outs), (ins MEMri:$addr, IntRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000344 "stb $src, [$addr]",
345 [(truncstorei8 IntRegs:$src, ADDRri:$addr)]>;
346def STHrr : F3_1<3, 0b000110,
Evan Chengb783fa32007-07-19 01:14:50 +0000347 (outs), (ins MEMrr:$addr, IntRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348 "sth $src, [$addr]",
349 [(truncstorei16 IntRegs:$src, ADDRrr:$addr)]>;
350def STHri : F3_2<3, 0b000110,
Evan Chengb783fa32007-07-19 01:14:50 +0000351 (outs), (ins MEMri:$addr, IntRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 "sth $src, [$addr]",
353 [(truncstorei16 IntRegs:$src, ADDRri:$addr)]>;
354def STrr : F3_1<3, 0b000100,
Evan Chengb783fa32007-07-19 01:14:50 +0000355 (outs), (ins MEMrr:$addr, IntRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356 "st $src, [$addr]",
357 [(store IntRegs:$src, ADDRrr:$addr)]>;
358def STri : F3_2<3, 0b000100,
Evan Chengb783fa32007-07-19 01:14:50 +0000359 (outs), (ins MEMri:$addr, IntRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 "st $src, [$addr]",
361 [(store IntRegs:$src, ADDRri:$addr)]>;
362
363// Section B.5 - Store Floating-point Instructions, p. 97
364def STFrr : F3_1<3, 0b100100,
Evan Chengb783fa32007-07-19 01:14:50 +0000365 (outs), (ins MEMrr:$addr, FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366 "st $src, [$addr]",
367 [(store FPRegs:$src, ADDRrr:$addr)]>;
368def STFri : F3_2<3, 0b100100,
Evan Chengb783fa32007-07-19 01:14:50 +0000369 (outs), (ins MEMri:$addr, FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370 "st $src, [$addr]",
371 [(store FPRegs:$src, ADDRri:$addr)]>;
372def STDFrr : F3_1<3, 0b100111,
Evan Chengb783fa32007-07-19 01:14:50 +0000373 (outs), (ins MEMrr:$addr, DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374 "std $src, [$addr]",
375 [(store DFPRegs:$src, ADDRrr:$addr)]>;
376def STDFri : F3_2<3, 0b100111,
Evan Chengb783fa32007-07-19 01:14:50 +0000377 (outs), (ins MEMri:$addr, DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000378 "std $src, [$addr]",
379 [(store DFPRegs:$src, ADDRri:$addr)]>;
380
381// Section B.9 - SETHI Instruction, p. 104
382def SETHIi: F2_1<0b100,
Evan Chengb783fa32007-07-19 01:14:50 +0000383 (outs IntRegs:$dst), (ins i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384 "sethi $src, $dst",
385 [(set IntRegs:$dst, SETHIimm:$src)]>;
386
387// Section B.10 - NOP Instruction, p. 105
388// (It's a special case of SETHI)
389let rd = 0, imm22 = 0 in
Evan Chengb783fa32007-07-19 01:14:50 +0000390 def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391
392// Section B.11 - Logical Instructions, p. 106
393defm AND : F3_12<"and", 0b000001, and>;
394
395def ANDNrr : F3_1<2, 0b000101,
Evan Chengb783fa32007-07-19 01:14:50 +0000396 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 "andn $b, $c, $dst",
398 [(set IntRegs:$dst, (and IntRegs:$b, (not IntRegs:$c)))]>;
399def ANDNri : F3_2<2, 0b000101,
Evan Chengb783fa32007-07-19 01:14:50 +0000400 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401 "andn $b, $c, $dst", []>;
402
403defm OR : F3_12<"or", 0b000010, or>;
404
405def ORNrr : F3_1<2, 0b000110,
Evan Chengb783fa32007-07-19 01:14:50 +0000406 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000407 "orn $b, $c, $dst",
408 [(set IntRegs:$dst, (or IntRegs:$b, (not IntRegs:$c)))]>;
409def ORNri : F3_2<2, 0b000110,
Evan Chengb783fa32007-07-19 01:14:50 +0000410 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411 "orn $b, $c, $dst", []>;
412defm XOR : F3_12<"xor", 0b000011, xor>;
413
414def XNORrr : F3_1<2, 0b000111,
Evan Chengb783fa32007-07-19 01:14:50 +0000415 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416 "xnor $b, $c, $dst",
417 [(set IntRegs:$dst, (not (xor IntRegs:$b, IntRegs:$c)))]>;
418def XNORri : F3_2<2, 0b000111,
Evan Chengb783fa32007-07-19 01:14:50 +0000419 (outs IntRegs:$dst), (ins IntRegs:$b, i32imm:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420 "xnor $b, $c, $dst", []>;
421
422// Section B.12 - Shift Instructions, p. 107
423defm SLL : F3_12<"sll", 0b100101, shl>;
424defm SRL : F3_12<"srl", 0b100110, srl>;
425defm SRA : F3_12<"sra", 0b100111, sra>;
426
427// Section B.13 - Add Instructions, p. 108
428defm ADD : F3_12<"add", 0b000000, add>;
429
430// "LEA" forms of add (patterns to make tblgen happy)
431def LEA_ADDri : F3_2<2, 0b000000,
Evan Chengb783fa32007-07-19 01:14:50 +0000432 (outs IntRegs:$dst), (ins MEMri:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000433 "add ${addr:arith}, $dst",
434 [(set IntRegs:$dst, ADDRri:$addr)]>;
435
436defm ADDCC : F3_12<"addcc", 0b010000, addc>;
437defm ADDX : F3_12<"addx", 0b001000, adde>;
438
439// Section B.15 - Subtract Instructions, p. 110
440defm SUB : F3_12 <"sub" , 0b000100, sub>;
441defm SUBX : F3_12 <"subx" , 0b001100, sube>;
442defm SUBCC : F3_12 <"subcc", 0b010100, SPcmpicc>;
443
444def SUBXCCrr: F3_1<2, 0b011100,
Evan Chengb783fa32007-07-19 01:14:50 +0000445 (outs IntRegs:$dst), (ins IntRegs:$b, IntRegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446 "subxcc $b, $c, $dst", []>;
447
448// Section B.18 - Multiply Instructions, p. 113
449defm UMUL : F3_12np<"umul", 0b001010>;
450defm SMUL : F3_12 <"smul", 0b001011, mul>;
451
452
453// Section B.19 - Divide Instructions, p. 115
454defm UDIV : F3_12np<"udiv", 0b001110>;
455defm SDIV : F3_12np<"sdiv", 0b001111>;
456
457// Section B.20 - SAVE and RESTORE, p. 117
458defm SAVE : F3_12np<"save" , 0b111100>;
459defm RESTORE : F3_12np<"restore", 0b111101>;
460
461// Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
462
463// conditional branch class:
Evan Chengb783fa32007-07-19 01:14:50 +0000464class BranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
465 : F2_2<cc, 0b010, (outs), ins, asmstr, pattern> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466 let isBranch = 1;
467 let isTerminator = 1;
468 let hasDelaySlot = 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469}
470
471let isBarrier = 1 in
Evan Chengb783fa32007-07-19 01:14:50 +0000472 def BA : BranchSP<0b1000, (ins brtarget:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 "ba $dst",
474 [(br bb:$dst)]>;
475
476// FIXME: the encoding for the JIT should look at the condition field.
Evan Chengb783fa32007-07-19 01:14:50 +0000477def BCOND : BranchSP<0, (ins brtarget:$dst, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000478 "b$cc $dst",
479 [(SPbricc bb:$dst, imm:$cc)]>;
480
481
482// Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
483
484// floating-point conditional branch class:
Evan Chengb783fa32007-07-19 01:14:50 +0000485class FPBranchSP<bits<4> cc, dag ins, string asmstr, list<dag> pattern>
486 : F2_2<cc, 0b110, (outs), ins, asmstr, pattern> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487 let isBranch = 1;
488 let isTerminator = 1;
489 let hasDelaySlot = 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490}
491
492// FIXME: the encoding for the JIT should look at the condition field.
Evan Chengb783fa32007-07-19 01:14:50 +0000493def FBCOND : FPBranchSP<0, (ins brtarget:$dst, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000494 "fb$cc $dst",
495 [(SPbrfcc bb:$dst, imm:$cc)]>;
496
497
498// Section B.24 - Call and Link Instruction, p. 125
499// This is the only Format 1 instruction
500let Uses = [O0, O1, O2, O3, O4, O5],
Evan Cheng37e7c752007-07-21 00:34:19 +0000501 hasDelaySlot = 1, isCall = 1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 Defs = [O0, O1, O2, O3, O4, O5, O7, G1, G2, G3, G4, G5, G6, G7,
503 D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15] in {
Evan Chengb783fa32007-07-19 01:14:50 +0000504 def CALL : InstSP<(outs), (ins calltarget:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505 "call $dst", []> {
506 bits<30> disp;
507 let op = 1;
508 let Inst{29-0} = disp;
509 }
510
511 // indirect calls
512 def JMPLrr : F3_1<2, 0b111000,
Evan Chengb783fa32007-07-19 01:14:50 +0000513 (outs), (ins MEMrr:$ptr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000514 "call $ptr",
515 [(call ADDRrr:$ptr)]>;
516 def JMPLri : F3_2<2, 0b111000,
Evan Chengb783fa32007-07-19 01:14:50 +0000517 (outs), (ins MEMri:$ptr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518 "call $ptr",
519 [(call ADDRri:$ptr)]>;
520}
521
522// Section B.28 - Read State Register Instructions
523def RDY : F3_1<2, 0b101000,
Evan Chengb783fa32007-07-19 01:14:50 +0000524 (outs IntRegs:$dst), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525 "rd %y, $dst", []>;
526
527// Section B.29 - Write State Register Instructions
528def WRYrr : F3_1<2, 0b110000,
Evan Chengb783fa32007-07-19 01:14:50 +0000529 (outs), (ins IntRegs:$b, IntRegs:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530 "wr $b, $c, %y", []>;
531def WRYri : F3_2<2, 0b110000,
Evan Chengb783fa32007-07-19 01:14:50 +0000532 (outs), (ins IntRegs:$b, i32imm:$c),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533 "wr $b, $c, %y", []>;
534
535// Convert Integer to Floating-point Instructions, p. 141
536def FITOS : F3_3<2, 0b110100, 0b011000100,
Evan Chengb783fa32007-07-19 01:14:50 +0000537 (outs FPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000538 "fitos $src, $dst",
539 [(set FPRegs:$dst, (SPitof FPRegs:$src))]>;
540def FITOD : F3_3<2, 0b110100, 0b011001000,
Evan Chengb783fa32007-07-19 01:14:50 +0000541 (outs DFPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542 "fitod $src, $dst",
543 [(set DFPRegs:$dst, (SPitof FPRegs:$src))]>;
544
545// Convert Floating-point to Integer Instructions, p. 142
546def FSTOI : F3_3<2, 0b110100, 0b011010001,
Evan Chengb783fa32007-07-19 01:14:50 +0000547 (outs FPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548 "fstoi $src, $dst",
549 [(set FPRegs:$dst, (SPftoi FPRegs:$src))]>;
550def FDTOI : F3_3<2, 0b110100, 0b011010010,
Evan Chengb783fa32007-07-19 01:14:50 +0000551 (outs FPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000552 "fdtoi $src, $dst",
553 [(set FPRegs:$dst, (SPftoi DFPRegs:$src))]>;
554
555// Convert between Floating-point Formats Instructions, p. 143
556def FSTOD : F3_3<2, 0b110100, 0b011001001,
Evan Chengb783fa32007-07-19 01:14:50 +0000557 (outs DFPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558 "fstod $src, $dst",
559 [(set DFPRegs:$dst, (fextend FPRegs:$src))]>;
560def FDTOS : F3_3<2, 0b110100, 0b011000110,
Evan Chengb783fa32007-07-19 01:14:50 +0000561 (outs FPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562 "fdtos $src, $dst",
563 [(set FPRegs:$dst, (fround DFPRegs:$src))]>;
564
565// Floating-point Move Instructions, p. 144
566def FMOVS : F3_3<2, 0b110100, 0b000000001,
Evan Chengb783fa32007-07-19 01:14:50 +0000567 (outs FPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 "fmovs $src, $dst", []>;
569def FNEGS : F3_3<2, 0b110100, 0b000000101,
Evan Chengb783fa32007-07-19 01:14:50 +0000570 (outs FPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571 "fnegs $src, $dst",
572 [(set FPRegs:$dst, (fneg FPRegs:$src))]>;
573def FABSS : F3_3<2, 0b110100, 0b000001001,
Evan Chengb783fa32007-07-19 01:14:50 +0000574 (outs FPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575 "fabss $src, $dst",
576 [(set FPRegs:$dst, (fabs FPRegs:$src))]>;
577
578
579// Floating-point Square Root Instructions, p.145
580def FSQRTS : F3_3<2, 0b110100, 0b000101001,
Evan Chengb783fa32007-07-19 01:14:50 +0000581 (outs FPRegs:$dst), (ins FPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582 "fsqrts $src, $dst",
583 [(set FPRegs:$dst, (fsqrt FPRegs:$src))]>;
584def FSQRTD : F3_3<2, 0b110100, 0b000101010,
Evan Chengb783fa32007-07-19 01:14:50 +0000585 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000586 "fsqrtd $src, $dst",
587 [(set DFPRegs:$dst, (fsqrt DFPRegs:$src))]>;
588
589
590
591// Floating-point Add and Subtract Instructions, p. 146
592def FADDS : F3_3<2, 0b110100, 0b001000001,
Evan Chengb783fa32007-07-19 01:14:50 +0000593 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000594 "fadds $src1, $src2, $dst",
595 [(set FPRegs:$dst, (fadd FPRegs:$src1, FPRegs:$src2))]>;
596def FADDD : F3_3<2, 0b110100, 0b001000010,
Evan Chengb783fa32007-07-19 01:14:50 +0000597 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598 "faddd $src1, $src2, $dst",
599 [(set DFPRegs:$dst, (fadd DFPRegs:$src1, DFPRegs:$src2))]>;
600def FSUBS : F3_3<2, 0b110100, 0b001000101,
Evan Chengb783fa32007-07-19 01:14:50 +0000601 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602 "fsubs $src1, $src2, $dst",
603 [(set FPRegs:$dst, (fsub FPRegs:$src1, FPRegs:$src2))]>;
604def FSUBD : F3_3<2, 0b110100, 0b001000110,
Evan Chengb783fa32007-07-19 01:14:50 +0000605 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000606 "fsubd $src1, $src2, $dst",
607 [(set DFPRegs:$dst, (fsub DFPRegs:$src1, DFPRegs:$src2))]>;
608
609// Floating-point Multiply and Divide Instructions, p. 147
610def FMULS : F3_3<2, 0b110100, 0b001001001,
Evan Chengb783fa32007-07-19 01:14:50 +0000611 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612 "fmuls $src1, $src2, $dst",
613 [(set FPRegs:$dst, (fmul FPRegs:$src1, FPRegs:$src2))]>;
614def FMULD : F3_3<2, 0b110100, 0b001001010,
Evan Chengb783fa32007-07-19 01:14:50 +0000615 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616 "fmuld $src1, $src2, $dst",
617 [(set DFPRegs:$dst, (fmul DFPRegs:$src1, DFPRegs:$src2))]>;
618def FSMULD : F3_3<2, 0b110100, 0b001101001,
Evan Chengb783fa32007-07-19 01:14:50 +0000619 (outs DFPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620 "fsmuld $src1, $src2, $dst",
621 [(set DFPRegs:$dst, (fmul (fextend FPRegs:$src1),
622 (fextend FPRegs:$src2)))]>;
623def FDIVS : F3_3<2, 0b110100, 0b001001101,
Evan Chengb783fa32007-07-19 01:14:50 +0000624 (outs FPRegs:$dst), (ins FPRegs:$src1, FPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000625 "fdivs $src1, $src2, $dst",
626 [(set FPRegs:$dst, (fdiv FPRegs:$src1, FPRegs:$src2))]>;
627def FDIVD : F3_3<2, 0b110100, 0b001001110,
Evan Chengb783fa32007-07-19 01:14:50 +0000628 (outs DFPRegs:$dst), (ins DFPRegs:$src1, DFPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629 "fdivd $src1, $src2, $dst",
630 [(set DFPRegs:$dst, (fdiv DFPRegs:$src1, DFPRegs:$src2))]>;
631
632// Floating-point Compare Instructions, p. 148
633// Note: the 2nd template arg is different for these guys.
634// Note 2: the result of a FCMP is not available until the 2nd cycle
635// after the instr is retired, but there is no interlock. This behavior
636// is modelled with a forced noop after the instruction.
637def FCMPS : F3_3<2, 0b110101, 0b001010001,
Evan Chengb783fa32007-07-19 01:14:50 +0000638 (outs), (ins FPRegs:$src1, FPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000639 "fcmps $src1, $src2\n\tnop",
640 [(SPcmpfcc FPRegs:$src1, FPRegs:$src2)]>;
641def FCMPD : F3_3<2, 0b110101, 0b001010010,
Evan Chengb783fa32007-07-19 01:14:50 +0000642 (outs), (ins DFPRegs:$src1, DFPRegs:$src2),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643 "fcmpd $src1, $src2\n\tnop",
644 [(SPcmpfcc DFPRegs:$src1, DFPRegs:$src2)]>;
645
646
647//===----------------------------------------------------------------------===//
648// V9 Instructions
649//===----------------------------------------------------------------------===//
650
651// V9 Conditional Moves.
652let Predicates = [HasV9], isTwoAddress = 1 in {
653 // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
654 // FIXME: Add instruction encodings for the JIT some day.
655 def MOVICCrr
Evan Chengb783fa32007-07-19 01:14:50 +0000656 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000657 "mov$cc %icc, $F, $dst",
658 [(set IntRegs:$dst,
659 (SPselecticc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
660 def MOVICCri
Evan Chengb783fa32007-07-19 01:14:50 +0000661 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662 "mov$cc %icc, $F, $dst",
663 [(set IntRegs:$dst,
664 (SPselecticc simm11:$F, IntRegs:$T, imm:$cc))]>;
665
666 def MOVFCCrr
Evan Chengb783fa32007-07-19 01:14:50 +0000667 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000668 "mov$cc %fcc0, $F, $dst",
669 [(set IntRegs:$dst,
670 (SPselectfcc IntRegs:$F, IntRegs:$T, imm:$cc))]>;
671 def MOVFCCri
Evan Chengb783fa32007-07-19 01:14:50 +0000672 : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, i32imm:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 "mov$cc %fcc0, $F, $dst",
674 [(set IntRegs:$dst,
675 (SPselectfcc simm11:$F, IntRegs:$T, imm:$cc))]>;
676
677 def FMOVS_ICC
Evan Chengb783fa32007-07-19 01:14:50 +0000678 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000679 "fmovs$cc %icc, $F, $dst",
680 [(set FPRegs:$dst,
681 (SPselecticc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
682 def FMOVD_ICC
Evan Chengb783fa32007-07-19 01:14:50 +0000683 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000684 "fmovd$cc %icc, $F, $dst",
685 [(set DFPRegs:$dst,
686 (SPselecticc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
687 def FMOVS_FCC
Evan Chengb783fa32007-07-19 01:14:50 +0000688 : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689 "fmovs$cc %fcc0, $F, $dst",
690 [(set FPRegs:$dst,
691 (SPselectfcc FPRegs:$F, FPRegs:$T, imm:$cc))]>;
692 def FMOVD_FCC
Evan Chengb783fa32007-07-19 01:14:50 +0000693 : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, CCOp:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694 "fmovd$cc %fcc0, $F, $dst",
695 [(set DFPRegs:$dst,
696 (SPselectfcc DFPRegs:$F, DFPRegs:$T, imm:$cc))]>;
697
698}
699
700// Floating-Point Move Instructions, p. 164 of the V9 manual.
701let Predicates = [HasV9] in {
702 def FMOVD : F3_3<2, 0b110100, 0b000000010,
Evan Chengb783fa32007-07-19 01:14:50 +0000703 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704 "fmovd $src, $dst", []>;
705 def FNEGD : F3_3<2, 0b110100, 0b000000110,
Evan Chengb783fa32007-07-19 01:14:50 +0000706 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707 "fnegd $src, $dst",
708 [(set DFPRegs:$dst, (fneg DFPRegs:$src))]>;
709 def FABSD : F3_3<2, 0b110100, 0b000001010,
Evan Chengb783fa32007-07-19 01:14:50 +0000710 (outs DFPRegs:$dst), (ins DFPRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000711 "fabsd $src, $dst",
712 [(set DFPRegs:$dst, (fabs DFPRegs:$src))]>;
713}
714
715// POPCrr - This does a ctpop of a 64-bit register. As such, we have to clear
716// the top 32-bits before using it. To do this clearing, we use a SLLri X,0.
717def POPCrr : F3_1<2, 0b101110,
Evan Chengb783fa32007-07-19 01:14:50 +0000718 (outs IntRegs:$dst), (ins IntRegs:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000719 "popc $src, $dst", []>, Requires<[HasV9]>;
720def : Pat<(ctpop IntRegs:$src),
721 (POPCrr (SLLri IntRegs:$src, 0))>;
722
723//===----------------------------------------------------------------------===//
724// Non-Instruction Patterns
725//===----------------------------------------------------------------------===//
726
727// Small immediates.
728def : Pat<(i32 simm13:$val),
729 (ORri G0, imm:$val)>;
730// Arbitrary immediates.
731def : Pat<(i32 imm:$val),
732 (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
733
734// subc
735def : Pat<(subc IntRegs:$b, IntRegs:$c),
736 (SUBCCrr IntRegs:$b, IntRegs:$c)>;
737def : Pat<(subc IntRegs:$b, simm13:$val),
738 (SUBCCri IntRegs:$b, imm:$val)>;
739
740// Global addresses, constant pool entries
741def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
742def : Pat<(SPlo tglobaladdr:$in), (ORri G0, tglobaladdr:$in)>;
743def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
744def : Pat<(SPlo tconstpool:$in), (ORri G0, tconstpool:$in)>;
745
746// Add reg, lo. This is used when taking the addr of a global/constpool entry.
747def : Pat<(add IntRegs:$r, (SPlo tglobaladdr:$in)),
748 (ADDri IntRegs:$r, tglobaladdr:$in)>;
749def : Pat<(add IntRegs:$r, (SPlo tconstpool:$in)),
750 (ADDri IntRegs:$r, tconstpool:$in)>;
751
752// Calls:
753def : Pat<(call tglobaladdr:$dst),
754 (CALL tglobaladdr:$dst)>;
755def : Pat<(call texternalsym:$dst),
756 (CALL texternalsym:$dst)>;
757
758def : Pat<(ret), (RETL)>;
759
760// Map integer extload's to zextloads.
761def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
762def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
763def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
764def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
765def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
766def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
767
768// zextload bool -> zextload byte
769def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
770def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
771
772// truncstore bool -> truncstore byte.
773def : Pat<(truncstorei1 IntRegs:$src, ADDRrr:$addr),
774 (STBrr ADDRrr:$addr, IntRegs:$src)>;
775def : Pat<(truncstorei1 IntRegs:$src, ADDRri:$addr),
776 (STBri ADDRri:$addr, IntRegs:$src)>;