X86InstrFPStack.td 40 KB

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