blob: 312cc0b2adb5258d2c3eb9a682be91cd7dc06273 [file] [log] [blame]
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +00001//===- MipsInstrFPU.td - Mips FPU Instruction Information -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the Mips implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +000015// Floating Point Instructions
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000016// ------------------------
17// * 64bit fp:
18// - 32 64-bit registers (default mode)
19// - 16 even 32-bit registers (32-bit compatible mode) for
20// single and double access.
21// * 32bit fp:
22// - 16 even 32-bit registers - single and double (aliased)
23// - 32 32-bit registers (within single-only mode)
24//===----------------------------------------------------------------------===//
25
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +000026// Floating Point Compare and Branch
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000027def SDT_MipsFPBrcond : SDTypeProfile<0, 3, [SDTCisSameAs<0, 2>, SDTCisInt<0>,
28 SDTCisVT<1, OtherVT>]>;
29def SDT_MipsFPCmp : SDTypeProfile<0, 3, [SDTCisSameAs<0, 1>, SDTCisFP<0>,
30 SDTCisInt<2>]>;
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +000031def SDT_MipsFPSelectCC : SDTypeProfile<1, 4, [SDTCisInt<1>, SDTCisInt<4>,
32 SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000033def MipsFPBrcond : SDNode<"MipsISD::FPBrcond", SDT_MipsFPBrcond,
34 [SDNPHasChain]>;
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +000035def MipsFPCmp : SDNode<"MipsISD::FPCmp", SDT_MipsFPCmp>;
36def MipsFPSelectCC : SDNode<"MipsISD::FPSelectCC", SDT_MipsFPSelectCC>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000037
38// Operand for printing out a condition code.
39let PrintMethod = "printFCCOperand" in
40 def condcode : Operand<i32>;
41
42//===----------------------------------------------------------------------===//
43// Feature predicates.
44//===----------------------------------------------------------------------===//
45
46def In32BitMode : Predicate<"!Subtarget.isFP64bit()">;
47def In64BitMode : Predicate<"Subtarget.isFP64bit()">;
48def IsSingleFloat : Predicate<"Subtarget.isSingleFloat()">;
49def IsNotSingleFloat : Predicate<"!Subtarget.isSingleFloat()">;
50
51//===----------------------------------------------------------------------===//
52// Instruction Class Templates
53//
54// A set of multiclasses is used to address this in one shot.
55// SO32 - single precision only, uses all 32 32-bit fp registers
56// require FGR32 Register Class and IsSingleFloat
57// AS32 - 16 even fp registers are used for single precision
58// require AFGR32 Register Class and In32BitMode
59// S64 - 32 64 bit registers are used to hold 32-bit single precision values.
60// require FGR64 Register Class and In64BitMode
61// D32 - 16 even fp registers are used for double precision
62// require AFGR64 Register Class and In32BitMode
63// D64 - 32 64 bit registers are used to hold 64-bit double precision values.
64// require FGR64 Register Class and In64BitMode
65//
66// Only SO32, AS32 and D32 are supported right now.
67//
68//===----------------------------------------------------------------------===//
69
70multiclass FFR1_1<bits<6> funct, string asmstr>
71{
72 def _SO32 : FFR<0x11, funct, 0x0, (outs FGR32:$fd), (ins FGR32:$fs),
73 !strconcat(asmstr, ".s $fd, $fs"), []>, Requires<[IsSingleFloat]>;
74
75 def _AS32 : FFR<0x11, funct, 0x0, (outs AFGR32:$fd), (ins AFGR32:$fs),
76 !strconcat(asmstr, ".s $fd, $fs"), []>, Requires<[In32BitMode]>;
77
78 def _D32 : FFR<0x11, funct, 0x1, (outs AFGR64:$fd), (ins AFGR64:$fs),
79 !strconcat(asmstr, ".d $fd, $fs"), []>, Requires<[In32BitMode]>;
80}
81
82multiclass FFR1_2<bits<6> funct, string asmstr, SDNode FOp>
83{
84 def _SO32 : FFR<0x11, funct, 0x0, (outs FGR32:$fd), (ins FGR32:$fs),
85 !strconcat(asmstr, ".s $fd, $fs"),
86 [(set FGR32:$fd, (FOp FGR32:$fs))]>, Requires<[IsSingleFloat]>;
87
88 def _AS32 : FFR<0x11, funct, 0x0, (outs AFGR32:$fd), (ins AFGR32:$fs),
89 !strconcat(asmstr, ".s $fd, $fs"),
90 [(set AFGR32:$fd, (FOp AFGR32:$fs))]>, Requires<[In32BitMode]>;
91
92 def _D32 : FFR<0x11, funct, 0x1, (outs AFGR64:$fd), (ins AFGR64:$fs),
93 !strconcat(asmstr, ".d $fd, $fs"),
94 [(set AFGR64:$fd, (FOp AFGR64:$fs))]>, Requires<[In32BitMode]>;
95}
96
97class FFR1_3<bits<6> funct, bits<5> fmt, RegisterClass RcSrc,
98 RegisterClass RcDst, string asmstr>:
99 FFR<0x11, funct, fmt, (outs RcSrc:$fd), (ins RcDst:$fs),
100 !strconcat(asmstr, " $fd, $fs"), []>;
101
102
103multiclass FFR1_4<bits<6> funct, string asmstr, SDNode FOp> {
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000104 def _SO32 : FFR<0x11, funct, 0x0, (outs FGR32:$fd),
105 (ins FGR32:$fs, FGR32:$ft),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000106 !strconcat(asmstr, ".s $fd, $fs, $ft"),
107 [(set FGR32:$fd, (FOp FGR32:$fs, FGR32:$ft))]>,
108 Requires<[IsSingleFloat]>;
109
110 def _AS32 : FFR<0x11, funct, 0x0, (outs AFGR32:$fd),
111 (ins AFGR32:$fs, AFGR32:$ft),
112 !strconcat(asmstr, ".s $fd, $fs, $ft"),
113 [(set AFGR32:$fd, (FOp AFGR32:$fs, AFGR32:$ft))]>,
114 Requires<[In32BitMode]>;
115
116 def _D32 : FFR<0x11, funct, 0x1, (outs AFGR64:$fd),
117 (ins AFGR64:$fs, AFGR64:$ft),
118 !strconcat(asmstr, ".d $fd, $fs, $ft"),
119 [(set AFGR64:$fd, (FOp AFGR64:$fs, AFGR64:$ft))]>,
120 Requires<[In32BitMode]>;
121}
122
123//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000124// Floating Point Instructions
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000125//===----------------------------------------------------------------------===//
126
127let ft = 0 in {
128 defm FLOOR_W : FFR1_1<0b001111, "floor.w">;
129 defm CEIL_W : FFR1_1<0b001110, "ceil.w">;
130 defm ROUND_W : FFR1_1<0b001100, "round.w">;
131 defm TRUNC_W : FFR1_1<0b001101, "trunc.w">;
132 defm CVTW : FFR1_1<0b100100, "cvt.w">;
133 defm FMOV : FFR1_1<0b000110, "mov">;
134
135 defm FABS : FFR1_2<0b000101, "abs", fabs>;
136 defm FNEG : FFR1_2<0b000111, "neg", fneg>;
137 defm FSQRT : FFR1_2<0b000100, "sqrt", fsqrt>;
138
139 let Predicates = [IsNotSingleFloat] in {
140 /// Ceil to long signed integer
141 def CEIL_LS : FFR1_3<0b001010, 0x0, AFGR32, AFGR32, "ceil.l">;
142 def CEIL_LD : FFR1_3<0b001010, 0x1, AFGR64, AFGR64, "ceil.l">;
143
144 /// Round to long signed integer
145 def ROUND_LS : FFR1_3<0b001000, 0x0, AFGR32, AFGR32, "round.l">;
146 def ROUND_LD : FFR1_3<0b001000, 0x1, AFGR64, AFGR64, "round.l">;
147
148 /// Floor to long signed integer
149 def FLOOR_LS : FFR1_3<0b001011, 0x0, AFGR32, AFGR32, "floor.l">;
150 def FLOOR_LD : FFR1_3<0b001011, 0x1, AFGR64, AFGR64, "floor.l">;
151
152 /// Trunc to long signed integer
153 def TRUNC_LS : FFR1_3<0b001001, 0x0, AFGR32, AFGR32, "trunc.l">;
154 def TRUNC_LD : FFR1_3<0b001001, 0x1, AFGR64, AFGR64, "trunc.l">;
155
156 /// Convert to long signed integer
157 def CVTL_S : FFR1_3<0b100101, 0x0, AFGR32, AFGR32, "cvt.l">;
158 def CVTL_D : FFR1_3<0b100101, 0x1, AFGR64, AFGR64, "cvt.l">;
159
160 /// Convert to Double Precison
161 def CVTD_S32 : FFR1_3<0b100001, 0x0, AFGR64, FGR32, "cvt.d.s">;
162 def CVTD_W32 : FFR1_3<0b100001, 0x2, AFGR64, FGR32, "cvt.d.w">;
163 def CVTD_L32 : FFR1_3<0b100001, 0x3, AFGR64, AFGR64, "cvt.d.l">;
164
165 /// Convert to Single Precison
166 def CVTS_D32 : FFR1_3<0b100000, 0x1, FGR32, AFGR64, "cvt.s.d">;
167 def CVTS_L32 : FFR1_3<0b100000, 0x3, FGR32, AFGR64, "cvt.s.l">;
168 }
169
170 /// Convert to Single Precison
171 def CVTS_W32 : FFR1_3<0b100000, 0x2, FGR32, FGR32, "cvt.s.w">,
172 Requires<[IsSingleFloat]>;
173}
174
175// The odd-numbered registers are only referenced when doing loads,
176// stores, and moves between floating-point and integer registers.
177// When defining instructions, we reference all 32-bit registers,
178// regardless of register aliasing.
179let fd = 0 in {
180 /// Move Control Registers From/To CPU Registers
181 ///def CFC1 : FFR<0x11, 0x0, 0x2, (outs CPURegs:$rt), (ins FGR32:$fs),
182 /// "cfc1 $rt, $fs", []>;
183
184 ///def CTC1 : FFR<0x11, 0x0, 0x6, (outs CPURegs:$rt), (ins FGR32:$fs),
185 /// "ctc1 $rt, $fs", []>;
186 ///
187 ///def CFC1A : FFR<0x11, 0x0, 0x2, (outs CPURegs:$rt), (ins AFGR32:$fs),
188 /// "cfc1 $rt, $fs", []>;
189
190 ///def CTC1A : FFR<0x11, 0x0, 0x6, (outs CPURegs:$rt), (ins AFGR32:$fs),
191 /// "ctc1 $rt, $fs", []>;
192
193 def MFC1 : FFR<0x11, 0x00, 0x00, (outs CPURegs:$rt), (ins FGR32:$fs),
194 "mfc1 $rt, $fs", []>;
195
196 def MTC1 : FFR<0x11, 0x00, 0x04, (outs FGR32:$fs), (ins CPURegs:$rt),
Bruno Cardoso Lopes7030ae72008-07-30 19:00:31 +0000197 "mtc1 $rt, $fs", []>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000198
199 def MFC1A : FFR<0x11, 0x00, 0x00, (outs CPURegs:$rt), (ins AFGR32:$fs),
200 "mfc1 $rt, $fs", []>;
201
202 def MTC1A : FFR<0x11, 0x00, 0x04, (outs AFGR32:$fs), (ins CPURegs:$rt),
Bruno Cardoso Lopes7030ae72008-07-30 19:00:31 +0000203 "mtc1 $rt, $fs", []>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000204}
205
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000206/// Floating Point Memory Instructions
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000207let Predicates = [IsNotSingleFloat] in {
208 def LDC1 : FFI<0b110101, (outs AFGR64:$ft), (ins mem:$addr),
209 "ldc1 $ft, $addr", [(set AFGR64:$ft, (load addr:$addr))]>;
210
211 def SDC1 : FFI<0b111101, (outs), (ins AFGR64:$ft, mem:$addr),
212 "sdc1 $ft, $addr", [(store AFGR64:$ft, addr:$addr)]>;
213}
214
215// LWC1 and SWC1 can always be emited with odd registers.
216def LWC1 : FFI<0b110001, (outs FGR32:$ft), (ins mem:$addr), "lwc1 $ft, $addr",
217 [(set FGR32:$ft, (load addr:$addr))]>;
218def SWC1 : FFI<0b111001, (outs), (ins FGR32:$ft, mem:$addr), "swc1 $ft, $addr",
219 [(store FGR32:$ft, addr:$addr)]>;
220
221def LWC1A : FFI<0b110001, (outs AFGR32:$ft), (ins mem:$addr), "lwc1 $ft, $addr",
222 [(set AFGR32:$ft, (load addr:$addr))]>;
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000223def SWC1A : FFI<0b111001, (outs), (ins AFGR32:$ft, mem:$addr),
224 "swc1 $ft, $addr", [(store AFGR32:$ft, addr:$addr)]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000225
226/// Floating-point Aritmetic
227defm FADD : FFR1_4<0x10, "add", fadd>;
228defm FDIV : FFR1_4<0x03, "div", fdiv>;
229defm FMUL : FFR1_4<0x02, "mul", fmul>;
230defm FSUB : FFR1_4<0x01, "sub", fsub>;
231
232//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000233// Floating Point Branch Codes
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000234//===----------------------------------------------------------------------===//
235// Mips branch codes. These correspond to condcode in MipsInstrInfo.h.
236// They must be kept in synch.
237def MIPS_BRANCH_F : PatLeaf<(i32 0)>;
238def MIPS_BRANCH_T : PatLeaf<(i32 1)>;
239def MIPS_BRANCH_FL : PatLeaf<(i32 2)>;
240def MIPS_BRANCH_TL : PatLeaf<(i32 3)>;
241
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000242/// Floating Point Branch of False/True (Likely)
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000243let isBranch=1, isTerminator=1, hasDelaySlot=1, base=0x8, Uses=[FCR31] in {
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000244 class FBRANCH<PatLeaf op, string asmstr> : FFI<0x11, (outs),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000245 (ins brtarget:$dst), !strconcat(asmstr, " $dst"),
246 [(MipsFPBrcond op, bb:$dst, FCR31)]>;
247}
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000248def BC1F : FBRANCH<MIPS_BRANCH_F, "bc1f">;
249def BC1T : FBRANCH<MIPS_BRANCH_T, "bc1t">;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000250def BC1FL : FBRANCH<MIPS_BRANCH_FL, "bc1fl">;
251def BC1TL : FBRANCH<MIPS_BRANCH_TL, "bc1tl">;
252
253//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000254// Floating Point Flag Conditions
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000255//===----------------------------------------------------------------------===//
256// Mips condition codes. They must correspond to condcode in MipsInstrInfo.h.
257// They must be kept in synch.
258def MIPS_FCOND_F : PatLeaf<(i32 0)>;
259def MIPS_FCOND_UN : PatLeaf<(i32 1)>;
260def MIPS_FCOND_EQ : PatLeaf<(i32 2)>;
261def MIPS_FCOND_UEQ : PatLeaf<(i32 3)>;
262def MIPS_FCOND_OLT : PatLeaf<(i32 4)>;
263def MIPS_FCOND_ULT : PatLeaf<(i32 5)>;
264def MIPS_FCOND_OLE : PatLeaf<(i32 6)>;
265def MIPS_FCOND_ULE : PatLeaf<(i32 7)>;
266def MIPS_FCOND_SF : PatLeaf<(i32 8)>;
267def MIPS_FCOND_NGLE : PatLeaf<(i32 9)>;
268def MIPS_FCOND_SEQ : PatLeaf<(i32 10)>;
269def MIPS_FCOND_NGL : PatLeaf<(i32 11)>;
270def MIPS_FCOND_LT : PatLeaf<(i32 12)>;
271def MIPS_FCOND_NGE : PatLeaf<(i32 13)>;
272def MIPS_FCOND_LE : PatLeaf<(i32 14)>;
273def MIPS_FCOND_NGT : PatLeaf<(i32 15)>;
274
275/// Floating Point Compare
276let hasDelaySlot = 1, Defs=[FCR31] in {
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000277 def FCMP_SO32 : FCC<0x0, (outs), (ins FGR32:$fs, FGR32:$ft, condcode:$cc),
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000278 "c.$cc.s $fs, $ft", [(MipsFPCmp FGR32:$fs, FGR32:$ft, imm:$cc),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000279 (implicit FCR31)]>, Requires<[IsSingleFloat]>;
280
281 def FCMP_AS32 : FCC<0x0, (outs), (ins AFGR32:$fs, AFGR32:$ft, condcode:$cc),
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000282 "c.$cc.s $fs, $ft", [(MipsFPCmp AFGR32:$fs, AFGR32:$ft, imm:$cc),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000283 (implicit FCR31)]>, Requires<[In32BitMode]>;
284
285 def FCMP_D32 : FCC<0x1, (outs), (ins AFGR64:$fs, AFGR64:$ft, condcode:$cc),
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000286 "c.$cc.d $fs, $ft", [(MipsFPCmp AFGR64:$fs, AFGR64:$ft, imm:$cc),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000287 (implicit FCR31)]>, Requires<[In32BitMode]>;
288}
289
290//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000291// Floating Point Pseudo-Instructions
292//===----------------------------------------------------------------------===//
293
294// For some explanation, see Select_CC at MipsInstrInfo.td. We also embedd a
295// condiciton code to enable easy handling by the Custom Inserter.
296let usesCustomDAGSchedInserter = 1, Uses=[FCR31] in {
297 class PseudoFPSelCC<RegisterClass RC, string asmstr> :
298 MipsPseudo<(outs RC:$dst),
299 (ins CPURegs:$CmpRes, RC:$T, RC:$F, condcode:$cc), asmstr,
300 [(set RC:$dst, (MipsFPSelectCC CPURegs:$CmpRes, RC:$T, RC:$F,
301 imm:$cc))]>;
302}
303
304// The values to be selected are fp but the condition test is with integers.
305def Select_CC_SO32 : PseudoSelCC<FGR32, "# MipsSelect_CC_SO32_f32">,
306 Requires<[IsSingleFloat]>;
307def Select_CC_AS32 : PseudoSelCC<AFGR32, "# MipsSelect_CC_AS32_f32">,
308 Requires<[In32BitMode]>;
309def Select_CC_D32 : PseudoSelCC<AFGR64, "# MipsSelect_CC_D32_f32">,
310 Requires<[In32BitMode]>;
311
312// The values to be selected are int but the condition test is done with fp.
313def Select_FCC : PseudoFPSelCC<CPURegs, "# MipsSelect_FCC">;
314
315// The values to be selected and the condition test is done with fp.
316def Select_FCC_SO32 : PseudoFPSelCC<FGR32, "# MipsSelect_FCC_SO32_f32">,
317 Requires<[IsSingleFloat]>;
318def Select_FCC_AS32 : PseudoFPSelCC<AFGR32, "# MipsSelect_FCC_AS32_f32">,
319 Requires<[In32BitMode]>;
320def Select_FCC_D32 : PseudoFPSelCC<AFGR64, "# MipsSelect_FCC_D32_f32">,
321 Requires<[In32BitMode]>;
322
323
324//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000325// Floating Point Patterns
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000326//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7030ae72008-07-30 19:00:31 +0000327def fpimm0 : PatLeaf<(fpimm), [{
328 return N->isExactlyValue(+0.0);
329}]>;
330
331def : Pat<(f32 fpimm0), (MTC1 ZERO)>, Requires<[IsSingleFloat]>;
332def : Pat<(f32 fpimm0), (MTC1A ZERO)>, Requires<[In32BitMode]>;
333
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000334def : Pat<(f32 (sint_to_fp CPURegs:$src)), (CVTS_W32 (MTC1 CPURegs:$src))>;
335def : Pat<(f64 (sint_to_fp CPURegs:$src)), (CVTD_W32 (MTC1 CPURegs:$src))>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000336
Bruno Cardoso Lopes7030ae72008-07-30 19:00:31 +0000337def : Pat<(i32 (fp_to_sint FGR32:$src)), (MFC1 (TRUNC_W_SO32 FGR32:$src))>;
338def : Pat<(i32 (fp_to_sint AFGR32:$src)), (MFC1A (TRUNC_W_AS32 AFGR32:$src))>;
339
340def : Pat<(i32 (bitconvert FGR32:$src)), (MFC1 FGR32:$src)>;
341def : Pat<(i32 (bitconvert AFGR32:$src)), (MFC1A AFGR32:$src)>;