1//==- RISCVSchedRocket.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 RocketModel : SchedMachineModel { 15 let MicroOpBufferSize = 0; // Rocket is in-order. 16 let IssueWidth = 1; // 1 micro-op is dispatched per cycle. 17 let LoadLatency = 3; 18 let MispredictPenalty = 3; 19 let CompleteModel = false; 20 let UnsupportedFeatures = [HasStdExtZbkb, HasStdExtZbkc, HasStdExtZbkx, 21 HasStdExtZknd, HasStdExtZkne, HasStdExtZknh, 22 HasStdExtZksed, HasStdExtZksh, HasStdExtZkr, 23 HasVInstructions, HasVInstructionsI64]; 24} 25 26//===----------------------------------------------------------------------===// 27// Define each kind of processor resource and number available. 28 29// Modeling each pipeline as a ProcResource using the BufferSize = 0 since 30// Rocket is in-order. 31 32let BufferSize = 0 in { 33def RocketUnitALU : ProcResource<1>; // Int ALU 34def RocketUnitIMul : ProcResource<1>; // Int Multiply 35def RocketUnitMem : ProcResource<1>; // Load/Store 36def RocketUnitB : ProcResource<1>; // Branch 37 38def RocketUnitFPALU : ProcResource<1>; // FP ALU 39} 40 41let BufferSize = 1 in { 42def RocketUnitIDiv : ProcResource<1>; // Int Division 43def RocketUnitFPDivSqrt : ProcResource<1>; // FP Divide/Sqrt 44} 45 46//===----------------------------------------------------------------------===// 47 48let SchedModel = RocketModel in { 49 50// Branching 51def : WriteRes<WriteJmp, [RocketUnitB]>; 52def : WriteRes<WriteJal, [RocketUnitB]>; 53def : WriteRes<WriteJalr, [RocketUnitB]>; 54def : WriteRes<WriteJmpReg, [RocketUnitB]>; 55 56// Integer arithmetic and logic 57def : WriteRes<WriteIALU32, [RocketUnitALU]>; 58def : WriteRes<WriteIALU, [RocketUnitALU]>; 59def : WriteRes<WriteShiftImm32, [RocketUnitALU]>; 60def : WriteRes<WriteShiftImm, [RocketUnitALU]>; 61def : WriteRes<WriteShiftReg32, [RocketUnitALU]>; 62def : WriteRes<WriteShiftReg, [RocketUnitALU]>; 63 64// Integer multiplication 65let Latency = 4 in { 66def : WriteRes<WriteIMul, [RocketUnitIMul]>; 67def : WriteRes<WriteIMul32, [RocketUnitIMul]>; 68} 69 70// Integer division 71// Worst case latency is used. 72def : WriteRes<WriteIDiv32, [RocketUnitIDiv]> { 73 let Latency = 34; 74 let ResourceCycles = [34]; 75} 76def : WriteRes<WriteIDiv, [RocketUnitIDiv]> { 77 let Latency = 33; 78 let ResourceCycles = [33]; 79} 80 81// Memory 82def : WriteRes<WriteSTB, [RocketUnitMem]>; 83def : WriteRes<WriteSTH, [RocketUnitMem]>; 84def : WriteRes<WriteSTW, [RocketUnitMem]>; 85def : WriteRes<WriteSTD, [RocketUnitMem]>; 86def : WriteRes<WriteFST32, [RocketUnitMem]>; 87def : WriteRes<WriteFST64, [RocketUnitMem]>; 88 89let Latency = 3 in { 90def : WriteRes<WriteLDB, [RocketUnitMem]>; 91def : WriteRes<WriteLDH, [RocketUnitMem]>; 92} 93 94let Latency = 2 in { 95def : WriteRes<WriteLDW, [RocketUnitMem]>; 96def : WriteRes<WriteLDD, [RocketUnitMem]>; 97def : WriteRes<WriteFLD32, [RocketUnitMem]>; 98def : WriteRes<WriteFLD64, [RocketUnitMem]>; 99 100// Atomic memory 101def : WriteRes<WriteAtomicW, [RocketUnitMem]>; 102def : WriteRes<WriteAtomicD, [RocketUnitMem]>; 103 104def : WriteRes<WriteAtomicLDW, [RocketUnitMem]>; 105def : WriteRes<WriteAtomicLDD, [RocketUnitMem]>; 106} 107 108def : WriteRes<WriteAtomicSTW, [RocketUnitMem]>; 109def : WriteRes<WriteAtomicSTD, [RocketUnitMem]>; 110 111// Single precision. 112let Latency = 4 in { 113def : WriteRes<WriteFAdd32, [RocketUnitFPALU]>; 114def : WriteRes<WriteFSGNJ32, [RocketUnitFPALU]>; 115def : WriteRes<WriteFMinMax32, [RocketUnitFPALU]>; 116} 117 118// Double precision 119let Latency = 6 in { 120def : WriteRes<WriteFAdd64, [RocketUnitFPALU]>; 121def : WriteRes<WriteFSGNJ64, [RocketUnitFPALU]>; 122def : WriteRes<WriteFMinMax64, [RocketUnitFPALU]>; 123} 124 125// Conversions 126let Latency = 2 in { 127def : WriteRes<WriteFCvtI32ToF32, [RocketUnitFPALU]>; 128def : WriteRes<WriteFCvtI32ToF64, [RocketUnitFPALU]>; 129def : WriteRes<WriteFCvtI64ToF32, [RocketUnitFPALU]>; 130def : WriteRes<WriteFCvtI64ToF64, [RocketUnitFPALU]>; 131def : WriteRes<WriteFCvtF32ToI32, [RocketUnitFPALU]>; 132def : WriteRes<WriteFCvtF32ToI64, [RocketUnitFPALU]>; 133def : WriteRes<WriteFCvtF64ToI32, [RocketUnitFPALU]>; 134def : WriteRes<WriteFCvtF64ToI64, [RocketUnitFPALU]>; 135def : WriteRes<WriteFCvtF32ToF64, [RocketUnitFPALU]>; 136def : WriteRes<WriteFCvtF64ToF32, [RocketUnitFPALU]>; 137 138def : WriteRes<WriteFClass32, [RocketUnitFPALU]>; 139def : WriteRes<WriteFClass64, [RocketUnitFPALU]>; 140def : WriteRes<WriteFCmp32, [RocketUnitFPALU]>; 141def : WriteRes<WriteFCmp64, [RocketUnitFPALU]>; 142def : WriteRes<WriteFMovF32ToI32, [RocketUnitFPALU]>; 143def : WriteRes<WriteFMovI32ToF32, [RocketUnitFPALU]>; 144def : WriteRes<WriteFMovF64ToI64, [RocketUnitFPALU]>; 145def : WriteRes<WriteFMovI64ToF64, [RocketUnitFPALU]>; 146} 147 148// FP multiplication 149let Latency = 5 in { 150def : WriteRes<WriteFMul32, [RocketUnitFPALU]>; 151def : WriteRes<WriteFMA32, [RocketUnitFPALU]>; 152} 153 154let Latency = 7 in { 155def : WriteRes<WriteFMul64, [RocketUnitFPALU]>; 156def : WriteRes<WriteFMA64, [RocketUnitFPALU]>; 157} 158 159// FP division 160// FP division unit on Rocket is not pipelined, so set resource cycles to latency. 161let Latency = 20, ResourceCycles = [20] in { 162def : WriteRes<WriteFDiv32, [RocketUnitFPDivSqrt]>; 163def : WriteRes<WriteFDiv64, [RocketUnitFPDivSqrt]>; 164} 165 166// FP square root unit on Rocket is not pipelined, so set resource cycles to latency. 167def : WriteRes<WriteFSqrt32, [RocketUnitFPDivSqrt]> { let Latency = 20; 168 let ResourceCycles = [20]; } 169def : WriteRes<WriteFSqrt64, [RocketUnitFPDivSqrt]> { let Latency = 25; 170 let ResourceCycles = [25]; } 171 172// Others 173def : WriteRes<WriteCSR, []>; 174def : WriteRes<WriteNop, []>; 175 176def : InstRW<[WriteIALU], (instrs COPY)>; 177 178//===----------------------------------------------------------------------===// 179// Bypass and advance 180def : ReadAdvance<ReadJmp, 0>; 181def : ReadAdvance<ReadJalr, 0>; 182def : ReadAdvance<ReadCSR, 0>; 183def : ReadAdvance<ReadStoreData, 0>; 184def : ReadAdvance<ReadMemBase, 0>; 185def : ReadAdvance<ReadIALU, 0>; 186def : ReadAdvance<ReadIALU32, 0>; 187def : ReadAdvance<ReadShiftImm, 0>; 188def : ReadAdvance<ReadShiftImm32, 0>; 189def : ReadAdvance<ReadShiftReg, 0>; 190def : ReadAdvance<ReadShiftReg32, 0>; 191def : ReadAdvance<ReadIDiv, 0>; 192def : ReadAdvance<ReadIDiv32, 0>; 193def : ReadAdvance<ReadIMul, 0>; 194def : ReadAdvance<ReadIMul32, 0>; 195def : ReadAdvance<ReadAtomicWA, 0>; 196def : ReadAdvance<ReadAtomicWD, 0>; 197def : ReadAdvance<ReadAtomicDA, 0>; 198def : ReadAdvance<ReadAtomicDD, 0>; 199def : ReadAdvance<ReadAtomicLDW, 0>; 200def : ReadAdvance<ReadAtomicLDD, 0>; 201def : ReadAdvance<ReadAtomicSTW, 0>; 202def : ReadAdvance<ReadAtomicSTD, 0>; 203def : ReadAdvance<ReadFStoreData, 0>; 204def : ReadAdvance<ReadFMemBase, 0>; 205def : ReadAdvance<ReadFAdd32, 0>; 206def : ReadAdvance<ReadFAdd64, 0>; 207def : ReadAdvance<ReadFMul32, 0>; 208def : ReadAdvance<ReadFMul64, 0>; 209def : ReadAdvance<ReadFMA32, 0>; 210def : ReadAdvance<ReadFMA64, 0>; 211def : ReadAdvance<ReadFDiv32, 0>; 212def : ReadAdvance<ReadFDiv64, 0>; 213def : ReadAdvance<ReadFSqrt32, 0>; 214def : ReadAdvance<ReadFSqrt64, 0>; 215def : ReadAdvance<ReadFCmp32, 0>; 216def : ReadAdvance<ReadFCmp64, 0>; 217def : ReadAdvance<ReadFSGNJ32, 0>; 218def : ReadAdvance<ReadFSGNJ64, 0>; 219def : ReadAdvance<ReadFMinMax32, 0>; 220def : ReadAdvance<ReadFMinMax64, 0>; 221def : ReadAdvance<ReadFCvtF32ToI32, 0>; 222def : ReadAdvance<ReadFCvtF32ToI64, 0>; 223def : ReadAdvance<ReadFCvtF64ToI32, 0>; 224def : ReadAdvance<ReadFCvtF64ToI64, 0>; 225def : ReadAdvance<ReadFCvtI32ToF32, 0>; 226def : ReadAdvance<ReadFCvtI32ToF64, 0>; 227def : ReadAdvance<ReadFCvtI64ToF32, 0>; 228def : ReadAdvance<ReadFCvtI64ToF64, 0>; 229def : ReadAdvance<ReadFCvtF32ToF64, 0>; 230def : ReadAdvance<ReadFCvtF64ToF32, 0>; 231def : ReadAdvance<ReadFMovF32ToI32, 0>; 232def : ReadAdvance<ReadFMovI32ToF32, 0>; 233def : ReadAdvance<ReadFMovF64ToI64, 0>; 234def : ReadAdvance<ReadFMovI64ToF64, 0>; 235def : ReadAdvance<ReadFClass32, 0>; 236def : ReadAdvance<ReadFClass64, 0>; 237 238//===----------------------------------------------------------------------===// 239// Unsupported extensions 240defm : UnsupportedSchedV; 241defm : UnsupportedSchedZba; 242defm : UnsupportedSchedZbb; 243defm : UnsupportedSchedZbc; 244defm : UnsupportedSchedZbs; 245defm : UnsupportedSchedZbkb; 246defm : UnsupportedSchedZbkx; 247defm : UnsupportedSchedZfh; 248defm : UnsupportedSchedSFB; 249} 250