OpenASIP  2.0
RV32MicroCodeGenerator.hh
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021-2022 Tampere University.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 /**
19  * @file RV32MicroCodeGenerator.hh
20  *
21  * Declaration of RV32MicroCodeGenerator class.
22  *
23  * @author Kari Hepola 2021-2022 (kari.hepola@tuni.fi)
24  * @note rating: red
25  */
26 
27 #ifndef TTA_RV32_TRANSLATOR_HH
28 #define TTA_RV32_TRANSLATOR_HH
29 
30 
31 #include <string>
32 #include <vector>
33 #include <unordered_map>
34 #include <map>
35 #include <set>
36 
37 #include "MicroCodeGenerator.hh"
39 
40 namespace TTAMachine {
41  class Machine;
42  class Socket;
43  class Bus;
44  class RFPort;
45  class FUPort;
46  class BaseFUPort;
47  class FunctionUnit;
48  class RegisterFile;
49  class Port;
50  class SpecialRegisterPort;
51 }
52 
53 namespace TTAProgram {
54  class Instruction;
55 }
56 
58 class BinaryEncoding;
61 
62 using namespace TTAMachine;
63 using namespace TTAProgram;
64 
65 namespace ProGe {
66 
68 
69 public:
72 
73  void generateRTL(HDLTemplateInstantiator& instantiator,
74  const std::string& fileDst);
75 
76  void setBypassInstructionRegister(const bool& value);
77 
78 
79 private:
80  std::unordered_map<std::string, BaseFUPort*> rs1Ports_;
81  std::unordered_map<std::string, BaseFUPort*> rs2Ports_;
82  std::unordered_map<std::string, BaseFUPort*> rdPorts_;
83  std::unordered_map<std::string, BaseFUPort*> simmPorts_;
84 
85  void initializeOperations();
86 
87  std::unordered_map<Port*, int> sourcePortID_;
88 
89  std::unordered_map<Port*, std::vector<std::string>>
91 
92  void findOperationSources();
93 
94  void generateFUTargetProcess(std::ofstream& stream);
95 
96  void addRs1ForwardingConditions(std::map<std::string, std::string>
97  ops, std::unordered_map<std::string, InstructionBitVector*>
98  (ProGe::RV32MicroCodeGenerator::*instructionFunc)(Port* p1, Port* p2) const,
99  std::ofstream& stream) const;
100 
101  void addRs2ForwardingConditions(std::map<std::string, std::string>
102  ops, std::unordered_map<std::string, InstructionBitVector*>
103  (ProGe::RV32MicroCodeGenerator::*instructionFunc)(Port* p1, Port* p2) const,
104  std::ofstream& stream) const;
105 
106  std::string generateOperationLatencyLogic(HDLTemplateInstantiator&
107  instantiator);
108 
109  std::map<std::string, std::string> rOperations_;
110  std::map<std::string, std::string> iOperations_;
111  std::map<std::string, std::string> sOperations_;
112  std::map<std::string, std::string> bOperations_;
113  std::map<std::string, std::string> ujOperations_;
114 
115 
116  std::set<Port*> operationPorts(
117  const std::unordered_map<std::string, BaseFUPort*>& ports) const;
118 
119  void validateOperations() const;
120 
121  FunctionUnit* mapFunctionUnit(const std::string& operation) const;
122 
123  void addRPorts(const std::string& opName);
124  void addIPorts(const std::string& opName);
125  void addSPorts(const std::string& opName);
126  void addBPorts(const std::string& opName);
127  void addUJPorts(const std::string& opName);
128 
129  void findOperationPorts();
130 
131  void connectRF();
132  void findRF();
133 
134  void findBusWidths();
135 
136  bool findConnectedBusses(Connection& rs1,
137  Connection& rs2, Connection& rd, Connection& simm, const bool& forwarding)
138  const;
139 
140  std::unordered_map<std::string, InstructionBitVector*>
141  constructRInstructions(Port* src1, Port* src2) const;
142  std::unordered_map<std::string, InstructionBitVector*>
143  constructIInstructions(Port* src1, Port* src2) const;
144  std::unordered_map<std::string, InstructionBitVector*>
145  constructSInstructions(Port* src1, Port* src2) const;
146  std::unordered_map<std::string, InstructionBitVector*>
147  constructBInstructions(Port* src1, Port* src2) const;
148  std::unordered_map<std::string, InstructionBitVector*>
149  constructUJInstructions() const;
150 
151  void addBitsToMap(
152  std::unordered_map<std::string, InstructionBitVector*> instructions,
153  const std::map<std::string, std::string> encodings,
154  std::ofstream& stream) const;
155 
156  void generateMap(const std::string& dstDirectory);
157 
158  void generateWrapper(HDLTemplateInstantiator& instantiator,
159  const std::string& fileDst);
160 
161  void generateNOP();
162 
163  void throwOperationNotFoundError(const std::string& op) const;
164 
165  void throwTriggeringPortError(const BaseFUPort* port,
166  const std::string& type) const;
167 
168  void throwInputPortError(const BaseFUPort* port,
169  const std::string& type) const;
170 
171  void throwOutputPortError(const BaseFUPort* port,
172  const std::string& type) const;
173 
174  void throwOperandCountError(
175  const std::string& op, int required, int found) const;
176 
177 
180  std::vector<Bus*> busses_;
181 
183 
188 
193 
194 
199 
204 
205 
209 
211 
212  std::string NOP_;
216  bool eVariant_;
217 
218 };
219 }
220 #endif
TTAProgram
Definition: Estimator.hh:65
ProGe::RV32MicroCodeGenerator::simmPorts_
std::unordered_map< std::string, BaseFUPort * > simmPorts_
Definition: RV32MicroCodeGenerator.hh:83
BinaryEncoding
Definition: BinaryEncoding.hh:61
ProGe::RV32MicroCodeGenerator::bem_
const BinaryEncoding * bem_
Definition: RV32MicroCodeGenerator.hh:179
ProGe::MicroCodeGenerator::Connection
Definition: MicroCodeGenerator.hh:55
MachineConnectivityCheck.hh
HDLTemplateInstantiator
Definition: HDLTemplateInstantiator.hh:45
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
ProGe::RV32MicroCodeGenerator::rs1Bus_
Bus * rs1Bus_
Definition: RV32MicroCodeGenerator.hh:200
ProGe::RV32MicroCodeGenerator
Definition: RV32MicroCodeGenerator.hh:67
ProGe::RV32MicroCodeGenerator::sourceOperationMap_
std::unordered_map< Port *, std::vector< std::string > > sourceOperationMap_
Definition: RV32MicroCodeGenerator.hh:90
ProGe::RV32MicroCodeGenerator::rdBusWidth_
int rdBusWidth_
Definition: RV32MicroCodeGenerator.hh:186
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAMachine::Bus
Definition: Bus.hh:53
TTAMachine::BaseFUPort
Definition: BaseFUPort.hh:44
ProGe::RV32MicroCodeGenerator::rs1RFPort_
RFPort * rs1RFPort_
Definition: RV32MicroCodeGenerator.hh:206
ProGe::RV32MicroCodeGenerator::busses_
std::vector< Bus * > busses_
Definition: RV32MicroCodeGenerator.hh:180
ProGe::RV32MicroCodeGenerator::rdRFPort_
RFPort * rdRFPort_
Definition: RV32MicroCodeGenerator.hh:208
ProGe::RV32MicroCodeGenerator::simmBusStart_
int simmBusStart_
Definition: RV32MicroCodeGenerator.hh:192
ProGe::RV32MicroCodeGenerator::ujOperations_
std::map< std::string, std::string > ujOperations_
Definition: RV32MicroCodeGenerator.hh:113
TTAMachine::RFPort
Definition: RFPort.hh:45
ProGe::RV32MicroCodeGenerator::rs2Bus_
Bus * rs2Bus_
Definition: RV32MicroCodeGenerator.hh:201
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::FUPort
Definition: FUPort.hh:46
ProGe::RV32MicroCodeGenerator::rdRFStart_
int rdRFStart_
Definition: RV32MicroCodeGenerator.hh:197
ProGe::MicroCodeGenerator
Definition: MicroCodeGenerator.hh:46
ProGe::RV32MicroCodeGenerator::sourcePortID_
std::unordered_map< Port *, int > sourcePortID_
Definition: RV32MicroCodeGenerator.hh:87
TTAMachine::SpecialRegisterPort
Definition: SpecialRegisterPort.hh:48
ProGe::RV32MicroCodeGenerator::rs2RFPort_
RFPort * rs2RFPort_
Definition: RV32MicroCodeGenerator.hh:207
ProGe::RV32MicroCodeGenerator::simmBusWidth_
int simmBusWidth_
Definition: RV32MicroCodeGenerator.hh:187
ProGe::RV32MicroCodeGenerator::rs2Ports_
std::unordered_map< std::string, BaseFUPort * > rs2Ports_
Definition: RV32MicroCodeGenerator.hh:81
TTAMachine::Port
Definition: Port.hh:54
ProGe::RV32MicroCodeGenerator::hasForwarding_
bool hasForwarding_
Definition: RV32MicroCodeGenerator.hh:214
ProGe::RV32MicroCodeGenerator::rs1BusStart_
int rs1BusStart_
Definition: RV32MicroCodeGenerator.hh:189
ProGe::RV32MicroCodeGenerator::rdBusStart_
int rdBusStart_
Definition: RV32MicroCodeGenerator.hh:191
TTAMachine::Socket
Definition: Socket.hh:53
ProgramImageGenerator
Definition: ProgramImageGenerator.hh:67
ProGe::RV32MicroCodeGenerator::bypassInstructionRegister_
bool bypassInstructionRegister_
Definition: RV32MicroCodeGenerator.hh:213
ProGe::RV32MicroCodeGenerator::rs2BusStart_
int rs2BusStart_
Definition: RV32MicroCodeGenerator.hh:190
ProGe::RV32MicroCodeGenerator::rdBus_
Bus * rdBus_
Definition: RV32MicroCodeGenerator.hh:202
ProGe::RV32MicroCodeGenerator::rs1Ports_
std::unordered_map< std::string, BaseFUPort * > rs1Ports_
Definition: RV32MicroCodeGenerator.hh:80
ProGe::RV32MicroCodeGenerator::simmBus_
Bus * simmBus_
Definition: RV32MicroCodeGenerator.hh:203
ProGe::RV32MicroCodeGenerator::rOperations_
std::map< std::string, std::string > rOperations_
Definition: RV32MicroCodeGenerator.hh:109
ProGe::RV32MicroCodeGenerator::rs2BusWidth_
int rs2BusWidth_
Definition: RV32MicroCodeGenerator.hh:185
ProGe::RV32MicroCodeGenerator::rdPorts_
std::unordered_map< std::string, BaseFUPort * > rdPorts_
Definition: RV32MicroCodeGenerator.hh:82
ProGe::RV32MicroCodeGenerator::rs2RFStart_
int rs2RFStart_
Definition: RV32MicroCodeGenerator.hh:196
ProGe::RV32MicroCodeGenerator::sOperations_
std::map< std::string, std::string > sOperations_
Definition: RV32MicroCodeGenerator.hh:111
ProGe::RV32MicroCodeGenerator::rs1BusWidth_
int rs1BusWidth_
Definition: RV32MicroCodeGenerator.hh:184
ProGe
Definition: FUGen.hh:54
ProGe::RV32MicroCodeGenerator::RF_
RegisterFile * RF_
Definition: RV32MicroCodeGenerator.hh:182
ProGe::RV32MicroCodeGenerator::NOP_
std::string NOP_
Definition: RV32MicroCodeGenerator.hh:212
ProGe::RV32MicroCodeGenerator::variableLengthOpLatency_
bool variableLengthOpLatency_
Definition: RV32MicroCodeGenerator.hh:215
MicroCodeGenerator.hh
ProGe::RV32MicroCodeGenerator::rs1RFStart_
int rs1RFStart_
Definition: RV32MicroCodeGenerator.hh:195
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
ProGe::RV32MicroCodeGenerator::pig_
ProgramImageGenerator * pig_
Definition: RV32MicroCodeGenerator.hh:210
TTAMachine
Definition: Assembler.hh:48
ProGe::RV32MicroCodeGenerator::machine_
const Machine * machine_
Definition: RV32MicroCodeGenerator.hh:178
ProGe::RV32MicroCodeGenerator::iOperations_
std::map< std::string, std::string > iOperations_
Definition: RV32MicroCodeGenerator.hh:110
ProGe::RV32MicroCodeGenerator::bOperations_
std::map< std::string, std::string > bOperations_
Definition: RV32MicroCodeGenerator.hh:112
ProGe::RV32MicroCodeGenerator::eVariant_
bool eVariant_
Definition: RV32MicroCodeGenerator.hh:216
TTAMachine::Machine
Definition: Machine.hh:73
InstructionBitVector
Definition: InstructionBitVector.hh:50
ProGe::RV32MicroCodeGenerator::simmRFStart_
int simmRFStart_
Definition: RV32MicroCodeGenerator.hh:198