X86ScheduleBtVer2.td 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. //=- X86ScheduleBtVer2.td - X86 BtVer2 (Jaguar) Scheduling ---*- 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 defines the machine model for AMD btver2 (Jaguar) to support
  10. // instruction scheduling and other instruction cost heuristics. Based off AMD Software
  11. // Optimization Guide for AMD Family 16h Processors & Instruction Latency appendix.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. def BtVer2Model : SchedMachineModel {
  15. // All x86 instructions are modeled as a single micro-op, and btver2 can
  16. // decode 2 instructions per cycle.
  17. let IssueWidth = 2;
  18. let MicroOpBufferSize = 64; // Retire Control Unit
  19. let LoadLatency = 5; // FPU latency (worse case cf Integer 3 cycle latency)
  20. let HighLatency = 25;
  21. let MispredictPenalty = 14; // Minimum branch misdirection penalty
  22. let PostRAScheduler = 1;
  23. // FIXME: SSE4/AVX is unimplemented. This flag is set to allow
  24. // the scheduler to assign a default model to unrecognized opcodes.
  25. let CompleteModel = 0;
  26. }
  27. let SchedModel = BtVer2Model in {
  28. // Jaguar can issue up to 6 micro-ops in one cycle
  29. def JALU0 : ProcResource<1>; // Integer Pipe0: integer ALU0 (also handle FP->INT jam)
  30. def JALU1 : ProcResource<1>; // Integer Pipe1: integer ALU1/MUL/DIV
  31. def JLAGU : ProcResource<1>; // Integer Pipe2: LAGU
  32. def JSAGU : ProcResource<1>; // Integer Pipe3: SAGU (also handles 3-operand LEA)
  33. def JFPU0 : ProcResource<1>; // Vector/FPU Pipe0: VALU0/VIMUL/FPA
  34. def JFPU1 : ProcResource<1>; // Vector/FPU Pipe1: VALU1/STC/FPM
  35. // The Integer PRF for Jaguar is 64 entries, and it holds the architectural and
  36. // speculative version of the 64-bit integer registers.
  37. // Reference: www.realworldtech.com/jaguar/4/
  38. //
  39. // The processor always keeps the different parts of an integer register
  40. // together. An instruction that writes to a part of a register will therefore
  41. // have a false dependence on any previous write to the same register or any
  42. // part of it.
  43. // Reference: Section 21.10 "AMD Bobcat and Jaguar pipeline: Partial register
  44. // access" - Agner Fog's "microarchitecture.pdf".
  45. def JIntegerPRF : RegisterFile<64, [GR64, CCR], [1, 1], [1, 0],
  46. 0, // Max moves that can be eliminated per cycle.
  47. 1>; // Restrict move elimination to zero regs.
  48. // The Jaguar FP Retire Queue renames SIMD and FP uOps onto a pool of 72 SSE
  49. // registers. Operations on 256-bit data types are cracked into two COPs.
  50. // Reference: www.realworldtech.com/jaguar/4/
  51. // The PRF in the floating point unit can eliminate a move from a MMX or SSE
  52. // register that is know to be zero (i.e. it has been zeroed using a zero-idiom
  53. // dependency breaking instruction, or via VZEROALL).
  54. // Reference: Section 21.8 "AMD Bobcat and Jaguar pipeline: Dependency-breaking
  55. // instructions" - Agner Fog's "microarchitecture.pdf"
  56. def JFpuPRF: RegisterFile<72, [VR64, VR128, VR256], [1, 1, 2], [1, 1, 0],
  57. 0, // Max moves that can be eliminated per cycle.
  58. 1>; // Restrict move elimination to zero regs.
  59. // The retire control unit (RCU) can track up to 64 macro-ops in-flight. It can
  60. // retire up to two macro-ops per cycle.
  61. // Reference: "Software Optimization Guide for AMD Family 16h Processors"
  62. def JRCU : RetireControlUnit<64, 2>;
  63. // Integer Pipe Scheduler
  64. def JALU01 : ProcResGroup<[JALU0, JALU1]> {
  65. let BufferSize=20;
  66. }
  67. // AGU Pipe Scheduler
  68. def JLSAGU : ProcResGroup<[JLAGU, JSAGU]> {
  69. let BufferSize=12;
  70. }
  71. // Fpu Pipe Scheduler
  72. def JFPU01 : ProcResGroup<[JFPU0, JFPU1]> {
  73. let BufferSize=18;
  74. }
  75. // Functional units
  76. def JDiv : ProcResource<1>; // integer division
  77. def JMul : ProcResource<1>; // integer multiplication
  78. def JVALU0 : ProcResource<1>; // vector integer
  79. def JVALU1 : ProcResource<1>; // vector integer
  80. def JVIMUL : ProcResource<1>; // vector integer multiplication
  81. def JSTC : ProcResource<1>; // vector store/convert
  82. def JFPM : ProcResource<1>; // FP multiplication
  83. def JFPA : ProcResource<1>; // FP addition
  84. // Functional unit groups
  85. def JFPX : ProcResGroup<[JFPA, JFPM]>;
  86. def JVALU : ProcResGroup<[JVALU0, JVALU1]>;
  87. // Integer loads are 3 cycles, so ReadAfterLd registers needn't be available until 3
  88. // cycles after the memory operand.
  89. def : ReadAdvance<ReadAfterLd, 3>;
  90. // Vector loads are 5 cycles, so ReadAfterVec*Ld registers needn't be available until 5
  91. // cycles after the memory operand.
  92. def : ReadAdvance<ReadAfterVecLd, 5>;
  93. def : ReadAdvance<ReadAfterVecXLd, 5>;
  94. def : ReadAdvance<ReadAfterVecYLd, 5>;
  95. /// "Additional 6 cycle transfer operation which moves a floating point
  96. /// operation input value from the integer unit to the floating point unit.
  97. /// Reference: AMDfam16h SOG (Appendix A "Instruction Latencies", Section A.2).
  98. def : ReadAdvance<ReadInt2Fpu, -6>;
  99. // Many SchedWrites are defined in pairs with and without a folded load.
  100. // Instructions with folded loads are usually micro-fused, so they only appear
  101. // as two micro-ops when dispatched by the schedulers.
  102. // This multiclass defines the resource usage for variants with and without
  103. // folded loads.
  104. multiclass JWriteResIntPair<X86FoldableSchedWrite SchedRW,
  105. list<ProcResourceKind> ExePorts,
  106. int Lat, list<int> Res = [], int UOps = 1,
  107. int LoadUOps = 0> {
  108. // Register variant is using a single cycle on ExePort.
  109. def : WriteRes<SchedRW, ExePorts> {
  110. let Latency = Lat;
  111. let ResourceCycles = Res;
  112. let NumMicroOps = UOps;
  113. }
  114. // Memory variant also uses a cycle on JLAGU and adds 3 cycles to the
  115. // latency.
  116. def : WriteRes<SchedRW.Folded, !listconcat([JLAGU], ExePorts)> {
  117. let Latency = !add(Lat, 3);
  118. let ResourceCycles = !if(!empty(Res), [], !listconcat([1], Res));
  119. let NumMicroOps = !add(UOps, LoadUOps);
  120. }
  121. }
  122. multiclass JWriteResFpuPair<X86FoldableSchedWrite SchedRW,
  123. list<ProcResourceKind> ExePorts,
  124. int Lat, list<int> Res = [], int UOps = 1,
  125. int LoadUOps = 0> {
  126. // Register variant is using a single cycle on ExePort.
  127. def : WriteRes<SchedRW, ExePorts> {
  128. let Latency = Lat;
  129. let ResourceCycles = Res;
  130. let NumMicroOps = UOps;
  131. }
  132. // Memory variant also uses a cycle on JLAGU and adds 5 cycles to the
  133. // latency.
  134. def : WriteRes<SchedRW.Folded, !listconcat([JLAGU], ExePorts)> {
  135. let Latency = !add(Lat, 5);
  136. let ResourceCycles = !if(!empty(Res), [], !listconcat([1], Res));
  137. let NumMicroOps = !add(UOps, LoadUOps);
  138. }
  139. }
  140. multiclass JWriteResYMMPair<X86FoldableSchedWrite SchedRW,
  141. list<ProcResourceKind> ExePorts,
  142. int Lat, list<int> Res = [2], int UOps = 2,
  143. int LoadUOps = 0> {
  144. // Register variant is using a single cycle on ExePort.
  145. def : WriteRes<SchedRW, ExePorts> {
  146. let Latency = Lat;
  147. let ResourceCycles = Res;
  148. let NumMicroOps = UOps;
  149. }
  150. // Memory variant also uses 2 cycles on JLAGU and adds 5 cycles to the
  151. // latency.
  152. def : WriteRes<SchedRW.Folded, !listconcat([JLAGU], ExePorts)> {
  153. let Latency = !add(Lat, 5);
  154. let ResourceCycles = !listconcat([2], Res);
  155. let NumMicroOps = !add(UOps, LoadUOps);
  156. }
  157. }
  158. // Instructions that have local forwarding disabled have an extra +1cy latency.
  159. // A folded store needs a cycle on the SAGU for the store data, most RMW
  160. // instructions don't need an extra uop. ALU RMW operations don't seem to
  161. // benefit from STLF, and their observed latency is 6cy. That is the reason why
  162. // this write adds two extra cycles (instead of just 1cy for the store).
  163. defm : X86WriteRes<WriteRMW, [JSAGU], 2, [1], 0>;
  164. ////////////////////////////////////////////////////////////////////////////////
  165. // Arithmetic.
  166. ////////////////////////////////////////////////////////////////////////////////
  167. defm : JWriteResIntPair<WriteALU, [JALU01], 1>;
  168. defm : JWriteResIntPair<WriteADC, [JALU01], 1, [2]>;
  169. defm : X86WriteRes<WriteBSWAP32, [JALU01], 1, [1], 1>;
  170. defm : X86WriteRes<WriteBSWAP64, [JALU01], 1, [1], 1>;
  171. defm : X86WriteRes<WriteCMPXCHG, [JALU01], 3, [3], 5>;
  172. defm : X86WriteRes<WriteCMPXCHGRMW, [JALU01, JSAGU, JLAGU], 11, [3, 1, 1], 6>;
  173. defm : X86WriteRes<WriteXCHG, [JALU01], 1, [2], 2>;
  174. defm : JWriteResIntPair<WriteIMul8, [JALU1, JMul], 3, [1, 1], 1>;
  175. defm : JWriteResIntPair<WriteIMul16, [JALU1, JMul], 3, [1, 3], 3>;
  176. defm : JWriteResIntPair<WriteIMul16Imm, [JALU1, JMul], 4, [1, 2], 2>;
  177. defm : JWriteResIntPair<WriteIMul16Reg, [JALU1, JMul], 3, [1, 1], 1>;
  178. defm : JWriteResIntPair<WriteIMul32, [JALU1, JMul], 3, [1, 2], 2>;
  179. defm : JWriteResIntPair<WriteIMul32Imm, [JALU1, JMul], 3, [1, 1], 1>;
  180. defm : JWriteResIntPair<WriteIMul32Reg, [JALU1, JMul], 3, [1, 1], 1>;
  181. defm : JWriteResIntPair<WriteIMul64, [JALU1, JMul], 6, [1, 4], 2>;
  182. defm : JWriteResIntPair<WriteIMul64Imm, [JALU1, JMul], 6, [1, 4], 1>;
  183. defm : JWriteResIntPair<WriteIMul64Reg, [JALU1, JMul], 6, [1, 4], 1>;
  184. defm : X86WriteResUnsupported<WriteIMulH>;
  185. defm : X86WriteResUnsupported<WriteIMulHLd>;
  186. defm : X86WriteResPairUnsupported<WriteMULX32>;
  187. defm : X86WriteResPairUnsupported<WriteMULX64>;
  188. defm : JWriteResIntPair<WriteDiv8, [JALU1, JDiv], 12, [1, 12], 1>;
  189. defm : JWriteResIntPair<WriteDiv16, [JALU1, JDiv], 17, [1, 17], 2>;
  190. defm : JWriteResIntPair<WriteDiv32, [JALU1, JDiv], 25, [1, 25], 2>;
  191. defm : JWriteResIntPair<WriteDiv64, [JALU1, JDiv], 41, [1, 41], 2>;
  192. defm : JWriteResIntPair<WriteIDiv8, [JALU1, JDiv], 12, [1, 12], 1>;
  193. defm : JWriteResIntPair<WriteIDiv16, [JALU1, JDiv], 17, [1, 17], 2>;
  194. defm : JWriteResIntPair<WriteIDiv32, [JALU1, JDiv], 25, [1, 25], 2>;
  195. defm : JWriteResIntPair<WriteIDiv64, [JALU1, JDiv], 41, [1, 41], 2>;
  196. defm : JWriteResIntPair<WriteCRC32, [JALU01], 3, [4], 3>;
  197. defm : JWriteResIntPair<WriteCMOV, [JALU01], 1>; // Conditional move.
  198. defm : X86WriteRes<WriteFCMOV, [JFPU0, JFPA], 3, [1,1], 1>; // x87 conditional move.
  199. def : WriteRes<WriteSETCC, [JALU01]>; // Setcc.
  200. def : WriteRes<WriteSETCCStore, [JALU01,JSAGU]>;
  201. def : WriteRes<WriteLAHFSAHF, [JALU01]>;
  202. defm : X86WriteRes<WriteBitTest, [JALU01], 1, [1], 1>;
  203. defm : X86WriteRes<WriteBitTestImmLd, [JALU01,JLAGU], 4, [1,1], 1>;
  204. defm : X86WriteRes<WriteBitTestRegLd, [JALU01,JLAGU], 4, [1,1], 5>;
  205. defm : X86WriteRes<WriteBitTestSet, [JALU01], 1, [1], 2>;
  206. defm : X86WriteRes<WriteBitTestSetImmLd, [JALU01,JLAGU], 4, [1,1], 4>;
  207. defm : X86WriteRes<WriteBitTestSetRegLd, [JALU01,JLAGU], 4, [1,1], 8>;
  208. // This is for simple LEAs with one or two input operands.
  209. def : WriteRes<WriteLEA, [JALU01]>;
  210. // Bit counts.
  211. defm : JWriteResIntPair<WriteBSF, [JALU01], 4, [8], 7>;
  212. defm : JWriteResIntPair<WriteBSR, [JALU01], 5, [8], 8>;
  213. defm : JWriteResIntPair<WritePOPCNT, [JALU01], 1>;
  214. defm : JWriteResIntPair<WriteLZCNT, [JALU01], 1>;
  215. defm : JWriteResIntPair<WriteTZCNT, [JALU01], 2, [2], 2>;
  216. // BMI1 BEXTR/BLS, BMI2 BZHI
  217. defm : JWriteResIntPair<WriteBEXTR, [JALU01], 1>;
  218. defm : JWriteResIntPair<WriteBLS, [JALU01], 2, [2], 2>;
  219. defm : X86WriteResPairUnsupported<WriteBZHI>;
  220. ////////////////////////////////////////////////////////////////////////////////
  221. // Integer shifts and rotates.
  222. ////////////////////////////////////////////////////////////////////////////////
  223. defm : JWriteResIntPair<WriteShift, [JALU01], 1>;
  224. defm : JWriteResIntPair<WriteShiftCL, [JALU01], 1>;
  225. defm : JWriteResIntPair<WriteRotate, [JALU01], 1>;
  226. defm : JWriteResIntPair<WriteRotateCL, [JALU01], 1>;
  227. // SHLD/SHRD.
  228. defm : X86WriteRes<WriteSHDrri, [JALU01], 3, [6], 6>;
  229. defm : X86WriteRes<WriteSHDrrcl,[JALU01], 4, [8], 7>;
  230. defm : X86WriteRes<WriteSHDmri, [JLAGU, JALU01], 9, [1, 22], 8>;
  231. defm : X86WriteRes<WriteSHDmrcl,[JLAGU, JALU01], 9, [1, 22], 8>;
  232. ////////////////////////////////////////////////////////////////////////////////
  233. // Loads, stores, and moves, not folded with other operations.
  234. ////////////////////////////////////////////////////////////////////////////////
  235. def : WriteRes<WriteLoad, [JLAGU]> { let Latency = 3; }
  236. def : WriteRes<WriteStore, [JSAGU]>;
  237. def : WriteRes<WriteStoreNT, [JSAGU]>;
  238. def : WriteRes<WriteMove, [JALU01]>;
  239. defm : X86WriteResUnsupported<WriteVecMaskedGatherWriteback>;
  240. // Load/store MXCSR.
  241. def : WriteRes<WriteLDMXCSR, [JLAGU]> { let Latency = 3; }
  242. def : WriteRes<WriteSTMXCSR, [JSAGU]>;
  243. // Treat misc copies as a move.
  244. def : InstRW<[WriteMove], (instrs COPY)>;
  245. ////////////////////////////////////////////////////////////////////////////////
  246. // Idioms that clear a register, like xorps %xmm0, %xmm0.
  247. // These can often bypass execution ports completely.
  248. ////////////////////////////////////////////////////////////////////////////////
  249. def : WriteRes<WriteZero, []>;
  250. ////////////////////////////////////////////////////////////////////////////////
  251. // Branches don't produce values, so they have no latency, but they still
  252. // consume resources. Indirect branches can fold loads.
  253. ////////////////////////////////////////////////////////////////////////////////
  254. defm : JWriteResIntPair<WriteJump, [JALU01], 1>;
  255. ////////////////////////////////////////////////////////////////////////////////
  256. // Special case scheduling classes.
  257. ////////////////////////////////////////////////////////////////////////////////
  258. def : WriteRes<WriteSystem, [JALU01]> { let Latency = 100; }
  259. def : WriteRes<WriteMicrocoded, [JALU01]> { let Latency = 100; }
  260. def : WriteRes<WriteFence, [JSAGU]>;
  261. // Nops don't have dependencies, so there's no actual latency, but we set this
  262. // to '1' to tell the scheduler that the nop uses an ALU slot for a cycle.
  263. def : WriteRes<WriteNop, [JALU01]> { let Latency = 1; }
  264. def JWriteCMPXCHG8rr : SchedWriteRes<[JALU01]> {
  265. let Latency = 3;
  266. let ResourceCycles = [3];
  267. let NumMicroOps = 3;
  268. }
  269. def JWriteLOCK_CMPXCHG8rm : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  270. let Latency = 16;
  271. let ResourceCycles = [3,16,16];
  272. let NumMicroOps = 5;
  273. }
  274. def JWriteLOCK_CMPXCHGrm : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  275. let Latency = 17;
  276. let ResourceCycles = [3,17,17];
  277. let NumMicroOps = 6;
  278. }
  279. def JWriteCMPXCHG8rm : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  280. let Latency = 11;
  281. let ResourceCycles = [3,1,1];
  282. let NumMicroOps = 5;
  283. }
  284. def JWriteCMPXCHG8B : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  285. let Latency = 11;
  286. let ResourceCycles = [3,1,1];
  287. let NumMicroOps = 18;
  288. }
  289. def JWriteCMPXCHG16B : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  290. let Latency = 32;
  291. let ResourceCycles = [6,1,1];
  292. let NumMicroOps = 28;
  293. }
  294. def JWriteLOCK_CMPXCHG8B : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  295. let Latency = 19;
  296. let ResourceCycles = [3,19,19];
  297. let NumMicroOps = 18;
  298. }
  299. def JWriteLOCK_CMPXCHG16B : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  300. let Latency = 38;
  301. let ResourceCycles = [6,38,38];
  302. let NumMicroOps = 28;
  303. }
  304. def JWriteCMPXCHGVariant : SchedWriteVariant<[
  305. SchedVar<MCSchedPredicate<IsAtomicCompareAndSwap8B>, [JWriteLOCK_CMPXCHG8B]>,
  306. SchedVar<MCSchedPredicate<IsAtomicCompareAndSwap16B>, [JWriteLOCK_CMPXCHG16B]>,
  307. SchedVar<MCSchedPredicate<IsAtomicCompareAndSwap_8>, [JWriteLOCK_CMPXCHG8rm]>,
  308. SchedVar<MCSchedPredicate<IsAtomicCompareAndSwap>, [JWriteLOCK_CMPXCHGrm]>,
  309. SchedVar<MCSchedPredicate<IsCompareAndSwap8B>, [JWriteCMPXCHG8B]>,
  310. SchedVar<MCSchedPredicate<IsCompareAndSwap16B>, [JWriteCMPXCHG16B]>,
  311. SchedVar<MCSchedPredicate<IsRegMemCompareAndSwap_8>, [JWriteCMPXCHG8rm]>,
  312. SchedVar<MCSchedPredicate<IsRegMemCompareAndSwap>, [WriteCMPXCHGRMW]>,
  313. SchedVar<MCSchedPredicate<IsRegRegCompareAndSwap_8>, [JWriteCMPXCHG8rr]>,
  314. SchedVar<NoSchedPred, [WriteCMPXCHG]>
  315. ]>;
  316. // The first five reads are contributed by the memory load operand.
  317. // We ignore those reads and set a read-advance for the other input operands
  318. // including the implicit read of RAX.
  319. def : InstRW<[JWriteCMPXCHGVariant,
  320. ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  321. ReadAfterLd, ReadAfterLd], (instrs LCMPXCHG8, LCMPXCHG16,
  322. LCMPXCHG32, LCMPXCHG64,
  323. CMPXCHG8rm, CMPXCHG16rm,
  324. CMPXCHG32rm, CMPXCHG64rm)>;
  325. def : InstRW<[JWriteCMPXCHGVariant], (instrs CMPXCHG8rr, CMPXCHG16rr,
  326. CMPXCHG32rr, CMPXCHG64rr)>;
  327. def : InstRW<[JWriteCMPXCHGVariant,
  328. // Ignore reads contributed by the memory operand.
  329. ReadDefault, ReadDefault, ReadDefault, ReadDefault, ReadDefault,
  330. // Add a read-advance to every implicit register read.
  331. ReadAfterLd, ReadAfterLd, ReadAfterLd, ReadAfterLd], (instrs LCMPXCHG8B, LCMPXCHG16B,
  332. CMPXCHG8B, CMPXCHG16B)>;
  333. def JWriteLOCK_ALURMW : SchedWriteRes<[JALU01, JLAGU, JSAGU]> {
  334. let Latency = 19;
  335. let ResourceCycles = [1,19,19];
  336. let NumMicroOps = 1;
  337. }
  338. def JWriteLOCK_ALURMWVariant : SchedWriteVariant<[
  339. SchedVar<MCSchedPredicate<CheckLockPrefix>, [JWriteLOCK_ALURMW]>,
  340. SchedVar<NoSchedPred, [WriteALURMW]>
  341. ]>;
  342. def : InstRW<[JWriteLOCK_ALURMWVariant], (instrs INC8m, INC16m, INC32m, INC64m,
  343. DEC8m, DEC16m, DEC32m, DEC64m,
  344. NOT8m, NOT16m, NOT32m, NOT64m,
  345. NEG8m, NEG16m, NEG32m, NEG64m)>;
  346. def JWriteXCHG8rr_XADDrr : SchedWriteRes<[JALU01]> {
  347. let Latency = 2;
  348. let ResourceCycles = [3];
  349. let NumMicroOps = 3;
  350. }
  351. def : InstRW<[JWriteXCHG8rr_XADDrr], (instrs XCHG8rr, XADD8rr, XADD16rr,
  352. XADD32rr, XADD64rr)>;
  353. // This write defines the latency of the in/out register operand of a non-atomic
  354. // XADDrm. This is the first of a pair of writes that model non-atomic
  355. // XADDrm instructions (the second write definition is JWriteXADDrm_LdSt_Part).
  356. //
  357. // We need two writes because the instruction latency differs from the output
  358. // register operand latency. In particular, the first write describes the first
  359. // (and only) output register operand of the instruction. However, the
  360. // instruction latency is set to the MAX of all the write latencies. That's why
  361. // a second write is needed in this case (see example below).
  362. //
  363. // Example:
  364. // XADD %ecx, (%rsp) ## Instruction latency: 11cy
  365. // ## ECX write Latency: 3cy
  366. //
  367. // Register ECX becomes available in 3 cycles. That is because the value of ECX
  368. // is exchanged with the value read from the stack pointer, and the load-to-use
  369. // latency is assumed to be 3cy.
  370. def JWriteXADDrm_XCHG_Part : SchedWriteRes<[JALU01]> {
  371. let Latency = 3; // load-to-use latency
  372. let ResourceCycles = [3];
  373. let NumMicroOps = 3;
  374. }
  375. // This write defines the latency of the in/out register operand of an atomic
  376. // XADDrm. This is the first of a sequence of two writes used to model atomic
  377. // XADD instructions. The second write of the sequence is JWriteXCHGrm_LdSt_Part.
  378. //
  379. //
  380. // Example:
  381. // LOCK XADD %ecx, (%rsp) ## Instruction Latency: 16cy
  382. // ## ECX write Latency: 11cy
  383. //
  384. // The value of ECX becomes available only after 11cy from the start of
  385. // execution. This write is used to specifically set that operand latency.
  386. def JWriteLOCK_XADDrm_XCHG_Part : SchedWriteRes<[JALU01]> {
  387. let Latency = 11;
  388. let ResourceCycles = [3];
  389. let NumMicroOps = 3;
  390. }
  391. // This write defines the latency of the in/out register operand of an atomic
  392. // XCHGrm. This write is the first of a sequence of two writes that describe
  393. // atomic XCHG operations. We need two writes because the instruction latency
  394. // differs from the output register write latency. We want to make sure that
  395. // the output register operand becomes visible after 11cy. However, we want to
  396. // set the instruction latency to 16cy.
  397. def JWriteXCHGrm_XCHG_Part : SchedWriteRes<[JALU01]> {
  398. let Latency = 11;
  399. let ResourceCycles = [2];
  400. let NumMicroOps = 2;
  401. }
  402. def JWriteXADDrm_LdSt_Part : SchedWriteRes<[JLAGU, JSAGU]> {
  403. let Latency = 11;
  404. let ResourceCycles = [1, 1];
  405. let NumMicroOps = 1;
  406. }
  407. def JWriteXCHGrm_LdSt_Part : SchedWriteRes<[JLAGU, JSAGU]> {
  408. let Latency = 16;
  409. let ResourceCycles = [16, 16];
  410. let NumMicroOps = 1;
  411. }
  412. def JWriteXADDrm_Part1 : SchedWriteVariant<[
  413. SchedVar<MCSchedPredicate<CheckLockPrefix>, [JWriteLOCK_XADDrm_XCHG_Part]>,
  414. SchedVar<NoSchedPred, [JWriteXADDrm_XCHG_Part]>
  415. ]>;
  416. def JWriteXADDrm_Part2 : SchedWriteVariant<[
  417. SchedVar<MCSchedPredicate<CheckLockPrefix>, [JWriteXCHGrm_LdSt_Part]>,
  418. SchedVar<NoSchedPred, [JWriteXADDrm_LdSt_Part]>
  419. ]>;
  420. def : InstRW<[JWriteXADDrm_Part1, JWriteXADDrm_Part2, ReadAfterLd],
  421. (instrs XADD8rm, XADD16rm, XADD32rm, XADD64rm,
  422. LXADD8, LXADD16, LXADD32, LXADD64)>;
  423. def : InstRW<[JWriteXCHGrm_XCHG_Part, JWriteXCHGrm_LdSt_Part, ReadAfterLd],
  424. (instrs XCHG8rm, XCHG16rm, XCHG32rm, XCHG64rm)>;
  425. ////////////////////////////////////////////////////////////////////////////////
  426. // Floating point. This covers both scalar and vector operations.
  427. ////////////////////////////////////////////////////////////////////////////////
  428. defm : X86WriteRes<WriteFLD0, [JFPU1, JSTC], 3, [1,1], 1>;
  429. defm : X86WriteRes<WriteFLD1, [JFPU1, JSTC], 3, [1,1], 1>;
  430. defm : X86WriteRes<WriteFLDC, [JFPU1, JSTC], 3, [1,1], 1>;
  431. defm : X86WriteRes<WriteFLoad, [JLAGU, JFPU01, JFPX], 5, [1, 1, 1], 1>;
  432. defm : X86WriteRes<WriteFLoadX, [JLAGU], 5, [1], 1>;
  433. defm : X86WriteRes<WriteFLoadY, [JLAGU], 5, [2], 2>;
  434. defm : X86WriteRes<WriteFMaskedLoad, [JLAGU, JFPU01, JFPX], 6, [1, 2, 2], 1>;
  435. defm : X86WriteRes<WriteFMaskedLoadY, [JLAGU, JFPU01, JFPX], 6, [2, 4, 4], 2>;
  436. defm : X86WriteRes<WriteFStore, [JSAGU, JFPU1, JSTC], 2, [1, 1, 1], 1>;
  437. defm : X86WriteRes<WriteFStoreX, [JSAGU, JFPU1, JSTC], 1, [1, 1, 1], 1>;
  438. defm : X86WriteRes<WriteFStoreY, [JSAGU, JFPU1, JSTC], 1, [2, 2, 2], 2>;
  439. defm : X86WriteRes<WriteFStoreNT, [JSAGU, JFPU1, JSTC], 3, [1, 1, 1], 1>;
  440. defm : X86WriteRes<WriteFStoreNTX, [JSAGU, JFPU1, JSTC], 3, [1, 1, 1], 1>;
  441. defm : X86WriteRes<WriteFStoreNTY, [JSAGU, JFPU1, JSTC], 3, [2, 2, 2], 1>;
  442. defm : X86WriteRes<WriteFMaskedStore32, [JFPU0, JFPA, JFPU1, JSTC, JLAGU, JSAGU, JALU01], 16, [1,1, 5, 5,4,4,4], 19>;
  443. defm : X86WriteRes<WriteFMaskedStore64, [JFPU0, JFPA, JFPU1, JSTC, JLAGU, JSAGU, JALU01], 13, [1,1, 2, 2,2,2,2], 10>;
  444. defm : X86WriteRes<WriteFMaskedStore32Y, [JFPU0, JFPA, JFPU1, JSTC, JLAGU, JSAGU, JALU01], 22, [1,1,10,10,8,8,8], 36>;
  445. defm : X86WriteRes<WriteFMaskedStore64Y, [JFPU0, JFPA, JFPU1, JSTC, JLAGU, JSAGU, JALU01], 16, [1,1, 4, 4,4,4,4], 18>;
  446. defm : X86WriteRes<WriteFMove, [JFPU01, JFPX], 1, [1, 1], 1>;
  447. defm : X86WriteRes<WriteFMoveX, [JFPU01, JFPX], 1, [1, 1], 1>;
  448. defm : X86WriteRes<WriteFMoveY, [JFPU01, JFPX], 1, [2, 2], 2>;
  449. defm : X86WriteResUnsupported<WriteFMoveZ>;
  450. defm : X86WriteRes<WriteEMMS, [JFPU01, JFPX], 2, [1, 1], 1>;
  451. defm : JWriteResFpuPair<WriteFAdd, [JFPU0, JFPA], 3>;
  452. defm : JWriteResFpuPair<WriteFAddX, [JFPU0, JFPA], 3>;
  453. defm : JWriteResYMMPair<WriteFAddY, [JFPU0, JFPA], 3, [2,2], 2>;
  454. defm : X86WriteResPairUnsupported<WriteFAddZ>;
  455. defm : JWriteResFpuPair<WriteFAdd64, [JFPU0, JFPA], 3>;
  456. defm : JWriteResFpuPair<WriteFAdd64X, [JFPU0, JFPA], 3>;
  457. defm : JWriteResYMMPair<WriteFAdd64Y, [JFPU0, JFPA], 3, [2,2], 2>;
  458. defm : X86WriteResPairUnsupported<WriteFAdd64Z>;
  459. defm : JWriteResFpuPair<WriteFCmp, [JFPU0, JFPA], 2>;
  460. defm : JWriteResFpuPair<WriteFCmpX, [JFPU0, JFPA], 2>;
  461. defm : JWriteResYMMPair<WriteFCmpY, [JFPU0, JFPA], 2, [2,2], 2>;
  462. defm : X86WriteResPairUnsupported<WriteFCmpZ>;
  463. defm : JWriteResFpuPair<WriteFCmp64, [JFPU0, JFPA], 2>;
  464. defm : JWriteResFpuPair<WriteFCmp64X, [JFPU0, JFPA], 2>;
  465. defm : JWriteResYMMPair<WriteFCmp64Y, [JFPU0, JFPA], 2, [2,2], 2>;
  466. defm : X86WriteResPairUnsupported<WriteFCmp64Z>;
  467. defm : JWriteResFpuPair<WriteFCom, [JFPU0, JFPA, JALU0], 3>;
  468. defm : JWriteResFpuPair<WriteFComX, [JFPU0, JFPA, JALU0], 3>;
  469. defm : JWriteResFpuPair<WriteFMul, [JFPU1, JFPM], 2>;
  470. defm : JWriteResFpuPair<WriteFMulX, [JFPU1, JFPM], 2>;
  471. defm : JWriteResYMMPair<WriteFMulY, [JFPU1, JFPM], 2, [2,2], 2>;
  472. defm : X86WriteResPairUnsupported<WriteFMulZ>;
  473. defm : JWriteResFpuPair<WriteFMul64, [JFPU1, JFPM], 4, [1,2]>;
  474. defm : JWriteResFpuPair<WriteFMul64X, [JFPU1, JFPM], 4, [1,2]>;
  475. defm : JWriteResYMMPair<WriteFMul64Y, [JFPU1, JFPM], 4, [2,4], 2>;
  476. defm : X86WriteResPairUnsupported<WriteFMul64Z>;
  477. defm : X86WriteResPairUnsupported<WriteFMA>;
  478. defm : X86WriteResPairUnsupported<WriteFMAX>;
  479. defm : X86WriteResPairUnsupported<WriteFMAY>;
  480. defm : X86WriteResPairUnsupported<WriteFMAZ>;
  481. defm : JWriteResFpuPair<WriteDPPD, [JFPU1, JFPM, JFPA], 9, [1, 3, 3], 3>;
  482. defm : JWriteResFpuPair<WriteDPPS, [JFPU1, JFPM, JFPA], 11, [1, 3, 3], 5>;
  483. defm : JWriteResYMMPair<WriteDPPSY, [JFPU1, JFPM, JFPA], 12, [2, 6, 6], 10>;
  484. defm : JWriteResFpuPair<WriteFRcp, [JFPU1, JFPM], 2>;
  485. defm : JWriteResFpuPair<WriteFRcpX, [JFPU1, JFPM], 2>;
  486. defm : JWriteResYMMPair<WriteFRcpY, [JFPU1, JFPM], 2, [2,2], 2>;
  487. defm : X86WriteResPairUnsupported<WriteFRcpZ>;
  488. defm : JWriteResFpuPair<WriteFRsqrt, [JFPU1, JFPM], 2>;
  489. defm : JWriteResFpuPair<WriteFRsqrtX, [JFPU1, JFPM], 2>;
  490. defm : JWriteResYMMPair<WriteFRsqrtY, [JFPU1, JFPM], 2, [2,2], 2>;
  491. defm : X86WriteResPairUnsupported<WriteFRsqrtZ>;
  492. defm : JWriteResFpuPair<WriteFDiv, [JFPU1, JFPM], 19, [1, 19]>;
  493. defm : JWriteResFpuPair<WriteFDivX, [JFPU1, JFPM], 19, [1, 19]>;
  494. defm : JWriteResYMMPair<WriteFDivY, [JFPU1, JFPM], 38, [2, 38], 2>;
  495. defm : X86WriteResPairUnsupported<WriteFDivZ>;
  496. defm : JWriteResFpuPair<WriteFDiv64, [JFPU1, JFPM], 19, [1, 19]>;
  497. defm : JWriteResFpuPair<WriteFDiv64X, [JFPU1, JFPM], 19, [1, 19]>;
  498. defm : JWriteResYMMPair<WriteFDiv64Y, [JFPU1, JFPM], 38, [2, 38], 2>;
  499. defm : X86WriteResPairUnsupported<WriteFDiv64Z>;
  500. defm : JWriteResFpuPair<WriteFSqrt, [JFPU1, JFPM], 21, [1, 21]>;
  501. defm : JWriteResFpuPair<WriteFSqrtX, [JFPU1, JFPM], 21, [1, 21]>;
  502. defm : JWriteResYMMPair<WriteFSqrtY, [JFPU1, JFPM], 42, [2, 42], 2>;
  503. defm : X86WriteResPairUnsupported<WriteFSqrtZ>;
  504. defm : JWriteResFpuPair<WriteFSqrt64, [JFPU1, JFPM], 27, [1, 27]>;
  505. defm : JWriteResFpuPair<WriteFSqrt64X, [JFPU1, JFPM], 27, [1, 27]>;
  506. defm : JWriteResYMMPair<WriteFSqrt64Y, [JFPU1, JFPM], 54, [2, 54], 2>;
  507. defm : X86WriteResPairUnsupported<WriteFSqrt64Z>;
  508. defm : JWriteResFpuPair<WriteFSqrt80, [JFPU1, JFPM], 35, [1, 35]>;
  509. defm : JWriteResFpuPair<WriteFSign, [JFPU1, JFPM], 2>;
  510. defm : JWriteResFpuPair<WriteFRnd, [JFPU1, JSTC], 3>;
  511. defm : JWriteResYMMPair<WriteFRndY, [JFPU1, JSTC], 3, [2,2], 2>;
  512. defm : X86WriteResPairUnsupported<WriteFRndZ>;
  513. defm : JWriteResFpuPair<WriteFLogic, [JFPU01, JFPX], 1>;
  514. defm : JWriteResYMMPair<WriteFLogicY, [JFPU01, JFPX], 1, [2, 2], 2>;
  515. defm : X86WriteResPairUnsupported<WriteFLogicZ>;
  516. defm : JWriteResFpuPair<WriteFTest, [JFPU0, JFPA, JALU0], 3>;
  517. defm : JWriteResYMMPair<WriteFTestY , [JFPU01, JFPX, JFPA, JALU0], 4, [2, 2, 2, 1], 3>;
  518. defm : X86WriteResPairUnsupported<WriteFTestZ>;
  519. defm : JWriteResFpuPair<WriteFShuffle, [JFPU01, JFPX], 1>;
  520. defm : JWriteResYMMPair<WriteFShuffleY, [JFPU01, JFPX], 1, [2, 2], 2>;
  521. defm : X86WriteResPairUnsupported<WriteFShuffleZ>;
  522. defm : JWriteResFpuPair<WriteFVarShuffle, [JFPU01, JFPX], 3, [1, 4], 3>; // +1cy latency.
  523. defm : JWriteResYMMPair<WriteFVarShuffleY,[JFPU01, JFPX], 4, [2, 6], 6>; // +1cy latency.
  524. defm : X86WriteResPairUnsupported<WriteFVarShuffleZ>;
  525. defm : JWriteResFpuPair<WriteFBlend, [JFPU01, JFPX], 1>;
  526. defm : JWriteResYMMPair<WriteFBlendY, [JFPU01, JFPX], 1, [2, 2], 2>;
  527. defm : X86WriteResPairUnsupported<WriteFBlendZ>;
  528. defm : JWriteResFpuPair<WriteFVarBlend, [JFPU01, JFPX], 2, [4, 4], 3>;
  529. defm : JWriteResYMMPair<WriteFVarBlendY, [JFPU01, JFPX], 3, [6, 6], 6>;
  530. defm : X86WriteResPairUnsupported<WriteFVarBlendZ>;
  531. defm : JWriteResFpuPair<WriteFShuffle256, [JFPU01, JFPX], 1, [2, 2], 2>;
  532. defm : X86WriteResPairUnsupported<WriteFVarShuffle256>;
  533. ////////////////////////////////////////////////////////////////////////////////
  534. // Conversions.
  535. ////////////////////////////////////////////////////////////////////////////////
  536. defm : JWriteResFpuPair<WriteCvtSS2I, [JFPU1, JSTC, JFPU0, JFPA, JALU0], 7, [1,1,1,1,1], 2>;
  537. defm : JWriteResFpuPair<WriteCvtPS2I, [JFPU1, JSTC], 3, [1,1], 1>;
  538. defm : JWriteResYMMPair<WriteCvtPS2IY, [JFPU1, JSTC], 3, [2,2], 2>;
  539. defm : X86WriteResPairUnsupported<WriteCvtPS2IZ>;
  540. defm : JWriteResFpuPair<WriteCvtSD2I, [JFPU1, JSTC, JFPU0, JFPA, JALU0], 7, [1,1,1,1,1], 2>;
  541. defm : JWriteResFpuPair<WriteCvtPD2I, [JFPU1, JSTC], 3, [1,1], 1>;
  542. defm : JWriteResYMMPair<WriteCvtPD2IY, [JFPU1, JSTC, JFPX], 6, [2,2,4], 3>;
  543. defm : X86WriteResPairUnsupported<WriteCvtPD2IZ>;
  544. defm : X86WriteRes<WriteCvtI2SS, [JFPU1, JSTC], 4, [1,1], 2>;
  545. defm : X86WriteRes<WriteCvtI2SSLd, [JLAGU, JFPU1, JSTC], 9, [1,1,1], 1>;
  546. defm : JWriteResFpuPair<WriteCvtI2PS, [JFPU1, JSTC], 3, [1,1], 1>;
  547. defm : JWriteResYMMPair<WriteCvtI2PSY, [JFPU1, JSTC], 3, [2,2], 2>;
  548. defm : X86WriteResPairUnsupported<WriteCvtI2PSZ>;
  549. defm : X86WriteRes<WriteCvtI2SD, [JFPU1, JSTC], 4, [1,1], 2>;
  550. defm : X86WriteRes<WriteCvtI2SDLd, [JLAGU, JFPU1, JSTC], 9, [1,1,1], 1>;
  551. defm : JWriteResFpuPair<WriteCvtI2PD, [JFPU1, JSTC], 3, [1,1], 1>;
  552. defm : JWriteResYMMPair<WriteCvtI2PDY, [JFPU1, JSTC], 3, [2,2], 2>;
  553. defm : X86WriteResPairUnsupported<WriteCvtI2PDZ>;
  554. defm : JWriteResFpuPair<WriteCvtSS2SD, [JFPU1, JSTC], 7, [1,2], 2>;
  555. defm : JWriteResFpuPair<WriteCvtPS2PD, [JFPU1, JSTC], 2, [1,1], 1>;
  556. defm : JWriteResYMMPair<WriteCvtPS2PDY, [JFPU1, JSTC], 2, [2,2], 2>;
  557. defm : X86WriteResPairUnsupported<WriteCvtPS2PDZ>;
  558. defm : JWriteResFpuPair<WriteCvtSD2SS, [JFPU1, JSTC], 7, [1,2], 2>;
  559. defm : JWriteResFpuPair<WriteCvtPD2PS, [JFPU1, JSTC], 3, [1,1], 1>;
  560. defm : JWriteResYMMPair<WriteCvtPD2PSY, [JFPU1, JSTC, JFPX], 6, [2,2,4], 3>;
  561. defm : X86WriteResPairUnsupported<WriteCvtPD2PSZ>;
  562. defm : JWriteResFpuPair<WriteCvtPH2PS, [JFPU1, JSTC], 3, [1,1], 1>;
  563. defm : JWriteResYMMPair<WriteCvtPH2PSY, [JFPU1, JSTC], 3, [2,2], 2>;
  564. defm : X86WriteResPairUnsupported<WriteCvtPH2PSZ>;
  565. defm : X86WriteRes<WriteCvtPS2PH, [JFPU1, JSTC], 3, [1,1], 1>;
  566. defm : X86WriteRes<WriteCvtPS2PHY, [JFPU1, JSTC, JFPX], 6, [2,2,2], 3>;
  567. defm : X86WriteResUnsupported<WriteCvtPS2PHZ>;
  568. defm : X86WriteRes<WriteCvtPS2PHSt, [JFPU1, JSTC, JSAGU], 4, [1,1,1], 1>;
  569. defm : X86WriteRes<WriteCvtPS2PHYSt, [JFPU1, JSTC, JFPX, JSAGU], 7, [2,2,2,1], 3>;
  570. defm : X86WriteResUnsupported<WriteCvtPS2PHZSt>;
  571. ////////////////////////////////////////////////////////////////////////////////
  572. // Vector integer operations.
  573. ////////////////////////////////////////////////////////////////////////////////
  574. defm : X86WriteRes<WriteVecLoad, [JLAGU, JFPU01, JVALU], 5, [1, 1, 1], 1>;
  575. defm : X86WriteRes<WriteVecLoadX, [JLAGU], 5, [1], 1>;
  576. defm : X86WriteRes<WriteVecLoadY, [JLAGU], 5, [2], 2>;
  577. defm : X86WriteRes<WriteVecLoadNT, [JLAGU, JFPU01, JVALU], 5, [1, 1, 1], 1>;
  578. defm : X86WriteRes<WriteVecLoadNTY, [JLAGU, JFPU01, JVALU], 5, [1, 1, 1], 1>;
  579. defm : X86WriteRes<WriteVecMaskedLoad, [JLAGU, JFPU01, JVALU], 6, [1, 2, 2], 1>;
  580. defm : X86WriteRes<WriteVecMaskedLoadY, [JLAGU, JFPU01, JVALU], 6, [2, 4, 4], 2>;
  581. defm : X86WriteRes<WriteVecStore, [JSAGU, JFPU1, JSTC], 2, [1, 1, 1], 1>;
  582. defm : X86WriteRes<WriteVecStoreX, [JSAGU, JFPU1, JSTC], 1, [1, 1, 1], 1>;
  583. defm : X86WriteRes<WriteVecStoreY, [JSAGU, JFPU1, JSTC], 1, [2, 2, 2], 2>;
  584. defm : X86WriteRes<WriteVecStoreNT, [JSAGU, JFPU1, JSTC], 2, [1, 1, 1], 1>;
  585. defm : X86WriteRes<WriteVecStoreNTY, [JSAGU, JFPU1, JSTC], 2, [2, 2, 2], 1>;
  586. defm : X86WriteResUnsupported<WriteVecMaskedStore32>;
  587. defm : X86WriteResUnsupported<WriteVecMaskedStore64>;
  588. defm : X86WriteResUnsupported<WriteVecMaskedStore32Y>;
  589. defm : X86WriteResUnsupported<WriteVecMaskedStore64Y>;
  590. defm : X86WriteRes<WriteVecMove, [JFPU01, JVALU], 1, [1, 1], 1>;
  591. defm : X86WriteRes<WriteVecMoveX, [JFPU01, JVALU], 1, [1, 1], 1>;
  592. defm : X86WriteRes<WriteVecMoveY, [JFPU01, JVALU], 1, [2, 2], 2>;
  593. defm : X86WriteResUnsupported<WriteVecMoveZ>;
  594. defm : X86WriteRes<WriteVecMoveToGpr, [JFPU0, JFPA, JALU0], 4, [1, 1, 1], 1>;
  595. defm : X86WriteRes<WriteVecMoveFromGpr, [JFPU01, JFPX], 8, [1, 1], 2>;
  596. defm : JWriteResFpuPair<WriteVecALU, [JFPU01, JVALU], 1>;
  597. defm : JWriteResFpuPair<WriteVecALUX, [JFPU01, JVALU], 1>;
  598. defm : X86WriteResPairUnsupported<WriteVecALUY>;
  599. defm : X86WriteResPairUnsupported<WriteVecALUZ>;
  600. defm : JWriteResFpuPair<WriteVecShift, [JFPU01, JVALU], 1>;
  601. defm : JWriteResFpuPair<WriteVecShiftX, [JFPU01, JVALU], 2>; // +1cy latency.
  602. defm : X86WriteResPairUnsupported<WriteVecShiftY>;
  603. defm : X86WriteResPairUnsupported<WriteVecShiftZ>;
  604. defm : JWriteResFpuPair<WriteVecShiftImm, [JFPU01, JVALU], 1>;
  605. defm : JWriteResFpuPair<WriteVecShiftImmX,[JFPU01, JVALU], 2>; // +1cy latency.
  606. defm : X86WriteResPairUnsupported<WriteVecShiftImmY>;
  607. defm : X86WriteResPairUnsupported<WriteVecShiftImmZ>;
  608. defm : X86WriteResPairUnsupported<WriteVarVecShift>;
  609. defm : X86WriteResPairUnsupported<WriteVarVecShiftY>;
  610. defm : X86WriteResPairUnsupported<WriteVarVecShiftZ>;
  611. defm : JWriteResFpuPair<WriteVecIMul, [JFPU0, JVIMUL], 2>;
  612. defm : JWriteResFpuPair<WriteVecIMulX, [JFPU0, JVIMUL], 2>;
  613. defm : X86WriteResPairUnsupported<WriteVecIMulY>;
  614. defm : X86WriteResPairUnsupported<WriteVecIMulZ>;
  615. defm : JWriteResFpuPair<WritePMULLD, [JFPU0, JFPU01, JVIMUL, JVALU], 4, [2, 1, 2, 1], 3>;
  616. defm : X86WriteResPairUnsupported<WritePMULLDY>;
  617. defm : X86WriteResPairUnsupported<WritePMULLDZ>;
  618. defm : JWriteResFpuPair<WriteMPSAD, [JFPU0, JVIMUL], 3, [1, 2], 3>;
  619. defm : X86WriteResPairUnsupported<WriteMPSADY>;
  620. defm : X86WriteResPairUnsupported<WriteMPSADZ>;
  621. defm : JWriteResFpuPair<WritePSADBW, [JFPU01, JVALU], 2>;
  622. defm : JWriteResFpuPair<WritePSADBWX, [JFPU01, JVALU], 2>;
  623. defm : X86WriteResPairUnsupported<WritePSADBWY>;
  624. defm : X86WriteResPairUnsupported<WritePSADBWZ>;
  625. defm : JWriteResFpuPair<WritePHMINPOS, [JFPU01, JVALU], 2>;
  626. defm : JWriteResFpuPair<WriteShuffle, [JFPU01, JVALU], 1>;
  627. defm : JWriteResFpuPair<WriteShuffleX, [JFPU01, JVALU], 1>;
  628. defm : X86WriteResPairUnsupported<WriteShuffleY>;
  629. defm : X86WriteResPairUnsupported<WriteShuffleZ>;
  630. defm : JWriteResFpuPair<WriteVarShuffle, [JFPU01, JVALU], 2, [1, 1], 1>;
  631. defm : JWriteResFpuPair<WriteVarShuffleX, [JFPU01, JVALU], 2, [1, 4], 3>;
  632. defm : X86WriteResPairUnsupported<WriteVarShuffleY>;
  633. defm : X86WriteResPairUnsupported<WriteVarShuffleZ>;
  634. defm : JWriteResFpuPair<WriteBlend, [JFPU01, JVALU], 1>;
  635. defm : X86WriteResPairUnsupported<WriteBlendY>;
  636. defm : X86WriteResPairUnsupported<WriteBlendZ>;
  637. defm : JWriteResFpuPair<WriteVarBlend, [JFPU01, JVALU], 2, [4, 4], 3>;
  638. defm : X86WriteResPairUnsupported<WriteVarBlendY>;
  639. defm : X86WriteResPairUnsupported<WriteVarBlendZ>;
  640. defm : JWriteResFpuPair<WriteVecLogic, [JFPU01, JVALU], 1>;
  641. defm : JWriteResFpuPair<WriteVecLogicX, [JFPU01, JVALU], 1>;
  642. defm : X86WriteResPairUnsupported<WriteVecLogicY>;
  643. defm : X86WriteResPairUnsupported<WriteVecLogicZ>;
  644. defm : JWriteResFpuPair<WriteVecTest, [JFPU0, JFPA, JALU0], 3>;
  645. defm : JWriteResYMMPair<WriteVecTestY, [JFPU01, JFPX, JFPA, JALU0], 4, [2, 2, 2, 1], 3>;
  646. defm : X86WriteResPairUnsupported<WriteVecTestZ>;
  647. defm : X86WriteResPairUnsupported<WriteShuffle256>;
  648. defm : X86WriteResPairUnsupported<WriteVPMOV256>;
  649. defm : X86WriteResPairUnsupported<WriteVarShuffle256>;
  650. ////////////////////////////////////////////////////////////////////////////////
  651. // Vector insert/extract operations.
  652. ////////////////////////////////////////////////////////////////////////////////
  653. defm : X86WriteRes<WriteVecInsert, [JFPU01, JVALU], 1, [1,1], 2>;
  654. defm : X86WriteRes<WriteVecInsertLd, [JFPU01, JVALU, JLAGU], 4, [1,1,1], 1>;
  655. defm : X86WriteRes<WriteVecExtract, [JFPU0, JFPA, JALU0], 3, [1,1,1], 1>;
  656. defm : X86WriteRes<WriteVecExtractSt, [JFPU1, JSTC, JSAGU], 3, [1,1,1], 1>;
  657. ////////////////////////////////////////////////////////////////////////////////
  658. // SSE42 String instructions.
  659. ////////////////////////////////////////////////////////////////////////////////
  660. defm : JWriteResFpuPair<WritePCmpIStrI, [JFPU1, JVALU1, JFPU0, JFPA, JALU0], 7, [2, 2, 1, 1, 1], 3>;
  661. defm : JWriteResFpuPair<WritePCmpIStrM, [JFPU1, JVALU1, JFPU0, JFPA, JALU0], 8, [2, 2, 1, 1, 1], 3>;
  662. defm : JWriteResFpuPair<WritePCmpEStrI, [JFPU1, JSAGU, JLAGU, JVALU, JVALU1, JFPA, JALU0], 14, [1, 2, 2, 6, 4, 1, 1], 9>;
  663. defm : JWriteResFpuPair<WritePCmpEStrM, [JFPU1, JSAGU, JLAGU, JVALU, JVALU1, JFPA, JALU0], 14, [1, 2, 2, 6, 4, 1, 1], 9>;
  664. ////////////////////////////////////////////////////////////////////////////////
  665. // MOVMSK Instructions.
  666. ////////////////////////////////////////////////////////////////////////////////
  667. def : WriteRes<WriteFMOVMSK, [JFPU0, JFPA, JALU0]> { let Latency = 3; }
  668. def : WriteRes<WriteVecMOVMSK, [JFPU0, JFPA, JALU0]> { let Latency = 3; }
  669. defm : X86WriteResUnsupported<WriteVecMOVMSKY>;
  670. def : WriteRes<WriteMMXMOVMSK, [JFPU0, JFPA, JALU0]> { let Latency = 3; }
  671. ////////////////////////////////////////////////////////////////////////////////
  672. // AES Instructions.
  673. ////////////////////////////////////////////////////////////////////////////////
  674. defm : JWriteResFpuPair<WriteAESIMC, [JFPU0, JVIMUL], 2>;
  675. defm : JWriteResFpuPair<WriteAESKeyGen, [JFPU0, JVIMUL], 2>;
  676. defm : JWriteResFpuPair<WriteAESDecEnc, [JFPU01, JVALU, JFPU0, JVIMUL], 3, [1,1,1,1], 2>;
  677. ////////////////////////////////////////////////////////////////////////////////
  678. // Horizontal add/sub instructions.
  679. ////////////////////////////////////////////////////////////////////////////////
  680. defm : JWriteResFpuPair<WriteFHAdd, [JFPU0, JFPA], 4>; // +1cy latency.
  681. defm : JWriteResYMMPair<WriteFHAddY, [JFPU0, JFPA], 4, [2,2], 2>; // +1cy latency.
  682. defm : JWriteResFpuPair<WritePHAdd, [JFPU01, JVALU], 1>;
  683. defm : JWriteResFpuPair<WritePHAddX, [JFPU01, JVALU], 2>; // +1cy latency.
  684. defm : X86WriteResPairUnsupported<WritePHAddY>;
  685. ////////////////////////////////////////////////////////////////////////////////
  686. // Carry-less multiplication instructions.
  687. ////////////////////////////////////////////////////////////////////////////////
  688. defm : JWriteResFpuPair<WriteCLMul, [JFPU0, JVIMUL], 2>;
  689. ////////////////////////////////////////////////////////////////////////////////
  690. // SSE4A instructions.
  691. ////////////////////////////////////////////////////////////////////////////////
  692. def JWriteINSERTQ: SchedWriteRes<[JFPU01, JVALU]> {
  693. let Latency = 2;
  694. let ResourceCycles = [1, 4];
  695. }
  696. def : InstRW<[JWriteINSERTQ], (instrs INSERTQ, INSERTQI)>;
  697. ////////////////////////////////////////////////////////////////////////////////
  698. // AVX instructions.
  699. ////////////////////////////////////////////////////////////////////////////////
  700. def JWriteVecExtractF128: SchedWriteRes<[JFPU01, JFPX]>;
  701. def : InstRW<[JWriteVecExtractF128], (instrs VEXTRACTF128rr)>;
  702. def JWriteVBROADCASTYLd: SchedWriteRes<[JLAGU, JFPU01, JFPX]> {
  703. let Latency = 6;
  704. let ResourceCycles = [1, 2, 4];
  705. let NumMicroOps = 2;
  706. }
  707. def : InstRW<[JWriteVBROADCASTYLd], (instrs VBROADCASTSDYrm,
  708. VBROADCASTSSYrm,
  709. VBROADCASTF128)>;
  710. def JWriteJVZEROALL: SchedWriteRes<[]> {
  711. let Latency = 90;
  712. let NumMicroOps = 73;
  713. }
  714. def : InstRW<[JWriteJVZEROALL], (instrs VZEROALL)>;
  715. def JWriteJVZEROUPPER: SchedWriteRes<[]> {
  716. let Latency = 46;
  717. let NumMicroOps = 37;
  718. }
  719. def : InstRW<[JWriteJVZEROUPPER], (instrs VZEROUPPER)>;
  720. ///////////////////////////////////////////////////////////////////////////////
  721. // SSE2/AVX Store Selected Bytes of Double Quadword - (V)MASKMOVDQ
  722. ///////////////////////////////////////////////////////////////////////////////
  723. def JWriteMASKMOVDQU: SchedWriteRes<[JFPU0, JFPA, JFPU1, JSTC, JLAGU, JSAGU, JALU01]> {
  724. let Latency = 34;
  725. let ResourceCycles = [1, 1, 2, 2, 2, 16, 42];
  726. let NumMicroOps = 63;
  727. }
  728. def : InstRW<[JWriteMASKMOVDQU], (instrs MASKMOVDQU, MASKMOVDQU64,
  729. VMASKMOVDQU, VMASKMOVDQU64)>;
  730. ///////////////////////////////////////////////////////////////////////////////
  731. // SchedWriteVariant definitions.
  732. ///////////////////////////////////////////////////////////////////////////////
  733. def JWriteZeroLatency : SchedWriteRes<[]> {
  734. let Latency = 0;
  735. }
  736. def JWriteZeroIdiomYmm : SchedWriteRes<[JFPU01, JFPX]> {
  737. let NumMicroOps = 2;
  738. }
  739. // Certain instructions that use the same register for both source
  740. // operands do not have a real dependency on the previous contents of the
  741. // register, and thus, do not have to wait before completing. They can be
  742. // optimized out at register renaming stage.
  743. // Reference: Section 10.8 of the "Software Optimization Guide for AMD Family
  744. // 15h Processors".
  745. // Reference: Agner's Fog "The microarchitecture of Intel, AMD and VIA CPUs",
  746. // Section 21.8 [Dependency-breaking instructions].
  747. def JWriteZeroIdiom : SchedWriteVariant<[
  748. SchedVar<MCSchedPredicate<ZeroIdiomPredicate>, [JWriteZeroLatency]>,
  749. SchedVar<NoSchedPred, [WriteALU]>
  750. ]>;
  751. def : InstRW<[JWriteZeroIdiom], (instrs SUB32rr, SUB64rr,
  752. XOR32rr, XOR64rr)>;
  753. def JWriteFZeroIdiom : SchedWriteVariant<[
  754. SchedVar<MCSchedPredicate<ZeroIdiomPredicate>, [JWriteZeroLatency]>,
  755. SchedVar<NoSchedPred, [WriteFLogic]>
  756. ]>;
  757. def : InstRW<[JWriteFZeroIdiom], (instrs XORPSrr, VXORPSrr, XORPDrr, VXORPDrr,
  758. ANDNPSrr, VANDNPSrr,
  759. ANDNPDrr, VANDNPDrr)>;
  760. def JWriteFZeroIdiomY : SchedWriteVariant<[
  761. SchedVar<MCSchedPredicate<ZeroIdiomPredicate>, [JWriteZeroIdiomYmm]>,
  762. SchedVar<NoSchedPred, [WriteFLogicY]>
  763. ]>;
  764. def : InstRW<[JWriteFZeroIdiomY], (instrs VXORPSYrr, VXORPDYrr,
  765. VANDNPSYrr, VANDNPDYrr)>;
  766. def JWriteVZeroIdiomLogic : SchedWriteVariant<[
  767. SchedVar<MCSchedPredicate<ZeroIdiomPredicate>, [JWriteZeroLatency]>,
  768. SchedVar<NoSchedPred, [WriteVecLogic]>
  769. ]>;
  770. def : InstRW<[JWriteVZeroIdiomLogic], (instrs MMX_PXORrr, MMX_PANDNrr)>;
  771. def JWriteVZeroIdiomLogicX : SchedWriteVariant<[
  772. SchedVar<MCSchedPredicate<ZeroIdiomPredicate>, [JWriteZeroLatency]>,
  773. SchedVar<NoSchedPred, [WriteVecLogicX]>
  774. ]>;
  775. def : InstRW<[JWriteVZeroIdiomLogicX], (instrs PXORrr, VPXORrr,
  776. PANDNrr, VPANDNrr)>;
  777. def JWriteVZeroIdiomALU : SchedWriteVariant<[
  778. SchedVar<MCSchedPredicate<ZeroIdiomPredicate>, [JWriteZeroLatency]>,
  779. SchedVar<NoSchedPred, [WriteVecALU]>
  780. ]>;
  781. def : InstRW<[JWriteVZeroIdiomALU], (instrs MMX_PSUBBrr, MMX_PSUBDrr,
  782. MMX_PSUBQrr, MMX_PSUBWrr,
  783. MMX_PSUBSBrr, MMX_PSUBSWrr,
  784. MMX_PSUBUSBrr, MMX_PSUBUSWrr,
  785. MMX_PCMPGTBrr, MMX_PCMPGTDrr,
  786. MMX_PCMPGTWrr)>;
  787. def JWriteVZeroIdiomALUX : SchedWriteVariant<[
  788. SchedVar<MCSchedPredicate<ZeroIdiomPredicate>, [JWriteZeroLatency]>,
  789. SchedVar<NoSchedPred, [WriteVecALUX]>
  790. ]>;
  791. def : InstRW<[JWriteVZeroIdiomALUX], (instrs PSUBBrr, VPSUBBrr,
  792. PSUBDrr, VPSUBDrr,
  793. PSUBQrr, VPSUBQrr,
  794. PSUBWrr, VPSUBWrr,
  795. PSUBSBrr, VPSUBSBrr,
  796. PSUBSWrr, VPSUBSWrr,
  797. PSUBUSBrr, VPSUBUSBrr,
  798. PSUBUSWrr, VPSUBUSWrr,
  799. PCMPGTBrr, VPCMPGTBrr,
  800. PCMPGTDrr, VPCMPGTDrr,
  801. PCMPGTQrr, VPCMPGTQrr,
  802. PCMPGTWrr, VPCMPGTWrr)>;
  803. def JWriteVPERM2F128 : SchedWriteVariant<[
  804. SchedVar<MCSchedPredicate<ZeroIdiomVPERMPredicate>, [JWriteZeroIdiomYmm]>,
  805. SchedVar<NoSchedPred, [WriteFShuffle256]>
  806. ]>;
  807. def : InstRW<[JWriteVPERM2F128], (instrs VPERM2F128rr)>;
  808. // This write is used for slow LEA instructions.
  809. def JWrite3OpsLEA : SchedWriteRes<[JALU1, JSAGU]> {
  810. let Latency = 2;
  811. }
  812. // On Jaguar, a slow LEA is either a 3Ops LEA (base, index, offset), or an LEA
  813. // with a `Scale` value different than 1.
  814. def JSlowLEAPredicate : MCSchedPredicate<
  815. CheckAny<[
  816. // A 3-operand LEA (base, index, offset).
  817. IsThreeOperandsLEAFn,
  818. // An LEA with a "Scale" different than 1.
  819. CheckAll<[
  820. CheckIsImmOperand<2>,
  821. CheckNot<CheckImmOperand<2, 1>>
  822. ]>
  823. ]>
  824. >;
  825. def JWriteLEA : SchedWriteVariant<[
  826. SchedVar<JSlowLEAPredicate, [JWrite3OpsLEA]>,
  827. SchedVar<NoSchedPred, [WriteLEA]>
  828. ]>;
  829. def : InstRW<[JWriteLEA], (instrs LEA32r, LEA64r, LEA64_32r)>;
  830. def JSlowLEA16r : SchedWriteRes<[JALU01]> {
  831. let Latency = 3;
  832. let ResourceCycles = [4];
  833. }
  834. def : InstRW<[JSlowLEA16r], (instrs LEA16r)>;
  835. ///////////////////////////////////////////////////////////////////////////////
  836. // Dependency breaking instructions.
  837. ///////////////////////////////////////////////////////////////////////////////
  838. def : IsZeroIdiomFunction<[
  839. // GPR Zero-idioms.
  840. DepBreakingClass<[ SUB32rr, SUB64rr, XOR32rr, XOR64rr ], ZeroIdiomPredicate>,
  841. // MMX Zero-idioms.
  842. DepBreakingClass<[
  843. MMX_PXORrr, MMX_PANDNrr, MMX_PSUBBrr,
  844. MMX_PSUBDrr, MMX_PSUBQrr, MMX_PSUBWrr,
  845. MMX_PSUBSBrr, MMX_PSUBSWrr, MMX_PSUBUSBrr, MMX_PSUBUSWrr,
  846. MMX_PCMPGTBrr, MMX_PCMPGTDrr, MMX_PCMPGTWrr
  847. ], ZeroIdiomPredicate>,
  848. // SSE Zero-idioms.
  849. DepBreakingClass<[
  850. // fp variants.
  851. XORPSrr, XORPDrr, ANDNPSrr, ANDNPDrr,
  852. // int variants.
  853. PXORrr, PANDNrr,
  854. PSUBBrr, PSUBWrr, PSUBDrr, PSUBQrr,
  855. PSUBSBrr, PSUBSWrr, PSUBUSBrr, PSUBUSWrr,
  856. PCMPGTBrr, PCMPGTDrr, PCMPGTQrr, PCMPGTWrr
  857. ], ZeroIdiomPredicate>,
  858. // AVX Zero-idioms.
  859. DepBreakingClass<[
  860. // xmm fp variants.
  861. VXORPSrr, VXORPDrr, VANDNPSrr, VANDNPDrr,
  862. // xmm int variants.
  863. VPXORrr, VPANDNrr,
  864. VPSUBBrr, VPSUBWrr, VPSUBDrr, VPSUBQrr,
  865. VPSUBSBrr, VPSUBSWrr, VPSUBUSBrr, VPSUBUSWrr,
  866. VPCMPGTBrr, VPCMPGTWrr, VPCMPGTDrr, VPCMPGTQrr,
  867. // ymm variants.
  868. VXORPSYrr, VXORPDYrr, VANDNPSYrr, VANDNPDYrr
  869. ], ZeroIdiomPredicate>,
  870. DepBreakingClass<[ VPERM2F128rr ], ZeroIdiomVPERMPredicate>
  871. ]>;
  872. def : IsDepBreakingFunction<[
  873. // GPR
  874. DepBreakingClass<[ SBB32rr, SBB64rr ], ZeroIdiomPredicate>,
  875. DepBreakingClass<[ CMP32rr, CMP64rr ], CheckSameRegOperand<0, 1> >,
  876. // MMX
  877. DepBreakingClass<[
  878. MMX_PCMPEQBrr, MMX_PCMPEQDrr, MMX_PCMPEQWrr
  879. ], ZeroIdiomPredicate>,
  880. // SSE
  881. DepBreakingClass<[
  882. PCMPEQBrr, PCMPEQWrr, PCMPEQDrr, PCMPEQQrr
  883. ], ZeroIdiomPredicate>,
  884. // AVX
  885. DepBreakingClass<[
  886. VPCMPEQBrr, VPCMPEQWrr, VPCMPEQDrr, VPCMPEQQrr
  887. ], ZeroIdiomPredicate>
  888. ]>;
  889. def : IsOptimizableRegisterMove<[
  890. InstructionEquivalenceClass<[
  891. // GPR variants.
  892. MOV32rr, MOV64rr,
  893. // MMX variants.
  894. MMX_MOVQ64rr,
  895. // SSE variants.
  896. MOVAPSrr, MOVUPSrr,
  897. MOVAPDrr, MOVUPDrr,
  898. MOVDQArr, MOVDQUrr,
  899. // AVX variants.
  900. VMOVAPSrr, VMOVUPSrr,
  901. VMOVAPDrr, VMOVUPDrr,
  902. VMOVDQArr, VMOVDQUrr
  903. ], TruePred >
  904. ]>;
  905. } // SchedModel