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