1//==- RISCVSchedRocket64.td - Rocket Scheduling Definitions -*- tablegen -*-=// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9// ===---------------------------------------------------------------------===// 10// The following definitions describe the simpler per-operand machine model. 11// This works with MachineScheduler. See MCSchedule.h for details. 12 13// Rocket machine model for scheduling and other instruction cost heuristics. 14def Rocket64Model : SchedMachineModel { 15 let MicroOpBufferSize = 0; // Explicitly set to zero since Rocket is in-order. 16 let IssueWidth = 1; // 1 micro-ops are dispatched per cycle. 17 let LoadLatency = 3; 18 let MispredictPenalty = 3; 19} 20 21//===----------------------------------------------------------------------===// 22// Define each kind of processor resource and number available. 23 24// Modeling each pipeline as a ProcResource using the BufferSize = 0 since 25// Rocket is in-order. 26 27let BufferSize = 0 in { 28def Rocket64UnitALU : ProcResource<1>; // Int ALU 29def Rocket64UnitIMul : ProcResource<1>; // Int Multiply 30def Rocket64UnitMem : ProcResource<1>; // Load/Store 31def Rocket64UnitB : ProcResource<1>; // Branch 32 33def Rocket64UnitFPALU : ProcResource<1>; // FP ALU 34} 35 36let BufferSize = 1 in { 37def Rocket64UnitIDiv : ProcResource<1>; // Int Division 38def Rocket64UnitFPDivSqrt : ProcResource<1>; // FP Divide/Sqrt 39} 40 41//===----------------------------------------------------------------------===// 42// Subtarget-specific SchedWrite types which both map the ProcResources and 43// set the latency. 44 45let SchedModel = Rocket64Model in { 46 47def : WriteRes<WriteJmp, [Rocket64UnitB]>; 48def : WriteRes<WriteJal, [Rocket64UnitB]>; 49def : WriteRes<WriteJalr, [Rocket64UnitB]>; 50def : WriteRes<WriteJmpReg, [Rocket64UnitB]>; 51 52def : WriteRes<WriteIALU32, [Rocket64UnitALU]>; 53def : WriteRes<WriteIALU, [Rocket64UnitALU]>; 54def : WriteRes<WriteShift32, [Rocket64UnitALU]>; 55def : WriteRes<WriteShift, [Rocket64UnitALU]>; 56 57let Latency = 4 in { 58def : WriteRes<WriteIMul, [Rocket64UnitIMul]>; 59def : WriteRes<WriteIMul32, [Rocket64UnitIMul]>; 60} 61 62// Integer divide varies based on operand magnitude and sign; worse case latency is 34. 63def : WriteRes<WriteIDiv32, [Rocket64UnitIDiv]> { 64 let Latency = 34; 65 let ResourceCycles = [34]; 66} 67def : WriteRes<WriteIDiv, [Rocket64UnitIDiv]> { 68 let Latency = 33; 69 let ResourceCycles = [33]; 70} 71 72// Memory 73def : WriteRes<WriteSTB, [Rocket64UnitMem]>; 74def : WriteRes<WriteSTH, [Rocket64UnitMem]>; 75def : WriteRes<WriteSTW, [Rocket64UnitMem]>; 76def : WriteRes<WriteSTD, [Rocket64UnitMem]>; 77def : WriteRes<WriteFST32, [Rocket64UnitMem]>; 78def : WriteRes<WriteFST64, [Rocket64UnitMem]>; 79 80let Latency = 3 in { 81def : WriteRes<WriteLDB, [Rocket64UnitMem]>; 82def : WriteRes<WriteLDH, [Rocket64UnitMem]>; 83def : WriteRes<WriteCSR, [Rocket64UnitALU]>; 84} 85 86let Latency = 2 in { 87def : WriteRes<WriteLDW, [Rocket64UnitMem]>; 88def : WriteRes<WriteLDWU, [Rocket64UnitMem]>; 89def : WriteRes<WriteLDD, [Rocket64UnitMem]>; 90def : WriteRes<WriteFLD32, [Rocket64UnitMem]>; 91def : WriteRes<WriteFLD64, [Rocket64UnitMem]>; 92 93def : WriteRes<WriteAtomicW, [Rocket64UnitMem]>; 94def : WriteRes<WriteAtomicD, [Rocket64UnitMem]>; 95 96def : WriteRes<WriteAtomicLDW, [Rocket64UnitMem]>; 97def : WriteRes<WriteAtomicLDD, [Rocket64UnitMem]>; 98} 99 100def : WriteRes<WriteAtomicSTW, [Rocket64UnitMem]>; 101def : WriteRes<WriteAtomicSTD, [Rocket64UnitMem]>; 102 103// Most FP single precision operations are 4 cycles 104def : WriteRes<WriteFALU32, [Rocket64UnitFPALU]> { let Latency = 4; } 105 106// Most FP double precision operations are 6 cycles 107def : WriteRes<WriteFALU64, [Rocket64UnitFPALU]> { let Latency = 6; } 108 109// Conversion instructions 110let Latency = 2 in { 111def : WriteRes<WriteFCvtI32ToF32, [Rocket32UnitFPALU]>; 112def : WriteRes<WriteFCvtI32ToF64, [Rocket32UnitFPALU]>; 113def : WriteRes<WriteFCvtI64ToF32, [Rocket32UnitFPALU]>; 114def : WriteRes<WriteFCvtI64ToF64, [Rocket32UnitFPALU]>; 115def : WriteRes<WriteFCvtF32ToI32, [Rocket32UnitFPALU]>; 116def : WriteRes<WriteFCvtF32ToI64, [Rocket32UnitFPALU]>; 117def : WriteRes<WriteFCvtF64ToI32, [Rocket32UnitFPALU]>; 118def : WriteRes<WriteFCvtF64ToI64, [Rocket32UnitFPALU]>; 119def : WriteRes<WriteFCvtF32ToF64, [Rocket32UnitFPALU]>; 120def : WriteRes<WriteFCvtF64ToF32, [Rocket32UnitFPALU]>; 121 122def : WriteRes<WriteFClass32, [Rocket64UnitFPALU]>; 123def : WriteRes<WriteFClass64, [Rocket64UnitFPALU]>; 124def : WriteRes<WriteFCmp32, [Rocket64UnitFPALU]>; 125def : WriteRes<WriteFCmp64, [Rocket64UnitFPALU]>; 126def : WriteRes<WriteFMovF32ToI32, [Rocket64UnitFPALU]>; 127def : WriteRes<WriteFMovI32ToF32, [Rocket64UnitFPALU]>; 128def : WriteRes<WriteFMovF64ToI64, [Rocket64UnitFPALU]>; 129def : WriteRes<WriteFMovI64ToF64, [Rocket64UnitFPALU]>; 130} 131 132let Latency = 5 in { 133def : WriteRes<WriteFMul32, [Rocket64UnitFPALU]>; 134def : WriteRes<WriteFMulAdd32, [Rocket64UnitFPALU]>; 135def : WriteRes<WriteFMulSub32, [Rocket64UnitFPALU]>; 136} 137 138let Latency = 7 in { 139def : WriteRes<WriteFMul64, [Rocket64UnitFPALU]>; 140def : WriteRes<WriteFMulAdd64, [Rocket64UnitFPALU]>; 141def : WriteRes<WriteFMulSub64, [Rocket64UnitFPALU]>; 142} 143 144// FP Divide unit on Rocket is not pipelined, so set resource cycles to latency 145let Latency = 20, ResourceCycles = [20] in { 146def : WriteRes<WriteFDiv32, [Rocket64UnitFPDivSqrt]>; 147def : WriteRes<WriteFDiv64, [Rocket64UnitFPDivSqrt]>; 148} 149 150// FP Sqrt unit on Rocket is not pipelined, so set resource cycles to latency 151def : WriteRes<WriteFSqrt32, [Rocket64UnitFPDivSqrt]> { let Latency = 20; 152 let ResourceCycles = [20]; } 153def : WriteRes<WriteFSqrt64, [Rocket64UnitFPDivSqrt]> { let Latency = 25; 154 let ResourceCycles = [25]; } 155 156def : WriteRes<WriteNop, []>; 157 158def : InstRW<[WriteIALU], (instrs COPY)>; 159 160//===----------------------------------------------------------------------===// 161// Subtarget-specific SchedRead types with cycles. 162// Dummy definitions for RocketCore. 163def : ReadAdvance<ReadJmp, 0>; 164def : ReadAdvance<ReadJalr, 0>; 165def : ReadAdvance<ReadCSR, 0>; 166def : ReadAdvance<ReadStoreData, 0>; 167def : ReadAdvance<ReadMemBase, 0>; 168def : ReadAdvance<ReadIALU, 0>; 169def : ReadAdvance<ReadIALU32, 0>; 170def : ReadAdvance<ReadShift, 0>; 171def : ReadAdvance<ReadShift32, 0>; 172def : ReadAdvance<ReadIDiv, 0>; 173def : ReadAdvance<ReadIDiv32, 0>; 174def : ReadAdvance<ReadIMul, 0>; 175def : ReadAdvance<ReadIMul32, 0>; 176def : ReadAdvance<ReadAtomicWA, 0>; 177def : ReadAdvance<ReadAtomicWD, 0>; 178def : ReadAdvance<ReadAtomicDA, 0>; 179def : ReadAdvance<ReadAtomicDD, 0>; 180def : ReadAdvance<ReadAtomicLDW, 0>; 181def : ReadAdvance<ReadAtomicLDD, 0>; 182def : ReadAdvance<ReadAtomicSTW, 0>; 183def : ReadAdvance<ReadAtomicSTD, 0>; 184def : ReadAdvance<ReadFALU32, 0>; 185def : ReadAdvance<ReadFALU64, 0>; 186def : ReadAdvance<ReadFMul32, 0>; 187def : ReadAdvance<ReadFMulAdd32, 0>; 188def : ReadAdvance<ReadFMulSub32, 0>; 189def : ReadAdvance<ReadFMul64, 0>; 190def : ReadAdvance<ReadFMulAdd64, 0>; 191def : ReadAdvance<ReadFMulSub64, 0>; 192def : ReadAdvance<ReadFDiv32, 0>; 193def : ReadAdvance<ReadFDiv64, 0>; 194def : ReadAdvance<ReadFSqrt32, 0>; 195def : ReadAdvance<ReadFSqrt64, 0>; 196def : ReadAdvance<ReadFCmp32, 0>; 197def : ReadAdvance<ReadFCmp64, 0>; 198def : ReadAdvance<ReadFCvtF32ToI32, 0>; 199def : ReadAdvance<ReadFCvtF32ToI64, 0>; 200def : ReadAdvance<ReadFCvtF64ToI32, 0>; 201def : ReadAdvance<ReadFCvtF64ToI64, 0>; 202def : ReadAdvance<ReadFCvtI32ToF32, 0>; 203def : ReadAdvance<ReadFCvtI32ToF64, 0>; 204def : ReadAdvance<ReadFCvtI64ToF32, 0>; 205def : ReadAdvance<ReadFCvtI64ToF64, 0>; 206def : ReadAdvance<ReadFCvtF32ToF64, 0>; 207def : ReadAdvance<ReadFCvtF64ToF32, 0>; 208def : ReadAdvance<ReadFMovF32ToI32, 0>; 209def : ReadAdvance<ReadFMovI32ToF32, 0>; 210def : ReadAdvance<ReadFMovF64ToI64, 0>; 211def : ReadAdvance<ReadFMovI64ToF64, 0>; 212def : ReadAdvance<ReadFClass32, 0>; 213def : ReadAdvance<ReadFClass64, 0>; 214} 215