1 //=- X86ScheduleZnver1.td - X86 Znver1 Scheduling -------------*- tablegen -*-=//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the machine model for Znver1 to support instruction
10 // scheduling and other instruction cost heuristics.
12 //===----------------------------------------------------------------------===//
14 def Znver1Model : SchedMachineModel {
15 // Zen can decode 4 instructions per cycle.
17 // Based on the reorder buffer we define MicroOpBufferSize
18 let MicroOpBufferSize = 192;
20 let MispredictPenalty = 17;
22 let PostRAScheduler = 1;
24 // FIXME: This variable is required for incomplete model.
25 // We haven't catered all instructions.
26 // So, we reset the value of this variable so as to
27 // say that the model is incomplete.
28 let CompleteModel = 0;
31 let SchedModel = Znver1Model in {
33 // Zen can issue micro-ops to 10 different units in one cycle.
35 // * Four integer ALU units (ZALU0, ZALU1, ZALU2, ZALU3)
36 // * Two AGU units (ZAGU0, ZAGU1)
37 // * Four FPU units (ZFPU0, ZFPU1, ZFPU2, ZFPU3)
38 // AGUs feed load store queues @two loads and 1 store per cycle.
40 // Four ALU units are defined below
41 def ZnALU0 : ProcResource<1>;
42 def ZnALU1 : ProcResource<1>;
43 def ZnALU2 : ProcResource<1>;
44 def ZnALU3 : ProcResource<1>;
46 // Two AGU units are defined below
47 def ZnAGU0 : ProcResource<1>;
48 def ZnAGU1 : ProcResource<1>;
50 // Four FPU units are defined below
51 def ZnFPU0 : ProcResource<1>;
52 def ZnFPU1 : ProcResource<1>;
53 def ZnFPU2 : ProcResource<1>;
54 def ZnFPU3 : ProcResource<1>;
57 def ZnFPU013 : ProcResGroup<[ZnFPU0, ZnFPU1, ZnFPU3]>;
58 def ZnFPU01 : ProcResGroup<[ZnFPU0, ZnFPU1]>;
59 def ZnFPU12 : ProcResGroup<[ZnFPU1, ZnFPU2]>;
60 def ZnFPU13 : ProcResGroup<[ZnFPU1, ZnFPU3]>;
61 def ZnFPU23 : ProcResGroup<[ZnFPU2, ZnFPU3]>;
62 def ZnFPU02 : ProcResGroup<[ZnFPU0, ZnFPU2]>;
63 def ZnFPU03 : ProcResGroup<[ZnFPU0, ZnFPU3]>;
65 // Below are the grouping of the units.
66 // Micro-ops to be issued to multiple units are tackled this way.
69 // ZnALU03 - 0,3 grouping
70 def ZnALU03: ProcResGroup<[ZnALU0, ZnALU3]>;
72 // 56 Entry (14x4 entries) Int Scheduler
73 def ZnALU : ProcResGroup<[ZnALU0, ZnALU1, ZnALU2, ZnALU3]> {
77 // 28 Entry (14x2) AGU group. AGUs can't be used for all ALU operations
78 // but are relevant for some instructions
79 def ZnAGU : ProcResGroup<[ZnAGU0, ZnAGU1]> {
83 // Integer Multiplication issued on ALU1.
84 def ZnMultiplier : ProcResource<1>;
86 // Integer division issued on ALU2.
87 def ZnDivider : ProcResource<1>;
89 // 4 Cycles integer load-to use Latency is captured
90 def : ReadAdvance<ReadAfterLd, 4>;
92 // 8 Cycles vector load-to use Latency is captured
93 def : ReadAdvance<ReadAfterVecLd, 8>;
94 def : ReadAdvance<ReadAfterVecXLd, 8>;
95 def : ReadAdvance<ReadAfterVecYLd, 8>;
97 def : ReadAdvance<ReadInt2Fpu, 0>;
99 // The Integer PRF for Zen is 168 entries, and it holds the architectural and
100 // speculative version of the 64-bit integer registers.
101 // Reference: "Software Optimization Guide for AMD Family 17h Processors"
102 def ZnIntegerPRF : RegisterFile<168, [GR64, CCR]>;
104 // 36 Entry (9x4 entries) floating-point Scheduler
105 def ZnFPU : ProcResGroup<[ZnFPU0, ZnFPU1, ZnFPU2, ZnFPU3]> {
109 // The Zen FP Retire Queue renames SIMD and FP uOps onto a pool of 160 128-bit
110 // registers. Operations on 256-bit data types are cracked into two COPs.
111 // Reference: "Software Optimization Guide for AMD Family 17h Processors"
112 def ZnFpuPRF: RegisterFile<160, [VR64, VR128, VR256], [1, 1, 2]>;
114 // The unit can track up to 192 macro ops in-flight.
115 // The retire unit handles in-order commit of up to 8 macro ops per cycle.
116 // Reference: "Software Optimization Guide for AMD Family 17h Processors"
117 // To be noted, the retire unit is shared between integer and FP ops.
118 // In SMT mode it is 96 entry per thread. But, we do not use the conservative
119 // value here because there is currently no way to fully mode the SMT mode,
120 // so there is no point in trying.
121 def ZnRCU : RetireControlUnit<192, 8>;
123 // FIXME: there are 72 read buffers and 44 write buffers.
125 // (a folded load is an instruction that loads and does some operation)
126 // Ex: ADDPD xmm,[mem]-> This instruction has two micro-ops
127 // Instructions with folded loads are usually micro-fused, so they only appear
131 // This multiclass is for folded loads for integer units.
132 multiclass ZnWriteResPair<X86FoldableSchedWrite SchedRW,
133 list<ProcResourceKind> ExePorts,
134 int Lat, list<int> Res = [], int UOps = 1,
135 int LoadLat = 4, int LoadUOps = 1> {
136 // Register variant takes 1-cycle on Execution Port.
137 def : WriteRes<SchedRW, ExePorts> {
139 let ResourceCycles = Res;
140 let NumMicroOps = UOps;
143 // Memory variant also uses a cycle on ZnAGU
144 // adds LoadLat cycles to the latency (default = 4).
145 def : WriteRes<SchedRW.Folded, !listconcat([ZnAGU], ExePorts)> {
146 let Latency = !add(Lat, LoadLat);
147 let ResourceCycles = !if(!empty(Res), [], !listconcat([1], Res));
148 let NumMicroOps = !add(UOps, LoadUOps);
152 // This multiclass is for folded loads for floating point units.
153 multiclass ZnWriteResFpuPair<X86FoldableSchedWrite SchedRW,
154 list<ProcResourceKind> ExePorts,
155 int Lat, list<int> Res = [], int UOps = 1,
156 int LoadLat = 7, int LoadUOps = 0> {
157 // Register variant takes 1-cycle on Execution Port.
158 def : WriteRes<SchedRW, ExePorts> {
160 let ResourceCycles = Res;
161 let NumMicroOps = UOps;
164 // Memory variant also uses a cycle on ZnAGU
165 // adds LoadLat cycles to the latency (default = 7).
166 def : WriteRes<SchedRW.Folded, !listconcat([ZnAGU], ExePorts)> {
167 let Latency = !add(Lat, LoadLat);
168 let ResourceCycles = !if(!empty(Res), [], !listconcat([1], Res));
169 let NumMicroOps = !add(UOps, LoadUOps);
173 // WriteRMW is set for instructions with Memory write
174 // operation in codegen
175 def : WriteRes<WriteRMW, [ZnAGU]>;
177 def : WriteRes<WriteStore, [ZnAGU]>;
178 def : WriteRes<WriteStoreNT, [ZnAGU]>;
179 def : WriteRes<WriteMove, [ZnALU]>;
180 def : WriteRes<WriteLoad, [ZnAGU]> { let Latency = 8; }
182 def : WriteRes<WriteZero, []>;
183 def : WriteRes<WriteLEA, [ZnALU]>;
184 defm : ZnWriteResPair<WriteALU, [ZnALU], 1>;
185 defm : ZnWriteResPair<WriteADC, [ZnALU], 1>;
187 defm : ZnWriteResPair<WriteIMul8, [ZnALU1, ZnMultiplier], 4>;
188 //defm : ZnWriteResPair<WriteIMul16, [ZnALU1, ZnMultiplier], 4>;
189 //defm : ZnWriteResPair<WriteIMul16Imm, [ZnALU1, ZnMultiplier], 4>;
190 //defm : ZnWriteResPair<WriteIMul16Reg, [ZnALU1, ZnMultiplier], 4>;
191 //defm : ZnWriteResPair<WriteIMul32, [ZnALU1, ZnMultiplier], 4>;
192 //defm : ZnWriteResPair<WriteIMul32Imm, [ZnALU1, ZnMultiplier], 4>;
193 //defm : ZnWriteResPair<WriteIMul32Reg, [ZnALU1, ZnMultiplier], 4>;
194 //defm : ZnWriteResPair<WriteIMul64, [ZnALU1, ZnMultiplier], 4, [1,1], 2>;
195 //defm : ZnWriteResPair<WriteIMul64Imm, [ZnALU1, ZnMultiplier], 4, [1,1], 2>;
196 //defm : ZnWriteResPair<WriteIMul64Reg, [ZnALU1, ZnMultiplier], 4, [1,1], 2>;
198 defm : X86WriteRes<WriteBSWAP32, [ZnALU], 1, [4], 1>;
199 defm : X86WriteRes<WriteBSWAP64, [ZnALU], 1, [4], 1>;
200 defm : X86WriteRes<WriteCMPXCHG, [ZnALU], 1, [1], 1>;
201 defm : X86WriteRes<WriteCMPXCHGRMW,[ZnALU,ZnAGU], 8, [1,1], 5>;
202 defm : X86WriteRes<WriteXCHG, [ZnALU], 1, [2], 2>;
204 defm : ZnWriteResPair<WriteShift, [ZnALU], 1>;
205 defm : ZnWriteResPair<WriteShiftCL, [ZnALU], 1>;
206 defm : ZnWriteResPair<WriteRotate, [ZnALU], 1>;
207 defm : ZnWriteResPair<WriteRotateCL, [ZnALU], 1>;
209 defm : X86WriteRes<WriteSHDrri, [ZnALU], 1, [1], 1>;
210 defm : X86WriteResUnsupported<WriteSHDrrcl>;
211 defm : X86WriteResUnsupported<WriteSHDmri>;
212 defm : X86WriteResUnsupported<WriteSHDmrcl>;
214 defm : ZnWriteResPair<WriteJump, [ZnALU], 1>;
215 defm : ZnWriteResFpuPair<WriteCRC32, [ZnFPU0], 3>;
217 defm : ZnWriteResPair<WriteCMOV, [ZnALU], 1>;
218 def : WriteRes<WriteSETCC, [ZnALU]>;
219 def : WriteRes<WriteSETCCStore, [ZnALU, ZnAGU]>;
220 defm : X86WriteRes<WriteLAHFSAHF, [ZnALU], 2, [1], 2>;
222 defm : X86WriteRes<WriteBitTest, [ZnALU], 1, [1], 1>;
223 defm : X86WriteRes<WriteBitTestImmLd, [ZnALU,ZnAGU], 5, [1,1], 2>;
224 defm : X86WriteRes<WriteBitTestRegLd, [ZnALU,ZnAGU], 5, [1,1], 2>;
225 defm : X86WriteRes<WriteBitTestSet, [ZnALU], 2, [1], 2>;
226 //defm : X86WriteRes<WriteBitTestSetImmLd, [ZnALU,ZnAGU], 5, [1,1], 2>;
227 //defm : X86WriteRes<WriteBitTestSetRegLd, [ZnALU,ZnAGU], 5, [1,1], 2>;
230 defm : ZnWriteResPair<WriteBSF, [ZnALU], 3>;
231 defm : ZnWriteResPair<WriteBSR, [ZnALU], 3>;
232 defm : ZnWriteResPair<WriteLZCNT, [ZnALU], 2>;
233 defm : ZnWriteResPair<WriteTZCNT, [ZnALU], 2>;
234 defm : ZnWriteResPair<WritePOPCNT, [ZnALU], 1>;
236 // Treat misc copies as a move.
237 def : InstRW<[WriteMove], (instrs COPY)>;
239 // BMI1 BEXTR/BLS, BMI2 BZHI
240 defm : ZnWriteResPair<WriteBEXTR, [ZnALU], 1>;
241 //defm : ZnWriteResPair<WriteBLS, [ZnALU], 2>;
242 defm : ZnWriteResPair<WriteBZHI, [ZnALU], 1>;
245 defm : ZnWriteResPair<WriteDiv8, [ZnALU2, ZnDivider], 15, [1,15], 1>;
246 defm : ZnWriteResPair<WriteDiv16, [ZnALU2, ZnDivider], 17, [1,17], 2>;
247 defm : ZnWriteResPair<WriteDiv32, [ZnALU2, ZnDivider], 25, [1,25], 2>;
248 defm : ZnWriteResPair<WriteDiv64, [ZnALU2, ZnDivider], 41, [1,41], 2>;
249 defm : ZnWriteResPair<WriteIDiv8, [ZnALU2, ZnDivider], 15, [1,15], 1>;
250 defm : ZnWriteResPair<WriteIDiv16, [ZnALU2, ZnDivider], 17, [1,17], 2>;
251 defm : ZnWriteResPair<WriteIDiv32, [ZnALU2, ZnDivider], 25, [1,25], 2>;
252 defm : ZnWriteResPair<WriteIDiv64, [ZnALU2, ZnDivider], 41, [1,41], 2>;
255 def : WriteRes<WriteIMulH, [ZnALU1, ZnMultiplier]>{
259 // Floating point operations
260 defm : X86WriteRes<WriteFLoad, [ZnAGU], 8, [1], 1>;
261 defm : X86WriteRes<WriteFLoadX, [ZnAGU], 8, [1], 1>;
262 defm : X86WriteRes<WriteFLoadY, [ZnAGU], 8, [1], 1>;
263 defm : X86WriteRes<WriteFMaskedLoad, [ZnAGU,ZnFPU01], 8, [1,1], 1>;
264 defm : X86WriteRes<WriteFMaskedLoadY, [ZnAGU,ZnFPU01], 8, [1,2], 2>;
265 defm : X86WriteRes<WriteFStore, [ZnAGU], 1, [1], 1>;
266 defm : X86WriteRes<WriteFStoreX, [ZnAGU], 1, [1], 1>;
267 defm : X86WriteRes<WriteFStoreY, [ZnAGU], 1, [1], 1>;
268 defm : X86WriteRes<WriteFStoreNT, [ZnAGU,ZnFPU2], 8, [1,1], 1>;
269 defm : X86WriteRes<WriteFStoreNTX, [ZnAGU], 1, [1], 1>;
270 defm : X86WriteRes<WriteFStoreNTY, [ZnAGU], 1, [1], 1>;
272 defm : X86WriteRes<WriteFMaskedStore32, [ZnAGU,ZnFPU01], 4, [1,1], 1>;
273 defm : X86WriteRes<WriteFMaskedStore32Y, [ZnAGU,ZnFPU01], 5, [1,2], 2>;
274 defm : X86WriteRes<WriteFMaskedStore64, [ZnAGU,ZnFPU01], 4, [1,1], 1>;
275 defm : X86WriteRes<WriteFMaskedStore64Y, [ZnAGU,ZnFPU01], 5, [1,2], 2>;
277 defm : X86WriteRes<WriteFMove, [ZnFPU], 1, [1], 1>;
278 defm : X86WriteRes<WriteFMoveX, [ZnFPU], 1, [1], 1>;
279 defm : X86WriteRes<WriteFMoveY, [ZnFPU], 1, [1], 1>;
281 defm : ZnWriteResFpuPair<WriteFAdd, [ZnFPU0], 3>;
282 defm : ZnWriteResFpuPair<WriteFAddX, [ZnFPU0], 3>;
283 defm : ZnWriteResFpuPair<WriteFAddY, [ZnFPU0], 3>;
284 defm : X86WriteResPairUnsupported<WriteFAddZ>;
285 defm : ZnWriteResFpuPair<WriteFAdd64, [ZnFPU0], 3>;
286 defm : ZnWriteResFpuPair<WriteFAdd64X, [ZnFPU0], 3>;
287 defm : ZnWriteResFpuPair<WriteFAdd64Y, [ZnFPU0], 3>;
288 defm : X86WriteResPairUnsupported<WriteFAdd64Z>;
289 defm : ZnWriteResFpuPair<WriteFCmp, [ZnFPU0], 3>;
290 defm : ZnWriteResFpuPair<WriteFCmpX, [ZnFPU0], 3>;
291 defm : ZnWriteResFpuPair<WriteFCmpY, [ZnFPU0], 3>;
292 defm : X86WriteResPairUnsupported<WriteFCmpZ>;
293 defm : ZnWriteResFpuPair<WriteFCmp64, [ZnFPU0], 3>;
294 defm : ZnWriteResFpuPair<WriteFCmp64X, [ZnFPU0], 3>;
295 defm : ZnWriteResFpuPair<WriteFCmp64Y, [ZnFPU0], 3>;
296 defm : X86WriteResPairUnsupported<WriteFCmp64Z>;
297 defm : ZnWriteResFpuPair<WriteFCom, [ZnFPU0], 3>;
298 defm : ZnWriteResFpuPair<WriteFBlend, [ZnFPU01], 1>;
299 defm : ZnWriteResFpuPair<WriteFBlendY, [ZnFPU01], 1>;
300 defm : X86WriteResPairUnsupported<WriteFBlendZ>;
301 defm : ZnWriteResFpuPair<WriteFVarBlend, [ZnFPU01], 1>;
302 defm : ZnWriteResFpuPair<WriteFVarBlendY,[ZnFPU01], 1>;
303 defm : X86WriteResPairUnsupported<WriteFVarBlendZ>;
304 defm : ZnWriteResFpuPair<WriteVarBlend, [ZnFPU0], 1>;
305 defm : ZnWriteResFpuPair<WriteVarBlendY, [ZnFPU0], 1>;
306 defm : X86WriteResPairUnsupported<WriteVarBlendZ>;
307 defm : ZnWriteResFpuPair<WriteCvtSS2I, [ZnFPU3], 5>;
308 defm : ZnWriteResFpuPair<WriteCvtPS2I, [ZnFPU3], 5>;
309 defm : ZnWriteResFpuPair<WriteCvtPS2IY, [ZnFPU3], 5>;
310 defm : X86WriteResPairUnsupported<WriteCvtPS2IZ>;
311 defm : ZnWriteResFpuPair<WriteCvtSD2I, [ZnFPU3], 5>;
312 defm : ZnWriteResFpuPair<WriteCvtPD2I, [ZnFPU3], 5>;
313 defm : ZnWriteResFpuPair<WriteCvtPD2IY, [ZnFPU3], 5>;
314 defm : X86WriteResPairUnsupported<WriteCvtPD2IZ>;
315 defm : ZnWriteResFpuPair<WriteCvtI2SS, [ZnFPU3], 5>;
316 defm : ZnWriteResFpuPair<WriteCvtI2PS, [ZnFPU3], 5>;
317 defm : ZnWriteResFpuPair<WriteCvtI2PSY, [ZnFPU3], 5>;
318 defm : X86WriteResPairUnsupported<WriteCvtI2PSZ>;
319 defm : ZnWriteResFpuPair<WriteCvtI2SD, [ZnFPU3], 5>;
320 defm : ZnWriteResFpuPair<WriteCvtI2PD, [ZnFPU3], 5>;
321 defm : ZnWriteResFpuPair<WriteCvtI2PDY, [ZnFPU3], 5>;
322 defm : X86WriteResPairUnsupported<WriteCvtI2PDZ>;
323 defm : ZnWriteResFpuPair<WriteFDiv, [ZnFPU3], 15>;
324 defm : ZnWriteResFpuPair<WriteFDivX, [ZnFPU3], 15>;
325 //defm : ZnWriteResFpuPair<WriteFDivY, [ZnFPU3], 15>;
326 defm : X86WriteResPairUnsupported<WriteFDivZ>;
327 defm : ZnWriteResFpuPair<WriteFDiv64, [ZnFPU3], 15>;
328 defm : ZnWriteResFpuPair<WriteFDiv64X, [ZnFPU3], 15>;
329 //defm : ZnWriteResFpuPair<WriteFDiv64Y, [ZnFPU3], 15>;
330 defm : X86WriteResPairUnsupported<WriteFDiv64Z>;
331 defm : ZnWriteResFpuPair<WriteFSign, [ZnFPU3], 2>;
332 defm : ZnWriteResFpuPair<WriteFRnd, [ZnFPU3], 4, [1], 1, 7, 1>; // FIXME: Should folds require 1 extra uops?
333 defm : ZnWriteResFpuPair<WriteFRndY, [ZnFPU3], 4, [1], 1, 7, 1>; // FIXME: Should folds require 1 extra uops?
334 defm : X86WriteResPairUnsupported<WriteFRndZ>;
335 defm : ZnWriteResFpuPair<WriteFLogic, [ZnFPU], 1>;
336 defm : ZnWriteResFpuPair<WriteFLogicY, [ZnFPU], 1>;
337 defm : X86WriteResPairUnsupported<WriteFLogicZ>;
338 defm : ZnWriteResFpuPair<WriteFTest, [ZnFPU], 1>;
339 defm : ZnWriteResFpuPair<WriteFTestY, [ZnFPU], 1>;
340 defm : X86WriteResPairUnsupported<WriteFTestZ>;
341 defm : ZnWriteResFpuPair<WriteFShuffle, [ZnFPU12], 1>;
342 defm : ZnWriteResFpuPair<WriteFShuffleY, [ZnFPU12], 1>;
343 defm : X86WriteResPairUnsupported<WriteFShuffleZ>;
344 defm : ZnWriteResFpuPair<WriteFVarShuffle, [ZnFPU12], 1>;
345 defm : ZnWriteResFpuPair<WriteFVarShuffleY,[ZnFPU12], 1>;
346 defm : X86WriteResPairUnsupported<WriteFVarShuffleZ>;
347 defm : ZnWriteResFpuPair<WriteFMul, [ZnFPU01], 3, [1], 1, 7, 1>;
348 defm : ZnWriteResFpuPair<WriteFMulX, [ZnFPU01], 3, [1], 1, 7, 1>;
349 defm : ZnWriteResFpuPair<WriteFMulY, [ZnFPU01], 4, [1], 1, 7, 1>;
350 defm : X86WriteResPairUnsupported<WriteFMulZ>;
351 defm : ZnWriteResFpuPair<WriteFMul64, [ZnFPU01], 3, [1], 1, 7, 1>;
352 defm : ZnWriteResFpuPair<WriteFMul64X, [ZnFPU01], 3, [1], 1, 7, 1>;
353 defm : ZnWriteResFpuPair<WriteFMul64Y, [ZnFPU01], 4, [1], 1, 7, 1>;
354 defm : X86WriteResPairUnsupported<WriteFMul64Z>;
355 defm : ZnWriteResFpuPair<WriteFMA, [ZnFPU03], 5>;
356 defm : ZnWriteResFpuPair<WriteFMAX, [ZnFPU03], 5>;
357 defm : ZnWriteResFpuPair<WriteFMAY, [ZnFPU03], 5>;
358 defm : X86WriteResPairUnsupported<WriteFMAZ>;
359 defm : ZnWriteResFpuPair<WriteFRcp, [ZnFPU01], 5>;
360 defm : ZnWriteResFpuPair<WriteFRcpX, [ZnFPU01], 5>;
361 defm : ZnWriteResFpuPair<WriteFRcpY, [ZnFPU01], 5, [1], 1, 7, 2>;
362 defm : X86WriteResPairUnsupported<WriteFRcpZ>;
363 //defm : ZnWriteResFpuPair<WriteFRsqrt, [ZnFPU02], 5>;
364 defm : ZnWriteResFpuPair<WriteFRsqrtX, [ZnFPU01], 5, [1], 1, 7, 1>;
365 //defm : ZnWriteResFpuPair<WriteFRsqrtY, [ZnFPU01], 5, [2], 2>;
366 defm : X86WriteResPairUnsupported<WriteFRsqrtZ>;
367 defm : ZnWriteResFpuPair<WriteFSqrt, [ZnFPU3], 20, [20]>;
368 defm : ZnWriteResFpuPair<WriteFSqrtX, [ZnFPU3], 20, [20]>;
369 defm : ZnWriteResFpuPair<WriteFSqrtY, [ZnFPU3], 28, [28], 1, 7, 1>;
370 defm : X86WriteResPairUnsupported<WriteFSqrtZ>;
371 defm : ZnWriteResFpuPair<WriteFSqrt64, [ZnFPU3], 20, [20]>;
372 defm : ZnWriteResFpuPair<WriteFSqrt64X, [ZnFPU3], 20, [20]>;
373 defm : ZnWriteResFpuPair<WriteFSqrt64Y, [ZnFPU3], 40, [40], 1, 7, 1>;
374 defm : X86WriteResPairUnsupported<WriteFSqrt64Z>;
375 defm : ZnWriteResFpuPair<WriteFSqrt80, [ZnFPU3], 20, [20]>;
377 // Vector integer operations which uses FPU units
378 defm : X86WriteRes<WriteVecLoad, [ZnAGU], 8, [1], 1>;
379 defm : X86WriteRes<WriteVecLoadX, [ZnAGU], 8, [1], 1>;
380 defm : X86WriteRes<WriteVecLoadY, [ZnAGU], 8, [1], 1>;
381 defm : X86WriteRes<WriteVecLoadNT, [ZnAGU], 8, [1], 1>;
382 defm : X86WriteRes<WriteVecLoadNTY, [ZnAGU], 8, [1], 1>;
383 defm : X86WriteRes<WriteVecMaskedLoad, [ZnAGU,ZnFPU01], 8, [1,2], 2>;
384 defm : X86WriteRes<WriteVecMaskedLoadY, [ZnAGU,ZnFPU01], 9, [1,3], 2>;
385 defm : X86WriteRes<WriteVecStore, [ZnAGU], 1, [1], 1>;
386 defm : X86WriteRes<WriteVecStoreX, [ZnAGU], 1, [1], 1>;
387 defm : X86WriteRes<WriteVecStoreY, [ZnAGU], 1, [1], 1>;
388 defm : X86WriteRes<WriteVecStoreNT, [ZnAGU], 1, [1], 1>;
389 defm : X86WriteRes<WriteVecStoreNTY, [ZnAGU], 1, [1], 1>;
390 defm : X86WriteRes<WriteVecMaskedStore, [ZnAGU,ZnFPU01], 4, [1,1], 1>;
391 defm : X86WriteRes<WriteVecMaskedStoreY, [ZnAGU,ZnFPU01], 5, [1,2], 2>;
392 defm : X86WriteRes<WriteVecMove, [ZnFPU], 1, [1], 1>;
393 defm : X86WriteRes<WriteVecMoveX, [ZnFPU], 1, [1], 1>;
394 defm : X86WriteRes<WriteVecMoveY, [ZnFPU], 2, [1], 2>;
395 defm : X86WriteRes<WriteVecMoveToGpr, [ZnFPU2], 2, [1], 1>;
396 defm : X86WriteRes<WriteVecMoveFromGpr, [ZnFPU2], 3, [1], 1>;
397 defm : X86WriteRes<WriteEMMS, [ZnFPU], 2, [1], 1>;
399 defm : ZnWriteResFpuPair<WriteVecShift, [ZnFPU], 1>;
400 defm : ZnWriteResFpuPair<WriteVecShiftX, [ZnFPU2], 1>;
401 defm : ZnWriteResFpuPair<WriteVecShiftY, [ZnFPU2], 2>;
402 defm : X86WriteResPairUnsupported<WriteVecShiftZ>;
403 defm : ZnWriteResFpuPair<WriteVecShiftImm, [ZnFPU], 1>;
404 defm : ZnWriteResFpuPair<WriteVecShiftImmX, [ZnFPU], 1>;
405 defm : ZnWriteResFpuPair<WriteVecShiftImmY, [ZnFPU], 1>;
406 defm : X86WriteResPairUnsupported<WriteVecShiftImmZ>;
407 defm : ZnWriteResFpuPair<WriteVecLogic, [ZnFPU], 1>;
408 defm : ZnWriteResFpuPair<WriteVecLogicX, [ZnFPU], 1>;
409 defm : ZnWriteResFpuPair<WriteVecLogicY, [ZnFPU], 1>;
410 defm : X86WriteResPairUnsupported<WriteVecLogicZ>;
411 defm : ZnWriteResFpuPair<WriteVecTest, [ZnFPU12], 1, [2], 1, 7, 1>;
412 defm : ZnWriteResFpuPair<WriteVecTestY, [ZnFPU12], 1, [2], 1, 7, 1>;
413 defm : X86WriteResPairUnsupported<WriteVecTestZ>;
414 defm : ZnWriteResFpuPair<WriteVecALU, [ZnFPU], 1>;
415 defm : ZnWriteResFpuPair<WriteVecALUX, [ZnFPU], 1>;
416 defm : ZnWriteResFpuPair<WriteVecALUY, [ZnFPU], 1>;
417 defm : X86WriteResPairUnsupported<WriteVecALUZ>;
418 defm : ZnWriteResFpuPair<WriteVecIMul, [ZnFPU0], 4>;
419 defm : ZnWriteResFpuPair<WriteVecIMulX, [ZnFPU0], 4>;
420 defm : ZnWriteResFpuPair<WriteVecIMulY, [ZnFPU0], 4>;
421 defm : X86WriteResPairUnsupported<WriteVecIMulZ>;
422 defm : ZnWriteResFpuPair<WritePMULLD, [ZnFPU0], 4, [1], 1, 7, 1>; // FIXME
423 defm : ZnWriteResFpuPair<WritePMULLDY, [ZnFPU0], 5, [2], 1, 7, 1>; // FIXME
424 defm : X86WriteResPairUnsupported<WritePMULLDZ>;
425 defm : ZnWriteResFpuPair<WriteShuffle, [ZnFPU], 1>;
426 defm : ZnWriteResFpuPair<WriteShuffleX, [ZnFPU], 1>;
427 defm : ZnWriteResFpuPair<WriteShuffleY, [ZnFPU], 1>;
428 defm : X86WriteResPairUnsupported<WriteShuffleZ>;
429 defm : ZnWriteResFpuPair<WriteVarShuffle, [ZnFPU], 1>;
430 defm : ZnWriteResFpuPair<WriteVarShuffleX,[ZnFPU], 1>;
431 defm : ZnWriteResFpuPair<WriteVarShuffleY,[ZnFPU], 1>;
432 defm : X86WriteResPairUnsupported<WriteVarShuffleZ>;
433 defm : ZnWriteResFpuPair<WriteBlend, [ZnFPU01], 1>;
434 defm : ZnWriteResFpuPair<WriteBlendY, [ZnFPU01], 1>;
435 defm : X86WriteResPairUnsupported<WriteBlendZ>;
436 defm : ZnWriteResFpuPair<WriteShuffle256, [ZnFPU], 2>;
437 defm : ZnWriteResFpuPair<WriteVarShuffle256, [ZnFPU], 2>;
438 defm : ZnWriteResFpuPair<WritePSADBW, [ZnFPU0], 3>;
439 defm : ZnWriteResFpuPair<WritePSADBWX, [ZnFPU0], 3>;
440 defm : ZnWriteResFpuPair<WritePSADBWY, [ZnFPU0], 3>;
441 defm : X86WriteResPairUnsupported<WritePSADBWZ>;
442 defm : ZnWriteResFpuPair<WritePHMINPOS, [ZnFPU0], 4>;
444 // Vector Shift Operations
445 defm : ZnWriteResFpuPair<WriteVarVecShift, [ZnFPU12], 1>;
446 defm : ZnWriteResFpuPair<WriteVarVecShiftY, [ZnFPU12], 1>;
447 defm : X86WriteResPairUnsupported<WriteVarVecShiftZ>;
449 // Vector insert/extract operations.
450 defm : ZnWriteResFpuPair<WriteVecInsert, [ZnFPU], 1>;
452 def : WriteRes<WriteVecExtract, [ZnFPU12, ZnFPU2]> {
454 let ResourceCycles = [1, 2];
456 def : WriteRes<WriteVecExtractSt, [ZnAGU, ZnFPU12, ZnFPU2]> {
459 let ResourceCycles = [1, 2, 3];
462 // MOVMSK Instructions.
463 def : WriteRes<WriteFMOVMSK, [ZnFPU2]>;
464 def : WriteRes<WriteMMXMOVMSK, [ZnFPU2]>;
465 def : WriteRes<WriteVecMOVMSK, [ZnFPU2]>;
467 def : WriteRes<WriteVecMOVMSKY, [ZnFPU2]> {
470 let ResourceCycles = [2];
474 defm : ZnWriteResFpuPair<WriteAESDecEnc, [ZnFPU01], 4>;
475 defm : ZnWriteResFpuPair<WriteAESIMC, [ZnFPU01], 4>;
476 defm : ZnWriteResFpuPair<WriteAESKeyGen, [ZnFPU01], 4>;
478 def : WriteRes<WriteFence, [ZnAGU]>;
479 def : WriteRes<WriteNop, []>;
481 // Following instructions with latency=100 are microcoded.
482 // We set long latency so as to block the entire pipeline.
483 defm : ZnWriteResFpuPair<WriteFShuffle256, [ZnFPU], 100>;
484 defm : ZnWriteResFpuPair<WriteFVarShuffle256, [ZnFPU], 100>;
486 // Microcoded Instructions
487 def ZnWriteMicrocoded : SchedWriteRes<[]> {
491 def : SchedAlias<WriteMicrocoded, ZnWriteMicrocoded>;
492 def : SchedAlias<WriteFCMOV, ZnWriteMicrocoded>;
493 def : SchedAlias<WriteSystem, ZnWriteMicrocoded>;
494 def : SchedAlias<WriteMPSAD, ZnWriteMicrocoded>;
495 def : SchedAlias<WriteMPSADY, ZnWriteMicrocoded>;
496 def : SchedAlias<WriteMPSADLd, ZnWriteMicrocoded>;
497 def : SchedAlias<WriteMPSADYLd, ZnWriteMicrocoded>;
498 def : SchedAlias<WriteCLMul, ZnWriteMicrocoded>;
499 def : SchedAlias<WriteCLMulLd, ZnWriteMicrocoded>;
500 def : SchedAlias<WritePCmpIStrM, ZnWriteMicrocoded>;
501 def : SchedAlias<WritePCmpIStrMLd, ZnWriteMicrocoded>;
502 def : SchedAlias<WritePCmpEStrI, ZnWriteMicrocoded>;
503 def : SchedAlias<WritePCmpEStrILd, ZnWriteMicrocoded>;
504 def : SchedAlias<WritePCmpEStrM, ZnWriteMicrocoded>;
505 def : SchedAlias<WritePCmpEStrMLd, ZnWriteMicrocoded>;
506 def : SchedAlias<WritePCmpIStrI, ZnWriteMicrocoded>;
507 def : SchedAlias<WritePCmpIStrILd, ZnWriteMicrocoded>;
508 def : SchedAlias<WriteLDMXCSR, ZnWriteMicrocoded>;
509 def : SchedAlias<WriteSTMXCSR, ZnWriteMicrocoded>;
511 //=== Regex based InstRW ===//
516 // - mm: 64 bit mmx register.
517 // - x = 128 bit xmm register.
518 // - (x)mm = mmx or xmm register.
519 // - y = 256 bit ymm register.
520 // - v = any vector register.
522 //=== Integer Instructions ===//
523 //-- Move instructions --//
526 def : InstRW<[WriteALULd, ReadAfterLd], (instrs MOV16rm)>;
530 def : InstRW<[WriteLoad], (instregex "MOV(S|Z)X32rm(8|16)")>;
534 def ZnWriteXCHGrm : SchedWriteRes<[ZnAGU, ZnALU]> {
538 def : InstRW<[ZnWriteXCHGrm, ReadAfterLd], (instregex "XCHG(8|16|32|64)rm")>;
540 def : InstRW<[WriteMicrocoded], (instrs XLAT)>;
544 def ZnWritePop16r : SchedWriteRes<[ZnAGU]>{
548 def : InstRW<[ZnWritePop16r], (instrs POP16rmm)>;
549 def : InstRW<[WriteMicrocoded], (instregex "POPF(16|32)")>;
550 def : InstRW<[WriteMicrocoded], (instregex "POPA(16|32)")>;
554 // r. Has default values.
556 def ZnWritePUSH : SchedWriteRes<[ZnAGU]>{
559 def : InstRW<[ZnWritePUSH], (instregex "PUSH(16|32)rmm")>;
562 def : InstRW<[WriteMicrocoded], (instregex "PUSHF(16|32)")>;
565 def ZnWritePushA : SchedWriteRes<[ZnAGU]> {
568 def : InstRW<[ZnWritePushA], (instregex "PUSHA(16|32)")>;
571 def : InstRW<[WriteMicrocoded], (instrs LAHF)>;
575 def ZnWriteMOVBE : SchedWriteRes<[ZnAGU, ZnALU]> {
578 def : InstRW<[ZnWriteMOVBE, ReadAfterLd], (instregex "MOVBE(16|32|64)rm")>;
581 def : InstRW<[ZnWriteMOVBE], (instregex "MOVBE(16|32|64)mr")>;
583 //-- Arithmetic instructions --//
587 def : InstRW<[WriteALULd], (instregex "(ADD|SUB)(8|16|32|64)m(r|i)",
588 "(ADD|SUB)(8|16|32|64)mi8",
593 def : InstRW<[WriteALULd],
594 (instregex "(ADC|SBB)(8|16|32|64)m(r|i)",
595 "(ADC|SBB)(16|32|64)mi8",
600 def : InstRW<[WriteALULd],
601 (instregex "(INC|DEC|NOT|NEG)(8|16|32|64)m")>;
605 def ZnWriteMul16 : SchedWriteRes<[ZnALU1, ZnMultiplier]> {
608 def : SchedAlias<WriteIMul16, ZnWriteMul16>;
609 def : SchedAlias<WriteIMul16Imm, ZnWriteMul16>; // TODO: is this right?
610 def : SchedAlias<WriteIMul16Reg, ZnWriteMul16>; // TODO: is this right?
611 def : SchedAlias<WriteIMul16ImmLd, ZnWriteMul16>; // TODO: this is definitely wrong but matches what the instregex did.
612 def : SchedAlias<WriteIMul16RegLd, ZnWriteMul16>; // TODO: this is definitely wrong but matches what the instregex did.
615 def ZnWriteMul16Ld : SchedWriteRes<[ZnAGU, ZnALU1, ZnMultiplier]> {
618 def : SchedAlias<WriteIMul16Ld, ZnWriteMul16Ld>;
621 def ZnWriteMul32 : SchedWriteRes<[ZnALU1, ZnMultiplier]> {
624 def : SchedAlias<WriteIMul32, ZnWriteMul32>;
625 def : SchedAlias<WriteIMul32Imm, ZnWriteMul32>; // TODO: is this right?
626 def : SchedAlias<WriteIMul32Reg, ZnWriteMul32>; // TODO: is this right?
627 def : SchedAlias<WriteIMul32ImmLd, ZnWriteMul32>; // TODO: this is definitely wrong but matches what the instregex did.
628 def : SchedAlias<WriteIMul32RegLd, ZnWriteMul32>; // TODO: this is definitely wrong but matches what the instregex did.
631 def ZnWriteMul32Ld : SchedWriteRes<[ZnAGU, ZnALU1, ZnMultiplier]> {
634 def : SchedAlias<WriteIMul32Ld, ZnWriteMul32Ld>;
637 def ZnWriteMul64 : SchedWriteRes<[ZnALU1, ZnMultiplier]> {
641 def : SchedAlias<WriteIMul64, ZnWriteMul64>;
642 def : SchedAlias<WriteIMul64Imm, ZnWriteMul64>; // TODO: is this right?
643 def : SchedAlias<WriteIMul64Reg, ZnWriteMul64>; // TODO: is this right?
644 def : SchedAlias<WriteIMul64ImmLd, ZnWriteMul64>; // TODO: this is definitely wrong but matches what the instregex did.
645 def : SchedAlias<WriteIMul64RegLd, ZnWriteMul64>; // TODO: this is definitely wrong but matches what the instregex did.
648 def ZnWriteMul64Ld : SchedWriteRes<[ZnAGU, ZnALU1, ZnMultiplier]> {
652 def : SchedAlias<WriteIMul64Ld, ZnWriteMul64Ld>;
656 def ZnWriteMulX32 : SchedWriteRes<[ZnALU1, ZnMultiplier]> {
658 let ResourceCycles = [1, 2];
660 def : InstRW<[ZnWriteMulX32], (instrs MULX32rr)>;
663 def ZnWriteMulX32Ld : SchedWriteRes<[ZnAGU, ZnALU1, ZnMultiplier]> {
665 let ResourceCycles = [1, 2, 2];
667 def : InstRW<[ZnWriteMulX32Ld, ReadAfterLd], (instrs MULX32rm)>;
670 def ZnWriteMulX64 : SchedWriteRes<[ZnALU1]> {
673 def : InstRW<[ZnWriteMulX64], (instrs MULX64rr)>;
676 def ZnWriteMulX64Ld : SchedWriteRes<[ZnAGU, ZnALU1, ZnMultiplier]> {
679 def : InstRW<[ZnWriteMulX64Ld, ReadAfterLd], (instrs MULX64rm)>;
681 //-- Control transfer instructions --//
684 def ZnWriteJCXZ : SchedWriteRes<[ZnALU03]>;
685 def : InstRW<[ZnWriteJCXZ], (instrs JCXZ, JECXZ, JRCXZ)>;
688 def : InstRW<[WriteMicrocoded], (instrs INTO)>;
691 def ZnWriteLOOP : SchedWriteRes<[ZnALU03]>;
692 def : InstRW<[ZnWriteLOOP], (instrs LOOP)>;
694 // LOOP(N)E, LOOP(N)Z
695 def ZnWriteLOOPE : SchedWriteRes<[ZnALU03]>;
696 def : InstRW<[ZnWriteLOOPE], (instrs LOOPE, LOOPNE)>;
700 def ZnWriteCALLr : SchedWriteRes<[ZnAGU, ZnALU03]>;
701 def : InstRW<[ZnWriteCALLr], (instregex "CALL(16|32)r")>;
703 def : InstRW<[WriteMicrocoded], (instregex "CALL(16|32)m")>;
706 def ZnWriteRET : SchedWriteRes<[ZnALU03]> {
709 def : InstRW<[ZnWriteRET], (instregex "RET(L|Q|W)", "LRET(L|Q|W)",
712 //-- Logic instructions --//
716 def : InstRW<[WriteALULd],
717 (instregex "(AND|OR|XOR)(8|16|32|64)m(r|i)",
718 "(AND|OR|XOR)(8|16|32|64)mi8", "(AND|OR|XOR)64mi32")>;
720 // Define ALU latency variants
721 def ZnWriteALULat2 : SchedWriteRes<[ZnALU]> {
724 def ZnWriteALULat2Ld : SchedWriteRes<[ZnAGU, ZnALU]> {
730 def ZnWriteBTRSCm : SchedWriteRes<[ZnAGU, ZnALU]> {
735 def : SchedAlias<WriteBitTestSetImmRMW, ZnWriteBTRSCm>;
736 def : SchedAlias<WriteBitTestSetRegRMW, ZnWriteBTRSCm>;
740 def : SchedAlias<WriteBLS, ZnWriteALULat2>;
742 def : SchedAlias<WriteBLSLd, ZnWriteALULat2Ld>;
745 def : InstRW<[WriteALU], (instrs STD, CLD)>;
749 def : InstRW<[WriteMicrocoded], (instregex "PDEP(32|64)rr", "PEXT(32|64)rr")>;
751 def : InstRW<[WriteMicrocoded], (instregex "PDEP(32|64)rm", "PEXT(32|64)rm")>;
755 def : InstRW<[WriteMicrocoded], (instregex "RC(R|L)(8|16|32|64)m(1|i|CL)")>;
759 def : InstRW<[WriteShiftLd], (instregex "S(A|H)(R|L)(8|16|32|64)m(i|1)")>;
763 def : InstRW<[WriteShiftLd], (instregex "SH(R|L)D(16|32|64)mri8")>;
766 def : InstRW<[WriteMicrocoded], (instregex "SH(R|L)D(16|32|64)rrCL")>;
769 def : InstRW<[WriteMicrocoded], (instregex "SH(R|L)D(16|32|64)mrCL")>;
771 //-- Misc instructions --//
773 def ZnWriteCMPXCHG8B : SchedWriteRes<[ZnAGU, ZnALU]> {
774 let NumMicroOps = 18;
776 def : InstRW<[ZnWriteCMPXCHG8B], (instrs CMPXCHG8B)>;
778 def : InstRW<[WriteMicrocoded], (instrs CMPXCHG16B)>;
781 def ZnWriteLEAVE : SchedWriteRes<[ZnALU, ZnAGU]> {
785 def : InstRW<[ZnWriteLEAVE], (instregex "LEAVE")>;
788 def : InstRW<[WriteMicrocoded], (instrs PAUSE)>;
791 def : InstRW<[WriteMicrocoded], (instregex "RDTSC")>;
794 def : InstRW<[WriteMicrocoded], (instrs RDPMC)>;
797 def : InstRW<[WriteMicrocoded], (instrs RDRAND16r, RDRAND32r, RDRAND64r)>;
800 def : InstRW<[WriteMicrocoded], (instrs XGETBV)>;
802 //-- String instructions --//
804 def : InstRW<[WriteMicrocoded], (instregex "CMPS(B|L|Q|W)")>;
807 def : InstRW<[WriteMicrocoded], (instregex "LODS(B|W)")>;
810 def : InstRW<[WriteMicrocoded], (instregex "LODS(L|Q)")>;
813 def : InstRW<[WriteMicrocoded], (instregex "MOVS(B|L|Q|W)")>;
816 def : InstRW<[WriteMicrocoded], (instregex "SCAS(B|W|L|Q)")>;
819 def : InstRW<[WriteMicrocoded], (instregex "STOS(B|L|Q|W)")>;
822 def ZnXADD : SchedWriteRes<[ZnALU]>;
823 def : InstRW<[ZnXADD], (instregex "XADD(8|16|32|64)rr")>;
824 def : InstRW<[WriteMicrocoded], (instregex "XADD(8|16|32|64)rm")>;
826 //=== Floating Point x87 Instructions ===//
827 //-- Move instructions --//
829 def ZnWriteFLDr : SchedWriteRes<[ZnFPU13]> ;
831 def ZnWriteSTr: SchedWriteRes<[ZnFPU23]> {
838 def : InstRW<[ZnWriteFLDr], (instrs LD_Frr)>;
841 def ZnWriteLD_F80m : SchedWriteRes<[ZnAGU, ZnFPU13]> {
844 def : InstRW<[ZnWriteLD_F80m], (instrs LD_F80m)>;
847 def : InstRW<[WriteMicrocoded], (instrs FBLDm)>;
851 def : InstRW<[ZnWriteSTr], (instregex "ST_(F|FP)rr")>;
854 def ZnWriteST_FP80m : SchedWriteRes<[ZnAGU, ZnFPU23]> {
857 def : InstRW<[ZnWriteST_FP80m], (instrs ST_FP80m)>;
861 def : InstRW<[WriteMicrocoded], (instrs FBSTPm)>;
863 def ZnWriteFXCH : SchedWriteRes<[ZnFPU]>;
866 def : InstRW<[ZnWriteFXCH], (instrs XCH_F)>;
869 def ZnWriteFILD : SchedWriteRes<[ZnAGU, ZnFPU3]> {
873 def : InstRW<[ZnWriteFILD], (instregex "ILD_F(16|32|64)m")>;
876 def ZnWriteFIST : SchedWriteRes<[ZnAGU, ZnFPU23]> {
879 def : InstRW<[ZnWriteFIST], (instregex "IS(T|TT)_(F|FP)(16|32|64)m")>;
881 def ZnWriteFPU13 : SchedWriteRes<[ZnAGU, ZnFPU13]> {
885 def ZnWriteFPU3 : SchedWriteRes<[ZnAGU, ZnFPU3]> {
890 def : SchedAlias<WriteFLD0, ZnWriteFPU13>;
893 def : SchedAlias<WriteFLD1, ZnWriteFPU3>;
896 def : SchedAlias<WriteFLDC, ZnWriteFPU3>;
900 def : InstRW<[WriteMicrocoded], (instrs FNSTSW16r)>;
903 def : InstRW<[WriteMicrocoded], (instrs FNSTSWm)>;
906 def : InstRW<[WriteMicrocoded], (instrs FLDCW16m)>;
909 def : InstRW<[WriteMicrocoded], (instrs FNSTCW16m)>;
912 def : InstRW<[ZnWriteFPU3], (instrs FINCSTP, FDECSTP)>;
915 def : InstRW<[ZnWriteFPU3], (instregex "FFREE")>;
918 def : InstRW<[WriteMicrocoded], (instrs FSAVEm)>;
921 def : InstRW<[WriteMicrocoded], (instrs FRSTORm)>;
923 //-- Arithmetic instructions --//
925 def ZnWriteFPU3Lat1 : SchedWriteRes<[ZnFPU3]> ;
927 def ZnWriteFPU0Lat1 : SchedWriteRes<[ZnFPU0]> ;
929 def ZnWriteFPU0Lat1Ld : SchedWriteRes<[ZnAGU, ZnFPU0]> {
934 def : InstRW<[ZnWriteFPU3Lat1], (instregex "CHS_F")>;
938 def : InstRW<[ZnWriteFPU0Lat1], (instregex "COM(P?)_FST0r", "UCOM_F(P?)r")>;
940 def : InstRW<[ZnWriteFPU0Lat1Ld], (instregex "FCOM(P?)(32|64)m")>;
944 def : InstRW<[ZnWriteFPU0Lat1], (instrs FCOMPP, UCOM_FPPr)>;
946 def ZnWriteFPU02 : SchedWriteRes<[ZnAGU, ZnFPU02]>
951 // FCOMI(P) FUCOMI(P).
953 def : InstRW<[ZnWriteFPU02], (instrs COM_FIPr, COM_FIr, UCOM_FIPr, UCOM_FIr)>;
955 def ZnWriteFPU03 : SchedWriteRes<[ZnAGU, ZnFPU03]>
959 let ResourceCycles = [1,3];
963 def : InstRW<[ZnWriteFPU03], (instregex "FICOM(P?)(16|32)m")>;
966 def : InstRW<[ZnWriteFPU0Lat1], (instregex "TST_F")>;
969 def : InstRW<[ZnWriteFPU3Lat1], (instrs FXAM)>;
972 def : InstRW<[WriteMicrocoded], (instrs FPREM)>;
975 def : InstRW<[WriteMicrocoded], (instrs FPREM1)>;
978 def : InstRW<[WriteMicrocoded], (instrs FRNDINT)>;
981 def : InstRW<[WriteMicrocoded], (instrs FSCALE)>;
984 def : InstRW<[WriteMicrocoded], (instrs FXTRACT)>;
987 def : InstRW<[ZnWriteFPU0Lat1], (instrs FNOP)>;
990 def : InstRW<[ZnWriteFPU0Lat1], (instrs WAIT)>;
993 def : InstRW<[WriteMicrocoded], (instrs FNCLEX)>;
996 def : InstRW<[WriteMicrocoded], (instrs FNINIT)>;
998 //=== Integer MMX and XMM Instructions ===//
1002 def ZnWriteFPU12 : SchedWriteRes<[ZnFPU12]> ;
1003 def ZnWriteFPU12Y : SchedWriteRes<[ZnFPU12]> {
1004 let NumMicroOps = 2;
1006 def ZnWriteFPU12m : SchedWriteRes<[ZnAGU, ZnFPU12]> ;
1007 def ZnWriteFPU12Ym : SchedWriteRes<[ZnAGU, ZnFPU12]> {
1009 let NumMicroOps = 2;
1012 def : InstRW<[ZnWriteFPU12], (instrs MMX_PACKSSDWirr,
1015 def : InstRW<[ZnWriteFPU12m], (instrs MMX_PACKSSDWirm,
1019 // VPMOVSX/ZX BW BD BQ WD WQ DQ.
1021 def : InstRW<[ZnWriteFPU12Y], (instregex "VPMOV(SX|ZX)(BW|BD|BQ|WD|WQ|DQ)Yrr")>;
1022 def : InstRW<[ZnWriteFPU12Ym], (instregex "VPMOV(SX|ZX)(BW|BD|BQ|WD|WQ|DQ)Yrm")>;
1024 def ZnWriteFPU013 : SchedWriteRes<[ZnFPU013]> ;
1025 def ZnWriteFPU013Y : SchedWriteRes<[ZnFPU013]> {
1028 def ZnWriteFPU013m : SchedWriteRes<[ZnAGU, ZnFPU013]> {
1030 let NumMicroOps = 2;
1032 def ZnWriteFPU013Ld : SchedWriteRes<[ZnAGU, ZnFPU013]> {
1034 let NumMicroOps = 2;
1036 def ZnWriteFPU013LdY : SchedWriteRes<[ZnAGU, ZnFPU013]> {
1038 let NumMicroOps = 2;
1043 def : InstRW<[ZnWriteFPU013], (instregex "(V?)PBLENDWrri")>;
1045 def : InstRW<[ZnWriteFPU013Y], (instrs VPBLENDWYrri)>;
1048 def : InstRW<[ZnWriteFPU013Ld], (instregex "(V?)PBLENDWrmi")>;
1050 def : InstRW<[ZnWriteFPU013LdY], (instrs VPBLENDWYrmi)>;
1052 def ZnWriteFPU01 : SchedWriteRes<[ZnFPU01]> ;
1053 def ZnWriteFPU01Y : SchedWriteRes<[ZnFPU01]> {
1054 let NumMicroOps = 2;
1059 def : InstRW<[ZnWriteFPU01], (instrs VPBLENDDrri)>;
1061 def : InstRW<[ZnWriteFPU01Y], (instrs VPBLENDDYrri)>;
1064 def ZnWriteFPU01Op2 : SchedWriteRes<[ZnAGU, ZnFPU01]> {
1065 let NumMicroOps = 2;
1067 let ResourceCycles = [1, 2];
1069 def ZnWriteFPU01Op2Y : SchedWriteRes<[ZnAGU, ZnFPU01]> {
1070 let NumMicroOps = 2;
1072 let ResourceCycles = [1, 3];
1074 def : InstRW<[ZnWriteFPU01Op2], (instrs VPBLENDDrmi)>;
1075 def : InstRW<[ZnWriteFPU01Op2Y], (instrs VPBLENDDYrmi)>;
1078 def : InstRW<[WriteMicrocoded], (instregex "MMX_MASKMOVQ(64)?")>;
1081 def : InstRW<[WriteMicrocoded], (instregex "(V?)MASKMOVDQU(64)?")>;
1085 def : InstRW<[WriteMicrocoded],
1086 (instregex "VPMASKMOVD(Y?)rm")>;
1088 def : InstRW<[WriteMicrocoded], (instregex "VPMASKMOV(D|Q)(Y?)mr")>;
1092 def ZnWriteVPBROADCAST128Ld : SchedWriteRes<[ZnAGU, ZnFPU12]> {
1094 let NumMicroOps = 2;
1095 let ResourceCycles = [1, 2];
1097 def : InstRW<[ZnWriteVPBROADCAST128Ld],
1098 (instregex "VPBROADCAST(B|W)rm")>;
1101 def ZnWriteVPBROADCAST256Ld : SchedWriteRes<[ZnAGU, ZnFPU1]> {
1103 let NumMicroOps = 2;
1104 let ResourceCycles = [1, 2];
1106 def : InstRW<[ZnWriteVPBROADCAST256Ld],
1107 (instregex "VPBROADCAST(B|W)Yrm")>;
1110 def : InstRW<[WriteMicrocoded], (instregex "VPGATHER(Q|D)(Q|D)(Y?)rm")>;
1112 //-- Arithmetic instructions --//
1115 // PHADD|PHSUB (S) W/D.
1116 def : SchedAlias<WritePHAdd, ZnWriteMicrocoded>;
1117 def : SchedAlias<WritePHAddLd, ZnWriteMicrocoded>;
1118 def : SchedAlias<WritePHAddX, ZnWriteMicrocoded>;
1119 def : SchedAlias<WritePHAddXLd, ZnWriteMicrocoded>;
1120 def : SchedAlias<WritePHAddY, ZnWriteMicrocoded>;
1121 def : SchedAlias<WritePHAddYLd, ZnWriteMicrocoded>;
1124 def ZnWritePCMPGTQr : SchedWriteRes<[ZnFPU03]>;
1125 def : InstRW<[ZnWritePCMPGTQr], (instregex "(V?)PCMPGTQ(Y?)rr")>;
1128 def ZnWritePCMPGTQm : SchedWriteRes<[ZnAGU, ZnFPU03]> {
1132 def ZnWritePCMPGTQYm : SchedWriteRes<[ZnAGU, ZnFPU03]> {
1134 let NumMicroOps = 2;
1135 let ResourceCycles = [1,2];
1137 def : InstRW<[ZnWritePCMPGTQm], (instregex "(V?)PCMPGTQrm")>;
1138 def : InstRW<[ZnWritePCMPGTQYm], (instrs VPCMPGTQYrm)>;
1140 //-- Logic instructions --//
1142 // PSLL,PSRL,PSRA W/D/Q.
1144 def ZnWritePShift : SchedWriteRes<[ZnFPU2]> ;
1145 def ZnWritePShiftY : SchedWriteRes<[ZnFPU2]> {
1150 def : InstRW<[ZnWritePShift], (instregex "(V?)PS(R|L)LDQri")>;
1151 def : InstRW<[ZnWritePShiftY], (instregex "(V?)PS(R|L)LDQYri")>;
1153 //=== Floating Point XMM and YMM Instructions ===//
1154 //-- Move instructions --//
1157 def : InstRW<[WriteMicrocoded], (instrs VPERM2F128rr)>;
1158 def : InstRW<[WriteMicrocoded], (instrs VPERM2F128rm)>;
1160 def ZnWriteBROADCAST : SchedWriteRes<[ZnAGU, ZnFPU13]> {
1161 let NumMicroOps = 2;
1165 def : InstRW<[ZnWriteBROADCAST], (instrs VBROADCASTF128)>;
1169 def ZnWriteEXTRACTPSr : SchedWriteRes<[ZnFPU12, ZnFPU2]> {
1171 let NumMicroOps = 2;
1172 let ResourceCycles = [1, 2];
1174 def : InstRW<[ZnWriteEXTRACTPSr], (instregex "(V?)EXTRACTPSrr")>;
1176 def ZnWriteEXTRACTPSm : SchedWriteRes<[ZnAGU,ZnFPU12, ZnFPU2]> {
1178 let NumMicroOps = 2;
1179 let ResourceCycles = [5, 1, 2];
1182 def : InstRW<[ZnWriteEXTRACTPSm], (instregex "(V?)EXTRACTPSmr")>;
1186 def : InstRW<[ZnWriteFPU013], (instrs VEXTRACTF128rr)>;
1189 def : InstRW<[ZnWriteFPU013m], (instrs VEXTRACTF128mr)>;
1191 def ZnWriteVINSERT128r: SchedWriteRes<[ZnFPU013]> {
1193 let ResourceCycles = [2];
1195 def ZnWriteVINSERT128Ld: SchedWriteRes<[ZnAGU,ZnFPU013]> {
1197 let NumMicroOps = 2;
1198 let ResourceCycles = [1, 2];
1202 def : InstRW<[ZnWriteVINSERT128r], (instrs VINSERTF128rr)>;
1203 def : InstRW<[ZnWriteVINSERT128Ld], (instrs VINSERTF128rm)>;
1206 def : InstRW<[WriteMicrocoded], (instregex "VGATHER(Q|D)(PD|PS)(Y?)rm")>;
1208 //-- Conversion instructions --//
1209 def ZnWriteCVTPD2PSr: SchedWriteRes<[ZnFPU3]> {
1212 def ZnWriteCVTPD2PSYr: SchedWriteRes<[ZnFPU3]> {
1218 def : SchedAlias<WriteCvtPD2PS, ZnWriteCVTPD2PSr>;
1220 def : SchedAlias<WriteCvtPD2PSY, ZnWriteCVTPD2PSYr>;
1222 defm : X86WriteResUnsupported<WriteCvtPD2PSZ>;
1224 def ZnWriteCVTPD2PSLd: SchedWriteRes<[ZnAGU,ZnFPU03]> {
1226 let NumMicroOps = 2;
1227 let ResourceCycles = [1,2];
1230 def : SchedAlias<WriteCvtPD2PSLd, ZnWriteCVTPD2PSLd>;
1233 def ZnWriteCVTPD2PSYLd : SchedWriteRes<[ZnAGU, ZnFPU3]> {
1236 def : SchedAlias<WriteCvtPD2PSYLd, ZnWriteCVTPD2PSYLd>;
1238 defm : X86WriteResUnsupported<WriteCvtPD2PSZLd>;
1242 // Same as WriteCVTPD2PSr
1243 def : SchedAlias<WriteCvtSD2SS, ZnWriteCVTPD2PSr>;
1246 def : SchedAlias<WriteCvtSD2SSLd, ZnWriteCVTPD2PSLd>;
1250 def ZnWriteCVTPS2PDr : SchedWriteRes<[ZnFPU3]> {
1253 def : SchedAlias<WriteCvtPS2PD, ZnWriteCVTPS2PDr>;
1257 def ZnWriteCVTPS2PDLd : SchedWriteRes<[ZnAGU, ZnFPU3]> {
1259 let NumMicroOps = 2;
1261 def : SchedAlias<WriteCvtPS2PDLd, ZnWriteCVTPS2PDLd>;
1262 def : SchedAlias<WriteCvtPS2PDYLd, ZnWriteCVTPS2PDLd>;
1263 defm : X86WriteResUnsupported<WriteCvtPS2PDZLd>;
1266 def ZnWriteVCVTPS2PDY : SchedWriteRes<[ZnFPU3]> {
1269 def : SchedAlias<WriteCvtPS2PDY, ZnWriteVCVTPS2PDY>;
1270 defm : X86WriteResUnsupported<WriteCvtPS2PDZ>;
1274 def ZnWriteCVTSS2SDr : SchedWriteRes<[ZnFPU3]> {
1277 def : SchedAlias<WriteCvtSS2SD, ZnWriteCVTSS2SDr>;
1280 def ZnWriteCVTSS2SDLd : SchedWriteRes<[ZnAGU, ZnFPU3]> {
1282 let NumMicroOps = 2;
1283 let ResourceCycles = [1, 2];
1285 def : SchedAlias<WriteCvtSS2SDLd, ZnWriteCVTSS2SDLd>;
1287 def ZnWriteCVTDQ2PDr: SchedWriteRes<[ZnFPU12,ZnFPU3]> {
1292 def : InstRW<[ZnWriteCVTDQ2PDr], (instregex "(V)?CVTDQ2PDrr")>;
1296 def : InstRW<[ZnWriteCVTDQ2PDr], (instrs VCVTDQ2PDYrr)>;
1298 def ZnWriteCVTPD2DQr: SchedWriteRes<[ZnFPU12, ZnFPU3]> {
1303 def : InstRW<[ZnWriteCVTDQ2PDr], (instregex "(V?)CVT(T?)PD2DQrr")>;
1305 def ZnWriteCVTPD2DQLd: SchedWriteRes<[ZnAGU,ZnFPU12,ZnFPU3]> {
1307 let NumMicroOps = 2;
1310 def : InstRW<[ZnWriteCVTPD2DQLd], (instregex "(V?)CVT(T?)PD2DQrm")>;
1311 // same as xmm handling
1313 def : InstRW<[ZnWriteCVTPD2DQr], (instregex "VCVT(T?)PD2DQYrr")>;
1315 def : InstRW<[ZnWriteCVTPD2DQLd], (instregex "VCVT(T?)PD2DQYrm")>;
1317 def ZnWriteCVTPS2PIr: SchedWriteRes<[ZnFPU3]> {
1322 def : InstRW<[ZnWriteCVTPS2PIr], (instregex "MMX_CVT(T?)PS2PIirr")>;
1326 def : InstRW<[ZnWriteCVTPS2PDr], (instrs MMX_CVTPI2PDirr)>;
1330 def : InstRW<[ZnWriteCVTPS2PIr], (instregex "MMX_CVT(T?)PD2PIirr")>;
1332 def ZnWriteCVSTSI2SSr: SchedWriteRes<[ZnFPU3]> {
1336 // same as CVTPD2DQr
1339 def : InstRW<[ZnWriteCVTPD2DQr], (instregex "(V?)CVT(T?)SS2SI(64)?rr")>;
1340 // same as CVTPD2DQm
1342 def : InstRW<[ZnWriteCVTPD2DQLd], (instregex "(V?)CVT(T?)SS2SI(64)?rm")>;
1344 def ZnWriteCVSTSI2SDr: SchedWriteRes<[ZnFPU013, ZnFPU3]> {
1349 def : InstRW<[ZnWriteCVSTSI2SDr], (instregex "(V?)CVTSI(64)?2SDrr")>;
1352 def ZnWriteCVSTSI2SIr: SchedWriteRes<[ZnFPU3, ZnFPU2]> {
1355 def ZnWriteCVSTSI2SILd: SchedWriteRes<[ZnAGU, ZnFPU3, ZnFPU2]> {
1360 def : InstRW<[ZnWriteCVSTSI2SIr], (instregex "(V?)CVT(T?)SD2SI(64)?rr")>;
1362 def : InstRW<[ZnWriteCVSTSI2SILd], (instregex "(V?)CVT(T?)SD2SI(64)?rm")>;
1366 def : SchedAlias<WriteCvtPS2PH, ZnWriteMicrocoded>;
1367 def : SchedAlias<WriteCvtPS2PHY, ZnWriteMicrocoded>;
1368 defm : X86WriteResUnsupported<WriteCvtPS2PHZ>;
1370 def : SchedAlias<WriteCvtPS2PHSt, ZnWriteMicrocoded>;
1371 def : SchedAlias<WriteCvtPS2PHYSt, ZnWriteMicrocoded>;
1372 defm : X86WriteResUnsupported<WriteCvtPS2PHZSt>;
1376 def : SchedAlias<WriteCvtPH2PS, ZnWriteMicrocoded>;
1377 def : SchedAlias<WriteCvtPH2PSY, ZnWriteMicrocoded>;
1378 defm : X86WriteResUnsupported<WriteCvtPH2PSZ>;
1380 def : SchedAlias<WriteCvtPH2PSLd, ZnWriteMicrocoded>;
1381 def : SchedAlias<WriteCvtPH2PSYLd, ZnWriteMicrocoded>;
1382 defm : X86WriteResUnsupported<WriteCvtPH2PSZLd>;
1384 //-- SSE4A instructions --//
1386 def ZnWriteEXTRQ: SchedWriteRes<[ZnFPU12, ZnFPU2]> {
1389 def : InstRW<[ZnWriteEXTRQ], (instregex "EXTRQ")>;
1392 def ZnWriteINSERTQ: SchedWriteRes<[ZnFPU03,ZnFPU1]> {
1395 def : InstRW<[ZnWriteINSERTQ], (instregex "INSERTQ")>;
1397 //-- SHA instructions --//
1399 def : InstRW<[WriteMicrocoded], (instregex "SHA256MSG2(Y?)r(r|m)")>;
1401 // SHA1MSG1, SHA256MSG1
1403 def ZnWriteSHA1MSG1r : SchedWriteRes<[ZnFPU12]> {
1405 let ResourceCycles = [2];
1407 def : InstRW<[ZnWriteSHA1MSG1r], (instregex "SHA(1|256)MSG1rr")>;
1409 def ZnWriteSHA1MSG1Ld : SchedWriteRes<[ZnAGU, ZnFPU12]> {
1411 let ResourceCycles = [1,2];
1413 def : InstRW<[ZnWriteSHA1MSG1Ld], (instregex "SHA(1|256)MSG1rm")>;
1417 def ZnWriteSHA1MSG2r : SchedWriteRes<[ZnFPU12]> ;
1418 def : InstRW<[ZnWriteSHA1MSG2r], (instrs SHA1MSG2rr)>;
1420 def ZnWriteSHA1MSG2Ld : SchedWriteRes<[ZnAGU, ZnFPU12]> {
1423 def : InstRW<[ZnWriteSHA1MSG2Ld], (instrs SHA1MSG2rm)>;
1427 def ZnWriteSHA1NEXTEr : SchedWriteRes<[ZnFPU1]> ;
1428 def : InstRW<[ZnWriteSHA1NEXTEr], (instrs SHA1NEXTErr)>;
1430 def ZnWriteSHA1NEXTELd : SchedWriteRes<[ZnAGU, ZnFPU1]> {
1433 def : InstRW<[ZnWriteSHA1NEXTELd], (instrs SHA1NEXTErm)>;
1437 def ZnWriteSHA1RNDS4r : SchedWriteRes<[ZnFPU1]> {
1440 def : InstRW<[ZnWriteSHA1RNDS4r], (instrs SHA1RNDS4rri)>;
1442 def ZnWriteSHA1RNDS4Ld : SchedWriteRes<[ZnAGU, ZnFPU1]> {
1445 def : InstRW<[ZnWriteSHA1RNDS4Ld], (instrs SHA1RNDS4rmi)>;
1449 def ZnWriteSHA256RNDS2r : SchedWriteRes<[ZnFPU1]> {
1452 def : InstRW<[ZnWriteSHA256RNDS2r], (instrs SHA256RNDS2rr)>;
1454 def ZnWriteSHA256RNDS2Ld : SchedWriteRes<[ZnAGU, ZnFPU1]> {
1457 def : InstRW<[ZnWriteSHA256RNDS2Ld], (instrs SHA256RNDS2rm)>;
1459 //-- Arithmetic instructions --//
1462 def : SchedAlias<WriteFHAdd, ZnWriteMicrocoded>;
1463 def : SchedAlias<WriteFHAddLd, ZnWriteMicrocoded>;
1464 def : SchedAlias<WriteFHAddY, ZnWriteMicrocoded>;
1465 def : SchedAlias<WriteFHAddYLd, ZnWriteMicrocoded>;
1468 // TODO - convert to ZnWriteResFpuPair
1470 def ZnWriteVDIVPSYr : SchedWriteRes<[ZnFPU3]> {
1472 let ResourceCycles = [12];
1474 def : SchedAlias<WriteFDivY, ZnWriteVDIVPSYr>;
1477 def ZnWriteVDIVPSYLd : SchedWriteRes<[ZnAGU, ZnFPU3]> {
1479 let NumMicroOps = 2;
1480 let ResourceCycles = [1, 19];
1482 def : SchedAlias<WriteFDivYLd, ZnWriteVDIVPSYLd>;
1485 // TODO - convert to ZnWriteResFpuPair
1487 def ZnWriteVDIVPDY : SchedWriteRes<[ZnFPU3]> {
1489 let ResourceCycles = [15];
1491 def : SchedAlias<WriteFDiv64Y, ZnWriteVDIVPDY>;
1494 def ZnWriteVDIVPDYLd : SchedWriteRes<[ZnAGU, ZnFPU3]> {
1496 let NumMicroOps = 2;
1497 let ResourceCycles = [1,22];
1499 def : SchedAlias<WriteFDiv64YLd, ZnWriteVDIVPDYLd>;
1503 def : SchedAlias<WriteDPPS, ZnWriteMicrocoded>;
1504 def : SchedAlias<WriteDPPSY, ZnWriteMicrocoded>;
1507 def : SchedAlias<WriteDPPSLd, ZnWriteMicrocoded>;
1508 def : SchedAlias<WriteDPPSYLd,ZnWriteMicrocoded>;
1512 def : SchedAlias<WriteDPPD, ZnWriteMicrocoded>;
1515 def : SchedAlias<WriteDPPDLd, ZnWriteMicrocoded>;
1518 // TODO - convert to ZnWriteResFpuPair
1520 def ZnWriteRSQRTSSr : SchedWriteRes<[ZnFPU02]> {
1523 def : SchedAlias<WriteFRsqrt, ZnWriteRSQRTSSr>;
1526 def ZnWriteRSQRTSSLd: SchedWriteRes<[ZnAGU, ZnFPU02]> {
1528 let NumMicroOps = 2;
1529 let ResourceCycles = [1,2]; // FIXME: Is this right?
1531 def : SchedAlias<WriteFRsqrtLd, ZnWriteRSQRTSSLd>;
1534 // TODO - convert to ZnWriteResFpuPair
1536 def ZnWriteRSQRTPSYr : SchedWriteRes<[ZnFPU01]> {
1538 let NumMicroOps = 2;
1539 let ResourceCycles = [2];
1541 def : SchedAlias<WriteFRsqrtY, ZnWriteRSQRTPSYr>;
1544 def ZnWriteRSQRTPSYLd : SchedWriteRes<[ZnAGU, ZnFPU01]> {
1546 let NumMicroOps = 2;
1548 def : SchedAlias<WriteFRsqrtYLd, ZnWriteRSQRTPSYLd>;
1550 //-- Other instructions --//
1553 def : InstRW<[WriteMicrocoded], (instrs VZEROUPPER)>;
1556 def : InstRW<[WriteMicrocoded], (instrs VZEROALL)>;