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