]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Target/X86/X86InstrFPStack.td
THIS BRANCH IS OBSOLETE, PLEASE READ:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Target / X86 / X86InstrFPStack.td
1 //===- X86InstrFPStack.td - FPU Instruction Set ------------*- tablegen -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file describes the X86 x87 FPU instruction set, defining the
10 // instructions, and properties of the instructions which are needed for code
11 // generation, machine code emission, and analysis.
12 //
13 //===----------------------------------------------------------------------===//
14
15 //===----------------------------------------------------------------------===//
16 // FPStack specific DAG Nodes.
17 //===----------------------------------------------------------------------===//
18
19 def SDTX86Fld       : SDTypeProfile<1, 1, [SDTCisFP<0>,
20                                            SDTCisPtrTy<1>]>;
21 def SDTX86Fst       : SDTypeProfile<0, 2, [SDTCisFP<0>,
22                                            SDTCisPtrTy<1>]>;
23 def SDTX86Fild      : SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
24 def SDTX86Fist      : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
25
26 def SDTX86CwdStore  : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
27
28 def X86fld          : SDNode<"X86ISD::FLD", SDTX86Fld,
29                              [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
30 def X86fst          : SDNode<"X86ISD::FST", SDTX86Fst,
31                              [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
32 def X86fild         : SDNode<"X86ISD::FILD", SDTX86Fild,
33                              [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
34 def X86fist         : SDNode<"X86ISD::FIST", SDTX86Fist,
35                              [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
36 def X86fp_to_mem : SDNode<"X86ISD::FP_TO_INT_IN_MEM", SDTX86Fst,
37                           [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
38 def X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m",          SDTX86CwdStore,
39                              [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
40                               SDNPMemOperand]>;
41
42 def X86fstf32 : PatFrag<(ops node:$val, node:$ptr),
43                         (X86fst node:$val, node:$ptr), [{
44   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
45 }]>;
46 def X86fstf64 : PatFrag<(ops node:$val, node:$ptr),
47                         (X86fst node:$val, node:$ptr), [{
48   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
49 }]>;
50 def X86fstf80 : PatFrag<(ops node:$val, node:$ptr),
51                         (X86fst node:$val, node:$ptr), [{
52   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
53 }]>;
54
55 def X86fldf32 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
56   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
57 }]>;
58 def X86fldf64 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
59   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
60 }]>;
61 def X86fldf80 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
62   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
63 }]>;
64
65 def X86fild16 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
66   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
67 }]>;
68 def X86fild32 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
69   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
70 }]>;
71 def X86fild64 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
72   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
73 }]>;
74
75 def X86fist32 : PatFrag<(ops node:$val, node:$ptr),
76                         (X86fist node:$val, node:$ptr), [{
77   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
78 }]>;
79
80 def X86fist64 : PatFrag<(ops node:$val, node:$ptr),
81                         (X86fist node:$val, node:$ptr), [{
82   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
83 }]>;
84
85 def X86fp_to_i16mem : PatFrag<(ops node:$val, node:$ptr),
86                               (X86fp_to_mem node:$val, node:$ptr), [{
87   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
88 }]>;
89 def X86fp_to_i32mem : PatFrag<(ops node:$val, node:$ptr),
90                               (X86fp_to_mem node:$val, node:$ptr), [{
91   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
92 }]>;
93 def X86fp_to_i64mem : PatFrag<(ops node:$val, node:$ptr),
94                               (X86fp_to_mem node:$val, node:$ptr), [{
95   return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
96 }]>;
97
98 //===----------------------------------------------------------------------===//
99 // FPStack pattern fragments
100 //===----------------------------------------------------------------------===//
101
102 def fpimm0 : FPImmLeaf<fAny, [{
103   return Imm.isExactlyValue(+0.0);
104 }]>;
105
106 def fpimmneg0 : FPImmLeaf<fAny, [{
107   return Imm.isExactlyValue(-0.0);
108 }]>;
109
110 def fpimm1 : FPImmLeaf<fAny, [{
111   return Imm.isExactlyValue(+1.0);
112 }]>;
113
114 def fpimmneg1 : FPImmLeaf<fAny, [{
115   return Imm.isExactlyValue(-1.0);
116 }]>;
117
118 // Some 'special' instructions - expanded after instruction selection.
119 // Clobbers EFLAGS due to OR instruction used internally.
120 // FIXME: Can we model this in SelectionDAG?
121 let usesCustomInserter = 1, hasNoSchedulingInfo = 1, Defs = [EFLAGS] in {
122   def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
123                               [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
124   def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
125                               [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
126   def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
127                               [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
128   def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
129                               [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
130   def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
131                               [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
132   def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
133                               [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
134   def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
135                               [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
136   def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
137                               [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
138   def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
139                               [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
140 }
141
142 // All FP Stack operations are represented with four instructions here.  The
143 // first three instructions, generated by the instruction selector, use "RFP32"
144 // "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
145 // 64-bit or 80-bit floating point values.  These sizes apply to the values,
146 // not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
147 // copied to each other without losing information.  These instructions are all
148 // pseudo instructions and use the "_Fp" suffix.
149 // In some cases there are additional variants with a mixture of different
150 // register sizes.
151 // The second instruction is defined with FPI, which is the actual instruction
152 // emitted by the assembler.  These use "RST" registers, although frequently
153 // the actual register(s) used are implicit.  These are always 80 bits.
154 // The FP stackifier pass converts one to the other after register allocation
155 // occurs.
156 //
157 // Note that the FpI instruction should have instruction selection info (e.g.
158 // a pattern) and the FPI instruction should have emission info (e.g. opcode
159 // encoding and asm printing info).
160
161 // FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
162 // f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
163 // f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
164 // f80 instructions cannot use SSE and use neither of these.
165 class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
166              FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
167 class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
168              FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
169
170 // Factoring for arithmetic.
171 multiclass FPBinary_rr<SDNode OpNode> {
172 // Register op register -> register
173 // These are separated out because they have no reversed form.
174 def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
175                 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
176 def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
177                 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
178 def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
179                 [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
180 }
181 // The FopST0 series are not included here because of the irregularities
182 // in where the 'r' goes in assembly output.
183 // These instructions cannot address 80-bit memory.
184 multiclass FPBinary<SDNode OpNode, Format fp, string asmstring,
185                     bit Forward = 1> {
186 // ST(0) = ST(0) + [mem]
187 def _Fp32m  : FpIf32<(outs RFP32:$dst),
188                      (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
189                   [!if(Forward,
190                        (set RFP32:$dst,
191                         (OpNode RFP32:$src1, (loadf32 addr:$src2))),
192                        (set RFP32:$dst,
193                         (OpNode (loadf32 addr:$src2), RFP32:$src1)))]>;
194 def _Fp64m  : FpIf64<(outs RFP64:$dst),
195                      (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
196                   [!if(Forward,
197                        (set RFP64:$dst,
198                         (OpNode RFP64:$src1, (loadf64 addr:$src2))),
199                        (set RFP64:$dst,
200                         (OpNode (loadf64 addr:$src2), RFP64:$src1)))]>;
201 def _Fp64m32: FpIf64<(outs RFP64:$dst),
202                      (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
203                   [!if(Forward,
204                        (set RFP64:$dst,
205                         (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2)))),
206                        (set RFP64:$dst,
207                         (OpNode (f64 (extloadf32 addr:$src2)), RFP64:$src1)))]>;
208 def _Fp80m32: FpI_<(outs RFP80:$dst),
209                    (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
210                   [!if(Forward,
211                        (set RFP80:$dst,
212                         (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2)))),
213                        (set RFP80:$dst,
214                         (OpNode (f80 (extloadf32 addr:$src2)), RFP80:$src1)))]>;
215 def _Fp80m64: FpI_<(outs RFP80:$dst),
216                    (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
217                   [!if(Forward,
218                        (set RFP80:$dst,
219                         (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2)))),
220                        (set RFP80:$dst,
221                         (OpNode (f80 (extloadf64 addr:$src2)), RFP80:$src1)))]>;
222 let mayLoad = 1 in
223 def _F32m  : FPI<0xD8, fp, (outs), (ins f32mem:$src),
224                  !strconcat("f", asmstring, "{s}\t$src")>;
225 let mayLoad = 1 in
226 def _F64m  : FPI<0xDC, fp, (outs), (ins f64mem:$src),
227                  !strconcat("f", asmstring, "{l}\t$src")>;
228 // ST(0) = ST(0) + [memint]
229 def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
230                        OneArgFPRW,
231                        [!if(Forward,
232                             (set RFP32:$dst,
233                              (OpNode RFP32:$src1, (X86fild16 addr:$src2))),
234                             (set RFP32:$dst,
235                              (OpNode (X86fild16 addr:$src2), RFP32:$src1)))]>;
236 def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
237                        OneArgFPRW,
238                        [!if(Forward,
239                             (set RFP32:$dst,
240                              (OpNode RFP32:$src1, (X86fild32 addr:$src2))),
241                             (set RFP32:$dst,
242                              (OpNode (X86fild32 addr:$src2), RFP32:$src1)))]>;
243 def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
244                        OneArgFPRW,
245                        [!if(Forward,
246                             (set RFP64:$dst,
247                              (OpNode RFP64:$src1, (X86fild16 addr:$src2))),
248                             (set RFP64:$dst,
249                              (OpNode (X86fild16 addr:$src2), RFP64:$src1)))]>;
250 def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
251                        OneArgFPRW,
252                        [!if(Forward,
253                             (set RFP64:$dst,
254                              (OpNode RFP64:$src1, (X86fild32 addr:$src2))),
255                             (set RFP64:$dst,
256                              (OpNode (X86fild32 addr:$src2), RFP64:$src1)))]>;
257 def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
258                      OneArgFPRW,
259                      [!if(Forward,
260                           (set RFP80:$dst,
261                            (OpNode RFP80:$src1, (X86fild16 addr:$src2))),
262                           (set RFP80:$dst,
263                            (OpNode (X86fild16 addr:$src2), RFP80:$src1)))]>;
264 def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
265                      OneArgFPRW,
266                      [!if(Forward,
267                           (set RFP80:$dst,
268                            (OpNode RFP80:$src1, (X86fild32 addr:$src2))),
269                           (set RFP80:$dst,
270                            (OpNode (X86fild32 addr:$src2), RFP80:$src1)))]>;
271 let mayLoad = 1 in
272 def _FI16m  : FPI<0xDE, fp, (outs), (ins i16mem:$src),
273                   !strconcat("fi", asmstring, "{s}\t$src")>;
274 let mayLoad = 1 in
275 def _FI32m  : FPI<0xDA, fp, (outs), (ins i32mem:$src),
276                   !strconcat("fi", asmstring, "{l}\t$src")>;
277 }
278
279 let Uses = [FPCW], mayRaiseFPException = 1 in {
280 // FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
281 // resources.
282 let hasNoSchedulingInfo = 1 in {
283 defm ADD : FPBinary_rr<any_fadd>;
284 defm SUB : FPBinary_rr<any_fsub>;
285 defm MUL : FPBinary_rr<any_fmul>;
286 defm DIV : FPBinary_rr<any_fdiv>;
287 }
288
289 // Sets the scheduling resources for the actual NAME#_F<size>m definitions.
290 let SchedRW = [WriteFAddLd] in {
291 defm ADD : FPBinary<any_fadd, MRM0m, "add">;
292 defm SUB : FPBinary<any_fsub, MRM4m, "sub">;
293 defm SUBR: FPBinary<any_fsub ,MRM5m, "subr", 0>;
294 }
295
296 let SchedRW = [WriteFMulLd] in {
297 defm MUL : FPBinary<any_fmul, MRM1m, "mul">;
298 }
299
300 let SchedRW = [WriteFDivLd] in {
301 defm DIV : FPBinary<any_fdiv, MRM6m, "div">;
302 defm DIVR: FPBinary<any_fdiv, MRM7m, "divr", 0>;
303 }
304 } // Uses = [FPCW], mayRaiseFPException = 1
305
306 class FPST0rInst<Format fp, string asm>
307   : FPI<0xD8, fp, (outs), (ins RSTi:$op), asm>;
308 class FPrST0Inst<Format fp, string asm>
309   : FPI<0xDC, fp, (outs), (ins RSTi:$op), asm>;
310 class FPrST0PInst<Format fp, string asm>
311   : FPI<0xDE, fp, (outs), (ins RSTi:$op), asm>;
312
313 // NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
314 // of some of the 'reverse' forms of the fsub and fdiv instructions.  As such,
315 // we have to put some 'r's in and take them out of weird places.
316 let SchedRW = [WriteFAdd], Uses = [FPCW], mayRaiseFPException = 1 in {
317 def ADD_FST0r   : FPST0rInst <MRM0r, "fadd\t{$op, %st|st, $op}">;
318 def ADD_FrST0   : FPrST0Inst <MRM0r, "fadd\t{%st, $op|$op, st}">;
319 def ADD_FPrST0  : FPrST0PInst<MRM0r, "faddp\t{%st, $op|$op, st}">;
320 def SUBR_FST0r  : FPST0rInst <MRM5r, "fsubr\t{$op, %st|st, $op}">;
321 def SUB_FrST0   : FPrST0Inst <MRM5r, "fsub{r}\t{%st, $op|$op, st}">;
322 def SUB_FPrST0  : FPrST0PInst<MRM5r, "fsub{r}p\t{%st, $op|$op, st}">;
323 def SUB_FST0r   : FPST0rInst <MRM4r, "fsub\t{$op, %st|st, $op}">;
324 def SUBR_FrST0  : FPrST0Inst <MRM4r, "fsub{|r}\t{%st, $op|$op, st}">;
325 def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t{%st, $op|$op, st}">;
326 } // SchedRW
327 let SchedRW = [WriteFCom], Uses = [FPCW], mayRaiseFPException = 1 in {
328 def COM_FST0r   : FPST0rInst <MRM2r, "fcom\t$op">;
329 def COMP_FST0r  : FPST0rInst <MRM3r, "fcomp\t$op">;
330 } // SchedRW
331 let SchedRW = [WriteFMul], Uses = [FPCW], mayRaiseFPException = 1 in {
332 def MUL_FST0r   : FPST0rInst <MRM1r, "fmul\t{$op, %st|st, $op}">;
333 def MUL_FrST0   : FPrST0Inst <MRM1r, "fmul\t{%st, $op|$op, st}">;
334 def MUL_FPrST0  : FPrST0PInst<MRM1r, "fmulp\t{%st, $op|$op, st}">;
335 } // SchedRW
336 let SchedRW = [WriteFDiv], Uses = [FPCW], mayRaiseFPException = 1 in {
337 def DIVR_FST0r  : FPST0rInst <MRM7r, "fdivr\t{$op, %st|st, $op}">;
338 def DIV_FrST0   : FPrST0Inst <MRM7r, "fdiv{r}\t{%st, $op|$op, st}">;
339 def DIV_FPrST0  : FPrST0PInst<MRM7r, "fdiv{r}p\t{%st, $op|$op, st}">;
340 def DIV_FST0r   : FPST0rInst <MRM6r, "fdiv\t{$op, %st|st, $op}">;
341 def DIVR_FrST0  : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st, $op|$op, st}">;
342 def DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t{%st, $op|$op, st}">;
343 } // SchedRW
344
345 // Unary operations.
346 multiclass FPUnary<SDNode OpNode, Format fp, string asmstring> {
347 def _Fp32  : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
348                  [(set RFP32:$dst, (OpNode RFP32:$src))]>;
349 def _Fp64  : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
350                  [(set RFP64:$dst, (OpNode RFP64:$src))]>;
351 def _Fp80  : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
352                  [(set RFP80:$dst, (OpNode RFP80:$src))]>;
353 def _F     : FPI<0xD9, fp, (outs), (ins), asmstring>;
354 }
355
356 let SchedRW = [WriteFSign] in {
357 defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
358 defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
359 }
360
361 let Uses = [FPCW], mayRaiseFPException = 1 in {
362 let SchedRW = [WriteFSqrt80] in
363 defm SQRT: FPUnary<any_fsqrt,MRM_FA, "fsqrt">;
364
365 let SchedRW = [WriteFCom] in {
366 let hasSideEffects = 0 in {
367 def TST_Fp32  : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
368 def TST_Fp64  : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
369 def TST_Fp80  : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
370 } // hasSideEffects
371
372 def TST_F  : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
373 } // SchedRW
374 } // Uses = [FPCW], mayRaiseFPException = 1
375
376 // Versions of FP instructions that take a single memory operand.  Added for the
377 //   disassembler; remove as they are included with patterns elsewhere.
378 let SchedRW = [WriteFComLd], Uses = [FPCW], mayRaiseFPException = 1,
379     mayLoad = 1 in {
380 def FCOM32m  : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
381 def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
382
383 def FCOM64m  : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
384 def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
385
386 def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
387 def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
388
389 def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
390 def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
391 } // SchedRW
392
393 let SchedRW = [WriteMicrocoded] in {
394 let Defs = [FPSW, FPCW], mayLoad = 1 in {
395 def FLDENVm  : FPI<0xD9, MRM4m, (outs), (ins f32mem:$src), "fldenv\t$src">;
396 def FRSTORm  : FPI<0xDD, MRM4m, (outs), (ins f32mem:$dst), "frstor\t$dst">;
397 }
398
399 let Defs = [FPSW, FPCW], Uses = [FPSW, FPCW], mayStore = 1 in {
400 def FSTENVm  : FPI<0xD9, MRM6m, (outs), (ins f32mem:$dst), "fnstenv\t$dst">;
401 def FSAVEm   : FPI<0xDD, MRM6m, (outs), (ins f32mem:$dst), "fnsave\t$dst">;
402 }
403
404 let Uses = [FPSW], mayStore = 1 in
405 def FNSTSWm  : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
406
407 let mayLoad = 1 in
408 def FBLDm    : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
409 let Uses = [FPCW] ,mayRaiseFPException = 1, mayStore = 1 in
410 def FBSTPm   : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
411 } // SchedRW
412
413 // Floating point cmovs.
414 class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
415   FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMov]>;
416 class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
417   FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMov]>;
418
419 multiclass FPCMov<PatLeaf cc> {
420   def _Fp32  : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
421                        CondMovFP,
422                      [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
423                                         cc, EFLAGS))]>;
424   def _Fp64  : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
425                        CondMovFP,
426                      [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
427                                         cc, EFLAGS))]>;
428   def _Fp80  : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
429                      CondMovFP,
430                      [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
431                                         cc, EFLAGS))]>,
432                                         Requires<[HasCMov]>;
433 }
434
435 let SchedRW = [WriteFCMOV] in {
436 let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
437 defm CMOVB  : FPCMov<X86_COND_B>;
438 defm CMOVBE : FPCMov<X86_COND_BE>;
439 defm CMOVE  : FPCMov<X86_COND_E>;
440 defm CMOVP  : FPCMov<X86_COND_P>;
441 defm CMOVNB : FPCMov<X86_COND_AE>;
442 defm CMOVNBE: FPCMov<X86_COND_A>;
443 defm CMOVNE : FPCMov<X86_COND_NE>;
444 defm CMOVNP : FPCMov<X86_COND_NP>;
445 } // Uses = [EFLAGS], Constraints = "$src1 = $dst"
446
447 let Predicates = [HasCMov] in {
448 // These are not factored because there's no clean way to pass DA/DB.
449 def CMOVB_F  : FPI<0xDA, MRM0r, (outs), (ins RSTi:$op),
450                   "fcmovb\t{$op, %st|st, $op}">;
451 def CMOVBE_F : FPI<0xDA, MRM2r, (outs), (ins RSTi:$op),
452                   "fcmovbe\t{$op, %st|st, $op}">;
453 def CMOVE_F  : FPI<0xDA, MRM1r, (outs), (ins RSTi:$op),
454                   "fcmove\t{$op, %st|st, $op}">;
455 def CMOVP_F  : FPI<0xDA, MRM3r, (outs), (ins RSTi:$op),
456                   "fcmovu\t{$op, %st|st, $op}">;
457 def CMOVNB_F : FPI<0xDB, MRM0r, (outs), (ins RSTi:$op),
458                   "fcmovnb\t{$op, %st|st, $op}">;
459 def CMOVNBE_F: FPI<0xDB, MRM2r, (outs), (ins RSTi:$op),
460                   "fcmovnbe\t{$op, %st|st, $op}">;
461 def CMOVNE_F : FPI<0xDB, MRM1r, (outs), (ins RSTi:$op),
462                   "fcmovne\t{$op, %st|st, $op}">;
463 def CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RSTi:$op),
464                   "fcmovnu\t{$op, %st|st, $op}">;
465 } // Predicates = [HasCMov]
466 } // SchedRW
467
468 let mayRaiseFPException = 1 in {
469 // Floating point loads & stores.
470 let SchedRW = [WriteLoad], Uses = [FPCW] in {
471 let canFoldAsLoad = 1 in {
472 def LD_Fp32m   : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
473                   [(set RFP32:$dst, (loadf32 addr:$src))]>;
474 def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
475                   [(set RFP64:$dst, (loadf64 addr:$src))]>;
476 def LD_Fp80m   : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
477                   [(set RFP80:$dst, (loadf80 addr:$src))]>;
478 } // canFoldAsLoad
479 def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
480                   [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
481 def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
482                   [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
483 def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
484                   [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
485 let mayRaiseFPException = 0 in {
486 def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
487                   [(set RFP32:$dst, (X86fild16 addr:$src))]>;
488 def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
489                   [(set RFP32:$dst, (X86fild32 addr:$src))]>;
490 def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
491                   [(set RFP32:$dst, (X86fild64 addr:$src))]>;
492 def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
493                   [(set RFP64:$dst, (X86fild16 addr:$src))]>;
494 def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
495                   [(set RFP64:$dst, (X86fild32 addr:$src))]>;
496 def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
497                   [(set RFP64:$dst, (X86fild64 addr:$src))]>;
498 def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
499                   [(set RFP80:$dst, (X86fild16 addr:$src))]>;
500 def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
501                   [(set RFP80:$dst, (X86fild32 addr:$src))]>;
502 def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
503                   [(set RFP80:$dst, (X86fild64 addr:$src))]>;
504 } // mayRaiseFPException = 0
505 } // SchedRW
506
507 let SchedRW = [WriteStore], Uses = [FPCW] in {
508 def ST_Fp32m   : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
509                   [(store RFP32:$src, addr:$op)]>;
510 def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
511                   [(truncstoref32 RFP64:$src, addr:$op)]>;
512 def ST_Fp64m   : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
513                   [(store RFP64:$src, addr:$op)]>;
514 def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
515                   [(truncstoref32 RFP80:$src, addr:$op)]>;
516 def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
517                   [(truncstoref64 RFP80:$src, addr:$op)]>;
518 // FST does not support 80-bit memory target; FSTP must be used.
519
520 let mayStore = 1, hasSideEffects = 0 in {
521 def ST_FpP32m    : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
522 def ST_FpP64m32  : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
523 def ST_FpP64m    : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
524 def ST_FpP80m32  : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
525 def ST_FpP80m64  : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
526 } // mayStore
527
528 def ST_FpP80m    : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
529                     [(store RFP80:$src, addr:$op)]>;
530
531 let mayStore = 1, hasSideEffects = 0 in {
532 def IST_Fp16m32  : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
533 def IST_Fp32m32  : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
534                           [(X86fist32 RFP32:$src, addr:$op)]>;
535 def IST_Fp64m32  : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
536                           [(X86fist64 RFP32:$src, addr:$op)]>;
537 def IST_Fp16m64  : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
538 def IST_Fp32m64  : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
539                           [(X86fist32 RFP64:$src, addr:$op)]>;
540 def IST_Fp64m64  : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
541                           [(X86fist64 RFP64:$src, addr:$op)]>;
542 def IST_Fp16m80  : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
543 def IST_Fp32m80  : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
544                         [(X86fist32 RFP80:$src, addr:$op)]>;
545 def IST_Fp64m80  : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
546                         [(X86fist64 RFP80:$src, addr:$op)]>;
547 } // mayStore
548 } // SchedRW, Uses = [FPCW]
549
550 let mayLoad = 1, SchedRW = [WriteLoad], Uses = [FPCW] in {
551 def LD_F32m   : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
552 def LD_F64m   : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
553 def LD_F80m   : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
554 let mayRaiseFPException = 0 in {
555 def ILD_F16m  : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
556 def ILD_F32m  : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
557 def ILD_F64m  : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
558 }
559 }
560 let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
561 def ST_F32m   : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
562 def ST_F64m   : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
563 def ST_FP32m  : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst">;
564 def ST_FP64m  : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst">;
565 def ST_FP80m  : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst">;
566 def IST_F16m  : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst">;
567 def IST_F32m  : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst">;
568 def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst">;
569 def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst">;
570 def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst">;
571 }
572
573 // FISTTP requires SSE3 even though it's a FPStack op.
574 let Predicates = [HasSSE3], SchedRW = [WriteStore], Uses = [FPCW] in {
575 def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
576                     [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
577 def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
578                     [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
579 def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
580                     [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
581 def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
582                     [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
583 def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
584                     [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
585 def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
586                     [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
587 def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
588                     [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
589 def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
590                     [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
591 def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
592                     [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
593 } // Predicates = [HasSSE3]
594
595 let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
596 def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst">;
597 def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst">;
598 def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll}\t$dst">;
599 }
600
601 // FP Stack manipulation instructions.
602 let SchedRW = [WriteMove], Uses = [FPCW] in {
603 def LD_Frr   : FPI<0xD9, MRM0r, (outs), (ins RSTi:$op), "fld\t$op">;
604 def ST_Frr   : FPI<0xDD, MRM2r, (outs), (ins RSTi:$op), "fst\t$op">;
605 def ST_FPrr  : FPI<0xDD, MRM3r, (outs), (ins RSTi:$op), "fstp\t$op">;
606 let mayRaiseFPException = 0 in
607 def XCH_F    : FPI<0xD9, MRM1r, (outs), (ins RSTi:$op), "fxch\t$op">;
608 }
609
610 // Floating point constant loads.
611 let SchedRW = [WriteZero], Uses = [FPCW] in {
612 def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
613                 [(set RFP32:$dst, fpimm0)]>;
614 def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
615                 [(set RFP32:$dst, fpimm1)]>;
616 def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
617                 [(set RFP64:$dst, fpimm0)]>;
618 def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
619                 [(set RFP64:$dst, fpimm1)]>;
620 def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
621                 [(set RFP80:$dst, fpimm0)]>;
622 def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
623                 [(set RFP80:$dst, fpimm1)]>;
624 }
625
626 let SchedRW = [WriteFLD0], Uses = [FPCW], mayRaiseFPException = 0 in
627 def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
628
629 let SchedRW = [WriteFLD1], Uses = [FPCW], mayRaiseFPException = 0 in
630 def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
631
632 let SchedRW = [WriteFLDC], Defs = [FPSW], Uses = [FPCW], mayRaiseFPException = 0 in {
633 def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
634 def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
635 def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
636 def FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", []>;
637 def FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", []>;
638 } // SchedRW
639
640 // Floating point compares.
641 let SchedRW = [WriteFCom], Uses = [FPCW], hasSideEffects = 0 in {
642 def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
643 def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
644 def UCOM_Fpr80 : FpI_  <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
645 def COM_Fpr32  : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
646 def COM_Fpr64  : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
647 def COM_Fpr80  : FpI_  <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
648 } // SchedRW
649 } // mayRaiseFPException = 1
650
651 let SchedRW = [WriteFCom], mayRaiseFPException = 1 in {
652 // CC = ST(0) cmp ST(i)
653 let Defs = [EFLAGS, FPSW], Uses = [FPCW] in {
654 def UCOM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
655                   [(set EFLAGS, (X86any_fcmp RFP32:$lhs, RFP32:$rhs))]>,
656                   Requires<[FPStackf32, HasCMov]>;
657 def UCOM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
658                   [(set EFLAGS, (X86any_fcmp RFP64:$lhs, RFP64:$rhs))]>,
659                   Requires<[FPStackf64, HasCMov]>;
660 def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
661                   [(set EFLAGS, (X86any_fcmp RFP80:$lhs, RFP80:$rhs))]>,
662                   Requires<[HasCMov]>;
663 def COM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
664                   [(set EFLAGS, (X86strict_fcmps RFP32:$lhs, RFP32:$rhs))]>,
665                   Requires<[FPStackf32, HasCMov]>;
666 def COM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
667                   [(set EFLAGS, (X86strict_fcmps RFP64:$lhs, RFP64:$rhs))]>,
668                   Requires<[FPStackf64, HasCMov]>;
669 def COM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
670                   [(set EFLAGS, (X86strict_fcmps RFP80:$lhs, RFP80:$rhs))]>,
671                   Requires<[HasCMov]>;
672 }
673
674 let Uses = [ST0, FPCW] in {
675 def UCOM_Fr    : FPI<0xDD, MRM4r,    // FPSW = cmp ST(0) with ST(i)
676                     (outs), (ins RSTi:$reg), "fucom\t$reg">;
677 def UCOM_FPr   : FPI<0xDD, MRM5r,    // FPSW = cmp ST(0) with ST(i), pop
678                     (outs), (ins RSTi:$reg), "fucomp\t$reg">;
679 def UCOM_FPPr  : FPI<0xDA, MRM_E9,       // cmp ST(0) with ST(1), pop, pop
680                     (outs), (ins), "fucompp">;
681 }
682
683 let Defs = [EFLAGS, FPSW], Uses = [ST0, FPCW] in {
684 def UCOM_FIr   : FPI<0xDB, MRM5r,     // CC = cmp ST(0) with ST(i)
685                     (outs), (ins RSTi:$reg), "fucomi\t{$reg, %st|st, $reg}">;
686 def UCOM_FIPr  : FPI<0xDF, MRM5r,     // CC = cmp ST(0) with ST(i), pop
687                     (outs), (ins RSTi:$reg), "fucompi\t{$reg, %st|st, $reg}">;
688
689 def COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RSTi:$reg),
690                   "fcomi\t{$reg, %st|st, $reg}">;
691 def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RSTi:$reg),
692                    "fcompi\t{$reg, %st|st, $reg}">;
693 }
694 } // SchedRW
695
696 // Floating point flag ops.
697 let SchedRW = [WriteALU] in {
698 let Defs = [AX, FPSW], Uses = [FPSW], hasSideEffects = 0 in
699 def FNSTSW16r : I<0xDF, MRM_E0,                  // AX = fp flags
700                   (outs), (ins), "fnstsw\t{%ax|ax}", []>;
701 let Defs = [FPSW], Uses = [FPCW] in
702 def FNSTCW16m : I<0xD9, MRM7m,                   // [mem16] = X87 control world
703                   (outs), (ins i16mem:$dst), "fnstcw\t$dst",
704                   [(X86fp_cwd_get16 addr:$dst)]>;
705 } // SchedRW
706 let Defs = [FPSW,FPCW], mayLoad = 1 in
707 def FLDCW16m  : I<0xD9, MRM5m,                   // X87 control world = [mem16]
708                   (outs), (ins i16mem:$dst), "fldcw\t$dst", []>,
709                 Sched<[WriteLoad]>;
710
711 // FPU control instructions
712 let SchedRW = [WriteMicrocoded] in {
713 def FFREE : FPI<0xDD, MRM0r, (outs), (ins RSTi:$reg), "ffree\t$reg">;
714 def FFREEP : FPI<0xDF, MRM0r, (outs), (ins RSTi:$reg), "ffreep\t$reg">;
715
716 let Defs = [FPSW, FPCW] in
717 def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
718 // Clear exceptions
719 let Defs = [FPSW] in
720 def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
721 } // SchedRW
722
723 // Operand-less floating-point instructions for the disassembler.
724 let Defs = [FPSW] in
725 def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
726
727 let SchedRW = [WriteMicrocoded] in {
728 let Defs = [FPSW] in {
729 def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
730 def FXAM : I<0xD9, MRM_E5, (outs), (ins), "fxam", []>;
731 def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
732 def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
733 let Uses = [FPCW], mayRaiseFPException = 1 in {
734 def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
735 def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
736 def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
737 def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
738 def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
739 def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
740 def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
741 def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
742 def FSIN : I<0xD9, MRM_FE, (outs), (ins), "fsin", []>;
743 def FCOS : I<0xD9, MRM_FF, (outs), (ins), "fcos", []>;
744 def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
745 def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
746 def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
747 def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
748 } // Uses = [FPCW], mayRaiseFPException = 1
749 } // Defs = [FPSW]
750
751 let Uses = [FPSW, FPCW] in {
752 def FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
753              "fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, PS,
754              Requires<[HasFXSR]>;
755 def FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
756                "fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
757                PS, Requires<[HasFXSR, In64BitMode]>;
758 } // Uses = [FPSW, FPCW]
759
760 let Defs = [FPSW, FPCW] in {
761 def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
762               "fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
763               PS, Requires<[HasFXSR]>;
764 def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
765                 "fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
766                 PS, Requires<[HasFXSR, In64BitMode]>;
767 } // Defs = [FPSW, FPCW]
768 } // SchedRW
769
770 //===----------------------------------------------------------------------===//
771 // Non-Instruction Patterns
772 //===----------------------------------------------------------------------===//
773
774 // Required for RET of f32 / f64 / f80 values.
775 def : Pat<(X86fldf32 addr:$src), (LD_Fp32m addr:$src)>;
776 def : Pat<(X86fldf32 addr:$src), (LD_Fp32m64 addr:$src)>;
777 def : Pat<(X86fldf64 addr:$src), (LD_Fp64m addr:$src)>;
778 def : Pat<(X86fldf32 addr:$src), (LD_Fp32m80 addr:$src)>;
779 def : Pat<(X86fldf64 addr:$src), (LD_Fp64m80 addr:$src)>;
780 def : Pat<(X86fldf80 addr:$src), (LD_Fp80m addr:$src)>;
781
782 // Required for CALL which return f32 / f64 / f80 values.
783 def : Pat<(X86fstf32 RFP32:$src, addr:$op), (ST_Fp32m addr:$op, RFP32:$src)>;
784 def : Pat<(X86fstf32 RFP64:$src, addr:$op), (ST_Fp64m32 addr:$op, RFP64:$src)>;
785 def : Pat<(X86fstf64 RFP64:$src, addr:$op), (ST_Fp64m addr:$op, RFP64:$src)>;
786 def : Pat<(X86fstf32 RFP80:$src, addr:$op), (ST_Fp80m32 addr:$op, RFP80:$src)>;
787 def : Pat<(X86fstf64 RFP80:$src, addr:$op), (ST_Fp80m64 addr:$op, RFP80:$src)>;
788 def : Pat<(X86fstf80 RFP80:$src, addr:$op), (ST_FpP80m addr:$op, RFP80:$src)>;
789
790 // Floating point constant -0.0 and -1.0
791 def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
792 def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
793 def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
794 def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
795 def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
796 def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
797
798 // FP extensions map onto simple pseudo-value conversions if they are to/from
799 // the FP stack.
800 def : Pat<(f64 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
801           Requires<[FPStackf32]>;
802 def : Pat<(f80 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
803            Requires<[FPStackf32]>;
804 def : Pat<(f80 (any_fpextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
805            Requires<[FPStackf64]>;
806
807 // FP truncations map onto simple pseudo-value conversions if they are to/from
808 // the FP stack.  We have validated that only value-preserving truncations make
809 // it through isel.
810 def : Pat<(f32 (any_fpround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
811           Requires<[FPStackf32]>;
812 def : Pat<(f32 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
813            Requires<[FPStackf32]>;
814 def : Pat<(f64 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
815            Requires<[FPStackf64]>;