xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86InstrFPStack.td (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
10b57cec5SDimitry Andric//===- X86InstrFPStack.td - FPU Instruction Set ------------*- tablegen -*-===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric//
90b57cec5SDimitry Andric// This file describes the X86 x87 FPU instruction set, defining the
100b57cec5SDimitry Andric// instructions, and properties of the instructions which are needed for code
110b57cec5SDimitry Andric// generation, machine code emission, and analysis.
120b57cec5SDimitry Andric//
130b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric
150b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
160b57cec5SDimitry Andric// FPStack specific DAG Nodes.
170b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
180b57cec5SDimitry Andric
190b57cec5SDimitry Andricdef SDTX86Fld       : SDTypeProfile<1, 1, [SDTCisFP<0>,
200b57cec5SDimitry Andric                                           SDTCisPtrTy<1>]>;
210b57cec5SDimitry Andricdef SDTX86Fst       : SDTypeProfile<0, 2, [SDTCisFP<0>,
220b57cec5SDimitry Andric                                           SDTCisPtrTy<1>]>;
230b57cec5SDimitry Andricdef SDTX86Fild      : SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
240b57cec5SDimitry Andricdef SDTX86Fist      : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
250b57cec5SDimitry Andric
260b57cec5SDimitry Andricdef SDTX86CwdStore  : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
27fe6060f1SDimitry Andricdef SDTX86CwdLoad   : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
28*06c3fb27SDimitry Andricdef SDTX86FPEnv     : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
290b57cec5SDimitry Andric
301ac55f4cSDimitry Andricdef X86fp80_add     : SDNode<"X86ISD::FP80_ADD", SDTFPBinOp, [SDNPCommutative]>;
311ac55f4cSDimitry Andricdef X86strict_fp80_add : SDNode<"X86ISD::STRICT_FP80_ADD", SDTFPBinOp,
321ac55f4cSDimitry Andric                        [SDNPHasChain,SDNPCommutative]>;
331ac55f4cSDimitry Andricdef any_X86fp80_add : PatFrags<(ops node:$lhs, node:$rhs),
341ac55f4cSDimitry Andric                               [(X86strict_fp80_add node:$lhs, node:$rhs),
351ac55f4cSDimitry Andric                                (X86fp80_add node:$lhs, node:$rhs)]>;
361ac55f4cSDimitry Andric
370b57cec5SDimitry Andricdef X86fld          : SDNode<"X86ISD::FLD", SDTX86Fld,
380b57cec5SDimitry Andric                             [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
390b57cec5SDimitry Andricdef X86fst          : SDNode<"X86ISD::FST", SDTX86Fst,
405ffd83dbSDimitry Andric                             [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
410b57cec5SDimitry Andricdef X86fild         : SDNode<"X86ISD::FILD", SDTX86Fild,
420b57cec5SDimitry Andric                             [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
430b57cec5SDimitry Andricdef X86fist         : SDNode<"X86ISD::FIST", SDTX86Fist,
445ffd83dbSDimitry Andric                             [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
450b57cec5SDimitry Andricdef X86fp_to_mem : SDNode<"X86ISD::FP_TO_INT_IN_MEM", SDTX86Fst,
460b57cec5SDimitry Andric                          [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
470b57cec5SDimitry Andricdef X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m",          SDTX86CwdStore,
480b57cec5SDimitry Andric                             [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
490b57cec5SDimitry Andric                              SDNPMemOperand]>;
50fe6060f1SDimitry Andricdef X86fp_cwd_set16 : SDNode<"X86ISD::FLDCW16m",           SDTX86CwdLoad,
51fe6060f1SDimitry Andric                             [SDNPHasChain, SDNPMayLoad, SDNPSideEffect,
52fe6060f1SDimitry Andric                              SDNPMemOperand]>;
53*06c3fb27SDimitry Andricdef X86fpenv_get    : SDNode<"X86ISD::FNSTENVm",           SDTX86FPEnv,
54*06c3fb27SDimitry Andric                             [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
55*06c3fb27SDimitry Andric                              SDNPMemOperand]>;
56*06c3fb27SDimitry Andricdef X86fpenv_set    : SDNode<"X86ISD::FLDENVm",            SDTX86FPEnv,
57*06c3fb27SDimitry Andric                             [SDNPHasChain, SDNPMayLoad, SDNPSideEffect,
58*06c3fb27SDimitry Andric                              SDNPMemOperand]>;
590b57cec5SDimitry Andric
600b57cec5SDimitry Andricdef X86fstf32 : PatFrag<(ops node:$val, node:$ptr),
610b57cec5SDimitry Andric                        (X86fst node:$val, node:$ptr), [{
620b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
630b57cec5SDimitry Andric}]>;
640b57cec5SDimitry Andricdef X86fstf64 : PatFrag<(ops node:$val, node:$ptr),
650b57cec5SDimitry Andric                        (X86fst node:$val, node:$ptr), [{
660b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
670b57cec5SDimitry Andric}]>;
680b57cec5SDimitry Andricdef X86fstf80 : PatFrag<(ops node:$val, node:$ptr),
690b57cec5SDimitry Andric                        (X86fst node:$val, node:$ptr), [{
700b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
710b57cec5SDimitry Andric}]>;
720b57cec5SDimitry Andric
730b57cec5SDimitry Andricdef X86fldf32 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
740b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
750b57cec5SDimitry Andric}]>;
760b57cec5SDimitry Andricdef X86fldf64 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
770b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
780b57cec5SDimitry Andric}]>;
790b57cec5SDimitry Andricdef X86fldf80 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
800b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
810b57cec5SDimitry Andric}]>;
820b57cec5SDimitry Andric
830b57cec5SDimitry Andricdef X86fild16 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
840b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
850b57cec5SDimitry Andric}]>;
860b57cec5SDimitry Andricdef X86fild32 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
870b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
880b57cec5SDimitry Andric}]>;
890b57cec5SDimitry Andricdef X86fild64 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
900b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
910b57cec5SDimitry Andric}]>;
920b57cec5SDimitry Andric
935ffd83dbSDimitry Andricdef X86fist32 : PatFrag<(ops node:$val, node:$ptr),
945ffd83dbSDimitry Andric                        (X86fist node:$val, node:$ptr), [{
955ffd83dbSDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
960b57cec5SDimitry Andric}]>;
970b57cec5SDimitry Andric
980b57cec5SDimitry Andricdef X86fist64 : PatFrag<(ops node:$val, node:$ptr),
990b57cec5SDimitry Andric                        (X86fist node:$val, node:$ptr), [{
1000b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
1010b57cec5SDimitry Andric}]>;
1020b57cec5SDimitry Andric
1030b57cec5SDimitry Andricdef X86fp_to_i16mem : PatFrag<(ops node:$val, node:$ptr),
1040b57cec5SDimitry Andric                              (X86fp_to_mem node:$val, node:$ptr), [{
1050b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
1060b57cec5SDimitry Andric}]>;
1070b57cec5SDimitry Andricdef X86fp_to_i32mem : PatFrag<(ops node:$val, node:$ptr),
1080b57cec5SDimitry Andric                              (X86fp_to_mem node:$val, node:$ptr), [{
1090b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
1100b57cec5SDimitry Andric}]>;
1110b57cec5SDimitry Andricdef X86fp_to_i64mem : PatFrag<(ops node:$val, node:$ptr),
1120b57cec5SDimitry Andric                              (X86fp_to_mem node:$val, node:$ptr), [{
1130b57cec5SDimitry Andric  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
1140b57cec5SDimitry Andric}]>;
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
1170b57cec5SDimitry Andric// FPStack pattern fragments
1180b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andricdef fpimm0 : FPImmLeaf<fAny, [{
1210b57cec5SDimitry Andric  return Imm.isExactlyValue(+0.0);
1220b57cec5SDimitry Andric}]>;
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andricdef fpimmneg0 : FPImmLeaf<fAny, [{
1250b57cec5SDimitry Andric  return Imm.isExactlyValue(-0.0);
1260b57cec5SDimitry Andric}]>;
1270b57cec5SDimitry Andric
1280b57cec5SDimitry Andricdef fpimm1 : FPImmLeaf<fAny, [{
1290b57cec5SDimitry Andric  return Imm.isExactlyValue(+1.0);
1300b57cec5SDimitry Andric}]>;
1310b57cec5SDimitry Andric
1320b57cec5SDimitry Andricdef fpimmneg1 : FPImmLeaf<fAny, [{
1330b57cec5SDimitry Andric  return Imm.isExactlyValue(-1.0);
1340b57cec5SDimitry Andric}]>;
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andric// Some 'special' instructions - expanded after instruction selection.
1370b57cec5SDimitry Andric// Clobbers EFLAGS due to OR instruction used internally.
1380b57cec5SDimitry Andric// FIXME: Can we model this in SelectionDAG?
1390b57cec5SDimitry Andriclet usesCustomInserter = 1, hasNoSchedulingInfo = 1, Defs = [EFLAGS] in {
1400b57cec5SDimitry Andric  def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
1410b57cec5SDimitry Andric                              [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
1420b57cec5SDimitry Andric  def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
1430b57cec5SDimitry Andric                              [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
1440b57cec5SDimitry Andric  def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
1450b57cec5SDimitry Andric                              [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
1460b57cec5SDimitry Andric  def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
1470b57cec5SDimitry Andric                              [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
1480b57cec5SDimitry Andric  def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
1490b57cec5SDimitry Andric                              [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
1500b57cec5SDimitry Andric  def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
1510b57cec5SDimitry Andric                              [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
1520b57cec5SDimitry Andric  def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
1530b57cec5SDimitry Andric                              [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
1540b57cec5SDimitry Andric  def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
1550b57cec5SDimitry Andric                              [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
1560b57cec5SDimitry Andric  def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
1570b57cec5SDimitry Andric                              [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
1581ac55f4cSDimitry Andric
1591ac55f4cSDimitry Andric  def FP80_ADDr : PseudoI<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
1601ac55f4cSDimitry Andric                          [(set RFP80:$dst,
1611ac55f4cSDimitry Andric                                (any_X86fp80_add  RFP80:$src1, RFP80:$src2))]>;
1621ac55f4cSDimitry Andric  def FP80_ADDm32 : PseudoI<(outs RFP80:$dst), (ins RFP80:$src1, f32mem:$src2),
1631ac55f4cSDimitry Andric                            [(set RFP80:$dst,
1641ac55f4cSDimitry Andric                                  (any_X86fp80_add RFP80:$src1,
1651ac55f4cSDimitry Andric                                                   (f80 (extloadf32 addr:$src2))))]>;
1660b57cec5SDimitry Andric}
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andric// All FP Stack operations are represented with four instructions here.  The
1690b57cec5SDimitry Andric// first three instructions, generated by the instruction selector, use "RFP32"
1700b57cec5SDimitry Andric// "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
1710b57cec5SDimitry Andric// 64-bit or 80-bit floating point values.  These sizes apply to the values,
1720b57cec5SDimitry Andric// not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
1730b57cec5SDimitry Andric// copied to each other without losing information.  These instructions are all
1740b57cec5SDimitry Andric// pseudo instructions and use the "_Fp" suffix.
1750b57cec5SDimitry Andric// In some cases there are additional variants with a mixture of different
1760b57cec5SDimitry Andric// register sizes.
1770b57cec5SDimitry Andric// The second instruction is defined with FPI, which is the actual instruction
1780b57cec5SDimitry Andric// emitted by the assembler.  These use "RST" registers, although frequently
1790b57cec5SDimitry Andric// the actual register(s) used are implicit.  These are always 80 bits.
1800b57cec5SDimitry Andric// The FP stackifier pass converts one to the other after register allocation
1810b57cec5SDimitry Andric// occurs.
1820b57cec5SDimitry Andric//
1830b57cec5SDimitry Andric// Note that the FpI instruction should have instruction selection info (e.g.
1840b57cec5SDimitry Andric// a pattern) and the FPI instruction should have emission info (e.g. opcode
1850b57cec5SDimitry Andric// encoding and asm printing info).
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric// FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
1880b57cec5SDimitry Andric// f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
1890b57cec5SDimitry Andric// f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
1900b57cec5SDimitry Andric// f80 instructions cannot use SSE and use neither of these.
1910b57cec5SDimitry Andricclass FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
1920b57cec5SDimitry Andric             FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
1930b57cec5SDimitry Andricclass FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
1940b57cec5SDimitry Andric             FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric// Factoring for arithmetic.
197fe6060f1SDimitry Andricmulticlass FPBinary_rr<SDPatternOperator OpNode> {
1980b57cec5SDimitry Andric// Register op register -> register
1990b57cec5SDimitry Andric// These are separated out because they have no reversed form.
2000b57cec5SDimitry Andricdef _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
2010b57cec5SDimitry Andric                [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
2020b57cec5SDimitry Andricdef _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
2030b57cec5SDimitry Andric                [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
2040b57cec5SDimitry Andricdef _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
2050b57cec5SDimitry Andric                [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
2060b57cec5SDimitry Andric}
2070b57cec5SDimitry Andric// The FopST0 series are not included here because of the irregularities
2080b57cec5SDimitry Andric// in where the 'r' goes in assembly output.
2090b57cec5SDimitry Andric// These instructions cannot address 80-bit memory.
210fe6060f1SDimitry Andricmulticlass FPBinary<SDPatternOperator OpNode, Format fp, string asmstring,
2110b57cec5SDimitry Andric                    bit Forward = 1> {
2120b57cec5SDimitry Andric// ST(0) = ST(0) + [mem]
2130b57cec5SDimitry Andricdef _Fp32m  : FpIf32<(outs RFP32:$dst),
2140b57cec5SDimitry Andric                     (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
2150b57cec5SDimitry Andric                  [!if(Forward,
2160b57cec5SDimitry Andric                       (set RFP32:$dst,
2170b57cec5SDimitry Andric                        (OpNode RFP32:$src1, (loadf32 addr:$src2))),
2180b57cec5SDimitry Andric                       (set RFP32:$dst,
2190b57cec5SDimitry Andric                        (OpNode (loadf32 addr:$src2), RFP32:$src1)))]>;
2200b57cec5SDimitry Andricdef _Fp64m  : FpIf64<(outs RFP64:$dst),
2210b57cec5SDimitry Andric                     (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
2220b57cec5SDimitry Andric                  [!if(Forward,
2230b57cec5SDimitry Andric                       (set RFP64:$dst,
2240b57cec5SDimitry Andric                        (OpNode RFP64:$src1, (loadf64 addr:$src2))),
2250b57cec5SDimitry Andric                       (set RFP64:$dst,
2260b57cec5SDimitry Andric                        (OpNode (loadf64 addr:$src2), RFP64:$src1)))]>;
2270b57cec5SDimitry Andricdef _Fp64m32: FpIf64<(outs RFP64:$dst),
2280b57cec5SDimitry Andric                     (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
2290b57cec5SDimitry Andric                  [!if(Forward,
2300b57cec5SDimitry Andric                       (set RFP64:$dst,
2310b57cec5SDimitry Andric                        (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2)))),
2320b57cec5SDimitry Andric                       (set RFP64:$dst,
2330b57cec5SDimitry Andric                        (OpNode (f64 (extloadf32 addr:$src2)), RFP64:$src1)))]>;
2340b57cec5SDimitry Andricdef _Fp80m32: FpI_<(outs RFP80:$dst),
2350b57cec5SDimitry Andric                   (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
2360b57cec5SDimitry Andric                  [!if(Forward,
2370b57cec5SDimitry Andric                       (set RFP80:$dst,
2380b57cec5SDimitry Andric                        (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2)))),
2390b57cec5SDimitry Andric                       (set RFP80:$dst,
2400b57cec5SDimitry Andric                        (OpNode (f80 (extloadf32 addr:$src2)), RFP80:$src1)))]>;
2410b57cec5SDimitry Andricdef _Fp80m64: FpI_<(outs RFP80:$dst),
2420b57cec5SDimitry Andric                   (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
2430b57cec5SDimitry Andric                  [!if(Forward,
2440b57cec5SDimitry Andric                       (set RFP80:$dst,
2450b57cec5SDimitry Andric                        (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2)))),
2460b57cec5SDimitry Andric                       (set RFP80:$dst,
2470b57cec5SDimitry Andric                        (OpNode (f80 (extloadf64 addr:$src2)), RFP80:$src1)))]>;
2480b57cec5SDimitry Andriclet mayLoad = 1 in
2490b57cec5SDimitry Andricdef _F32m  : FPI<0xD8, fp, (outs), (ins f32mem:$src),
2500b57cec5SDimitry Andric                 !strconcat("f", asmstring, "{s}\t$src")>;
2510b57cec5SDimitry Andriclet mayLoad = 1 in
2520b57cec5SDimitry Andricdef _F64m  : FPI<0xDC, fp, (outs), (ins f64mem:$src),
2530b57cec5SDimitry Andric                 !strconcat("f", asmstring, "{l}\t$src")>;
2540b57cec5SDimitry Andric// ST(0) = ST(0) + [memint]
2550b57cec5SDimitry Andricdef _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
2560b57cec5SDimitry Andric                       OneArgFPRW,
2570b57cec5SDimitry Andric                       [!if(Forward,
2580b57cec5SDimitry Andric                            (set RFP32:$dst,
2590b57cec5SDimitry Andric                             (OpNode RFP32:$src1, (X86fild16 addr:$src2))),
2600b57cec5SDimitry Andric                            (set RFP32:$dst,
2610b57cec5SDimitry Andric                             (OpNode (X86fild16 addr:$src2), RFP32:$src1)))]>;
2620b57cec5SDimitry Andricdef _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
2630b57cec5SDimitry Andric                       OneArgFPRW,
2640b57cec5SDimitry Andric                       [!if(Forward,
2650b57cec5SDimitry Andric                            (set RFP32:$dst,
2660b57cec5SDimitry Andric                             (OpNode RFP32:$src1, (X86fild32 addr:$src2))),
2670b57cec5SDimitry Andric                            (set RFP32:$dst,
2680b57cec5SDimitry Andric                             (OpNode (X86fild32 addr:$src2), RFP32:$src1)))]>;
2690b57cec5SDimitry Andricdef _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
2700b57cec5SDimitry Andric                       OneArgFPRW,
2710b57cec5SDimitry Andric                       [!if(Forward,
2720b57cec5SDimitry Andric                            (set RFP64:$dst,
2730b57cec5SDimitry Andric                             (OpNode RFP64:$src1, (X86fild16 addr:$src2))),
2740b57cec5SDimitry Andric                            (set RFP64:$dst,
2750b57cec5SDimitry Andric                             (OpNode (X86fild16 addr:$src2), RFP64:$src1)))]>;
2760b57cec5SDimitry Andricdef _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
2770b57cec5SDimitry Andric                       OneArgFPRW,
2780b57cec5SDimitry Andric                       [!if(Forward,
2790b57cec5SDimitry Andric                            (set RFP64:$dst,
2800b57cec5SDimitry Andric                             (OpNode RFP64:$src1, (X86fild32 addr:$src2))),
2810b57cec5SDimitry Andric                            (set RFP64:$dst,
2820b57cec5SDimitry Andric                             (OpNode (X86fild32 addr:$src2), RFP64:$src1)))]>;
2830b57cec5SDimitry Andricdef _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
2840b57cec5SDimitry Andric                     OneArgFPRW,
2850b57cec5SDimitry Andric                     [!if(Forward,
2860b57cec5SDimitry Andric                          (set RFP80:$dst,
2870b57cec5SDimitry Andric                           (OpNode RFP80:$src1, (X86fild16 addr:$src2))),
2880b57cec5SDimitry Andric                          (set RFP80:$dst,
2890b57cec5SDimitry Andric                           (OpNode (X86fild16 addr:$src2), RFP80:$src1)))]>;
2900b57cec5SDimitry Andricdef _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
2910b57cec5SDimitry Andric                     OneArgFPRW,
2920b57cec5SDimitry Andric                     [!if(Forward,
2930b57cec5SDimitry Andric                          (set RFP80:$dst,
2940b57cec5SDimitry Andric                           (OpNode RFP80:$src1, (X86fild32 addr:$src2))),
2950b57cec5SDimitry Andric                          (set RFP80:$dst,
2960b57cec5SDimitry Andric                           (OpNode (X86fild32 addr:$src2), RFP80:$src1)))]>;
2970b57cec5SDimitry Andriclet mayLoad = 1 in
2980b57cec5SDimitry Andricdef _FI16m  : FPI<0xDE, fp, (outs), (ins i16mem:$src),
2990b57cec5SDimitry Andric                  !strconcat("fi", asmstring, "{s}\t$src")>;
3000b57cec5SDimitry Andriclet mayLoad = 1 in
3010b57cec5SDimitry Andricdef _FI32m  : FPI<0xDA, fp, (outs), (ins i32mem:$src),
3020b57cec5SDimitry Andric                  !strconcat("fi", asmstring, "{l}\t$src")>;
3030b57cec5SDimitry Andric}
3040b57cec5SDimitry Andric
305480093f4SDimitry Andriclet Uses = [FPCW], mayRaiseFPException = 1 in {
3060b57cec5SDimitry Andric// FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
3070b57cec5SDimitry Andric// resources.
3080b57cec5SDimitry Andriclet hasNoSchedulingInfo = 1 in {
309480093f4SDimitry Andricdefm ADD : FPBinary_rr<any_fadd>;
310480093f4SDimitry Andricdefm SUB : FPBinary_rr<any_fsub>;
311480093f4SDimitry Andricdefm MUL : FPBinary_rr<any_fmul>;
312480093f4SDimitry Andricdefm DIV : FPBinary_rr<any_fdiv>;
3130b57cec5SDimitry Andric}
3140b57cec5SDimitry Andric
3155ffd83dbSDimitry Andric// Sets the scheduling resources for the actual NAME#_F<size>m definitions.
3160b57cec5SDimitry Andriclet SchedRW = [WriteFAddLd] in {
317480093f4SDimitry Andricdefm ADD : FPBinary<any_fadd, MRM0m, "add">;
318480093f4SDimitry Andricdefm SUB : FPBinary<any_fsub, MRM4m, "sub">;
319480093f4SDimitry Andricdefm SUBR: FPBinary<any_fsub ,MRM5m, "subr", 0>;
3200b57cec5SDimitry Andric}
3210b57cec5SDimitry Andric
3220b57cec5SDimitry Andriclet SchedRW = [WriteFMulLd] in {
323480093f4SDimitry Andricdefm MUL : FPBinary<any_fmul, MRM1m, "mul">;
3240b57cec5SDimitry Andric}
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andriclet SchedRW = [WriteFDivLd] in {
327480093f4SDimitry Andricdefm DIV : FPBinary<any_fdiv, MRM6m, "div">;
328480093f4SDimitry Andricdefm DIVR: FPBinary<any_fdiv, MRM7m, "divr", 0>;
3290b57cec5SDimitry Andric}
330480093f4SDimitry Andric} // Uses = [FPCW], mayRaiseFPException = 1
3310b57cec5SDimitry Andric
3320b57cec5SDimitry Andricclass FPST0rInst<Format fp, string asm>
3330b57cec5SDimitry Andric  : FPI<0xD8, fp, (outs), (ins RSTi:$op), asm>;
3340b57cec5SDimitry Andricclass FPrST0Inst<Format fp, string asm>
3350b57cec5SDimitry Andric  : FPI<0xDC, fp, (outs), (ins RSTi:$op), asm>;
3360b57cec5SDimitry Andricclass FPrST0PInst<Format fp, string asm>
3370b57cec5SDimitry Andric  : FPI<0xDE, fp, (outs), (ins RSTi:$op), asm>;
3380b57cec5SDimitry Andric
3390b57cec5SDimitry Andric// NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
3400b57cec5SDimitry Andric// of some of the 'reverse' forms of the fsub and fdiv instructions.  As such,
3410b57cec5SDimitry Andric// we have to put some 'r's in and take them out of weird places.
342480093f4SDimitry Andriclet SchedRW = [WriteFAdd], Uses = [FPCW], mayRaiseFPException = 1 in {
3430b57cec5SDimitry Andricdef ADD_FST0r   : FPST0rInst <MRM0r, "fadd\t{$op, %st|st, $op}">;
3440b57cec5SDimitry Andricdef ADD_FrST0   : FPrST0Inst <MRM0r, "fadd\t{%st, $op|$op, st}">;
3450b57cec5SDimitry Andricdef ADD_FPrST0  : FPrST0PInst<MRM0r, "faddp\t{%st, $op|$op, st}">;
3460b57cec5SDimitry Andricdef SUBR_FST0r  : FPST0rInst <MRM5r, "fsubr\t{$op, %st|st, $op}">;
3470b57cec5SDimitry Andricdef SUB_FrST0   : FPrST0Inst <MRM5r, "fsub{r}\t{%st, $op|$op, st}">;
3480b57cec5SDimitry Andricdef SUB_FPrST0  : FPrST0PInst<MRM5r, "fsub{r}p\t{%st, $op|$op, st}">;
3490b57cec5SDimitry Andricdef SUB_FST0r   : FPST0rInst <MRM4r, "fsub\t{$op, %st|st, $op}">;
3500b57cec5SDimitry Andricdef SUBR_FrST0  : FPrST0Inst <MRM4r, "fsub{|r}\t{%st, $op|$op, st}">;
3510b57cec5SDimitry Andricdef SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t{%st, $op|$op, st}">;
3520b57cec5SDimitry Andric} // SchedRW
353480093f4SDimitry Andriclet SchedRW = [WriteFCom], Uses = [FPCW], mayRaiseFPException = 1 in {
3540b57cec5SDimitry Andricdef COM_FST0r   : FPST0rInst <MRM2r, "fcom\t$op">;
3550b57cec5SDimitry Andricdef COMP_FST0r  : FPST0rInst <MRM3r, "fcomp\t$op">;
3560b57cec5SDimitry Andric} // SchedRW
357480093f4SDimitry Andriclet SchedRW = [WriteFMul], Uses = [FPCW], mayRaiseFPException = 1 in {
3580b57cec5SDimitry Andricdef MUL_FST0r   : FPST0rInst <MRM1r, "fmul\t{$op, %st|st, $op}">;
3590b57cec5SDimitry Andricdef MUL_FrST0   : FPrST0Inst <MRM1r, "fmul\t{%st, $op|$op, st}">;
3600b57cec5SDimitry Andricdef MUL_FPrST0  : FPrST0PInst<MRM1r, "fmulp\t{%st, $op|$op, st}">;
3610b57cec5SDimitry Andric} // SchedRW
362480093f4SDimitry Andriclet SchedRW = [WriteFDiv], Uses = [FPCW], mayRaiseFPException = 1 in {
3630b57cec5SDimitry Andricdef DIVR_FST0r  : FPST0rInst <MRM7r, "fdivr\t{$op, %st|st, $op}">;
3640b57cec5SDimitry Andricdef DIV_FrST0   : FPrST0Inst <MRM7r, "fdiv{r}\t{%st, $op|$op, st}">;
3650b57cec5SDimitry Andricdef DIV_FPrST0  : FPrST0PInst<MRM7r, "fdiv{r}p\t{%st, $op|$op, st}">;
3660b57cec5SDimitry Andricdef DIV_FST0r   : FPST0rInst <MRM6r, "fdiv\t{$op, %st|st, $op}">;
3670b57cec5SDimitry Andricdef DIVR_FrST0  : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st, $op|$op, st}">;
3680b57cec5SDimitry Andricdef DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t{%st, $op|$op, st}">;
3690b57cec5SDimitry Andric} // SchedRW
3700b57cec5SDimitry Andric
3710b57cec5SDimitry Andric// Unary operations.
372fe6060f1SDimitry Andricmulticlass FPUnary<SDPatternOperator OpNode, Format fp, string asmstring> {
3730b57cec5SDimitry Andricdef _Fp32  : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
3740b57cec5SDimitry Andric                 [(set RFP32:$dst, (OpNode RFP32:$src))]>;
3750b57cec5SDimitry Andricdef _Fp64  : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
3760b57cec5SDimitry Andric                 [(set RFP64:$dst, (OpNode RFP64:$src))]>;
3770b57cec5SDimitry Andricdef _Fp80  : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
3780b57cec5SDimitry Andric                 [(set RFP80:$dst, (OpNode RFP80:$src))]>;
3790b57cec5SDimitry Andricdef _F     : FPI<0xD9, fp, (outs), (ins), asmstring>;
3800b57cec5SDimitry Andric}
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andriclet SchedRW = [WriteFSign] in {
3830b57cec5SDimitry Andricdefm CHS : FPUnary<fneg, MRM_E0, "fchs">;
3840b57cec5SDimitry Andricdefm ABS : FPUnary<fabs, MRM_E1, "fabs">;
3850b57cec5SDimitry Andric}
3860b57cec5SDimitry Andric
387480093f4SDimitry Andriclet Uses = [FPCW], mayRaiseFPException = 1 in {
3880b57cec5SDimitry Andriclet SchedRW = [WriteFSqrt80] in
389480093f4SDimitry Andricdefm SQRT: FPUnary<any_fsqrt,MRM_FA, "fsqrt">;
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andriclet SchedRW = [WriteFCom] in {
3920b57cec5SDimitry Andriclet hasSideEffects = 0 in {
3930b57cec5SDimitry Andricdef TST_Fp32  : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
3940b57cec5SDimitry Andricdef TST_Fp64  : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
3950b57cec5SDimitry Andricdef TST_Fp80  : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
3960b57cec5SDimitry Andric} // hasSideEffects
3970b57cec5SDimitry Andric
3980b57cec5SDimitry Andricdef TST_F  : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
3990b57cec5SDimitry Andric} // SchedRW
400480093f4SDimitry Andric} // Uses = [FPCW], mayRaiseFPException = 1
4010b57cec5SDimitry Andric
402349cc55cSDimitry Andriclet SchedRW = [WriteFTest], Defs = [FPSW] in {
403fe6060f1SDimitry Andricdef XAM_Fp32  : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
404fe6060f1SDimitry Andricdef XAM_Fp64  : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
405fe6060f1SDimitry Andricdef XAM_Fp80  : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
406fe6060f1SDimitry Andricdef XAM_F     : FPI<0xD9, MRM_E5, (outs), (ins), "fxam">;
407fe6060f1SDimitry Andric} // SchedRW
408fe6060f1SDimitry Andric
4090b57cec5SDimitry Andric// Versions of FP instructions that take a single memory operand.  Added for the
4100b57cec5SDimitry Andric//   disassembler; remove as they are included with patterns elsewhere.
4115ffd83dbSDimitry Andriclet SchedRW = [WriteFComLd], Uses = [FPCW], mayRaiseFPException = 1,
4125ffd83dbSDimitry Andric    mayLoad = 1 in {
4130b57cec5SDimitry Andricdef FCOM32m  : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
4140b57cec5SDimitry Andricdef FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
4150b57cec5SDimitry Andric
4160b57cec5SDimitry Andricdef FCOM64m  : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
4170b57cec5SDimitry Andricdef FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
4180b57cec5SDimitry Andric
4190b57cec5SDimitry Andricdef FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
4200b57cec5SDimitry Andricdef FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
4210b57cec5SDimitry Andric
4220b57cec5SDimitry Andricdef FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
4230b57cec5SDimitry Andricdef FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
4240b57cec5SDimitry Andric} // SchedRW
4250b57cec5SDimitry Andric
4260b57cec5SDimitry Andriclet SchedRW = [WriteMicrocoded] in {
4275ffd83dbSDimitry Andriclet Defs = [FPSW, FPCW], mayLoad = 1 in {
428e8d8bef9SDimitry Andricdef FRSTORm  : FPI<0xDD, MRM4m, (outs), (ins anymem:$src), "frstor\t$src">;
429*06c3fb27SDimitry Andriclet Predicates = [HasX87] in
430*06c3fb27SDimitry Andricdef FLDENVm  : I<0xD9, MRM4m, (outs), (ins anymem:$src), "fldenv\t$src",
431*06c3fb27SDimitry Andric                 [(X86fpenv_set addr:$src)]>;
432480093f4SDimitry Andric}
433480093f4SDimitry Andric
4345ffd83dbSDimitry Andriclet Defs = [FPSW, FPCW], Uses = [FPSW, FPCW], mayStore = 1 in {
435e8d8bef9SDimitry Andricdef FSAVEm   : FPI<0xDD, MRM6m, (outs), (ins anymem:$dst), "fnsave\t$dst">;
436*06c3fb27SDimitry Andriclet Predicates = [HasX87] in
437*06c3fb27SDimitry Andricdef FSTENVm  : I<0xD9, MRM6m, (outs), (ins anymem:$dst), "fnstenv\t$dst",
438*06c3fb27SDimitry Andric                 [(X86fpenv_get addr:$dst)]>;
439480093f4SDimitry Andric}
440480093f4SDimitry Andric
4415ffd83dbSDimitry Andriclet Uses = [FPSW], mayStore = 1 in
4420b57cec5SDimitry Andricdef FNSTSWm  : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
4430b57cec5SDimitry Andric
4445ffd83dbSDimitry Andriclet mayLoad = 1 in
4450b57cec5SDimitry Andricdef FBLDm    : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
4465ffd83dbSDimitry Andriclet Uses = [FPCW] ,mayRaiseFPException = 1, mayStore = 1 in
4470b57cec5SDimitry Andricdef FBSTPm   : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
4480b57cec5SDimitry Andric} // SchedRW
4490b57cec5SDimitry Andric
4500b57cec5SDimitry Andric// Floating point cmovs.
4510b57cec5SDimitry Andricclass FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
45281ad6265SDimitry Andric  FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMOV]>;
4530b57cec5SDimitry Andricclass FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
45481ad6265SDimitry Andric  FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMOV]>;
4550b57cec5SDimitry Andric
4560b57cec5SDimitry Andricmulticlass FPCMov<PatLeaf cc> {
4570b57cec5SDimitry Andric  def _Fp32  : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
4580b57cec5SDimitry Andric                       CondMovFP,
4590b57cec5SDimitry Andric                     [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
4600b57cec5SDimitry Andric                                        cc, EFLAGS))]>;
4610b57cec5SDimitry Andric  def _Fp64  : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
4620b57cec5SDimitry Andric                       CondMovFP,
4630b57cec5SDimitry Andric                     [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
4640b57cec5SDimitry Andric                                        cc, EFLAGS))]>;
4650b57cec5SDimitry Andric  def _Fp80  : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
4660b57cec5SDimitry Andric                     CondMovFP,
4670b57cec5SDimitry Andric                     [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
4680b57cec5SDimitry Andric                                        cc, EFLAGS))]>,
46981ad6265SDimitry Andric                                        Requires<[HasCMOV]>;
4700b57cec5SDimitry Andric}
4710b57cec5SDimitry Andric
4720b57cec5SDimitry Andriclet SchedRW = [WriteFCMOV] in {
4730b57cec5SDimitry Andriclet Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
4740b57cec5SDimitry Andricdefm CMOVB  : FPCMov<X86_COND_B>;
4750b57cec5SDimitry Andricdefm CMOVBE : FPCMov<X86_COND_BE>;
4760b57cec5SDimitry Andricdefm CMOVE  : FPCMov<X86_COND_E>;
4770b57cec5SDimitry Andricdefm CMOVP  : FPCMov<X86_COND_P>;
4780b57cec5SDimitry Andricdefm CMOVNB : FPCMov<X86_COND_AE>;
4790b57cec5SDimitry Andricdefm CMOVNBE: FPCMov<X86_COND_A>;
4800b57cec5SDimitry Andricdefm CMOVNE : FPCMov<X86_COND_NE>;
4810b57cec5SDimitry Andricdefm CMOVNP : FPCMov<X86_COND_NP>;
4820b57cec5SDimitry Andric} // Uses = [EFLAGS], Constraints = "$src1 = $dst"
4830b57cec5SDimitry Andric
48481ad6265SDimitry Andriclet Predicates = [HasCMOV] in {
4850b57cec5SDimitry Andric// These are not factored because there's no clean way to pass DA/DB.
4860b57cec5SDimitry Andricdef CMOVB_F  : FPI<0xDA, MRM0r, (outs), (ins RSTi:$op),
4870b57cec5SDimitry Andric                  "fcmovb\t{$op, %st|st, $op}">;
4880b57cec5SDimitry Andricdef CMOVBE_F : FPI<0xDA, MRM2r, (outs), (ins RSTi:$op),
4890b57cec5SDimitry Andric                  "fcmovbe\t{$op, %st|st, $op}">;
4900b57cec5SDimitry Andricdef CMOVE_F  : FPI<0xDA, MRM1r, (outs), (ins RSTi:$op),
4910b57cec5SDimitry Andric                  "fcmove\t{$op, %st|st, $op}">;
4920b57cec5SDimitry Andricdef CMOVP_F  : FPI<0xDA, MRM3r, (outs), (ins RSTi:$op),
4930b57cec5SDimitry Andric                  "fcmovu\t{$op, %st|st, $op}">;
4940b57cec5SDimitry Andricdef CMOVNB_F : FPI<0xDB, MRM0r, (outs), (ins RSTi:$op),
4950b57cec5SDimitry Andric                  "fcmovnb\t{$op, %st|st, $op}">;
4960b57cec5SDimitry Andricdef CMOVNBE_F: FPI<0xDB, MRM2r, (outs), (ins RSTi:$op),
4970b57cec5SDimitry Andric                  "fcmovnbe\t{$op, %st|st, $op}">;
4980b57cec5SDimitry Andricdef CMOVNE_F : FPI<0xDB, MRM1r, (outs), (ins RSTi:$op),
4990b57cec5SDimitry Andric                  "fcmovne\t{$op, %st|st, $op}">;
5000b57cec5SDimitry Andricdef CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RSTi:$op),
5010b57cec5SDimitry Andric                  "fcmovnu\t{$op, %st|st, $op}">;
50281ad6265SDimitry Andric} // Predicates = [HasCMOV]
5030b57cec5SDimitry Andric} // SchedRW
5040b57cec5SDimitry Andric
505480093f4SDimitry Andriclet mayRaiseFPException = 1 in {
5060b57cec5SDimitry Andric// Floating point loads & stores.
5070b57cec5SDimitry Andriclet SchedRW = [WriteLoad], Uses = [FPCW] in {
5080b57cec5SDimitry Andriclet canFoldAsLoad = 1 in {
5090b57cec5SDimitry Andricdef LD_Fp32m   : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
5100b57cec5SDimitry Andric                  [(set RFP32:$dst, (loadf32 addr:$src))]>;
5110b57cec5SDimitry Andricdef LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
5120b57cec5SDimitry Andric                  [(set RFP64:$dst, (loadf64 addr:$src))]>;
5130b57cec5SDimitry Andricdef LD_Fp80m   : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
5140b57cec5SDimitry Andric                  [(set RFP80:$dst, (loadf80 addr:$src))]>;
5150b57cec5SDimitry Andric} // canFoldAsLoad
5160b57cec5SDimitry Andricdef LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
5170b57cec5SDimitry Andric                  [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
5180b57cec5SDimitry Andricdef LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
5190b57cec5SDimitry Andric                  [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
5200b57cec5SDimitry Andricdef LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
5210b57cec5SDimitry Andric                  [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
522480093f4SDimitry Andriclet mayRaiseFPException = 0 in {
5230b57cec5SDimitry Andricdef ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
5240b57cec5SDimitry Andric                  [(set RFP32:$dst, (X86fild16 addr:$src))]>;
5250b57cec5SDimitry Andricdef ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
5260b57cec5SDimitry Andric                  [(set RFP32:$dst, (X86fild32 addr:$src))]>;
5270b57cec5SDimitry Andricdef ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
5280b57cec5SDimitry Andric                  [(set RFP32:$dst, (X86fild64 addr:$src))]>;
5290b57cec5SDimitry Andricdef ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
5300b57cec5SDimitry Andric                  [(set RFP64:$dst, (X86fild16 addr:$src))]>;
5310b57cec5SDimitry Andricdef ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
5320b57cec5SDimitry Andric                  [(set RFP64:$dst, (X86fild32 addr:$src))]>;
5330b57cec5SDimitry Andricdef ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
5340b57cec5SDimitry Andric                  [(set RFP64:$dst, (X86fild64 addr:$src))]>;
5350b57cec5SDimitry Andricdef ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
5360b57cec5SDimitry Andric                  [(set RFP80:$dst, (X86fild16 addr:$src))]>;
5370b57cec5SDimitry Andricdef ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
5380b57cec5SDimitry Andric                  [(set RFP80:$dst, (X86fild32 addr:$src))]>;
5390b57cec5SDimitry Andricdef ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
5400b57cec5SDimitry Andric                  [(set RFP80:$dst, (X86fild64 addr:$src))]>;
541480093f4SDimitry Andric} // mayRaiseFPException = 0
5420b57cec5SDimitry Andric} // SchedRW
5430b57cec5SDimitry Andric
5440b57cec5SDimitry Andriclet SchedRW = [WriteStore], Uses = [FPCW] in {
5450b57cec5SDimitry Andricdef ST_Fp32m   : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
5460b57cec5SDimitry Andric                  [(store RFP32:$src, addr:$op)]>;
5470b57cec5SDimitry Andricdef ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
5480b57cec5SDimitry Andric                  [(truncstoref32 RFP64:$src, addr:$op)]>;
5490b57cec5SDimitry Andricdef ST_Fp64m   : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
5500b57cec5SDimitry Andric                  [(store RFP64:$src, addr:$op)]>;
5510b57cec5SDimitry Andricdef ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
5520b57cec5SDimitry Andric                  [(truncstoref32 RFP80:$src, addr:$op)]>;
5530b57cec5SDimitry Andricdef ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
5540b57cec5SDimitry Andric                  [(truncstoref64 RFP80:$src, addr:$op)]>;
5550b57cec5SDimitry Andric// FST does not support 80-bit memory target; FSTP must be used.
5560b57cec5SDimitry Andric
5570b57cec5SDimitry Andriclet mayStore = 1, hasSideEffects = 0 in {
5580b57cec5SDimitry Andricdef ST_FpP32m    : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
5590b57cec5SDimitry Andricdef ST_FpP64m32  : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
5600b57cec5SDimitry Andricdef ST_FpP64m    : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
5610b57cec5SDimitry Andricdef ST_FpP80m32  : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
5620b57cec5SDimitry Andricdef ST_FpP80m64  : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
5630b57cec5SDimitry Andric} // mayStore
5640b57cec5SDimitry Andric
5650b57cec5SDimitry Andricdef ST_FpP80m    : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
5660b57cec5SDimitry Andric                    [(store RFP80:$src, addr:$op)]>;
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andriclet mayStore = 1, hasSideEffects = 0 in {
5690b57cec5SDimitry Andricdef IST_Fp16m32  : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
5705ffd83dbSDimitry Andricdef IST_Fp32m32  : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
5715ffd83dbSDimitry Andric                          [(X86fist32 RFP32:$src, addr:$op)]>;
5725ffd83dbSDimitry Andricdef IST_Fp64m32  : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
5735ffd83dbSDimitry Andric                          [(X86fist64 RFP32:$src, addr:$op)]>;
5740b57cec5SDimitry Andricdef IST_Fp16m64  : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
5755ffd83dbSDimitry Andricdef IST_Fp32m64  : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
5765ffd83dbSDimitry Andric                          [(X86fist32 RFP64:$src, addr:$op)]>;
5775ffd83dbSDimitry Andricdef IST_Fp64m64  : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
5785ffd83dbSDimitry Andric                          [(X86fist64 RFP64:$src, addr:$op)]>;
5790b57cec5SDimitry Andricdef IST_Fp16m80  : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
5805ffd83dbSDimitry Andricdef IST_Fp32m80  : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
5815ffd83dbSDimitry Andric                        [(X86fist32 RFP80:$src, addr:$op)]>;
5825ffd83dbSDimitry Andricdef IST_Fp64m80  : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
5835ffd83dbSDimitry Andric                        [(X86fist64 RFP80:$src, addr:$op)]>;
5840b57cec5SDimitry Andric} // mayStore
5850b57cec5SDimitry Andric} // SchedRW, Uses = [FPCW]
5860b57cec5SDimitry Andric
5870b57cec5SDimitry Andriclet mayLoad = 1, SchedRW = [WriteLoad], Uses = [FPCW] in {
5880b57cec5SDimitry Andricdef LD_F32m   : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
5890b57cec5SDimitry Andricdef LD_F64m   : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
5900b57cec5SDimitry Andricdef LD_F80m   : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
591480093f4SDimitry Andriclet mayRaiseFPException = 0 in {
5920b57cec5SDimitry Andricdef ILD_F16m  : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
5930b57cec5SDimitry Andricdef ILD_F32m  : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
5940b57cec5SDimitry Andricdef ILD_F64m  : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
5950b57cec5SDimitry Andric}
596480093f4SDimitry Andric}
5970b57cec5SDimitry Andriclet mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
5980b57cec5SDimitry Andricdef ST_F32m   : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
5990b57cec5SDimitry Andricdef ST_F64m   : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
6000b57cec5SDimitry Andricdef ST_FP32m  : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst">;
6010b57cec5SDimitry Andricdef ST_FP64m  : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst">;
6020b57cec5SDimitry Andricdef ST_FP80m  : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst">;
6030b57cec5SDimitry Andricdef IST_F16m  : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst">;
6040b57cec5SDimitry Andricdef IST_F32m  : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst">;
6050b57cec5SDimitry Andricdef IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst">;
6060b57cec5SDimitry Andricdef IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst">;
6070b57cec5SDimitry Andricdef IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst">;
6080b57cec5SDimitry Andric}
6090b57cec5SDimitry Andric
6100b57cec5SDimitry Andric// FISTTP requires SSE3 even though it's a FPStack op.
6110b57cec5SDimitry Andriclet Predicates = [HasSSE3], SchedRW = [WriteStore], Uses = [FPCW] in {
6120b57cec5SDimitry Andricdef ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
6130b57cec5SDimitry Andric                    [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
6140b57cec5SDimitry Andricdef ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
6150b57cec5SDimitry Andric                    [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
6160b57cec5SDimitry Andricdef ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
6170b57cec5SDimitry Andric                    [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
6180b57cec5SDimitry Andricdef ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
6190b57cec5SDimitry Andric                    [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
6200b57cec5SDimitry Andricdef ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
6210b57cec5SDimitry Andric                    [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
6220b57cec5SDimitry Andricdef ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
6230b57cec5SDimitry Andric                    [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
6240b57cec5SDimitry Andricdef ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
6250b57cec5SDimitry Andric                    [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
6260b57cec5SDimitry Andricdef ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
6270b57cec5SDimitry Andric                    [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
6280b57cec5SDimitry Andricdef ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
6290b57cec5SDimitry Andric                    [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
6300b57cec5SDimitry Andric} // Predicates = [HasSSE3]
6310b57cec5SDimitry Andric
6320b57cec5SDimitry Andriclet mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
6330b57cec5SDimitry Andricdef ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst">;
6340b57cec5SDimitry Andricdef ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst">;
6350b57cec5SDimitry Andricdef ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll}\t$dst">;
6360b57cec5SDimitry Andric}
6370b57cec5SDimitry Andric
6380b57cec5SDimitry Andric// FP Stack manipulation instructions.
6390b57cec5SDimitry Andriclet SchedRW = [WriteMove], Uses = [FPCW] in {
6400b57cec5SDimitry Andricdef LD_Frr   : FPI<0xD9, MRM0r, (outs), (ins RSTi:$op), "fld\t$op">;
6410b57cec5SDimitry Andricdef ST_Frr   : FPI<0xDD, MRM2r, (outs), (ins RSTi:$op), "fst\t$op">;
6420b57cec5SDimitry Andricdef ST_FPrr  : FPI<0xDD, MRM3r, (outs), (ins RSTi:$op), "fstp\t$op">;
6435ffd83dbSDimitry Andriclet mayRaiseFPException = 0 in
6440b57cec5SDimitry Andricdef XCH_F    : FPI<0xD9, MRM1r, (outs), (ins RSTi:$op), "fxch\t$op">;
6450b57cec5SDimitry Andric}
6460b57cec5SDimitry Andric
6470b57cec5SDimitry Andric// Floating point constant loads.
6480b57cec5SDimitry Andriclet SchedRW = [WriteZero], Uses = [FPCW] in {
6490b57cec5SDimitry Andricdef LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
6500b57cec5SDimitry Andric                [(set RFP32:$dst, fpimm0)]>;
6510b57cec5SDimitry Andricdef LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
6520b57cec5SDimitry Andric                [(set RFP32:$dst, fpimm1)]>;
6530b57cec5SDimitry Andricdef LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
6540b57cec5SDimitry Andric                [(set RFP64:$dst, fpimm0)]>;
6550b57cec5SDimitry Andricdef LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
6560b57cec5SDimitry Andric                [(set RFP64:$dst, fpimm1)]>;
6570b57cec5SDimitry Andricdef LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
6580b57cec5SDimitry Andric                [(set RFP80:$dst, fpimm0)]>;
6590b57cec5SDimitry Andricdef LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
6600b57cec5SDimitry Andric                [(set RFP80:$dst, fpimm1)]>;
6610b57cec5SDimitry Andric}
6620b57cec5SDimitry Andric
6635ffd83dbSDimitry Andriclet SchedRW = [WriteFLD0], Uses = [FPCW], mayRaiseFPException = 0 in
6640b57cec5SDimitry Andricdef LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
6650b57cec5SDimitry Andric
6665ffd83dbSDimitry Andriclet SchedRW = [WriteFLD1], Uses = [FPCW], mayRaiseFPException = 0 in
6670b57cec5SDimitry Andricdef LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
6680b57cec5SDimitry Andric
6695ffd83dbSDimitry Andriclet SchedRW = [WriteFLDC], Defs = [FPSW], Uses = [FPCW], mayRaiseFPException = 0 in {
6700b57cec5SDimitry Andricdef FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
6710b57cec5SDimitry Andricdef FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
6720b57cec5SDimitry Andricdef FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
6730b57cec5SDimitry Andricdef FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", []>;
6740b57cec5SDimitry Andricdef FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", []>;
6750b57cec5SDimitry Andric} // SchedRW
6760b57cec5SDimitry Andric
6770b57cec5SDimitry Andric// Floating point compares.
6785ffd83dbSDimitry Andriclet SchedRW = [WriteFCom], Uses = [FPCW], hasSideEffects = 0 in {
6795ffd83dbSDimitry Andricdef UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
6805ffd83dbSDimitry Andricdef UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
6815ffd83dbSDimitry Andricdef UCOM_Fpr80 : FpI_  <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
6825ffd83dbSDimitry Andricdef COM_Fpr32  : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
6835ffd83dbSDimitry Andricdef COM_Fpr64  : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
6845ffd83dbSDimitry Andricdef COM_Fpr80  : FpI_  <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
6850b57cec5SDimitry Andric} // SchedRW
686480093f4SDimitry Andric} // mayRaiseFPException = 1
6870b57cec5SDimitry Andric
688480093f4SDimitry Andriclet SchedRW = [WriteFCom], mayRaiseFPException = 1 in {
6890b57cec5SDimitry Andric// CC = ST(0) cmp ST(i)
6905ffd83dbSDimitry Andriclet Defs = [EFLAGS, FPSW], Uses = [FPCW] in {
6910b57cec5SDimitry Andricdef UCOM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
692480093f4SDimitry Andric                  [(set EFLAGS, (X86any_fcmp RFP32:$lhs, RFP32:$rhs))]>,
69381ad6265SDimitry Andric                  Requires<[FPStackf32, HasCMOV]>;
6940b57cec5SDimitry Andricdef UCOM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
695480093f4SDimitry Andric                  [(set EFLAGS, (X86any_fcmp RFP64:$lhs, RFP64:$rhs))]>,
69681ad6265SDimitry Andric                  Requires<[FPStackf64, HasCMOV]>;
6970b57cec5SDimitry Andricdef UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
698480093f4SDimitry Andric                  [(set EFLAGS, (X86any_fcmp RFP80:$lhs, RFP80:$rhs))]>,
69981ad6265SDimitry Andric                  Requires<[HasCMOV]>;
700480093f4SDimitry Andricdef COM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
701480093f4SDimitry Andric                  [(set EFLAGS, (X86strict_fcmps RFP32:$lhs, RFP32:$rhs))]>,
70281ad6265SDimitry Andric                  Requires<[FPStackf32, HasCMOV]>;
703480093f4SDimitry Andricdef COM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
704480093f4SDimitry Andric                  [(set EFLAGS, (X86strict_fcmps RFP64:$lhs, RFP64:$rhs))]>,
70581ad6265SDimitry Andric                  Requires<[FPStackf64, HasCMOV]>;
706480093f4SDimitry Andricdef COM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
707480093f4SDimitry Andric                  [(set EFLAGS, (X86strict_fcmps RFP80:$lhs, RFP80:$rhs))]>,
70881ad6265SDimitry Andric                  Requires<[HasCMOV]>;
7090b57cec5SDimitry Andric}
7100b57cec5SDimitry Andric
711480093f4SDimitry Andriclet Uses = [ST0, FPCW] in {
7120b57cec5SDimitry Andricdef UCOM_Fr    : FPI<0xDD, MRM4r,    // FPSW = cmp ST(0) with ST(i)
7130b57cec5SDimitry Andric                    (outs), (ins RSTi:$reg), "fucom\t$reg">;
7140b57cec5SDimitry Andricdef UCOM_FPr   : FPI<0xDD, MRM5r,    // FPSW = cmp ST(0) with ST(i), pop
7150b57cec5SDimitry Andric                    (outs), (ins RSTi:$reg), "fucomp\t$reg">;
7160b57cec5SDimitry Andricdef UCOM_FPPr  : FPI<0xDA, MRM_E9,       // cmp ST(0) with ST(1), pop, pop
7170b57cec5SDimitry Andric                    (outs), (ins), "fucompp">;
7180b57cec5SDimitry Andric}
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andriclet Defs = [EFLAGS, FPSW], Uses = [ST0, FPCW] in {
7210b57cec5SDimitry Andricdef UCOM_FIr   : FPI<0xDB, MRM5r,     // CC = cmp ST(0) with ST(i)
7220b57cec5SDimitry Andric                    (outs), (ins RSTi:$reg), "fucomi\t{$reg, %st|st, $reg}">;
7230b57cec5SDimitry Andricdef UCOM_FIPr  : FPI<0xDF, MRM5r,     // CC = cmp ST(0) with ST(i), pop
7240b57cec5SDimitry Andric                    (outs), (ins RSTi:$reg), "fucompi\t{$reg, %st|st, $reg}">;
7250b57cec5SDimitry Andric
7260b57cec5SDimitry Andricdef COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RSTi:$reg),
7270b57cec5SDimitry Andric                  "fcomi\t{$reg, %st|st, $reg}">;
7280b57cec5SDimitry Andricdef COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RSTi:$reg),
7290b57cec5SDimitry Andric                   "fcompi\t{$reg, %st|st, $reg}">;
7300b57cec5SDimitry Andric}
7310b57cec5SDimitry Andric} // SchedRW
7320b57cec5SDimitry Andric
7330b57cec5SDimitry Andric// Floating point flag ops.
7340b57cec5SDimitry Andriclet SchedRW = [WriteALU] in {
7355ffd83dbSDimitry Andriclet Defs = [AX, FPSW], Uses = [FPSW], hasSideEffects = 0 in
7360b57cec5SDimitry Andricdef FNSTSW16r : I<0xDF, MRM_E0,                  // AX = fp flags
7375ffd83dbSDimitry Andric                  (outs), (ins), "fnstsw\t{%ax|ax}", []>;
7380b57cec5SDimitry Andriclet Defs = [FPSW], Uses = [FPCW] in
7390b57cec5SDimitry Andricdef FNSTCW16m : I<0xD9, MRM7m,                   // [mem16] = X87 control world
7400b57cec5SDimitry Andric                  (outs), (ins i16mem:$dst), "fnstcw\t$dst",
7410b57cec5SDimitry Andric                  [(X86fp_cwd_get16 addr:$dst)]>;
7420b57cec5SDimitry Andric} // SchedRW
7430b57cec5SDimitry Andriclet Defs = [FPSW,FPCW], mayLoad = 1 in
7440b57cec5SDimitry Andricdef FLDCW16m  : I<0xD9, MRM5m,                   // X87 control world = [mem16]
745fe6060f1SDimitry Andric                  (outs), (ins i16mem:$dst), "fldcw\t$dst",
746fe6060f1SDimitry Andric                  [(X86fp_cwd_set16 addr:$dst)]>,
7470b57cec5SDimitry Andric                Sched<[WriteLoad]>;
7480b57cec5SDimitry Andric
7490b57cec5SDimitry Andric// FPU control instructions
7500b57cec5SDimitry Andriclet SchedRW = [WriteMicrocoded] in {
7510b57cec5SDimitry Andricdef FFREE : FPI<0xDD, MRM0r, (outs), (ins RSTi:$reg), "ffree\t$reg">;
7520b57cec5SDimitry Andricdef FFREEP : FPI<0xDF, MRM0r, (outs), (ins RSTi:$reg), "ffreep\t$reg">;
7530b57cec5SDimitry Andric
754480093f4SDimitry Andriclet Defs = [FPSW, FPCW] in
755480093f4SDimitry Andricdef FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
7560b57cec5SDimitry Andric// Clear exceptions
757480093f4SDimitry Andriclet Defs = [FPSW] in
7580b57cec5SDimitry Andricdef FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
7590b57cec5SDimitry Andric} // SchedRW
7600b57cec5SDimitry Andric
7610b57cec5SDimitry Andric// Operand-less floating-point instructions for the disassembler.
762480093f4SDimitry Andriclet Defs = [FPSW] in
7630b57cec5SDimitry Andricdef FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
7640b57cec5SDimitry Andric
7650b57cec5SDimitry Andriclet SchedRW = [WriteMicrocoded] in {
7660b57cec5SDimitry Andriclet Defs = [FPSW] in {
7670b57cec5SDimitry Andricdef WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
768480093f4SDimitry Andricdef FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
769480093f4SDimitry Andricdef FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
770480093f4SDimitry Andriclet Uses = [FPCW], mayRaiseFPException = 1 in {
7710b57cec5SDimitry Andricdef F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
7720b57cec5SDimitry Andricdef FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
7730b57cec5SDimitry Andricdef FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
7740b57cec5SDimitry Andricdef FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
7750b57cec5SDimitry Andricdef FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
7760b57cec5SDimitry Andricdef FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
7770b57cec5SDimitry Andricdef FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
7780b57cec5SDimitry Andricdef FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
779480093f4SDimitry Andricdef FSIN : I<0xD9, MRM_FE, (outs), (ins), "fsin", []>;
780480093f4SDimitry Andricdef FCOS : I<0xD9, MRM_FF, (outs), (ins), "fcos", []>;
7810b57cec5SDimitry Andricdef FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
7820b57cec5SDimitry Andricdef FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
7830b57cec5SDimitry Andricdef FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
7840b57cec5SDimitry Andricdef FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
785480093f4SDimitry Andric} // Uses = [FPCW], mayRaiseFPException = 1
7860b57cec5SDimitry Andric} // Defs = [FPSW]
7870b57cec5SDimitry Andric
788480093f4SDimitry Andriclet Uses = [FPSW, FPCW] in {
7890b57cec5SDimitry Andricdef FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
7905ffd83dbSDimitry Andric             "fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, PS,
7910b57cec5SDimitry Andric             Requires<[HasFXSR]>;
7920b57cec5SDimitry Andricdef FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
7930b57cec5SDimitry Andric               "fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
7945ffd83dbSDimitry Andric               PS, Requires<[HasFXSR, In64BitMode]>;
795480093f4SDimitry Andric} // Uses = [FPSW, FPCW]
796480093f4SDimitry Andric
797480093f4SDimitry Andriclet Defs = [FPSW, FPCW] in {
7980b57cec5SDimitry Andricdef FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
7990b57cec5SDimitry Andric              "fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
8005ffd83dbSDimitry Andric              PS, Requires<[HasFXSR]>;
8010b57cec5SDimitry Andricdef FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
8020b57cec5SDimitry Andric                "fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
8035ffd83dbSDimitry Andric                PS, Requires<[HasFXSR, In64BitMode]>;
804480093f4SDimitry Andric} // Defs = [FPSW, FPCW]
8050b57cec5SDimitry Andric} // SchedRW
8060b57cec5SDimitry Andric
8070b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
8080b57cec5SDimitry Andric// Non-Instruction Patterns
8090b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
8100b57cec5SDimitry Andric
8110b57cec5SDimitry Andric// Required for RET of f32 / f64 / f80 values.
8120b57cec5SDimitry Andricdef : Pat<(X86fldf32 addr:$src), (LD_Fp32m addr:$src)>;
813480093f4SDimitry Andricdef : Pat<(X86fldf32 addr:$src), (LD_Fp32m64 addr:$src)>;
8140b57cec5SDimitry Andricdef : Pat<(X86fldf64 addr:$src), (LD_Fp64m addr:$src)>;
815480093f4SDimitry Andricdef : Pat<(X86fldf32 addr:$src), (LD_Fp32m80 addr:$src)>;
816480093f4SDimitry Andricdef : Pat<(X86fldf64 addr:$src), (LD_Fp64m80 addr:$src)>;
8170b57cec5SDimitry Andricdef : Pat<(X86fldf80 addr:$src), (LD_Fp80m addr:$src)>;
8180b57cec5SDimitry Andric
8190b57cec5SDimitry Andric// Required for CALL which return f32 / f64 / f80 values.
8200b57cec5SDimitry Andricdef : Pat<(X86fstf32 RFP32:$src, addr:$op), (ST_Fp32m addr:$op, RFP32:$src)>;
8210b57cec5SDimitry Andricdef : Pat<(X86fstf32 RFP64:$src, addr:$op), (ST_Fp64m32 addr:$op, RFP64:$src)>;
8220b57cec5SDimitry Andricdef : Pat<(X86fstf64 RFP64:$src, addr:$op), (ST_Fp64m addr:$op, RFP64:$src)>;
8230b57cec5SDimitry Andricdef : Pat<(X86fstf32 RFP80:$src, addr:$op), (ST_Fp80m32 addr:$op, RFP80:$src)>;
8240b57cec5SDimitry Andricdef : Pat<(X86fstf64 RFP80:$src, addr:$op), (ST_Fp80m64 addr:$op, RFP80:$src)>;
8250b57cec5SDimitry Andricdef : Pat<(X86fstf80 RFP80:$src, addr:$op), (ST_FpP80m addr:$op, RFP80:$src)>;
8260b57cec5SDimitry Andric
8270b57cec5SDimitry Andric// Floating point constant -0.0 and -1.0
8280b57cec5SDimitry Andricdef : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
8290b57cec5SDimitry Andricdef : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
8300b57cec5SDimitry Andricdef : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
8310b57cec5SDimitry Andricdef : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
8320b57cec5SDimitry Andricdef : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
8330b57cec5SDimitry Andricdef : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
8340b57cec5SDimitry Andric
8350b57cec5SDimitry Andric// FP extensions map onto simple pseudo-value conversions if they are to/from
8360b57cec5SDimitry Andric// the FP stack.
837480093f4SDimitry Andricdef : Pat<(f64 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
8380b57cec5SDimitry Andric          Requires<[FPStackf32]>;
839480093f4SDimitry Andricdef : Pat<(f80 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
8400b57cec5SDimitry Andric           Requires<[FPStackf32]>;
841480093f4SDimitry Andricdef : Pat<(f80 (any_fpextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
8420b57cec5SDimitry Andric           Requires<[FPStackf64]>;
8430b57cec5SDimitry Andric
8440b57cec5SDimitry Andric// FP truncations map onto simple pseudo-value conversions if they are to/from
8450b57cec5SDimitry Andric// the FP stack.  We have validated that only value-preserving truncations make
8460b57cec5SDimitry Andric// it through isel.
847480093f4SDimitry Andricdef : Pat<(f32 (any_fpround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
8480b57cec5SDimitry Andric          Requires<[FPStackf32]>;
849480093f4SDimitry Andricdef : Pat<(f32 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
8500b57cec5SDimitry Andric           Requires<[FPStackf32]>;
851480093f4SDimitry Andricdef : Pat<(f64 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
8520b57cec5SDimitry Andric           Requires<[FPStackf64]>;
853