1 //=- X86SchedSandyBridge.td - X86 Sandy Bridge Scheduling ----*- tablegen -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the machine model for Sandy Bridge to support instruction
11 // scheduling and other instruction cost heuristics.
13 //===----------------------------------------------------------------------===//
15 def SandyBridgeModel : SchedMachineModel {
16 // All x86 instructions are modeled as a single micro-op, and SB can decode 4
17 // instructions per cycle.
18 // FIXME: Identify instructions that aren't a single fused micro-op.
20 let MinLatency = 0; // 0 = Out-of-order execution.
23 let MispredictPenalty = 16;
26 let SchedModel = SandyBridgeModel in {
28 // Sandy Bridge can issue micro-ops to 6 different ports in one cycle.
30 // Ports 0, 1, and 5 handle all computation.
31 def SBPort0 : ProcResource<1>;
32 def SBPort1 : ProcResource<1>;
33 def SBPort5 : ProcResource<1>;
35 // Ports 2 and 3 are identical. They handle loads and the address half of
37 def SBPort23 : ProcResource<2>;
39 // Port 4 gets the data half of stores. Store data can be available later than
40 // the store address, but since we don't model the latency of stores, we can
42 def SBPort4 : ProcResource<1>;
44 // Many micro-ops are capable of issuing on multiple ports.
45 def SBPort01 : ProcResGroup<[SBPort0, SBPort1]>;
46 def SBPort05 : ProcResGroup<[SBPort0, SBPort5]>;
47 def SBPort15 : ProcResGroup<[SBPort1, SBPort5]>;
48 def SBPort015 : ProcResGroup<[SBPort0, SBPort1, SBPort5]>;
50 // Integer division issued on port 0, but uses the non-pipelined divider.
51 def SBDivider : ProcResource<1> { let Buffered = 0; }
53 // Loads are 4 cycles, so ReadAfterLd registers needn't be available until 4
54 // cycles after the memory operand.
55 def : ReadAdvance<ReadAfterLd, 4>;
57 // Many SchedWrites are defined in pairs with and without a folded load.
58 // Instructions with folded loads are usually micro-fused, so they only appear
59 // as two micro-ops when queued in the reservation station.
60 // This multiclass defines the resource usage for variants with and without
62 multiclass SBWriteResPair<X86FoldableSchedWrite SchedRW,
63 ProcResourceKind ExePort,
65 // Register variant is using a single cycle on ExePort.
66 def : WriteRes<SchedRW, [ExePort]> { let Latency = Lat; }
68 // Memory variant also uses a cycle on port 2/3 and adds 4 cycles to the
70 def : WriteRes<SchedRW.Folded, [SBPort23, ExePort]> {
71 let Latency = !add(Lat, 4);
75 // A folded store needs a cycle on port 4 for the store data, but it does not
76 // need an extra port 2/3 cycle to recompute the address.
77 def : WriteRes<WriteRMW, [SBPort4]>;
79 def : WriteRes<WriteStore, [SBPort23, SBPort4]>;
80 def : WriteRes<WriteLoad, [SBPort23]> { let Latency = 4; }
81 def : WriteRes<WriteMove, [SBPort015]>;
82 def : WriteRes<WriteZero, []>;
84 defm : SBWriteResPair<WriteALU, SBPort015, 1>;
85 defm : SBWriteResPair<WriteIMul, SBPort1, 3>;
86 defm : SBWriteResPair<WriteShift, SBPort05, 1>;
87 defm : SBWriteResPair<WriteJump, SBPort5, 1>;
89 // This is for simple LEAs with one or two input operands.
90 // The complex ones can only execute on port 1, and they require two cycles on
91 // the port to read all inputs. We don't model that.
92 def : WriteRes<WriteLEA, [SBPort15]>;
94 // This is quite rough, latency depends on the dividend.
95 def : WriteRes<WriteIDiv, [SBPort0, SBDivider]> {
97 let ResourceCycles = [1, 10];
99 def : WriteRes<WriteIDivLd, [SBPort23, SBPort0, SBDivider]> {
101 let ResourceCycles = [1, 1, 10];
104 // Scalar and vector floating point.
105 defm : SBWriteResPair<WriteFAdd, SBPort1, 3>;
106 defm : SBWriteResPair<WriteFMul, SBPort0, 5>;
107 defm : SBWriteResPair<WriteFDiv, SBPort0, 12>; // 10-14 cycles.
108 defm : SBWriteResPair<WriteFRcp, SBPort0, 5>;
109 defm : SBWriteResPair<WriteFSqrt, SBPort0, 15>;
110 defm : SBWriteResPair<WriteCvtF2I, SBPort1, 3>;
111 defm : SBWriteResPair<WriteCvtI2F, SBPort1, 4>;
112 defm : SBWriteResPair<WriteCvtF2F, SBPort1, 3>;
114 // Vector integer operations.
115 defm : SBWriteResPair<WriteVecShift, SBPort05, 1>;
116 defm : SBWriteResPair<WriteVecLogic, SBPort015, 1>;
117 defm : SBWriteResPair<WriteVecALU, SBPort15, 1>;
118 defm : SBWriteResPair<WriteVecIMul, SBPort0, 5>;
119 defm : SBWriteResPair<WriteShuffle, SBPort15, 1>;
121 def : WriteRes<WriteSystem, [SBPort015]> { let Latency = 100; }
122 def : WriteRes<WriteMicrocoded, [SBPort015]> { let Latency = 100; }