• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<WriteShift32, [RocketUnitALU]>;
56def : WriteRes<WriteShift, [RocketUnitALU]>;
57
58// Integer multiplication
59let Latency = 4 in {
60def : WriteRes<WriteIMul, [RocketUnitIMul]>;
61def : WriteRes<WriteIMul32, [RocketUnitIMul]>;
62}
63
64// Integer division
65// Worst case latency is used.
66def : WriteRes<WriteIDiv32, [RocketUnitIDiv]> {
67  let Latency = 34;
68  let ResourceCycles = [34];
69}
70def : WriteRes<WriteIDiv, [RocketUnitIDiv]> {
71  let Latency = 33;
72  let ResourceCycles = [33];
73}
74
75// Memory
76def : WriteRes<WriteSTB, [RocketUnitMem]>;
77def : WriteRes<WriteSTH, [RocketUnitMem]>;
78def : WriteRes<WriteSTW, [RocketUnitMem]>;
79def : WriteRes<WriteSTD, [RocketUnitMem]>;
80def : WriteRes<WriteFST32, [RocketUnitMem]>;
81def : WriteRes<WriteFST64, [RocketUnitMem]>;
82
83let Latency = 3 in {
84def : WriteRes<WriteLDB, [RocketUnitMem]>;
85def : WriteRes<WriteLDH, [RocketUnitMem]>;
86}
87
88let Latency = 2 in {
89def : WriteRes<WriteLDW, [RocketUnitMem]>;
90def : WriteRes<WriteLDWU, [RocketUnitMem]>;
91def : WriteRes<WriteLDD, [RocketUnitMem]>;
92def : WriteRes<WriteFLD32, [RocketUnitMem]>;
93def : WriteRes<WriteFLD64, [RocketUnitMem]>;
94
95// Atomic memory
96def : WriteRes<WriteAtomicW, [RocketUnitMem]>;
97def : WriteRes<WriteAtomicD, [RocketUnitMem]>;
98
99def : WriteRes<WriteAtomicLDW, [RocketUnitMem]>;
100def : WriteRes<WriteAtomicLDD, [RocketUnitMem]>;
101}
102
103def : WriteRes<WriteAtomicSTW, [RocketUnitMem]>;
104def : WriteRes<WriteAtomicSTD, [RocketUnitMem]>;
105
106// Single precision.
107let Latency = 4 in {
108def : WriteRes<WriteFALU32, [RocketUnitFPALU]>;
109def : WriteRes<WriteFSGNJ32, [RocketUnitFPALU]>;
110def : WriteRes<WriteFMinMax32, [RocketUnitFPALU]>;
111}
112
113// Double precision
114let Latency = 6 in {
115def : WriteRes<WriteFALU64, [RocketUnitFPALU]>;
116def : WriteRes<WriteFSGNJ64, [RocketUnitFPALU]>;
117def : WriteRes<WriteFMinMax64, [RocketUnitFPALU]>;
118}
119
120// Conversions
121let Latency = 2 in {
122def : WriteRes<WriteFCvtI32ToF32, [RocketUnitFPALU]>;
123def : WriteRes<WriteFCvtI32ToF64, [RocketUnitFPALU]>;
124def : WriteRes<WriteFCvtI64ToF32, [RocketUnitFPALU]>;
125def : WriteRes<WriteFCvtI64ToF64, [RocketUnitFPALU]>;
126def : WriteRes<WriteFCvtF32ToI32, [RocketUnitFPALU]>;
127def : WriteRes<WriteFCvtF32ToI64, [RocketUnitFPALU]>;
128def : WriteRes<WriteFCvtF64ToI32, [RocketUnitFPALU]>;
129def : WriteRes<WriteFCvtF64ToI64, [RocketUnitFPALU]>;
130def : WriteRes<WriteFCvtF32ToF64, [RocketUnitFPALU]>;
131def : WriteRes<WriteFCvtF64ToF32, [RocketUnitFPALU]>;
132
133def : WriteRes<WriteFClass32, [RocketUnitFPALU]>;
134def : WriteRes<WriteFClass64, [RocketUnitFPALU]>;
135def : WriteRes<WriteFCmp32, [RocketUnitFPALU]>;
136def : WriteRes<WriteFCmp64, [RocketUnitFPALU]>;
137def : WriteRes<WriteFMovF32ToI32, [RocketUnitFPALU]>;
138def : WriteRes<WriteFMovI32ToF32, [RocketUnitFPALU]>;
139def : WriteRes<WriteFMovF64ToI64, [RocketUnitFPALU]>;
140def : WriteRes<WriteFMovI64ToF64, [RocketUnitFPALU]>;
141}
142
143// FP multiplication
144let Latency = 5 in {
145def : WriteRes<WriteFMul32, [RocketUnitFPALU]>;
146def : WriteRes<WriteFMulAdd32, [RocketUnitFPALU]>;
147def : WriteRes<WriteFMulSub32, [RocketUnitFPALU]>;
148}
149
150let Latency = 7 in {
151def : WriteRes<WriteFMul64, [RocketUnitFPALU]>;
152def : WriteRes<WriteFMulAdd64, [RocketUnitFPALU]>;
153def : WriteRes<WriteFMulSub64, [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<ReadShift, 0>;
185def : ReadAdvance<ReadShift32, 0>;
186def : ReadAdvance<ReadIDiv, 0>;
187def : ReadAdvance<ReadIDiv32, 0>;
188def : ReadAdvance<ReadIMul, 0>;
189def : ReadAdvance<ReadIMul32, 0>;
190def : ReadAdvance<ReadAtomicWA, 0>;
191def : ReadAdvance<ReadAtomicWD, 0>;
192def : ReadAdvance<ReadAtomicDA, 0>;
193def : ReadAdvance<ReadAtomicDD, 0>;
194def : ReadAdvance<ReadAtomicLDW, 0>;
195def : ReadAdvance<ReadAtomicLDD, 0>;
196def : ReadAdvance<ReadAtomicSTW, 0>;
197def : ReadAdvance<ReadAtomicSTD, 0>;
198def : ReadAdvance<ReadFMemBase, 0>;
199def : ReadAdvance<ReadFALU32, 0>;
200def : ReadAdvance<ReadFALU64, 0>;
201def : ReadAdvance<ReadFMul32, 0>;
202def : ReadAdvance<ReadFMulAdd32, 0>;
203def : ReadAdvance<ReadFMulSub32, 0>;
204def : ReadAdvance<ReadFMul64, 0>;
205def : ReadAdvance<ReadFMulAdd64, 0>;
206def : ReadAdvance<ReadFMulSub64, 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