X86InstrFPStack.td 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. //===- X86InstrFPStack.td - FPU Instruction Set ------------*- tablegen -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file describes the X86 x87 FPU instruction set, defining the
  10. // instructions, and properties of the instructions which are needed for code
  11. // generation, machine code emission, and analysis.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. //===----------------------------------------------------------------------===//
  15. // FPStack specific DAG Nodes.
  16. //===----------------------------------------------------------------------===//
  17. def SDTX86Fld : SDTypeProfile<1, 1, [SDTCisFP<0>,
  18. SDTCisPtrTy<1>]>;
  19. def SDTX86Fst : SDTypeProfile<0, 2, [SDTCisFP<0>,
  20. SDTCisPtrTy<1>]>;
  21. def SDTX86Fild : SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
  22. def SDTX86Fist : SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisPtrTy<1>]>;
  23. def SDTX86CwdStore : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
  24. def SDTX86CwdLoad : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
  25. def X86fp80_add : SDNode<"X86ISD::FP80_ADD", SDTFPBinOp, [SDNPCommutative]>;
  26. def X86strict_fp80_add : SDNode<"X86ISD::STRICT_FP80_ADD", SDTFPBinOp,
  27. [SDNPHasChain,SDNPCommutative]>;
  28. def any_X86fp80_add : PatFrags<(ops node:$lhs, node:$rhs),
  29. [(X86strict_fp80_add node:$lhs, node:$rhs),
  30. (X86fp80_add node:$lhs, node:$rhs)]>;
  31. def X86fld : SDNode<"X86ISD::FLD", SDTX86Fld,
  32. [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
  33. def X86fst : SDNode<"X86ISD::FST", SDTX86Fst,
  34. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  35. def X86fild : SDNode<"X86ISD::FILD", SDTX86Fild,
  36. [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
  37. def X86fist : SDNode<"X86ISD::FIST", SDTX86Fist,
  38. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  39. def X86fp_to_mem : SDNode<"X86ISD::FP_TO_INT_IN_MEM", SDTX86Fst,
  40. [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
  41. def X86fp_cwd_get16 : SDNode<"X86ISD::FNSTCW16m", SDTX86CwdStore,
  42. [SDNPHasChain, SDNPMayStore, SDNPSideEffect,
  43. SDNPMemOperand]>;
  44. def X86fp_cwd_set16 : SDNode<"X86ISD::FLDCW16m", SDTX86CwdLoad,
  45. [SDNPHasChain, SDNPMayLoad, SDNPSideEffect,
  46. SDNPMemOperand]>;
  47. def X86fstf32 : PatFrag<(ops node:$val, node:$ptr),
  48. (X86fst node:$val, node:$ptr), [{
  49. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
  50. }]>;
  51. def X86fstf64 : PatFrag<(ops node:$val, node:$ptr),
  52. (X86fst node:$val, node:$ptr), [{
  53. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
  54. }]>;
  55. def X86fstf80 : PatFrag<(ops node:$val, node:$ptr),
  56. (X86fst node:$val, node:$ptr), [{
  57. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
  58. }]>;
  59. def X86fldf32 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
  60. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f32;
  61. }]>;
  62. def X86fldf64 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
  63. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f64;
  64. }]>;
  65. def X86fldf80 : PatFrag<(ops node:$ptr), (X86fld node:$ptr), [{
  66. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::f80;
  67. }]>;
  68. def X86fild16 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
  69. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
  70. }]>;
  71. def X86fild32 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
  72. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
  73. }]>;
  74. def X86fild64 : PatFrag<(ops node:$ptr), (X86fild node:$ptr), [{
  75. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
  76. }]>;
  77. def X86fist32 : PatFrag<(ops node:$val, node:$ptr),
  78. (X86fist node:$val, node:$ptr), [{
  79. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
  80. }]>;
  81. def X86fist64 : PatFrag<(ops node:$val, node:$ptr),
  82. (X86fist node:$val, node:$ptr), [{
  83. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
  84. }]>;
  85. def X86fp_to_i16mem : PatFrag<(ops node:$val, node:$ptr),
  86. (X86fp_to_mem node:$val, node:$ptr), [{
  87. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
  88. }]>;
  89. def X86fp_to_i32mem : PatFrag<(ops node:$val, node:$ptr),
  90. (X86fp_to_mem node:$val, node:$ptr), [{
  91. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
  92. }]>;
  93. def X86fp_to_i64mem : PatFrag<(ops node:$val, node:$ptr),
  94. (X86fp_to_mem node:$val, node:$ptr), [{
  95. return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
  96. }]>;
  97. //===----------------------------------------------------------------------===//
  98. // FPStack pattern fragments
  99. //===----------------------------------------------------------------------===//
  100. def fpimm0 : FPImmLeaf<fAny, [{
  101. return Imm.isExactlyValue(+0.0);
  102. }]>;
  103. def fpimmneg0 : FPImmLeaf<fAny, [{
  104. return Imm.isExactlyValue(-0.0);
  105. }]>;
  106. def fpimm1 : FPImmLeaf<fAny, [{
  107. return Imm.isExactlyValue(+1.0);
  108. }]>;
  109. def fpimmneg1 : FPImmLeaf<fAny, [{
  110. return Imm.isExactlyValue(-1.0);
  111. }]>;
  112. // Some 'special' instructions - expanded after instruction selection.
  113. // Clobbers EFLAGS due to OR instruction used internally.
  114. // FIXME: Can we model this in SelectionDAG?
  115. let usesCustomInserter = 1, hasNoSchedulingInfo = 1, Defs = [EFLAGS] in {
  116. def FP32_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP32:$src),
  117. [(X86fp_to_i16mem RFP32:$src, addr:$dst)]>;
  118. def FP32_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP32:$src),
  119. [(X86fp_to_i32mem RFP32:$src, addr:$dst)]>;
  120. def FP32_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP32:$src),
  121. [(X86fp_to_i64mem RFP32:$src, addr:$dst)]>;
  122. def FP64_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP64:$src),
  123. [(X86fp_to_i16mem RFP64:$src, addr:$dst)]>;
  124. def FP64_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP64:$src),
  125. [(X86fp_to_i32mem RFP64:$src, addr:$dst)]>;
  126. def FP64_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP64:$src),
  127. [(X86fp_to_i64mem RFP64:$src, addr:$dst)]>;
  128. def FP80_TO_INT16_IN_MEM : PseudoI<(outs), (ins i16mem:$dst, RFP80:$src),
  129. [(X86fp_to_i16mem RFP80:$src, addr:$dst)]>;
  130. def FP80_TO_INT32_IN_MEM : PseudoI<(outs), (ins i32mem:$dst, RFP80:$src),
  131. [(X86fp_to_i32mem RFP80:$src, addr:$dst)]>;
  132. def FP80_TO_INT64_IN_MEM : PseudoI<(outs), (ins i64mem:$dst, RFP80:$src),
  133. [(X86fp_to_i64mem RFP80:$src, addr:$dst)]>;
  134. def FP80_ADDr : PseudoI<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
  135. [(set RFP80:$dst,
  136. (any_X86fp80_add RFP80:$src1, RFP80:$src2))]>;
  137. def FP80_ADDm32 : PseudoI<(outs RFP80:$dst), (ins RFP80:$src1, f32mem:$src2),
  138. [(set RFP80:$dst,
  139. (any_X86fp80_add RFP80:$src1,
  140. (f80 (extloadf32 addr:$src2))))]>;
  141. }
  142. // All FP Stack operations are represented with four instructions here. The
  143. // first three instructions, generated by the instruction selector, use "RFP32"
  144. // "RFP64" or "RFP80" registers: traditional register files to reference 32-bit,
  145. // 64-bit or 80-bit floating point values. These sizes apply to the values,
  146. // not the registers, which are always 80 bits; RFP32, RFP64 and RFP80 can be
  147. // copied to each other without losing information. These instructions are all
  148. // pseudo instructions and use the "_Fp" suffix.
  149. // In some cases there are additional variants with a mixture of different
  150. // register sizes.
  151. // The second instruction is defined with FPI, which is the actual instruction
  152. // emitted by the assembler. These use "RST" registers, although frequently
  153. // the actual register(s) used are implicit. These are always 80 bits.
  154. // The FP stackifier pass converts one to the other after register allocation
  155. // occurs.
  156. //
  157. // Note that the FpI instruction should have instruction selection info (e.g.
  158. // a pattern) and the FPI instruction should have emission info (e.g. opcode
  159. // encoding and asm printing info).
  160. // FpIf32, FpIf64 - Floating Point Pseudo Instruction template.
  161. // f32 instructions can use SSE1 and are predicated on FPStackf32 == !SSE1.
  162. // f64 instructions can use SSE2 and are predicated on FPStackf64 == !SSE2.
  163. // f80 instructions cannot use SSE and use neither of these.
  164. class FpIf32<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
  165. FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32]>;
  166. class FpIf64<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
  167. FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64]>;
  168. // Factoring for arithmetic.
  169. multiclass FPBinary_rr<SDPatternOperator OpNode> {
  170. // Register op register -> register
  171. // These are separated out because they have no reversed form.
  172. def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2), TwoArgFP,
  173. [(set RFP32:$dst, (OpNode RFP32:$src1, RFP32:$src2))]>;
  174. def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2), TwoArgFP,
  175. [(set RFP64:$dst, (OpNode RFP64:$src1, RFP64:$src2))]>;
  176. def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2), TwoArgFP,
  177. [(set RFP80:$dst, (OpNode RFP80:$src1, RFP80:$src2))]>;
  178. }
  179. // The FopST0 series are not included here because of the irregularities
  180. // in where the 'r' goes in assembly output.
  181. // These instructions cannot address 80-bit memory.
  182. multiclass FPBinary<SDPatternOperator OpNode, Format fp, string asmstring,
  183. bit Forward = 1> {
  184. // ST(0) = ST(0) + [mem]
  185. def _Fp32m : FpIf32<(outs RFP32:$dst),
  186. (ins RFP32:$src1, f32mem:$src2), OneArgFPRW,
  187. [!if(Forward,
  188. (set RFP32:$dst,
  189. (OpNode RFP32:$src1, (loadf32 addr:$src2))),
  190. (set RFP32:$dst,
  191. (OpNode (loadf32 addr:$src2), RFP32:$src1)))]>;
  192. def _Fp64m : FpIf64<(outs RFP64:$dst),
  193. (ins RFP64:$src1, f64mem:$src2), OneArgFPRW,
  194. [!if(Forward,
  195. (set RFP64:$dst,
  196. (OpNode RFP64:$src1, (loadf64 addr:$src2))),
  197. (set RFP64:$dst,
  198. (OpNode (loadf64 addr:$src2), RFP64:$src1)))]>;
  199. def _Fp64m32: FpIf64<(outs RFP64:$dst),
  200. (ins RFP64:$src1, f32mem:$src2), OneArgFPRW,
  201. [!if(Forward,
  202. (set RFP64:$dst,
  203. (OpNode RFP64:$src1, (f64 (extloadf32 addr:$src2)))),
  204. (set RFP64:$dst,
  205. (OpNode (f64 (extloadf32 addr:$src2)), RFP64:$src1)))]>;
  206. def _Fp80m32: FpI_<(outs RFP80:$dst),
  207. (ins RFP80:$src1, f32mem:$src2), OneArgFPRW,
  208. [!if(Forward,
  209. (set RFP80:$dst,
  210. (OpNode RFP80:$src1, (f80 (extloadf32 addr:$src2)))),
  211. (set RFP80:$dst,
  212. (OpNode (f80 (extloadf32 addr:$src2)), RFP80:$src1)))]>;
  213. def _Fp80m64: FpI_<(outs RFP80:$dst),
  214. (ins RFP80:$src1, f64mem:$src2), OneArgFPRW,
  215. [!if(Forward,
  216. (set RFP80:$dst,
  217. (OpNode RFP80:$src1, (f80 (extloadf64 addr:$src2)))),
  218. (set RFP80:$dst,
  219. (OpNode (f80 (extloadf64 addr:$src2)), RFP80:$src1)))]>;
  220. let mayLoad = 1 in
  221. def _F32m : FPI<0xD8, fp, (outs), (ins f32mem:$src),
  222. !strconcat("f", asmstring, "{s}\t$src")>;
  223. let mayLoad = 1 in
  224. def _F64m : FPI<0xDC, fp, (outs), (ins f64mem:$src),
  225. !strconcat("f", asmstring, "{l}\t$src")>;
  226. // ST(0) = ST(0) + [memint]
  227. def _FpI16m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i16mem:$src2),
  228. OneArgFPRW,
  229. [!if(Forward,
  230. (set RFP32:$dst,
  231. (OpNode RFP32:$src1, (X86fild16 addr:$src2))),
  232. (set RFP32:$dst,
  233. (OpNode (X86fild16 addr:$src2), RFP32:$src1)))]>;
  234. def _FpI32m32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src1, i32mem:$src2),
  235. OneArgFPRW,
  236. [!if(Forward,
  237. (set RFP32:$dst,
  238. (OpNode RFP32:$src1, (X86fild32 addr:$src2))),
  239. (set RFP32:$dst,
  240. (OpNode (X86fild32 addr:$src2), RFP32:$src1)))]>;
  241. def _FpI16m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i16mem:$src2),
  242. OneArgFPRW,
  243. [!if(Forward,
  244. (set RFP64:$dst,
  245. (OpNode RFP64:$src1, (X86fild16 addr:$src2))),
  246. (set RFP64:$dst,
  247. (OpNode (X86fild16 addr:$src2), RFP64:$src1)))]>;
  248. def _FpI32m64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src1, i32mem:$src2),
  249. OneArgFPRW,
  250. [!if(Forward,
  251. (set RFP64:$dst,
  252. (OpNode RFP64:$src1, (X86fild32 addr:$src2))),
  253. (set RFP64:$dst,
  254. (OpNode (X86fild32 addr:$src2), RFP64:$src1)))]>;
  255. def _FpI16m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i16mem:$src2),
  256. OneArgFPRW,
  257. [!if(Forward,
  258. (set RFP80:$dst,
  259. (OpNode RFP80:$src1, (X86fild16 addr:$src2))),
  260. (set RFP80:$dst,
  261. (OpNode (X86fild16 addr:$src2), RFP80:$src1)))]>;
  262. def _FpI32m80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, i32mem:$src2),
  263. OneArgFPRW,
  264. [!if(Forward,
  265. (set RFP80:$dst,
  266. (OpNode RFP80:$src1, (X86fild32 addr:$src2))),
  267. (set RFP80:$dst,
  268. (OpNode (X86fild32 addr:$src2), RFP80:$src1)))]>;
  269. let mayLoad = 1 in
  270. def _FI16m : FPI<0xDE, fp, (outs), (ins i16mem:$src),
  271. !strconcat("fi", asmstring, "{s}\t$src")>;
  272. let mayLoad = 1 in
  273. def _FI32m : FPI<0xDA, fp, (outs), (ins i32mem:$src),
  274. !strconcat("fi", asmstring, "{l}\t$src")>;
  275. }
  276. let Uses = [FPCW], mayRaiseFPException = 1 in {
  277. // FPBinary_rr just defines pseudo-instructions, no need to set a scheduling
  278. // resources.
  279. let hasNoSchedulingInfo = 1 in {
  280. defm ADD : FPBinary_rr<any_fadd>;
  281. defm SUB : FPBinary_rr<any_fsub>;
  282. defm MUL : FPBinary_rr<any_fmul>;
  283. defm DIV : FPBinary_rr<any_fdiv>;
  284. }
  285. // Sets the scheduling resources for the actual NAME#_F<size>m definitions.
  286. let SchedRW = [WriteFAddLd] in {
  287. defm ADD : FPBinary<any_fadd, MRM0m, "add">;
  288. defm SUB : FPBinary<any_fsub, MRM4m, "sub">;
  289. defm SUBR: FPBinary<any_fsub ,MRM5m, "subr", 0>;
  290. }
  291. let SchedRW = [WriteFMulLd] in {
  292. defm MUL : FPBinary<any_fmul, MRM1m, "mul">;
  293. }
  294. let SchedRW = [WriteFDivLd] in {
  295. defm DIV : FPBinary<any_fdiv, MRM6m, "div">;
  296. defm DIVR: FPBinary<any_fdiv, MRM7m, "divr", 0>;
  297. }
  298. } // Uses = [FPCW], mayRaiseFPException = 1
  299. class FPST0rInst<Format fp, string asm>
  300. : FPI<0xD8, fp, (outs), (ins RSTi:$op), asm>;
  301. class FPrST0Inst<Format fp, string asm>
  302. : FPI<0xDC, fp, (outs), (ins RSTi:$op), asm>;
  303. class FPrST0PInst<Format fp, string asm>
  304. : FPI<0xDE, fp, (outs), (ins RSTi:$op), asm>;
  305. // NOTE: GAS and apparently all other AT&T style assemblers have a broken notion
  306. // of some of the 'reverse' forms of the fsub and fdiv instructions. As such,
  307. // we have to put some 'r's in and take them out of weird places.
  308. let SchedRW = [WriteFAdd], Uses = [FPCW], mayRaiseFPException = 1 in {
  309. def ADD_FST0r : FPST0rInst <MRM0r, "fadd\t{$op, %st|st, $op}">;
  310. def ADD_FrST0 : FPrST0Inst <MRM0r, "fadd\t{%st, $op|$op, st}">;
  311. def ADD_FPrST0 : FPrST0PInst<MRM0r, "faddp\t{%st, $op|$op, st}">;
  312. def SUBR_FST0r : FPST0rInst <MRM5r, "fsubr\t{$op, %st|st, $op}">;
  313. def SUB_FrST0 : FPrST0Inst <MRM5r, "fsub{r}\t{%st, $op|$op, st}">;
  314. def SUB_FPrST0 : FPrST0PInst<MRM5r, "fsub{r}p\t{%st, $op|$op, st}">;
  315. def SUB_FST0r : FPST0rInst <MRM4r, "fsub\t{$op, %st|st, $op}">;
  316. def SUBR_FrST0 : FPrST0Inst <MRM4r, "fsub{|r}\t{%st, $op|$op, st}">;
  317. def SUBR_FPrST0 : FPrST0PInst<MRM4r, "fsub{|r}p\t{%st, $op|$op, st}">;
  318. } // SchedRW
  319. let SchedRW = [WriteFCom], Uses = [FPCW], mayRaiseFPException = 1 in {
  320. def COM_FST0r : FPST0rInst <MRM2r, "fcom\t$op">;
  321. def COMP_FST0r : FPST0rInst <MRM3r, "fcomp\t$op">;
  322. } // SchedRW
  323. let SchedRW = [WriteFMul], Uses = [FPCW], mayRaiseFPException = 1 in {
  324. def MUL_FST0r : FPST0rInst <MRM1r, "fmul\t{$op, %st|st, $op}">;
  325. def MUL_FrST0 : FPrST0Inst <MRM1r, "fmul\t{%st, $op|$op, st}">;
  326. def MUL_FPrST0 : FPrST0PInst<MRM1r, "fmulp\t{%st, $op|$op, st}">;
  327. } // SchedRW
  328. let SchedRW = [WriteFDiv], Uses = [FPCW], mayRaiseFPException = 1 in {
  329. def DIVR_FST0r : FPST0rInst <MRM7r, "fdivr\t{$op, %st|st, $op}">;
  330. def DIV_FrST0 : FPrST0Inst <MRM7r, "fdiv{r}\t{%st, $op|$op, st}">;
  331. def DIV_FPrST0 : FPrST0PInst<MRM7r, "fdiv{r}p\t{%st, $op|$op, st}">;
  332. def DIV_FST0r : FPST0rInst <MRM6r, "fdiv\t{$op, %st|st, $op}">;
  333. def DIVR_FrST0 : FPrST0Inst <MRM6r, "fdiv{|r}\t{%st, $op|$op, st}">;
  334. def DIVR_FPrST0 : FPrST0PInst<MRM6r, "fdiv{|r}p\t{%st, $op|$op, st}">;
  335. } // SchedRW
  336. // Unary operations.
  337. multiclass FPUnary<SDPatternOperator OpNode, Format fp, string asmstring> {
  338. def _Fp32 : FpIf32<(outs RFP32:$dst), (ins RFP32:$src), OneArgFPRW,
  339. [(set RFP32:$dst, (OpNode RFP32:$src))]>;
  340. def _Fp64 : FpIf64<(outs RFP64:$dst), (ins RFP64:$src), OneArgFPRW,
  341. [(set RFP64:$dst, (OpNode RFP64:$src))]>;
  342. def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src), OneArgFPRW,
  343. [(set RFP80:$dst, (OpNode RFP80:$src))]>;
  344. def _F : FPI<0xD9, fp, (outs), (ins), asmstring>;
  345. }
  346. let SchedRW = [WriteFSign] in {
  347. defm CHS : FPUnary<fneg, MRM_E0, "fchs">;
  348. defm ABS : FPUnary<fabs, MRM_E1, "fabs">;
  349. }
  350. let Uses = [FPCW], mayRaiseFPException = 1 in {
  351. let SchedRW = [WriteFSqrt80] in
  352. defm SQRT: FPUnary<any_fsqrt,MRM_FA, "fsqrt">;
  353. let SchedRW = [WriteFCom] in {
  354. let hasSideEffects = 0 in {
  355. def TST_Fp32 : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
  356. def TST_Fp64 : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
  357. def TST_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
  358. } // hasSideEffects
  359. def TST_F : FPI<0xD9, MRM_E4, (outs), (ins), "ftst">;
  360. } // SchedRW
  361. } // Uses = [FPCW], mayRaiseFPException = 1
  362. let SchedRW = [WriteFTest], Defs = [FPSW] in {
  363. def XAM_Fp32 : FpIf32<(outs), (ins RFP32:$src), OneArgFP, []>;
  364. def XAM_Fp64 : FpIf64<(outs), (ins RFP64:$src), OneArgFP, []>;
  365. def XAM_Fp80 : FpI_<(outs), (ins RFP80:$src), OneArgFP, []>;
  366. def XAM_F : FPI<0xD9, MRM_E5, (outs), (ins), "fxam">;
  367. } // SchedRW
  368. // Versions of FP instructions that take a single memory operand. Added for the
  369. // disassembler; remove as they are included with patterns elsewhere.
  370. let SchedRW = [WriteFComLd], Uses = [FPCW], mayRaiseFPException = 1,
  371. mayLoad = 1 in {
  372. def FCOM32m : FPI<0xD8, MRM2m, (outs), (ins f32mem:$src), "fcom{s}\t$src">;
  373. def FCOMP32m : FPI<0xD8, MRM3m, (outs), (ins f32mem:$src), "fcomp{s}\t$src">;
  374. def FCOM64m : FPI<0xDC, MRM2m, (outs), (ins f64mem:$src), "fcom{l}\t$src">;
  375. def FCOMP64m : FPI<0xDC, MRM3m, (outs), (ins f64mem:$src), "fcomp{l}\t$src">;
  376. def FICOM16m : FPI<0xDE, MRM2m, (outs), (ins i16mem:$src), "ficom{s}\t$src">;
  377. def FICOMP16m: FPI<0xDE, MRM3m, (outs), (ins i16mem:$src), "ficomp{s}\t$src">;
  378. def FICOM32m : FPI<0xDA, MRM2m, (outs), (ins i32mem:$src), "ficom{l}\t$src">;
  379. def FICOMP32m: FPI<0xDA, MRM3m, (outs), (ins i32mem:$src), "ficomp{l}\t$src">;
  380. } // SchedRW
  381. let SchedRW = [WriteMicrocoded] in {
  382. let Defs = [FPSW, FPCW], mayLoad = 1 in {
  383. def FLDENVm : FPI<0xD9, MRM4m, (outs), (ins anymem:$src), "fldenv\t$src">;
  384. def FRSTORm : FPI<0xDD, MRM4m, (outs), (ins anymem:$src), "frstor\t$src">;
  385. }
  386. let Defs = [FPSW, FPCW], Uses = [FPSW, FPCW], mayStore = 1 in {
  387. def FSTENVm : FPI<0xD9, MRM6m, (outs), (ins anymem:$dst), "fnstenv\t$dst">;
  388. def FSAVEm : FPI<0xDD, MRM6m, (outs), (ins anymem:$dst), "fnsave\t$dst">;
  389. }
  390. let Uses = [FPSW], mayStore = 1 in
  391. def FNSTSWm : FPI<0xDD, MRM7m, (outs), (ins i16mem:$dst), "fnstsw\t$dst">;
  392. let mayLoad = 1 in
  393. def FBLDm : FPI<0xDF, MRM4m, (outs), (ins f80mem:$src), "fbld\t$src">;
  394. let Uses = [FPCW] ,mayRaiseFPException = 1, mayStore = 1 in
  395. def FBSTPm : FPI<0xDF, MRM6m, (outs), (ins f80mem:$dst), "fbstp\t$dst">;
  396. } // SchedRW
  397. // Floating point cmovs.
  398. class FpIf32CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
  399. FpI_<outs, ins, fp, pattern>, Requires<[FPStackf32, HasCMOV]>;
  400. class FpIf64CMov<dag outs, dag ins, FPFormat fp, list<dag> pattern> :
  401. FpI_<outs, ins, fp, pattern>, Requires<[FPStackf64, HasCMOV]>;
  402. multiclass FPCMov<PatLeaf cc> {
  403. def _Fp32 : FpIf32CMov<(outs RFP32:$dst), (ins RFP32:$src1, RFP32:$src2),
  404. CondMovFP,
  405. [(set RFP32:$dst, (X86cmov RFP32:$src1, RFP32:$src2,
  406. cc, EFLAGS))]>;
  407. def _Fp64 : FpIf64CMov<(outs RFP64:$dst), (ins RFP64:$src1, RFP64:$src2),
  408. CondMovFP,
  409. [(set RFP64:$dst, (X86cmov RFP64:$src1, RFP64:$src2,
  410. cc, EFLAGS))]>;
  411. def _Fp80 : FpI_<(outs RFP80:$dst), (ins RFP80:$src1, RFP80:$src2),
  412. CondMovFP,
  413. [(set RFP80:$dst, (X86cmov RFP80:$src1, RFP80:$src2,
  414. cc, EFLAGS))]>,
  415. Requires<[HasCMOV]>;
  416. }
  417. let SchedRW = [WriteFCMOV] in {
  418. let Uses = [EFLAGS], Constraints = "$src1 = $dst" in {
  419. defm CMOVB : FPCMov<X86_COND_B>;
  420. defm CMOVBE : FPCMov<X86_COND_BE>;
  421. defm CMOVE : FPCMov<X86_COND_E>;
  422. defm CMOVP : FPCMov<X86_COND_P>;
  423. defm CMOVNB : FPCMov<X86_COND_AE>;
  424. defm CMOVNBE: FPCMov<X86_COND_A>;
  425. defm CMOVNE : FPCMov<X86_COND_NE>;
  426. defm CMOVNP : FPCMov<X86_COND_NP>;
  427. } // Uses = [EFLAGS], Constraints = "$src1 = $dst"
  428. let Predicates = [HasCMOV] in {
  429. // These are not factored because there's no clean way to pass DA/DB.
  430. def CMOVB_F : FPI<0xDA, MRM0r, (outs), (ins RSTi:$op),
  431. "fcmovb\t{$op, %st|st, $op}">;
  432. def CMOVBE_F : FPI<0xDA, MRM2r, (outs), (ins RSTi:$op),
  433. "fcmovbe\t{$op, %st|st, $op}">;
  434. def CMOVE_F : FPI<0xDA, MRM1r, (outs), (ins RSTi:$op),
  435. "fcmove\t{$op, %st|st, $op}">;
  436. def CMOVP_F : FPI<0xDA, MRM3r, (outs), (ins RSTi:$op),
  437. "fcmovu\t{$op, %st|st, $op}">;
  438. def CMOVNB_F : FPI<0xDB, MRM0r, (outs), (ins RSTi:$op),
  439. "fcmovnb\t{$op, %st|st, $op}">;
  440. def CMOVNBE_F: FPI<0xDB, MRM2r, (outs), (ins RSTi:$op),
  441. "fcmovnbe\t{$op, %st|st, $op}">;
  442. def CMOVNE_F : FPI<0xDB, MRM1r, (outs), (ins RSTi:$op),
  443. "fcmovne\t{$op, %st|st, $op}">;
  444. def CMOVNP_F : FPI<0xDB, MRM3r, (outs), (ins RSTi:$op),
  445. "fcmovnu\t{$op, %st|st, $op}">;
  446. } // Predicates = [HasCMOV]
  447. } // SchedRW
  448. let mayRaiseFPException = 1 in {
  449. // Floating point loads & stores.
  450. let SchedRW = [WriteLoad], Uses = [FPCW] in {
  451. let canFoldAsLoad = 1 in {
  452. def LD_Fp32m : FpIf32<(outs RFP32:$dst), (ins f32mem:$src), ZeroArgFP,
  453. [(set RFP32:$dst, (loadf32 addr:$src))]>;
  454. def LD_Fp64m : FpIf64<(outs RFP64:$dst), (ins f64mem:$src), ZeroArgFP,
  455. [(set RFP64:$dst, (loadf64 addr:$src))]>;
  456. def LD_Fp80m : FpI_<(outs RFP80:$dst), (ins f80mem:$src), ZeroArgFP,
  457. [(set RFP80:$dst, (loadf80 addr:$src))]>;
  458. } // canFoldAsLoad
  459. def LD_Fp32m64 : FpIf64<(outs RFP64:$dst), (ins f32mem:$src), ZeroArgFP,
  460. [(set RFP64:$dst, (f64 (extloadf32 addr:$src)))]>;
  461. def LD_Fp64m80 : FpI_<(outs RFP80:$dst), (ins f64mem:$src), ZeroArgFP,
  462. [(set RFP80:$dst, (f80 (extloadf64 addr:$src)))]>;
  463. def LD_Fp32m80 : FpI_<(outs RFP80:$dst), (ins f32mem:$src), ZeroArgFP,
  464. [(set RFP80:$dst, (f80 (extloadf32 addr:$src)))]>;
  465. let mayRaiseFPException = 0 in {
  466. def ILD_Fp16m32: FpIf32<(outs RFP32:$dst), (ins i16mem:$src), ZeroArgFP,
  467. [(set RFP32:$dst, (X86fild16 addr:$src))]>;
  468. def ILD_Fp32m32: FpIf32<(outs RFP32:$dst), (ins i32mem:$src), ZeroArgFP,
  469. [(set RFP32:$dst, (X86fild32 addr:$src))]>;
  470. def ILD_Fp64m32: FpIf32<(outs RFP32:$dst), (ins i64mem:$src), ZeroArgFP,
  471. [(set RFP32:$dst, (X86fild64 addr:$src))]>;
  472. def ILD_Fp16m64: FpIf64<(outs RFP64:$dst), (ins i16mem:$src), ZeroArgFP,
  473. [(set RFP64:$dst, (X86fild16 addr:$src))]>;
  474. def ILD_Fp32m64: FpIf64<(outs RFP64:$dst), (ins i32mem:$src), ZeroArgFP,
  475. [(set RFP64:$dst, (X86fild32 addr:$src))]>;
  476. def ILD_Fp64m64: FpIf64<(outs RFP64:$dst), (ins i64mem:$src), ZeroArgFP,
  477. [(set RFP64:$dst, (X86fild64 addr:$src))]>;
  478. def ILD_Fp16m80: FpI_<(outs RFP80:$dst), (ins i16mem:$src), ZeroArgFP,
  479. [(set RFP80:$dst, (X86fild16 addr:$src))]>;
  480. def ILD_Fp32m80: FpI_<(outs RFP80:$dst), (ins i32mem:$src), ZeroArgFP,
  481. [(set RFP80:$dst, (X86fild32 addr:$src))]>;
  482. def ILD_Fp64m80: FpI_<(outs RFP80:$dst), (ins i64mem:$src), ZeroArgFP,
  483. [(set RFP80:$dst, (X86fild64 addr:$src))]>;
  484. } // mayRaiseFPException = 0
  485. } // SchedRW
  486. let SchedRW = [WriteStore], Uses = [FPCW] in {
  487. def ST_Fp32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP,
  488. [(store RFP32:$src, addr:$op)]>;
  489. def ST_Fp64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP,
  490. [(truncstoref32 RFP64:$src, addr:$op)]>;
  491. def ST_Fp64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP,
  492. [(store RFP64:$src, addr:$op)]>;
  493. def ST_Fp80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP,
  494. [(truncstoref32 RFP80:$src, addr:$op)]>;
  495. def ST_Fp80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP,
  496. [(truncstoref64 RFP80:$src, addr:$op)]>;
  497. // FST does not support 80-bit memory target; FSTP must be used.
  498. let mayStore = 1, hasSideEffects = 0 in {
  499. def ST_FpP32m : FpIf32<(outs), (ins f32mem:$op, RFP32:$src), OneArgFP, []>;
  500. def ST_FpP64m32 : FpIf64<(outs), (ins f32mem:$op, RFP64:$src), OneArgFP, []>;
  501. def ST_FpP64m : FpIf64<(outs), (ins f64mem:$op, RFP64:$src), OneArgFP, []>;
  502. def ST_FpP80m32 : FpI_<(outs), (ins f32mem:$op, RFP80:$src), OneArgFP, []>;
  503. def ST_FpP80m64 : FpI_<(outs), (ins f64mem:$op, RFP80:$src), OneArgFP, []>;
  504. } // mayStore
  505. def ST_FpP80m : FpI_<(outs), (ins f80mem:$op, RFP80:$src), OneArgFP,
  506. [(store RFP80:$src, addr:$op)]>;
  507. let mayStore = 1, hasSideEffects = 0 in {
  508. def IST_Fp16m32 : FpIf32<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP, []>;
  509. def IST_Fp32m32 : FpIf32<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
  510. [(X86fist32 RFP32:$src, addr:$op)]>;
  511. def IST_Fp64m32 : FpIf32<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
  512. [(X86fist64 RFP32:$src, addr:$op)]>;
  513. def IST_Fp16m64 : FpIf64<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP, []>;
  514. def IST_Fp32m64 : FpIf64<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
  515. [(X86fist32 RFP64:$src, addr:$op)]>;
  516. def IST_Fp64m64 : FpIf64<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
  517. [(X86fist64 RFP64:$src, addr:$op)]>;
  518. def IST_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP, []>;
  519. def IST_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
  520. [(X86fist32 RFP80:$src, addr:$op)]>;
  521. def IST_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
  522. [(X86fist64 RFP80:$src, addr:$op)]>;
  523. } // mayStore
  524. } // SchedRW, Uses = [FPCW]
  525. let mayLoad = 1, SchedRW = [WriteLoad], Uses = [FPCW] in {
  526. def LD_F32m : FPI<0xD9, MRM0m, (outs), (ins f32mem:$src), "fld{s}\t$src">;
  527. def LD_F64m : FPI<0xDD, MRM0m, (outs), (ins f64mem:$src), "fld{l}\t$src">;
  528. def LD_F80m : FPI<0xDB, MRM5m, (outs), (ins f80mem:$src), "fld{t}\t$src">;
  529. let mayRaiseFPException = 0 in {
  530. def ILD_F16m : FPI<0xDF, MRM0m, (outs), (ins i16mem:$src), "fild{s}\t$src">;
  531. def ILD_F32m : FPI<0xDB, MRM0m, (outs), (ins i32mem:$src), "fild{l}\t$src">;
  532. def ILD_F64m : FPI<0xDF, MRM5m, (outs), (ins i64mem:$src), "fild{ll}\t$src">;
  533. }
  534. }
  535. let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
  536. def ST_F32m : FPI<0xD9, MRM2m, (outs), (ins f32mem:$dst), "fst{s}\t$dst">;
  537. def ST_F64m : FPI<0xDD, MRM2m, (outs), (ins f64mem:$dst), "fst{l}\t$dst">;
  538. def ST_FP32m : FPI<0xD9, MRM3m, (outs), (ins f32mem:$dst), "fstp{s}\t$dst">;
  539. def ST_FP64m : FPI<0xDD, MRM3m, (outs), (ins f64mem:$dst), "fstp{l}\t$dst">;
  540. def ST_FP80m : FPI<0xDB, MRM7m, (outs), (ins f80mem:$dst), "fstp{t}\t$dst">;
  541. def IST_F16m : FPI<0xDF, MRM2m, (outs), (ins i16mem:$dst), "fist{s}\t$dst">;
  542. def IST_F32m : FPI<0xDB, MRM2m, (outs), (ins i32mem:$dst), "fist{l}\t$dst">;
  543. def IST_FP16m : FPI<0xDF, MRM3m, (outs), (ins i16mem:$dst), "fistp{s}\t$dst">;
  544. def IST_FP32m : FPI<0xDB, MRM3m, (outs), (ins i32mem:$dst), "fistp{l}\t$dst">;
  545. def IST_FP64m : FPI<0xDF, MRM7m, (outs), (ins i64mem:$dst), "fistp{ll}\t$dst">;
  546. }
  547. // FISTTP requires SSE3 even though it's a FPStack op.
  548. let Predicates = [HasSSE3], SchedRW = [WriteStore], Uses = [FPCW] in {
  549. def ISTT_Fp16m32 : FpI_<(outs), (ins i16mem:$op, RFP32:$src), OneArgFP,
  550. [(X86fp_to_i16mem RFP32:$src, addr:$op)]>;
  551. def ISTT_Fp32m32 : FpI_<(outs), (ins i32mem:$op, RFP32:$src), OneArgFP,
  552. [(X86fp_to_i32mem RFP32:$src, addr:$op)]>;
  553. def ISTT_Fp64m32 : FpI_<(outs), (ins i64mem:$op, RFP32:$src), OneArgFP,
  554. [(X86fp_to_i64mem RFP32:$src, addr:$op)]>;
  555. def ISTT_Fp16m64 : FpI_<(outs), (ins i16mem:$op, RFP64:$src), OneArgFP,
  556. [(X86fp_to_i16mem RFP64:$src, addr:$op)]>;
  557. def ISTT_Fp32m64 : FpI_<(outs), (ins i32mem:$op, RFP64:$src), OneArgFP,
  558. [(X86fp_to_i32mem RFP64:$src, addr:$op)]>;
  559. def ISTT_Fp64m64 : FpI_<(outs), (ins i64mem:$op, RFP64:$src), OneArgFP,
  560. [(X86fp_to_i64mem RFP64:$src, addr:$op)]>;
  561. def ISTT_Fp16m80 : FpI_<(outs), (ins i16mem:$op, RFP80:$src), OneArgFP,
  562. [(X86fp_to_i16mem RFP80:$src, addr:$op)]>;
  563. def ISTT_Fp32m80 : FpI_<(outs), (ins i32mem:$op, RFP80:$src), OneArgFP,
  564. [(X86fp_to_i32mem RFP80:$src, addr:$op)]>;
  565. def ISTT_Fp64m80 : FpI_<(outs), (ins i64mem:$op, RFP80:$src), OneArgFP,
  566. [(X86fp_to_i64mem RFP80:$src, addr:$op)]>;
  567. } // Predicates = [HasSSE3]
  568. let mayStore = 1, SchedRW = [WriteStore], Uses = [FPCW] in {
  569. def ISTT_FP16m : FPI<0xDF, MRM1m, (outs), (ins i16mem:$dst), "fisttp{s}\t$dst">;
  570. def ISTT_FP32m : FPI<0xDB, MRM1m, (outs), (ins i32mem:$dst), "fisttp{l}\t$dst">;
  571. def ISTT_FP64m : FPI<0xDD, MRM1m, (outs), (ins i64mem:$dst), "fisttp{ll}\t$dst">;
  572. }
  573. // FP Stack manipulation instructions.
  574. let SchedRW = [WriteMove], Uses = [FPCW] in {
  575. def LD_Frr : FPI<0xD9, MRM0r, (outs), (ins RSTi:$op), "fld\t$op">;
  576. def ST_Frr : FPI<0xDD, MRM2r, (outs), (ins RSTi:$op), "fst\t$op">;
  577. def ST_FPrr : FPI<0xDD, MRM3r, (outs), (ins RSTi:$op), "fstp\t$op">;
  578. let mayRaiseFPException = 0 in
  579. def XCH_F : FPI<0xD9, MRM1r, (outs), (ins RSTi:$op), "fxch\t$op">;
  580. }
  581. // Floating point constant loads.
  582. let SchedRW = [WriteZero], Uses = [FPCW] in {
  583. def LD_Fp032 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
  584. [(set RFP32:$dst, fpimm0)]>;
  585. def LD_Fp132 : FpIf32<(outs RFP32:$dst), (ins), ZeroArgFP,
  586. [(set RFP32:$dst, fpimm1)]>;
  587. def LD_Fp064 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
  588. [(set RFP64:$dst, fpimm0)]>;
  589. def LD_Fp164 : FpIf64<(outs RFP64:$dst), (ins), ZeroArgFP,
  590. [(set RFP64:$dst, fpimm1)]>;
  591. def LD_Fp080 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
  592. [(set RFP80:$dst, fpimm0)]>;
  593. def LD_Fp180 : FpI_<(outs RFP80:$dst), (ins), ZeroArgFP,
  594. [(set RFP80:$dst, fpimm1)]>;
  595. }
  596. let SchedRW = [WriteFLD0], Uses = [FPCW], mayRaiseFPException = 0 in
  597. def LD_F0 : FPI<0xD9, MRM_EE, (outs), (ins), "fldz">;
  598. let SchedRW = [WriteFLD1], Uses = [FPCW], mayRaiseFPException = 0 in
  599. def LD_F1 : FPI<0xD9, MRM_E8, (outs), (ins), "fld1">;
  600. let SchedRW = [WriteFLDC], Defs = [FPSW], Uses = [FPCW], mayRaiseFPException = 0 in {
  601. def FLDL2T : I<0xD9, MRM_E9, (outs), (ins), "fldl2t", []>;
  602. def FLDL2E : I<0xD9, MRM_EA, (outs), (ins), "fldl2e", []>;
  603. def FLDPI : I<0xD9, MRM_EB, (outs), (ins), "fldpi", []>;
  604. def FLDLG2 : I<0xD9, MRM_EC, (outs), (ins), "fldlg2", []>;
  605. def FLDLN2 : I<0xD9, MRM_ED, (outs), (ins), "fldln2", []>;
  606. } // SchedRW
  607. // Floating point compares.
  608. let SchedRW = [WriteFCom], Uses = [FPCW], hasSideEffects = 0 in {
  609. def UCOM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
  610. def UCOM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
  611. def UCOM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
  612. def COM_Fpr32 : FpIf32<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP, []>;
  613. def COM_Fpr64 : FpIf64<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP, []>;
  614. def COM_Fpr80 : FpI_ <(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP, []>;
  615. } // SchedRW
  616. } // mayRaiseFPException = 1
  617. let SchedRW = [WriteFCom], mayRaiseFPException = 1 in {
  618. // CC = ST(0) cmp ST(i)
  619. let Defs = [EFLAGS, FPSW], Uses = [FPCW] in {
  620. def UCOM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
  621. [(set EFLAGS, (X86any_fcmp RFP32:$lhs, RFP32:$rhs))]>,
  622. Requires<[FPStackf32, HasCMOV]>;
  623. def UCOM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
  624. [(set EFLAGS, (X86any_fcmp RFP64:$lhs, RFP64:$rhs))]>,
  625. Requires<[FPStackf64, HasCMOV]>;
  626. def UCOM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
  627. [(set EFLAGS, (X86any_fcmp RFP80:$lhs, RFP80:$rhs))]>,
  628. Requires<[HasCMOV]>;
  629. def COM_FpIr32: FpI_<(outs), (ins RFP32:$lhs, RFP32:$rhs), CompareFP,
  630. [(set EFLAGS, (X86strict_fcmps RFP32:$lhs, RFP32:$rhs))]>,
  631. Requires<[FPStackf32, HasCMOV]>;
  632. def COM_FpIr64: FpI_<(outs), (ins RFP64:$lhs, RFP64:$rhs), CompareFP,
  633. [(set EFLAGS, (X86strict_fcmps RFP64:$lhs, RFP64:$rhs))]>,
  634. Requires<[FPStackf64, HasCMOV]>;
  635. def COM_FpIr80: FpI_<(outs), (ins RFP80:$lhs, RFP80:$rhs), CompareFP,
  636. [(set EFLAGS, (X86strict_fcmps RFP80:$lhs, RFP80:$rhs))]>,
  637. Requires<[HasCMOV]>;
  638. }
  639. let Uses = [ST0, FPCW] in {
  640. def UCOM_Fr : FPI<0xDD, MRM4r, // FPSW = cmp ST(0) with ST(i)
  641. (outs), (ins RSTi:$reg), "fucom\t$reg">;
  642. def UCOM_FPr : FPI<0xDD, MRM5r, // FPSW = cmp ST(0) with ST(i), pop
  643. (outs), (ins RSTi:$reg), "fucomp\t$reg">;
  644. def UCOM_FPPr : FPI<0xDA, MRM_E9, // cmp ST(0) with ST(1), pop, pop
  645. (outs), (ins), "fucompp">;
  646. }
  647. let Defs = [EFLAGS, FPSW], Uses = [ST0, FPCW] in {
  648. def UCOM_FIr : FPI<0xDB, MRM5r, // CC = cmp ST(0) with ST(i)
  649. (outs), (ins RSTi:$reg), "fucomi\t{$reg, %st|st, $reg}">;
  650. def UCOM_FIPr : FPI<0xDF, MRM5r, // CC = cmp ST(0) with ST(i), pop
  651. (outs), (ins RSTi:$reg), "fucompi\t{$reg, %st|st, $reg}">;
  652. def COM_FIr : FPI<0xDB, MRM6r, (outs), (ins RSTi:$reg),
  653. "fcomi\t{$reg, %st|st, $reg}">;
  654. def COM_FIPr : FPI<0xDF, MRM6r, (outs), (ins RSTi:$reg),
  655. "fcompi\t{$reg, %st|st, $reg}">;
  656. }
  657. } // SchedRW
  658. // Floating point flag ops.
  659. let SchedRW = [WriteALU] in {
  660. let Defs = [AX, FPSW], Uses = [FPSW], hasSideEffects = 0 in
  661. def FNSTSW16r : I<0xDF, MRM_E0, // AX = fp flags
  662. (outs), (ins), "fnstsw\t{%ax|ax}", []>;
  663. let Defs = [FPSW], Uses = [FPCW] in
  664. def FNSTCW16m : I<0xD9, MRM7m, // [mem16] = X87 control world
  665. (outs), (ins i16mem:$dst), "fnstcw\t$dst",
  666. [(X86fp_cwd_get16 addr:$dst)]>;
  667. } // SchedRW
  668. let Defs = [FPSW,FPCW], mayLoad = 1 in
  669. def FLDCW16m : I<0xD9, MRM5m, // X87 control world = [mem16]
  670. (outs), (ins i16mem:$dst), "fldcw\t$dst",
  671. [(X86fp_cwd_set16 addr:$dst)]>,
  672. Sched<[WriteLoad]>;
  673. // FPU control instructions
  674. let SchedRW = [WriteMicrocoded] in {
  675. def FFREE : FPI<0xDD, MRM0r, (outs), (ins RSTi:$reg), "ffree\t$reg">;
  676. def FFREEP : FPI<0xDF, MRM0r, (outs), (ins RSTi:$reg), "ffreep\t$reg">;
  677. let Defs = [FPSW, FPCW] in
  678. def FNINIT : I<0xDB, MRM_E3, (outs), (ins), "fninit", []>;
  679. // Clear exceptions
  680. let Defs = [FPSW] in
  681. def FNCLEX : I<0xDB, MRM_E2, (outs), (ins), "fnclex", []>;
  682. } // SchedRW
  683. // Operand-less floating-point instructions for the disassembler.
  684. let Defs = [FPSW] in
  685. def FNOP : I<0xD9, MRM_D0, (outs), (ins), "fnop", []>, Sched<[WriteNop]>;
  686. let SchedRW = [WriteMicrocoded] in {
  687. let Defs = [FPSW] in {
  688. def WAIT : I<0x9B, RawFrm, (outs), (ins), "wait", []>;
  689. def FDECSTP : I<0xD9, MRM_F6, (outs), (ins), "fdecstp", []>;
  690. def FINCSTP : I<0xD9, MRM_F7, (outs), (ins), "fincstp", []>;
  691. let Uses = [FPCW], mayRaiseFPException = 1 in {
  692. def F2XM1 : I<0xD9, MRM_F0, (outs), (ins), "f2xm1", []>;
  693. def FYL2X : I<0xD9, MRM_F1, (outs), (ins), "fyl2x", []>;
  694. def FPTAN : I<0xD9, MRM_F2, (outs), (ins), "fptan", []>;
  695. def FPATAN : I<0xD9, MRM_F3, (outs), (ins), "fpatan", []>;
  696. def FXTRACT : I<0xD9, MRM_F4, (outs), (ins), "fxtract", []>;
  697. def FPREM1 : I<0xD9, MRM_F5, (outs), (ins), "fprem1", []>;
  698. def FPREM : I<0xD9, MRM_F8, (outs), (ins), "fprem", []>;
  699. def FYL2XP1 : I<0xD9, MRM_F9, (outs), (ins), "fyl2xp1", []>;
  700. def FSIN : I<0xD9, MRM_FE, (outs), (ins), "fsin", []>;
  701. def FCOS : I<0xD9, MRM_FF, (outs), (ins), "fcos", []>;
  702. def FSINCOS : I<0xD9, MRM_FB, (outs), (ins), "fsincos", []>;
  703. def FRNDINT : I<0xD9, MRM_FC, (outs), (ins), "frndint", []>;
  704. def FSCALE : I<0xD9, MRM_FD, (outs), (ins), "fscale", []>;
  705. def FCOMPP : I<0xDE, MRM_D9, (outs), (ins), "fcompp", []>;
  706. } // Uses = [FPCW], mayRaiseFPException = 1
  707. } // Defs = [FPSW]
  708. let Uses = [FPSW, FPCW] in {
  709. def FXSAVE : I<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
  710. "fxsave\t$dst", [(int_x86_fxsave addr:$dst)]>, PS,
  711. Requires<[HasFXSR]>;
  712. def FXSAVE64 : RI<0xAE, MRM0m, (outs), (ins opaquemem:$dst),
  713. "fxsave64\t$dst", [(int_x86_fxsave64 addr:$dst)]>,
  714. PS, Requires<[HasFXSR, In64BitMode]>;
  715. } // Uses = [FPSW, FPCW]
  716. let Defs = [FPSW, FPCW] in {
  717. def FXRSTOR : I<0xAE, MRM1m, (outs), (ins opaquemem:$src),
  718. "fxrstor\t$src", [(int_x86_fxrstor addr:$src)]>,
  719. PS, Requires<[HasFXSR]>;
  720. def FXRSTOR64 : RI<0xAE, MRM1m, (outs), (ins opaquemem:$src),
  721. "fxrstor64\t$src", [(int_x86_fxrstor64 addr:$src)]>,
  722. PS, Requires<[HasFXSR, In64BitMode]>;
  723. } // Defs = [FPSW, FPCW]
  724. } // SchedRW
  725. //===----------------------------------------------------------------------===//
  726. // Non-Instruction Patterns
  727. //===----------------------------------------------------------------------===//
  728. // Required for RET of f32 / f64 / f80 values.
  729. def : Pat<(X86fldf32 addr:$src), (LD_Fp32m addr:$src)>;
  730. def : Pat<(X86fldf32 addr:$src), (LD_Fp32m64 addr:$src)>;
  731. def : Pat<(X86fldf64 addr:$src), (LD_Fp64m addr:$src)>;
  732. def : Pat<(X86fldf32 addr:$src), (LD_Fp32m80 addr:$src)>;
  733. def : Pat<(X86fldf64 addr:$src), (LD_Fp64m80 addr:$src)>;
  734. def : Pat<(X86fldf80 addr:$src), (LD_Fp80m addr:$src)>;
  735. // Required for CALL which return f32 / f64 / f80 values.
  736. def : Pat<(X86fstf32 RFP32:$src, addr:$op), (ST_Fp32m addr:$op, RFP32:$src)>;
  737. def : Pat<(X86fstf32 RFP64:$src, addr:$op), (ST_Fp64m32 addr:$op, RFP64:$src)>;
  738. def : Pat<(X86fstf64 RFP64:$src, addr:$op), (ST_Fp64m addr:$op, RFP64:$src)>;
  739. def : Pat<(X86fstf32 RFP80:$src, addr:$op), (ST_Fp80m32 addr:$op, RFP80:$src)>;
  740. def : Pat<(X86fstf64 RFP80:$src, addr:$op), (ST_Fp80m64 addr:$op, RFP80:$src)>;
  741. def : Pat<(X86fstf80 RFP80:$src, addr:$op), (ST_FpP80m addr:$op, RFP80:$src)>;
  742. // Floating point constant -0.0 and -1.0
  743. def : Pat<(f32 fpimmneg0), (CHS_Fp32 (LD_Fp032))>, Requires<[FPStackf32]>;
  744. def : Pat<(f32 fpimmneg1), (CHS_Fp32 (LD_Fp132))>, Requires<[FPStackf32]>;
  745. def : Pat<(f64 fpimmneg0), (CHS_Fp64 (LD_Fp064))>, Requires<[FPStackf64]>;
  746. def : Pat<(f64 fpimmneg1), (CHS_Fp64 (LD_Fp164))>, Requires<[FPStackf64]>;
  747. def : Pat<(f80 fpimmneg0), (CHS_Fp80 (LD_Fp080))>;
  748. def : Pat<(f80 fpimmneg1), (CHS_Fp80 (LD_Fp180))>;
  749. // FP extensions map onto simple pseudo-value conversions if they are to/from
  750. // the FP stack.
  751. def : Pat<(f64 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP64)>,
  752. Requires<[FPStackf32]>;
  753. def : Pat<(f80 (any_fpextend RFP32:$src)), (COPY_TO_REGCLASS RFP32:$src, RFP80)>,
  754. Requires<[FPStackf32]>;
  755. def : Pat<(f80 (any_fpextend RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP80)>,
  756. Requires<[FPStackf64]>;
  757. // FP truncations map onto simple pseudo-value conversions if they are to/from
  758. // the FP stack. We have validated that only value-preserving truncations make
  759. // it through isel.
  760. def : Pat<(f32 (any_fpround RFP64:$src)), (COPY_TO_REGCLASS RFP64:$src, RFP32)>,
  761. Requires<[FPStackf32]>;
  762. def : Pat<(f32 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP32)>,
  763. Requires<[FPStackf32]>;
  764. def : Pat<(f64 (any_fpround RFP80:$src)), (COPY_TO_REGCLASS RFP80:$src, RFP64)>,
  765. Requires<[FPStackf64]>;