blob: 568726e08eced4e4607eefdcbe1b2be2c574a577 [file] [log] [blame]
Jia Liu44de83a2012-02-19 02:03:36 +00001//===- X86InstrFPStack.td - FPU Instruction Set ------------*- tablegen -*-===//
Jia Liu31d157a2012-02-18 12:03:15 +00002//
Evan Chengffcb95b2006-02-21 19:13:53 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jia Liu31d157a2012-02-18 12:03:15 +00007//
Evan Chengffcb95b2006-02-21 19:13:53 +00008//===----------------------------------------------------------------------===//
9//
10// This file describes the X86 x87 FPU instruction set, defining the
11// instructions, and properties of the instructions which are needed for code
12// generation, machine code emission, and analysis.
13//
14//===----------------------------------------------------------------------===//
15
Evan Cheng06a8aa12006-03-17 19:55:52 +000016//===----------------------------------------------------------------------===//
Evan Cheng2246f842006-03-18 01:23:20 +000017// FPStack specific DAG Nodes.
18//===----------------------------------------------------------------------===//
19
Chris Lattner6fa2f9c2008-03-09 07:05:32 +000020def SDTX86FpGet2 : SDTypeProfile<2, 0, [SDTCisVT<0, f80>,
21 SDTCisVT<1, f80>]>;
Dale Johannesen411d9c52007-07-03 17:07:33 +000022def SDTX86Fld : SDTypeProfile<1, 2, [SDTCisFP<0>,
Dale Johannesenbf6b8272007-07-10 20:53:41 +000023 SDTCisPtrTy<1>,
24 SDTCisVT<2, OtherVT>]>;
Dale Johannesen411d9c52007-07-03 17:07:33 +000025def SDTX86Fst : SDTypeProfile<0, 3, [SDTCisFP<0>,
Dale Johannesenbf6b8272007-07-10 20:53:41 +000026 SDTCisPtrTy<1>,
27 SDTCisVT<2, OtherVT>]>;
Dale Johannesen411d9c52007-07-03 17:07:33 +000028def SDTX86Fild : SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisPtrTy<1>,
29 SDTCisVT<2, OtherVT>]>;
Benjamin Kramer17c836c2012-04-27 12:07:43 +000030def SDTX86Fnstsw : SDTypeProfile<1, 1, [SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
Dale Johannesen411d9c52007-07-03 17:07:33 +000031def SDTX86FpToIMem : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
Evan Cheng2246f842006-03-18 01:23:20 +000032
Anton Korobeynikov45b22fa2007-11-16 01:31:51 +000033def SDTX86CwdStore : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
34
Chris Lattnerba7e7562008-01-10 07:59:24 +000035def X86fld : SDNode<"X86ISD::FLD", SDTX86Fld,
Chris Lattner492a43e2010-09-22 01:28:21 +000036 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattnerba7e7562008-01-10 07:59:24 +000037def X86fst : SDNode<"X86ISD::FST", SDTX86Fst,
Chris Lattner036609b2010-12-23 18:28:41 +000038 [SDNPHasChain, SDNPInGlue, SDNPMayStore,
Chris Lattner492a43e2010-09-22 01:28:21 +000039 SDNPMemOperand]>;
Chris Lattnerba7e7562008-01-10 07:59:24 +000040def X86fild : SDNode<"X86ISD::FILD", SDTX86Fild,
Chris Lattner492a43e2010-09-22 01:28:21 +000041 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattnerba7e7562008-01-10 07:59:24 +000042def X86fildflag : SDNode<"X86ISD::FILD_FLAG", SDTX86Fild,
Chris Lattner036609b2010-12-23 18:28:41 +000043 [SDNPHasChain, SDNPOutGlue, SDNPMayLoad,
Chris Lattner492a43e2010-09-22 01:28:21 +000044 SDNPMemOperand]>;
Benjamin Kramer17c836c2012-04-27 12:07:43 +000045def X86fp_stsw : SDNode<"X86ISD::FNSTSW16r", SDTX86Fnstsw>;
Evan Cheng2246f842006-03-18 01:23:20 +000046def X86fp_to_i16mem : SDNode<"X86ISD::FP_TO_INT16_IN_MEM", SDTX86FpToIMem,
Chris Lattner07290932010-09-22 01:05:16 +000047 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Evan Cheng2246f842006-03-18 01:23:20 +000048def X86fp_to_i32mem : SDNode<"X86ISD::FP_TO_INT32_IN_MEM", SDTX86FpToIMem,
Chris Lattner07290932010-09-22 01:05:16 +000049 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Evan Cheng2246f842006-03-18 01:23:20 +000050def X86fp_to_i64mem : SDNode<"X86ISD::FP_TO_INT64_IN_MEM", SDTX86FpToIMem,
Chris Lattner07290932010-09-22 01:05:16 +000051 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Anton Korobeynikov45b22fa2007-11-16 01:31:51 +000052def X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m", SDTX86CwdStore,
Chris Lattner07290932010-09-22 01:05:16 +000053 [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
54 SDNPMemOperand]>;
Evan Cheng2246f842006-03-18 01:23:20 +000055
56//===----------------------------------------------------------------------===//
Evan Cheng06a8aa12006-03-17 19:55:52 +000057// FPStack pattern fragments
58//===----------------------------------------------------------------------===//
59
Dale Johannesen849f2142007-07-03 00:53:03 +000060def fpimm0 : PatLeaf<(fpimm), [{
Evan Cheng06a8aa12006-03-17 19:55:52 +000061 return N->isExactlyValue(+0.0);
62}]>;
63
Dale Johannesen849f2142007-07-03 00:53:03 +000064def fpimmneg0 : PatLeaf<(fpimm), [{
Evan Cheng06a8aa12006-03-17 19:55:52 +000065 return N->isExactlyValue(-0.0);
66}]>;
67
Dale Johannesen849f2142007-07-03 00:53:03 +000068def fpimm1 : PatLeaf<(fpimm), [{
Evan Cheng06a8aa12006-03-17 19:55:52 +000069 return N->isExactlyValue(+1.0);
70}]>;
71
Dale Johannesen849f2142007-07-03 00:53:03 +000072def fpimmneg1 : PatLeaf<(fpimm), [{
Evan Cheng06a8aa12006-03-17 19:55:52 +000073 return N->isExactlyValue(-1.0);
74}]>;
75
Evan Cheng4e4c71e2006-02-21 20:00:20 +000076// Some 'special' instructions
Dan Gohman533297b2009-10-29 18:10:34 +000077let usesCustomInserter = 1 in { // Expanded after instruction selection.
Eric Christopherc563ded2010-11-30 21:57:32 +000078 def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
Dale Johannesen411d9c52007-07-03 17:07:33 +000079 [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000080 def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
Dale Johannesen411d9c52007-07-03 17:07:33 +000081 [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000082 def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
Dale Johannesen411d9c52007-07-03 17:07:33 +000083 [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000084 def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
Dale Johannesen411d9c52007-07-03 17:07:33 +000085 [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000086 def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
Dale Johannesen411d9c52007-07-03 17:07:33 +000087 [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000088 def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
Dale Johannesen411d9c52007-07-03 17:07:33 +000089 [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000090 def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
Dale Johannesena996d522007-08-07 01:17:37 +000091 [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000092 def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
Dale Johannesena996d522007-08-07 01:17:37 +000093 [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
Eric Christopherc563ded2010-11-30 21:57:32 +000094 def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
Dale Johannesena996d522007-08-07 01:17:37 +000095 [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +000096}
97
Dale Johannesencdbe4d32007-08-07 20:29:26 +000098// All FP Stack operations are represented with four instructions here. The
99// first three instructions, generated by the instruction selector, use "RFP32"
100// "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
101// 64-bit or 80-bit floating point values. These sizes apply to the values,
102// not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
103// copied to each other without losing information. These instructions are all
104// pseudo instructions and use the "_Fp" suffix.
105// In some cases there are additional variants with a mixture of different
106// register sizes.
Evan Chengffcb95b2006-02-21 19:13:53 +0000107// The second instruction is defined with FPI, which is the actual instruction
Dale Johannesene377d4d2007-07-04 21:07:47 +0000108// emitted by the assembler. These use "RST" registers, although frequently
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000109// the actual register(s) used are implicit. These are always 80 bits.
Dale Johannesene377d4d2007-07-04 21:07:47 +0000110// The FP stackifier pass converts one to the other after register allocation
111// occurs.
Evan Chengffcb95b2006-02-21 19:13:53 +0000112//
113// Note that the FpI instruction should have instruction selection info (e.g.
114// a pattern) and the FPI instruction should have emission info (e.g. opcode
115// encoding and asm printing info).
116
Jakob Stoklund Olesen9bbe4d62011-06-28 18:32:28 +0000117// Pseudo Instruction for FP stack return values.
118def FpPOP_RETVAL : FpI_<(outs RFP80:$dst), (ins), SpecialFP, []>;
Evan Chenga0eedac2009-02-09 23:32:07 +0000119
Bob Wilson3b7bbfd2010-08-26 18:08:11 +0000120// FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000121// f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
122// f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
123// f80 instructions cannot use SSE and use neither of these.
124class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
125 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
126class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
127 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
Evan Chengffcb95b2006-02-21 19:13:53 +0000128
Dale Johannesene377d4d2007-07-04 21:07:47 +0000129// Factoring for arithmetic.
130multiclass FPBinary_rr<SDNode OpNode> {
131// Register op register -> register
132// These are separated out because they have no reversed form.
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000133def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000134 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000135def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000136 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000137def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000138 [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
Dale Johannesene377d4d2007-07-04 21:07:47 +0000139}
140// The FopST0 series are not included here because of the irregularities
141// in where the 'r' goes in assembly output.
Dale Johannesen59a58732007-08-05 18:49:15 +0000142// These instructions cannot address 80-bit memory.
Dale Johannesene377d4d2007-07-04 21:07:47 +0000143multiclass FPBinary<SDNode OpNode, Format fp, string asmstring> {
144// ST(0) = ST(0) + [mem]
Sean Callanan108934c2009-12-18 00:01:26 +0000145def _Fp32m : FpIf32<(outs RFP32:$dst),
146 (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
Dale Johannesenbf6b8272007-07-10 20:53:41 +0000147 [(set RFP32:$dst,
148 (OpNode RFP32:$src1, (loadf32 addr:$src2)))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000149def _Fp64m : FpIf64<(outs RFP64:$dst),
150 (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
Dale Johannesenbf6b8272007-07-10 20:53:41 +0000151 [(set RFP64:$dst,
152 (OpNode RFP64:$src1, (loadf64 addr:$src2)))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000153def _Fp64m32: FpIf64<(outs RFP64:$dst),
154 (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
Dale Johannesenafdc7fd2007-07-10 21:53:30 +0000155 [(set RFP64:$dst,
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000156 (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2))))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000157def _Fp80m32: FpI_<(outs RFP80:$dst),
158 (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
Dale Johannesen59a58732007-08-05 18:49:15 +0000159 [(set RFP80:$dst,
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000160 (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2))))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000161def _Fp80m64: FpI_<(outs RFP80:$dst),
162 (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
Dale Johannesen59a58732007-08-05 18:49:15 +0000163 [(set RFP80:$dst,
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000164 (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2))))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000165def _F32m : FPI<0xD8, fp, (outs), (ins f32mem:$src),
Chris Lattner8d978a72010-10-05 23:58:18 +0000166 !strconcat("f", asmstring, "{s}\t$src")> {
Sean Callanan108934c2009-12-18 00:01:26 +0000167 let mayLoad = 1;
168}
Evan Cheng64d80e32007-07-19 01:14:50 +0000169def _F64m : FPI<0xDC, fp, (outs), (ins f64mem:$src),
Chris Lattner8d978a72010-10-05 23:58:18 +0000170 !strconcat("f", asmstring, "{l}\t$src")> {
Sean Callanan108934c2009-12-18 00:01:26 +0000171 let mayLoad = 1;
172}
Dale Johannesene377d4d2007-07-04 21:07:47 +0000173// ST(0) = ST(0) + [memint]
Sean Callanan108934c2009-12-18 00:01:26 +0000174def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
175 OneArgFPRW,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000176 [(set RFP32:$dst, (OpNode RFP32:$src1,
177 (X86fild addr:$src2, i16)))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000178def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
179 OneArgFPRW,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000180 [(set RFP32:$dst, (OpNode RFP32:$src1,
181 (X86fild addr:$src2, i32)))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000182def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
183 OneArgFPRW,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000184 [(set RFP64:$dst, (OpNode RFP64:$src1,
185 (X86fild addr:$src2, i16)))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000186def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
187 OneArgFPRW,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000188 [(set RFP64:$dst, (OpNode RFP64:$src1,
189 (X86fild addr:$src2, i32)))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000190def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
191 OneArgFPRW,
Dale Johannesen59a58732007-08-05 18:49:15 +0000192 [(set RFP80:$dst, (OpNode RFP80:$src1,
193 (X86fild addr:$src2, i16)))]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000194def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
195 OneArgFPRW,
Dale Johannesen59a58732007-08-05 18:49:15 +0000196 [(set RFP80:$dst, (OpNode RFP80:$src1,
197 (X86fild addr:$src2, i32)))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000198def _FI16m : FPI<0xDE, fp, (outs), (ins i16mem:$src),
Chris Lattner8d978a72010-10-05 23:58:18 +0000199 !strconcat("fi", asmstring, "{s}\t$src")> {
Sean Callanan108934c2009-12-18 00:01:26 +0000200 let mayLoad = 1;
201}
Evan Cheng64d80e32007-07-19 01:14:50 +0000202def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
Chris Lattner8d978a72010-10-05 23:58:18 +0000203 !strconcat("fi", asmstring, "{l}\t$src")> {
Sean Callanan108934c2009-12-18 00:01:26 +0000204 let mayLoad = 1;
205}
Dale Johannesene377d4d2007-07-04 21:07:47 +0000206}
207
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000208let Defs = [FPSW] in {
Dale Johannesene377d4d2007-07-04 21:07:47 +0000209defm ADD : FPBinary_rr<fadd>;
210defm SUB : FPBinary_rr<fsub>;
211defm MUL : FPBinary_rr<fmul>;
212defm DIV : FPBinary_rr<fdiv>;
213defm ADD : FPBinary<fadd, MRM0m, "add">;
214defm SUB : FPBinary<fsub, MRM4m, "sub">;
215defm SUBR: FPBinary<fsub ,MRM5m, "subr">;
216defm MUL : FPBinary<fmul, MRM1m, "mul">;
217defm DIV : FPBinary<fdiv, MRM6m, "div">;
218defm DIVR: FPBinary<fdiv, MRM7m, "divr">;
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000219}
Evan Chengffcb95b2006-02-21 19:13:53 +0000220
221class FPST0rInst<bits<8> o, string asm>
Evan Cheng64d80e32007-07-19 01:14:50 +0000222 : FPI<o, AddRegFrm, (outs), (ins RST:$op), asm>, D8;
Evan Chengffcb95b2006-02-21 19:13:53 +0000223class FPrST0Inst<bits<8> o, string asm>
Evan Cheng64d80e32007-07-19 01:14:50 +0000224 : FPI<o, AddRegFrm, (outs), (ins RST:$op), asm>, DC;
Evan Chengffcb95b2006-02-21 19:13:53 +0000225class FPrST0PInst<bits<8> o, string asm>
Evan Cheng64d80e32007-07-19 01:14:50 +0000226 : FPI<o, AddRegFrm, (outs), (ins RST:$op), asm>, DE;
Evan Chengffcb95b2006-02-21 19:13:53 +0000227
Evan Chengffcb95b2006-02-21 19:13:53 +0000228// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
229// of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
230// we have to put some 'r's in and take them out of weird places.
Dan Gohmanb1576f52007-07-31 20:11:57 +0000231def ADD_FST0r : FPST0rInst <0xC0, "fadd\t$op">;
Devang Patelb1666b92012-01-03 18:22:10 +0000232def ADD_FrST0 : FPrST0Inst <0xC0, "fadd\t{%st(0), $op|$op, ST(0)}">;
Dan Gohmanb1576f52007-07-31 20:11:57 +0000233def ADD_FPrST0 : FPrST0PInst<0xC0, "faddp\t$op">;
234def SUBR_FST0r : FPST0rInst <0xE8, "fsubr\t$op">;
Devang Patelb1666b92012-01-03 18:22:10 +0000235def SUB_FrST0 : FPrST0Inst <0xE8, "fsub{r}\t{%st(0), $op|$op, ST(0)}">;
Dan Gohmanb1576f52007-07-31 20:11:57 +0000236def SUB_FPrST0 : FPrST0PInst<0xE8, "fsub{r}p\t$op">;
237def SUB_FST0r : FPST0rInst <0xE0, "fsub\t$op">;
Devang Patelb1666b92012-01-03 18:22:10 +0000238def SUBR_FrST0 : FPrST0Inst <0xE0, "fsub{|r}\t{%st(0), $op|$op, ST(0)}">;
Dan Gohmanb1576f52007-07-31 20:11:57 +0000239def SUBR_FPrST0 : FPrST0PInst<0xE0, "fsub{|r}p\t$op">;
240def MUL_FST0r : FPST0rInst <0xC8, "fmul\t$op">;
Devang Patelb1666b92012-01-03 18:22:10 +0000241def MUL_FrST0 : FPrST0Inst <0xC8, "fmul\t{%st(0), $op|$op, ST(0)}">;
Dan Gohmanb1576f52007-07-31 20:11:57 +0000242def MUL_FPrST0 : FPrST0PInst<0xC8, "fmulp\t$op">;
243def DIVR_FST0r : FPST0rInst <0xF8, "fdivr\t$op">;
Devang Patelb1666b92012-01-03 18:22:10 +0000244def DIV_FrST0 : FPrST0Inst <0xF8, "fdiv{r}\t{%st(0), $op|$op, ST(0)}">;
Dan Gohmanb1576f52007-07-31 20:11:57 +0000245def DIV_FPrST0 : FPrST0PInst<0xF8, "fdiv{r}p\t$op">;
246def DIV_FST0r : FPST0rInst <0xF0, "fdiv\t$op">;
Devang Patelb1666b92012-01-03 18:22:10 +0000247def DIVR_FrST0 : FPrST0Inst <0xF0, "fdiv{|r}\t{%st(0), $op|$op, ST(0)}">;
Dan Gohmanb1576f52007-07-31 20:11:57 +0000248def DIVR_FPrST0 : FPrST0PInst<0xF0, "fdiv{|r}p\t$op">;
Evan Chengffcb95b2006-02-21 19:13:53 +0000249
Sean Callanan108934c2009-12-18 00:01:26 +0000250def COM_FST0r : FPST0rInst <0xD0, "fcom\t$op">;
251def COMP_FST0r : FPST0rInst <0xD8, "fcomp\t$op">;
252
Evan Chengffcb95b2006-02-21 19:13:53 +0000253// Unary operations.
Dale Johannesene377d4d2007-07-04 21:07:47 +0000254multiclass FPUnary<SDNode OpNode, bits<8> opcode, string asmstring> {
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000255def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000256 [(set RFP32:$dst, (OpNode RFP32:$src))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000257def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000258 [(set RFP64:$dst, (OpNode RFP64:$src))]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000259def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
Dale Johannesen59a58732007-08-05 18:49:15 +0000260 [(set RFP80:$dst, (OpNode RFP80:$src))]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000261def _F : FPI<opcode, RawFrm, (outs), (ins), asmstring>, D9;
Evan Chengffcb95b2006-02-21 19:13:53 +0000262}
263
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000264let Defs = [FPSW] in {
Dale Johannesene377d4d2007-07-04 21:07:47 +0000265defm CHS : FPUnary<fneg, 0xE0, "fchs">;
266defm ABS : FPUnary<fabs, 0xE1, "fabs">;
267defm SQRT: FPUnary<fsqrt,0xFA, "fsqrt">;
268defm SIN : FPUnary<fsin, 0xFE, "fsin">;
269defm COS : FPUnary<fcos, 0xFF, "fcos">;
270
Chris Lattnera731c9f2008-01-11 07:18:17 +0000271let neverHasSideEffects = 1 in {
272def TST_Fp32 : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
273def TST_Fp64 : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
274def TST_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
275}
Evan Cheng64d80e32007-07-19 01:14:50 +0000276def TST_F : FPI<0xE4, RawFrm, (outs), (ins), "ftst">, D9;
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000277} // Defs = [FPSW]
Dale Johannesene377d4d2007-07-04 21:07:47 +0000278
Sean Callanan5ab94032009-09-16 01:13:52 +0000279// Versions of FP instructions that take a single memory operand. Added for the
280// disassembler; remove as they are included with patterns elsewhere.
Kevin Enderby9d0838f2010-05-03 21:31:40 +0000281def FCOM32m : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
282def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
Sean Callanan5ab94032009-09-16 01:13:52 +0000283
284def FLDENVm : FPI<0xD9, MRM4m, (outs), (ins f32mem:$src), "fldenv\t$src">;
Sean Callanan108934c2009-12-18 00:01:26 +0000285def FSTENVm : FPI<0xD9, MRM6m, (outs f32mem:$dst), (ins), "fnstenv\t$dst">;
Sean Callanan5ab94032009-09-16 01:13:52 +0000286
287def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
288def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
289
Kevin Enderby9d0838f2010-05-03 21:31:40 +0000290def FCOM64m : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
291def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
Sean Callanan5ab94032009-09-16 01:13:52 +0000292
Sean Callanan5ab94032009-09-16 01:13:52 +0000293def FRSTORm : FPI<0xDD, MRM4m, (outs f32mem:$dst), (ins), "frstor\t$dst">;
Sean Callanan108934c2009-12-18 00:01:26 +0000294def FSAVEm : FPI<0xDD, MRM6m, (outs f32mem:$dst), (ins), "fnsave\t$dst">;
Andrew Trick0966ec02010-10-22 03:58:29 +0000295def FNSTSWm : FPI<0xDD, MRM7m, (outs f32mem:$dst), (ins), "fnstsw\t$dst">;
Sean Callanan5ab94032009-09-16 01:13:52 +0000296
Kevin Enderby9d0838f2010-05-03 21:31:40 +0000297def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
298def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
Sean Callanan5ab94032009-09-16 01:13:52 +0000299
300def FBLDm : FPI<0xDF, MRM4m, (outs), (ins f32mem:$src), "fbld\t$src">;
Sean Callanan5ab94032009-09-16 01:13:52 +0000301def FBSTPm : FPI<0xDF, MRM6m, (outs f32mem:$dst), (ins), "fbstp\t$dst">;
Sean Callanan5ab94032009-09-16 01:13:52 +0000302
Dale Johannesene377d4d2007-07-04 21:07:47 +0000303// Floating point cmovs.
Chris Lattner314a1132010-03-14 18:31:44 +0000304class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
305 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMov]>;
306class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
307 FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMov]>;
308
Dale Johannesene377d4d2007-07-04 21:07:47 +0000309multiclass FPCMov<PatLeaf cc> {
Chris Lattner314a1132010-03-14 18:31:44 +0000310 def _Fp32 : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
Evan Chenge5f62042007-09-29 00:00:36 +0000311 CondMovFP,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000312 [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +0000313 cc, EFLAGS))]>;
Chris Lattner314a1132010-03-14 18:31:44 +0000314 def _Fp64 : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
Evan Chenge5f62042007-09-29 00:00:36 +0000315 CondMovFP,
Dale Johannesene377d4d2007-07-04 21:07:47 +0000316 [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
Evan Chenge5f62042007-09-29 00:00:36 +0000317 cc, EFLAGS))]>;
318 def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
319 CondMovFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000320 [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
Chris Lattner314a1132010-03-14 18:31:44 +0000321 cc, EFLAGS))]>,
322 Requires<[HasCMov]>;
Dale Johannesene377d4d2007-07-04 21:07:47 +0000323}
Chris Lattner314a1132010-03-14 18:31:44 +0000324
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000325let Defs = [FPSW] in {
Eric Christopher96ab7f42010-06-18 23:56:07 +0000326let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
Dale Johannesene377d4d2007-07-04 21:07:47 +0000327defm CMOVB : FPCMov<X86_COND_B>;
328defm CMOVBE : FPCMov<X86_COND_BE>;
329defm CMOVE : FPCMov<X86_COND_E>;
330defm CMOVP : FPCMov<X86_COND_P>;
331defm CMOVNB : FPCMov<X86_COND_AE>;
332defm CMOVNBE: FPCMov<X86_COND_A>;
333defm CMOVNE : FPCMov<X86_COND_NE>;
334defm CMOVNP : FPCMov<X86_COND_NP>;
Eric Christopher96ab7f42010-06-18 23:56:07 +0000335} // Uses = [EFLAGS], Constraints = "$src1 = $dst"
Dale Johannesene377d4d2007-07-04 21:07:47 +0000336
Chris Lattner314a1132010-03-14 18:31:44 +0000337let Predicates = [HasCMov] in {
Dale Johannesene377d4d2007-07-04 21:07:47 +0000338// These are not factored because there's no clean way to pass DA/DB.
Evan Cheng64d80e32007-07-19 01:14:50 +0000339def CMOVB_F : FPI<0xC0, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000340 "fcmovb\t{$op, %st(0)|ST(0), $op}">, DA;
Evan Cheng64d80e32007-07-19 01:14:50 +0000341def CMOVBE_F : FPI<0xD0, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000342 "fcmovbe\t{$op, %st(0)|ST(0), $op}">, DA;
Evan Cheng64d80e32007-07-19 01:14:50 +0000343def CMOVE_F : FPI<0xC8, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000344 "fcmove\t{$op, %st(0)|ST(0), $op}">, DA;
Evan Cheng64d80e32007-07-19 01:14:50 +0000345def CMOVP_F : FPI<0xD8, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000346 "fcmovu\t {$op, %st(0)|ST(0), $op}">, DA;
Evan Cheng64d80e32007-07-19 01:14:50 +0000347def CMOVNB_F : FPI<0xC0, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000348 "fcmovnb\t{$op, %st(0)|ST(0), $op}">, DB;
Evan Cheng64d80e32007-07-19 01:14:50 +0000349def CMOVNBE_F: FPI<0xD0, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000350 "fcmovnbe\t{$op, %st(0)|ST(0), $op}">, DB;
Evan Cheng64d80e32007-07-19 01:14:50 +0000351def CMOVNE_F : FPI<0xC8, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000352 "fcmovne\t{$op, %st(0)|ST(0), $op}">, DB;
Evan Cheng64d80e32007-07-19 01:14:50 +0000353def CMOVNP_F : FPI<0xD8, AddRegFrm, (outs RST:$op), (ins),
Devang Patelb1666b92012-01-03 18:22:10 +0000354 "fcmovnu\t{$op, %st(0)|ST(0), $op}">, DB;
Chris Lattner314a1132010-03-14 18:31:44 +0000355} // Predicates = [HasCMov]
Evan Chengffcb95b2006-02-21 19:13:53 +0000356
357// Floating point loads & stores.
Dan Gohman15511cf2008-12-03 18:15:48 +0000358let canFoldAsLoad = 1 in {
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000359def LD_Fp32m : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000360 [(set RFP32:$dst, (loadf32 addr:$src))]>;
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000361let isReMaterializable = 1 in
Bill Wendling691de382007-12-17 22:17:14 +0000362 def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000363 [(set RFP64:$dst, (loadf64 addr:$src))]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000364def LD_Fp80m : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000365 [(set RFP80:$dst, (loadf80 addr:$src))]>;
Evan Cheng2f394262007-08-30 05:49:43 +0000366}
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000367def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000368 [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
369def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
370 [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
371def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
372 [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000373def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000374 [(set RFP32:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000375def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000376 [(set RFP32:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000377def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000378 [(set RFP32:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000379def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000380 [(set RFP64:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000381def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000382 [(set RFP64:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000383def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000384 [(set RFP64:$dst, (X86fild addr:$src, i64))]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000385def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000386 [(set RFP80:$dst, (X86fild addr:$src, i16))]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000387def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000388 [(set RFP80:$dst, (X86fild addr:$src, i32))]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000389def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000390 [(set RFP80:$dst, (X86fild addr:$src, i64))]>;
Evan Chengffcb95b2006-02-21 19:13:53 +0000391
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000392def ST_Fp32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000393 [(store RFP32:$src, addr:$op)]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000394def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000395 [(truncstoref32 RFP64:$src, addr:$op)]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000396def ST_Fp64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
Dale Johannesen411d9c52007-07-03 17:07:33 +0000397 [(store RFP64:$src, addr:$op)]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000398def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000399 [(truncstoref32 RFP80:$src, addr:$op)]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000400def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000401 [(truncstoref64 RFP80:$src, addr:$op)]>;
402// FST does not support 80-bit memory target; FSTP must be used.
Evan Chengffcb95b2006-02-21 19:13:53 +0000403
Chris Lattnera731c9f2008-01-11 07:18:17 +0000404let mayStore = 1, neverHasSideEffects = 1 in {
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000405def ST_FpP32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
406def ST_FpP64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
407def ST_FpP64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
408def ST_FpP80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
409def ST_FpP80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000410}
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000411def ST_FpP80m : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000412 [(store RFP80:$src, addr:$op)]>;
Chris Lattnera731c9f2008-01-11 07:18:17 +0000413let mayStore = 1, neverHasSideEffects = 1 in {
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000414def IST_Fp16m32 : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
415def IST_Fp32m32 : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP, []>;
416def IST_Fp64m32 : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP, []>;
417def IST_Fp16m64 : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
418def IST_Fp32m64 : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP, []>;
419def IST_Fp64m64 : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP, []>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000420def IST_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
421def IST_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP, []>;
422def IST_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP, []>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000423}
Evan Chengffcb95b2006-02-21 19:13:53 +0000424
Chris Lattnerba7e7562008-01-10 07:59:24 +0000425let mayLoad = 1 in {
Preston Gurd95f0cf02012-05-02 16:03:35 +0000426def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src",
427 IIC_FLD>;
428def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src",
429 IIC_FLD>;
430def LD_F80m : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src",
431 IIC_FLD80>;
432def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src",
433 IIC_FILD>;
434def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src",
435 IIC_FILD>;
436def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src",
437 IIC_FILD>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000438}
439let mayStore = 1 in {
Preston Gurd95f0cf02012-05-02 16:03:35 +0000440def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst",
441 IIC_FST>;
442def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst",
443 IIC_FST>;
444def ST_FP32m : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst",
445 IIC_FST>;
446def ST_FP64m : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst",
447 IIC_FST>;
448def ST_FP80m : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst",
449 IIC_FST80>;
450def IST_F16m : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst",
451 IIC_FIST>;
452def IST_F32m : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst",
453 IIC_FIST>;
454def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst",
455 IIC_FIST>;
456def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst",
457 IIC_FIST>;
458def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst",
459 IIC_FIST>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000460}
Evan Chengffcb95b2006-02-21 19:13:53 +0000461
462// FISTTP requires SSE3 even though it's a FPStack op.
Craig Topperc6d59952012-01-10 06:30:56 +0000463let Predicates = [HasSSE3] in {
Evan Cheng64d80e32007-07-19 01:14:50 +0000464def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000465 [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000466def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000467 [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000468def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000469 [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000470def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000471 [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000472def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000473 [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
Evan Cheng64d80e32007-07-19 01:14:50 +0000474def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000475 [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
Dale Johannesena996d522007-08-07 01:17:37 +0000476def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000477 [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
Dale Johannesena996d522007-08-07 01:17:37 +0000478def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000479 [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
Dale Johannesena996d522007-08-07 01:17:37 +0000480def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
Craig Topperc6d59952012-01-10 06:30:56 +0000481 [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
482} // Predicates = [HasSSE3]
Evan Chengffcb95b2006-02-21 19:13:53 +0000483
Chris Lattnerba7e7562008-01-10 07:59:24 +0000484let mayStore = 1 in {
Preston Gurd95f0cf02012-05-02 16:03:35 +0000485def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst",
486 IIC_FST>;
487def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst",
488 IIC_FST>;
Sean Callanan108934c2009-12-18 00:01:26 +0000489def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000490 "fisttp{ll}\t$dst", IIC_FST>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000491}
Evan Chengffcb95b2006-02-21 19:13:53 +0000492
493// FP Stack manipulation instructions.
Preston Gurd95f0cf02012-05-02 16:03:35 +0000494def LD_Frr : FPI<0xC0, AddRegFrm, (outs), (ins RST:$op), "fld\t$op",
495 IIC_FLD>, D9;
496def ST_Frr : FPI<0xD0, AddRegFrm, (outs), (ins RST:$op), "fst\t$op",
497 IIC_FST>, DD;
498def ST_FPrr : FPI<0xD8, AddRegFrm, (outs), (ins RST:$op), "fstp\t$op",
499 IIC_FST>, DD;
500def XCH_F : FPI<0xC8, AddRegFrm, (outs), (ins RST:$op), "fxch\t$op",
501 IIC_FXCH>, D9;
Evan Chengffcb95b2006-02-21 19:13:53 +0000502
503// Floating point constant loads.
Chris Lattnerdd415272008-01-10 05:45:39 +0000504let isReMaterializable = 1 in {
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000505def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesen849f2142007-07-03 00:53:03 +0000506 [(set RFP32:$dst, fpimm0)]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000507def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
Dale Johannesen849f2142007-07-03 00:53:03 +0000508 [(set RFP32:$dst, fpimm1)]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000509def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesen849f2142007-07-03 00:53:03 +0000510 [(set RFP64:$dst, fpimm0)]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000511def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
Dale Johannesen849f2142007-07-03 00:53:03 +0000512 [(set RFP64:$dst, fpimm1)]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000513def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000514 [(set RFP80:$dst, fpimm0)]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000515def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
Dale Johannesen59a58732007-08-05 18:49:15 +0000516 [(set RFP80:$dst, fpimm1)]>;
Dan Gohmand45eddd2007-06-26 00:48:07 +0000517}
Evan Chengffcb95b2006-02-21 19:13:53 +0000518
Preston Gurd95f0cf02012-05-02 16:03:35 +0000519def LD_F0 : FPI<0xEE, RawFrm, (outs), (ins), "fldz", IIC_FLDZ>, D9;
520def LD_F1 : FPI<0xE8, RawFrm, (outs), (ins), "fld1", IIC_FIST>, D9;
Evan Chengffcb95b2006-02-21 19:13:53 +0000521
522
523// Floating point compares.
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000524def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000525 [(set FPSW, (trunc (X86cmp RFP32:$lhs, RFP32:$rhs)))]>;
Chris Lattnera731c9f2008-01-11 07:18:17 +0000526def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000527 [(set FPSW, (trunc (X86cmp RFP64:$lhs, RFP64:$rhs)))]>;
Chris Lattnera731c9f2008-01-11 07:18:17 +0000528def UCOM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000529 [(set FPSW, (trunc (X86cmp RFP80:$lhs, RFP80:$rhs)))]>;
530} // Defs = [FPSW]
531
Chris Lattnere3486a42010-03-19 00:01:11 +0000532// CC = ST(0) cmp ST(i)
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000533let Defs = [EFLAGS, FPSW] in {
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000534def UCOM_FpIr32: FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Chris Lattnere3486a42010-03-19 00:01:11 +0000535 [(set EFLAGS, (X86cmp RFP32:$lhs, RFP32:$rhs))]>;
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000536def UCOM_FpIr64: FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Chris Lattnere3486a42010-03-19 00:01:11 +0000537 [(set EFLAGS, (X86cmp RFP64:$lhs, RFP64:$rhs))]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000538def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
Chris Lattnere3486a42010-03-19 00:01:11 +0000539 [(set EFLAGS, (X86cmp RFP80:$lhs, RFP80:$rhs))]>;
Evan Cheng4e4d2d72007-09-25 19:08:02 +0000540}
541
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000542let Defs = [FPSW], Uses = [ST0] in {
Dale Johannesene377d4d2007-07-04 21:07:47 +0000543def UCOM_Fr : FPI<0xE0, AddRegFrm, // FPSW = cmp ST(0) with ST(i)
Evan Cheng64d80e32007-07-19 01:14:50 +0000544 (outs), (ins RST:$reg),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000545 "fucom\t$reg", IIC_FUCOM>, DD;
Dale Johannesene377d4d2007-07-04 21:07:47 +0000546def UCOM_FPr : FPI<0xE8, AddRegFrm, // FPSW = cmp ST(0) with ST(i), pop
Evan Cheng64d80e32007-07-19 01:14:50 +0000547 (outs), (ins RST:$reg),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000548 "fucomp\t$reg", IIC_FUCOM>, DD;
Dale Johannesene377d4d2007-07-04 21:07:47 +0000549def UCOM_FPPr : FPI<0xE9, RawFrm, // cmp ST(0) with ST(1), pop, pop
Evan Cheng64d80e32007-07-19 01:14:50 +0000550 (outs), (ins),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000551 "fucompp", IIC_FUCOM>, DA;
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000552}
Evan Chengffcb95b2006-02-21 19:13:53 +0000553
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000554let Defs = [EFLAGS, FPSW], Uses = [ST0] in {
Dale Johannesene377d4d2007-07-04 21:07:47 +0000555def UCOM_FIr : FPI<0xE8, AddRegFrm, // CC = cmp ST(0) with ST(i)
Evan Cheng64d80e32007-07-19 01:14:50 +0000556 (outs), (ins RST:$reg),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000557 "fucomi\t$reg", IIC_FUCOMI>, DB;
Dale Johannesene377d4d2007-07-04 21:07:47 +0000558def UCOM_FIPr : FPI<0xE8, AddRegFrm, // CC = cmp ST(0) with ST(i), pop
Evan Cheng64d80e32007-07-19 01:14:50 +0000559 (outs), (ins RST:$reg),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000560 "fucompi\t$reg", IIC_FUCOMI>, DF;
Evan Cheng071a2792007-09-11 19:55:27 +0000561}
Evan Chengffcb95b2006-02-21 19:13:53 +0000562
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000563let Defs = [EFLAGS, FPSW] in {
Sean Callanan108934c2009-12-18 00:01:26 +0000564def COM_FIr : FPI<0xF0, AddRegFrm, (outs), (ins RST:$reg),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000565 "fcomi\t$reg", IIC_FCOMI>, DB;
Sean Callanan108934c2009-12-18 00:01:26 +0000566def COM_FIPr : FPI<0xF0, AddRegFrm, (outs), (ins RST:$reg),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000567 "fcompi\t$reg", IIC_FCOMI>, DF;
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000568}
Sean Callanan108934c2009-12-18 00:01:26 +0000569
Evan Chengffcb95b2006-02-21 19:13:53 +0000570// Floating point flag ops.
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000571let Defs = [AX], Uses = [FPSW] in
572def FNSTSW16r : I<0xE0, RawFrm, // AX = fp flags
573 (outs), (ins), "fnstsw %ax",
Preston Gurd95f0cf02012-05-02 16:03:35 +0000574 [(set AX, (X86fp_stsw FPSW))], IIC_FNSTSW>, DF;
Evan Chengffcb95b2006-02-21 19:13:53 +0000575
576def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
Andrew Trick0966ec02010-10-22 03:58:29 +0000577 (outs), (ins i16mem:$dst), "fnstcw\t$dst",
Preston Gurd95f0cf02012-05-02 16:03:35 +0000578 [(X86fp_cwd_get16 addr:$dst)], IIC_FNSTCW>;
Chris Lattnerba7e7562008-01-10 07:59:24 +0000579
580let mayLoad = 1 in
Evan Chengffcb95b2006-02-21 19:13:53 +0000581def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
Preston Gurd95f0cf02012-05-02 16:03:35 +0000582 (outs), (ins i16mem:$dst), "fldcw\t$dst", [], IIC_FLDCW>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000583
Chris Lattner434c7cb2010-10-05 05:32:15 +0000584// FPU control instructions
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000585let Defs = [FPSW] in
Preston Gurd95f0cf02012-05-02 16:03:35 +0000586def FNINIT : I<0xE3, RawFrm, (outs), (ins), "fninit", [], IIC_FNINIT>, DB;
Sean Callanan108934c2009-12-18 00:01:26 +0000587def FFREE : FPI<0xC0, AddRegFrm, (outs), (ins RST:$reg),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000588 "ffree\t$reg", IIC_FFREE>, DD;
Sean Callanan108934c2009-12-18 00:01:26 +0000589
590// Clear exceptions
591
Benjamin Kramer17c836c2012-04-27 12:07:43 +0000592let Defs = [FPSW] in
Preston Gurd95f0cf02012-05-02 16:03:35 +0000593def FNCLEX : I<0xE2, RawFrm, (outs), (ins), "fnclex", [], IIC_FNCLEX>, DB;
Sean Callanan108934c2009-12-18 00:01:26 +0000594
Chris Lattner434c7cb2010-10-05 05:32:15 +0000595// Operandless floating-point instructions for the disassembler.
Preston Gurd95f0cf02012-05-02 16:03:35 +0000596def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", [], IIC_WAIT>;
Sean Callanan108934c2009-12-18 00:01:26 +0000597
Preston Gurd95f0cf02012-05-02 16:03:35 +0000598def FNOP : I<0xD0, RawFrm, (outs), (ins), "fnop", [], IIC_FNOP>, D9;
599def FXAM : I<0xE5, RawFrm, (outs), (ins), "fxam", [], IIC_FXAM>, D9;
600def FLDL2T : I<0xE9, RawFrm, (outs), (ins), "fldl2t", [], IIC_FLDL>, D9;
601def FLDL2E : I<0xEA, RawFrm, (outs), (ins), "fldl2e", [], IIC_FLDL>, D9;
602def FLDPI : I<0xEB, RawFrm, (outs), (ins), "fldpi", [], IIC_FLDL>, D9;
603def FLDLG2 : I<0xEC, RawFrm, (outs), (ins), "fldlg2", [], IIC_FLDL>, D9;
604def FLDLN2 : I<0xED, RawFrm, (outs), (ins), "fldln2", [], IIC_FLDL>, D9;
605def F2XM1 : I<0xF0, RawFrm, (outs), (ins), "f2xm1", [], IIC_F2XM1>, D9;
606def FYL2X : I<0xF1, RawFrm, (outs), (ins), "fyl2x", [], IIC_FYL2X>, D9;
607def FPTAN : I<0xF2, RawFrm, (outs), (ins), "fptan", [], IIC_FPTAN>, D9;
608def FPATAN : I<0xF3, RawFrm, (outs), (ins), "fpatan", [], IIC_FPATAN>, D9;
609def FXTRACT : I<0xF4, RawFrm, (outs), (ins), "fxtract", [], IIC_FXTRACT>, D9;
610def FPREM1 : I<0xF5, RawFrm, (outs), (ins), "fprem1", [], IIC_FPREM1>, D9;
611def FDECSTP : I<0xF6, RawFrm, (outs), (ins), "fdecstp", [], IIC_FPSTP>, D9;
612def FINCSTP : I<0xF7, RawFrm, (outs), (ins), "fincstp", [], IIC_FPSTP>, D9;
613def FPREM : I<0xF8, RawFrm, (outs), (ins), "fprem", [], IIC_FPREM>, D9;
614def FYL2XP1 : I<0xF9, RawFrm, (outs), (ins), "fyl2xp1", [], IIC_FYL2XP1>, D9;
615def FSINCOS : I<0xFB, RawFrm, (outs), (ins), "fsincos", [], IIC_FSINCOS>, D9;
616def FRNDINT : I<0xFC, RawFrm, (outs), (ins), "frndint", [], IIC_FRNDINT>, D9;
617def FSCALE : I<0xFD, RawFrm, (outs), (ins), "fscale", [], IIC_FSCALE>, D9;
618def FCOMPP : I<0xD9, RawFrm, (outs), (ins), "fcompp", [], IIC_FCOMPP>, DE;
Sean Callanan108934c2009-12-18 00:01:26 +0000619
620def FXSAVE : I<0xAE, MRM0m, (outs opaque512mem:$dst), (ins),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000621 "fxsave\t$dst", [], IIC_FXSAVE>, TB;
Reid Kleckner26f23102011-02-12 23:24:13 +0000622def FXSAVE64 : I<0xAE, MRM0m, (outs opaque512mem:$dst), (ins),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000623 "fxsaveq\t$dst", [], IIC_FXSAVE>, TB, REX_W,
624 Requires<[In64BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000625def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaque512mem:$src),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000626 "fxrstor\t$src", [], IIC_FXRSTOR>, TB;
Reid Kleckner26f23102011-02-12 23:24:13 +0000627def FXRSTOR64 : I<0xAE, MRM1m, (outs), (ins opaque512mem:$src),
Preston Gurd95f0cf02012-05-02 16:03:35 +0000628 "fxrstorq\t$src", [], IIC_FXRSTOR>, TB, REX_W,
629 Requires<[In64BitMode]>;
Sean Callanan108934c2009-12-18 00:01:26 +0000630
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000631//===----------------------------------------------------------------------===//
632// Non-Instruction Patterns
633//===----------------------------------------------------------------------===//
634
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000635// Required for RET of f32 / f64 / f80 values.
Dale Johannesene377d4d2007-07-04 21:07:47 +0000636def : Pat<(X86fld addr:$src, f32), (LD_Fp32m addr:$src)>;
637def : Pat<(X86fld addr:$src, f64), (LD_Fp64m addr:$src)>;
Dale Johannesen59a58732007-08-05 18:49:15 +0000638def : Pat<(X86fld addr:$src, f80), (LD_Fp80m addr:$src)>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000639
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000640// Required for CALL which return f32 / f64 / f80 values.
Dale Johannesene377d4d2007-07-04 21:07:47 +0000641def : Pat<(X86fst RFP32:$src, addr:$op, f32), (ST_Fp32m addr:$op, RFP32:$src)>;
Sean Callanan108934c2009-12-18 00:01:26 +0000642def : Pat<(X86fst RFP64:$src, addr:$op, f32), (ST_Fp64m32 addr:$op,
643 RFP64:$src)>;
Dale Johannesene377d4d2007-07-04 21:07:47 +0000644def : Pat<(X86fst RFP64:$src, addr:$op, f64), (ST_Fp64m addr:$op, RFP64:$src)>;
Sean Callanan108934c2009-12-18 00:01:26 +0000645def : Pat<(X86fst RFP80:$src, addr:$op, f32), (ST_Fp80m32 addr:$op,
646 RFP80:$src)>;
647def : Pat<(X86fst RFP80:$src, addr:$op, f64), (ST_Fp80m64 addr:$op,
648 RFP80:$src)>;
649def : Pat<(X86fst RFP80:$src, addr:$op, f80), (ST_FpP80m addr:$op,
650 RFP80:$src)>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000651
652// Floating point constant -0.0 and -1.0
Dale Johannesenf1fc3a82007-09-23 14:52:20 +0000653def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
654def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
655def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
656def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
Dale Johannesencdbe4d32007-08-07 20:29:26 +0000657def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
658def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
Evan Cheng4e4c71e2006-02-21 20:00:20 +0000659
660// Used to conv. i64 to f64 since there isn't a SSE version.
Dale Johannesene377d4d2007-07-04 21:07:47 +0000661def : Pat<(X86fildflag addr:$src, i64), (ILD_Fp64m64 addr:$src)>;
Dale Johannesen849f2142007-07-03 00:53:03 +0000662
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000663// FP extensions map onto simple pseudo-value conversions if they are to/from
664// the FP stack.
Jakob Stoklund Olesena66450d2010-07-11 18:19:39 +0000665def : Pat<(f64 (fextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000666 Requires<[FPStackf32]>;
Jakob Stoklund Olesena66450d2010-07-11 18:19:39 +0000667def : Pat<(f80 (fextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000668 Requires<[FPStackf32]>;
Jakob Stoklund Olesena66450d2010-07-11 18:19:39 +0000669def : Pat<(f80 (fextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000670 Requires<[FPStackf64]>;
671
672// FP truncations map onto simple pseudo-value conversions if they are to/from
673// the FP stack. We have validated that only value-preserving truncations make
674// it through isel.
Jakob Stoklund Olesena66450d2010-07-11 18:19:39 +0000675def : Pat<(f32 (fround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000676 Requires<[FPStackf32]>;
Jakob Stoklund Olesena66450d2010-07-11 18:19:39 +0000677def : Pat<(f32 (fround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000678 Requires<[FPStackf32]>;
Jakob Stoklund Olesena66450d2010-07-11 18:19:39 +0000679def : Pat<(f64 (fround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
Chris Lattner6fa2f9c2008-03-09 07:05:32 +0000680 Requires<[FPStackf64]>;