blob: 550c8354117d3979e67503b3928b068d734dc1f3 [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>]>;
31def MipsFPBrcond : SDNode<"MipsISD::FPBrcond", SDT_MipsFPBrcond,
32 [SDNPHasChain]>;
33def MipsFPCmp : SDNode<"MipsISD::FPCmp", SDT_MipsFPCmp>;
34
35// Operand for printing out a condition code.
36let PrintMethod = "printFCCOperand" in
37 def condcode : Operand<i32>;
38
39//===----------------------------------------------------------------------===//
40// Feature predicates.
41//===----------------------------------------------------------------------===//
42
43def In32BitMode : Predicate<"!Subtarget.isFP64bit()">;
44def In64BitMode : Predicate<"Subtarget.isFP64bit()">;
45def IsSingleFloat : Predicate<"Subtarget.isSingleFloat()">;
46def IsNotSingleFloat : Predicate<"!Subtarget.isSingleFloat()">;
47
48//===----------------------------------------------------------------------===//
49// Instruction Class Templates
50//
51// A set of multiclasses is used to address this in one shot.
52// SO32 - single precision only, uses all 32 32-bit fp registers
53// require FGR32 Register Class and IsSingleFloat
54// AS32 - 16 even fp registers are used for single precision
55// require AFGR32 Register Class and In32BitMode
56// S64 - 32 64 bit registers are used to hold 32-bit single precision values.
57// require FGR64 Register Class and In64BitMode
58// D32 - 16 even fp registers are used for double precision
59// require AFGR64 Register Class and In32BitMode
60// D64 - 32 64 bit registers are used to hold 64-bit double precision values.
61// require FGR64 Register Class and In64BitMode
62//
63// Only SO32, AS32 and D32 are supported right now.
64//
65//===----------------------------------------------------------------------===//
66
67multiclass FFR1_1<bits<6> funct, string asmstr>
68{
69 def _SO32 : FFR<0x11, funct, 0x0, (outs FGR32:$fd), (ins FGR32:$fs),
70 !strconcat(asmstr, ".s $fd, $fs"), []>, Requires<[IsSingleFloat]>;
71
72 def _AS32 : FFR<0x11, funct, 0x0, (outs AFGR32:$fd), (ins AFGR32:$fs),
73 !strconcat(asmstr, ".s $fd, $fs"), []>, Requires<[In32BitMode]>;
74
75 def _D32 : FFR<0x11, funct, 0x1, (outs AFGR64:$fd), (ins AFGR64:$fs),
76 !strconcat(asmstr, ".d $fd, $fs"), []>, Requires<[In32BitMode]>;
77}
78
79multiclass FFR1_2<bits<6> funct, string asmstr, SDNode FOp>
80{
81 def _SO32 : FFR<0x11, funct, 0x0, (outs FGR32:$fd), (ins FGR32:$fs),
82 !strconcat(asmstr, ".s $fd, $fs"),
83 [(set FGR32:$fd, (FOp FGR32:$fs))]>, Requires<[IsSingleFloat]>;
84
85 def _AS32 : FFR<0x11, funct, 0x0, (outs AFGR32:$fd), (ins AFGR32:$fs),
86 !strconcat(asmstr, ".s $fd, $fs"),
87 [(set AFGR32:$fd, (FOp AFGR32:$fs))]>, Requires<[In32BitMode]>;
88
89 def _D32 : FFR<0x11, funct, 0x1, (outs AFGR64:$fd), (ins AFGR64:$fs),
90 !strconcat(asmstr, ".d $fd, $fs"),
91 [(set AFGR64:$fd, (FOp AFGR64:$fs))]>, Requires<[In32BitMode]>;
92}
93
94class FFR1_3<bits<6> funct, bits<5> fmt, RegisterClass RcSrc,
95 RegisterClass RcDst, string asmstr>:
96 FFR<0x11, funct, fmt, (outs RcSrc:$fd), (ins RcDst:$fs),
97 !strconcat(asmstr, " $fd, $fs"), []>;
98
99
100multiclass FFR1_4<bits<6> funct, string asmstr, SDNode FOp> {
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000101 def _SO32 : FFR<0x11, funct, 0x0, (outs FGR32:$fd),
102 (ins FGR32:$fs, FGR32:$ft),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000103 !strconcat(asmstr, ".s $fd, $fs, $ft"),
104 [(set FGR32:$fd, (FOp FGR32:$fs, FGR32:$ft))]>,
105 Requires<[IsSingleFloat]>;
106
107 def _AS32 : FFR<0x11, funct, 0x0, (outs AFGR32:$fd),
108 (ins AFGR32:$fs, AFGR32:$ft),
109 !strconcat(asmstr, ".s $fd, $fs, $ft"),
110 [(set AFGR32:$fd, (FOp AFGR32:$fs, AFGR32:$ft))]>,
111 Requires<[In32BitMode]>;
112
113 def _D32 : FFR<0x11, funct, 0x1, (outs AFGR64:$fd),
114 (ins AFGR64:$fs, AFGR64:$ft),
115 !strconcat(asmstr, ".d $fd, $fs, $ft"),
116 [(set AFGR64:$fd, (FOp AFGR64:$fs, AFGR64:$ft))]>,
117 Requires<[In32BitMode]>;
118}
119
120//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000121// Floating Point Instructions
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000122//===----------------------------------------------------------------------===//
123
124let ft = 0 in {
125 defm FLOOR_W : FFR1_1<0b001111, "floor.w">;
126 defm CEIL_W : FFR1_1<0b001110, "ceil.w">;
127 defm ROUND_W : FFR1_1<0b001100, "round.w">;
128 defm TRUNC_W : FFR1_1<0b001101, "trunc.w">;
129 defm CVTW : FFR1_1<0b100100, "cvt.w">;
130 defm FMOV : FFR1_1<0b000110, "mov">;
131
132 defm FABS : FFR1_2<0b000101, "abs", fabs>;
133 defm FNEG : FFR1_2<0b000111, "neg", fneg>;
134 defm FSQRT : FFR1_2<0b000100, "sqrt", fsqrt>;
135
136 let Predicates = [IsNotSingleFloat] in {
137 /// Ceil to long signed integer
138 def CEIL_LS : FFR1_3<0b001010, 0x0, AFGR32, AFGR32, "ceil.l">;
139 def CEIL_LD : FFR1_3<0b001010, 0x1, AFGR64, AFGR64, "ceil.l">;
140
141 /// Round to long signed integer
142 def ROUND_LS : FFR1_3<0b001000, 0x0, AFGR32, AFGR32, "round.l">;
143 def ROUND_LD : FFR1_3<0b001000, 0x1, AFGR64, AFGR64, "round.l">;
144
145 /// Floor to long signed integer
146 def FLOOR_LS : FFR1_3<0b001011, 0x0, AFGR32, AFGR32, "floor.l">;
147 def FLOOR_LD : FFR1_3<0b001011, 0x1, AFGR64, AFGR64, "floor.l">;
148
149 /// Trunc to long signed integer
150 def TRUNC_LS : FFR1_3<0b001001, 0x0, AFGR32, AFGR32, "trunc.l">;
151 def TRUNC_LD : FFR1_3<0b001001, 0x1, AFGR64, AFGR64, "trunc.l">;
152
153 /// Convert to long signed integer
154 def CVTL_S : FFR1_3<0b100101, 0x0, AFGR32, AFGR32, "cvt.l">;
155 def CVTL_D : FFR1_3<0b100101, 0x1, AFGR64, AFGR64, "cvt.l">;
156
157 /// Convert to Double Precison
158 def CVTD_S32 : FFR1_3<0b100001, 0x0, AFGR64, FGR32, "cvt.d.s">;
159 def CVTD_W32 : FFR1_3<0b100001, 0x2, AFGR64, FGR32, "cvt.d.w">;
160 def CVTD_L32 : FFR1_3<0b100001, 0x3, AFGR64, AFGR64, "cvt.d.l">;
161
162 /// Convert to Single Precison
163 def CVTS_D32 : FFR1_3<0b100000, 0x1, FGR32, AFGR64, "cvt.s.d">;
164 def CVTS_L32 : FFR1_3<0b100000, 0x3, FGR32, AFGR64, "cvt.s.l">;
165 }
166
167 /// Convert to Single Precison
168 def CVTS_W32 : FFR1_3<0b100000, 0x2, FGR32, FGR32, "cvt.s.w">,
169 Requires<[IsSingleFloat]>;
170}
171
172// The odd-numbered registers are only referenced when doing loads,
173// stores, and moves between floating-point and integer registers.
174// When defining instructions, we reference all 32-bit registers,
175// regardless of register aliasing.
176let fd = 0 in {
177 /// Move Control Registers From/To CPU Registers
178 ///def CFC1 : FFR<0x11, 0x0, 0x2, (outs CPURegs:$rt), (ins FGR32:$fs),
179 /// "cfc1 $rt, $fs", []>;
180
181 ///def CTC1 : FFR<0x11, 0x0, 0x6, (outs CPURegs:$rt), (ins FGR32:$fs),
182 /// "ctc1 $rt, $fs", []>;
183 ///
184 ///def CFC1A : FFR<0x11, 0x0, 0x2, (outs CPURegs:$rt), (ins AFGR32:$fs),
185 /// "cfc1 $rt, $fs", []>;
186
187 ///def CTC1A : FFR<0x11, 0x0, 0x6, (outs CPURegs:$rt), (ins AFGR32:$fs),
188 /// "ctc1 $rt, $fs", []>;
189
190 def MFC1 : FFR<0x11, 0x00, 0x00, (outs CPURegs:$rt), (ins FGR32:$fs),
191 "mfc1 $rt, $fs", []>;
192
193 def MTC1 : FFR<0x11, 0x00, 0x04, (outs FGR32:$fs), (ins CPURegs:$rt),
194 "mtc1 $fs, $rt", []>;
195
196 def MFC1A : FFR<0x11, 0x00, 0x00, (outs CPURegs:$rt), (ins AFGR32:$fs),
197 "mfc1 $rt, $fs", []>;
198
199 def MTC1A : FFR<0x11, 0x00, 0x04, (outs AFGR32:$fs), (ins CPURegs:$rt),
200 "mtc1 $fs, $rt", []>;
201}
202
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000203/// Floating Point Memory Instructions
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000204let Predicates = [IsNotSingleFloat] in {
205 def LDC1 : FFI<0b110101, (outs AFGR64:$ft), (ins mem:$addr),
206 "ldc1 $ft, $addr", [(set AFGR64:$ft, (load addr:$addr))]>;
207
208 def SDC1 : FFI<0b111101, (outs), (ins AFGR64:$ft, mem:$addr),
209 "sdc1 $ft, $addr", [(store AFGR64:$ft, addr:$addr)]>;
210}
211
212// LWC1 and SWC1 can always be emited with odd registers.
213def LWC1 : FFI<0b110001, (outs FGR32:$ft), (ins mem:$addr), "lwc1 $ft, $addr",
214 [(set FGR32:$ft, (load addr:$addr))]>;
215def SWC1 : FFI<0b111001, (outs), (ins FGR32:$ft, mem:$addr), "swc1 $ft, $addr",
216 [(store FGR32:$ft, addr:$addr)]>;
217
218def LWC1A : FFI<0b110001, (outs AFGR32:$ft), (ins mem:$addr), "lwc1 $ft, $addr",
219 [(set AFGR32:$ft, (load addr:$addr))]>;
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000220def SWC1A : FFI<0b111001, (outs), (ins AFGR32:$ft, mem:$addr),
221 "swc1 $ft, $addr", [(store AFGR32:$ft, addr:$addr)]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000222
223/// Floating-point Aritmetic
224defm FADD : FFR1_4<0x10, "add", fadd>;
225defm FDIV : FFR1_4<0x03, "div", fdiv>;
226defm FMUL : FFR1_4<0x02, "mul", fmul>;
227defm FSUB : FFR1_4<0x01, "sub", fsub>;
228
229//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000230// Floating Point Branch Codes
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000231//===----------------------------------------------------------------------===//
232// Mips branch codes. These correspond to condcode in MipsInstrInfo.h.
233// They must be kept in synch.
234def MIPS_BRANCH_F : PatLeaf<(i32 0)>;
235def MIPS_BRANCH_T : PatLeaf<(i32 1)>;
236def MIPS_BRANCH_FL : PatLeaf<(i32 2)>;
237def MIPS_BRANCH_TL : PatLeaf<(i32 3)>;
238
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000239/// Floating Point Branch of False/True (Likely)
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000240let isBranch=1, isTerminator=1, hasDelaySlot=1, base=0x8, Uses=[FCR31] in {
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000241 class FBRANCH<PatLeaf op, string asmstr> : FFI<0x11, (outs),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000242 (ins brtarget:$dst), !strconcat(asmstr, " $dst"),
243 [(MipsFPBrcond op, bb:$dst, FCR31)]>;
244}
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000245def BC1F : FBRANCH<MIPS_BRANCH_F, "bc1f">;
246def BC1T : FBRANCH<MIPS_BRANCH_T, "bc1t">;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000247def BC1FL : FBRANCH<MIPS_BRANCH_FL, "bc1fl">;
248def BC1TL : FBRANCH<MIPS_BRANCH_TL, "bc1tl">;
249
250//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000251// Floating Point Flag Conditions
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000252//===----------------------------------------------------------------------===//
253// Mips condition codes. They must correspond to condcode in MipsInstrInfo.h.
254// They must be kept in synch.
255def MIPS_FCOND_F : PatLeaf<(i32 0)>;
256def MIPS_FCOND_UN : PatLeaf<(i32 1)>;
257def MIPS_FCOND_EQ : PatLeaf<(i32 2)>;
258def MIPS_FCOND_UEQ : PatLeaf<(i32 3)>;
259def MIPS_FCOND_OLT : PatLeaf<(i32 4)>;
260def MIPS_FCOND_ULT : PatLeaf<(i32 5)>;
261def MIPS_FCOND_OLE : PatLeaf<(i32 6)>;
262def MIPS_FCOND_ULE : PatLeaf<(i32 7)>;
263def MIPS_FCOND_SF : PatLeaf<(i32 8)>;
264def MIPS_FCOND_NGLE : PatLeaf<(i32 9)>;
265def MIPS_FCOND_SEQ : PatLeaf<(i32 10)>;
266def MIPS_FCOND_NGL : PatLeaf<(i32 11)>;
267def MIPS_FCOND_LT : PatLeaf<(i32 12)>;
268def MIPS_FCOND_NGE : PatLeaf<(i32 13)>;
269def MIPS_FCOND_LE : PatLeaf<(i32 14)>;
270def MIPS_FCOND_NGT : PatLeaf<(i32 15)>;
271
272/// Floating Point Compare
273let hasDelaySlot = 1, Defs=[FCR31] in {
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000274 def FCMP_SO32 : FCC<0x0, (outs), (ins FGR32:$fs, FGR32:$ft, condcode:$cc),
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000275 "c.$cc.s $fs, $ft", [(MipsFPCmp FGR32:$fs, FGR32:$ft, imm:$cc),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000276 (implicit FCR31)]>, Requires<[IsSingleFloat]>;
277
278 def FCMP_AS32 : FCC<0x0, (outs), (ins AFGR32:$fs, AFGR32:$ft, condcode:$cc),
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000279 "c.$cc.s $fs, $ft", [(MipsFPCmp AFGR32:$fs, AFGR32:$ft, imm:$cc),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000280 (implicit FCR31)]>, Requires<[In32BitMode]>;
281
282 def FCMP_D32 : FCC<0x1, (outs), (ins AFGR64:$fs, AFGR64:$ft, condcode:$cc),
Bruno Cardoso Lopes85e31e32008-07-28 19:11:24 +0000283 "c.$cc.d $fs, $ft", [(MipsFPCmp AFGR64:$fs, AFGR64:$ft, imm:$cc),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000284 (implicit FCR31)]>, Requires<[In32BitMode]>;
285}
286
287//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes7b76da12008-07-09 04:45:36 +0000288// Floating Point Patterns
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000289//===----------------------------------------------------------------------===//
290def : Pat<(f32 (sint_to_fp CPURegs:$src)), (CVTS_W32 (MTC1 CPURegs:$src))>;
291def : Pat<(f64 (sint_to_fp CPURegs:$src)), (CVTD_W32 (MTC1 CPURegs:$src))>;
Bruno Cardoso Lopes85e92122008-07-07 19:11:24 +0000292def : Pat<(i32 (fp_to_sint FGR32:$src)), (MFC1 (TRUNC_W_SO32 FGR32:$src))>;
293def : Pat<(i32 (fp_to_sint AFGR32:$src)), (MFC1 (TRUNC_W_AS32 AFGR32:$src))>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000294