blob: 8a756bfc3b1767ce5476e6918a9a278624b57486 [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
Craig Topperd7303ec2019-02-12 06:14:16 +000019def SDTX86Fld : SDTypeProfile<1, 1, [SDTCisFP<0>,
20 SDTCisPtrTy<1>]>;
21def SDTX86Fst : SDTypeProfile<0, 2, [SDTCisFP<0>,
22 SDTCisPtrTy<1>]>;
23def SDTX86Fild : SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +000024def SDTX86Fnstsw : SDTypeProfile<1, 1, [SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000025
Anton Korobeynikov91460e42007-11-16 01:31:51 +000026def SDTX86CwdStore : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
27
Chris Lattner317332f2008-01-10 07:59:24 +000028def X86fld : SDNode<"X86ISD::FLD", SDTX86Fld,
Chris Lattnera5156c32010-09-22 01:28:21 +000029 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000030def X86fst : SDNode<"X86ISD::FST", SDTX86Fst,
Chris Lattner2a0a3b42010-12-23 18:28:41 +000031 [SDNPHasChain, SDNPInGlue, SDNPMayStore,
Chris Lattnera5156c32010-09-22 01:28:21 +000032 SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000033def X86fild : SDNode<"X86ISD::FILD", SDTX86Fild,
Chris Lattnera5156c32010-09-22 01:28:21 +000034 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattner317332f2008-01-10 07:59:24 +000035def X86fildflag : SDNode<"X86ISD::FILD_FLAG", SDTX86Fild,
Chris Lattner2a0a3b42010-12-23 18:28:41 +000036 [SDNPHasChain, SDNPOutGlue, SDNPMayLoad,
Chris Lattnera5156c32010-09-22 01:28:21 +000037 SDNPMemOperand]>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +000038def X86fp_stsw : SDNode<"X86ISD::FNSTSW16r", SDTX86Fnstsw>;
Craig Topper7670ede2019-02-12 06:14:18 +000039def X86fp_to_mem : SDNode<"X86ISD::FP_TO_INT_IN_MEM", SDTX86Fst,
40 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Anton Korobeynikov91460e42007-11-16 01:31:51 +000041def X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m", SDTX86CwdStore,
Chris Lattner78f518b2010-09-22 01:05:16 +000042 [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
43 SDNPMemOperand]>;
Evan Cheng9bf978d2006-03-18 01:23:20 +000044
Craig Topperd7303ec2019-02-12 06:14:16 +000045def X86fstf32 : PatFrag<(ops node:$val, node:$ptr),
46 (X86fst node:$val, node:$ptr), [{
47 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
48}]>;
49def X86fstf64 : PatFrag<(ops node:$val, node:$ptr),
50 (X86fst node:$val, node:$ptr), [{
51 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
52}]>;
53def X86fstf80 : PatFrag<(ops node:$val, node:$ptr),
54 (X86fst node:$val, node:$ptr), [{
55 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
56}]>;
57
58def X86fldf32 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
59 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
60}]>;
61def X86fldf64 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
62 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
63}]>;
64def X86fldf80 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
65 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
66}]>;
67
68def X86fild16 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
69 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
70}]>;
71def X86fild32 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
72 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
73}]>;
74def X86fild64 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
75 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
76}]>;
77
78def X86fildflag64 : PatFrag<(ops node:$ptr), (X86fildflag node:$ptr), [{
79 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
80}]>;
81
Craig Topper7670ede2019-02-12 06:14:18 +000082def X86fp_to_i16mem : PatFrag<(ops node:$val, node:$ptr),
83 (X86fp_to_mem node:$val, node:$ptr), [{
84 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
85}]>;
86def X86fp_to_i32mem : PatFrag<(ops node:$val, node:$ptr),
87 (X86fp_to_mem node:$val, node:$ptr), [{
88 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
89}]>;
90def X86fp_to_i64mem : PatFrag<(ops node:$val, node:$ptr),
91 (X86fp_to_mem node:$val, node:$ptr), [{
92 return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
93}]>;
94
Evan Cheng9bf978d2006-03-18 01:23:20 +000095//===----------------------------------------------------------------------===//
Evan Cheng4f674922006-03-17 19:55:52 +000096// FPStack pattern fragments
97//===----------------------------------------------------------------------===//
98
Daniel Sanders11300ce2017-10-13 21:28:03 +000099def fpimm0 : FPImmLeaf<fAny, [{
100 return Imm.isExactlyValue(+0.0);
Evan Cheng4f674922006-03-17 19:55:52 +0000101}]>;
102
Daniel Sanders11300ce2017-10-13 21:28:03 +0000103def fpimmneg0 : FPImmLeaf<fAny, [{
104 return Imm.isExactlyValue(-0.0);
Evan Cheng4f674922006-03-17 19:55:52 +0000105}]>;
106
Daniel Sanders11300ce2017-10-13 21:28:03 +0000107def fpimm1 : FPImmLeaf<fAny, [{
108 return Imm.isExactlyValue(+1.0);
Evan Cheng4f674922006-03-17 19:55:52 +0000109}]>;
110
Daniel Sanders11300ce2017-10-13 21:28:03 +0000111def fpimmneg1 : FPImmLeaf<fAny, [{
112 return Imm.isExactlyValue(-1.0);
Evan Cheng4f674922006-03-17 19:55:52 +0000113}]>;
114
Simon Pilgrim4fecbd82017-11-28 18:10:29 +0000115// Some 'special' instructions - expanded after instruction selection.
Craig Topper8eade092019-02-19 22:37:00 +0000116// Clobbers EFLAGS due to OR instruction used internally.
117// FIXME: Can we model this in SelectionDAG?
118let usesCustomInserter = 1, hasNoSchedulingInfo = 1, Defs = [EFLAGS] in {
Eric Christophera964f4d2010-11-30 21:57:32 +0000119 def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +0000120 [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000121 def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +0000122 [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000123 def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +0000124 [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000125 def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +0000126 [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000127 def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +0000128 [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000129 def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
Dale Johannesenc2a60892007-07-03 17:07:33 +0000130 [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000131 def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000132 [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000133 def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000134 [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
Eric Christophera964f4d2010-11-30 21:57:32 +0000135 def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000136 [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
Evan Chengd5847812006-02-21 20:00:20 +0000137}
138
Dale Johannesena47f7d72007-08-07 20:29:26 +0000139// All FP Stack operations are represented with four instructions here. The
140// first three instructions, generated by the instruction selector, use "RFP32"
141// "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
Michael Liao5bf95782014-12-04 05:20:33 +0000142// 64-bit or 80-bit floating point values. These sizes apply to the values,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000143// not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
144// copied to each other without losing information. These instructions are all
145// pseudo instructions and use the "_Fp" suffix.
146// In some cases there are additional variants with a mixture of different
147// register sizes.
Evan Cheng6e595b92006-02-21 19:13:53 +0000148// The second instruction is defined with FPI, which is the actual instruction
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000149// emitted by the assembler. These use "RST" registers, although frequently
Dale Johannesena47f7d72007-08-07 20:29:26 +0000150// the actual register(s) used are implicit. These are always 80 bits.
Michael Liao5bf95782014-12-04 05:20:33 +0000151// The FP stackifier pass converts one to the other after register allocation
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000152// occurs.
Evan Cheng6e595b92006-02-21 19:13:53 +0000153//
154// Note that the FpI instruction should have instruction selection info (e.g.
155// a pattern) and the FPI instruction should have emission info (e.g. opcode
156// encoding and asm printing info).
157
Bob Wilsona967c422010-08-26 18:08:11 +0000158// FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
Dale Johannesene36c4002007-09-23 14:52:20 +0000159// f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
160// f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
161// f80 instructions cannot use SSE and use neither of these.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000162class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
163 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
164class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
165 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000166
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000167// Factoring for arithmetic.
168multiclass FPBinary_rr<SDNode OpNode> {
169// Register op register -> register
170// These are separated out because they have no reversed form.
Dale Johannesene36c4002007-09-23 14:52:20 +0000171def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000172 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000173def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000174 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000175def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000176 [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000177}
178// The FopST0 series are not included here because of the irregularities
179// in where the 'r' goes in assembly output.
Dale Johannesenb1888e72007-08-05 18:49:15 +0000180// These instructions cannot address 80-bit memory.
Craig Topperc458c7c62015-12-01 06:13:16 +0000181multiclass FPBinary<SDNode OpNode, Format fp, string asmstring,
182 bit Forward = 1> {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000183// ST(0) = ST(0) + [mem]
Michael Liao5bf95782014-12-04 05:20:33 +0000184def _Fp32m : FpIf32<(outs RFP32:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000185 (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000186 [!if(Forward,
187 (set RFP32:$dst,
188 (OpNode RFP32:$src1, (loadf32 addr:$src2))),
189 (set RFP32:$dst,
190 (OpNode (loadf32 addr:$src2), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000191def _Fp64m : FpIf64<(outs RFP64:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000192 (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000193 [!if(Forward,
194 (set RFP64:$dst,
195 (OpNode RFP64:$src1, (loadf64 addr:$src2))),
196 (set RFP64:$dst,
197 (OpNode (loadf64 addr:$src2), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000198def _Fp64m32: FpIf64<(outs RFP64:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000199 (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000200 [!if(Forward,
201 (set RFP64:$dst,
202 (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2)))),
203 (set RFP64:$dst,
204 (OpNode (f64 (extloadf32 addr:$src2)), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000205def _Fp80m32: FpI_<(outs RFP80:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000206 (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000207 [!if(Forward,
208 (set RFP80:$dst,
209 (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2)))),
210 (set RFP80:$dst,
211 (OpNode (f80 (extloadf32 addr:$src2)), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000212def _Fp80m64: FpI_<(outs RFP80:$dst),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000213 (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000214 [!if(Forward,
215 (set RFP80:$dst,
216 (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2)))),
217 (set RFP80:$dst,
218 (OpNode (f80 (extloadf64 addr:$src2)), RFP80:$src1)))]>;
Craig Topper2b34fdc2019-02-21 22:00:15 +0000219let mayLoad = 1 in
Michael Liao5bf95782014-12-04 05:20:33 +0000220def _F32m : FPI<0xD8, fp, (outs), (ins f32mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000221 !strconcat("f", asmstring, "{s}\t$src")>;
Craig Topper2b34fdc2019-02-21 22:00:15 +0000222let mayLoad = 1 in
Michael Liao5bf95782014-12-04 05:20:33 +0000223def _F64m : FPI<0xDC, fp, (outs), (ins f64mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000224 !strconcat("f", asmstring, "{l}\t$src")>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000225// ST(0) = ST(0) + [memint]
Michael Liao5bf95782014-12-04 05:20:33 +0000226def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000227 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000228 [!if(Forward,
229 (set RFP32:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000230 (OpNode RFP32:$src1, (X86fild16 addr:$src2))),
Craig Topperc458c7c62015-12-01 06:13:16 +0000231 (set RFP32:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000232 (OpNode (X86fild16 addr:$src2), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000233def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000234 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000235 [!if(Forward,
236 (set RFP32:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000237 (OpNode RFP32:$src1, (X86fild32 addr:$src2))),
Craig Topperc458c7c62015-12-01 06:13:16 +0000238 (set RFP32:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000239 (OpNode (X86fild32 addr:$src2), RFP32:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000240def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000241 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000242 [!if(Forward,
243 (set RFP64:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000244 (OpNode RFP64:$src1, (X86fild16 addr:$src2))),
Craig Topperc458c7c62015-12-01 06:13:16 +0000245 (set RFP64:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000246 (OpNode (X86fild16 addr:$src2), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000247def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
Sean Callanan04d8cb72009-12-18 00:01:26 +0000248 OneArgFPRW,
Craig Topperc458c7c62015-12-01 06:13:16 +0000249 [!if(Forward,
250 (set RFP64:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000251 (OpNode RFP64:$src1, (X86fild32 addr:$src2))),
Craig Topperc458c7c62015-12-01 06:13:16 +0000252 (set RFP64:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000253 (OpNode (X86fild32 addr:$src2), RFP64:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000254def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
Craig Topperc458c7c62015-12-01 06:13:16 +0000255 OneArgFPRW,
256 [!if(Forward,
257 (set RFP80:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000258 (OpNode RFP80:$src1, (X86fild16 addr:$src2))),
Craig Topperc458c7c62015-12-01 06:13:16 +0000259 (set RFP80:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000260 (OpNode (X86fild16 addr:$src2), RFP80:$src1)))]>;
Michael Liao5bf95782014-12-04 05:20:33 +0000261def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
Craig Topperc458c7c62015-12-01 06:13:16 +0000262 OneArgFPRW,
263 [!if(Forward,
264 (set RFP80:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000265 (OpNode RFP80:$src1, (X86fild32 addr:$src2))),
Craig Topperc458c7c62015-12-01 06:13:16 +0000266 (set RFP80:$dst,
Craig Topperd7303ec2019-02-12 06:14:16 +0000267 (OpNode (X86fild32 addr:$src2), RFP80:$src1)))]>;
Craig Topper2b34fdc2019-02-21 22:00:15 +0000268let mayLoad = 1 in
Michael Liao5bf95782014-12-04 05:20:33 +0000269def _FI16m : FPI<0xDE, fp, (outs), (ins i16mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000270 !strconcat("fi", asmstring, "{s}\t$src")>;
Craig Topper2b34fdc2019-02-21 22:00:15 +0000271let mayLoad = 1 in
Michael Liao5bf95782014-12-04 05:20:33 +0000272def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
Craig Topperc458c7c62015-12-01 06:13:16 +0000273 !strconcat("fi", asmstring, "{l}\t$src")>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000274}
275
Craig Topperc782f182019-02-08 00:44:39 +0000276let Defs = [FPSW], Uses = [FPCW] in {
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000277// FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
278// resources.
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000279let hasNoSchedulingInfo = 1 in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000280defm ADD : FPBinary_rr<fadd>;
281defm SUB : FPBinary_rr<fsub>;
282defm MUL : FPBinary_rr<fmul>;
283defm DIV : FPBinary_rr<fdiv>;
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000284}
285
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000286// Sets the scheduling resources for the actual NAME#_F<size>m defintions.
287let SchedRW = [WriteFAddLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000288defm ADD : FPBinary<fadd, MRM0m, "add">;
289defm SUB : FPBinary<fsub, MRM4m, "sub">;
Craig Topperc458c7c62015-12-01 06:13:16 +0000290defm SUBR: FPBinary<fsub ,MRM5m, "subr", 0>;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000291}
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000292
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000293let SchedRW = [WriteFMulLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000294defm MUL : FPBinary<fmul, MRM1m, "mul">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000295}
Simon Pilgrimbd5f7452017-12-07 14:07:18 +0000296
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000297let SchedRW = [WriteFDivLd] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000298defm DIV : FPBinary<fdiv, MRM6m, "div">;
Craig Topperc458c7c62015-12-01 06:13:16 +0000299defm DIVR: FPBinary<fdiv, MRM7m, "divr", 0>;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000300}
Simon Pilgrim17e290f2017-08-06 13:21:09 +0000301} // Defs = [FPSW]
Evan Cheng6e595b92006-02-21 19:13:53 +0000302
Craig Topper623b0d62014-01-01 14:22:37 +0000303class FPST0rInst<Format fp, string asm>
Craig Topper7a2944e2019-02-04 04:15:10 +0000304 : FPI<0xD8, fp, (outs), (ins RSTi:$op), asm>;
Craig Topper623b0d62014-01-01 14:22:37 +0000305class FPrST0Inst<Format fp, string asm>
Craig Topper7a2944e2019-02-04 04:15:10 +0000306 : FPI<0xDC, fp, (outs), (ins RSTi:$op), asm>;
Craig Topper623b0d62014-01-01 14:22:37 +0000307class FPrST0PInst<Format fp, string asm>
Craig Topper7a2944e2019-02-04 04:15:10 +0000308 : FPI<0xDE, fp, (outs), (ins RSTi:$op), asm>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000309
Evan Cheng6e595b92006-02-21 19:13:53 +0000310// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
311// of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
312// we have to put some 'r's in and take them out of weird places.
Craig Topperc782f182019-02-08 00:44:39 +0000313let SchedRW = [WriteFAdd], Defs = [FPSW], Uses = [FPCW] in {
Craig Topperbf7593e2019-02-04 17:28:18 +0000314def ADD_FST0r : FPST0rInst <MRM0r, "fadd\t{$op, %st|st, $op}">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000315def ADD_FrST0 : FPrST0Inst <MRM0r, "fadd\t{%st, $op|$op, st}">;
Craig Topperbf7593e2019-02-04 17:28:18 +0000316def ADD_FPrST0 : FPrST0PInst<MRM0r, "faddp\t{%st, $op|$op, st}">;
317def SUBR_FST0r : FPST0rInst <MRM5r, "fsubr\t{$op, %st|st, $op}">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000318def SUB_FrST0 : FPrST0Inst <MRM5r, "fsub{r}\t{%st, $op|$op, st}">;
Craig Topperbf7593e2019-02-04 17:28:18 +0000319def SUB_FPrST0 : FPrST0PInst<MRM5r, "fsub{r}p\t{%st, $op|$op, st}">;
320def SUB_FST0r : FPST0rInst <MRM4r, "fsub\t{$op, %st|st, $op}">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000321def SUBR_FrST0 : FPrST0Inst <MRM4r, "fsub{|r}\t{%st, $op|$op, st}">;
Craig Topperbf7593e2019-02-04 17:28:18 +0000322def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t{%st, $op|$op, st}">;
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000323} // SchedRW
Craig Topperc782f182019-02-08 00:44:39 +0000324let SchedRW = [WriteFCom], Defs = [FPSW], Uses = [FPCW] in {
Simon Pilgrim6415f562017-12-08 20:10:31 +0000325def COM_FST0r : FPST0rInst <MRM2r, "fcom\t$op">;
326def COMP_FST0r : FPST0rInst <MRM3r, "fcomp\t$op">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000327} // SchedRW
Craig Topperc782f182019-02-08 00:44:39 +0000328let SchedRW = [WriteFMul], Defs = [FPSW], Uses = [FPCW] in {
Craig Topperbf7593e2019-02-04 17:28:18 +0000329def MUL_FST0r : FPST0rInst <MRM1r, "fmul\t{$op, %st|st, $op}">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000330def MUL_FrST0 : FPrST0Inst <MRM1r, "fmul\t{%st, $op|$op, st}">;
Craig Topperbf7593e2019-02-04 17:28:18 +0000331def MUL_FPrST0 : FPrST0PInst<MRM1r, "fmulp\t{%st, $op|$op, st}">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000332} // SchedRW
Craig Topperc782f182019-02-08 00:44:39 +0000333let SchedRW = [WriteFDiv], Defs = [FPSW], Uses = [FPCW] in {
Craig Topperbf7593e2019-02-04 17:28:18 +0000334def DIVR_FST0r : FPST0rInst <MRM7r, "fdivr\t{$op, %st|st, $op}">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000335def DIV_FrST0 : FPrST0Inst <MRM7r, "fdiv{r}\t{%st, $op|$op, st}">;
Craig Topperbf7593e2019-02-04 17:28:18 +0000336def DIV_FPrST0 : FPrST0PInst<MRM7r, "fdiv{r}p\t{%st, $op|$op, st}">;
337def DIV_FST0r : FPST0rInst <MRM6r, "fdiv\t{$op, %st|st, $op}">;
Craig Topper7a2944e2019-02-04 04:15:10 +0000338def DIVR_FrST0 : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st, $op|$op, st}">;
Craig Topperbf7593e2019-02-04 17:28:18 +0000339def DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t{%st, $op|$op, st}">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000340} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000341
Evan Cheng6e595b92006-02-21 19:13:53 +0000342// Unary operations.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000343multiclass FPUnary<SDNode OpNode, Format fp, string asmstring> {
Dale Johannesene36c4002007-09-23 14:52:20 +0000344def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000345 [(set RFP32:$dst, (OpNode RFP32:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000346def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000347 [(set RFP64:$dst, (OpNode RFP64:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000348def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000349 [(set RFP80:$dst, (OpNode RFP80:$src))]>;
350def _F : FPI<0xD9, fp, (outs), (ins), asmstring>;
Evan Cheng6e595b92006-02-21 19:13:53 +0000351}
352
Craig Topperc782f182019-02-08 00:44:39 +0000353let Defs = [FPSW], Uses = [FPCW] in {
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000354
Simon Pilgrimd14d2e72018-04-20 21:16:05 +0000355let SchedRW = [WriteFSign] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000356defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
357defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
Quentin Colombetb5e41ea2014-03-12 17:33:42 +0000358}
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000359
Simon Pilgrimf3ae50f2018-05-07 11:50:44 +0000360let SchedRW = [WriteFSqrt80] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000361defm SQRT: FPUnary<fsqrt,MRM_FA, "fsqrt">;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000362
363let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000364defm SIN : FPUnary<fsin, MRM_FE, "fsin">;
365defm COS : FPUnary<fcos, MRM_FF, "fcos">;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000366}
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000367
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000368let SchedRW = [WriteFCom] in {
Craig Topperc50d64b2014-11-26 00:46:26 +0000369let hasSideEffects = 0 in {
Chris Lattner92831732008-01-11 07:18:17 +0000370def TST_Fp32 : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
371def TST_Fp64 : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
372def TST_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
Simon Pilgrim0747a7e2017-11-28 15:03:42 +0000373} // hasSideEffects
374
Simon Pilgrim32d36812018-04-12 10:27:37 +0000375def TST_F : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000376} // SchedRW
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000377} // Defs = [FPSW]
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000378
Sean Callanane739ac82009-09-16 01:13:52 +0000379// Versions of FP instructions that take a single memory operand. Added for the
380// disassembler; remove as they are included with patterns elsewhere.
Craig Topperc782f182019-02-08 00:44:39 +0000381let SchedRW = [WriteFComLd], Defs = [FPSW], Uses = [FPCW] in {
Kevin Enderby6f2f8d02010-05-03 21:31:40 +0000382def FCOM32m : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
383def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000384
Simon Pilgrim6415f562017-12-08 20:10:31 +0000385def FCOM64m : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
386def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
387
388def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
389def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
Sean Callanane739ac82009-09-16 01:13:52 +0000390
391def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
392def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000393} // SchedRW
Sean Callanane739ac82009-09-16 01:13:52 +0000394
Simon Pilgrim6415f562017-12-08 20:10:31 +0000395let SchedRW = [WriteMicrocoded] in {
396def FLDENVm : FPI<0xD9, MRM4m, (outs), (ins f32mem:$src), "fldenv\t$src">;
397def FSTENVm : FPI<0xD9, MRM6m, (outs), (ins f32mem:$dst), "fnstenv\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000398
Craig Topper955308f2016-03-13 02:56:31 +0000399def FRSTORm : FPI<0xDD, MRM4m, (outs), (ins f32mem:$dst), "frstor\t$dst">;
400def FSAVEm : FPI<0xDD, MRM6m, (outs), (ins f32mem:$dst), "fnsave\t$dst">;
401def FNSTSWm : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
Sean Callanane739ac82009-09-16 01:13:52 +0000402
Marina Yatsinabce1ab62015-08-20 11:51:24 +0000403def FBLDm : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
Craig Topper955308f2016-03-13 02:56:31 +0000404def FBSTPm : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
Simon Pilgrim6415f562017-12-08 20:10:31 +0000405} // SchedRW
Sean Callanane739ac82009-09-16 01:13:52 +0000406
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000407// Floating point cmovs.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000408class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
409 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMov]>;
410class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
411 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMov]>;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000412
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000413multiclass FPCMov<PatLeaf cc> {
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000414 def _Fp32 : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000415 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000416 [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000417 cc, EFLAGS))]>;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000418 def _Fp64 : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000419 CondMovFP,
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000420 [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000421 cc, EFLAGS))]>;
Evan Cheng5fb5a1f2007-09-29 00:00:36 +0000422 def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
423 CondMovFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000424 [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
Simon Pilgrim32d36812018-04-12 10:27:37 +0000425 cc, EFLAGS))]>,
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000426 Requires<[HasCMov]>;
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000427}
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000428
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000429let Defs = [FPSW] in {
Simon Pilgrim6e160c12018-05-12 18:07:07 +0000430let SchedRW = [WriteFCMOV] in {
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000431let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000432defm CMOVB : FPCMov<X86_COND_B>;
433defm CMOVBE : FPCMov<X86_COND_BE>;
434defm CMOVE : FPCMov<X86_COND_E>;
435defm CMOVP : FPCMov<X86_COND_P>;
436defm CMOVNB : FPCMov<X86_COND_AE>;
437defm CMOVNBE: FPCMov<X86_COND_A>;
438defm CMOVNE : FPCMov<X86_COND_NE>;
439defm CMOVNP : FPCMov<X86_COND_NP>;
Eric Christopher6bdbdb52010-06-18 23:56:07 +0000440} // Uses = [EFLAGS], Constraints = "$src1 = $dst"
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000441
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000442let Predicates = [HasCMov] in {
Dale Johannesen3d7008c2007-07-04 21:07:47 +0000443// These are not factored because there's no clean way to pass DA/DB.
Craig Topper7a2944e2019-02-04 04:15:10 +0000444def CMOVB_F : FPI<0xDA, MRM0r, (outs), (ins RSTi:$op),
445 "fcmovb\t{$op, %st|st, $op}">;
446def CMOVBE_F : FPI<0xDA, MRM2r, (outs), (ins RSTi:$op),
447 "fcmovbe\t{$op, %st|st, $op}">;
448def CMOVE_F : FPI<0xDA, MRM1r, (outs), (ins RSTi:$op),
449 "fcmove\t{$op, %st|st, $op}">;
450def CMOVP_F : FPI<0xDA, MRM3r, (outs), (ins RSTi:$op),
451 "fcmovu\t{$op, %st|st, $op}">;
452def CMOVNB_F : FPI<0xDB, MRM0r, (outs), (ins RSTi:$op),
453 "fcmovnb\t{$op, %st|st, $op}">;
454def CMOVNBE_F: FPI<0xDB, MRM2r, (outs), (ins RSTi:$op),
455 "fcmovnbe\t{$op, %st|st, $op}">;
456def CMOVNE_F : FPI<0xDB, MRM1r, (outs), (ins RSTi:$op),
457 "fcmovne\t{$op, %st|st, $op}">;
458def CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RSTi:$op),
459 "fcmovnu\t{$op, %st|st, $op}">;
Chris Lattnera30d4ce2010-03-14 18:31:44 +0000460} // Predicates = [HasCMov]
Simon Pilgrim65f805f2017-12-05 18:01:26 +0000461} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000462
463// Floating point loads & stores.
Craig Topperfcb63c42019-02-08 20:50:09 +0000464let SchedRW = [WriteLoad], Uses = [FPCW] in {
Dan Gohman69cc2cb2008-12-03 18:15:48 +0000465let canFoldAsLoad = 1 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000466def LD_Fp32m : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000467 [(set RFP32:$dst, (loadf32 addr:$src))]>;
Craig Topper41a17922019-02-08 17:07:54 +0000468def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000469 [(set RFP64:$dst, (loadf64 addr:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000470def LD_Fp80m : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000471 [(set RFP80:$dst, (loadf80 addr:$src))]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000472} // canFoldAsLoad
Dale Johannesene36c4002007-09-23 14:52:20 +0000473def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesena47f7d72007-08-07 20:29:26 +0000474 [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
475def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
476 [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
477def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
478 [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000479def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000480 [(set RFP32:$dst, (X86fild16 addr:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000481def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000482 [(set RFP32:$dst, (X86fild32 addr:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000483def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000484 [(set RFP32:$dst, (X86fild64 addr:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000485def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000486 [(set RFP64:$dst, (X86fild16 addr:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000487def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000488 [(set RFP64:$dst, (X86fild32 addr:$src))]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000489def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000490 [(set RFP64:$dst, (X86fild64 addr:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000491def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000492 [(set RFP80:$dst, (X86fild16 addr:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000493def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000494 [(set RFP80:$dst, (X86fild32 addr:$src))]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000495def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
Craig Topperd7303ec2019-02-12 06:14:16 +0000496 [(set RFP80:$dst, (X86fild64 addr:$src))]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000497} // SchedRW
Evan Cheng6e595b92006-02-21 19:13:53 +0000498
Craig Topperc782f182019-02-08 00:44:39 +0000499let SchedRW = [WriteStore], Uses = [FPCW] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000500def ST_Fp32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000501 [(store RFP32:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000502def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000503 [(truncstoref32 RFP64:$src, addr:$op)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000504def ST_Fp64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
Dale Johannesenc2a60892007-07-03 17:07:33 +0000505 [(store RFP64:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000506def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000507 [(truncstoref32 RFP80:$src, addr:$op)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000508def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000509 [(truncstoref64 RFP80:$src, addr:$op)]>;
510// FST does not support 80-bit memory target; FSTP must be used.
Evan Cheng6e595b92006-02-21 19:13:53 +0000511
Craig Topperc50d64b2014-11-26 00:46:26 +0000512let mayStore = 1, hasSideEffects = 0 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000513def ST_FpP32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
514def ST_FpP64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
515def ST_FpP64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
516def ST_FpP80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
517def ST_FpP80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000518} // mayStore
519
Dale Johannesena47f7d72007-08-07 20:29:26 +0000520def ST_FpP80m : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000521 [(store RFP80:$src, addr:$op)]>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000522
Craig Topperc50d64b2014-11-26 00:46:26 +0000523let mayStore = 1, hasSideEffects = 0 in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000524def IST_Fp16m32 : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
525def IST_Fp32m32 : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP, []>;
526def IST_Fp64m32 : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP, []>;
527def IST_Fp16m64 : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
528def IST_Fp32m64 : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP, []>;
529def IST_Fp64m64 : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP, []>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000530def IST_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
531def IST_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP, []>;
532def IST_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP, []>;
Simon Pilgrimf621dcf2017-12-08 20:31:48 +0000533} // mayStore
Craig Topperc782f182019-02-08 00:44:39 +0000534} // SchedRW, Uses = [FPCW]
Evan Cheng6e595b92006-02-21 19:13:53 +0000535
Craig Topperfcb63c42019-02-08 20:50:09 +0000536let mayLoad = 1, SchedRW = [WriteLoad], Uses = [FPCW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000537def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
538def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
539def LD_F80m : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
540def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
541def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
542def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
Chris Lattner317332f2008-01-10 07:59:24 +0000543}
Craig Topperc782f182019-02-08 00:44:39 +0000544let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000545def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
546def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
547def ST_FP32m : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst">;
548def ST_FP64m : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst">;
549def ST_FP80m : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst">;
550def IST_F16m : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst">;
551def IST_F32m : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst">;
552def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst">;
553def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst">;
554def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst">;
Chris Lattner317332f2008-01-10 07:59:24 +0000555}
Evan Cheng6e595b92006-02-21 19:13:53 +0000556
557// FISTTP requires SSE3 even though it's a FPStack op.
Craig Topperc782f182019-02-08 00:44:39 +0000558let Predicates = [HasSSE3], SchedRW = [WriteStore], Uses = [FPCW] in {
Evan Cheng94b5a802007-07-19 01:14:50 +0000559def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000560 [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000561def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000562 [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000563def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000564 [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000565def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000566 [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000567def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000568 [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
Evan Cheng94b5a802007-07-19 01:14:50 +0000569def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000570 [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000571def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000572 [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000573def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000574 [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
Dale Johannesen57c6ac5f2007-08-07 01:17:37 +0000575def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
Craig Toppereb8f9e92012-01-10 06:30:56 +0000576 [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
577} // Predicates = [HasSSE3]
Evan Cheng6e595b92006-02-21 19:13:53 +0000578
Craig Topperc782f182019-02-08 00:44:39 +0000579let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000580def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst">;
581def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst">;
582def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll}\t$dst">;
Chris Lattner317332f2008-01-10 07:59:24 +0000583}
Evan Cheng6e595b92006-02-21 19:13:53 +0000584
585// FP Stack manipulation instructions.
Craig Topperfcb63c42019-02-08 20:50:09 +0000586let SchedRW = [WriteMove], Uses = [FPCW] in {
Craig Topper7a2944e2019-02-04 04:15:10 +0000587def LD_Frr : FPI<0xD9, MRM0r, (outs), (ins RSTi:$op), "fld\t$op">;
588def ST_Frr : FPI<0xDD, MRM2r, (outs), (ins RSTi:$op), "fst\t$op">;
589def ST_FPrr : FPI<0xDD, MRM3r, (outs), (ins RSTi:$op), "fstp\t$op">;
590def XCH_F : FPI<0xD9, MRM1r, (outs), (ins RSTi:$op), "fxch\t$op">;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000591}
Evan Cheng6e595b92006-02-21 19:13:53 +0000592
593// Floating point constant loads.
Craig Topperfcb63c42019-02-08 20:50:09 +0000594let SchedRW = [WriteZero], Uses = [FPCW] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000595def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000596 [(set RFP32:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000597def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000598 [(set RFP32:$dst, fpimm1)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000599def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000600 [(set RFP64:$dst, fpimm0)]>;
Dale Johannesene36c4002007-09-23 14:52:20 +0000601def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesena2b3c172007-07-03 00:53:03 +0000602 [(set RFP64:$dst, fpimm1)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000603def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000604 [(set RFP80:$dst, fpimm0)]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000605def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesenb1888e72007-08-05 18:49:15 +0000606 [(set RFP80:$dst, fpimm1)]>;
Dan Gohmane8c1e422007-06-26 00:48:07 +0000607}
Evan Cheng6e595b92006-02-21 19:13:53 +0000608
Craig Topperfcb63c42019-02-08 20:50:09 +0000609let SchedRW = [WriteFLD0], Uses = [FPCW] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000610def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
Clement Courbetb78ab502018-05-31 11:41:27 +0000611
Craig Topperfcb63c42019-02-08 20:50:09 +0000612let SchedRW = [WriteFLD1], Uses = [FPCW] in
Simon Pilgrim32d36812018-04-12 10:27:37 +0000613def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
Evan Cheng6e595b92006-02-21 19:13:53 +0000614
Craig Topperfcb63c42019-02-08 20:50:09 +0000615let SchedRW = [WriteFLDC], Uses = [FPCW] in {
Clement Courbet2e41c5a2018-05-31 14:22:01 +0000616def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
617def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
618def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
619def FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", []>;
620def FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", []>;
621} // SchedRW
622
Evan Cheng6e595b92006-02-21 19:13:53 +0000623// Floating point compares.
Craig Topperc782f182019-02-08 00:44:39 +0000624let SchedRW = [WriteFCom], Uses = [FPCW] in {
Dale Johannesene36c4002007-09-23 14:52:20 +0000625def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000626 [(set FPSW, (trunc (X86cmp RFP32:$lhs, RFP32:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000627def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000628 [(set FPSW, (trunc (X86cmp RFP64:$lhs, RFP64:$rhs)))]>;
Chris Lattner92831732008-01-11 07:18:17 +0000629def UCOM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000630 [(set FPSW, (trunc (X86cmp RFP80:$lhs, RFP80:$rhs)))]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000631} // SchedRW
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000632} // Defs = [FPSW]
633
Simon Pilgrim86e3c2692018-04-17 07:22:44 +0000634let SchedRW = [WriteFCom] in {
Chris Lattner83facb02010-03-19 00:01:11 +0000635// CC = ST(0) cmp ST(i)
Craig Topperc782f182019-02-08 00:44:39 +0000636let Defs = [EFLAGS, FPSW], Uses = [FPCW] in {
637def UCOM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
638 [(set EFLAGS, (X86cmp RFP32:$lhs, RFP32:$rhs))]>,
639 Requires<[FPStackf32, HasCMov]>;
640def UCOM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
641 [(set EFLAGS, (X86cmp RFP64:$lhs, RFP64:$rhs))]>,
642 Requires<[FPStackf64, HasCMov]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000643def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Craig Topperc782f182019-02-08 00:44:39 +0000644 [(set EFLAGS, (X86cmp RFP80:$lhs, RFP80:$rhs))]>,
645 Requires<[HasCMov]>;
Evan Cheng8ee1ecf2007-09-25 19:08:02 +0000646}
647
Craig Topperc782f182019-02-08 00:44:39 +0000648let Defs = [FPSW], Uses = [ST0, FPCW] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000649def UCOM_Fr : FPI<0xDD, MRM4r, // FPSW = cmp ST(0) with ST(i)
Craig Topper7a2944e2019-02-04 04:15:10 +0000650 (outs), (ins RSTi:$reg), "fucom\t$reg">;
Craig Topper623b0d62014-01-01 14:22:37 +0000651def UCOM_FPr : FPI<0xDD, MRM5r, // FPSW = cmp ST(0) with ST(i), pop
Craig Topper7a2944e2019-02-04 04:15:10 +0000652 (outs), (ins RSTi:$reg), "fucomp\t$reg">;
Craig Topper56f0ed812014-02-19 08:25:02 +0000653def UCOM_FPPr : FPI<0xDA, MRM_E9, // cmp ST(0) with ST(1), pop, pop
Simon Pilgrim32d36812018-04-12 10:27:37 +0000654 (outs), (ins), "fucompp">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000655}
Evan Cheng6e595b92006-02-21 19:13:53 +0000656
Craig Topperc782f182019-02-08 00:44:39 +0000657let Defs = [EFLAGS, FPSW], Uses = [ST0, FPCW] in {
Craig Topper623b0d62014-01-01 14:22:37 +0000658def UCOM_FIr : FPI<0xDB, MRM5r, // CC = cmp ST(0) with ST(i)
Craig Topperbf7593e2019-02-04 17:28:18 +0000659 (outs), (ins RSTi:$reg), "fucomi\t{$reg, %st|st, $reg}">;
Craig Topper623b0d62014-01-01 14:22:37 +0000660def UCOM_FIPr : FPI<0xDF, MRM5r, // CC = cmp ST(0) with ST(i), pop
Craig Topperbf7593e2019-02-04 17:28:18 +0000661 (outs), (ins RSTi:$reg), "fucompi\t{$reg, %st|st, $reg}">;
Evan Cheng6e595b92006-02-21 19:13:53 +0000662
Craig Topperbf7593e2019-02-04 17:28:18 +0000663def COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RSTi:$reg),
664 "fcomi\t{$reg, %st|st, $reg}">;
665def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RSTi:$reg),
666 "fcompi\t{$reg, %st|st, $reg}">;
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000667}
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000668} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000669
Evan Cheng6e595b92006-02-21 19:13:53 +0000670// Floating point flag ops.
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000671let SchedRW = [WriteALU] in {
Benjamin Kramer913da4b2012-04-27 12:07:43 +0000672let Defs = [AX], Uses = [FPSW] in
Craig Topper56f0ed812014-02-19 08:25:02 +0000673def FNSTSW16r : I<0xDF, MRM_E0, // AX = fp flags
Craig Topperefd67d42013-07-31 02:47:52 +0000674 (outs), (ins), "fnstsw\t{%ax|ax}",
Simon Pilgrim32d36812018-04-12 10:27:37 +0000675 [(set AX, (X86fp_stsw FPSW))]>;
Craig Topperc782f182019-02-08 00:44:39 +0000676let Defs = [FPSW], Uses = [FPCW] in
Evan Cheng6e595b92006-02-21 19:13:53 +0000677def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
Andrew Trickedd006c2010-10-22 03:58:29 +0000678 (outs), (ins i16mem:$dst), "fnstcw\t$dst",
Simon Pilgrim32d36812018-04-12 10:27:37 +0000679 [(X86fp_cwd_get16 addr:$dst)]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000680} // SchedRW
Craig Topperc782f182019-02-08 00:44:39 +0000681let Defs = [FPSW,FPCW], mayLoad = 1 in
Evan Cheng6e595b92006-02-21 19:13:53 +0000682def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
Simon Pilgrim32d36812018-04-12 10:27:37 +0000683 (outs), (ins i16mem:$dst), "fldcw\t$dst", []>,
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000684 Sched<[WriteLoad]>;
Evan Chengd5847812006-02-21 20:00:20 +0000685
Chris Lattnerdec85b82010-10-05 05:32:15 +0000686// FPU control instructions
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000687let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim05710a82017-09-06 10:23:12 +0000688let Defs = [FPSW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000689def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
Craig Topper7a2944e2019-02-04 04:15:10 +0000690def FFREE : FPI<0xDD, MRM0r, (outs), (ins RSTi:$reg), "ffree\t$reg">;
691def FFREEP : FPI<0xDF, MRM0r, (outs), (ins RSTi:$reg), "ffreep\t$reg">;
Chris Ray535e7d12017-01-27 18:02:53 +0000692
Sean Callanan04d8cb72009-12-18 00:01:26 +0000693// Clear exceptions
Simon Pilgrim32d36812018-04-12 10:27:37 +0000694def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000695} // Defs = [FPSW]
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000696} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000697
Sanjay Patel05daae72018-03-19 14:26:50 +0000698// Operand-less floating-point instructions for the disassembler.
Simon Pilgrim32d36812018-04-12 10:27:37 +0000699def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000700
Sanjay Patel05daae72018-03-19 14:26:50 +0000701let SchedRW = [WriteMicrocoded] in {
Simon Pilgrim05710a82017-09-06 10:23:12 +0000702let Defs = [FPSW] in {
Simon Pilgrim32d36812018-04-12 10:27:37 +0000703def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
704def FXAM : I<0xD9, MRM_E5, (outs), (ins), "fxam", []>;
Simon Pilgrim32d36812018-04-12 10:27:37 +0000705def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
706def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
707def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
708def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
709def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
710def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
711def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
712def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
713def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
714def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
715def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
716def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
717def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
718def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
Simon Pilgrim05710a82017-09-06 10:23:12 +0000719} // Defs = [FPSW]
Sean Callanan04d8cb72009-12-18 00:01:26 +0000720
Craig Topper33dc01d2018-05-01 04:42:00 +0000721def FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000722 "fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, TB,
Craig Toppera1639502017-12-15 17:22:58 +0000723 Requires<[HasFXSR]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000724def FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000725 "fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
726 TB, Requires<[HasFXSR, In64BitMode]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000727def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000728 "fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
Craig Toppera1639502017-12-15 17:22:58 +0000729 TB, Requires<[HasFXSR]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000730def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
Simon Pilgrim32d36812018-04-12 10:27:37 +0000731 "fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
732 TB, Requires<[HasFXSR, In64BitMode]>;
Jakob Stoklund Olesen267dd942013-03-26 18:24:20 +0000733} // SchedRW
Sean Callanan04d8cb72009-12-18 00:01:26 +0000734
Evan Chengd5847812006-02-21 20:00:20 +0000735//===----------------------------------------------------------------------===//
736// Non-Instruction Patterns
737//===----------------------------------------------------------------------===//
738
Dale Johannesena47f7d72007-08-07 20:29:26 +0000739// Required for RET of f32 / f64 / f80 values.
Craig Topperd7303ec2019-02-12 06:14:16 +0000740def : Pat<(X86fldf32 addr:$src), (LD_Fp32m addr:$src)>;
741def : Pat<(X86fldf64 addr:$src), (LD_Fp64m addr:$src)>;
742def : Pat<(X86fldf80 addr:$src), (LD_Fp80m addr:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000743
Dale Johannesena47f7d72007-08-07 20:29:26 +0000744// Required for CALL which return f32 / f64 / f80 values.
Craig Topperd7303ec2019-02-12 06:14:16 +0000745def : Pat<(X86fstf32 RFP32:$src, addr:$op), (ST_Fp32m addr:$op, RFP32:$src)>;
746def : Pat<(X86fstf32 RFP64:$src, addr:$op), (ST_Fp64m32 addr:$op, RFP64:$src)>;
747def : Pat<(X86fstf64 RFP64:$src, addr:$op), (ST_Fp64m addr:$op, RFP64:$src)>;
748def : Pat<(X86fstf32 RFP80:$src, addr:$op), (ST_Fp80m32 addr:$op, RFP80:$src)>;
749def : Pat<(X86fstf64 RFP80:$src, addr:$op), (ST_Fp80m64 addr:$op, RFP80:$src)>;
750def : Pat<(X86fstf80 RFP80:$src, addr:$op), (ST_FpP80m addr:$op, RFP80:$src)>;
Evan Chengd5847812006-02-21 20:00:20 +0000751
752// Floating point constant -0.0 and -1.0
Dale Johannesene36c4002007-09-23 14:52:20 +0000753def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
754def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
755def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
756def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
Dale Johannesena47f7d72007-08-07 20:29:26 +0000757def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
758def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
Evan Chengd5847812006-02-21 20:00:20 +0000759
760// Used to conv. i64 to f64 since there isn't a SSE version.
Craig Topperd7303ec2019-02-12 06:14:16 +0000761def : Pat<(X86fildflag64 addr:$src), (ILD_Fp64m64 addr:$src)>;
Dale Johannesena2b3c172007-07-03 00:53:03 +0000762
Chris Lattnerd587e582008-03-09 07:05:32 +0000763// FP extensions map onto simple pseudo-value conversions if they are to/from
764// the FP stack.
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000765def : Pat<(f64 (fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000766 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000767def : Pat<(f80 (fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000768 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000769def : Pat<(f80 (fpextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000770 Requires<[FPStackf64]>;
771
772// FP truncations map onto simple pseudo-value conversions if they are to/from
773// the FP stack. We have validated that only value-preserving truncations make
774// it through isel.
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000775def : Pat<(f32 (fpround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000776 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000777def : Pat<(f32 (fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000778 Requires<[FPStackf32]>;
Michael Kuperstein2bc3d4d2016-08-18 20:08:15 +0000779def : Pat<(f64 (fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
Chris Lattnerd587e582008-03-09 07:05:32 +0000780 Requires<[FPStackf64]>;