1//==- RISCVSchedSiFive7.td - SiFive7 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
11// SiFive7 machine model for scheduling and other instruction cost heuristics.
12def SiFive7Model : SchedMachineModel {
13  let MicroOpBufferSize = 0; // Explicitly set to zero since SiFive7 is in-order.
14  let IssueWidth = 2;        // 2 micro-ops are dispatched per cycle.
15  let LoadLatency = 3;
16  let MispredictPenalty = 3;
17  let CompleteModel = 0;
18  let UnsupportedFeatures = [HasStdExtV, HasStdExtZvamo, HasStdExtZvlsseg];
19}
20
21// The SiFive7 microarchitecure has two pipelines: A and B.
22// Pipe A can handle memory, integer alu and vector operations.
23// Pipe B can handle integer alu, control flow, integer multiply and divide,
24// and floating point computation.
25let SchedModel = SiFive7Model in {
26let BufferSize = 0 in {
27def SiFive7PipeA       : ProcResource<1>;
28def SiFive7PipeB       : ProcResource<1>;
29}
30
31let BufferSize = 1 in {
32def SiFive7IDiv        : ProcResource<1> { let Super = SiFive7PipeB; } // Int Division
33def SiFive7FDiv        : ProcResource<1> { let Super = SiFive7PipeB; } // FP Division/Sqrt
34}
35
36def SiFive7PipeAB : ProcResGroup<[SiFive7PipeA, SiFive7PipeB]>;
37
38// Branching
39def : WriteRes<WriteJmp, [SiFive7PipeB]>;
40def : WriteRes<WriteJal, [SiFive7PipeB]>;
41def : WriteRes<WriteJalr, [SiFive7PipeB]>;
42def : WriteRes<WriteJmpReg, [SiFive7PipeB]>;
43
44// Integer arithmetic and logic
45let Latency = 3 in {
46def : WriteRes<WriteIALU, [SiFive7PipeAB]>;
47def : WriteRes<WriteIALU32, [SiFive7PipeAB]>;
48def : WriteRes<WriteShift, [SiFive7PipeAB]>;
49def : WriteRes<WriteShift32, [SiFive7PipeAB]>;
50}
51
52// Integer multiplication
53let Latency = 3 in {
54def : WriteRes<WriteIMul, [SiFive7PipeB]>;
55def : WriteRes<WriteIMul32, [SiFive7PipeB]>;
56}
57
58// Integer division
59def : WriteRes<WriteIDiv, [SiFive7PipeB, SiFive7IDiv]> {
60  let Latency = 16;
61  let ResourceCycles = [1, 15];
62}
63def : WriteRes<WriteIDiv32,  [SiFive7PipeB, SiFive7IDiv]> {
64  let Latency = 16;
65  let ResourceCycles = [1, 15];
66}
67
68// Memory
69def : WriteRes<WriteSTB, [SiFive7PipeA]>;
70def : WriteRes<WriteSTH, [SiFive7PipeA]>;
71def : WriteRes<WriteSTW, [SiFive7PipeA]>;
72def : WriteRes<WriteSTD, [SiFive7PipeA]>;
73def : WriteRes<WriteFST32, [SiFive7PipeA]>;
74def : WriteRes<WriteFST64, [SiFive7PipeA]>;
75
76let Latency = 3 in {
77def : WriteRes<WriteLDB, [SiFive7PipeA]>;
78def : WriteRes<WriteLDH, [SiFive7PipeA]>;
79def : WriteRes<WriteLDW, [SiFive7PipeA]>;
80def : WriteRes<WriteLDWU, [SiFive7PipeA]>;
81def : WriteRes<WriteLDD, [SiFive7PipeA]>;
82}
83
84let Latency = 2 in {
85def : WriteRes<WriteFLD32, [SiFive7PipeA]>;
86def : WriteRes<WriteFLD64, [SiFive7PipeA]>;
87}
88
89// Atomic memory
90def : WriteRes<WriteAtomicSTW, [SiFive7PipeA]>;
91def : WriteRes<WriteAtomicSTD, [SiFive7PipeA]>;
92
93let Latency = 3 in {
94def : WriteRes<WriteAtomicW, [SiFive7PipeA]>;
95def : WriteRes<WriteAtomicD, [SiFive7PipeA]>;
96def : WriteRes<WriteAtomicLDW, [SiFive7PipeA]>;
97def : WriteRes<WriteAtomicLDD, [SiFive7PipeA]>;
98}
99
100// Single precision.
101let Latency = 5 in {
102def : WriteRes<WriteFALU32, [SiFive7PipeB]>;
103def : WriteRes<WriteFMul32, [SiFive7PipeB]>;
104def : WriteRes<WriteFMulAdd32, [SiFive7PipeB]>;
105def : WriteRes<WriteFMulSub32, [SiFive7PipeB]>;
106}
107let Latency = 3 in {
108def : WriteRes<WriteFSGNJ32, [SiFive7PipeB]>;
109def : WriteRes<WriteFMinMax32, [SiFive7PipeB]>;
110}
111
112def : WriteRes<WriteFDiv32, [SiFive7PipeB, SiFive7FDiv]> { let Latency = 27;
113                                                         let ResourceCycles = [1, 26]; }
114def : WriteRes<WriteFSqrt32, [SiFive7PipeB, SiFive7FDiv]> { let Latency = 27;
115                                                          let ResourceCycles = [1, 26]; }
116
117// Double precision
118let Latency = 7 in {
119def : WriteRes<WriteFALU64, [SiFive7PipeB]>;
120def : WriteRes<WriteFMul64, [SiFive7PipeB]>;
121def : WriteRes<WriteFMulAdd64, [SiFive7PipeB]>;
122def : WriteRes<WriteFMulSub64, [SiFive7PipeB]>;
123}
124let Latency = 3 in {
125def : WriteRes<WriteFSGNJ64, [SiFive7PipeB]>;
126def : WriteRes<WriteFMinMax64, [SiFive7PipeB]>;
127}
128
129def : WriteRes<WriteFDiv64, [SiFive7PipeB, SiFive7FDiv]> { let Latency = 56;
130                                                         let ResourceCycles = [1, 55]; }
131def : WriteRes<WriteFSqrt64, [SiFive7PipeB, SiFive7FDiv]> { let Latency = 56;
132                                                          let ResourceCycles = [1, 55]; }
133
134// Conversions
135let Latency = 3 in {
136def : WriteRes<WriteFCvtI32ToF32, [SiFive7PipeB]>;
137def : WriteRes<WriteFCvtI32ToF64, [SiFive7PipeB]>;
138def : WriteRes<WriteFCvtI64ToF32, [SiFive7PipeB]>;
139def : WriteRes<WriteFCvtI64ToF64, [SiFive7PipeB]>;
140def : WriteRes<WriteFCvtF32ToI32, [SiFive7PipeB]>;
141def : WriteRes<WriteFCvtF32ToI64, [SiFive7PipeB]>;
142def : WriteRes<WriteFCvtF32ToF64, [SiFive7PipeB]>;
143def : WriteRes<WriteFCvtF64ToI32, [SiFive7PipeB]>;
144def : WriteRes<WriteFCvtF64ToI64, [SiFive7PipeB]>;
145def : WriteRes<WriteFCvtF64ToF32, [SiFive7PipeB]>;
146
147def : WriteRes<WriteFClass32, [SiFive7PipeB]>;
148def : WriteRes<WriteFClass64, [SiFive7PipeB]>;
149def : WriteRes<WriteFCmp32, [SiFive7PipeB]>;
150def : WriteRes<WriteFCmp64, [SiFive7PipeB]>;
151def : WriteRes<WriteFMovI32ToF32, [SiFive7PipeB]>;
152def : WriteRes<WriteFMovF32ToI32, [SiFive7PipeB]>;
153def : WriteRes<WriteFMovI64ToF64, [SiFive7PipeB]>;
154def : WriteRes<WriteFMovF64ToI64, [SiFive7PipeB]>;
155}
156
157// Others
158def : WriteRes<WriteCSR, [SiFive7PipeB]>;
159def : WriteRes<WriteNop, []>;
160
161def : InstRW<[WriteIALU], (instrs COPY)>;
162
163
164//===----------------------------------------------------------------------===//
165// Bypass and advance
166def : ReadAdvance<ReadJmp, 0>;
167def : ReadAdvance<ReadJalr, 0>;
168def : ReadAdvance<ReadCSR, 0>;
169def : ReadAdvance<ReadStoreData, 0>;
170def : ReadAdvance<ReadMemBase, 0>;
171def : ReadAdvance<ReadIALU, 0>;
172def : ReadAdvance<ReadIALU32, 0>;
173def : ReadAdvance<ReadShift, 0>;
174def : ReadAdvance<ReadShift32, 0>;
175def : ReadAdvance<ReadIDiv, 0>;
176def : ReadAdvance<ReadIDiv32, 0>;
177def : ReadAdvance<ReadIMul, 0>;
178def : ReadAdvance<ReadIMul32, 0>;
179def : ReadAdvance<ReadAtomicWA, 0>;
180def : ReadAdvance<ReadAtomicWD, 0>;
181def : ReadAdvance<ReadAtomicDA, 0>;
182def : ReadAdvance<ReadAtomicDD, 0>;
183def : ReadAdvance<ReadAtomicLDW, 0>;
184def : ReadAdvance<ReadAtomicLDD, 0>;
185def : ReadAdvance<ReadAtomicSTW, 0>;
186def : ReadAdvance<ReadAtomicSTD, 0>;
187def : ReadAdvance<ReadFMemBase, 0>;
188def : ReadAdvance<ReadFALU32, 0>;
189def : ReadAdvance<ReadFALU64, 0>;
190def : ReadAdvance<ReadFMul32, 0>;
191def : ReadAdvance<ReadFMulAdd32, 0>;
192def : ReadAdvance<ReadFMulSub32, 0>;
193def : ReadAdvance<ReadFMul64, 0>;
194def : ReadAdvance<ReadFMulAdd64, 0>;
195def : ReadAdvance<ReadFMulSub64, 0>;
196def : ReadAdvance<ReadFDiv32, 0>;
197def : ReadAdvance<ReadFDiv64, 0>;
198def : ReadAdvance<ReadFSqrt32, 0>;
199def : ReadAdvance<ReadFSqrt64, 0>;
200def : ReadAdvance<ReadFCmp32, 0>;
201def : ReadAdvance<ReadFCmp64, 0>;
202def : ReadAdvance<ReadFSGNJ32, 0>;
203def : ReadAdvance<ReadFSGNJ64, 0>;
204def : ReadAdvance<ReadFMinMax32, 0>;
205def : ReadAdvance<ReadFMinMax64, 0>;
206def : ReadAdvance<ReadFCvtF32ToI32, 0>;
207def : ReadAdvance<ReadFCvtF32ToI64, 0>;
208def : ReadAdvance<ReadFCvtF64ToI32, 0>;
209def : ReadAdvance<ReadFCvtF64ToI64, 0>;
210def : ReadAdvance<ReadFCvtI32ToF32, 0>;
211def : ReadAdvance<ReadFCvtI32ToF64, 0>;
212def : ReadAdvance<ReadFCvtI64ToF32, 0>;
213def : ReadAdvance<ReadFCvtI64ToF64, 0>;
214def : ReadAdvance<ReadFCvtF32ToF64, 0>;
215def : ReadAdvance<ReadFCvtF64ToF32, 0>;
216def : ReadAdvance<ReadFMovF32ToI32, 0>;
217def : ReadAdvance<ReadFMovI32ToF32, 0>;
218def : ReadAdvance<ReadFMovF64ToI64, 0>;
219def : ReadAdvance<ReadFMovI64ToF64, 0>;
220def : ReadAdvance<ReadFClass32, 0>;
221def : ReadAdvance<ReadFClass64, 0>;
222}
223