blob: 4ad7b7e32a0ad42e90768b9214fcedd85379fa76 [file] [log] [blame]
Jia Liue1d61962012-02-19 02:03:36 +00001//===- X86InstrFPStack.td - FPU Instruction Set ------------*- tablegen -*-===//
Jia Liub22310f2012-02-18 12:03:15 +00002//
Evan Cheng6e595b92006-02-21 19:13:53 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jia Liub22310f2012-02-18 12:03:15 +00007//
Evan Cheng6e595b92006-02-21 19:13:53 +00008//===----------------------------------------------------------------------===//
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
Chris Lattnerd587e582008-03-09 07:05:32 +000020def SDTX86FpGet2 : SDTypeProfile<2, 0, [SDTCisVT<0, f80>,
21 SDTCisVT<1, f80>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000022def SDTX86Fld : SDTypeProfile<1, 2, [SDTCisFP<0>,
Dale Johannesen23f631d2007-07-10 20:53:41 +000023 SDTCisPtrTy<1>,
24 SDTCisVT<2, OtherVT>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000025def SDTX86Fst : SDTypeProfile<0, 3, [SDTCisFP<0>,
Dale Johannesen23f631d2007-07-10 20:53:41 +000026 SDTCisPtrTy<1>,
27 SDTCisVT<2, OtherVT>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000028def SDTX86Fild : SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisPtrTy<1>,
29 SDTCisVT<2, OtherVT>]>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +000030def SDTX86Fnstsw : SDTypeProfile<1, 1, [SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000031def SDTX86FpToIMem : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000032
Anton Korobeynikov91460e42007-11-16 01:31:51 +000033def SDTX86CwdStore : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
34
Chris Lattner317332f2008-01-10 07:59:24 +000035def X86fld : SDNode<"X86ISD::FLD", SDTX86Fld,
Chris Lattnera5156c32010-09-22 01:28:21 +000036 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000037def X86fst : SDNode<"X86ISD::FST", SDTX86Fst,
Chris Lattner2a0a3b42010-12-23 18:28:41 +000038 [SDNPHasChain, SDNPInGlue, SDNPMayStore,
Chris Lattnera5156c32010-09-22 01:28:21 +000039 SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000040def X86fild : SDNode<"X86ISD::FILD", SDTX86Fild,
Chris Lattnera5156c32010-09-22 01:28:21 +000041 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000042def X86fildflag : SDNode<"X86ISD::FILD_FLAG", SDTX86Fild,
Chris Lattner2a0a3b42010-12-23 18:28:41 +000043 [SDNPHasChain, SDNPOutGlue, SDNPMayLoad,
Chris Lattnera5156c32010-09-22 01:28:21 +000044 SDNPMemOperand]>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +000045def X86fp_stsw : SDNode<"X86ISD::FNSTSW16r", SDTX86Fnstsw>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000046def X86fp_to_i16mem : SDNode<"X86ISD::FP_TO_INT16_IN_MEM", SDTX86FpToIMem,
Chris Lattner78f518b2010-09-22 01:05:16 +000047 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000048def X86fp_to_i32mem : SDNode<"X86ISD::FP_TO_INT32_IN_MEM", SDTX86FpToIMem,
Chris Lattner78f518b2010-09-22 01:05:16 +000049 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000050def X86fp_to_i64mem : SDNode<"X86ISD::FP_TO_INT64_IN_MEM", SDTX86FpToIMem,
Chris Lattner78f518b2010-09-22 01:05:16 +000051 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Anton Korobeynikov91460e42007-11-16 01:31:51 +000052def X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m", SDTX86CwdStore,
Chris Lattner78f518b2010-09-22 01:05:16 +000053 [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
54 SDNPMemOperand]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000055
56//===----------------------------------------------------------------------===//
Evan Cheng4f674922006-03-17 19:55:52 +000057// FPStack pattern fragments
58//===----------------------------------------------------------------------===//
59
Dale Johannesena2b3c172007-07-03 00:53:03 +000060def fpimm0 : PatLeaf<(fpimm), [{
Evan Cheng4f674922006-03-17 19:55:52 +000061 return N->isExactlyValue(+0.0);
62}]>;
63
Dale Johannesena2b3c172007-07-03 00:53:03 +000064def fpimmneg0 : PatLeaf<(fpimm), [{
Evan Cheng4f674922006-03-17 19:55:52 +000065 return N->isExactlyValue(-0.0);
66}]>;
67
Dale Johannesena2b3c172007-07-03 00:53:03 +000068def fpimm1 : PatLeaf<(fpimm), [{
Evan Cheng4f674922006-03-17 19:55:52 +000069 return N->isExactlyValue(+1.0);
70}]>;
71
Dale Johannesena2b3c172007-07-03 00:53:03 +000072def fpimmneg1 : PatLeaf<(fpimm), [{
Evan Cheng4f674922006-03-17 19:55:52 +000073 return N->isExactlyValue(-1.0);
74}]>;
75
Evan Chengd5847812006-02-21 20:00:20 +000076// Some 'special' instructions
Dan Gohman453d64c2009-10-29 18:10:34 +000077let usesCustomInserter = 1 in { // Expanded after instruction selection.
Eric Christophera964f4d2010-11-30 21:57:32 +000078 def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000079 [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000080 def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000081 [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000082 def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000083 [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000084 def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000085 [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000086 def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000087 [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000088 def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000089 [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000090 def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +000091 [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000092 def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +000093 [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000094 def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +000095 [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
Evan Chengd5847812006-02-21 20:00:20 +000096}
97
Dale Johannesena47f7d72007-08-07 20:29:26 +000098// All FP Stack operations are represented with four instructions here. The
99// first three instructions, generated by the instruction selector, use "RFP32"
100// "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
101// 64-bit or 80-bit floating point values. These sizes apply to the values,
102// not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
103// copied to each other without losing information. These instructions are all
104// pseudo instructions and use the "_Fp" suffix.
105// In some cases there are additional variants with a mixture of different
106// register sizes.
Evan Cheng6e595b92006-02-21 19:13:53 +0000107// The second instruction is defined with FPI, which is the actual instruction
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000108// emitted by the assembler. These use "RST" registers, although frequently
Dale Johannesena47f7d72007-08-07 20:29:26 +0000109// the actual register(s) used are implicit. These are always 80 bits.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000110// The FP stackifier pass converts one to the other after register allocation
111// occurs.
Evan Cheng6e595b92006-02-21 19:13:53 +0000112//
113// Note that the FpI instruction should have instruction selection info (e.g.
114// a pattern) and the FPI instruction should have emission info (e.g. opcode
115// encoding and asm printing info).
116
Jakob Stoklund Olesen7297e7e2011-06-28 18:32:28 +0000117// Pseudo Instruction for FP stack return values.
118def FpPOP_RETVAL : FpI_<(outs RFP80:$dst), (ins), SpecialFP, []>;
Evan Chenge5ade4a2009-02-09 23:32:07 +0000119
Bob Wilsona967c422010-08-26 18:08:11 +0000120// FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
Dale Johannesene36c4002007-09-23 14:52:20 +0000121// f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
122// f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
123// f80 instructions cannot use SSE and use neither of these.
124class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
125 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
126class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
127 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000128
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000129// Factoring for arithmetic.
130multiclass FPBinary_rr<SDNode OpNode> {
131// Register op register -> register
132// These are separated out because they have no reversed form.
Dale Johannesene36c4002007-09-23 14:52:20 +0000133def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000134 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000135def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000136 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000137def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000138 [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000139}
140// The FopST0 series are not included here because of the irregularities
141// in where the 'r' goes in assembly output.
Dale Johannesenb1888e72007-08-05 18:49:15 +0000142// These instructions cannot address 80-bit memory.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000143multiclass FPBinary<SDNode OpNode, Format fp, string asmstring> {
144// ST(0) = ST(0) + [mem]
Sean Callanan04d8cb72009-12-18 00:01:26 +0000145def _Fp32m : FpIf32<(outs RFP32:$dst),
146 (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
Dale Johannesen23f631d2007-07-10 20:53:41 +0000147 [(set RFP32:$dst,
148 (OpNode RFP32:$src1, (loadf32 addr:$src2)))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000149def _Fp64m : FpIf64<(outs RFP64:$dst),
150 (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
Dale Johannesen23f631d2007-07-10 20:53:41 +0000151 [(set RFP64:$dst,
152 (OpNode RFP64:$src1, (loadf64 addr:$src2)))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000153def _Fp64m32: FpIf64<(outs RFP64:$dst),
154 (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
Dale Johannesen68471d22007-07-10 21:53:30 +0000155 [(set RFP64:$dst,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000156 (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2))))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000157def _Fp80m32: FpI_<(outs RFP80:$dst),
158 (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000159 [(set RFP80:$dst,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000160 (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2))))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000161def _Fp80m64: FpI_<(outs RFP80:$dst),
162 (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000163 [(set RFP80:$dst,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000164 (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2))))]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000165def _F32m : FPI<0xD8, fp, (outs), (ins f32mem:$src),
Chris Lattner61ea00b2010-10-05 23:58:18 +0000166 !strconcat("f", asmstring, "{s}\t$src")> {
Sean Callanan04d8cb72009-12-18 00:01:26 +0000167 let mayLoad = 1;
168}
Evan Cheng94b5a802007-07-19 01:14:50 +0000169def _F64m : FPI<0xDC, fp, (outs), (ins f64mem:$src),
Chris Lattner61ea00b2010-10-05 23:58:18 +0000170 !strconcat("f", asmstring, "{l}\t$src")> {
Sean Callanan04d8cb72009-12-18 00:01:26 +0000171 let mayLoad = 1;
172}
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000173// ST(0) = ST(0) + [memint]
Sean Callanan04d8cb72009-12-18 00:01:26 +0000174def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
175 OneArgFPRW,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000176 [(set RFP32:$dst, (OpNode RFP32:$src1,
177 (X86fild addr:$src2, i16)))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000178def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
179 OneArgFPRW,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000180 [(set RFP32:$dst, (OpNode RFP32:$src1,
181 (X86fild addr:$src2, i32)))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000182def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
183 OneArgFPRW,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000184 [(set RFP64:$dst, (OpNode RFP64:$src1,
185 (X86fild addr:$src2, i16)))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000186def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
187 OneArgFPRW,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000188 [(set RFP64:$dst, (OpNode RFP64:$src1,
189 (X86fild addr:$src2, i32)))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000190def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
191 OneArgFPRW,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000192 [(set RFP80:$dst, (OpNode RFP80:$src1,
193 (X86fild addr:$src2, i16)))]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000194def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
195 OneArgFPRW,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000196 [(set RFP80:$dst, (OpNode RFP80:$src1,
197 (X86fild addr:$src2, i32)))]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000198def _FI16m : FPI<0xDE, fp, (outs), (ins i16mem:$src),
Chris Lattner61ea00b2010-10-05 23:58:18 +0000199 !strconcat("fi", asmstring, "{s}\t$src")> {
Sean Callanan04d8cb72009-12-18 00:01:26 +0000200 let mayLoad = 1;
201}
Evan Cheng94b5a802007-07-19 01:14:50 +0000202def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
Chris Lattner61ea00b2010-10-05 23:58:18 +0000203 !strconcat("fi", asmstring, "{l}\t$src")> {
Sean Callanan04d8cb72009-12-18 00:01:26 +0000204 let mayLoad = 1;
205}
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000206}
207
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000208let Defs = [FPSW] in {
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000209// FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
210// resources.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000211defm ADD : FPBinary_rr<fadd>;
212defm SUB : FPBinary_rr<fsub>;
213defm MUL : FPBinary_rr<fmul>;
214defm DIV : FPBinary_rr<fdiv>;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000215// Sets the scheduling resources for the actual NAME#_F<size>m defintions.
216let SchedRW = [WriteFAddLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000217defm ADD : FPBinary<fadd, MRM0m, "add">;
218defm SUB : FPBinary<fsub, MRM4m, "sub">;
219defm SUBR: FPBinary<fsub ,MRM5m, "subr">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000220}
221let SchedRW = [WriteFMulLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000222defm MUL : FPBinary<fmul, MRM1m, "mul">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000223}
224let SchedRW = [WriteFDivLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000225defm DIV : FPBinary<fdiv, MRM6m, "div">;
226defm DIVR: FPBinary<fdiv, MRM7m, "divr">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000227}
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000228}
Evan Cheng6e595b92006-02-21 19:13:53 +0000229
Craig Topper623b0d62014-01-01 14:22:37 +0000230class FPST0rInst<Format fp, string asm>
231 : FPI<0xD8, fp, (outs), (ins RST:$op), asm>;
232class FPrST0Inst<Format fp, string asm>
233 : FPI<0xDC, fp, (outs), (ins RST:$op), asm>;
234class FPrST0PInst<Format fp, string asm>
235 : FPI<0xDE, fp, (outs), (ins RST:$op), asm>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000236
Evan Cheng6e595b92006-02-21 19:13:53 +0000237// 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.
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000240let SchedRW = [WriteFAdd] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000241def ADD_FST0r : FPST0rInst <MRM0r, "fadd\t$op">;
242def ADD_FrST0 : FPrST0Inst <MRM0r, "fadd\t{%st(0), $op|$op, st(0)}">;
243def ADD_FPrST0 : FPrST0PInst<MRM0r, "faddp\t$op">;
244def SUBR_FST0r : FPST0rInst <MRM5r, "fsubr\t$op">;
245def SUB_FrST0 : FPrST0Inst <MRM5r, "fsub{r}\t{%st(0), $op|$op, st(0)}">;
246def SUB_FPrST0 : FPrST0PInst<MRM5r, "fsub{r}p\t$op">;
247def SUB_FST0r : FPST0rInst <MRM4r, "fsub\t$op">;
248def SUBR_FrST0 : FPrST0Inst <MRM4r, "fsub{|r}\t{%st(0), $op|$op, st(0)}">;
249def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000250} // SchedRW
251let SchedRW = [WriteFMul] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000252def MUL_FST0r : FPST0rInst <MRM1r, "fmul\t$op">;
253def MUL_FrST0 : FPrST0Inst <MRM1r, "fmul\t{%st(0), $op|$op, st(0)}">;
254def MUL_FPrST0 : FPrST0PInst<MRM1r, "fmulp\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000255} // SchedRW
256let SchedRW = [WriteFDiv] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000257def DIVR_FST0r : FPST0rInst <MRM7r, "fdivr\t$op">;
258def DIV_FrST0 : FPrST0Inst <MRM7r, "fdiv{r}\t{%st(0), $op|$op, st(0)}">;
259def DIV_FPrST0 : FPrST0PInst<MRM7r, "fdiv{r}p\t$op">;
260def DIV_FST0r : FPST0rInst <MRM6r, "fdiv\t$op">;
261def DIVR_FrST0 : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st(0), $op|$op, st(0)}">;
262def DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000263} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000264
Craig Topper623b0d62014-01-01 14:22:37 +0000265def COM_FST0r : FPST0rInst <MRM2r, "fcom\t$op">;
266def COMP_FST0r : FPST0rInst <MRM3r, "fcomp\t$op">;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000267
Evan Cheng6e595b92006-02-21 19:13:53 +0000268// Unary operations.
Craig Topper56f0ed812014-02-19 08:25:02 +0000269multiclass FPUnary<SDNode OpNode, Format fp, string asmstring> {
Dale Johannesene36c4002007-09-23 14:52:20 +0000270def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000271 [(set RFP32:$dst, (OpNode RFP32:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000272def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000273 [(set RFP64:$dst, (OpNode RFP64:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000274def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000275 [(set RFP80:$dst, (OpNode RFP80:$src))]>;
Craig Topper56f0ed812014-02-19 08:25:02 +0000276def _F : FPI<0xD9, fp, (outs), (ins), asmstring>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000277}
278
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000279let Defs = [FPSW] in {
Craig Topper56f0ed812014-02-19 08:25:02 +0000280defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
281defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000282let SchedRW = [WriteFSqrt] in {
Craig Topper56f0ed812014-02-19 08:25:02 +0000283defm SQRT: FPUnary<fsqrt,MRM_FA, "fsqrt">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000284}
Craig Topper56f0ed812014-02-19 08:25:02 +0000285defm SIN : FPUnary<fsin, MRM_FE, "fsin">;
286defm COS : FPUnary<fcos, MRM_FF, "fcos">;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000287
Chris Lattner92831732008-01-11 07:18:17 +0000288let neverHasSideEffects = 1 in {
289def TST_Fp32 : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
290def TST_Fp64 : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
291def TST_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
292}
Craig Topper56f0ed812014-02-19 08:25:02 +0000293def TST_F : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000294} // Defs = [FPSW]
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000295
Sean Callanane739ac82009-09-16 01:13:52 +0000296// Versions of FP instructions that take a single memory operand. Added for the
297// disassembler; remove as they are included with patterns elsewhere.
Kevin Enderby6f2f8d02010-05-03 21:31:40 +0000298def FCOM32m : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
299def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000300
301def FLDENVm : FPI<0xD9, MRM4m, (outs), (ins f32mem:$src), "fldenv\t$src">;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000302def FSTENVm : FPI<0xD9, MRM6m, (outs f32mem:$dst), (ins), "fnstenv\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000303
304def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
305def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
306
Kevin Enderby6f2f8d02010-05-03 21:31:40 +0000307def FCOM64m : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
308def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000309
Sean Callanane739ac82009-09-16 01:13:52 +0000310def FRSTORm : FPI<0xDD, MRM4m, (outs f32mem:$dst), (ins), "frstor\t$dst">;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000311def FSAVEm : FPI<0xDD, MRM6m, (outs f32mem:$dst), (ins), "fnsave\t$dst">;
Andrew Trickedd006c2010-10-22 03:58:29 +0000312def FNSTSWm : FPI<0xDD, MRM7m, (outs f32mem:$dst), (ins), "fnstsw\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000313
Kevin Enderby6f2f8d02010-05-03 21:31:40 +0000314def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
315def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000316
317def FBLDm : FPI<0xDF, MRM4m, (outs), (ins f32mem:$src), "fbld\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000318def FBSTPm : FPI<0xDF, MRM6m, (outs f32mem:$dst), (ins), "fbstp\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000319
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000320// Floating point cmovs.
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000321class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
322 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMov]>;
323class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
324 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMov]>;
325
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000326multiclass FPCMov<PatLeaf cc> {
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000327 def _Fp32 : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000328 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000329 [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000330 cc, EFLAGS))]>;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000331 def _Fp64 : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000332 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000333 [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000334 cc, EFLAGS))]>;
335 def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
336 CondMovFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000337 [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000338 cc, EFLAGS))]>,
339 Requires<[HasCMov]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000340}
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000341
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000342let Defs = [FPSW] in {
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000343let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000344defm CMOVB : FPCMov<X86_COND_B>;
345defm CMOVBE : FPCMov<X86_COND_BE>;
346defm CMOVE : FPCMov<X86_COND_E>;
347defm CMOVP : FPCMov<X86_COND_P>;
348defm CMOVNB : FPCMov<X86_COND_AE>;
349defm CMOVNBE: FPCMov<X86_COND_A>;
350defm CMOVNE : FPCMov<X86_COND_NE>;
351defm CMOVNP : FPCMov<X86_COND_NP>;
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000352} // Uses = [EFLAGS], Constraints = "$src1 = $dst"
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000353
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000354let Predicates = [HasCMov] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000355// These are not factored because there's no clean way to pass DA/DB.
Craig Topper623b0d62014-01-01 14:22:37 +0000356def CMOVB_F : FPI<0xDA, MRM0r, (outs RST:$op), (ins),
357 "fcmovb\t{$op, %st(0)|st(0), $op}">;
358def CMOVBE_F : FPI<0xDA, MRM2r, (outs RST:$op), (ins),
359 "fcmovbe\t{$op, %st(0)|st(0), $op}">;
360def CMOVE_F : FPI<0xDA, MRM1r, (outs RST:$op), (ins),
361 "fcmove\t{$op, %st(0)|st(0), $op}">;
362def CMOVP_F : FPI<0xDA, MRM3r, (outs RST:$op), (ins),
363 "fcmovu\t{$op, %st(0)|st(0), $op}">;
364def CMOVNB_F : FPI<0xDB, MRM0r, (outs RST:$op), (ins),
365 "fcmovnb\t{$op, %st(0)|st(0), $op}">;
366def CMOVNBE_F: FPI<0xDB, MRM2r, (outs RST:$op), (ins),
367 "fcmovnbe\t{$op, %st(0)|st(0), $op}">;
368def CMOVNE_F : FPI<0xDB, MRM1r, (outs RST:$op), (ins),
369 "fcmovne\t{$op, %st(0)|st(0), $op}">;
370def CMOVNP_F : FPI<0xDB, MRM3r, (outs RST:$op), (ins),
371 "fcmovnu\t{$op, %st(0)|st(0), $op}">;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000372} // Predicates = [HasCMov]
Evan Cheng6e595b92006-02-21 19:13:53 +0000373
374// Floating point loads & stores.
Dan Gohman69cc2cb2008-12-03 18:15:48 +0000375let canFoldAsLoad = 1 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000376def LD_Fp32m : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000377 [(set RFP32:$dst, (loadf32 addr:$src))]>;
Dan Gohman8c5d6832010-02-27 23:47:46 +0000378let isReMaterializable = 1 in
Bill Wendlinga2401be2007-12-17 22:17:14 +0000379 def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000380 [(set RFP64:$dst, (loadf64 addr:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000381def LD_Fp80m : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000382 [(set RFP80:$dst, (loadf80 addr:$src))]>;
Evan Chengc2081fe2007-08-30 05:49:43 +0000383}
Dale Johannesene36c4002007-09-23 14:52:20 +0000384def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000385 [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
386def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
387 [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
388def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
389 [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000390def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000391 [(set RFP32:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000392def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000393 [(set RFP32:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000394def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000395 [(set RFP32:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000396def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000397 [(set RFP64:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000398def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000399 [(set RFP64:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000400def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000401 [(set RFP64:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000402def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000403 [(set RFP80:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000404def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000405 [(set RFP80:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000406def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000407 [(set RFP80:$dst, (X86fild addr:$src, i64))]>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000408
Dale Johannesene36c4002007-09-23 14:52:20 +0000409def ST_Fp32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000410 [(store RFP32:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000411def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000412 [(truncstoref32 RFP64:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000413def ST_Fp64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000414 [(store RFP64:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000415def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000416 [(truncstoref32 RFP80:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000417def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000418 [(truncstoref64 RFP80:$src, addr:$op)]>;
419// FST does not support 80-bit memory target; FSTP must be used.
Evan Cheng6e595b92006-02-21 19:13:53 +0000420
Chris Lattner92831732008-01-11 07:18:17 +0000421let mayStore = 1, neverHasSideEffects = 1 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000422def ST_FpP32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
423def ST_FpP64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
424def ST_FpP64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
425def ST_FpP80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
426def ST_FpP80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
Chris Lattner317332f2008-01-10 07:59:24 +0000427}
Dale Johannesena47f7d72007-08-07 20:29:26 +0000428def ST_FpP80m : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000429 [(store RFP80:$src, addr:$op)]>;
Chris Lattner92831732008-01-11 07:18:17 +0000430let mayStore = 1, neverHasSideEffects = 1 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000431def IST_Fp16m32 : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
432def IST_Fp32m32 : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP, []>;
433def IST_Fp64m32 : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP, []>;
434def IST_Fp16m64 : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
435def IST_Fp32m64 : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP, []>;
436def IST_Fp64m64 : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP, []>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000437def IST_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
438def IST_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP, []>;
439def IST_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP, []>;
Chris Lattner317332f2008-01-10 07:59:24 +0000440}
Evan Cheng6e595b92006-02-21 19:13:53 +0000441
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000442let mayLoad = 1, SchedRW = [WriteLoad] in {
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000443def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src",
444 IIC_FLD>;
445def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src",
446 IIC_FLD>;
447def LD_F80m : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src",
448 IIC_FLD80>;
449def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src",
450 IIC_FILD>;
451def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src",
452 IIC_FILD>;
453def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src",
454 IIC_FILD>;
Chris Lattner317332f2008-01-10 07:59:24 +0000455}
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000456let mayStore = 1, SchedRW = [WriteStore] in {
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000457def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst",
458 IIC_FST>;
459def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst",
460 IIC_FST>;
461def ST_FP32m : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst",
462 IIC_FST>;
463def ST_FP64m : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst",
464 IIC_FST>;
465def ST_FP80m : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst",
466 IIC_FST80>;
467def IST_F16m : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst",
468 IIC_FIST>;
469def IST_F32m : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst",
470 IIC_FIST>;
471def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst",
472 IIC_FIST>;
473def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst",
474 IIC_FIST>;
475def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst",
476 IIC_FIST>;
Chris Lattner317332f2008-01-10 07:59:24 +0000477}
Evan Cheng6e595b92006-02-21 19:13:53 +0000478
479// FISTTP requires SSE3 even though it's a FPStack op.
Craig Toppereb8f9e92012-01-10 06:30:56 +0000480let Predicates = [HasSSE3] in {
Evan Cheng94b5a802007-07-19 01:14:50 +0000481def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000482 [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000483def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000484 [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000485def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000486 [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000487def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000488 [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000489def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000490 [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000491def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000492 [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000493def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000494 [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000495def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000496 [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000497def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000498 [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
499} // Predicates = [HasSSE3]
Evan Cheng6e595b92006-02-21 19:13:53 +0000500
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000501let mayStore = 1, SchedRW = [WriteStore] in {
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000502def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst",
503 IIC_FST>;
504def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst",
505 IIC_FST>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000506def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst),
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000507 "fisttp{ll}\t$dst", IIC_FST>;
Chris Lattner317332f2008-01-10 07:59:24 +0000508}
Evan Cheng6e595b92006-02-21 19:13:53 +0000509
510// FP Stack manipulation instructions.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000511let SchedRW = [WriteMove] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000512def LD_Frr : FPI<0xD9, MRM0r, (outs), (ins RST:$op), "fld\t$op", IIC_FLD>;
513def ST_Frr : FPI<0xDD, MRM2r, (outs), (ins RST:$op), "fst\t$op", IIC_FST>;
514def ST_FPrr : FPI<0xDD, MRM3r, (outs), (ins RST:$op), "fstp\t$op", IIC_FST>;
515def XCH_F : FPI<0xD9, MRM1r, (outs), (ins RST:$op), "fxch\t$op", IIC_FXCH>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000516}
Evan Cheng6e595b92006-02-21 19:13:53 +0000517
518// Floating point constant loads.
Chris Lattneraca7ca32008-01-10 05:45:39 +0000519let isReMaterializable = 1 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000520def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000521 [(set RFP32:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000522def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000523 [(set RFP32:$dst, fpimm1)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000524def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000525 [(set RFP64:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000526def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000527 [(set RFP64:$dst, fpimm1)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000528def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000529 [(set RFP80:$dst, fpimm0)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000530def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000531 [(set RFP80:$dst, fpimm1)]>;
Dan Gohmane8c1e422007-06-26 00:48:07 +0000532}
Evan Cheng6e595b92006-02-21 19:13:53 +0000533
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000534let SchedRW = [WriteZero] in {
Craig Topper56f0ed812014-02-19 08:25:02 +0000535def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz", IIC_FLDZ>;
536def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1", IIC_FIST>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000537}
Evan Cheng6e595b92006-02-21 19:13:53 +0000538
539// Floating point compares.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000540let SchedRW = [WriteFAdd] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000541def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000542 [(set FPSW, (trunc (X86cmp RFP32:$lhs, RFP32:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000543def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000544 [(set FPSW, (trunc (X86cmp RFP64:$lhs, RFP64:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000545def UCOM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000546 [(set FPSW, (trunc (X86cmp RFP80:$lhs, RFP80:$rhs)))]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000547} // SchedRW
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000548} // Defs = [FPSW]
549
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000550let SchedRW = [WriteFAdd] in {
Chris Lattner83facb02010-03-19 00:01:11 +0000551// CC = ST(0) cmp ST(i)
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000552let Defs = [EFLAGS, FPSW] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000553def UCOM_FpIr32: FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000554 [(set EFLAGS, (X86cmp RFP32:$lhs, RFP32:$rhs))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000555def UCOM_FpIr64: FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000556 [(set EFLAGS, (X86cmp RFP64:$lhs, RFP64:$rhs))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000557def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000558 [(set EFLAGS, (X86cmp RFP80:$lhs, RFP80:$rhs))]>;
Evan Cheng8ee1ecf2007-09-25 19:08:02 +0000559}
560
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000561let Defs = [FPSW], Uses = [ST0] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000562def UCOM_Fr : FPI<0xDD, MRM4r, // FPSW = cmp ST(0) with ST(i)
563 (outs), (ins RST:$reg), "fucom\t$reg", IIC_FUCOM>;
564def UCOM_FPr : FPI<0xDD, MRM5r, // FPSW = cmp ST(0) with ST(i), pop
565 (outs), (ins RST:$reg), "fucomp\t$reg", IIC_FUCOM>;
Craig Topper56f0ed812014-02-19 08:25:02 +0000566def UCOM_FPPr : FPI<0xDA, MRM_E9, // cmp ST(0) with ST(1), pop, pop
567 (outs), (ins), "fucompp", IIC_FUCOM>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000568}
Evan Cheng6e595b92006-02-21 19:13:53 +0000569
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000570let Defs = [EFLAGS, FPSW], Uses = [ST0] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000571def UCOM_FIr : FPI<0xDB, MRM5r, // CC = cmp ST(0) with ST(i)
572 (outs), (ins RST:$reg), "fucomi\t$reg", IIC_FUCOMI>;
573def UCOM_FIPr : FPI<0xDF, MRM5r, // CC = cmp ST(0) with ST(i), pop
574 (outs), (ins RST:$reg), "fucompi\t$reg", IIC_FUCOMI>;
Evan Cheng3e18e502007-09-11 19:55:27 +0000575}
Evan Cheng6e595b92006-02-21 19:13:53 +0000576
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000577let Defs = [EFLAGS, FPSW] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000578def COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RST:$reg),
579 "fcomi\t$reg", IIC_FCOMI>;
580def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RST:$reg),
581 "fcompi\t$reg", IIC_FCOMI>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000582}
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000583} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000584
Evan Cheng6e595b92006-02-21 19:13:53 +0000585// Floating point flag ops.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000586let SchedRW = [WriteALU] in {
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000587let Defs = [AX], Uses = [FPSW] in
Craig Topper56f0ed812014-02-19 08:25:02 +0000588def FNSTSW16r : I<0xDF, MRM_E0, // AX = fp flags
Craig Topperefd67d42013-07-31 02:47:52 +0000589 (outs), (ins), "fnstsw\t{%ax|ax}",
Craig Topper56f0ed812014-02-19 08:25:02 +0000590 [(set AX, (X86fp_stsw FPSW))], IIC_FNSTSW>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000591
592def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
Andrew Trickedd006c2010-10-22 03:58:29 +0000593 (outs), (ins i16mem:$dst), "fnstcw\t$dst",
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000594 [(X86fp_cwd_get16 addr:$dst)], IIC_FNSTCW>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000595} // SchedRW
Chris Lattner317332f2008-01-10 07:59:24 +0000596let mayLoad = 1 in
Evan Cheng6e595b92006-02-21 19:13:53 +0000597def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000598 (outs), (ins i16mem:$dst), "fldcw\t$dst", [], IIC_FLDCW>,
599 Sched<[WriteLoad]>;
Evan Chengd5847812006-02-21 20:00:20 +0000600
Chris Lattnerdec85b82010-10-05 05:32:15 +0000601// FPU control instructions
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000602let SchedRW = [WriteMicrocoded] in {
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000603let Defs = [FPSW] in
Craig Topper56f0ed812014-02-19 08:25:02 +0000604def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", [], IIC_FNINIT>;
Craig Topper623b0d62014-01-01 14:22:37 +0000605def FFREE : FPI<0xDD, MRM0r, (outs), (ins RST:$reg),
606 "ffree\t$reg", IIC_FFREE>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000607// Clear exceptions
608
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000609let Defs = [FPSW] in
Craig Topper56f0ed812014-02-19 08:25:02 +0000610def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", [], IIC_FNCLEX>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000611} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000612
Chris Lattnerdec85b82010-10-05 05:32:15 +0000613// Operandless floating-point instructions for the disassembler.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000614let SchedRW = [WriteMicrocoded] in {
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000615def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", [], IIC_WAIT>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000616
Craig Topper56f0ed812014-02-19 08:25:02 +0000617def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", [], IIC_FNOP>;
618def FXAM : I<0xD9, MRM_E5, (outs), (ins), "fxam", [], IIC_FXAM>;
619def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", [], IIC_FLDL>;
620def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", [], IIC_FLDL>;
621def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", [], IIC_FLDL>;
622def FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", [], IIC_FLDL>;
623def FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", [], IIC_FLDL>;
624def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", [], IIC_F2XM1>;
625def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", [], IIC_FYL2X>;
626def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", [], IIC_FPTAN>;
627def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", [], IIC_FPATAN>;
628def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", [], IIC_FXTRACT>;
629def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", [], IIC_FPREM1>;
630def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", [], IIC_FPSTP>;
631def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", [], IIC_FPSTP>;
632def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", [], IIC_FPREM>;
633def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", [], IIC_FYL2XP1>;
634def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", [], IIC_FSINCOS>;
635def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", [], IIC_FRNDINT>;
636def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", [], IIC_FSCALE>;
637def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", [], IIC_FCOMPP>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000638
639def FXSAVE : I<0xAE, MRM0m, (outs opaque512mem:$dst), (ins),
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000640 "fxsave\t$dst", [], IIC_FXSAVE>, TB;
Craig Topper80ab2682014-01-17 08:16:57 +0000641def FXSAVE64 : RI<0xAE, MRM0m, (outs opaque512mem:$dst), (ins),
642 "fxsave{q|64}\t$dst", [], IIC_FXSAVE>, TB,
643 Requires<[In64BitMode]>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000644def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaque512mem:$src),
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000645 "fxrstor\t$src", [], IIC_FXRSTOR>, TB;
Craig Topper80ab2682014-01-17 08:16:57 +0000646def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaque512mem:$src),
647 "fxrstor{q|64}\t$src", [], IIC_FXRSTOR>, TB,
Preston Gurdfa3f6cb2012-05-02 16:03:35 +0000648 Requires<[In64BitMode]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000649} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000650
Evan Chengd5847812006-02-21 20:00:20 +0000651//===----------------------------------------------------------------------===//
652// Non-Instruction Patterns
653//===----------------------------------------------------------------------===//
654
Dale Johannesena47f7d72007-08-07 20:29:26 +0000655// Required for RET of f32 / f64 / f80 values.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000656def : Pat<(X86fld addr:$src, f32), (LD_Fp32m addr:$src)>;
657def : Pat<(X86fld addr:$src, f64), (LD_Fp64m addr:$src)>;
Dale Johannesenb1888e72007-08-05 18:49:15 +0000658def : Pat<(X86fld addr:$src, f80), (LD_Fp80m addr:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000659
Dale Johannesena47f7d72007-08-07 20:29:26 +0000660// Required for CALL which return f32 / f64 / f80 values.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000661def : Pat<(X86fst RFP32:$src, addr:$op, f32), (ST_Fp32m addr:$op, RFP32:$src)>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000662def : Pat<(X86fst RFP64:$src, addr:$op, f32), (ST_Fp64m32 addr:$op,
663 RFP64:$src)>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000664def : Pat<(X86fst RFP64:$src, addr:$op, f64), (ST_Fp64m addr:$op, RFP64:$src)>;
Sean Callanan04d8cb72009-12-18 00:01:26 +0000665def : Pat<(X86fst RFP80:$src, addr:$op, f32), (ST_Fp80m32 addr:$op,
666 RFP80:$src)>;
667def : Pat<(X86fst RFP80:$src, addr:$op, f64), (ST_Fp80m64 addr:$op,
668 RFP80:$src)>;
669def : Pat<(X86fst RFP80:$src, addr:$op, f80), (ST_FpP80m addr:$op,
670 RFP80:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000671
672// Floating point constant -0.0 and -1.0
Dale Johannesene36c4002007-09-23 14:52:20 +0000673def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
674def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
675def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
676def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000677def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
678def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
Evan Chengd5847812006-02-21 20:00:20 +0000679
680// Used to conv. i64 to f64 since there isn't a SSE version.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000681def : Pat<(X86fildflag addr:$src, i64), (ILD_Fp64m64 addr:$src)>;
Dale Johannesena2b3c172007-07-03 00:53:03 +0000682
Chris Lattnerd587e582008-03-09 07:05:32 +0000683// FP extensions map onto simple pseudo-value conversions if they are to/from
684// the FP stack.
Jakob Stoklund Olesenf6c7d7f2010-07-11 18:19:39 +0000685def : Pat<(f64 (fextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000686 Requires<[FPStackf32]>;
Jakob Stoklund Olesenf6c7d7f2010-07-11 18:19:39 +0000687def : Pat<(f80 (fextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000688 Requires<[FPStackf32]>;
Jakob Stoklund Olesenf6c7d7f2010-07-11 18:19:39 +0000689def : Pat<(f80 (fextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000690 Requires<[FPStackf64]>;
691
692// FP truncations map onto simple pseudo-value conversions if they are to/from
693// the FP stack. We have validated that only value-preserving truncations make
694// it through isel.
Jakob Stoklund Olesenf6c7d7f2010-07-11 18:19:39 +0000695def : Pat<(f32 (fround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000696 Requires<[FPStackf32]>;
Jakob Stoklund Olesenf6c7d7f2010-07-11 18:19:39 +0000697def : Pat<(f32 (fround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000698 Requires<[FPStackf32]>;
Jakob Stoklund Olesenf6c7d7f2010-07-11 18:19:39 +0000699def : Pat<(f64 (fround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000700 Requires<[FPStackf64]>;