1 //=- X86ScheduleZnver2.td - X86 Znver2 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 Znver2 to support instruction
10 // scheduling and other instruction cost heuristics.
12 //===----------------------------------------------------------------------===//
14 def Znver2Model : SchedMachineModel {
15 // Zen can decode 4 instructions per cycle.
17 // Based on the reorder buffer we define MicroOpBufferSize
18 let MicroOpBufferSize = 224;
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 = Znver2Model in {
33 // Zen can issue micro-ops to 10 different units in one cycle.
35 // * Four integer ALU units (ZALU0, ZALU1, ZALU2, ZALU3)
36 // * Three AGU units (ZAGU0, ZAGU1, ZAGU2)
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 Zn2ALU0 : ProcResource<1>;
42 def Zn2ALU1 : ProcResource<1>;
43 def Zn2ALU2 : ProcResource<1>;
44 def Zn2ALU3 : ProcResource<1>;
46 // Three AGU units are defined below
47 def Zn2AGU0 : ProcResource<1>;
48 def Zn2AGU1 : ProcResource<1>;
49 def Zn2AGU2 : ProcResource<1>;
51 // Four FPU units are defined below
52 def Zn2FPU0 : ProcResource<1>;
53 def Zn2FPU1 : ProcResource<1>;
54 def Zn2FPU2 : ProcResource<1>;
55 def Zn2FPU3 : ProcResource<1>;
58 def Zn2FPU013 : ProcResGroup<[Zn2FPU0, Zn2FPU1, Zn2FPU3]>;
59 def Zn2FPU01 : ProcResGroup<[Zn2FPU0, Zn2FPU1]>;
60 def Zn2FPU12 : ProcResGroup<[Zn2FPU1, Zn2FPU2]>;
61 def Zn2FPU13 : ProcResGroup<[Zn2FPU1, Zn2FPU3]>;
62 def Zn2FPU23 : ProcResGroup<[Zn2FPU2, Zn2FPU3]>;
63 def Zn2FPU02 : ProcResGroup<[Zn2FPU0, Zn2FPU2]>;
64 def Zn2FPU03 : ProcResGroup<[Zn2FPU0, Zn2FPU3]>;
66 // Below are the grouping of the units.
67 // Micro-ops to be issued to multiple units are tackled this way.
70 // Zn2ALU03 - 0,3 grouping
71 def Zn2ALU03: ProcResGroup<[Zn2ALU0, Zn2ALU3]>;
73 // 64 Entry (16x4 entries) Int Scheduler
74 def Zn2ALU : ProcResGroup<[Zn2ALU0, Zn2ALU1, Zn2ALU2, Zn2ALU3]> {
78 // 28 Entry (14x2) AGU group. AGUs can't be used for all ALU operations
79 // but are relevant for some instructions
80 def Zn2AGU : ProcResGroup<[Zn2AGU0, Zn2AGU1, Zn2AGU2]> {
84 // Integer Multiplication issued on ALU1.
85 def Zn2Multiplier : ProcResource<1>;
87 // Integer division issued on ALU2.
88 def Zn2Divider : ProcResource<1>;
90 // 4 Cycles load-to use Latency is captured
91 def : ReadAdvance<ReadAfterLd, 4>;
93 // 7 Cycles vector load-to use Latency is captured
94 def : ReadAdvance<ReadAfterVecLd, 7>;
95 def : ReadAdvance<ReadAfterVecXLd, 7>;
96 def : ReadAdvance<ReadAfterVecYLd, 7>;
98 def : ReadAdvance<ReadInt2Fpu, 0>;
100 // The Integer PRF for Zen is 168 entries, and it holds the architectural and
101 // speculative version of the 64-bit integer registers.
102 // Reference: "Software Optimization Guide for AMD Family 17h Processors"
103 def Zn2IntegerPRF : RegisterFile<168, [GR64, CCR]>;
105 // 36 Entry (9x4 entries) floating-point Scheduler
106 def Zn2FPU : ProcResGroup<[Zn2FPU0, Zn2FPU1, Zn2FPU2, Zn2FPU3]> {
110 // The Zen FP Retire Queue renames SIMD and FP uOps onto a pool of 160 128-bit
111 // registers. Operations on 256-bit data types are cracked into two COPs.
112 // Reference: "Software Optimization Guide for AMD Family 17h Processors"
113 def Zn2FpuPRF: RegisterFile<160, [VR64, VR128, VR256], [1, 1, 2]>;
115 // The unit can track up to 192 macro ops in-flight.
116 // The retire unit handles in-order commit of up to 8 macro ops per cycle.
117 // Reference: "Software Optimization Guide for AMD Family 17h Processors"
118 // To be noted, the retire unit is shared between integer and FP ops.
119 // In SMT mode it is 96 entry per thread. But, we do not use the conservative
120 // value here because there is currently no way to fully mode the SMT mode,
121 // so there is no point in trying.
122 def Zn2RCU : RetireControlUnit<192, 8>;
124 // (a folded load is an instruction that loads and does some operation)
125 // Ex: ADDPD xmm,[mem]-> This instruction has two micro-ops
126 // Instructions with folded loads are usually micro-fused, so they only appear
130 // This multiclass is for folded loads for integer units.
131 multiclass Zn2WriteResPair<X86FoldableSchedWrite SchedRW,
132 list<ProcResourceKind> ExePorts,
133 int Lat, list<int> Res = [], int UOps = 1,
134 int LoadLat = 4, int LoadUOps = 1> {
135 // Register variant takes 1-cycle on Execution Port.
136 def : WriteRes<SchedRW, ExePorts> {
138 let ResourceCycles = Res;
139 let NumMicroOps = UOps;
142 // Memory variant also uses a cycle on Zn2AGU
143 // adds LoadLat cycles to the latency (default = 4).
144 def : WriteRes<SchedRW.Folded, !listconcat([Zn2AGU], ExePorts)> {
145 let Latency = !add(Lat, LoadLat);
146 let ResourceCycles = !if(!empty(Res), [], !listconcat([1], Res));
147 let NumMicroOps = !add(UOps, LoadUOps);
151 // This multiclass is for folded loads for floating point units.
152 multiclass Zn2WriteResFpuPair<X86FoldableSchedWrite SchedRW,
153 list<ProcResourceKind> ExePorts,
154 int Lat, list<int> Res = [], int UOps = 1,
155 int LoadLat = 7, int LoadUOps = 0> {
156 // Register variant takes 1-cycle on Execution Port.
157 def : WriteRes<SchedRW, ExePorts> {
159 let ResourceCycles = Res;
160 let NumMicroOps = UOps;
163 // Memory variant also uses a cycle on Zn2AGU
164 // adds LoadLat cycles to the latency (default = 7).
165 def : WriteRes<SchedRW.Folded, !listconcat([Zn2AGU], ExePorts)> {
166 let Latency = !add(Lat, LoadLat);
167 let ResourceCycles = !if(!empty(Res), [], !listconcat([1], Res));
168 let NumMicroOps = !add(UOps, LoadUOps);
172 // WriteRMW is set for instructions with Memory write
173 // operation in codegen
174 def : WriteRes<WriteRMW, [Zn2AGU]>;
176 def : WriteRes<WriteStore, [Zn2AGU]>;
177 def : WriteRes<WriteStoreNT, [Zn2AGU]>;
178 def : WriteRes<WriteMove, [Zn2ALU]>;
179 def : WriteRes<WriteLoad, [Zn2AGU]> { let Latency = 8; }
181 // Model the effect of clobbering the read-write mask operand of the GATHER operation.
182 // Does not cost anything by itself, only has latency, matching that of the WriteLoad,
183 def : WriteRes<WriteVecMaskedGatherWriteback, []> { let Latency = 8; let NumMicroOps = 0; }
185 def : WriteRes<WriteZero, []>;
186 def : WriteRes<WriteLEA, [Zn2ALU]>;
187 defm : Zn2WriteResPair<WriteALU, [Zn2ALU], 1>;
188 defm : Zn2WriteResPair<WriteADC, [Zn2ALU], 1>;
190 defm : Zn2WriteResPair<WriteIMul8, [Zn2ALU1, Zn2Multiplier], 4>;
192 defm : X86WriteRes<WriteBSWAP32, [Zn2ALU], 1, [4], 1>;
193 defm : X86WriteRes<WriteBSWAP64, [Zn2ALU], 1, [4], 1>;
194 defm : X86WriteRes<WriteCMPXCHG, [Zn2ALU], 3, [1], 1>;
195 defm : X86WriteRes<WriteCMPXCHGRMW,[Zn2ALU,Zn2AGU], 8, [1,1], 5>;
196 defm : X86WriteRes<WriteXCHG, [Zn2ALU], 1, [2], 2>;
198 defm : Zn2WriteResPair<WriteShift, [Zn2ALU], 1>;
199 defm : Zn2WriteResPair<WriteShiftCL, [Zn2ALU], 1>;
200 defm : Zn2WriteResPair<WriteRotate, [Zn2ALU], 1>;
201 defm : Zn2WriteResPair<WriteRotateCL, [Zn2ALU], 1>;
203 defm : X86WriteRes<WriteSHDrri, [Zn2ALU], 1, [1], 1>;
204 defm : X86WriteResUnsupported<WriteSHDrrcl>;
205 defm : X86WriteResUnsupported<WriteSHDmri>;
206 defm : X86WriteResUnsupported<WriteSHDmrcl>;
208 defm : Zn2WriteResPair<WriteJump, [Zn2ALU], 1>;
209 defm : Zn2WriteResFpuPair<WriteCRC32, [Zn2FPU0], 3>;
211 defm : Zn2WriteResPair<WriteCMOV, [Zn2ALU], 1>;
212 def : WriteRes<WriteSETCC, [Zn2ALU]>;
213 def : WriteRes<WriteSETCCStore, [Zn2ALU, Zn2AGU]>;
214 defm : X86WriteRes<WriteLAHFSAHF, [Zn2ALU], 2, [1], 2>;
216 defm : X86WriteRes<WriteBitTest, [Zn2ALU], 1, [1], 1>;
217 defm : X86WriteRes<WriteBitTestImmLd, [Zn2ALU,Zn2AGU], 5, [1,1], 2>;
218 defm : X86WriteRes<WriteBitTestRegLd, [Zn2ALU,Zn2AGU], 5, [1,1], 2>;
219 defm : X86WriteRes<WriteBitTestSet, [Zn2ALU], 2, [1], 2>;
222 defm : Zn2WriteResPair<WriteBSF, [Zn2ALU], 3>;
223 defm : Zn2WriteResPair<WriteBSR, [Zn2ALU], 4>;
224 defm : Zn2WriteResPair<WriteLZCNT, [Zn2ALU], 1>;
225 defm : Zn2WriteResPair<WriteTZCNT, [Zn2ALU], 2>;
226 defm : Zn2WriteResPair<WritePOPCNT, [Zn2ALU], 1>;
228 // Treat misc copies as a move.
229 def : InstRW<[WriteMove], (instrs COPY)>;
231 // BMI1 BEXTR, BMI2 BZHI
232 defm : Zn2WriteResPair<WriteBEXTR, [Zn2ALU], 1>;
233 defm : Zn2WriteResPair<WriteBZHI, [Zn2ALU], 1>;
236 defm : Zn2WriteResPair<WriteDiv8, [Zn2ALU2, Zn2Divider], 15, [1,15], 1>;
237 defm : Zn2WriteResPair<WriteDiv16, [Zn2ALU2, Zn2Divider], 17, [1,17], 2>;
238 defm : Zn2WriteResPair<WriteDiv32, [Zn2ALU2, Zn2Divider], 25, [1,25], 2>;
239 defm : Zn2WriteResPair<WriteDiv64, [Zn2ALU2, Zn2Divider], 41, [1,41], 2>;
240 defm : Zn2WriteResPair<WriteIDiv8, [Zn2ALU2, Zn2Divider], 15, [1,15], 1>;
241 defm : Zn2WriteResPair<WriteIDiv16, [Zn2ALU2, Zn2Divider], 17, [1,17], 2>;
242 defm : Zn2WriteResPair<WriteIDiv32, [Zn2ALU2, Zn2Divider], 25, [1,25], 2>;
243 defm : Zn2WriteResPair<WriteIDiv64, [Zn2ALU2, Zn2Divider], 41, [1,41], 2>;
246 def : WriteRes<WriteIMulH, [Zn2Multiplier]>{
251 // Floating point operations
252 defm : X86WriteRes<WriteFLoad, [Zn2AGU], 8, [1], 1>;
253 defm : X86WriteRes<WriteFLoadX, [Zn2AGU], 8, [1], 1>;
254 defm : X86WriteRes<WriteFLoadY, [Zn2AGU], 8, [1], 1>;
255 defm : X86WriteRes<WriteFMaskedLoad, [Zn2AGU,Zn2FPU01], 8, [1,1], 1>;
256 defm : X86WriteRes<WriteFMaskedLoadY, [Zn2AGU,Zn2FPU01], 8, [1,1], 2>;
257 defm : X86WriteRes<WriteFMaskedStore32, [Zn2AGU,Zn2FPU01], 4, [1,1], 1>;
258 defm : X86WriteRes<WriteFMaskedStore32Y, [Zn2AGU,Zn2FPU01], 5, [1,2], 2>;
259 defm : X86WriteRes<WriteFMaskedStore64, [Zn2AGU,Zn2FPU01], 4, [1,1], 1>;
260 defm : X86WriteRes<WriteFMaskedStore64Y, [Zn2AGU,Zn2FPU01], 5, [1,2], 2>;
262 defm : X86WriteRes<WriteFStore, [Zn2AGU], 1, [1], 1>;
263 defm : X86WriteRes<WriteFStoreX, [Zn2AGU], 1, [1], 1>;
264 defm : X86WriteRes<WriteFStoreY, [Zn2AGU], 1, [1], 1>;
265 defm : X86WriteRes<WriteFStoreNT, [Zn2AGU,Zn2FPU2], 8, [1,1], 1>;
266 defm : X86WriteRes<WriteFStoreNTX, [Zn2AGU], 1, [1], 1>;
267 defm : X86WriteRes<WriteFStoreNTY, [Zn2AGU], 1, [1], 1>;
268 defm : X86WriteRes<WriteFMove, [Zn2FPU], 1, [1], 1>;
269 defm : X86WriteRes<WriteFMoveX, [Zn2FPU], 1, [1], 1>;
270 defm : X86WriteRes<WriteFMoveY, [Zn2FPU], 1, [1], 1>;
272 defm : Zn2WriteResFpuPair<WriteFAdd, [Zn2FPU0], 3>;
273 defm : Zn2WriteResFpuPair<WriteFAddX, [Zn2FPU0], 3>;
274 defm : Zn2WriteResFpuPair<WriteFAddY, [Zn2FPU0], 3>;
275 defm : X86WriteResPairUnsupported<WriteFAddZ>;
276 defm : Zn2WriteResFpuPair<WriteFAdd64, [Zn2FPU0], 3>;
277 defm : Zn2WriteResFpuPair<WriteFAdd64X, [Zn2FPU0], 3>;
278 defm : Zn2WriteResFpuPair<WriteFAdd64Y, [Zn2FPU0], 3>;
279 defm : X86WriteResPairUnsupported<WriteFAdd64Z>;
280 defm : Zn2WriteResFpuPair<WriteFCmp, [Zn2FPU0], 1>;
281 defm : Zn2WriteResFpuPair<WriteFCmpX, [Zn2FPU0], 1>;
282 defm : Zn2WriteResFpuPair<WriteFCmpY, [Zn2FPU0], 1>;
283 defm : X86WriteResPairUnsupported<WriteFCmpZ>;
284 defm : Zn2WriteResFpuPair<WriteFCmp64, [Zn2FPU0], 1>;
285 defm : Zn2WriteResFpuPair<WriteFCmp64X, [Zn2FPU0], 1>;
286 defm : Zn2WriteResFpuPair<WriteFCmp64Y, [Zn2FPU0], 1>;
287 defm : X86WriteResPairUnsupported<WriteFCmp64Z>;
288 defm : Zn2WriteResFpuPair<WriteFCom, [Zn2FPU0], 3>;
289 defm : Zn2WriteResFpuPair<WriteFComX, [Zn2FPU0], 3>;
290 defm : Zn2WriteResFpuPair<WriteFBlend, [Zn2FPU01], 1>;
291 defm : Zn2WriteResFpuPair<WriteFBlendY, [Zn2FPU01], 1>;
292 defm : X86WriteResPairUnsupported<WriteFBlendZ>;
293 defm : Zn2WriteResFpuPair<WriteFVarBlend, [Zn2FPU01], 1>;
294 defm : Zn2WriteResFpuPair<WriteFVarBlendY,[Zn2FPU01], 1>;
295 defm : X86WriteResPairUnsupported<WriteFVarBlendZ>;
296 defm : Zn2WriteResFpuPair<WriteVarBlend, [Zn2FPU0], 1>;
297 defm : Zn2WriteResFpuPair<WriteVarBlendY, [Zn2FPU0], 1>;
298 defm : X86WriteResPairUnsupported<WriteVarBlendZ>;
299 defm : Zn2WriteResFpuPair<WriteCvtSS2I, [Zn2FPU3], 5>;
300 defm : Zn2WriteResFpuPair<WriteCvtPS2I, [Zn2FPU3], 5>;
301 defm : Zn2WriteResFpuPair<WriteCvtPS2IY, [Zn2FPU3], 5>;
302 defm : X86WriteResPairUnsupported<WriteCvtPS2IZ>;
303 defm : Zn2WriteResFpuPair<WriteCvtSD2I, [Zn2FPU3], 5>;
304 defm : Zn2WriteResFpuPair<WriteCvtPD2I, [Zn2FPU3], 5>;
305 defm : Zn2WriteResFpuPair<WriteCvtPD2IY, [Zn2FPU3], 5>;
306 defm : X86WriteResPairUnsupported<WriteCvtPD2IZ>;
307 defm : Zn2WriteResFpuPair<WriteCvtI2SS, [Zn2FPU3], 5>;
308 defm : Zn2WriteResFpuPair<WriteCvtI2PS, [Zn2FPU3], 5>;
309 defm : Zn2WriteResFpuPair<WriteCvtI2PSY, [Zn2FPU3], 5>;
310 defm : X86WriteResPairUnsupported<WriteCvtI2PSZ>;
311 defm : Zn2WriteResFpuPair<WriteCvtI2SD, [Zn2FPU3], 5>;
312 defm : Zn2WriteResFpuPair<WriteCvtI2PD, [Zn2FPU3], 5>;
313 defm : Zn2WriteResFpuPair<WriteCvtI2PDY, [Zn2FPU3], 5>;
314 defm : X86WriteResPairUnsupported<WriteCvtI2PDZ>;
315 defm : Zn2WriteResFpuPair<WriteFDiv, [Zn2FPU3], 15>;
316 defm : Zn2WriteResFpuPair<WriteFDivX, [Zn2FPU3], 15>;
317 defm : X86WriteResPairUnsupported<WriteFDivZ>;
318 defm : Zn2WriteResFpuPair<WriteFDiv64, [Zn2FPU3], 15>;
319 defm : Zn2WriteResFpuPair<WriteFDiv64X, [Zn2FPU3], 15>;
320 defm : X86WriteResPairUnsupported<WriteFDiv64Z>;
321 defm : Zn2WriteResFpuPair<WriteFSign, [Zn2FPU3], 2>;
322 defm : Zn2WriteResFpuPair<WriteFRnd, [Zn2FPU3], 3, [1], 1, 7, 0>;
323 defm : Zn2WriteResFpuPair<WriteFRndY, [Zn2FPU3], 3, [1], 1, 7, 0>;
324 defm : X86WriteResPairUnsupported<WriteFRndZ>;
325 defm : Zn2WriteResFpuPair<WriteFLogic, [Zn2FPU], 1>;
326 defm : Zn2WriteResFpuPair<WriteFLogicY, [Zn2FPU], 1>;
327 defm : X86WriteResPairUnsupported<WriteFLogicZ>;
328 defm : Zn2WriteResFpuPair<WriteFTest, [Zn2FPU], 1>;
329 defm : Zn2WriteResFpuPair<WriteFTestY, [Zn2FPU], 1>;
330 defm : X86WriteResPairUnsupported<WriteFTestZ>;
331 defm : Zn2WriteResFpuPair<WriteFShuffle, [Zn2FPU12], 1>;
332 defm : Zn2WriteResFpuPair<WriteFShuffleY, [Zn2FPU12], 1>;
333 defm : X86WriteResPairUnsupported<WriteFShuffleZ>;
334 defm : Zn2WriteResFpuPair<WriteFVarShuffle, [Zn2FPU12], 3>;
335 defm : Zn2WriteResFpuPair<WriteFVarShuffleY,[Zn2FPU12], 3>;
336 defm : X86WriteResPairUnsupported<WriteFVarShuffleZ>;
337 defm : Zn2WriteResFpuPair<WriteFMul, [Zn2FPU01], 3, [1], 1, 7, 1>;
338 defm : Zn2WriteResFpuPair<WriteFMulX, [Zn2FPU01], 3, [1], 1, 7, 1>;
339 defm : Zn2WriteResFpuPair<WriteFMulY, [Zn2FPU01], 3, [1], 1, 7, 1>;
340 defm : X86WriteResPairUnsupported<WriteFMulZ>;
341 defm : Zn2WriteResFpuPair<WriteFMul64, [Zn2FPU01], 3, [1], 1, 7, 1>;
342 defm : Zn2WriteResFpuPair<WriteFMul64X, [Zn2FPU01], 3, [1], 1, 7, 1>;
343 defm : Zn2WriteResFpuPair<WriteFMul64Y, [Zn2FPU01], 3, [1], 1, 7, 1>;
344 defm : X86WriteResPairUnsupported<WriteFMul64Z>;
345 defm : Zn2WriteResFpuPair<WriteFMA, [Zn2FPU03], 5>;
346 defm : Zn2WriteResFpuPair<WriteFMAX, [Zn2FPU03], 5>;
347 defm : Zn2WriteResFpuPair<WriteFMAY, [Zn2FPU03], 5>;
348 defm : X86WriteResPairUnsupported<WriteFMAZ>;
349 defm : Zn2WriteResFpuPair<WriteFRcp, [Zn2FPU01], 5>;
350 defm : Zn2WriteResFpuPair<WriteFRcpX, [Zn2FPU01], 5>;
351 defm : Zn2WriteResFpuPair<WriteFRcpY, [Zn2FPU01], 5, [1], 1, 7, 2>;
352 defm : X86WriteResPairUnsupported<WriteFRcpZ>;
353 defm : Zn2WriteResFpuPair<WriteFRsqrtX, [Zn2FPU01], 5, [1], 1, 7, 1>;
354 defm : X86WriteResPairUnsupported<WriteFRsqrtZ>;
355 defm : Zn2WriteResFpuPair<WriteFSqrt, [Zn2FPU3], 20, [20]>;
356 defm : Zn2WriteResFpuPair<WriteFSqrtX, [Zn2FPU3], 20, [20]>;
357 defm : Zn2WriteResFpuPair<WriteFSqrtY, [Zn2FPU3], 28, [28], 1, 7, 1>;
358 defm : X86WriteResPairUnsupported<WriteFSqrtZ>;
359 defm : Zn2WriteResFpuPair<WriteFSqrt64, [Zn2FPU3], 20, [20]>;
360 defm : Zn2WriteResFpuPair<WriteFSqrt64X, [Zn2FPU3], 20, [20]>;
361 defm : Zn2WriteResFpuPair<WriteFSqrt64Y, [Zn2FPU3], 20, [20], 1, 7, 1>;
362 defm : X86WriteResPairUnsupported<WriteFSqrt64Z>;
363 defm : Zn2WriteResFpuPair<WriteFSqrt80, [Zn2FPU3], 20, [20]>;
365 // Vector integer operations which uses FPU units
366 defm : X86WriteRes<WriteVecLoad, [Zn2AGU], 8, [1], 1>;
367 defm : X86WriteRes<WriteVecLoadX, [Zn2AGU], 8, [1], 1>;
368 defm : X86WriteRes<WriteVecLoadY, [Zn2AGU], 8, [1], 1>;
369 defm : X86WriteRes<WriteVecLoadNT, [Zn2AGU], 8, [1], 1>;
370 defm : X86WriteRes<WriteVecLoadNTY, [Zn2AGU], 8, [1], 1>;
371 defm : X86WriteRes<WriteVecMaskedLoad, [Zn2AGU,Zn2FPU01], 8, [1,2], 2>;
372 defm : X86WriteRes<WriteVecMaskedLoadY, [Zn2AGU,Zn2FPU01], 8, [1,2], 2>;
373 defm : X86WriteRes<WriteVecStore, [Zn2AGU], 1, [1], 1>;
374 defm : X86WriteRes<WriteVecStoreX, [Zn2AGU], 1, [1], 1>;
375 defm : X86WriteRes<WriteVecStoreY, [Zn2AGU], 1, [1], 1>;
376 defm : X86WriteRes<WriteVecStoreNT, [Zn2AGU], 1, [1], 1>;
377 defm : X86WriteRes<WriteVecStoreNTY, [Zn2AGU], 1, [1], 1>;
378 defm : X86WriteRes<WriteVecMaskedStore32, [Zn2AGU,Zn2FPU01], 4, [1,1], 1>;
379 defm : X86WriteRes<WriteVecMaskedStore32Y, [Zn2AGU,Zn2FPU01], 5, [1,2], 2>;
380 defm : X86WriteRes<WriteVecMaskedStore64, [Zn2AGU,Zn2FPU01], 4, [1,1], 1>;
381 defm : X86WriteRes<WriteVecMaskedStore64Y, [Zn2AGU,Zn2FPU01], 5, [1,2], 2>;
382 defm : X86WriteRes<WriteVecMove, [Zn2FPU], 1, [1], 1>;
383 defm : X86WriteRes<WriteVecMoveX, [Zn2FPU], 1, [1], 1>;
384 defm : X86WriteRes<WriteVecMoveY, [Zn2FPU], 2, [1], 2>;
385 defm : X86WriteRes<WriteVecMoveToGpr, [Zn2FPU2], 2, [1], 1>;
386 defm : X86WriteRes<WriteVecMoveFromGpr, [Zn2FPU2], 3, [1], 1>;
387 defm : X86WriteRes<WriteEMMS, [Zn2FPU], 2, [1], 1>;
389 defm : Zn2WriteResFpuPair<WriteVecShift, [Zn2FPU], 1>;
390 defm : Zn2WriteResFpuPair<WriteVecShiftX, [Zn2FPU2], 1>;
391 defm : Zn2WriteResFpuPair<WriteVecShiftY, [Zn2FPU2], 1>;
392 defm : X86WriteResPairUnsupported<WriteVecShiftZ>;
393 defm : Zn2WriteResFpuPair<WriteVecShiftImm, [Zn2FPU], 1>;
394 defm : Zn2WriteResFpuPair<WriteVecShiftImmX, [Zn2FPU], 1>;
395 defm : Zn2WriteResFpuPair<WriteVecShiftImmY, [Zn2FPU], 1>;
396 defm : X86WriteResPairUnsupported<WriteVecShiftImmZ>;
397 defm : Zn2WriteResFpuPair<WriteVecLogic, [Zn2FPU], 1>;
398 defm : Zn2WriteResFpuPair<WriteVecLogicX, [Zn2FPU], 1>;
399 defm : Zn2WriteResFpuPair<WriteVecLogicY, [Zn2FPU], 1>;
400 defm : X86WriteResPairUnsupported<WriteVecLogicZ>;
401 defm : Zn2WriteResFpuPair<WriteVecTest, [Zn2FPU12], 1, [2], 1, 7, 1>;
402 defm : Zn2WriteResFpuPair<WriteVecTestY, [Zn2FPU12], 1, [2], 1, 7, 1>;
403 defm : X86WriteResPairUnsupported<WriteVecTestZ>;
404 defm : Zn2WriteResFpuPair<WriteVecALU, [Zn2FPU], 1>;
405 defm : Zn2WriteResFpuPair<WriteVecALUX, [Zn2FPU], 1>;
406 defm : Zn2WriteResFpuPair<WriteVecALUY, [Zn2FPU], 1>;
407 defm : X86WriteResPairUnsupported<WriteVecALUZ>;
408 defm : Zn2WriteResFpuPair<WriteVecIMul, [Zn2FPU0], 4>;
409 defm : Zn2WriteResFpuPair<WriteVecIMulX, [Zn2FPU0], 4>;
410 defm : Zn2WriteResFpuPair<WriteVecIMulY, [Zn2FPU0], 4>;
411 defm : X86WriteResPairUnsupported<WriteVecIMulZ>;
412 defm : Zn2WriteResFpuPair<WritePMULLD, [Zn2FPU0], 4, [1], 1, 7, 1>;
413 defm : Zn2WriteResFpuPair<WritePMULLDY, [Zn2FPU0], 4, [1], 1, 7, 1>;
414 defm : X86WriteResPairUnsupported<WritePMULLDZ>;
415 defm : Zn2WriteResFpuPair<WriteShuffle, [Zn2FPU], 1>;
416 defm : Zn2WriteResFpuPair<WriteShuffleX, [Zn2FPU], 1>;
417 defm : Zn2WriteResFpuPair<WriteShuffleY, [Zn2FPU], 1>;
418 defm : X86WriteResPairUnsupported<WriteShuffleZ>;
419 defm : Zn2WriteResFpuPair<WriteVarShuffle, [Zn2FPU], 1>;
420 defm : Zn2WriteResFpuPair<WriteVarShuffleX,[Zn2FPU], 1>;
421 defm : Zn2WriteResFpuPair<WriteVarShuffleY,[Zn2FPU], 1>;
422 defm : X86WriteResPairUnsupported<WriteVarShuffleZ>;
423 defm : Zn2WriteResFpuPair<WriteBlend, [Zn2FPU01], 1>;
424 defm : Zn2WriteResFpuPair<WriteBlendY, [Zn2FPU01], 1>;
425 defm : X86WriteResPairUnsupported<WriteBlendZ>;
426 defm : Zn2WriteResFpuPair<WriteShuffle256, [Zn2FPU], 2>;
427 defm : Zn2WriteResFpuPair<WriteVPMOV256, [Zn2FPU12], 4, [1], 2, 4>;
428 defm : Zn2WriteResFpuPair<WriteVarShuffle256, [Zn2FPU], 2>;
429 defm : Zn2WriteResFpuPair<WritePSADBW, [Zn2FPU0], 3>;
430 defm : Zn2WriteResFpuPair<WritePSADBWX, [Zn2FPU0], 3>;
431 defm : Zn2WriteResFpuPair<WritePSADBWY, [Zn2FPU0], 3>;
432 defm : X86WriteResPairUnsupported<WritePSADBWZ>;
433 defm : Zn2WriteResFpuPair<WritePHMINPOS, [Zn2FPU0], 4>;
435 // Vector Shift Operations
436 defm : Zn2WriteResFpuPair<WriteVarVecShift, [Zn2FPU12], 3>;
437 defm : Zn2WriteResFpuPair<WriteVarVecShiftY, [Zn2FPU12], 3>;
438 defm : X86WriteResPairUnsupported<WriteVarVecShiftZ>;
440 // Vector insert/extract operations.
441 defm : Zn2WriteResFpuPair<WriteVecInsert, [Zn2FPU], 1>;
443 def : WriteRes<WriteVecExtract, [Zn2FPU12, Zn2FPU2]> {
445 let ResourceCycles = [1, 2];
447 def : WriteRes<WriteVecExtractSt, [Zn2AGU, Zn2FPU12, Zn2FPU2]> {
450 let ResourceCycles = [1, 2, 3];
453 // MOVMSK Instructions.
454 def : WriteRes<WriteFMOVMSK, [Zn2FPU2]>;
455 def : WriteRes<WriteMMXMOVMSK, [Zn2FPU2]>;
456 def : WriteRes<WriteVecMOVMSK, [Zn2FPU2]>;
458 def : WriteRes<WriteVecMOVMSKY, [Zn2FPU2]> {
461 let ResourceCycles = [2];
465 defm : Zn2WriteResFpuPair<WriteAESDecEnc, [Zn2FPU01], 4>;
466 defm : Zn2WriteResFpuPair<WriteAESIMC, [Zn2FPU01], 4>;
467 defm : Zn2WriteResFpuPair<WriteAESKeyGen, [Zn2FPU01], 4>;
469 def : WriteRes<WriteFence, [Zn2AGU]>;
470 def : WriteRes<WriteNop, []>;
472 // Following instructions with latency=100 are microcoded.
473 // We set long latency so as to block the entire pipeline.
474 defm : Zn2WriteResFpuPair<WriteFShuffle256, [Zn2FPU], 100>;
475 defm : Zn2WriteResFpuPair<WriteFVarShuffle256, [Zn2FPU], 100>;
477 // Microcoded Instructions
478 def Zn2WriteMicrocoded : SchedWriteRes<[]> {
481 defm : Zn2WriteResPair<WriteDPPS, [], 15>;
482 defm : Zn2WriteResPair<WriteFHAdd, [], 7>;
483 defm : Zn2WriteResPair<WriteFHAddY, [], 7>;
484 defm : Zn2WriteResPair<WritePHAdd, [], 3>;
485 defm : Zn2WriteResPair<WritePHAddX, [], 3>;
486 defm : Zn2WriteResPair<WritePHAddY, [], 3>;
488 def : SchedAlias<WriteMicrocoded, Zn2WriteMicrocoded>;
489 def : SchedAlias<WriteFCMOV, Zn2WriteMicrocoded>;
490 def : SchedAlias<WriteSystem, Zn2WriteMicrocoded>;
491 def : SchedAlias<WriteMPSAD, Zn2WriteMicrocoded>;
492 def : SchedAlias<WriteMPSADY, Zn2WriteMicrocoded>;
493 def : SchedAlias<WriteMPSADLd, Zn2WriteMicrocoded>;
494 def : SchedAlias<WriteMPSADYLd, Zn2WriteMicrocoded>;
495 def : SchedAlias<WriteCLMul, Zn2WriteMicrocoded>;
496 def : SchedAlias<WriteCLMulLd, Zn2WriteMicrocoded>;
497 def : SchedAlias<WritePCmpIStrM, Zn2WriteMicrocoded>;
498 def : SchedAlias<WritePCmpIStrMLd, Zn2WriteMicrocoded>;
499 def : SchedAlias<WritePCmpEStrI, Zn2WriteMicrocoded>;
500 def : SchedAlias<WritePCmpEStrILd, Zn2WriteMicrocoded>;
501 def : SchedAlias<WritePCmpEStrM, Zn2WriteMicrocoded>;
502 def : SchedAlias<WritePCmpEStrMLd, Zn2WriteMicrocoded>;
503 def : SchedAlias<WritePCmpIStrI, Zn2WriteMicrocoded>;
504 def : SchedAlias<WritePCmpIStrILd, Zn2WriteMicrocoded>;
505 def : SchedAlias<WriteLDMXCSR, Zn2WriteMicrocoded>;
506 def : SchedAlias<WriteSTMXCSR, Zn2WriteMicrocoded>;
508 //=== Regex based InstRW ===//
513 // - mm: 64 bit mmx register.
514 // - x = 128 bit xmm register.
515 // - (x)mm = mmx or xmm register.
516 // - y = 256 bit ymm register.
517 // - v = any vector register.
519 //=== Integer Instructions ===//
520 //-- Move instructions --//
523 def : InstRW<[WriteALULd, ReadAfterLd], (instregex "MOV16rm")>;
527 def : InstRW<[WriteLoad], (instregex "MOV(S|Z)X32rm(8|16)")>;
531 def Zn2WriteXCHG : SchedWriteRes<[Zn2ALU]> {
535 def : InstRW<[Zn2WriteXCHG], (instregex "^XCHG(8|16|32|64)rr", "^XCHG(16|32|64)ar")>;
538 def Zn2WriteXCHGrm : SchedWriteRes<[Zn2AGU, Zn2ALU]> {
542 def : InstRW<[Zn2WriteXCHGrm, ReadAfterLd], (instregex "^XCHG(8|16|32|64)rm")>;
544 def : InstRW<[WriteMicrocoded], (instrs XLAT)>;
548 def Zn2WritePop16r : SchedWriteRes<[Zn2AGU]>{
552 def : InstRW<[Zn2WritePop16r], (instregex "POP16rmm")>;
553 def : InstRW<[WriteMicrocoded], (instregex "POPF(16|32)")>;
554 def : InstRW<[WriteMicrocoded], (instregex "POPA(16|32)")>;
558 // r. Has default values.
560 def Zn2WritePUSH : SchedWriteRes<[Zn2AGU]>{
563 def : InstRW<[Zn2WritePUSH], (instregex "PUSH(16|32)rmm")>;
566 def : InstRW<[WriteMicrocoded], (instregex "PUSHF(16|32)")>;
569 def Zn2WritePushA : SchedWriteRes<[Zn2AGU]> {
572 def : InstRW<[Zn2WritePushA], (instregex "PUSHA(16|32)")>;
575 def : InstRW<[WriteMicrocoded], (instrs LAHF)>;
579 def Zn2WriteMOVBE : SchedWriteRes<[Zn2AGU, Zn2ALU]> {
582 def : InstRW<[Zn2WriteMOVBE, ReadAfterLd], (instregex "MOVBE(16|32|64)rm")>;
585 def : InstRW<[Zn2WriteMOVBE], (instregex "MOVBE(16|32|64)mr")>;
587 //-- Arithmetic instructions --//
591 def : InstRW<[WriteALULd], (instregex "(ADD|SUB)(8|16|32|64)m(r|i)",
592 "(ADD|SUB)(8|16|32|64)mi8",
597 def : InstRW<[WriteALULd],
598 (instregex "(ADC|SBB)(8|16|32|64)m(r|i)",
599 "(ADC|SBB)(16|32|64)mi8",
604 def : InstRW<[WriteALULd],
605 (instregex "(INC|DEC|NOT|NEG)(8|16|32|64)m")>;
609 def Zn2WriteMul16 : SchedWriteRes<[Zn2ALU1, Zn2Multiplier]> {
612 def Zn2WriteMul16Imm : SchedWriteRes<[Zn2ALU1, Zn2Multiplier]> {
615 def : SchedAlias<WriteIMul16, Zn2WriteMul16>;
616 def : SchedAlias<WriteIMul16Imm, Zn2WriteMul16Imm>;
617 def : SchedAlias<WriteIMul16Reg, Zn2WriteMul16>;
620 def Zn2WriteMul16Ld : SchedWriteRes<[Zn2AGU, Zn2ALU1, Zn2Multiplier]> {
623 def : SchedAlias<WriteIMul16Ld, Zn2WriteMul16Ld>;
624 def : SchedAlias<WriteIMul16ImmLd, Zn2WriteMul16Ld>;
625 def : SchedAlias<WriteIMul16RegLd, Zn2WriteMul16Ld>;
628 def Zn2WriteMul32 : SchedWriteRes<[Zn2ALU1, Zn2Multiplier]> {
631 def : SchedAlias<WriteIMul32, Zn2WriteMul32>;
632 def : SchedAlias<WriteIMul32Imm, Zn2WriteMul32>;
633 def : SchedAlias<WriteIMul32Reg, Zn2WriteMul32>;
636 def Zn2WriteMul32Ld : SchedWriteRes<[Zn2AGU, Zn2ALU1, Zn2Multiplier]> {
639 def : SchedAlias<WriteIMul32Ld, Zn2WriteMul32Ld>;
640 def : SchedAlias<WriteIMul32ImmLd, Zn2WriteMul32Ld>;
641 def : SchedAlias<WriteIMul32RegLd, Zn2WriteMul32Ld>;
644 def Zn2WriteMul64 : SchedWriteRes<[Zn2ALU1, Zn2Multiplier]> {
648 def : SchedAlias<WriteIMul64, Zn2WriteMul64>;
649 def : SchedAlias<WriteIMul64Imm, Zn2WriteMul64>;
650 def : SchedAlias<WriteIMul64Reg, Zn2WriteMul64>;
653 def Zn2WriteMul64Ld : SchedWriteRes<[Zn2AGU, Zn2ALU1, Zn2Multiplier]> {
657 def : SchedAlias<WriteIMul64Ld, Zn2WriteMul64Ld>;
658 def : SchedAlias<WriteIMul64ImmLd, Zn2WriteMul64Ld>;
659 def : SchedAlias<WriteIMul64RegLd, Zn2WriteMul64Ld>;
662 // Numbers are based on the AMD SOG for Family 17h - Instruction Latencies.
663 defm : Zn2WriteResPair<WriteMULX32, [Zn2ALU1, Zn2Multiplier], 3, [1, 1], 1, 4, 0>;
664 defm : Zn2WriteResPair<WriteMULX64, [Zn2ALU1, Zn2Multiplier], 3, [1, 1], 1, 4, 0>;
666 //-- Control transfer instructions --//
669 def Zn2WriteJCXZ : SchedWriteRes<[Zn2ALU03]>;
670 def : InstRW<[Zn2WriteJCXZ], (instrs JCXZ, JECXZ, JRCXZ)>;
673 def : InstRW<[WriteMicrocoded], (instrs INTO)>;
676 def Zn2WriteLOOP : SchedWriteRes<[Zn2ALU03]>;
677 def : InstRW<[Zn2WriteLOOP], (instrs LOOP)>;
679 // LOOP(N)E, LOOP(N)Z
680 def Zn2WriteLOOPE : SchedWriteRes<[Zn2ALU03]>;
681 def : InstRW<[Zn2WriteLOOPE], (instrs LOOPE, LOOPNE)>;
685 def Zn2WriteCALLr : SchedWriteRes<[Zn2AGU, Zn2ALU03]>;
686 def : InstRW<[Zn2WriteCALLr], (instregex "CALL(16|32)r")>;
688 def : InstRW<[WriteMicrocoded], (instregex "CALL(16|32)m")>;
691 def Zn2WriteRET : SchedWriteRes<[Zn2ALU03]> {
694 def : InstRW<[Zn2WriteRET], (instregex "RET(L|Q|W)", "LRET(L|Q|W)",
697 //-- Logic instructions --//
701 def : InstRW<[WriteALULd],
702 (instregex "(AND|OR|XOR)(8|16|32|64)m(r|i)",
703 "(AND|OR|XOR)(8|16|32|64)mi8", "(AND|OR|XOR)64mi32")>;
705 // Define ALU latency variants
706 def Zn2WriteALULat2 : SchedWriteRes<[Zn2ALU]> {
709 def Zn2WriteALULat2Ld : SchedWriteRes<[Zn2AGU, Zn2ALU]> {
715 def : InstRW<[WriteShiftLd], (instregex "BT(16|32|64)mi8")>;
719 def Zn2WriteBTRSC : SchedWriteRes<[Zn2ALU]> {
723 def : InstRW<[Zn2WriteBTRSC], (instregex "BT(R|S|C)(16|32|64)r(r|i8)")>;
726 def Zn2WriteBTRSCm : SchedWriteRes<[Zn2AGU, Zn2ALU]> {
731 def : SchedAlias<WriteBitTestSetImmRMW, Zn2WriteBTRSCm>;
732 def : SchedAlias<WriteBitTestSetRegRMW, Zn2WriteBTRSCm>;
736 def : SchedAlias<WriteBLS, Zn2WriteALULat2>;
738 def : SchedAlias<WriteBLSLd, Zn2WriteALULat2Ld>;
741 def : InstRW<[WriteALU], (instrs STD, CLD)>;
745 def : InstRW<[WriteMicrocoded], (instregex "PDEP(32|64)rr", "PEXT(32|64)rr")>;
747 def : InstRW<[WriteMicrocoded], (instregex "PDEP(32|64)rm", "PEXT(32|64)rm")>;
751 def : InstRW<[WriteMicrocoded], (instregex "RC(R|L)(8|16|32|64)m(1|i|CL)")>;
755 def : InstRW<[WriteShiftLd], (instregex "S(A|H)(R|L)(8|16|32|64)m(i|1)")>;
759 def : InstRW<[WriteShiftLd], (instregex "SH(R|L)D(16|32|64)mri8")>;
762 def : InstRW<[WriteMicrocoded], (instregex "SH(R|L)D(16|32|64)rrCL")>;
765 def : InstRW<[WriteMicrocoded], (instregex "SH(R|L)D(16|32|64)mrCL")>;
767 //-- Misc instructions --//
769 def Zn2WriteCMPXCHG8B : SchedWriteRes<[Zn2AGU, Zn2ALU]> {
770 let NumMicroOps = 18;
772 def : InstRW<[Zn2WriteCMPXCHG8B], (instrs CMPXCHG8B)>;
774 def : InstRW<[WriteMicrocoded], (instrs CMPXCHG16B)>;
777 def Zn2WriteLEAVE : SchedWriteRes<[Zn2ALU, Zn2AGU]> {
781 def : InstRW<[Zn2WriteLEAVE], (instregex "LEAVE")>;
784 def : InstRW<[WriteMicrocoded], (instrs PAUSE)>;
787 def : InstRW<[WriteMicrocoded], (instregex "RDTSC")>;
790 def : InstRW<[WriteMicrocoded], (instrs RDPMC)>;
793 def : InstRW<[WriteMicrocoded], (instregex "RDRAND(16|32|64)r")>;
796 def : InstRW<[WriteMicrocoded], (instregex "XGETBV")>;
798 //-- String instructions --//
800 def : InstRW<[WriteMicrocoded], (instregex "CMPS(B|L|Q|W)")>;
803 def : InstRW<[WriteMicrocoded], (instregex "LODS(B|W)")>;
806 def : InstRW<[WriteMicrocoded], (instregex "LODS(L|Q)")>;
809 def : InstRW<[WriteMicrocoded], (instregex "MOVS(B|L|Q|W)")>;
812 def : InstRW<[WriteMicrocoded], (instregex "SCAS(B|W|L|Q)")>;
815 def : InstRW<[WriteMicrocoded], (instregex "STOS(B|L|Q|W)")>;
818 def Zn2XADD : SchedWriteRes<[Zn2ALU]>;
819 def : InstRW<[Zn2XADD], (instregex "XADD(8|16|32|64)rr")>;
820 def : InstRW<[WriteMicrocoded], (instregex "XADD(8|16|32|64)rm")>;
822 //=== Floating Point x87 Instructions ===//
823 //-- Move instructions --//
825 def Zn2WriteFLDr : SchedWriteRes<[Zn2FPU13]> ;
827 def Zn2WriteSTr: SchedWriteRes<[Zn2FPU23]> {
834 def : InstRW<[Zn2WriteFLDr], (instregex "LD_Frr")>;
837 def Zn2WriteLD_F80m : SchedWriteRes<[Zn2AGU, Zn2FPU13]> {
840 def : InstRW<[Zn2WriteLD_F80m], (instregex "LD_F80m")>;
843 def : InstRW<[WriteMicrocoded], (instregex "FBLDm")>;
847 def : InstRW<[Zn2WriteSTr], (instregex "ST_(F|FP)rr")>;
850 def Zn2WriteST_FP80m : SchedWriteRes<[Zn2AGU, Zn2FPU23]> {
853 def : InstRW<[Zn2WriteST_FP80m], (instregex "ST_FP80m")>;
857 def : InstRW<[WriteMicrocoded], (instregex "FBSTPm")>;
859 def Zn2WriteFXCH : SchedWriteRes<[Zn2FPU]>;
862 def : InstRW<[Zn2WriteFXCH], (instrs XCH_F)>;
865 def Zn2WriteFILD : SchedWriteRes<[Zn2AGU, Zn2FPU3]> {
869 def : InstRW<[Zn2WriteFILD], (instregex "ILD_F(16|32|64)m")>;
872 def Zn2WriteFIST : SchedWriteRes<[Zn2AGU, Zn2FPU23]> {
875 def : InstRW<[Zn2WriteFIST], (instregex "IS(T|TT)_(F|FP)(16|32|64)m")>;
877 def Zn2WriteFPU13 : SchedWriteRes<[Zn2AGU, Zn2FPU13]> {
881 def Zn2WriteFPU3 : SchedWriteRes<[Zn2AGU, Zn2FPU3]> {
886 def : SchedAlias<WriteFLD0, Zn2WriteFPU13>;
889 def : SchedAlias<WriteFLD1, Zn2WriteFPU3>;
892 def : SchedAlias<WriteFLDC, Zn2WriteFPU3>;
896 def : InstRW<[WriteMicrocoded], (instrs FNSTSW16r)>;
899 def : InstRW<[WriteMicrocoded], (instrs FNSTSWm)>;
902 def : InstRW<[WriteMicrocoded], (instrs FLDCW16m)>;
905 def : InstRW<[WriteMicrocoded], (instrs FNSTCW16m)>;
908 def : InstRW<[Zn2WriteFPU3], (instrs FINCSTP, FDECSTP)>;
911 def : InstRW<[Zn2WriteFPU3], (instregex "FFREE")>;
914 def : InstRW<[WriteMicrocoded], (instregex "FSAVEm")>;
917 def : InstRW<[WriteMicrocoded], (instregex "FRSTORm")>;
919 //-- Arithmetic instructions --//
921 def Zn2WriteFPU3Lat1 : SchedWriteRes<[Zn2FPU3]> ;
923 def Zn2WriteFPU0Lat1 : SchedWriteRes<[Zn2FPU0]> ;
925 def Zn2WriteFPU0Lat1Ld : SchedWriteRes<[Zn2AGU, Zn2FPU0]> {
930 def : InstRW<[Zn2WriteFPU3Lat1], (instregex "CHS_F")>;
934 def : InstRW<[Zn2WriteFPU0Lat1], (instregex "COM(P?)_FST0r", "UCOM_F(P?)r")>;
936 def : InstRW<[Zn2WriteFPU0Lat1Ld], (instregex "FCOM(P?)(32|64)m")>;
940 def : InstRW<[Zn2WriteFPU0Lat1], (instrs FCOMPP, UCOM_FPPr)>;
942 def Zn2WriteFPU02 : SchedWriteRes<[Zn2AGU, Zn2FPU02]>
947 // FCOMI(P) FUCOMI(P).
949 def : InstRW<[Zn2WriteFPU02], (instrs COM_FIPr, COM_FIr, UCOM_FIPr, UCOM_FIr)>;
951 def Zn2WriteFPU03 : SchedWriteRes<[Zn2AGU, Zn2FPU03]>
955 let ResourceCycles = [1,3];
959 def : InstRW<[Zn2WriteFPU03], (instregex "FICOM(P?)(16|32)m")>;
962 def : InstRW<[Zn2WriteFPU0Lat1], (instregex "TST_F")>;
965 def : InstRW<[Zn2WriteFPU3Lat1], (instrs XAM_F)>;
968 def : InstRW<[WriteMicrocoded], (instrs FPREM)>;
971 def : InstRW<[WriteMicrocoded], (instrs FPREM1)>;
974 def : InstRW<[WriteMicrocoded], (instrs FRNDINT)>;
977 def : InstRW<[WriteMicrocoded], (instrs FSCALE)>;
980 def : InstRW<[WriteMicrocoded], (instrs FXTRACT)>;
983 def : InstRW<[Zn2WriteFPU0Lat1], (instrs FNOP)>;
986 def : InstRW<[Zn2WriteFPU0Lat1], (instrs WAIT)>;
989 def : InstRW<[WriteMicrocoded], (instrs FNCLEX)>;
992 def : InstRW<[WriteMicrocoded], (instrs FNINIT)>;
994 //=== Integer MMX and XMM Instructions ===//
998 def Zn2WriteFPU12 : SchedWriteRes<[Zn2FPU12]> ;
999 def Zn2WriteFPU12Y : SchedWriteRes<[Zn2FPU12]> {
1001 let NumMicroOps = 2;
1003 def Zn2WriteFPU12m : SchedWriteRes<[Zn2AGU, Zn2FPU12]> ;
1004 def Zn2WriteFPU12Ym : SchedWriteRes<[Zn2AGU, Zn2FPU12]> {
1006 let NumMicroOps = 2;
1009 def : InstRW<[Zn2WriteFPU12], (instrs MMX_PACKSSDWirr,
1012 def : InstRW<[Zn2WriteFPU12m], (instrs MMX_PACKSSDWirm,
1016 def Zn2WriteFPU013 : SchedWriteRes<[Zn2FPU013]> ;
1017 def Zn2WriteFPU013Y : SchedWriteRes<[Zn2FPU013]> ;
1018 def Zn2WriteFPU013m : SchedWriteRes<[Zn2AGU, Zn2FPU013]> {
1020 let NumMicroOps = 2;
1022 def Zn2WriteFPU013Ld : SchedWriteRes<[Zn2AGU, Zn2FPU013]> {
1024 let NumMicroOps = 2;
1026 def Zn2WriteFPU013LdY : SchedWriteRes<[Zn2AGU, Zn2FPU013]> {
1028 let NumMicroOps = 2;
1033 def : InstRW<[Zn2WriteFPU013], (instregex "(V?)PBLENDWrri")>;
1035 def : InstRW<[Zn2WriteFPU013Y], (instrs VPBLENDWYrri)>;
1038 def : InstRW<[Zn2WriteFPU013Ld], (instregex "(V?)PBLENDWrmi")>;
1040 def : InstRW<[Zn2WriteFPU013LdY], (instrs VPBLENDWYrmi)>;
1042 def Zn2WriteFPU01 : SchedWriteRes<[Zn2FPU01]> ;
1043 def Zn2WriteFPU01Y : SchedWriteRes<[Zn2FPU01]> {
1044 let NumMicroOps = 2;
1049 def : InstRW<[Zn2WriteFPU01], (instrs VPBLENDDrri)>;
1051 def : InstRW<[Zn2WriteFPU01Y], (instrs VPBLENDDYrri)>;
1054 def Zn2WriteFPU01Op2 : SchedWriteRes<[Zn2AGU, Zn2FPU01]> {
1055 let NumMicroOps = 2;
1057 let ResourceCycles = [1, 2];
1059 def Zn2WriteFPU01Op2Y : SchedWriteRes<[Zn2AGU, Zn2FPU01]> {
1060 let NumMicroOps = 2;
1062 let ResourceCycles = [1, 3];
1064 def : InstRW<[Zn2WriteFPU01Op2], (instrs VPBLENDDrmi)>;
1065 def : InstRW<[Zn2WriteFPU01Op2Y], (instrs VPBLENDDYrmi)>;
1068 def : InstRW<[WriteMicrocoded], (instregex "MMX_MASKMOVQ(64)?")>;
1071 def : InstRW<[WriteMicrocoded], (instregex "(V?)MASKMOVDQU(64)?")>;
1075 def : InstRW<[WriteMicrocoded],
1076 (instregex "VPMASKMOVD(Y?)rm")>;
1078 def : InstRW<[WriteMicrocoded], (instregex "VPMASKMOV(D|Q)(Y?)mr")>;
1082 def Zn2WriteVPBROADCAST128Ld : SchedWriteRes<[Zn2AGU, Zn2FPU12]> {
1084 let NumMicroOps = 2;
1085 let ResourceCycles = [1, 2];
1087 def : InstRW<[Zn2WriteVPBROADCAST128Ld],
1088 (instregex "VPBROADCAST(B|W)rm")>;
1091 def Zn2WriteVPBROADCAST256Ld : SchedWriteRes<[Zn2AGU, Zn2FPU1]> {
1093 let NumMicroOps = 2;
1094 let ResourceCycles = [1, 2];
1096 def : InstRW<[Zn2WriteVPBROADCAST256Ld],
1097 (instregex "VPBROADCAST(B|W)Yrm")>;
1100 def : InstRW<[WriteMicrocoded], (instregex "VPGATHER(Q|D)(Q|D)(Y?)rm")>;
1102 //-- Arithmetic instructions --//
1105 def Zn2WritePCMPGTQr : SchedWriteRes<[Zn2FPU03]>;
1106 def : InstRW<[Zn2WritePCMPGTQr], (instregex "(V?)PCMPGTQ(Y?)rr")>;
1109 def Zn2WritePCMPGTQm : SchedWriteRes<[Zn2AGU, Zn2FPU03]> {
1113 def Zn2WritePCMPGTQYm : SchedWriteRes<[Zn2AGU, Zn2FPU03]> {
1116 def : InstRW<[Zn2WritePCMPGTQm], (instregex "(V?)PCMPGTQrm")>;
1117 def : InstRW<[Zn2WritePCMPGTQYm], (instrs VPCMPGTQYrm)>;
1119 //-- Logic instructions --//
1121 // PSLL,PSRL,PSRA W/D/Q.
1123 def Zn2WritePShift : SchedWriteRes<[Zn2FPU2]> {
1126 def Zn2WritePShiftY : SchedWriteRes<[Zn2FPU2]> {
1131 def : InstRW<[Zn2WritePShift], (instregex "(V?)PS(R|L)LDQri")>;
1132 def : InstRW<[Zn2WritePShiftY], (instregex "(V?)PS(R|L)LDQYri")>;
1134 //=== Floating Point XMM and YMM Instructions ===//
1135 //-- Move instructions --//
1138 def : InstRW<[WriteMicrocoded], (instrs VPERM2F128rr)>;
1139 def : InstRW<[WriteMicrocoded], (instrs VPERM2F128rm)>;
1141 def Zn2WriteBROADCAST : SchedWriteRes<[Zn2AGU, Zn2FPU13]> {
1142 let NumMicroOps = 2;
1146 def : InstRW<[Zn2WriteBROADCAST], (instrs VBROADCASTF128)>;
1150 def Zn2WriteEXTRACTPSr : SchedWriteRes<[Zn2FPU12, Zn2FPU2]> {
1152 let ResourceCycles = [1, 2];
1154 def : InstRW<[Zn2WriteEXTRACTPSr], (instregex "(V?)EXTRACTPSrr")>;
1156 def Zn2WriteEXTRACTPSm : SchedWriteRes<[Zn2AGU,Zn2FPU12, Zn2FPU2]> {
1158 let NumMicroOps = 2;
1159 let ResourceCycles = [5, 1, 2];
1162 def : InstRW<[Zn2WriteEXTRACTPSm], (instregex "(V?)EXTRACTPSmr")>;
1166 def : InstRW<[Zn2WriteFPU013], (instrs VEXTRACTF128rr)>;
1169 def : InstRW<[Zn2WriteFPU013m], (instrs VEXTRACTF128mr)>;
1171 def Zn2WriteVINSERT128r: SchedWriteRes<[Zn2FPU013]> {
1173 // let ResourceCycles = [2];
1175 def Zn2WriteVINSERT128Ld: SchedWriteRes<[Zn2AGU,Zn2FPU013]> {
1177 let NumMicroOps = 2;
1181 def : InstRW<[Zn2WriteVINSERT128r], (instrs VINSERTF128rr)>;
1182 def : InstRW<[Zn2WriteVINSERT128Ld], (instrs VINSERTF128rm)>;
1185 def : InstRW<[WriteMicrocoded], (instregex "VGATHER(Q|D)(PD|PS)(Y?)rm")>;
1187 //-- Conversion instructions --//
1188 def Zn2WriteCVTPD2PSr: SchedWriteRes<[Zn2FPU3]> {
1191 def Zn2WriteCVTPD2PSYr: SchedWriteRes<[Zn2FPU3]> {
1197 def : SchedAlias<WriteCvtPD2PS, Zn2WriteCVTPD2PSr>;
1199 def : SchedAlias<WriteCvtPD2PSY, Zn2WriteCVTPD2PSYr>;
1201 defm : X86WriteResUnsupported<WriteCvtPD2PSZ>;
1203 def Zn2WriteCVTPD2PSLd: SchedWriteRes<[Zn2AGU,Zn2FPU03]> {
1205 let NumMicroOps = 2;
1208 def : SchedAlias<WriteCvtPD2PSLd, Zn2WriteCVTPD2PSLd>;
1211 def Zn2WriteCVTPD2PSYLd : SchedWriteRes<[Zn2AGU, Zn2FPU3]> {
1214 def : SchedAlias<WriteCvtPD2PSYLd, Zn2WriteCVTPD2PSYLd>;
1216 defm : X86WriteResUnsupported<WriteCvtPD2PSZLd>;
1220 // Same as WriteCVTPD2PSr
1221 def : SchedAlias<WriteCvtSD2SS, Zn2WriteCVTPD2PSr>;
1224 def : SchedAlias<WriteCvtSD2SSLd, Zn2WriteCVTPD2PSLd>;
1228 def Zn2WriteCVTPS2PDr : SchedWriteRes<[Zn2FPU3]> {
1231 def : SchedAlias<WriteCvtPS2PD, Zn2WriteCVTPS2PDr>;
1235 def Zn2WriteCVTPS2PDLd : SchedWriteRes<[Zn2AGU, Zn2FPU3]> {
1237 let NumMicroOps = 2;
1239 def : SchedAlias<WriteCvtPS2PDLd, Zn2WriteCVTPS2PDLd>;
1240 def : SchedAlias<WriteCvtPS2PDYLd, Zn2WriteCVTPS2PDLd>;
1241 defm : X86WriteResUnsupported<WriteCvtPS2PDZLd>;
1244 def Zn2WriteVCVTPS2PDY : SchedWriteRes<[Zn2FPU3]> {
1247 def : SchedAlias<WriteCvtPS2PDY, Zn2WriteVCVTPS2PDY>;
1248 defm : X86WriteResUnsupported<WriteCvtPS2PDZ>;
1252 def Zn2WriteCVTSS2SDr : SchedWriteRes<[Zn2FPU3]> {
1255 def : SchedAlias<WriteCvtSS2SD, Zn2WriteCVTSS2SDr>;
1258 def Zn2WriteCVTSS2SDLd : SchedWriteRes<[Zn2AGU, Zn2FPU3]> {
1260 let NumMicroOps = 2;
1261 let ResourceCycles = [1, 2];
1263 def : SchedAlias<WriteCvtSS2SDLd, Zn2WriteCVTSS2SDLd>;
1265 def Zn2WriteCVTDQ2PDr: SchedWriteRes<[Zn2FPU12,Zn2FPU3]> {
1270 def : InstRW<[Zn2WriteCVTDQ2PDr], (instregex "(V)?CVTDQ2P(D|S)rr")>;
1274 def : InstRW<[Zn2WriteCVTDQ2PDr], (instrs VCVTDQ2PDYrr)>;
1275 def : InstRW<[Zn2WriteCVTDQ2PDr], (instrs VCVTDQ2PSYrr)>;
1277 def Zn2WriteCVTPD2DQr: SchedWriteRes<[Zn2FPU12, Zn2FPU3]> {
1282 def : InstRW<[Zn2WriteCVTPD2DQr], (instregex "(V?)CVT(T?)P(D|S)2DQrr")>;
1284 def Zn2WriteCVTPD2DQLd: SchedWriteRes<[Zn2AGU,Zn2FPU12,Zn2FPU3]> {
1286 let NumMicroOps = 2;
1289 def : InstRW<[Zn2WriteCVTPD2DQLd], (instregex "(V?)CVT(T?)PD2DQrm")>;
1290 // same as xmm handling
1292 def : InstRW<[Zn2WriteCVTPD2DQr], (instregex "VCVT(T?)PD2DQYrr")>;
1294 def : InstRW<[Zn2WriteCVTPD2DQLd], (instregex "VCVT(T?)PD2DQYrm")>;
1296 def Zn2WriteCVTPS2PIr: SchedWriteRes<[Zn2FPU3]> {
1301 def : InstRW<[Zn2WriteCVTPS2PIr], (instregex "MMX_CVT(T?)PS2PIirr")>;
1305 def : InstRW<[Zn2WriteCVTPS2PDr], (instrs MMX_CVTPI2PDirr)>;
1309 def : InstRW<[Zn2WriteCVTPS2PIr], (instregex "MMX_CVT(T?)PD2PIirr")>;
1311 def Zn2WriteCVSTSI2SSr: SchedWriteRes<[Zn2FPU3]> {
1315 // same as CVTPD2DQr
1318 def : InstRW<[Zn2WriteCVTPD2DQr], (instregex "(V?)CVT(T?)SS2SI(64)?rr")>;
1319 // same as CVTPD2DQm
1321 def : InstRW<[Zn2WriteCVTPD2DQLd], (instregex "(V?)CVT(T?)SS2SI(64)?rm")>;
1323 def Zn2WriteCVSTSI2SDr: SchedWriteRes<[Zn2FPU013, Zn2FPU3]> {
1328 def : InstRW<[Zn2WriteCVSTSI2SDr], (instregex "(V?)CVTSI(64)?2SDrr")>;
1331 def Zn2WriteCVSTSI2SIr: SchedWriteRes<[Zn2FPU3, Zn2FPU2]> {
1334 def Zn2WriteCVSTSI2SILd: SchedWriteRes<[Zn2AGU, Zn2FPU3, Zn2FPU2]> {
1339 def : InstRW<[Zn2WriteCVSTSI2SIr], (instregex "(V?)CVT(T?)SD2SI(64)?rr")>;
1341 def : InstRW<[Zn2WriteCVSTSI2SILd], (instregex "(V?)CVT(T?)SD2SI(64)?rm")>;
1345 def : SchedAlias<WriteCvtPS2PH, Zn2WriteMicrocoded>;
1346 def : SchedAlias<WriteCvtPS2PHY, Zn2WriteMicrocoded>;
1347 defm : X86WriteResUnsupported<WriteCvtPS2PHZ>;
1349 def : SchedAlias<WriteCvtPS2PHSt, Zn2WriteMicrocoded>;
1350 def : SchedAlias<WriteCvtPS2PHYSt, Zn2WriteMicrocoded>;
1351 defm : X86WriteResUnsupported<WriteCvtPS2PHZSt>;
1355 def : SchedAlias<WriteCvtPH2PS, Zn2WriteMicrocoded>;
1356 def : SchedAlias<WriteCvtPH2PSY, Zn2WriteMicrocoded>;
1357 defm : X86WriteResUnsupported<WriteCvtPH2PSZ>;
1359 def : SchedAlias<WriteCvtPH2PSLd, Zn2WriteMicrocoded>;
1360 def : SchedAlias<WriteCvtPH2PSYLd, Zn2WriteMicrocoded>;
1361 defm : X86WriteResUnsupported<WriteCvtPH2PSZLd>;
1363 //-- SSE4A instructions --//
1365 def Zn2WriteEXTRQ: SchedWriteRes<[Zn2FPU12, Zn2FPU2]> {
1368 def : InstRW<[Zn2WriteEXTRQ], (instregex "EXTRQ")>;
1371 def Zn2WriteINSERTQ: SchedWriteRes<[Zn2FPU03,Zn2FPU1]> {
1374 def : InstRW<[Zn2WriteINSERTQ], (instregex "INSERTQ")>;
1376 //-- SHA instructions --//
1378 def : InstRW<[WriteMicrocoded], (instregex "SHA256MSG2(Y?)r(r|m)")>;
1380 // SHA1MSG1, SHA256MSG1
1382 def Zn2WriteSHA1MSG1r : SchedWriteRes<[Zn2FPU12]> {
1385 def : InstRW<[Zn2WriteSHA1MSG1r], (instregex "SHA(1|256)MSG1rr")>;
1387 def Zn2WriteSHA1MSG1Ld : SchedWriteRes<[Zn2AGU, Zn2FPU12]> {
1390 def : InstRW<[Zn2WriteSHA1MSG1Ld], (instregex "SHA(1|256)MSG1rm")>;
1394 def Zn2WriteSHA1MSG2r : SchedWriteRes<[Zn2FPU12]> ;
1395 def : InstRW<[Zn2WriteSHA1MSG2r], (instregex "SHA1MSG2rr")>;
1397 def Zn2WriteSHA1MSG2Ld : SchedWriteRes<[Zn2AGU, Zn2FPU12]> {
1400 def : InstRW<[Zn2WriteSHA1MSG2Ld], (instregex "SHA1MSG2rm")>;
1404 def Zn2WriteSHA1NEXTEr : SchedWriteRes<[Zn2FPU1]> ;
1405 def : InstRW<[Zn2WriteSHA1NEXTEr], (instregex "SHA1NEXTErr")>;
1407 def Zn2WriteSHA1NEXTELd : SchedWriteRes<[Zn2AGU, Zn2FPU1]> {
1410 def : InstRW<[Zn2WriteSHA1NEXTELd], (instregex "SHA1NEXTErm")>;
1414 def Zn2WriteSHA1RNDS4r : SchedWriteRes<[Zn2FPU1]> {
1417 def : InstRW<[Zn2WriteSHA1RNDS4r], (instregex "SHA1RNDS4rr")>;
1419 def Zn2WriteSHA1RNDS4Ld : SchedWriteRes<[Zn2AGU, Zn2FPU1]> {
1422 def : InstRW<[Zn2WriteSHA1RNDS4Ld], (instregex "SHA1RNDS4rm")>;
1426 def Zn2WriteSHA256RNDS2r : SchedWriteRes<[Zn2FPU1]> {
1429 def : InstRW<[Zn2WriteSHA256RNDS2r], (instregex "SHA256RNDS2rr")>;
1431 def Zn2WriteSHA256RNDS2Ld : SchedWriteRes<[Zn2AGU, Zn2FPU1]> {
1434 def : InstRW<[Zn2WriteSHA256RNDS2Ld], (instregex "SHA256RNDS2rm")>;
1436 //-- Arithmetic instructions --//
1439 // TODO - convert to Zn2WriteResFpuPair
1441 def Zn2WriteVDIVPSYr : SchedWriteRes<[Zn2FPU3]> {
1443 let ResourceCycles = [10];
1445 def : SchedAlias<WriteFDivY, Zn2WriteVDIVPSYr>;
1448 def Zn2WriteVDIVPSYLd : SchedWriteRes<[Zn2AGU, Zn2FPU3]> {
1450 let NumMicroOps = 2;
1451 let ResourceCycles = [1, 17];
1453 def : SchedAlias<WriteFDivYLd, Zn2WriteVDIVPSYLd>;
1456 // TODO - convert to Zn2WriteResFpuPair
1458 def Zn2WriteVDIVPDY : SchedWriteRes<[Zn2FPU3]> {
1460 let ResourceCycles = [13];
1462 def : SchedAlias<WriteFDiv64Y, Zn2WriteVDIVPDY>;
1465 def Zn2WriteVDIVPDYLd : SchedWriteRes<[Zn2AGU, Zn2FPU3]> {
1467 let NumMicroOps = 2;
1468 let ResourceCycles = [1,20];
1470 def : SchedAlias<WriteFDiv64YLd, Zn2WriteVDIVPDYLd>;
1474 def : SchedAlias<WriteDPPSY, Zn2WriteMicrocoded>;
1477 def : SchedAlias<WriteDPPSYLd,Zn2WriteMicrocoded>;
1481 def : SchedAlias<WriteDPPD, Zn2WriteMicrocoded>;
1484 def : SchedAlias<WriteDPPDLd, Zn2WriteMicrocoded>;
1487 // TODO - convert to Zn2WriteResFpuPair
1489 def Zn2WriteRSQRTSSr : SchedWriteRes<[Zn2FPU02]> {
1492 def : SchedAlias<WriteFRsqrt, Zn2WriteRSQRTSSr>;
1495 def Zn2WriteRSQRTSSLd: SchedWriteRes<[Zn2AGU, Zn2FPU02]> {
1497 let NumMicroOps = 2;
1498 let ResourceCycles = [1,2];
1500 def : SchedAlias<WriteFRsqrtLd, Zn2WriteRSQRTSSLd>;
1503 // TODO - convert to Zn2WriteResFpuPair
1505 def Zn2WriteRSQRTPSYr : SchedWriteRes<[Zn2FPU01]> {
1507 let NumMicroOps = 2;
1508 let ResourceCycles = [2];
1510 def : SchedAlias<WriteFRsqrtY, Zn2WriteRSQRTPSYr>;
1513 def Zn2WriteRSQRTPSYLd : SchedWriteRes<[Zn2AGU, Zn2FPU01]> {
1515 let NumMicroOps = 2;
1517 def : SchedAlias<WriteFRsqrtYLd, Zn2WriteRSQRTPSYLd>;
1519 //-- Other instructions --//
1522 def : InstRW<[WriteALU], (instrs VZEROUPPER)>;
1525 def : InstRW<[WriteMicrocoded], (instrs VZEROALL)>;