blob: cc81a919ec99bd42ffaf6fbabb2bbab001557b98 [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
Michael Liao5bf95782014-12-04 05:20:33 +000020def SDTX86FpGet2 : SDTypeProfile<2, 0, [SDTCisVT<0, f80>,
Chris Lattnerd587e582008-03-09 07:05:32 +000021 SDTCisVT<1, f80>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000022def SDTX86Fld : SDTypeProfile<1, 2, [SDTCisFP<0>,
Michael Liao5bf95782014-12-04 05:20:33 +000023 SDTCisPtrTy<1>,
Dale Johannesen23f631d2007-07-10 20:53:41 +000024 SDTCisVT<2, OtherVT>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000025def SDTX86Fst : SDTypeProfile<0, 3, [SDTCisFP<0>,
Michael Liao5bf95782014-12-04 05:20:33 +000026 SDTCisPtrTy<1>,
Dale Johannesen23f631d2007-07-10 20:53:41 +000027 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
Daniel Sanders11300ce2017-10-13 21:28:03 +000060def fpimm0 : FPImmLeaf<fAny, [{
61 return Imm.isExactlyValue(+0.0);
Evan Cheng4f674922006-03-17 19:55:52 +000062}]>;
63
Daniel Sanders11300ce2017-10-13 21:28:03 +000064def fpimmneg0 : FPImmLeaf<fAny, [{
65 return Imm.isExactlyValue(-0.0);
Evan Cheng4f674922006-03-17 19:55:52 +000066}]>;
67
Daniel Sanders11300ce2017-10-13 21:28:03 +000068def fpimm1 : FPImmLeaf<fAny, [{
69 return Imm.isExactlyValue(+1.0);
Evan Cheng4f674922006-03-17 19:55:52 +000070}]>;
71
Daniel Sanders11300ce2017-10-13 21:28:03 +000072def fpimmneg1 : FPImmLeaf<fAny, [{
73 return Imm.isExactlyValue(-1.0);
Evan Cheng4f674922006-03-17 19:55:52 +000074}]>;
75
Simon Pilgrim4fecbd82017-11-28 18:10:29 +000076// Some 'special' instructions - expanded after instruction selection.
77let usesCustomInserter = 1, hasNoSchedulingInfo = 1 in {
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,
Michael Liao5bf95782014-12-04 05:20:33 +0000101// 64-bit or 80-bit floating point values. These sizes apply to the values,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000102// 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.
Michael Liao5bf95782014-12-04 05:20:33 +0000110// The FP stackifier pass converts one to the other after register allocation
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000111// 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
Bob Wilsona967c422010-08-26 18:08:11 +0000117// FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
Dale Johannesene36c4002007-09-23 14:52:20 +0000118// f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
119// f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
120// f80 instructions cannot use SSE and use neither of these.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000121class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
122 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
123class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
124 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000125
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000126// Factoring for arithmetic.
127multiclass FPBinary_rr<SDNode OpNode> {
128// Register op register -> register
129// These are separated out because they have no reversed form.
Dale Johannesene36c4002007-09-23 14:52:20 +0000130def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000131 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000132def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000133 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000134def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000135 [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000136}
137// The FopST0 series are not included here because of the irregularities
138// in where the 'r' goes in assembly output.
Dale Johannesenb1888e72007-08-05 18:49:15 +0000139// These instructions cannot address 80-bit memory.
Craig Topperc458c7c62015-12-01 06:13:16 +0000140multiclass FPBinary<SDNode OpNode, Format fp, string asmstring,
141 bit Forward = 1> {
Simon Pilgrime0434fa2017-12-24 12:20:21 +0000142let mayLoad = 1, hasSideEffects = 1 in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000143// ST(0) = ST(0) + [mem]
Michael Liao5bf95782014-12-04 05:20:33 +0000144def _Fp32m : FpIf32<(outs RFP32:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000145 (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000146 [!if(Forward,
147 (set RFP32:$dst,
148 (OpNode RFP32:$src1, (loadf32 addr:$src2))),
149 (set RFP32:$dst,
150 (OpNode (loadf32 addr:$src2), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000151def _Fp64m : FpIf64<(outs RFP64:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000152 (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000153 [!if(Forward,
154 (set RFP64:$dst,
155 (OpNode RFP64:$src1, (loadf64 addr:$src2))),
156 (set RFP64:$dst,
157 (OpNode (loadf64 addr:$src2), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000158def _Fp64m32: FpIf64<(outs RFP64:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000159 (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000160 [!if(Forward,
161 (set RFP64:$dst,
162 (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2)))),
163 (set RFP64:$dst,
164 (OpNode (f64 (extloadf32 addr:$src2)), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000165def _Fp80m32: FpI_<(outs RFP80:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000166 (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000167 [!if(Forward,
168 (set RFP80:$dst,
169 (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2)))),
170 (set RFP80:$dst,
171 (OpNode (f80 (extloadf32 addr:$src2)), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000172def _Fp80m64: FpI_<(outs RFP80:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000173 (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000174 [!if(Forward,
175 (set RFP80:$dst,
176 (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2)))),
177 (set RFP80:$dst,
178 (OpNode (f80 (extloadf64 addr:$src2)), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000179def _F32m : FPI<0xD8, fp, (outs), (ins f32mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000180 !strconcat("f", asmstring, "{s}\t$src")>;
Michael Liao5bf95782014-12-04 05:20:33 +0000181def _F64m : FPI<0xDC, fp, (outs), (ins f64mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000182 !strconcat("f", asmstring, "{l}\t$src")>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000183// ST(0) = ST(0) + [memint]
Michael Liao5bf95782014-12-04 05:20:33 +0000184def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000185 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000186 [!if(Forward,
187 (set RFP32:$dst,
188 (OpNode RFP32:$src1, (X86fild addr:$src2, i16))),
189 (set RFP32:$dst,
190 (OpNode (X86fild addr:$src2, i16), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000191def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000192 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000193 [!if(Forward,
194 (set RFP32:$dst,
195 (OpNode RFP32:$src1, (X86fild addr:$src2, i32))),
196 (set RFP32:$dst,
197 (OpNode (X86fild addr:$src2, i32), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000198def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000199 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000200 [!if(Forward,
201 (set RFP64:$dst,
202 (OpNode RFP64:$src1, (X86fild addr:$src2, i16))),
203 (set RFP64:$dst,
204 (OpNode (X86fild addr:$src2, i16), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000205def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000206 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000207 [!if(Forward,
208 (set RFP64:$dst,
209 (OpNode RFP64:$src1, (X86fild addr:$src2, i32))),
210 (set RFP64:$dst,
211 (OpNode (X86fild addr:$src2, i32), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000212def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
Craig Topperc458c7c62015-12-01 06:13:16 +0000213 OneArgFPRW,
214 [!if(Forward,
215 (set RFP80:$dst,
216 (OpNode RFP80:$src1, (X86fild addr:$src2, i16))),
217 (set RFP80:$dst,
218 (OpNode (X86fild addr:$src2, i16), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000219def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
Craig Topperc458c7c62015-12-01 06:13:16 +0000220 OneArgFPRW,
221 [!if(Forward,
222 (set RFP80:$dst,
223 (OpNode RFP80:$src1, (X86fild addr:$src2, i32))),
224 (set RFP80:$dst,
225 (OpNode (X86fild addr:$src2, i32), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000226def _FI16m : FPI<0xDE, fp, (outs), (ins i16mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000227 !strconcat("fi", asmstring, "{s}\t$src")>;
Michael Liao5bf95782014-12-04 05:20:33 +0000228def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000229 !strconcat("fi", asmstring, "{l}\t$src")>;
Simon Pilgrime0434fa2017-12-24 12:20:21 +0000230} // mayLoad = 1, hasSideEffects = 1
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000231}
232
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000233let Defs = [FPSW] in {
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000234// FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
235// resources.
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000236let hasNoSchedulingInfo = 1 in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000237defm ADD : FPBinary_rr<fadd>;
238defm SUB : FPBinary_rr<fsub>;
239defm MUL : FPBinary_rr<fmul>;
240defm DIV : FPBinary_rr<fdiv>;
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000241}
242
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000243// Sets the scheduling resources for the actual NAME#_F<size>m defintions.
244let SchedRW = [WriteFAddLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000245defm ADD : FPBinary<fadd, MRM0m, "add">;
246defm SUB : FPBinary<fsub, MRM4m, "sub">;
Craig Topperc458c7c62015-12-01 06:13:16 +0000247defm SUBR: FPBinary<fsub ,MRM5m, "subr", 0>;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000248}
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000249
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000250let SchedRW = [WriteFMulLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000251defm MUL : FPBinary<fmul, MRM1m, "mul">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000252}
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000253
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000254let SchedRW = [WriteFDivLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000255defm DIV : FPBinary<fdiv, MRM6m, "div">;
Craig Topperc458c7c62015-12-01 06:13:16 +0000256defm DIVR: FPBinary<fdiv, MRM7m, "divr", 0>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000257}
Simon Pilgrim17e290f2017-08-06 13:21:09 +0000258} // Defs = [FPSW]
Evan Cheng6e595b92006-02-21 19:13:53 +0000259
Craig Topper623b0d62014-01-01 14:22:37 +0000260class FPST0rInst<Format fp, string asm>
261 : FPI<0xD8, fp, (outs), (ins RST:$op), asm>;
262class FPrST0Inst<Format fp, string asm>
263 : FPI<0xDC, fp, (outs), (ins RST:$op), asm>;
264class FPrST0PInst<Format fp, string asm>
265 : FPI<0xDE, fp, (outs), (ins RST:$op), asm>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000266
Evan Cheng6e595b92006-02-21 19:13:53 +0000267// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
268// of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
269// we have to put some 'r's in and take them out of weird places.
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000270let SchedRW = [WriteFAdd] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000271def ADD_FST0r : FPST0rInst <MRM0r, "fadd\t$op">;
272def ADD_FrST0 : FPrST0Inst <MRM0r, "fadd\t{%st(0), $op|$op, st(0)}">;
273def ADD_FPrST0 : FPrST0PInst<MRM0r, "faddp\t$op">;
274def SUBR_FST0r : FPST0rInst <MRM5r, "fsubr\t$op">;
275def SUB_FrST0 : FPrST0Inst <MRM5r, "fsub{r}\t{%st(0), $op|$op, st(0)}">;
276def SUB_FPrST0 : FPrST0PInst<MRM5r, "fsub{r}p\t$op">;
277def SUB_FST0r : FPST0rInst <MRM4r, "fsub\t$op">;
278def SUBR_FrST0 : FPrST0Inst <MRM4r, "fsub{|r}\t{%st(0), $op|$op, st(0)}">;
279def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t$op">;
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000280} // SchedRW
281let SchedRW = [WriteFCom] in {
Simon Pilgrim6415f562017-12-08 20:10:31 +0000282def COM_FST0r : FPST0rInst <MRM2r, "fcom\t$op">;
283def COMP_FST0r : FPST0rInst <MRM3r, "fcomp\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000284} // SchedRW
285let SchedRW = [WriteFMul] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000286def MUL_FST0r : FPST0rInst <MRM1r, "fmul\t$op">;
287def MUL_FrST0 : FPrST0Inst <MRM1r, "fmul\t{%st(0), $op|$op, st(0)}">;
288def MUL_FPrST0 : FPrST0PInst<MRM1r, "fmulp\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000289} // SchedRW
290let SchedRW = [WriteFDiv] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000291def DIVR_FST0r : FPST0rInst <MRM7r, "fdivr\t$op">;
292def DIV_FrST0 : FPrST0Inst <MRM7r, "fdiv{r}\t{%st(0), $op|$op, st(0)}">;
293def DIV_FPrST0 : FPrST0PInst<MRM7r, "fdiv{r}p\t$op">;
294def DIV_FST0r : FPST0rInst <MRM6r, "fdiv\t$op">;
295def DIVR_FrST0 : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st(0), $op|$op, st(0)}">;
296def DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000297} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000298
Evan Cheng6e595b92006-02-21 19:13:53 +0000299// Unary operations.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000300multiclass FPUnary<SDNode OpNode, Format fp, string asmstring> {
Dale Johannesene36c4002007-09-23 14:52:20 +0000301def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000302 [(set RFP32:$dst, (OpNode RFP32:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000303def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000304 [(set RFP64:$dst, (OpNode RFP64:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000305def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000306 [(set RFP80:$dst, (OpNode RFP80:$src))]>;
307def _F : FPI<0xD9, fp, (outs), (ins), asmstring>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000308}
309
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000310let Defs = [FPSW] in {
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000311
Simon Pilgrimd14d2e72018-04-20 21:16:05 +0000312let SchedRW = [WriteFSign] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000313defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
314defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000315}
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000316
Simon Pilgrimf3ae50f2018-05-07 11:50:44 +0000317let SchedRW = [WriteFSqrt80] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000318defm SQRT: FPUnary<fsqrt,MRM_FA, "fsqrt">;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000319
320let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000321defm SIN : FPUnary<fsin, MRM_FE, "fsin">;
322defm COS : FPUnary<fcos, MRM_FF, "fcos">;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000323}
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000324
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000325let SchedRW = [WriteFCom] in {
Craig Topperc50d64b2014-11-26 00:46:26 +0000326let hasSideEffects = 0 in {
Chris Lattner92831732008-01-11 07:18:17 +0000327def TST_Fp32 : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
328def TST_Fp64 : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
329def TST_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000330} // hasSideEffects
331
Simon Pilgrim32d36812018-04-12 10:27:37 +0000332def TST_F : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000333} // SchedRW
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000334} // Defs = [FPSW]
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000335
Sean Callanane739ac82009-09-16 01:13:52 +0000336// Versions of FP instructions that take a single memory operand. Added for the
337// disassembler; remove as they are included with patterns elsewhere.
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000338let SchedRW = [WriteFComLd] in {
Kevin Enderby6f2f8d02010-05-03 21:31:40 +0000339def FCOM32m : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
340def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000341
Simon Pilgrim6415f562017-12-08 20:10:31 +0000342def FCOM64m : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
343def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
344
345def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
346def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000347
348def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
349def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000350} // SchedRW
Sean Callanane739ac82009-09-16 01:13:52 +0000351
Simon Pilgrim6415f562017-12-08 20:10:31 +0000352let SchedRW = [WriteMicrocoded] in {
353def FLDENVm : FPI<0xD9, MRM4m, (outs), (ins f32mem:$src), "fldenv\t$src">;
354def FSTENVm : FPI<0xD9, MRM6m, (outs), (ins f32mem:$dst), "fnstenv\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000355
Craig Topper955308f2016-03-13 02:56:31 +0000356def FRSTORm : FPI<0xDD, MRM4m, (outs), (ins f32mem:$dst), "frstor\t$dst">;
357def FSAVEm : FPI<0xDD, MRM6m, (outs), (ins f32mem:$dst), "fnsave\t$dst">;
358def FNSTSWm : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000359
Marina Yatsinabce1ab62015-08-20 11:51:24 +0000360def FBLDm : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
Craig Topper955308f2016-03-13 02:56:31 +0000361def FBSTPm : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000362} // SchedRW
Sean Callanane739ac82009-09-16 01:13:52 +0000363
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000364// Floating point cmovs.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000365class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
366 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMov]>;
367class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
368 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMov]>;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000369
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000370multiclass FPCMov<PatLeaf cc> {
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000371 def _Fp32 : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000372 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000373 [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000374 cc, EFLAGS))]>;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000375 def _Fp64 : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000376 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000377 [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000378 cc, EFLAGS))]>;
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000379 def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
380 CondMovFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000381 [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000382 cc, EFLAGS))]>,
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000383 Requires<[HasCMov]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000384}
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000385
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000386let Defs = [FPSW] in {
Simon Pilgrim6e160c12018-05-12 18:07:07 +0000387let SchedRW = [WriteFCMOV] in {
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000388let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000389defm CMOVB : FPCMov<X86_COND_B>;
390defm CMOVBE : FPCMov<X86_COND_BE>;
391defm CMOVE : FPCMov<X86_COND_E>;
392defm CMOVP : FPCMov<X86_COND_P>;
393defm CMOVNB : FPCMov<X86_COND_AE>;
394defm CMOVNBE: FPCMov<X86_COND_A>;
395defm CMOVNE : FPCMov<X86_COND_NE>;
396defm CMOVNP : FPCMov<X86_COND_NP>;
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000397} // Uses = [EFLAGS], Constraints = "$src1 = $dst"
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000398
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000399let Predicates = [HasCMov] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000400// These are not factored because there's no clean way to pass DA/DB.
Pete Cooper46361a12015-04-29 23:51:33 +0000401def CMOVB_F : FPI<0xDA, MRM0r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000402 "fcmovb\t{$op, %st(0)|st(0), $op}">;
Pete Cooper46361a12015-04-29 23:51:33 +0000403def CMOVBE_F : FPI<0xDA, MRM2r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000404 "fcmovbe\t{$op, %st(0)|st(0), $op}">;
Pete Cooper46361a12015-04-29 23:51:33 +0000405def CMOVE_F : FPI<0xDA, MRM1r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000406 "fcmove\t{$op, %st(0)|st(0), $op}">;
Pete Cooper46361a12015-04-29 23:51:33 +0000407def CMOVP_F : FPI<0xDA, MRM3r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000408 "fcmovu\t{$op, %st(0)|st(0), $op}">;
Pete Cooper46361a12015-04-29 23:51:33 +0000409def CMOVNB_F : FPI<0xDB, MRM0r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000410 "fcmovnb\t{$op, %st(0)|st(0), $op}">;
Pete Cooper46361a12015-04-29 23:51:33 +0000411def CMOVNBE_F: FPI<0xDB, MRM2r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000412 "fcmovnbe\t{$op, %st(0)|st(0), $op}">;
Pete Cooper46361a12015-04-29 23:51:33 +0000413def CMOVNE_F : FPI<0xDB, MRM1r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000414 "fcmovne\t{$op, %st(0)|st(0), $op}">;
Pete Cooper46361a12015-04-29 23:51:33 +0000415def CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RST:$op),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000416 "fcmovnu\t{$op, %st(0)|st(0), $op}">;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000417} // Predicates = [HasCMov]
Simon Pilgrim65f805f2017-12-05 18:01:26 +0000418} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000419
420// Floating point loads & stores.
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000421let SchedRW = [WriteLoad] in {
Dan Gohman69cc2cb2008-12-03 18:15:48 +0000422let canFoldAsLoad = 1 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000423def LD_Fp32m : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000424 [(set RFP32:$dst, (loadf32 addr:$src))]>;
Dan Gohman8c5d6832010-02-27 23:47:46 +0000425let isReMaterializable = 1 in
Bill Wendlinga2401be2007-12-17 22:17:14 +0000426 def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000427 [(set RFP64:$dst, (loadf64 addr:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000428def LD_Fp80m : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000429 [(set RFP80:$dst, (loadf80 addr:$src))]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000430} // canFoldAsLoad
Dale Johannesene36c4002007-09-23 14:52:20 +0000431def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000432 [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
433def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
434 [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
435def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
436 [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000437def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000438 [(set RFP32:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000439def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000440 [(set RFP32:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000441def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000442 [(set RFP32:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000443def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000444 [(set RFP64:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000445def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000446 [(set RFP64:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000447def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000448 [(set RFP64:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000449def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000450 [(set RFP80:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000451def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000452 [(set RFP80:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000453def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000454 [(set RFP80:$dst, (X86fild addr:$src, i64))]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000455} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000456
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000457let SchedRW = [WriteStore] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000458def ST_Fp32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000459 [(store RFP32:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000460def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000461 [(truncstoref32 RFP64:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000462def ST_Fp64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000463 [(store RFP64:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000464def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000465 [(truncstoref32 RFP80:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000466def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000467 [(truncstoref64 RFP80:$src, addr:$op)]>;
468// FST does not support 80-bit memory target; FSTP must be used.
Evan Cheng6e595b92006-02-21 19:13:53 +0000469
Craig Topperc50d64b2014-11-26 00:46:26 +0000470let mayStore = 1, hasSideEffects = 0 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000471def ST_FpP32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
472def ST_FpP64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
473def ST_FpP64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
474def ST_FpP80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
475def ST_FpP80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000476} // mayStore
477
Dale Johannesena47f7d72007-08-07 20:29:26 +0000478def ST_FpP80m : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000479 [(store RFP80:$src, addr:$op)]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000480
Craig Topperc50d64b2014-11-26 00:46:26 +0000481let mayStore = 1, hasSideEffects = 0 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000482def IST_Fp16m32 : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
483def IST_Fp32m32 : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP, []>;
484def IST_Fp64m32 : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP, []>;
485def IST_Fp16m64 : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
486def IST_Fp32m64 : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP, []>;
487def IST_Fp64m64 : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP, []>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000488def IST_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
489def IST_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP, []>;
490def IST_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP, []>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000491} // mayStore
492} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000493
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000494let mayLoad = 1, SchedRW = [WriteLoad] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000495def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
496def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
497def LD_F80m : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
498def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
499def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
500def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
Chris Lattner317332f2008-01-10 07:59:24 +0000501}
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000502let mayStore = 1, SchedRW = [WriteStore] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000503def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
504def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
505def ST_FP32m : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst">;
506def ST_FP64m : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst">;
507def ST_FP80m : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst">;
508def IST_F16m : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst">;
509def IST_F32m : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst">;
510def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst">;
511def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst">;
512def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst">;
Chris Lattner317332f2008-01-10 07:59:24 +0000513}
Evan Cheng6e595b92006-02-21 19:13:53 +0000514
515// FISTTP requires SSE3 even though it's a FPStack op.
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000516let Predicates = [HasSSE3], SchedRW = [WriteStore] in {
Evan Cheng94b5a802007-07-19 01:14:50 +0000517def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000518 [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000519def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000520 [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000521def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000522 [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000523def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000524 [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000525def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000526 [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000527def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000528 [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000529def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000530 [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000531def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000532 [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000533def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000534 [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
535} // Predicates = [HasSSE3]
Evan Cheng6e595b92006-02-21 19:13:53 +0000536
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000537let mayStore = 1, SchedRW = [WriteStore] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000538def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst">;
539def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst">;
540def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll}\t$dst">;
Chris Lattner317332f2008-01-10 07:59:24 +0000541}
Evan Cheng6e595b92006-02-21 19:13:53 +0000542
543// FP Stack manipulation instructions.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000544let SchedRW = [WriteMove] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000545def LD_Frr : FPI<0xD9, MRM0r, (outs), (ins RST:$op), "fld\t$op">;
546def ST_Frr : FPI<0xDD, MRM2r, (outs), (ins RST:$op), "fst\t$op">;
547def ST_FPrr : FPI<0xDD, MRM3r, (outs), (ins RST:$op), "fstp\t$op">;
548def XCH_F : FPI<0xD9, MRM1r, (outs), (ins RST:$op), "fxch\t$op">;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000549}
Evan Cheng6e595b92006-02-21 19:13:53 +0000550
551// Floating point constant loads.
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000552let isReMaterializable = 1, SchedRW = [WriteZero] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000553def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000554 [(set RFP32:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000555def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000556 [(set RFP32:$dst, fpimm1)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000557def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000558 [(set RFP64:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000559def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000560 [(set RFP64:$dst, fpimm1)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000561def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000562 [(set RFP80:$dst, fpimm0)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000563def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000564 [(set RFP80:$dst, fpimm1)]>;
Dan Gohmane8c1e422007-06-26 00:48:07 +0000565}
Evan Cheng6e595b92006-02-21 19:13:53 +0000566
Clement Courbetb78ab502018-05-31 11:41:27 +0000567let SchedRW = [WriteFLD0] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000568def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
Clement Courbetb78ab502018-05-31 11:41:27 +0000569
570let SchedRW = [WriteFLD1] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000571def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
Evan Cheng6e595b92006-02-21 19:13:53 +0000572
Clement Courbet2e41c5a2018-05-31 14:22:01 +0000573let SchedRW = [WriteFLDC], Defs = [FPSW] in {
574def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
575def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
576def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
577def FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", []>;
578def FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", []>;
579} // SchedRW
580
Evan Cheng6e595b92006-02-21 19:13:53 +0000581// Floating point compares.
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000582let SchedRW = [WriteFCom] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000583def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000584 [(set FPSW, (trunc (X86cmp RFP32:$lhs, RFP32:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000585def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000586 [(set FPSW, (trunc (X86cmp RFP64:$lhs, RFP64:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000587def UCOM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000588 [(set FPSW, (trunc (X86cmp RFP80:$lhs, RFP80:$rhs)))]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000589} // SchedRW
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000590} // Defs = [FPSW]
591
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000592let SchedRW = [WriteFCom] in {
Chris Lattner83facb02010-03-19 00:01:11 +0000593// CC = ST(0) cmp ST(i)
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000594let Defs = [EFLAGS, FPSW] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000595def UCOM_FpIr32: FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000596 [(set EFLAGS, (X86cmp RFP32:$lhs, RFP32:$rhs))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000597def UCOM_FpIr64: FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000598 [(set EFLAGS, (X86cmp RFP64:$lhs, RFP64:$rhs))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000599def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000600 [(set EFLAGS, (X86cmp RFP80:$lhs, RFP80:$rhs))]>;
Evan Cheng8ee1ecf2007-09-25 19:08:02 +0000601}
602
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000603let Defs = [FPSW], Uses = [ST0] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000604def UCOM_Fr : FPI<0xDD, MRM4r, // FPSW = cmp ST(0) with ST(i)
Simon Pilgrim32d36812018-04-12 10:27:37 +0000605 (outs), (ins RST:$reg), "fucom\t$reg">;
Craig Topper623b0d62014-01-01 14:22:37 +0000606def UCOM_FPr : FPI<0xDD, MRM5r, // FPSW = cmp ST(0) with ST(i), pop
Simon Pilgrim32d36812018-04-12 10:27:37 +0000607 (outs), (ins RST:$reg), "fucomp\t$reg">;
Craig Topper56f0ed812014-02-19 08:25:02 +0000608def UCOM_FPPr : FPI<0xDA, MRM_E9, // cmp ST(0) with ST(1), pop, pop
Simon Pilgrim32d36812018-04-12 10:27:37 +0000609 (outs), (ins), "fucompp">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000610}
Evan Cheng6e595b92006-02-21 19:13:53 +0000611
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000612let Defs = [EFLAGS, FPSW], Uses = [ST0] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000613def UCOM_FIr : FPI<0xDB, MRM5r, // CC = cmp ST(0) with ST(i)
Simon Pilgrim32d36812018-04-12 10:27:37 +0000614 (outs), (ins RST:$reg), "fucomi\t$reg">;
Craig Topper623b0d62014-01-01 14:22:37 +0000615def UCOM_FIPr : FPI<0xDF, MRM5r, // CC = cmp ST(0) with ST(i), pop
Simon Pilgrim32d36812018-04-12 10:27:37 +0000616 (outs), (ins RST:$reg), "fucompi\t$reg">;
Evan Cheng3e18e502007-09-11 19:55:27 +0000617}
Evan Cheng6e595b92006-02-21 19:13:53 +0000618
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000619let Defs = [EFLAGS, FPSW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000620def COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RST:$reg), "fcomi\t$reg">;
621def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RST:$reg), "fcompi\t$reg">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000622}
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000623} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000624
Evan Cheng6e595b92006-02-21 19:13:53 +0000625// Floating point flag ops.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000626let SchedRW = [WriteALU] in {
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000627let Defs = [AX], Uses = [FPSW] in
Craig Topper56f0ed812014-02-19 08:25:02 +0000628def FNSTSW16r : I<0xDF, MRM_E0, // AX = fp flags
Craig Topperefd67d42013-07-31 02:47:52 +0000629 (outs), (ins), "fnstsw\t{%ax|ax}",
Simon Pilgrim32d36812018-04-12 10:27:37 +0000630 [(set AX, (X86fp_stsw FPSW))]>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000631let Defs = [FPSW] in
Evan Cheng6e595b92006-02-21 19:13:53 +0000632def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
Andrew Trickedd006c2010-10-22 03:58:29 +0000633 (outs), (ins i16mem:$dst), "fnstcw\t$dst",
Simon Pilgrim32d36812018-04-12 10:27:37 +0000634 [(X86fp_cwd_get16 addr:$dst)]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000635} // SchedRW
Simon Pilgrim05710a82017-09-06 10:23:12 +0000636let Defs = [FPSW], mayLoad = 1 in
Evan Cheng6e595b92006-02-21 19:13:53 +0000637def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
Simon Pilgrim32d36812018-04-12 10:27:37 +0000638 (outs), (ins i16mem:$dst), "fldcw\t$dst", []>,
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000639 Sched<[WriteLoad]>;
Evan Chengd5847812006-02-21 20:00:20 +0000640
Chris Lattnerdec85b82010-10-05 05:32:15 +0000641// FPU control instructions
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000642let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim05710a82017-09-06 10:23:12 +0000643let Defs = [FPSW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000644def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
645def FFREE : FPI<0xDD, MRM0r, (outs), (ins RST:$reg), "ffree\t$reg">;
646def FFREEP : FPI<0xDF, MRM0r, (outs), (ins RST:$reg), "ffreep\t$reg">;
Chris Ray535e7d12017-01-27 18:02:53 +0000647
Sean Callanan04d8cb72009-12-18 00:01:26 +0000648// Clear exceptions
Simon Pilgrim32d36812018-04-12 10:27:37 +0000649def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000650} // Defs = [FPSW]
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000651} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000652
Sanjay Patel05daae72018-03-19 14:26:50 +0000653// Operand-less floating-point instructions for the disassembler.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000654def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000655
Sanjay Patel05daae72018-03-19 14:26:50 +0000656let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim05710a82017-09-06 10:23:12 +0000657let Defs = [FPSW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000658def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
659def FXAM : I<0xD9, MRM_E5, (outs), (ins), "fxam", []>;
Simon Pilgrim32d36812018-04-12 10:27:37 +0000660def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
661def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
662def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
663def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
664def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
665def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
666def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
667def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
668def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
669def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
670def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
671def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
672def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
673def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000674} // Defs = [FPSW]
Sean Callanan04d8cb72009-12-18 00:01:26 +0000675
Craig Topper33dc01d2018-05-01 04:42:00 +0000676def FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000677 "fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, TB,
Craig Toppera1639502017-12-15 17:22:58 +0000678 Requires<[HasFXSR]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000679def FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000680 "fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
681 TB, Requires<[HasFXSR, In64BitMode]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000682def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000683 "fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
Craig Toppera1639502017-12-15 17:22:58 +0000684 TB, Requires<[HasFXSR]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000685def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000686 "fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
687 TB, Requires<[HasFXSR, In64BitMode]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000688} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000689
Evan Chengd5847812006-02-21 20:00:20 +0000690//===----------------------------------------------------------------------===//
691// Non-Instruction Patterns
692//===----------------------------------------------------------------------===//
693
Dale Johannesena47f7d72007-08-07 20:29:26 +0000694// Required for RET of f32 / f64 / f80 values.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000695def : Pat<(X86fld addr:$src, f32), (LD_Fp32m addr:$src)>;
696def : Pat<(X86fld addr:$src, f64), (LD_Fp64m addr:$src)>;
Dale Johannesenb1888e72007-08-05 18:49:15 +0000697def : Pat<(X86fld addr:$src, f80), (LD_Fp80m addr:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000698
Dale Johannesena47f7d72007-08-07 20:29:26 +0000699// Required for CALL which return f32 / f64 / f80 values.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000700def : Pat<(X86fst RFP32:$src, addr:$op, f32), (ST_Fp32m addr:$op, RFP32:$src)>;
Michael Liao5bf95782014-12-04 05:20:33 +0000701def : Pat<(X86fst RFP64:$src, addr:$op, f32), (ST_Fp64m32 addr:$op,
Sean Callanan04d8cb72009-12-18 00:01:26 +0000702 RFP64:$src)>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000703def : Pat<(X86fst RFP64:$src, addr:$op, f64), (ST_Fp64m addr:$op, RFP64:$src)>;
Michael Liao5bf95782014-12-04 05:20:33 +0000704def : Pat<(X86fst RFP80:$src, addr:$op, f32), (ST_Fp80m32 addr:$op,
Sean Callanan04d8cb72009-12-18 00:01:26 +0000705 RFP80:$src)>;
Michael Liao5bf95782014-12-04 05:20:33 +0000706def : Pat<(X86fst RFP80:$src, addr:$op, f64), (ST_Fp80m64 addr:$op,
Sean Callanan04d8cb72009-12-18 00:01:26 +0000707 RFP80:$src)>;
708def : Pat<(X86fst RFP80:$src, addr:$op, f80), (ST_FpP80m addr:$op,
709 RFP80:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000710
711// Floating point constant -0.0 and -1.0
Dale Johannesene36c4002007-09-23 14:52:20 +0000712def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
713def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
714def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
715def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000716def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
717def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
Evan Chengd5847812006-02-21 20:00:20 +0000718
719// Used to conv. i64 to f64 since there isn't a SSE version.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000720def : Pat<(X86fildflag addr:$src, i64), (ILD_Fp64m64 addr:$src)>;
Dale Johannesena2b3c172007-07-03 00:53:03 +0000721
Chris Lattnerd587e582008-03-09 07:05:32 +0000722// FP extensions map onto simple pseudo-value conversions if they are to/from
723// the FP stack.
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000724def : Pat<(f64 (fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000725 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000726def : Pat<(f80 (fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000727 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000728def : Pat<(f80 (fpextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000729 Requires<[FPStackf64]>;
730
731// FP truncations map onto simple pseudo-value conversions if they are to/from
732// the FP stack. We have validated that only value-preserving truncations make
733// it through isel.
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000734def : Pat<(f32 (fpround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000735 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000736def : Pat<(f32 (fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000737 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000738def : Pat<(f64 (fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000739 Requires<[FPStackf64]>;