blob: d4798f2f659b49b867ab0712fa1ce90e0e4c159c [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//==- X86InstrFPStack.td - Describe the X86 Instruction Set -------*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the Evan Cheng and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
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
16//===----------------------------------------------------------------------===//
17// FPStack specific DAG Nodes.
18//===----------------------------------------------------------------------===//
19
20def SDTX86FpGet : SDTypeProfile<1, 0, [SDTCisFP<0>]>;
21def SDTX86FpSet : SDTypeProfile<0, 1, [SDTCisFP<0>]>;
22def SDTX86Fld : SDTypeProfile<1, 2, [SDTCisFP<0>,
23 SDTCisPtrTy<1>,
24 SDTCisVT<2, OtherVT>]>;
25def SDTX86Fst : SDTypeProfile<0, 3, [SDTCisFP<0>,
26 SDTCisPtrTy<1>,
27 SDTCisVT<2, OtherVT>]>;
28def SDTX86Fild : SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisPtrTy<1>,
29 SDTCisVT<2, OtherVT>]>;
30def SDTX86FpToIMem : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
31
32def X86fpget : SDNode<"X86ISD::FP_GET_RESULT", SDTX86FpGet,
33 [SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
34def X86fpset : SDNode<"X86ISD::FP_SET_RESULT", SDTX86FpSet,
35 [SDNPHasChain, SDNPOutFlag]>;
36def X86fld : SDNode<"X86ISD::FLD", SDTX86Fld,
37 [SDNPHasChain]>;
38def X86fst : SDNode<"X86ISD::FST", SDTX86Fst,
39 [SDNPHasChain, SDNPInFlag]>;
40def X86fild : SDNode<"X86ISD::FILD", SDTX86Fild,
41 [SDNPHasChain]>;
42def X86fildflag : SDNode<"X86ISD::FILD_FLAG",SDTX86Fild,
43 [SDNPHasChain, SDNPOutFlag]>;
44def X86fp_to_i16mem : SDNode<"X86ISD::FP_TO_INT16_IN_MEM", SDTX86FpToIMem,
45 [SDNPHasChain]>;
46def X86fp_to_i32mem : SDNode<"X86ISD::FP_TO_INT32_IN_MEM", SDTX86FpToIMem,
47 [SDNPHasChain]>;
48def X86fp_to_i64mem : SDNode<"X86ISD::FP_TO_INT64_IN_MEM", SDTX86FpToIMem,
49 [SDNPHasChain]>;
50
51//===----------------------------------------------------------------------===//
52// FPStack pattern fragments
53//===----------------------------------------------------------------------===//
54
55def fpimm0 : PatLeaf<(fpimm), [{
56 return N->isExactlyValue(+0.0);
57}]>;
58
59def fpimmneg0 : PatLeaf<(fpimm), [{
60 return N->isExactlyValue(-0.0);
61}]>;
62
63def fpimm1 : PatLeaf<(fpimm), [{
64 return N->isExactlyValue(+1.0);
65}]>;
66
67def fpimmneg1 : PatLeaf<(fpimm), [{
68 return N->isExactlyValue(-1.0);
69}]>;
70
71// Some 'special' instructions
72let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
73 def FP32_TO_INT16_IN_MEM : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +000074 (outs), (ins i16mem:$dst, RFP32:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075 "#FP32_TO_INT16_IN_MEM PSEUDO!",
76 [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
77 def FP32_TO_INT32_IN_MEM : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +000078 (outs), (ins i32mem:$dst, RFP32:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079 "#FP32_TO_INT32_IN_MEM PSEUDO!",
80 [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
81 def FP32_TO_INT64_IN_MEM : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +000082 (outs), (ins i64mem:$dst, RFP32:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000083 "#FP32_TO_INT64_IN_MEM PSEUDO!",
84 [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
85 def FP64_TO_INT16_IN_MEM : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +000086 (outs), (ins i16mem:$dst, RFP64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087 "#FP64_TO_INT16_IN_MEM PSEUDO!",
88 [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
89 def FP64_TO_INT32_IN_MEM : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +000090 (outs), (ins i32mem:$dst, RFP64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091 "#FP64_TO_INT32_IN_MEM PSEUDO!",
92 [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
93 def FP64_TO_INT64_IN_MEM : I<0, Pseudo,
Evan Chengb783fa32007-07-19 01:14:50 +000094 (outs), (ins i64mem:$dst, RFP64:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095 "#FP64_TO_INT64_IN_MEM PSEUDO!",
96 [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
97}
98
99let isTerminator = 1 in
100 let Defs = [FP0, FP1, FP2, FP3, FP4, FP5, FP6] in
Evan Chengb783fa32007-07-19 01:14:50 +0000101 def FP_REG_KILL : I<0, Pseudo, (outs), (ins), "#FP_REG_KILL", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000102
103// All FP Stack operations are represented with three instructions here. The
104// first two instructions, generated by the instruction selector, uses "RFP32"
105// or "RFP64" registers: traditional register files to reference 32-bit or
106// 64-bit floating point values. These sizes apply to the values, not the
107// registers, which are always 64 bits; RFP32 and RFP64 can be copied to
108// each other without losing information. These instructions are all psuedo
109// instructions and use the "_Fp" suffix.
110// In some cases there are additional variants with a mixture of 32-bit and
111// 64-bit registers.
112// The second instruction is defined with FPI, which is the actual instruction
113// emitted by the assembler. These use "RST" registers, although frequently
114// the actual register(s) used are implicit. These are always 64-bits.
115// The FP stackifier pass converts one to the other after register allocation
116// occurs.
117//
118// Note that the FpI instruction should have instruction selection info (e.g.
119// a pattern) and the FPI instruction should have emission info (e.g. opcode
120// encoding and asm printing info).
121
122// FPI - Floating Point Instruction template.
Evan Chengb783fa32007-07-19 01:14:50 +0000123class FPI<bits<8> o, Format F, dag outs, dag ins, string asm>
124 : I<o, F, outs, ins, asm, []> {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000125
126// FpI_ - Floating Point Psuedo Instruction template. Not Predicated.
Evan Chengb783fa32007-07-19 01:14:50 +0000127class FpI_<dag outs, dag ins, FPFormat fp, list<dag> pattern>
128 : X86Inst<0, Pseudo, NoImm, outs, ins, ""> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000129 let FPForm = fp; let FPFormBits = FPForm.Value;
130 let Pattern = pattern;
131}
132
133// Random Pseudo Instructions.
Evan Chengb783fa32007-07-19 01:14:50 +0000134def FpGETRESULT32 : FpI_<(outs RFP32:$dst), (ins), SpecialFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000135 [(set RFP32:$dst, X86fpget)]>; // FPR = ST(0)
136
Evan Chengb783fa32007-07-19 01:14:50 +0000137def FpGETRESULT64 : FpI_<(outs RFP64:$dst), (ins), SpecialFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000138 [(set RFP64:$dst, X86fpget)]>; // FPR = ST(0)
139
Evan Cheng37e7c752007-07-21 00:34:19 +0000140def FpSETRESULT32 : FpI_<(outs), (ins RFP32:$src), SpecialFP,
141 [(X86fpset RFP32:$src)]>, Imp<[], [ST0]>;// ST(0) = FPR
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142
Evan Cheng37e7c752007-07-21 00:34:19 +0000143def FpSETRESULT64 : FpI_<(outs), (ins RFP64:$src), SpecialFP,
144 [(X86fpset RFP64:$src)]>, Imp<[], [ST0]>;// ST(0) = FPR
145
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000146// FpI - Floating Point Psuedo Instruction template. Predicated on FPStack.
Evan Chengb783fa32007-07-19 01:14:50 +0000147class FpI<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
148 FpI_<outs, ins, fp, pattern>, Requires<[FPStack]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000149
150// Register copies. Just copies, the 64->32 version does not truncate.
Evan Chengb783fa32007-07-19 01:14:50 +0000151def MOV_Fp3232 : FpI<(outs RFP32:$dst), (ins RFP32:$src), SpecialFP, []>;
152def MOV_Fp3264 : FpI<(outs RFP64:$dst), (ins RFP32:$src), SpecialFP, []>;
153def MOV_Fp6432 : FpI<(outs RFP32:$dst), (ins RFP64:$src), SpecialFP, []>;
154def MOV_Fp6464 : FpI<(outs RFP64:$dst), (ins RFP64:$src), SpecialFP, []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155
156// Factoring for arithmetic.
157multiclass FPBinary_rr<SDNode OpNode> {
158// Register op register -> register
159// These are separated out because they have no reversed form.
Evan Chengb783fa32007-07-19 01:14:50 +0000160def _Fp32 : FpI<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161 [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000162def _Fp64 : FpI<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163 [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
164}
165// The FopST0 series are not included here because of the irregularities
166// in where the 'r' goes in assembly output.
167multiclass FPBinary<SDNode OpNode, Format fp, string asmstring> {
168// ST(0) = ST(0) + [mem]
Evan Chengb783fa32007-07-19 01:14:50 +0000169def _Fp32m : FpI<(outs RFP32:$dst), (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170 [(set RFP32:$dst,
171 (OpNode RFP32:$src1, (loadf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000172def _Fp64m : FpI<(outs RFP64:$dst), (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173 [(set RFP64:$dst,
174 (OpNode RFP64:$src1, (loadf64 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000175def _Fp64m32: FpI<(outs RFP64:$dst), (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176 [(set RFP64:$dst,
177 (OpNode RFP64:$src1, (extloadf32 addr:$src2)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000178def _F32m : FPI<0xD8, fp, (outs), (ins f32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179 !strconcat("f", !strconcat(asmstring, "{s} $src"))>;
Evan Chengb783fa32007-07-19 01:14:50 +0000180def _F64m : FPI<0xDC, fp, (outs), (ins f64mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181 !strconcat("f", !strconcat(asmstring, "{l} $src"))>;
182// ST(0) = ST(0) + [memint]
Evan Chengb783fa32007-07-19 01:14:50 +0000183def _FpI16m32 : FpI<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 [(set RFP32:$dst, (OpNode RFP32:$src1,
185 (X86fild addr:$src2, i16)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000186def _FpI32m32 : FpI<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187 [(set RFP32:$dst, (OpNode RFP32:$src1,
188 (X86fild addr:$src2, i32)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000189def _FpI16m64 : FpI<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000190 [(set RFP64:$dst, (OpNode RFP64:$src1,
191 (X86fild addr:$src2, i16)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000192def _FpI32m64 : FpI<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000193 [(set RFP64:$dst, (OpNode RFP64:$src1,
194 (X86fild addr:$src2, i32)))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000195def _FI16m : FPI<0xDE, fp, (outs), (ins i16mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196 !strconcat("fi", !strconcat(asmstring, "{s} $src"))>;
Evan Chengb783fa32007-07-19 01:14:50 +0000197def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198 !strconcat("fi", !strconcat(asmstring, "{l} $src"))>;
199}
200
201defm ADD : FPBinary_rr<fadd>;
202defm SUB : FPBinary_rr<fsub>;
203defm MUL : FPBinary_rr<fmul>;
204defm DIV : FPBinary_rr<fdiv>;
205defm ADD : FPBinary<fadd, MRM0m, "add">;
206defm SUB : FPBinary<fsub, MRM4m, "sub">;
207defm SUBR: FPBinary<fsub ,MRM5m, "subr">;
208defm MUL : FPBinary<fmul, MRM1m, "mul">;
209defm DIV : FPBinary<fdiv, MRM6m, "div">;
210defm DIVR: FPBinary<fdiv, MRM7m, "divr">;
211
212class FPST0rInst<bits<8> o, string asm>
Evan Chengb783fa32007-07-19 01:14:50 +0000213 : FPI<o, AddRegFrm, (outs), (ins RST:$op), asm>, D8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214class FPrST0Inst<bits<8> o, string asm>
Evan Chengb783fa32007-07-19 01:14:50 +0000215 : FPI<o, AddRegFrm, (outs), (ins RST:$op), asm>, DC;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216class FPrST0PInst<bits<8> o, string asm>
Evan Chengb783fa32007-07-19 01:14:50 +0000217 : FPI<o, AddRegFrm, (outs), (ins RST:$op), asm>, DE;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218
219// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
220// of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
221// we have to put some 'r's in and take them out of weird places.
222def ADD_FST0r : FPST0rInst <0xC0, "fadd $op">;
223def ADD_FrST0 : FPrST0Inst <0xC0, "fadd {%st(0), $op|$op, %ST(0)}">;
224def ADD_FPrST0 : FPrST0PInst<0xC0, "faddp $op">;
225def SUBR_FST0r : FPST0rInst <0xE8, "fsubr $op">;
226def SUB_FrST0 : FPrST0Inst <0xE8, "fsub{r} {%st(0), $op|$op, %ST(0)}">;
227def SUB_FPrST0 : FPrST0PInst<0xE8, "fsub{r}p $op">;
228def SUB_FST0r : FPST0rInst <0xE0, "fsub $op">;
229def SUBR_FrST0 : FPrST0Inst <0xE0, "fsub{|r} {%st(0), $op|$op, %ST(0)}">;
230def SUBR_FPrST0 : FPrST0PInst<0xE0, "fsub{|r}p $op">;
231def MUL_FST0r : FPST0rInst <0xC8, "fmul $op">;
232def MUL_FrST0 : FPrST0Inst <0xC8, "fmul {%st(0), $op|$op, %ST(0)}">;
233def MUL_FPrST0 : FPrST0PInst<0xC8, "fmulp $op">;
234def DIVR_FST0r : FPST0rInst <0xF8, "fdivr $op">;
235def DIV_FrST0 : FPrST0Inst <0xF8, "fdiv{r} {%st(0), $op|$op, %ST(0)}">;
236def DIV_FPrST0 : FPrST0PInst<0xF8, "fdiv{r}p $op">;
237def DIV_FST0r : FPST0rInst <0xF0, "fdiv $op">;
238def DIVR_FrST0 : FPrST0Inst <0xF0, "fdiv{|r} {%st(0), $op|$op, %ST(0)}">;
239def DIVR_FPrST0 : FPrST0PInst<0xF0, "fdiv{|r}p $op">;
240
241// Unary operations.
242multiclass FPUnary<SDNode OpNode, bits<8> opcode, string asmstring> {
Evan Chengb783fa32007-07-19 01:14:50 +0000243def _Fp32 : FpI<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244 [(set RFP32:$dst, (OpNode RFP32:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000245def _Fp64 : FpI<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000246 [(set RFP64:$dst, (OpNode RFP64:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000247def _F : FPI<opcode, RawFrm, (outs), (ins), asmstring>, D9;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248}
249
250defm CHS : FPUnary<fneg, 0xE0, "fchs">;
251defm ABS : FPUnary<fabs, 0xE1, "fabs">;
252defm SQRT: FPUnary<fsqrt,0xFA, "fsqrt">;
253defm SIN : FPUnary<fsin, 0xFE, "fsin">;
254defm COS : FPUnary<fcos, 0xFF, "fcos">;
255
Evan Chengb783fa32007-07-19 01:14:50 +0000256def TST_Fp32 : FpI<(outs), (ins RFP32:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000257 []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000258def TST_Fp64 : FpI<(outs), (ins RFP64:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 []>;
Evan Chengb783fa32007-07-19 01:14:50 +0000260def TST_F : FPI<0xE4, RawFrm, (outs), (ins), "ftst">, D9;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261
262// Floating point cmovs.
263multiclass FPCMov<PatLeaf cc> {
Evan Chengb783fa32007-07-19 01:14:50 +0000264 def _Fp32 : FpI<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), CondMovFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000265 [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
266 cc))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000267 def _Fp64 : FpI<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), CondMovFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268 [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
269 cc))]>;
270}
271let isTwoAddress = 1 in {
272defm CMOVB : FPCMov<X86_COND_B>;
273defm CMOVBE : FPCMov<X86_COND_BE>;
274defm CMOVE : FPCMov<X86_COND_E>;
275defm CMOVP : FPCMov<X86_COND_P>;
276defm CMOVNB : FPCMov<X86_COND_AE>;
277defm CMOVNBE: FPCMov<X86_COND_A>;
278defm CMOVNE : FPCMov<X86_COND_NE>;
279defm CMOVNP : FPCMov<X86_COND_NP>;
280}
281
282// These are not factored because there's no clean way to pass DA/DB.
Evan Chengb783fa32007-07-19 01:14:50 +0000283def CMOVB_F : FPI<0xC0, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 "fcmovb {$op, %st(0)|%ST(0), $op}">, DA;
Evan Chengb783fa32007-07-19 01:14:50 +0000285def CMOVBE_F : FPI<0xD0, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286 "fcmovbe {$op, %st(0)|%ST(0), $op}">, DA;
Evan Chengb783fa32007-07-19 01:14:50 +0000287def CMOVE_F : FPI<0xC8, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 "fcmove {$op, %st(0)|%ST(0), $op}">, DA;
Evan Chengb783fa32007-07-19 01:14:50 +0000289def CMOVP_F : FPI<0xD8, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000290 "fcmovu {$op, %st(0)|%ST(0), $op}">, DA;
Evan Chengb783fa32007-07-19 01:14:50 +0000291def CMOVNB_F : FPI<0xC0, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 "fcmovnb {$op, %st(0)|%ST(0), $op}">, DB;
Evan Chengb783fa32007-07-19 01:14:50 +0000293def CMOVNBE_F: FPI<0xD0, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000294 "fcmovnbe {$op, %st(0)|%ST(0), $op}">, DB;
Evan Chengb783fa32007-07-19 01:14:50 +0000295def CMOVNE_F : FPI<0xC8, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296 "fcmovne {$op, %st(0)|%ST(0), $op}">, DB;
Evan Chengb783fa32007-07-19 01:14:50 +0000297def CMOVNP_F : FPI<0xD8, AddRegFrm, (outs RST:$op), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298 "fcmovnu {$op, %st(0)|%ST(0), $op}">, DB;
299
300// Floating point loads & stores.
Evan Chengb783fa32007-07-19 01:14:50 +0000301def LD_Fp32m : FpI<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000302 [(set RFP32:$dst, (loadf32 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000303def LD_Fp64m : FpI<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000304 [(set RFP64:$dst, (loadf64 addr:$src))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000305def ILD_Fp16m32: FpI<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 [(set RFP32:$dst, (X86fild addr:$src, i16))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000307def ILD_Fp32m32: FpI<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308 [(set RFP32:$dst, (X86fild addr:$src, i32))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000309def ILD_Fp64m32: FpI<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000310 [(set RFP32:$dst, (X86fild addr:$src, i64))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000311def ILD_Fp16m64: FpI<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312 [(set RFP64:$dst, (X86fild addr:$src, i16))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000313def ILD_Fp32m64: FpI<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314 [(set RFP64:$dst, (X86fild addr:$src, i32))]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000315def ILD_Fp64m64: FpI<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316 [(set RFP64:$dst, (X86fild addr:$src, i64))]>;
317
Evan Chengb783fa32007-07-19 01:14:50 +0000318def ST_Fp32m : FpI<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000319 [(store RFP32:$src, addr:$op)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000320def ST_Fp64m32 : FpI<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000321 [(truncstoref32 RFP64:$src, addr:$op)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000322def ST_Fp64m : FpI<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323 [(store RFP64:$src, addr:$op)]>;
324
Evan Chengb783fa32007-07-19 01:14:50 +0000325def ST_FpP32m : FpI<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
326def ST_FpP64m32 : FpI<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
327def ST_FpP64m : FpI<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
328def IST_Fp16m32 : FpI<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
329def IST_Fp32m32 : FpI<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP, []>;
330def IST_Fp64m32 : FpI<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP, []>;
331def IST_Fp16m64 : FpI<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
332def IST_Fp32m64 : FpI<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP, []>;
333def IST_Fp64m64 : FpI<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP, []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334
Evan Chengb783fa32007-07-19 01:14:50 +0000335def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s} $src">;
336def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l} $src">;
337def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s} $src">;
338def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l} $src">;
339def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll} $src">;
340def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s} $dst">;
341def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l} $dst">;
342def ST_FP32m : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s} $dst">;
343def ST_FP64m : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l} $dst">;
344def IST_F16m : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s} $dst">;
345def IST_F32m : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l} $dst">;
346def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s} $dst">;
347def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l} $dst">;
348def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll} $dst">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349
350// FISTTP requires SSE3 even though it's a FPStack op.
Evan Chengb783fa32007-07-19 01:14:50 +0000351def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 [(X86fp_to_i16mem RFP32:$src, addr:$op)]>,
353 Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000354def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000355 [(X86fp_to_i32mem RFP32:$src, addr:$op)]>,
356 Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000357def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000358 [(X86fp_to_i64mem RFP32:$src, addr:$op)]>,
359 Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000360def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361 [(X86fp_to_i16mem RFP64:$src, addr:$op)]>,
362 Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000363def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364 [(X86fp_to_i32mem RFP64:$src, addr:$op)]>,
365 Requires<[HasSSE3]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000366def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000367 [(X86fp_to_i64mem RFP64:$src, addr:$op)]>,
368 Requires<[HasSSE3]>;
369
Evan Chengb783fa32007-07-19 01:14:50 +0000370def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s} $dst">;
371def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l} $dst">;
372def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll} $dst">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373
374// FP Stack manipulation instructions.
Evan Chengb783fa32007-07-19 01:14:50 +0000375def LD_Frr : FPI<0xC0, AddRegFrm, (outs), (ins RST:$op), "fld $op">, D9;
376def ST_Frr : FPI<0xD0, AddRegFrm, (outs), (ins RST:$op), "fst $op">, DD;
377def ST_FPrr : FPI<0xD8, AddRegFrm, (outs), (ins RST:$op), "fstp $op">, DD;
378def XCH_F : FPI<0xC8, AddRegFrm, (outs), (ins RST:$op), "fxch $op">, D9;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379
380// Floating point constant loads.
381let isReMaterializable = 1 in {
Evan Chengb783fa32007-07-19 01:14:50 +0000382def LD_Fp032 : FpI<(outs RFP32:$dst), (ins), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000383 [(set RFP32:$dst, fpimm0)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000384def LD_Fp132 : FpI<(outs RFP32:$dst), (ins), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000385 [(set RFP32:$dst, fpimm1)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000386def LD_Fp064 : FpI<(outs RFP64:$dst), (ins), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387 [(set RFP64:$dst, fpimm0)]>;
Evan Chengb783fa32007-07-19 01:14:50 +0000388def LD_Fp164 : FpI<(outs RFP64:$dst), (ins), ZeroArgFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389 [(set RFP64:$dst, fpimm1)]>;
390}
391
Evan Chengb783fa32007-07-19 01:14:50 +0000392def LD_F0 : FPI<0xEE, RawFrm, (outs), (ins), "fldz">, D9;
393def LD_F1 : FPI<0xE8, RawFrm, (outs), (ins), "fld1">, D9;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394
395
396// Floating point compares.
Evan Chengb783fa32007-07-19 01:14:50 +0000397def UCOM_Fpr32 : FpI<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398 []>; // FPSW = cmp ST(0) with ST(i)
Evan Chengb783fa32007-07-19 01:14:50 +0000399def UCOM_FpIr32: FpI<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400 [(X86cmp RFP32:$lhs, RFP32:$rhs)]>; // CC = ST(0) cmp ST(i)
Evan Chengb783fa32007-07-19 01:14:50 +0000401def UCOM_Fpr64 : FpI<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000402 []>; // FPSW = cmp ST(0) with ST(i)
Evan Chengb783fa32007-07-19 01:14:50 +0000403def UCOM_FpIr64: FpI<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404 [(X86cmp RFP64:$lhs, RFP64:$rhs)]>; // CC = ST(0) cmp ST(i)
405
406def UCOM_Fr : FPI<0xE0, AddRegFrm, // FPSW = cmp ST(0) with ST(i)
Evan Chengb783fa32007-07-19 01:14:50 +0000407 (outs), (ins RST:$reg),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408 "fucom $reg">, DD, Imp<[ST0],[]>;
409def UCOM_FPr : FPI<0xE8, AddRegFrm, // FPSW = cmp ST(0) with ST(i), pop
Evan Chengb783fa32007-07-19 01:14:50 +0000410 (outs), (ins RST:$reg),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411 "fucomp $reg">, DD, Imp<[ST0],[]>;
412def UCOM_FPPr : FPI<0xE9, RawFrm, // cmp ST(0) with ST(1), pop, pop
Evan Chengb783fa32007-07-19 01:14:50 +0000413 (outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000414 "fucompp">, DA, Imp<[ST0],[]>;
415
416def UCOM_FIr : FPI<0xE8, AddRegFrm, // CC = cmp ST(0) with ST(i)
Evan Chengb783fa32007-07-19 01:14:50 +0000417 (outs), (ins RST:$reg),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418 "fucomi {$reg, %st(0)|%ST(0), $reg}">, DB, Imp<[ST0],[]>;
419def UCOM_FIPr : FPI<0xE8, AddRegFrm, // CC = cmp ST(0) with ST(i), pop
Evan Chengb783fa32007-07-19 01:14:50 +0000420 (outs), (ins RST:$reg),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421 "fucomip {$reg, %st(0)|%ST(0), $reg}">, DF, Imp<[ST0],[]>;
422
423// Floating point flag ops.
424def FNSTSW8r : I<0xE0, RawFrm, // AX = fp flags
Evan Chengb783fa32007-07-19 01:14:50 +0000425 (outs), (ins), "fnstsw", []>, DF, Imp<[],[AX]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426
427def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
Evan Chengb783fa32007-07-19 01:14:50 +0000428 (outs), (ins i16mem:$dst), "fnstcw $dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
Evan Chengb783fa32007-07-19 01:14:50 +0000430 (outs), (ins i16mem:$dst), "fldcw $dst", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431
432//===----------------------------------------------------------------------===//
433// Non-Instruction Patterns
434//===----------------------------------------------------------------------===//
435
436// Required for RET of f32 / f64 values.
437def : Pat<(X86fld addr:$src, f32), (LD_Fp32m addr:$src)>;
438def : Pat<(X86fld addr:$src, f64), (LD_Fp64m addr:$src)>;
439
440// Required for CALL which return f32 / f64 values.
441def : Pat<(X86fst RFP32:$src, addr:$op, f32), (ST_Fp32m addr:$op, RFP32:$src)>;
442def : Pat<(X86fst RFP64:$src, addr:$op, f32), (ST_Fp64m32 addr:$op, RFP64:$src)>;
443def : Pat<(X86fst RFP64:$src, addr:$op, f64), (ST_Fp64m addr:$op, RFP64:$src)>;
444
445// Floating point constant -0.0 and -1.0
446def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStack]>;
447def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStack]>;
448def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStack]>;
449def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStack]>;
450
451// Used to conv. i64 to f64 since there isn't a SSE version.
452def : Pat<(X86fildflag addr:$src, i64), (ILD_Fp64m64 addr:$src)>;
453
454def : Pat<(extloadf32 addr:$src),
455 (MOV_Fp3264 (LD_Fp32m addr:$src))>, Requires<[FPStack]>;
456def : Pat<(fextend RFP32:$src), (MOV_Fp3264 RFP32:$src)>, Requires<[FPStack]>;