1 //=- X86SchedHaswell.td - X86 Haswell Scheduling -------------*- tablegen -*-=// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the machine model for Haswell to support instruction 11 // scheduling and other instruction cost heuristics. 12 // 13 //===----------------------------------------------------------------------===// 14 15 def HaswellModel : SchedMachineModel { 16 // All x86 instructions are modeled as a single micro-op, and HW can decode 4 17 // instructions per cycle. 18 let IssueWidth = 4; 19 let MicroOpBufferSize = 192; // Based on the reorder buffer. 20 let LoadLatency = 4; 21 let MispredictPenalty = 16; 22 23 // Based on the LSD (loop-stream detector) queue size and benchmarking data. 24 let LoopMicroOpBufferSize = 50; 25 26 // FIXME: SSE4 and AVX are unimplemented. This flag is set to allow 27 // the scheduler to assign a default model to unrecognized opcodes. 28 let CompleteModel = 0; 29 } 30 31 let SchedModel = HaswellModel in { 32 33 // Haswell can issue micro-ops to 8 different ports in one cycle. 34 35 // Ports 0, 1, 5, and 6 handle all computation. 36 // Port 4 gets the data half of stores. Store data can be available later than 37 // the store address, but since we don't model the latency of stores, we can 38 // ignore that. 39 // Ports 2 and 3 are identical. They handle loads and the address half of 40 // stores. Port 7 can handle address calculations. 41 def HWPort0 : ProcResource<1>; 42 def HWPort1 : ProcResource<1>; 43 def HWPort2 : ProcResource<1>; 44 def HWPort3 : ProcResource<1>; 45 def HWPort4 : ProcResource<1>; 46 def HWPort5 : ProcResource<1>; 47 def HWPort6 : ProcResource<1>; 48 def HWPort7 : ProcResource<1>; 49 50 // Many micro-ops are capable of issuing on multiple ports. 51 def HWPort23 : ProcResGroup<[HWPort2, HWPort3]>; 52 def HWPort237 : ProcResGroup<[HWPort2, HWPort3, HWPort7]>; 53 def HWPort05 : ProcResGroup<[HWPort0, HWPort5]>; 54 def HWPort06 : ProcResGroup<[HWPort0, HWPort6]>; 55 def HWPort15 : ProcResGroup<[HWPort1, HWPort5]>; 56 def HWPort16 : ProcResGroup<[HWPort1, HWPort6]>; 57 def HWPort015 : ProcResGroup<[HWPort0, HWPort1, HWPort5]>; 58 def HWPort0156: ProcResGroup<[HWPort0, HWPort1, HWPort5, HWPort6]>; 59 60 // 60 Entry Unified Scheduler 61 def HWPortAny : ProcResGroup<[HWPort0, HWPort1, HWPort2, HWPort3, HWPort4, 62 HWPort5, HWPort6, HWPort7]> { 63 let BufferSize=60; 64 } 65 66 // Integer division issued on port 0. 67 def HWDivider : ProcResource<1>; 68 69 // Loads are 4 cycles, so ReadAfterLd registers needn't be available until 4 70 // cycles after the memory operand. 71 def : ReadAdvance<ReadAfterLd, 4>; 72 73 // Many SchedWrites are defined in pairs with and without a folded load. 74 // Instructions with folded loads are usually micro-fused, so they only appear 75 // as two micro-ops when queued in the reservation station. 76 // This multiclass defines the resource usage for variants with and without 77 // folded loads. 78 multiclass HWWriteResPair<X86FoldableSchedWrite SchedRW, 79 ProcResourceKind ExePort, 80 int Lat> { 81 // Register variant is using a single cycle on ExePort. 82 def : WriteRes<SchedRW, [ExePort]> { let Latency = Lat; } 83 84 // Memory variant also uses a cycle on port 2/3 and adds 4 cycles to the 85 // latency. 86 def : WriteRes<SchedRW.Folded, [HWPort23, ExePort]> { 87 let Latency = !add(Lat, 4); 88 } 89 } 90 91 // A folded store needs a cycle on port 4 for the store data, but it does not 92 // need an extra port 2/3 cycle to recompute the address. 93 def : WriteRes<WriteRMW, [HWPort4]>; 94 95 // Store_addr on 237. 96 // Store_data on 4. 97 def : WriteRes<WriteStore, [HWPort237, HWPort4]>; 98 def : WriteRes<WriteLoad, [HWPort23]> { let Latency = 4; } 99 def : WriteRes<WriteMove, [HWPort0156]>; 100 def : WriteRes<WriteZero, []>; 101 102 defm : HWWriteResPair<WriteALU, HWPort0156, 1>; 103 defm : HWWriteResPair<WriteIMul, HWPort1, 3>; 104 def : WriteRes<WriteIMulH, []> { let Latency = 3; } 105 defm : HWWriteResPair<WriteShift, HWPort06, 1>; 106 defm : HWWriteResPair<WriteJump, HWPort06, 1>; 107 108 // This is for simple LEAs with one or two input operands. 109 // The complex ones can only execute on port 1, and they require two cycles on 110 // the port to read all inputs. We don't model that. 111 def : WriteRes<WriteLEA, [HWPort15]>; 112 113 // This is quite rough, latency depends on the dividend. 114 def : WriteRes<WriteIDiv, [HWPort0, HWDivider]> { 115 let Latency = 25; 116 let ResourceCycles = [1, 10]; 117 } 118 def : WriteRes<WriteIDivLd, [HWPort23, HWPort0, HWDivider]> { 119 let Latency = 29; 120 let ResourceCycles = [1, 1, 10]; 121 } 122 123 // Scalar and vector floating point. 124 defm : HWWriteResPair<WriteFAdd, HWPort1, 3>; 125 defm : HWWriteResPair<WriteFMul, HWPort0, 5>; 126 defm : HWWriteResPair<WriteFDiv, HWPort0, 12>; // 10-14 cycles. 127 defm : HWWriteResPair<WriteFRcp, HWPort0, 5>; 128 defm : HWWriteResPair<WriteFSqrt, HWPort0, 15>; 129 defm : HWWriteResPair<WriteCvtF2I, HWPort1, 3>; 130 defm : HWWriteResPair<WriteCvtI2F, HWPort1, 4>; 131 defm : HWWriteResPair<WriteCvtF2F, HWPort1, 3>; 132 defm : HWWriteResPair<WriteFShuffle, HWPort5, 1>; 133 defm : HWWriteResPair<WriteFBlend, HWPort015, 1>; 134 defm : HWWriteResPair<WriteFShuffle256, HWPort5, 3>; 135 136 def : WriteRes<WriteFVarBlend, [HWPort5]> { 137 let Latency = 2; 138 let ResourceCycles = [2]; 139 } 140 def : WriteRes<WriteFVarBlendLd, [HWPort5, HWPort23]> { 141 let Latency = 6; 142 let ResourceCycles = [2, 1]; 143 } 144 145 // Vector integer operations. 146 defm : HWWriteResPair<WriteVecShift, HWPort0, 1>; 147 defm : HWWriteResPair<WriteVecLogic, HWPort015, 1>; 148 defm : HWWriteResPair<WriteVecALU, HWPort15, 1>; 149 defm : HWWriteResPair<WriteVecIMul, HWPort0, 5>; 150 defm : HWWriteResPair<WriteShuffle, HWPort5, 1>; 151 defm : HWWriteResPair<WriteBlend, HWPort15, 1>; 152 defm : HWWriteResPair<WriteShuffle256, HWPort5, 3>; 153 154 def : WriteRes<WriteVarBlend, [HWPort5]> { 155 let Latency = 2; 156 let ResourceCycles = [2]; 157 } 158 def : WriteRes<WriteVarBlendLd, [HWPort5, HWPort23]> { 159 let Latency = 6; 160 let ResourceCycles = [2, 1]; 161 } 162 163 def : WriteRes<WriteVarVecShift, [HWPort0, HWPort5]> { 164 let Latency = 2; 165 let ResourceCycles = [2, 1]; 166 } 167 def : WriteRes<WriteVarVecShiftLd, [HWPort0, HWPort5, HWPort23]> { 168 let Latency = 6; 169 let ResourceCycles = [2, 1, 1]; 170 } 171 172 def : WriteRes<WriteMPSAD, [HWPort0, HWPort5]> { 173 let Latency = 6; 174 let ResourceCycles = [1, 2]; 175 } 176 def : WriteRes<WriteMPSADLd, [HWPort23, HWPort0, HWPort5]> { 177 let Latency = 6; 178 let ResourceCycles = [1, 1, 2]; 179 } 180 181 // String instructions. 182 // Packed Compare Implicit Length Strings, Return Mask 183 def : WriteRes<WritePCmpIStrM, [HWPort0]> { 184 let Latency = 10; 185 let ResourceCycles = [3]; 186 } 187 def : WriteRes<WritePCmpIStrMLd, [HWPort0, HWPort23]> { 188 let Latency = 10; 189 let ResourceCycles = [3, 1]; 190 } 191 192 // Packed Compare Explicit Length Strings, Return Mask 193 def : WriteRes<WritePCmpEStrM, [HWPort0, HWPort16, HWPort5]> { 194 let Latency = 10; 195 let ResourceCycles = [3, 2, 4]; 196 } 197 def : WriteRes<WritePCmpEStrMLd, [HWPort05, HWPort16, HWPort23]> { 198 let Latency = 10; 199 let ResourceCycles = [6, 2, 1]; 200 } 201 202 // Packed Compare Implicit Length Strings, Return Index 203 def : WriteRes<WritePCmpIStrI, [HWPort0]> { 204 let Latency = 11; 205 let ResourceCycles = [3]; 206 } 207 def : WriteRes<WritePCmpIStrILd, [HWPort0, HWPort23]> { 208 let Latency = 11; 209 let ResourceCycles = [3, 1]; 210 } 211 212 // Packed Compare Explicit Length Strings, Return Index 213 def : WriteRes<WritePCmpEStrI, [HWPort05, HWPort16]> { 214 let Latency = 11; 215 let ResourceCycles = [6, 2]; 216 } 217 def : WriteRes<WritePCmpEStrILd, [HWPort0, HWPort16, HWPort5, HWPort23]> { 218 let Latency = 11; 219 let ResourceCycles = [3, 2, 2, 1]; 220 } 221 222 // AES Instructions. 223 def : WriteRes<WriteAESDecEnc, [HWPort5]> { 224 let Latency = 7; 225 let ResourceCycles = [1]; 226 } 227 def : WriteRes<WriteAESDecEncLd, [HWPort5, HWPort23]> { 228 let Latency = 7; 229 let ResourceCycles = [1, 1]; 230 } 231 232 def : WriteRes<WriteAESIMC, [HWPort5]> { 233 let Latency = 14; 234 let ResourceCycles = [2]; 235 } 236 def : WriteRes<WriteAESIMCLd, [HWPort5, HWPort23]> { 237 let Latency = 14; 238 let ResourceCycles = [2, 1]; 239 } 240 241 def : WriteRes<WriteAESKeyGen, [HWPort0, HWPort5]> { 242 let Latency = 10; 243 let ResourceCycles = [2, 8]; 244 } 245 def : WriteRes<WriteAESKeyGenLd, [HWPort0, HWPort5, HWPort23]> { 246 let Latency = 10; 247 let ResourceCycles = [2, 7, 1]; 248 } 249 250 // Carry-less multiplication instructions. 251 def : WriteRes<WriteCLMul, [HWPort0, HWPort5]> { 252 let Latency = 7; 253 let ResourceCycles = [2, 1]; 254 } 255 def : WriteRes<WriteCLMulLd, [HWPort0, HWPort5, HWPort23]> { 256 let Latency = 7; 257 let ResourceCycles = [2, 1, 1]; 258 } 259 260 def : WriteRes<WriteSystem, [HWPort0156]> { let Latency = 100; } 261 def : WriteRes<WriteMicrocoded, [HWPort0156]> { let Latency = 100; } 262 def : WriteRes<WriteFence, [HWPort23, HWPort4]>; 263 def : WriteRes<WriteNop, []>; 264 } // SchedModel 265