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