blob: 03b615cddb84281a2a2a6f88290817c514a7da0b [file] [log] [blame]
Evan Cheng6e595b92006-02-21 19:13:53 +00001//==- X86InstrFPStack.td - Describe the X86 Instruction Set -------*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the Evan Cheng 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 X86 x87 FPU instruction set, defining the
11// instructions, and properties of the instructions which are needed for code
12// generation, machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
Evan Cheng4f674922006-03-17 19:55:52 +000016//===----------------------------------------------------------------------===//
Evan Cheng9bf978d2006-03-18 01:23:20 +000017// FPStack specific DAG Nodes.
18//===----------------------------------------------------------------------===//
19
20def SDTX86FpGet : SDTypeProfile<1, 0, [SDTCisVT<0, f64>]>;
21def SDTX86FpSet : SDTypeProfile<0, 1, [SDTCisFP<0>]>;
22def SDTX86Fld : SDTypeProfile<1, 2, [SDTCisVT<0, f64>,
23 SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>]>;
24def SDTX86Fst : SDTypeProfile<0, 3, [SDTCisFP<0>,
25 SDTCisPtrTy<1>, SDTCisVT<2, OtherVT>]>;
26def SDTX86Fild : SDTypeProfile<1, 2, [SDTCisVT<0, f64>, SDTCisPtrTy<1>,
27 SDTCisVT<2, OtherVT>]>;
28def SDTX86FpToIMem: SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
29
30def X86fpget : SDNode<"X86ISD::FP_GET_RESULT", SDTX86FpGet,
31 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
32def X86fpset : SDNode<"X86ISD::FP_SET_RESULT", SDTX86FpSet,
33 [SDNPHasChain, SDNPOutFlag]>;
34def X86fld : SDNode<"X86ISD::FLD", SDTX86Fld,
35 [SDNPHasChain]>;
36def X86fst : SDNode<"X86ISD::FST", SDTX86Fst,
37 [SDNPHasChain, SDNPInFlag]>;
38def X86fild : SDNode<"X86ISD::FILD", SDTX86Fild,
39 [SDNPHasChain]>;
40def X86fildflag: SDNode<"X86ISD::FILD_FLAG",SDTX86Fild,
41 [SDNPHasChain, SDNPOutFlag]>;
42def X86fp_to_i16mem : SDNode<"X86ISD::FP_TO_INT16_IN_MEM", SDTX86FpToIMem,
43 [SDNPHasChain]>;
44def X86fp_to_i32mem : SDNode<"X86ISD::FP_TO_INT32_IN_MEM", SDTX86FpToIMem,
45 [SDNPHasChain]>;
46def X86fp_to_i64mem : SDNode<"X86ISD::FP_TO_INT64_IN_MEM", SDTX86FpToIMem,
47 [SDNPHasChain]>;
48
49//===----------------------------------------------------------------------===//
Evan Cheng4f674922006-03-17 19:55:52 +000050// FPStack pattern fragments
51//===----------------------------------------------------------------------===//
52
53def fp32imm0 : PatLeaf<(f32 fpimm), [{
54 return N->isExactlyValue(+0.0);
55}]>;
56
57def fp64imm0 : PatLeaf<(f64 fpimm), [{
58 return N->isExactlyValue(+0.0);
59}]>;
60
61def fp64immneg0 : PatLeaf<(f64 fpimm), [{
62 return N->isExactlyValue(-0.0);
63}]>;
64
65def fp64imm1 : PatLeaf<(f64 fpimm), [{
66 return N->isExactlyValue(+1.0);
67}]>;
68
69def fp64immneg1 : PatLeaf<(f64 fpimm), [{
70 return N->isExactlyValue(-1.0);
71}]>;
72
73def extloadf64f32 : PatFrag<(ops node:$ptr), (f64 (extload node:$ptr, f32))>;
74
Evan Chengd5847812006-02-21 20:00:20 +000075// Some 'special' instructions
76let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
77 def FP_TO_INT16_IN_MEM : I<0, Pseudo,
78 (ops i16mem:$dst, RFP:$src),
79 "#FP_TO_INT16_IN_MEM PSEUDO!",
80 [(X86fp_to_i16mem RFP:$src, addr:$dst)]>;
81 def FP_TO_INT32_IN_MEM : I<0, Pseudo,
82 (ops i32mem:$dst, RFP:$src),
83 "#FP_TO_INT32_IN_MEM PSEUDO!",
84 [(X86fp_to_i32mem RFP:$src, addr:$dst)]>;
85 def FP_TO_INT64_IN_MEM : I<0, Pseudo,
86 (ops i64mem:$dst, RFP:$src),
87 "#FP_TO_INT64_IN_MEM PSEUDO!",
88 [(X86fp_to_i64mem RFP:$src, addr:$dst)]>;
89}
90
91let isTerminator = 1 in
92 let Defs = [FP0, FP1, FP2, FP3, FP4, FP5, FP6] in
93 def FP_REG_KILL : I<0, Pseudo, (ops), "#FP_REG_KILL", []>;
94
Evan Cheng6e595b92006-02-21 19:13:53 +000095// All FP Stack operations are represented with two instructions here. The
96// first instruction, generated by the instruction selector, uses "RFP"
97// registers: a traditional register file to reference floating point values.
98// These instructions are all psuedo instructions and use the "Fp" prefix.
99// The second instruction is defined with FPI, which is the actual instruction
100// emitted by the assembler. The FP stackifier pass converts one to the other
101// after register allocation occurs.
102//
103// Note that the FpI instruction should have instruction selection info (e.g.
104// a pattern) and the FPI instruction should have emission info (e.g. opcode
105// encoding and asm printing info).
106
107// FPI - Floating Point Instruction template.
108class FPI<bits<8> o, Format F, dag ops, string asm> : I<o, F, ops, asm, []> {}
109
110// FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
111class FpI_<dag ops, FPFormat fp, list<dag> pattern>
112 : X86Inst<0, Pseudo, NoImm, ops, ""> {
113 let FPForm = fp; let FPFormBits = FPForm.Value;
114 let Pattern = pattern;
115}
116
117// Random Pseudo Instructions.
118def FpGETRESULT : FpI_<(ops RFP:$dst), SpecialFP,
119 [(set RFP:$dst, X86fpget)]>; // FPR = ST(0)
120
121let noResults = 1 in
122 def FpSETRESULT : FpI_<(ops RFP:$src), SpecialFP,
123 [(X86fpset RFP:$src)]>, Imp<[], [ST0]>; // ST(0) = FPR
124
125// FpI - Floating Point Psuedo Instruction template. Predicated on FPStack.
126class FpI<dag ops, FPFormat fp, list<dag> pattern> :
127 FpI_<ops, fp, pattern>, Requires<[FPStack]>;
128
129
130def FpMOV : FpI<(ops RFP:$dst, RFP:$src), SpecialFP, []>; // f1 = fmov f2
131
132// Arithmetic
133// Add, Sub, Mul, Div.
134def FpADD : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
135 [(set RFP:$dst, (fadd RFP:$src1, RFP:$src2))]>;
136def FpSUB : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
137 [(set RFP:$dst, (fsub RFP:$src1, RFP:$src2))]>;
138def FpMUL : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
139 [(set RFP:$dst, (fmul RFP:$src1, RFP:$src2))]>;
140def FpDIV : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), TwoArgFP,
141 [(set RFP:$dst, (fdiv RFP:$src1, RFP:$src2))]>;
142
143class FPST0rInst<bits<8> o, string asm>
144 : FPI<o, AddRegFrm, (ops RST:$op), asm>, D8;
145class FPrST0Inst<bits<8> o, string asm>
146 : FPI<o, AddRegFrm, (ops RST:$op), asm>, DC;
147class FPrST0PInst<bits<8> o, string asm>
148 : FPI<o, AddRegFrm, (ops RST:$op), asm>, DE;
149
150// Binary Ops with a memory source.
151def FpADD32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
152 [(set RFP:$dst, (fadd RFP:$src1,
153 (extloadf64f32 addr:$src2)))]>;
154 // ST(0) = ST(0) + [mem32]
155def FpADD64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
156 [(set RFP:$dst, (fadd RFP:$src1, (loadf64 addr:$src2)))]>;
157 // ST(0) = ST(0) + [mem64]
158def FpMUL32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
159 [(set RFP:$dst, (fmul RFP:$src1,
160 (extloadf64f32 addr:$src2)))]>;
161 // ST(0) = ST(0) * [mem32]
162def FpMUL64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
163 [(set RFP:$dst, (fmul RFP:$src1, (loadf64 addr:$src2)))]>;
164 // ST(0) = ST(0) * [mem64]
165def FpSUB32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
166 [(set RFP:$dst, (fsub RFP:$src1,
167 (extloadf64f32 addr:$src2)))]>;
168 // ST(0) = ST(0) - [mem32]
169def FpSUB64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
170 [(set RFP:$dst, (fsub RFP:$src1, (loadf64 addr:$src2)))]>;
171 // ST(0) = ST(0) - [mem64]
172def FpSUBR32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
173 [(set RFP:$dst, (fsub (extloadf64f32 addr:$src2),
174 RFP:$src1))]>;
175 // ST(0) = [mem32] - ST(0)
176def FpSUBR64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
177 [(set RFP:$dst, (fsub (loadf64 addr:$src2), RFP:$src1))]>;
178 // ST(0) = [mem64] - ST(0)
179def FpDIV32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
180 [(set RFP:$dst, (fdiv RFP:$src1,
181 (extloadf64f32 addr:$src2)))]>;
182 // ST(0) = ST(0) / [mem32]
183def FpDIV64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
184 [(set RFP:$dst, (fdiv RFP:$src1, (loadf64 addr:$src2)))]>;
185 // ST(0) = ST(0) / [mem64]
186def FpDIVR32m : FpI<(ops RFP:$dst, RFP:$src1, f32mem:$src2), OneArgFPRW,
187 [(set RFP:$dst, (fdiv (extloadf64f32 addr:$src2),
188 RFP:$src1))]>;
189 // ST(0) = [mem32] / ST(0)
190def FpDIVR64m : FpI<(ops RFP:$dst, RFP:$src1, f64mem:$src2), OneArgFPRW,
191 [(set RFP:$dst, (fdiv (loadf64 addr:$src2), RFP:$src1))]>;
192 // ST(0) = [mem64] / ST(0)
193
194
195def FADD32m : FPI<0xD8, MRM0m, (ops f32mem:$src), "fadd{s} $src">;
196def FADD64m : FPI<0xDC, MRM0m, (ops f64mem:$src), "fadd{l} $src">;
197def FMUL32m : FPI<0xD8, MRM1m, (ops f32mem:$src), "fmul{s} $src">;
198def FMUL64m : FPI<0xDC, MRM1m, (ops f64mem:$src), "fmul{l} $src">;
199def FSUB32m : FPI<0xD8, MRM4m, (ops f32mem:$src), "fsub{s} $src">;
200def FSUB64m : FPI<0xDC, MRM4m, (ops f64mem:$src), "fsub{l} $src">;
201def FSUBR32m : FPI<0xD8, MRM5m, (ops f32mem:$src), "fsubr{s} $src">;
202def FSUBR64m : FPI<0xDC, MRM5m, (ops f64mem:$src), "fsubr{l} $src">;
203def FDIV32m : FPI<0xD8, MRM6m, (ops f32mem:$src), "fdiv{s} $src">;
204def FDIV64m : FPI<0xDC, MRM6m, (ops f64mem:$src), "fdiv{l} $src">;
205def FDIVR32m : FPI<0xD8, MRM7m, (ops f32mem:$src), "fdivr{s} $src">;
206def FDIVR64m : FPI<0xDC, MRM7m, (ops f64mem:$src), "fdivr{l} $src">;
207
208def FpIADD16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
209 [(set RFP:$dst, (fadd RFP:$src1,
210 (X86fild addr:$src2, i16)))]>;
211 // ST(0) = ST(0) + [mem16int]
212def FpIADD32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
213 [(set RFP:$dst, (fadd RFP:$src1,
214 (X86fild addr:$src2, i32)))]>;
215 // ST(0) = ST(0) + [mem32int]
216def FpIMUL16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
217 [(set RFP:$dst, (fmul RFP:$src1,
218 (X86fild addr:$src2, i16)))]>;
219 // ST(0) = ST(0) * [mem16int]
220def FpIMUL32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
221 [(set RFP:$dst, (fmul RFP:$src1,
222 (X86fild addr:$src2, i32)))]>;
223 // ST(0) = ST(0) * [mem32int]
224def FpISUB16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
225 [(set RFP:$dst, (fsub RFP:$src1,
226 (X86fild addr:$src2, i16)))]>;
227 // ST(0) = ST(0) - [mem16int]
228def FpISUB32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
229 [(set RFP:$dst, (fsub RFP:$src1,
230 (X86fild addr:$src2, i32)))]>;
231 // ST(0) = ST(0) - [mem32int]
232def FpISUBR16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
233 [(set RFP:$dst, (fsub (X86fild addr:$src2, i16),
234 RFP:$src1))]>;
235 // ST(0) = [mem16int] - ST(0)
236def FpISUBR32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
237 [(set RFP:$dst, (fsub (X86fild addr:$src2, i32),
238 RFP:$src1))]>;
239 // ST(0) = [mem32int] - ST(0)
240def FpIDIV16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
241 [(set RFP:$dst, (fdiv RFP:$src1,
242 (X86fild addr:$src2, i16)))]>;
243 // ST(0) = ST(0) / [mem16int]
244def FpIDIV32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
245 [(set RFP:$dst, (fdiv RFP:$src1,
246 (X86fild addr:$src2, i32)))]>;
247 // ST(0) = ST(0) / [mem32int]
248def FpIDIVR16m : FpI<(ops RFP:$dst, RFP:$src1, i16mem:$src2), OneArgFPRW,
249 [(set RFP:$dst, (fdiv (X86fild addr:$src2, i16),
250 RFP:$src1))]>;
251 // ST(0) = [mem16int] / ST(0)
252def FpIDIVR32m : FpI<(ops RFP:$dst, RFP:$src1, i32mem:$src2), OneArgFPRW,
253 [(set RFP:$dst, (fdiv (X86fild addr:$src2, i32),
254 RFP:$src1))]>;
255 // ST(0) = [mem32int] / ST(0)
256
257def FIADD16m : FPI<0xDE, MRM0m, (ops i16mem:$src), "fiadd{s} $src">;
258def FIADD32m : FPI<0xDA, MRM0m, (ops i32mem:$src), "fiadd{l} $src">;
259def FIMUL16m : FPI<0xDE, MRM1m, (ops i16mem:$src), "fimul{s} $src">;
260def FIMUL32m : FPI<0xDA, MRM1m, (ops i32mem:$src), "fimul{l} $src">;
261def FISUB16m : FPI<0xDE, MRM4m, (ops i16mem:$src), "fisub{s} $src">;
262def FISUB32m : FPI<0xDA, MRM4m, (ops i32mem:$src), "fisub{l} $src">;
263def FISUBR16m : FPI<0xDE, MRM5m, (ops i16mem:$src), "fisubr{s} $src">;
264def FISUBR32m : FPI<0xDA, MRM5m, (ops i32mem:$src), "fisubr{l} $src">;
265def FIDIV16m : FPI<0xDE, MRM6m, (ops i16mem:$src), "fidiv{s} $src">;
266def FIDIV32m : FPI<0xDA, MRM6m, (ops i32mem:$src), "fidiv{l} $src">;
267def FIDIVR16m : FPI<0xDE, MRM7m, (ops i16mem:$src), "fidivr{s} $src">;
268def FIDIVR32m : FPI<0xDA, MRM7m, (ops i32mem:$src), "fidivr{l} $src">;
269
270// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
271// of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
272// we have to put some 'r's in and take them out of weird places.
273def FADDST0r : FPST0rInst <0xC0, "fadd $op">;
274def FADDrST0 : FPrST0Inst <0xC0, "fadd {%st(0), $op|$op, %ST(0)}">;
275def FADDPrST0 : FPrST0PInst<0xC0, "faddp $op">;
276def FSUBRST0r : FPST0rInst <0xE8, "fsubr $op">;
277def FSUBrST0 : FPrST0Inst <0xE8, "fsub{r} {%st(0), $op|$op, %ST(0)}">;
278def FSUBPrST0 : FPrST0PInst<0xE8, "fsub{r}p $op">;
279def FSUBST0r : FPST0rInst <0xE0, "fsub $op">;
280def FSUBRrST0 : FPrST0Inst <0xE0, "fsub{|r} {%st(0), $op|$op, %ST(0)}">;
281def FSUBRPrST0 : FPrST0PInst<0xE0, "fsub{|r}p $op">;
282def FMULST0r : FPST0rInst <0xC8, "fmul $op">;
283def FMULrST0 : FPrST0Inst <0xC8, "fmul {%st(0), $op|$op, %ST(0)}">;
284def FMULPrST0 : FPrST0PInst<0xC8, "fmulp $op">;
285def FDIVRST0r : FPST0rInst <0xF8, "fdivr $op">;
286def FDIVrST0 : FPrST0Inst <0xF8, "fdiv{r} {%st(0), $op|$op, %ST(0)}">;
287def FDIVPrST0 : FPrST0PInst<0xF8, "fdiv{r}p $op">;
288def FDIVST0r : FPST0rInst <0xF0, "fdiv $op">;
289def FDIVRrST0 : FPrST0Inst <0xF0, "fdiv{|r} {%st(0), $op|$op, %ST(0)}">;
290def FDIVRPrST0 : FPrST0PInst<0xF0, "fdiv{|r}p $op">;
291
292
293// Unary operations.
294def FpCHS : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
295 [(set RFP:$dst, (fneg RFP:$src))]>;
296def FpABS : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
297 [(set RFP:$dst, (fabs RFP:$src))]>;
298def FpSQRT : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
299 [(set RFP:$dst, (fsqrt RFP:$src))]>;
300def FpSIN : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
301 [(set RFP:$dst, (fsin RFP:$src))]>;
302def FpCOS : FpI<(ops RFP:$dst, RFP:$src), OneArgFPRW,
303 [(set RFP:$dst, (fcos RFP:$src))]>;
304def FpTST : FpI<(ops RFP:$src), OneArgFP,
305 []>;
306
307def FCHS : FPI<0xE0, RawFrm, (ops), "fchs">, D9;
308def FABS : FPI<0xE1, RawFrm, (ops), "fabs">, D9;
309def FSQRT : FPI<0xFA, RawFrm, (ops), "fsqrt">, D9;
310def FSIN : FPI<0xFE, RawFrm, (ops), "fsin">, D9;
311def FCOS : FPI<0xFF, RawFrm, (ops), "fcos">, D9;
312def FTST : FPI<0xE4, RawFrm, (ops), "ftst">, D9;
313
314
315// Floating point cmovs.
316let isTwoAddress = 1 in {
317 def FpCMOVB : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
318 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
319 X86_COND_B))]>;
320 def FpCMOVBE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
321 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
322 X86_COND_BE))]>;
323 def FpCMOVE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
324 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
325 X86_COND_E))]>;
326 def FpCMOVP : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
327 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
328 X86_COND_P))]>;
329 def FpCMOVNB : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
330 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
331 X86_COND_AE))]>;
332 def FpCMOVNBE: FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
333 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
334 X86_COND_A))]>;
335 def FpCMOVNE : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
336 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
337 X86_COND_NE))]>;
338 def FpCMOVNP : FpI<(ops RFP:$dst, RFP:$src1, RFP:$src2), CondMovFP,
339 [(set RFP:$dst, (X86cmov RFP:$src1, RFP:$src2,
340 X86_COND_NP))]>;
341}
342
343def FCMOVB : FPI<0xC0, AddRegFrm, (ops RST:$op),
344 "fcmovb {$op, %st(0)|%ST(0), $op}">, DA;
345def FCMOVBE : FPI<0xD0, AddRegFrm, (ops RST:$op),
346 "fcmovbe {$op, %st(0)|%ST(0), $op}">, DA;
347def FCMOVE : FPI<0xC8, AddRegFrm, (ops RST:$op),
348 "fcmove {$op, %st(0)|%ST(0), $op}">, DA;
349def FCMOVP : FPI<0xD8, AddRegFrm, (ops RST:$op),
350 "fcmovu {$op, %st(0)|%ST(0), $op}">, DA;
351def FCMOVNB : FPI<0xC0, AddRegFrm, (ops RST:$op),
352 "fcmovnb {$op, %st(0)|%ST(0), $op}">, DB;
353def FCMOVNBE : FPI<0xD0, AddRegFrm, (ops RST:$op),
354 "fcmovnbe {$op, %st(0)|%ST(0), $op}">, DB;
355def FCMOVNE : FPI<0xC8, AddRegFrm, (ops RST:$op),
356 "fcmovne {$op, %st(0)|%ST(0), $op}">, DB;
357def FCMOVNP : FPI<0xD8, AddRegFrm, (ops RST:$op),
358 "fcmovnu {$op, %st(0)|%ST(0), $op}">, DB;
359
360// Floating point loads & stores.
361def FpLD32m : FpI<(ops RFP:$dst, f32mem:$src), ZeroArgFP,
362 [(set RFP:$dst, (extloadf64f32 addr:$src))]>;
363def FpLD64m : FpI<(ops RFP:$dst, f64mem:$src), ZeroArgFP,
364 [(set RFP:$dst, (loadf64 addr:$src))]>;
365def FpILD16m : FpI<(ops RFP:$dst, i16mem:$src), ZeroArgFP,
366 [(set RFP:$dst, (X86fild addr:$src, i16))]>;
367def FpILD32m : FpI<(ops RFP:$dst, i32mem:$src), ZeroArgFP,
368 [(set RFP:$dst, (X86fild addr:$src, i32))]>;
369def FpILD64m : FpI<(ops RFP:$dst, i64mem:$src), ZeroArgFP,
370 [(set RFP:$dst, (X86fild addr:$src, i64))]>;
371
372def FpST32m : FpI<(ops f32mem:$op, RFP:$src), OneArgFP,
373 [(truncstore RFP:$src, addr:$op, f32)]>;
374def FpST64m : FpI<(ops f64mem:$op, RFP:$src), OneArgFP,
375 [(store RFP:$src, addr:$op)]>;
376
377def FpSTP32m : FpI<(ops f32mem:$op, RFP:$src), OneArgFP, []>;
378def FpSTP64m : FpI<(ops f64mem:$op, RFP:$src), OneArgFP, []>;
379def FpIST16m : FpI<(ops i16mem:$op, RFP:$src), OneArgFP, []>;
380def FpIST32m : FpI<(ops i32mem:$op, RFP:$src), OneArgFP, []>;
381def FpIST64m : FpI<(ops i64mem:$op, RFP:$src), OneArgFP, []>;
382
383def FLD32m : FPI<0xD9, MRM0m, (ops f32mem:$src), "fld{s} $src">;
384def FLD64m : FPI<0xDD, MRM0m, (ops f64mem:$src), "fld{l} $src">;
385def FILD16m : FPI<0xDF, MRM0m, (ops i16mem:$src), "fild{s} $src">;
386def FILD32m : FPI<0xDB, MRM0m, (ops i32mem:$src), "fild{l} $src">;
387def FILD64m : FPI<0xDF, MRM5m, (ops i64mem:$src), "fild{ll} $src">;
388def FST32m : FPI<0xD9, MRM2m, (ops f32mem:$dst), "fst{s} $dst">;
389def FST64m : FPI<0xDD, MRM2m, (ops f64mem:$dst), "fst{l} $dst">;
390def FSTP32m : FPI<0xD9, MRM3m, (ops f32mem:$dst), "fstp{s} $dst">;
391def FSTP64m : FPI<0xDD, MRM3m, (ops f64mem:$dst), "fstp{l} $dst">;
392def FIST16m : FPI<0xDF, MRM2m, (ops i16mem:$dst), "fist{s} $dst">;
393def FIST32m : FPI<0xDB, MRM2m, (ops i32mem:$dst), "fist{l} $dst">;
394def FISTP16m : FPI<0xDF, MRM3m, (ops i16mem:$dst), "fistp{s} $dst">;
395def FISTP32m : FPI<0xDB, MRM3m, (ops i32mem:$dst), "fistp{l} $dst">;
396def FISTP64m : FPI<0xDF, MRM7m, (ops i64mem:$dst), "fistp{ll} $dst">;
397
398// FISTTP requires SSE3 even though it's a FPStack op.
399def FpISTT16m : FpI_<(ops i16mem:$op, RFP:$src), OneArgFP,
400 [(X86fp_to_i16mem RFP:$src, addr:$op)]>,
401 Requires<[HasSSE3]>;
402def FpISTT32m : FpI_<(ops i32mem:$op, RFP:$src), OneArgFP,
403 [(X86fp_to_i32mem RFP:$src, addr:$op)]>,
404 Requires<[HasSSE3]>;
405def FpISTT64m : FpI_<(ops i64mem:$op, RFP:$src), OneArgFP,
406 [(X86fp_to_i64mem RFP:$src, addr:$op)]>,
407 Requires<[HasSSE3]>;
408
409def FISTTP16m : FPI<0xDF, MRM1m, (ops i16mem:$dst), "fisttp{s} $dst">;
410def FISTTP32m : FPI<0xDB, MRM1m, (ops i32mem:$dst), "fisttp{l} $dst">;
411def FISTTP64m : FPI<0xDD, MRM1m, (ops i64mem:$dst), "fisttp{ll} $dst">;
412
413// FP Stack manipulation instructions.
414def FLDrr : FPI<0xC0, AddRegFrm, (ops RST:$op), "fld $op">, D9;
415def FSTrr : FPI<0xD0, AddRegFrm, (ops RST:$op), "fst $op">, DD;
416def FSTPrr : FPI<0xD8, AddRegFrm, (ops RST:$op), "fstp $op">, DD;
417def FXCH : FPI<0xC8, AddRegFrm, (ops RST:$op), "fxch $op">, D9;
418
419// Floating point constant loads.
420def FpLD0 : FpI<(ops RFP:$dst), ZeroArgFP,
421 [(set RFP:$dst, fp64imm0)]>;
422def FpLD1 : FpI<(ops RFP:$dst), ZeroArgFP,
423 [(set RFP:$dst, fp64imm1)]>;
424
425def FLD0 : FPI<0xEE, RawFrm, (ops), "fldz">, D9;
426def FLD1 : FPI<0xE8, RawFrm, (ops), "fld1">, D9;
427
428
429// Floating point compares.
430def FpUCOMr : FpI<(ops RFP:$lhs, RFP:$rhs), CompareFP,
431 []>; // FPSW = cmp ST(0) with ST(i)
432def FpUCOMIr : FpI<(ops RFP:$lhs, RFP:$rhs), CompareFP,
433 [(X86cmp RFP:$lhs, RFP:$rhs)]>; // CC = cmp ST(0) with ST(i)
434
435def FUCOMr : FPI<0xE0, AddRegFrm, // FPSW = cmp ST(0) with ST(i)
436 (ops RST:$reg),
437 "fucom $reg">, DD, Imp<[ST0],[]>;
438def FUCOMPr : FPI<0xE8, AddRegFrm, // FPSW = cmp ST(0) with ST(i), pop
439 (ops RST:$reg),
440 "fucomp $reg">, DD, Imp<[ST0],[]>;
441def FUCOMPPr : FPI<0xE9, RawFrm, // cmp ST(0) with ST(1), pop, pop
442 (ops),
443 "fucompp">, DA, Imp<[ST0],[]>;
444
445def FUCOMIr : FPI<0xE8, AddRegFrm, // CC = cmp ST(0) with ST(i)
446 (ops RST:$reg),
447 "fucomi {$reg, %st(0)|%ST(0), $reg}">, DB, Imp<[ST0],[]>;
448def FUCOMIPr : FPI<0xE8, AddRegFrm, // CC = cmp ST(0) with ST(i), pop
449 (ops RST:$reg),
450 "fucomip {$reg, %st(0)|%ST(0), $reg}">, DF, Imp<[ST0],[]>;
451
452
453// Floating point flag ops.
454def FNSTSW8r : I<0xE0, RawFrm, // AX = fp flags
455 (ops), "fnstsw", []>, DF, Imp<[],[AX]>;
456
457def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
458 (ops i16mem:$dst), "fnstcw $dst", []>;
459def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
460 (ops i16mem:$dst), "fldcw $dst", []>;
Evan Chengd5847812006-02-21 20:00:20 +0000461
462//===----------------------------------------------------------------------===//
463// Non-Instruction Patterns
464//===----------------------------------------------------------------------===//
465
466// Required for RET of f32 / f64 values.
467def : Pat<(X86fld addr:$src, f32), (FpLD32m addr:$src)>;
468def : Pat<(X86fld addr:$src, f64), (FpLD64m addr:$src)>;
469
470// Required for CALL which return f32 / f64 values.
471def : Pat<(X86fst RFP:$src, addr:$op, f32), (FpST32m addr:$op, RFP:$src)>;
472def : Pat<(X86fst RFP:$src, addr:$op, f64), (FpST64m addr:$op, RFP:$src)>;
473
474// Floating point constant -0.0 and -1.0
475def : Pat<(f64 fp64immneg0), (FpCHS (FpLD0))>, Requires<[FPStack]>;
476def : Pat<(f64 fp64immneg1), (FpCHS (FpLD1))>, Requires<[FPStack]>;
477
478// Used to conv. i64 to f64 since there isn't a SSE version.
479def : Pat<(X86fildflag addr:$src, i64), (FpILD64m addr:$src)>;