blob: b1c64163894197494103d02b5251241f29c81333 [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Jia Liub22310f2012-02-18 12:03:15 +00006//
Evan Cheng6e595b92006-02-21 19:13:53 +00007//===----------------------------------------------------------------------===//
8//
9// This file describes the X86 x87 FPU instruction set, defining the
10// instructions, and properties of the instructions which are needed for code
11// generation, machine code emission, and analysis.
12//
13//===----------------------------------------------------------------------===//
14
Evan Cheng4f674922006-03-17 19:55:52 +000015//===----------------------------------------------------------------------===//
Evan Cheng9bf978d2006-03-18 01:23:20 +000016// FPStack specific DAG Nodes.
17//===----------------------------------------------------------------------===//
18
Michael Liao5bf95782014-12-04 05:20:33 +000019def SDTX86FpGet2 : SDTypeProfile<2, 0, [SDTCisVT<0, f80>,
Chris Lattnerd587e582008-03-09 07:05:32 +000020 SDTCisVT<1, f80>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000021def SDTX86Fld : SDTypeProfile<1, 2, [SDTCisFP<0>,
Michael Liao5bf95782014-12-04 05:20:33 +000022 SDTCisPtrTy<1>,
Dale Johannesen23f631d2007-07-10 20:53:41 +000023 SDTCisVT<2, OtherVT>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000024def SDTX86Fst : SDTypeProfile<0, 3, [SDTCisFP<0>,
Michael Liao5bf95782014-12-04 05:20:33 +000025 SDTCisPtrTy<1>,
Dale Johannesen23f631d2007-07-10 20:53:41 +000026 SDTCisVT<2, OtherVT>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000027def SDTX86Fild : SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisPtrTy<1>,
28 SDTCisVT<2, OtherVT>]>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +000029def SDTX86Fnstsw : SDTypeProfile<1, 1, [SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
Dale Johannesenc2a60892007-07-03 17:07:33 +000030def SDTX86FpToIMem : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000031
Anton Korobeynikov91460e42007-11-16 01:31:51 +000032def SDTX86CwdStore : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
33
Chris Lattner317332f2008-01-10 07:59:24 +000034def X86fld : SDNode<"X86ISD::FLD", SDTX86Fld,
Chris Lattnera5156c32010-09-22 01:28:21 +000035 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000036def X86fst : SDNode<"X86ISD::FST", SDTX86Fst,
Chris Lattner2a0a3b42010-12-23 18:28:41 +000037 [SDNPHasChain, SDNPInGlue, SDNPMayStore,
Chris Lattnera5156c32010-09-22 01:28:21 +000038 SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000039def X86fild : SDNode<"X86ISD::FILD", SDTX86Fild,
Chris Lattnera5156c32010-09-22 01:28:21 +000040 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000041def X86fildflag : SDNode<"X86ISD::FILD_FLAG", SDTX86Fild,
Chris Lattner2a0a3b42010-12-23 18:28:41 +000042 [SDNPHasChain, SDNPOutGlue, SDNPMayLoad,
Chris Lattnera5156c32010-09-22 01:28:21 +000043 SDNPMemOperand]>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +000044def X86fp_stsw : SDNode<"X86ISD::FNSTSW16r", SDTX86Fnstsw>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000045def X86fp_to_i16mem : SDNode<"X86ISD::FP_TO_INT16_IN_MEM", SDTX86FpToIMem,
Chris Lattner78f518b2010-09-22 01:05:16 +000046 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000047def X86fp_to_i32mem : SDNode<"X86ISD::FP_TO_INT32_IN_MEM", SDTX86FpToIMem,
Chris Lattner78f518b2010-09-22 01:05:16 +000048 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000049def X86fp_to_i64mem : SDNode<"X86ISD::FP_TO_INT64_IN_MEM", SDTX86FpToIMem,
Chris Lattner78f518b2010-09-22 01:05:16 +000050 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Anton Korobeynikov91460e42007-11-16 01:31:51 +000051def X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m", SDTX86CwdStore,
Chris Lattner78f518b2010-09-22 01:05:16 +000052 [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
53 SDNPMemOperand]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000054
55//===----------------------------------------------------------------------===//
Evan Cheng4f674922006-03-17 19:55:52 +000056// FPStack pattern fragments
57//===----------------------------------------------------------------------===//
58
Daniel Sanders11300ce2017-10-13 21:28:03 +000059def fpimm0 : FPImmLeaf<fAny, [{
60 return Imm.isExactlyValue(+0.0);
Evan Cheng4f674922006-03-17 19:55:52 +000061}]>;
62
Daniel Sanders11300ce2017-10-13 21:28:03 +000063def fpimmneg0 : FPImmLeaf<fAny, [{
64 return Imm.isExactlyValue(-0.0);
Evan Cheng4f674922006-03-17 19:55:52 +000065}]>;
66
Daniel Sanders11300ce2017-10-13 21:28:03 +000067def fpimm1 : FPImmLeaf<fAny, [{
68 return Imm.isExactlyValue(+1.0);
Evan Cheng4f674922006-03-17 19:55:52 +000069}]>;
70
Daniel Sanders11300ce2017-10-13 21:28:03 +000071def fpimmneg1 : FPImmLeaf<fAny, [{
72 return Imm.isExactlyValue(-1.0);
Evan Cheng4f674922006-03-17 19:55:52 +000073}]>;
74
Simon Pilgrim4fecbd82017-11-28 18:10:29 +000075// Some 'special' instructions - expanded after instruction selection.
76let usesCustomInserter = 1, hasNoSchedulingInfo = 1 in {
Eric Christophera964f4d2010-11-30 21:57:32 +000077 def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000078 [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000079 def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000080 [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000081 def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000082 [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000083 def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000084 [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000085 def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000086 [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000087 def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +000088 [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000089 def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +000090 [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000091 def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +000092 [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +000093 def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +000094 [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
Evan Chengd5847812006-02-21 20:00:20 +000095}
96
Dale Johannesena47f7d72007-08-07 20:29:26 +000097// All FP Stack operations are represented with four instructions here. The
98// first three instructions, generated by the instruction selector, use "RFP32"
99// "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
Michael Liao5bf95782014-12-04 05:20:33 +0000100// 64-bit or 80-bit floating point values. These sizes apply to the values,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000101// not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
102// copied to each other without losing information. These instructions are all
103// pseudo instructions and use the "_Fp" suffix.
104// In some cases there are additional variants with a mixture of different
105// register sizes.
Evan Cheng6e595b92006-02-21 19:13:53 +0000106// The second instruction is defined with FPI, which is the actual instruction
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000107// emitted by the assembler. These use "RST" registers, although frequently
Dale Johannesena47f7d72007-08-07 20:29:26 +0000108// the actual register(s) used are implicit. These are always 80 bits.
Michael Liao5bf95782014-12-04 05:20:33 +0000109// The FP stackifier pass converts one to the other after register allocation
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000110// occurs.
Evan Cheng6e595b92006-02-21 19:13:53 +0000111//
112// Note that the FpI instruction should have instruction selection info (e.g.
113// a pattern) and the FPI instruction should have emission info (e.g. opcode
114// encoding and asm printing info).
115
Bob Wilsona967c422010-08-26 18:08:11 +0000116// FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
Dale Johannesene36c4002007-09-23 14:52:20 +0000117// f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
118// f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
119// f80 instructions cannot use SSE and use neither of these.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000120class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
121 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
122class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
123 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000124
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000125// Factoring for arithmetic.
126multiclass FPBinary_rr<SDNode OpNode> {
127// Register op register -> register
128// These are separated out because they have no reversed form.
Dale Johannesene36c4002007-09-23 14:52:20 +0000129def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000130 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000131def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000132 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000133def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000134 [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000135}
136// The FopST0 series are not included here because of the irregularities
137// in where the 'r' goes in assembly output.
Dale Johannesenb1888e72007-08-05 18:49:15 +0000138// These instructions cannot address 80-bit memory.
Craig Topperc458c7c62015-12-01 06:13:16 +0000139multiclass FPBinary<SDNode OpNode, Format fp, string asmstring,
140 bit Forward = 1> {
Simon Pilgrime0434fa2017-12-24 12:20:21 +0000141let mayLoad = 1, hasSideEffects = 1 in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000142// ST(0) = ST(0) + [mem]
Michael Liao5bf95782014-12-04 05:20:33 +0000143def _Fp32m : FpIf32<(outs RFP32:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000144 (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000145 [!if(Forward,
146 (set RFP32:$dst,
147 (OpNode RFP32:$src1, (loadf32 addr:$src2))),
148 (set RFP32:$dst,
149 (OpNode (loadf32 addr:$src2), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000150def _Fp64m : FpIf64<(outs RFP64:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000151 (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000152 [!if(Forward,
153 (set RFP64:$dst,
154 (OpNode RFP64:$src1, (loadf64 addr:$src2))),
155 (set RFP64:$dst,
156 (OpNode (loadf64 addr:$src2), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000157def _Fp64m32: FpIf64<(outs RFP64:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000158 (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000159 [!if(Forward,
160 (set RFP64:$dst,
161 (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2)))),
162 (set RFP64:$dst,
163 (OpNode (f64 (extloadf32 addr:$src2)), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000164def _Fp80m32: FpI_<(outs RFP80:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000165 (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000166 [!if(Forward,
167 (set RFP80:$dst,
168 (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2)))),
169 (set RFP80:$dst,
170 (OpNode (f80 (extloadf32 addr:$src2)), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000171def _Fp80m64: FpI_<(outs RFP80:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000172 (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000173 [!if(Forward,
174 (set RFP80:$dst,
175 (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2)))),
176 (set RFP80:$dst,
177 (OpNode (f80 (extloadf64 addr:$src2)), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000178def _F32m : FPI<0xD8, fp, (outs), (ins f32mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000179 !strconcat("f", asmstring, "{s}\t$src")>;
Michael Liao5bf95782014-12-04 05:20:33 +0000180def _F64m : FPI<0xDC, fp, (outs), (ins f64mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000181 !strconcat("f", asmstring, "{l}\t$src")>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000182// ST(0) = ST(0) + [memint]
Michael Liao5bf95782014-12-04 05:20:33 +0000183def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000184 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000185 [!if(Forward,
186 (set RFP32:$dst,
187 (OpNode RFP32:$src1, (X86fild addr:$src2, i16))),
188 (set RFP32:$dst,
189 (OpNode (X86fild addr:$src2, i16), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000190def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000191 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000192 [!if(Forward,
193 (set RFP32:$dst,
194 (OpNode RFP32:$src1, (X86fild addr:$src2, i32))),
195 (set RFP32:$dst,
196 (OpNode (X86fild addr:$src2, i32), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000197def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000198 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000199 [!if(Forward,
200 (set RFP64:$dst,
201 (OpNode RFP64:$src1, (X86fild addr:$src2, i16))),
202 (set RFP64:$dst,
203 (OpNode (X86fild addr:$src2, i16), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000204def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000205 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000206 [!if(Forward,
207 (set RFP64:$dst,
208 (OpNode RFP64:$src1, (X86fild addr:$src2, i32))),
209 (set RFP64:$dst,
210 (OpNode (X86fild addr:$src2, i32), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000211def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
Craig Topperc458c7c62015-12-01 06:13:16 +0000212 OneArgFPRW,
213 [!if(Forward,
214 (set RFP80:$dst,
215 (OpNode RFP80:$src1, (X86fild addr:$src2, i16))),
216 (set RFP80:$dst,
217 (OpNode (X86fild addr:$src2, i16), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000218def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
Craig Topperc458c7c62015-12-01 06:13:16 +0000219 OneArgFPRW,
220 [!if(Forward,
221 (set RFP80:$dst,
222 (OpNode RFP80:$src1, (X86fild addr:$src2, i32))),
223 (set RFP80:$dst,
224 (OpNode (X86fild addr:$src2, i32), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000225def _FI16m : FPI<0xDE, fp, (outs), (ins i16mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000226 !strconcat("fi", asmstring, "{s}\t$src")>;
Michael Liao5bf95782014-12-04 05:20:33 +0000227def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000228 !strconcat("fi", asmstring, "{l}\t$src")>;
Simon Pilgrime0434fa2017-12-24 12:20:21 +0000229} // mayLoad = 1, hasSideEffects = 1
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000230}
231
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000232let Defs = [FPSW] in {
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000233// FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
234// resources.
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000235let hasNoSchedulingInfo = 1 in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000236defm ADD : FPBinary_rr<fadd>;
237defm SUB : FPBinary_rr<fsub>;
238defm MUL : FPBinary_rr<fmul>;
239defm DIV : FPBinary_rr<fdiv>;
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000240}
241
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000242// Sets the scheduling resources for the actual NAME#_F<size>m defintions.
243let SchedRW = [WriteFAddLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000244defm ADD : FPBinary<fadd, MRM0m, "add">;
245defm SUB : FPBinary<fsub, MRM4m, "sub">;
Craig Topperc458c7c62015-12-01 06:13:16 +0000246defm SUBR: FPBinary<fsub ,MRM5m, "subr", 0>;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000247}
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000248
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000249let SchedRW = [WriteFMulLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000250defm MUL : FPBinary<fmul, MRM1m, "mul">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000251}
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000252
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000253let SchedRW = [WriteFDivLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000254defm DIV : FPBinary<fdiv, MRM6m, "div">;
Craig Topperc458c7c62015-12-01 06:13:16 +0000255defm DIVR: FPBinary<fdiv, MRM7m, "divr", 0>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000256}
Simon Pilgrim17e290f2017-08-06 13:21:09 +0000257} // Defs = [FPSW]
Evan Cheng6e595b92006-02-21 19:13:53 +0000258
Craig Topper623b0d62014-01-01 14:22:37 +0000259class FPST0rInst<Format fp, string asm>
Craig Topper7a2944e2019-02-04 04:15:10 +0000260 : FPI<0xD8, fp, (outs), (ins RSTi:$op), asm>;
Craig Topper623b0d62014-01-01 14:22:37 +0000261class FPrST0Inst<Format fp, string asm>
Craig Topper7a2944e2019-02-04 04:15:10 +0000262 : FPI<0xDC, fp, (outs), (ins RSTi:$op), asm>;
Craig Topper623b0d62014-01-01 14:22:37 +0000263class FPrST0PInst<Format fp, string asm>
Craig Topper7a2944e2019-02-04 04:15:10 +0000264 : FPI<0xDE, fp, (outs), (ins RSTi:$op), asm>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000265
Evan Cheng6e595b92006-02-21 19:13:53 +0000266// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
267// of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
268// we have to put some 'r's in and take them out of weird places.
Craig Topper9dfe9b082019-01-30 07:08:44 +0000269let SchedRW = [WriteFAdd], Defs = [FPSW] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000270def ADD_FST0r : FPST0rInst <MRM0r, "fadd\t$op">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000271def ADD_FrST0 : FPrST0Inst <MRM0r, "fadd\t{%st, $op|$op, st}">;
Craig Topper623b0d62014-01-01 14:22:37 +0000272def ADD_FPrST0 : FPrST0PInst<MRM0r, "faddp\t$op">;
273def SUBR_FST0r : FPST0rInst <MRM5r, "fsubr\t$op">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000274def SUB_FrST0 : FPrST0Inst <MRM5r, "fsub{r}\t{%st, $op|$op, st}">;
Craig Topper623b0d62014-01-01 14:22:37 +0000275def SUB_FPrST0 : FPrST0PInst<MRM5r, "fsub{r}p\t$op">;
276def SUB_FST0r : FPST0rInst <MRM4r, "fsub\t$op">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000277def SUBR_FrST0 : FPrST0Inst <MRM4r, "fsub{|r}\t{%st, $op|$op, st}">;
Craig Topper623b0d62014-01-01 14:22:37 +0000278def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t$op">;
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000279} // SchedRW
Craig Topper9dfe9b082019-01-30 07:08:44 +0000280let SchedRW = [WriteFCom], Defs = [FPSW] in {
Simon Pilgrim6415f562017-12-08 20:10:31 +0000281def COM_FST0r : FPST0rInst <MRM2r, "fcom\t$op">;
282def COMP_FST0r : FPST0rInst <MRM3r, "fcomp\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000283} // SchedRW
Craig Topper9dfe9b082019-01-30 07:08:44 +0000284let SchedRW = [WriteFMul], Defs = [FPSW] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000285def MUL_FST0r : FPST0rInst <MRM1r, "fmul\t$op">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000286def MUL_FrST0 : FPrST0Inst <MRM1r, "fmul\t{%st, $op|$op, st}">;
Craig Topper623b0d62014-01-01 14:22:37 +0000287def MUL_FPrST0 : FPrST0PInst<MRM1r, "fmulp\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000288} // SchedRW
Craig Topper9dfe9b082019-01-30 07:08:44 +0000289let SchedRW = [WriteFDiv], Defs = [FPSW] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000290def DIVR_FST0r : FPST0rInst <MRM7r, "fdivr\t$op">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000291def DIV_FrST0 : FPrST0Inst <MRM7r, "fdiv{r}\t{%st, $op|$op, st}">;
Craig Topper623b0d62014-01-01 14:22:37 +0000292def DIV_FPrST0 : FPrST0PInst<MRM7r, "fdiv{r}p\t$op">;
293def DIV_FST0r : FPST0rInst <MRM6r, "fdiv\t$op">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000294def DIVR_FrST0 : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st, $op|$op, st}">;
Craig Topper623b0d62014-01-01 14:22:37 +0000295def DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000296} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000297
Evan Cheng6e595b92006-02-21 19:13:53 +0000298// Unary operations.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000299multiclass FPUnary<SDNode OpNode, Format fp, string asmstring> {
Dale Johannesene36c4002007-09-23 14:52:20 +0000300def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000301 [(set RFP32:$dst, (OpNode RFP32:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000302def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000303 [(set RFP64:$dst, (OpNode RFP64:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000304def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000305 [(set RFP80:$dst, (OpNode RFP80:$src))]>;
306def _F : FPI<0xD9, fp, (outs), (ins), asmstring>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000307}
308
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000309let Defs = [FPSW] in {
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000310
Simon Pilgrimd14d2e72018-04-20 21:16:05 +0000311let SchedRW = [WriteFSign] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000312defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
313defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000314}
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000315
Simon Pilgrimf3ae50f2018-05-07 11:50:44 +0000316let SchedRW = [WriteFSqrt80] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000317defm SQRT: FPUnary<fsqrt,MRM_FA, "fsqrt">;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000318
319let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000320defm SIN : FPUnary<fsin, MRM_FE, "fsin">;
321defm COS : FPUnary<fcos, MRM_FF, "fcos">;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000322}
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000323
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000324let SchedRW = [WriteFCom] in {
Craig Topperc50d64b2014-11-26 00:46:26 +0000325let hasSideEffects = 0 in {
Chris Lattner92831732008-01-11 07:18:17 +0000326def TST_Fp32 : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
327def TST_Fp64 : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
328def TST_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000329} // hasSideEffects
330
Simon Pilgrim32d36812018-04-12 10:27:37 +0000331def TST_F : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000332} // SchedRW
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000333} // Defs = [FPSW]
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000334
Sean Callanane739ac82009-09-16 01:13:52 +0000335// Versions of FP instructions that take a single memory operand. Added for the
336// disassembler; remove as they are included with patterns elsewhere.
Craig Topper9dfe9b082019-01-30 07:08:44 +0000337let SchedRW = [WriteFComLd], Defs = [FPSW] in {
Kevin Enderby6f2f8d02010-05-03 21:31:40 +0000338def FCOM32m : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
339def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000340
Simon Pilgrim6415f562017-12-08 20:10:31 +0000341def FCOM64m : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
342def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
343
344def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
345def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000346
347def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
348def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000349} // SchedRW
Sean Callanane739ac82009-09-16 01:13:52 +0000350
Simon Pilgrim6415f562017-12-08 20:10:31 +0000351let SchedRW = [WriteMicrocoded] in {
352def FLDENVm : FPI<0xD9, MRM4m, (outs), (ins f32mem:$src), "fldenv\t$src">;
353def FSTENVm : FPI<0xD9, MRM6m, (outs), (ins f32mem:$dst), "fnstenv\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000354
Craig Topper955308f2016-03-13 02:56:31 +0000355def FRSTORm : FPI<0xDD, MRM4m, (outs), (ins f32mem:$dst), "frstor\t$dst">;
356def FSAVEm : FPI<0xDD, MRM6m, (outs), (ins f32mem:$dst), "fnsave\t$dst">;
357def FNSTSWm : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000358
Marina Yatsinabce1ab62015-08-20 11:51:24 +0000359def FBLDm : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
Craig Topper955308f2016-03-13 02:56:31 +0000360def FBSTPm : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000361} // SchedRW
Sean Callanane739ac82009-09-16 01:13:52 +0000362
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000363// Floating point cmovs.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000364class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
365 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMov]>;
366class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
367 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMov]>;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000368
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000369multiclass FPCMov<PatLeaf cc> {
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000370 def _Fp32 : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000371 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000372 [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000373 cc, EFLAGS))]>;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000374 def _Fp64 : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000375 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000376 [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000377 cc, EFLAGS))]>;
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000378 def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
379 CondMovFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000380 [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000381 cc, EFLAGS))]>,
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000382 Requires<[HasCMov]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000383}
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000384
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000385let Defs = [FPSW] in {
Simon Pilgrim6e160c12018-05-12 18:07:07 +0000386let SchedRW = [WriteFCMOV] in {
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000387let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000388defm CMOVB : FPCMov<X86_COND_B>;
389defm CMOVBE : FPCMov<X86_COND_BE>;
390defm CMOVE : FPCMov<X86_COND_E>;
391defm CMOVP : FPCMov<X86_COND_P>;
392defm CMOVNB : FPCMov<X86_COND_AE>;
393defm CMOVNBE: FPCMov<X86_COND_A>;
394defm CMOVNE : FPCMov<X86_COND_NE>;
395defm CMOVNP : FPCMov<X86_COND_NP>;
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000396} // Uses = [EFLAGS], Constraints = "$src1 = $dst"
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000397
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000398let Predicates = [HasCMov] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000399// These are not factored because there's no clean way to pass DA/DB.
Craig Topper7a2944e2019-02-04 04:15:10 +0000400def CMOVB_F : FPI<0xDA, MRM0r, (outs), (ins RSTi:$op),
401 "fcmovb\t{$op, %st|st, $op}">;
402def CMOVBE_F : FPI<0xDA, MRM2r, (outs), (ins RSTi:$op),
403 "fcmovbe\t{$op, %st|st, $op}">;
404def CMOVE_F : FPI<0xDA, MRM1r, (outs), (ins RSTi:$op),
405 "fcmove\t{$op, %st|st, $op}">;
406def CMOVP_F : FPI<0xDA, MRM3r, (outs), (ins RSTi:$op),
407 "fcmovu\t{$op, %st|st, $op}">;
408def CMOVNB_F : FPI<0xDB, MRM0r, (outs), (ins RSTi:$op),
409 "fcmovnb\t{$op, %st|st, $op}">;
410def CMOVNBE_F: FPI<0xDB, MRM2r, (outs), (ins RSTi:$op),
411 "fcmovnbe\t{$op, %st|st, $op}">;
412def CMOVNE_F : FPI<0xDB, MRM1r, (outs), (ins RSTi:$op),
413 "fcmovne\t{$op, %st|st, $op}">;
414def CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RSTi:$op),
415 "fcmovnu\t{$op, %st|st, $op}">;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000416} // Predicates = [HasCMov]
Simon Pilgrim65f805f2017-12-05 18:01:26 +0000417} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000418
419// Floating point loads & stores.
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000420let SchedRW = [WriteLoad] in {
Dan Gohman69cc2cb2008-12-03 18:15:48 +0000421let canFoldAsLoad = 1 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000422def LD_Fp32m : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000423 [(set RFP32:$dst, (loadf32 addr:$src))]>;
Dan Gohman8c5d6832010-02-27 23:47:46 +0000424let isReMaterializable = 1 in
Bill Wendlinga2401be2007-12-17 22:17:14 +0000425 def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000426 [(set RFP64:$dst, (loadf64 addr:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000427def LD_Fp80m : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000428 [(set RFP80:$dst, (loadf80 addr:$src))]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000429} // canFoldAsLoad
Dale Johannesene36c4002007-09-23 14:52:20 +0000430def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000431 [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
432def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
433 [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
434def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
435 [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000436def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000437 [(set RFP32:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000438def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000439 [(set RFP32:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000440def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000441 [(set RFP32:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000442def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000443 [(set RFP64:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000444def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000445 [(set RFP64:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000446def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000447 [(set RFP64:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000448def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000449 [(set RFP80:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000450def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000451 [(set RFP80:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000452def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000453 [(set RFP80:$dst, (X86fild addr:$src, i64))]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000454} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000455
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000456let SchedRW = [WriteStore] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000457def ST_Fp32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000458 [(store RFP32:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000459def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000460 [(truncstoref32 RFP64:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000461def ST_Fp64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000462 [(store RFP64:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000463def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000464 [(truncstoref32 RFP80:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000465def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000466 [(truncstoref64 RFP80:$src, addr:$op)]>;
467// FST does not support 80-bit memory target; FSTP must be used.
Evan Cheng6e595b92006-02-21 19:13:53 +0000468
Craig Topperc50d64b2014-11-26 00:46:26 +0000469let mayStore = 1, hasSideEffects = 0 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000470def ST_FpP32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
471def ST_FpP64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
472def ST_FpP64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
473def ST_FpP80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
474def ST_FpP80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000475} // mayStore
476
Dale Johannesena47f7d72007-08-07 20:29:26 +0000477def ST_FpP80m : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000478 [(store RFP80:$src, addr:$op)]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000479
Craig Topperc50d64b2014-11-26 00:46:26 +0000480let mayStore = 1, hasSideEffects = 0 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000481def IST_Fp16m32 : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
482def IST_Fp32m32 : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP, []>;
483def IST_Fp64m32 : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP, []>;
484def IST_Fp16m64 : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
485def IST_Fp32m64 : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP, []>;
486def IST_Fp64m64 : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP, []>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000487def IST_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
488def IST_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP, []>;
489def IST_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP, []>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000490} // mayStore
491} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000492
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000493let mayLoad = 1, SchedRW = [WriteLoad] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000494def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
495def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
496def LD_F80m : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
497def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
498def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
499def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
Chris Lattner317332f2008-01-10 07:59:24 +0000500}
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000501let mayStore = 1, SchedRW = [WriteStore] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000502def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
503def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
504def ST_FP32m : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst">;
505def ST_FP64m : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst">;
506def ST_FP80m : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst">;
507def IST_F16m : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst">;
508def IST_F32m : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst">;
509def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst">;
510def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst">;
511def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst">;
Chris Lattner317332f2008-01-10 07:59:24 +0000512}
Evan Cheng6e595b92006-02-21 19:13:53 +0000513
514// FISTTP requires SSE3 even though it's a FPStack op.
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000515let Predicates = [HasSSE3], SchedRW = [WriteStore] in {
Evan Cheng94b5a802007-07-19 01:14:50 +0000516def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000517 [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000518def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000519 [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000520def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000521 [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000522def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000523 [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000524def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000525 [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000526def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000527 [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000528def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000529 [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000530def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000531 [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000532def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000533 [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
534} // Predicates = [HasSSE3]
Evan Cheng6e595b92006-02-21 19:13:53 +0000535
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000536let mayStore = 1, SchedRW = [WriteStore] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000537def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst">;
538def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst">;
539def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll}\t$dst">;
Chris Lattner317332f2008-01-10 07:59:24 +0000540}
Evan Cheng6e595b92006-02-21 19:13:53 +0000541
542// FP Stack manipulation instructions.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000543let SchedRW = [WriteMove] in {
Craig Topper7a2944e2019-02-04 04:15:10 +0000544def LD_Frr : FPI<0xD9, MRM0r, (outs), (ins RSTi:$op), "fld\t$op">;
545def ST_Frr : FPI<0xDD, MRM2r, (outs), (ins RSTi:$op), "fst\t$op">;
546def ST_FPrr : FPI<0xDD, MRM3r, (outs), (ins RSTi:$op), "fstp\t$op">;
547def XCH_F : FPI<0xD9, MRM1r, (outs), (ins RSTi:$op), "fxch\t$op">;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000548}
Evan Cheng6e595b92006-02-21 19:13:53 +0000549
550// Floating point constant loads.
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000551let isReMaterializable = 1, SchedRW = [WriteZero] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000552def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000553 [(set RFP32:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000554def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000555 [(set RFP32:$dst, fpimm1)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000556def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000557 [(set RFP64:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000558def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000559 [(set RFP64:$dst, fpimm1)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000560def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000561 [(set RFP80:$dst, fpimm0)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000562def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000563 [(set RFP80:$dst, fpimm1)]>;
Dan Gohmane8c1e422007-06-26 00:48:07 +0000564}
Evan Cheng6e595b92006-02-21 19:13:53 +0000565
Clement Courbetb78ab502018-05-31 11:41:27 +0000566let SchedRW = [WriteFLD0] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000567def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
Clement Courbetb78ab502018-05-31 11:41:27 +0000568
569let SchedRW = [WriteFLD1] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000570def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
Evan Cheng6e595b92006-02-21 19:13:53 +0000571
Clement Courbet2e41c5a2018-05-31 14:22:01 +0000572let SchedRW = [WriteFLDC], Defs = [FPSW] in {
573def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
574def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
575def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
576def FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", []>;
577def FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", []>;
578} // SchedRW
579
Evan Cheng6e595b92006-02-21 19:13:53 +0000580// Floating point compares.
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000581let SchedRW = [WriteFCom] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000582def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000583 [(set FPSW, (trunc (X86cmp RFP32:$lhs, RFP32:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000584def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000585 [(set FPSW, (trunc (X86cmp RFP64:$lhs, RFP64:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000586def UCOM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000587 [(set FPSW, (trunc (X86cmp RFP80:$lhs, RFP80:$rhs)))]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000588} // SchedRW
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000589} // Defs = [FPSW]
590
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000591let SchedRW = [WriteFCom] in {
Chris Lattner83facb02010-03-19 00:01:11 +0000592// CC = ST(0) cmp ST(i)
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000593let Defs = [EFLAGS, FPSW] in {
Craig Topperc73095e2018-08-28 17:17:13 +0000594let Predicates = [FPStackf32, HasCMov] 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))]>;
Craig Topperc73095e2018-08-28 17:17:13 +0000597let Predicates = [FPStackf64, HasCMov] in
Dale Johannesene36c4002007-09-23 14:52:20 +0000598def UCOM_FpIr64: FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000599 [(set EFLAGS, (X86cmp RFP64:$lhs, RFP64:$rhs))]>;
Craig Topperc73095e2018-08-28 17:17:13 +0000600let Predicates = [HasCMov] in
Dale Johannesena47f7d72007-08-07 20:29:26 +0000601def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Chris Lattner83facb02010-03-19 00:01:11 +0000602 [(set EFLAGS, (X86cmp RFP80:$lhs, RFP80:$rhs))]>;
Evan Cheng8ee1ecf2007-09-25 19:08:02 +0000603}
604
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000605let Defs = [FPSW], Uses = [ST0] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000606def UCOM_Fr : FPI<0xDD, MRM4r, // FPSW = cmp ST(0) with ST(i)
Craig Topper7a2944e2019-02-04 04:15:10 +0000607 (outs), (ins RSTi:$reg), "fucom\t$reg">;
Craig Topper623b0d62014-01-01 14:22:37 +0000608def UCOM_FPr : FPI<0xDD, MRM5r, // FPSW = cmp ST(0) with ST(i), pop
Craig Topper7a2944e2019-02-04 04:15:10 +0000609 (outs), (ins RSTi:$reg), "fucomp\t$reg">;
Craig Topper56f0ed812014-02-19 08:25:02 +0000610def UCOM_FPPr : FPI<0xDA, MRM_E9, // cmp ST(0) with ST(1), pop, pop
Simon Pilgrim32d36812018-04-12 10:27:37 +0000611 (outs), (ins), "fucompp">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000612}
Evan Cheng6e595b92006-02-21 19:13:53 +0000613
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000614let Defs = [EFLAGS, FPSW], Uses = [ST0] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000615def UCOM_FIr : FPI<0xDB, MRM5r, // CC = cmp ST(0) with ST(i)
Craig Topper7a2944e2019-02-04 04:15:10 +0000616 (outs), (ins RSTi:$reg), "fucomi\t$reg">;
Craig Topper623b0d62014-01-01 14:22:37 +0000617def UCOM_FIPr : FPI<0xDF, MRM5r, // CC = cmp ST(0) with ST(i), pop
Craig Topper7a2944e2019-02-04 04:15:10 +0000618 (outs), (ins RSTi:$reg), "fucompi\t$reg">;
Evan Cheng3e18e502007-09-11 19:55:27 +0000619}
Evan Cheng6e595b92006-02-21 19:13:53 +0000620
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000621let Defs = [EFLAGS, FPSW] in {
Craig Topper7a2944e2019-02-04 04:15:10 +0000622def COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RSTi:$reg), "fcomi\t$reg">;
623def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RSTi:$reg), "fcompi\t$reg">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000624}
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000625} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000626
Evan Cheng6e595b92006-02-21 19:13:53 +0000627// Floating point flag ops.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000628let SchedRW = [WriteALU] in {
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000629let Defs = [AX], Uses = [FPSW] in
Craig Topper56f0ed812014-02-19 08:25:02 +0000630def FNSTSW16r : I<0xDF, MRM_E0, // AX = fp flags
Craig Topperefd67d42013-07-31 02:47:52 +0000631 (outs), (ins), "fnstsw\t{%ax|ax}",
Simon Pilgrim32d36812018-04-12 10:27:37 +0000632 [(set AX, (X86fp_stsw FPSW))]>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000633let Defs = [FPSW] in
Evan Cheng6e595b92006-02-21 19:13:53 +0000634def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
Andrew Trickedd006c2010-10-22 03:58:29 +0000635 (outs), (ins i16mem:$dst), "fnstcw\t$dst",
Simon Pilgrim32d36812018-04-12 10:27:37 +0000636 [(X86fp_cwd_get16 addr:$dst)]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000637} // SchedRW
Simon Pilgrim05710a82017-09-06 10:23:12 +0000638let Defs = [FPSW], mayLoad = 1 in
Evan Cheng6e595b92006-02-21 19:13:53 +0000639def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
Simon Pilgrim32d36812018-04-12 10:27:37 +0000640 (outs), (ins i16mem:$dst), "fldcw\t$dst", []>,
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000641 Sched<[WriteLoad]>;
Evan Chengd5847812006-02-21 20:00:20 +0000642
Chris Lattnerdec85b82010-10-05 05:32:15 +0000643// FPU control instructions
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000644let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim05710a82017-09-06 10:23:12 +0000645let Defs = [FPSW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000646def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
Craig Topper7a2944e2019-02-04 04:15:10 +0000647def FFREE : FPI<0xDD, MRM0r, (outs), (ins RSTi:$reg), "ffree\t$reg">;
648def FFREEP : FPI<0xDF, MRM0r, (outs), (ins RSTi:$reg), "ffreep\t$reg">;
Chris Ray535e7d12017-01-27 18:02:53 +0000649
Sean Callanan04d8cb72009-12-18 00:01:26 +0000650// Clear exceptions
Simon Pilgrim32d36812018-04-12 10:27:37 +0000651def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000652} // Defs = [FPSW]
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000653} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000654
Sanjay Patel05daae72018-03-19 14:26:50 +0000655// Operand-less floating-point instructions for the disassembler.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000656def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000657
Sanjay Patel05daae72018-03-19 14:26:50 +0000658let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim05710a82017-09-06 10:23:12 +0000659let Defs = [FPSW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000660def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
661def FXAM : I<0xD9, MRM_E5, (outs), (ins), "fxam", []>;
Simon Pilgrim32d36812018-04-12 10:27:37 +0000662def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
663def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
664def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
665def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
666def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
667def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
668def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
669def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
670def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
671def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
672def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
673def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
674def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
675def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000676} // Defs = [FPSW]
Sean Callanan04d8cb72009-12-18 00:01:26 +0000677
Craig Topper33dc01d2018-05-01 04:42:00 +0000678def FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000679 "fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, TB,
Craig Toppera1639502017-12-15 17:22:58 +0000680 Requires<[HasFXSR]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000681def FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000682 "fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
683 TB, Requires<[HasFXSR, In64BitMode]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000684def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000685 "fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
Craig Toppera1639502017-12-15 17:22:58 +0000686 TB, Requires<[HasFXSR]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000687def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000688 "fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
689 TB, Requires<[HasFXSR, In64BitMode]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000690} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000691
Evan Chengd5847812006-02-21 20:00:20 +0000692//===----------------------------------------------------------------------===//
693// Non-Instruction Patterns
694//===----------------------------------------------------------------------===//
695
Dale Johannesena47f7d72007-08-07 20:29:26 +0000696// Required for RET of f32 / f64 / f80 values.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000697def : Pat<(X86fld addr:$src, f32), (LD_Fp32m addr:$src)>;
698def : Pat<(X86fld addr:$src, f64), (LD_Fp64m addr:$src)>;
Dale Johannesenb1888e72007-08-05 18:49:15 +0000699def : Pat<(X86fld addr:$src, f80), (LD_Fp80m addr:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000700
Dale Johannesena47f7d72007-08-07 20:29:26 +0000701// Required for CALL which return f32 / f64 / f80 values.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000702def : Pat<(X86fst RFP32:$src, addr:$op, f32), (ST_Fp32m addr:$op, RFP32:$src)>;
Michael Liao5bf95782014-12-04 05:20:33 +0000703def : Pat<(X86fst RFP64:$src, addr:$op, f32), (ST_Fp64m32 addr:$op,
Sean Callanan04d8cb72009-12-18 00:01:26 +0000704 RFP64:$src)>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000705def : Pat<(X86fst RFP64:$src, addr:$op, f64), (ST_Fp64m addr:$op, RFP64:$src)>;
Michael Liao5bf95782014-12-04 05:20:33 +0000706def : Pat<(X86fst RFP80:$src, addr:$op, f32), (ST_Fp80m32 addr:$op,
Sean Callanan04d8cb72009-12-18 00:01:26 +0000707 RFP80:$src)>;
Michael Liao5bf95782014-12-04 05:20:33 +0000708def : Pat<(X86fst RFP80:$src, addr:$op, f64), (ST_Fp80m64 addr:$op,
Sean Callanan04d8cb72009-12-18 00:01:26 +0000709 RFP80:$src)>;
710def : Pat<(X86fst RFP80:$src, addr:$op, f80), (ST_FpP80m addr:$op,
711 RFP80:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000712
713// Floating point constant -0.0 and -1.0
Dale Johannesene36c4002007-09-23 14:52:20 +0000714def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
715def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
716def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
717def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000718def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
719def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
Evan Chengd5847812006-02-21 20:00:20 +0000720
721// Used to conv. i64 to f64 since there isn't a SSE version.
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000722def : Pat<(X86fildflag addr:$src, i64), (ILD_Fp64m64 addr:$src)>;
Dale Johannesena2b3c172007-07-03 00:53:03 +0000723
Chris Lattnerd587e582008-03-09 07:05:32 +0000724// FP extensions map onto simple pseudo-value conversions if they are to/from
725// the FP stack.
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000726def : Pat<(f64 (fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000727 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000728def : Pat<(f80 (fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000729 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000730def : Pat<(f80 (fpextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000731 Requires<[FPStackf64]>;
732
733// FP truncations map onto simple pseudo-value conversions if they are to/from
734// the FP stack. We have validated that only value-preserving truncations make
735// it through isel.
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000736def : Pat<(f32 (fpround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000737 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000738def : Pat<(f32 (fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000739 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000740def : Pat<(f64 (fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000741 Requires<[FPStackf64]>;