Skip to content

Commit aff36ac

Browse files
authored
Merge branch 'riscv-software-src:master' into jatin/spike-stf-dockerfile
2 parents c60c37f + 4900b70 commit aff36ac

25 files changed

+2431
-1356
lines changed

core/Inst.cpp

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
// <Inst.cpp> -*- C++ -*-
22

33
#include "Inst.hpp"
4+
#include "rename/RenameData.hpp"
5+
#include "CoreUtils.hpp"
46
#include <unordered_map>
57

68
namespace olympia
79
{
8-
const std::unordered_map<Inst::Status,std::string> Inst::status2String = {
9-
{ Inst::Status::BEFORE_FETCH,"BEFORE_FETCH" },
10-
{ Inst::Status::FETCHED, "FETCHED" },
11-
{ Inst::Status::DECODED, "DECODED" },
12-
{ Inst::Status::RENAMED, "RENAMED" },
13-
{ Inst::Status::DISPATCHED, "DISPATCHED" },
14-
{ Inst::Status::SCHEDULED, "SCHEDULED" },
15-
{ Inst::Status::COMPLETED, "COMPLETED" },
16-
{ Inst::Status::RETIRED, "RETIRED" },
17-
{ Inst::Status::FLUSHED, "FLUSHED" },
18-
{ Inst::Status::UNMOD, "UNMOD" },
19-
{ Inst::Status::FUSED, "FUSED" },
20-
{ Inst::Status::FUSION_GHOST,"FUSION_GHOST" }
21-
};
10+
const std::unordered_map<Inst::Status, std::string> Inst::status2String = {
11+
{Inst::Status::BEFORE_FETCH, "BEFORE_FETCH"},
12+
{Inst::Status::FETCHED, "FETCHED"},
13+
{Inst::Status::DECODED, "DECODED"},
14+
{Inst::Status::RENAMED, "RENAMED"},
15+
{Inst::Status::DISPATCHED, "DISPATCHED"},
16+
{Inst::Status::SCHEDULED, "SCHEDULED"},
17+
{Inst::Status::COMPLETED, "COMPLETED"},
18+
{Inst::Status::RETIRED, "RETIRED"},
19+
{Inst::Status::FLUSHED, "FLUSHED"},
20+
{Inst::Status::UNMOD, "UNMOD"},
21+
{Inst::Status::FUSED, "FUSED"},
22+
{Inst::Status::FUSION_GHOST, "FUSION_GHOST"}};
23+
24+
RenameData::OpInfoWithRegfile::OpInfoWithRegfile(const OpInfoList::value_type & op_info) :
25+
field_value(op_info.field_value),
26+
field_id(op_info.field_id),
27+
reg_file(coreutils::determineRegisterFile(op_info)),
28+
is_x0(field_value == 0 && reg_file == core_types::RF_INTEGER)
29+
{ }
30+
2231

2332
bool isCallInstruction(const mavis::OpcodeInfo::PtrType & opcode_info)
2433
{
@@ -48,6 +57,17 @@ namespace olympia
4857
return false;
4958
}
5059

60+
template<class OpInfoListType>
61+
OpInfoListType getOpcodeInfoWithRegFileInfo(const Inst::OpInfoList & mavis_opcode_info)
62+
{
63+
OpInfoListType op_list;
64+
for (const auto & op : mavis_opcode_info)
65+
{
66+
op_list.emplace_back(op);
67+
}
68+
return op_list;
69+
}
70+
5171
/*!
5272
* \brief Construct an Instruction
5373
* \param opcode_info Mavis Opcode information
@@ -61,7 +81,13 @@ namespace olympia
6181
const InstArchInfo::PtrType & inst_arch_info, const sparta::Clock* clk) :
6282
opcode_info_(opcode_info),
6383
inst_arch_info_(inst_arch_info),
84+
dest_opcode_info_with_reg_file_(
85+
getOpcodeInfoWithRegFileInfo<RenameData::DestOpInfoWithRegfileList>(opcode_info_->getDestOpInfoList())),
86+
src_opcode_info_with_reg_file_(
87+
getOpcodeInfoWithRegFileInfo<RenameData::SrcOpInfoWithRegfileList>(opcode_info_->getSourceOpInfoList())),
6488
is_store_(opcode_info->isInstType(mavis::OpcodeInfo::InstructionTypes::STORE)),
89+
is_load_(opcode_info->isInstType(mavis::OpcodeInfo::InstructionTypes::LOAD)),
90+
is_move_(opcode_info->isInstTypeAnyOf(mavis::OpcodeInfo::InstructionTypes::MOVE)),
6591
is_transfer_(miscutils::isOneOf(inst_arch_info_->getTargetPipe(),
6692
InstArchInfo::TargetPipe::I2F,
6793
InstArchInfo::TargetPipe::F2I)),
@@ -71,6 +97,7 @@ namespace olympia
7197
is_csr_(opcode_info->isInstType(mavis::OpcodeInfo::InstructionTypes::CSR)),
7298
is_return_(isReturnInstruction(opcode_info)),
7399
has_immediate_(opcode_info_->hasImmediate()),
100+
rob_targeted_(getPipe() == InstArchInfo::TargetPipe::ROB),
74101
is_vector_(opcode_info->isInstType(mavis::OpcodeInfo::InstructionTypes::VECTOR)),
75102
is_vector_whole_reg_(
76103
is_vector_ && opcode_info->isInstType(mavis::OpcodeInfo::InstructionTypes::WHOLE)),
@@ -82,8 +109,8 @@ namespace olympia
82109

83110
// Check that instruction is supported
84111
sparta_assert(getPipe() != InstArchInfo::TargetPipe::UNKNOWN,
85-
"Unknown target pipe (execution) for " << getMnemonic());
112+
"Unknown target pipe (execution) for " << getMnemonic());
86113
sparta_assert(getExecuteTime() != 0,
87-
"Unknown execution time (latency) for " << getMnemonic());
114+
"Unknown execution time (latency) for " << getMnemonic());
88115
}
89116
} // namespace olympia

core/Inst.hpp

Lines changed: 100 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "sparta/memory/AddressTypes.hpp"
66
#include "sparta/resources/Scoreboard.hpp"
77
#include "sparta/resources/Queue.hpp"
8+
#include "sparta/resources/Buffer.hpp"
89
#include "sparta/pairs/SpartaKeyPairs.hpp"
910
#include "sparta/simulation/State.hpp"
1011
#include "sparta/utils/SpartaSharedPointer.hpp"
@@ -17,6 +18,7 @@
1718
#include "CoreTypes.hpp"
1819
#include "vector/VectorConfig.hpp"
1920
#include "MiscUtils.hpp"
21+
#include "rename/RenameData.hpp"
2022

2123
#include <cstdint>
2224
#include <cstdlib>
@@ -38,47 +40,12 @@ namespace olympia
3840
class Inst
3941
{
4042
public:
41-
class RenameData
42-
{
43-
public:
44-
// A register consists of its value and its register file.
45-
struct Reg
46-
{
47-
uint32_t val = 0;
48-
core_types::RegFile rf = core_types::RegFile::RF_INVALID;
49-
mavis::InstMetaData::OperandFieldID field_id =
50-
mavis::InstMetaData::OperandFieldID::NONE;
51-
bool is_x0 = false;
52-
};
53-
54-
using RegList = std::vector<Reg>;
55-
56-
void setOriginalDestination(const Reg & destination) { original_dest_ = destination; }
57-
58-
void setDestination(const Reg & destination) { dest_ = destination; }
59-
60-
void setDataReg(const Reg & data_reg) { data_reg_ = data_reg; }
61-
62-
void setSource(const Reg & source) { src_.emplace_back(source); }
63-
64-
const RegList & getSourceList() const { return src_; }
65-
66-
const Reg & getOriginalDestination() const { return original_dest_; }
67-
68-
const Reg & getDestination() const { return dest_; }
69-
70-
const Reg & getDataReg() const { return data_reg_; }
71-
72-
private:
73-
Reg original_dest_;
74-
Reg dest_;
75-
RegList src_;
76-
Reg data_reg_;
77-
};
78-
7943
// Used by Mavis
8044
using PtrType = sparta::SpartaSharedPointer<Inst>;
8145

46+
// Used by Rename, etc
47+
using WeakPtrType = sparta::SpartaWeakPointer<Inst>;
48+
8249
// The modeler needs to alias a type called
8350
// "SpartaPairDefinitionType" to the Pair Definition class of
8451
// itself
@@ -229,12 +196,9 @@ namespace olympia
229196

230197
bool hasTail() const { return has_tail_; }
231198

232-
void setUOpParent(sparta::SpartaWeakPointer<olympia::Inst> & parent_uop)
233-
{
234-
parent_uop_ = parent_uop;
235-
}
199+
void setUOpParent(WeakPtrType & parent_uop) { parent_uop_ = parent_uop; }
236200

237-
sparta::SpartaWeakPointer<olympia::Inst> getUOpParent() { return parent_uop_; }
201+
WeakPtrType getUOpParent() { return parent_uop_; }
238202

239203
// Branch instruction was taken (always set for JAL/JALR)
240204
void setTakenBranch(bool taken) { is_taken_branch_ = taken; }
@@ -252,6 +216,14 @@ namespace olympia
252216

253217
bool isLastInFetchBlock() const { return last_in_fetch_block_; }
254218

219+
// ROB target information
220+
void setTargetROB(bool tgt = true) { rob_targeted_ = tgt; }
221+
222+
bool isTargetROB() const
223+
{
224+
return rob_targeted_;
225+
}
226+
255227
// Opcode information
256228
std::string getMnemonic() const { return opcode_info_->getMnemonic(); }
257229

@@ -272,7 +244,20 @@ namespace olympia
272244
return opcode_info_->getSourceOpInfoList();
273245
}
274246

275-
const OpInfoList & getDestOpInfoList() const { return opcode_info_->getDestOpInfoList(); }
247+
const OpInfoList & getDestOpInfoList() const
248+
{
249+
return opcode_info_->getDestOpInfoList();
250+
}
251+
252+
const RenameData::DestOpInfoWithRegfileList & getDestOpInfoListWithRegfile() const
253+
{
254+
return dest_opcode_info_with_reg_file_;
255+
}
256+
257+
const RenameData::SrcOpInfoWithRegfileList & getSrcOpInfoListWithRegfile() const
258+
{
259+
return src_opcode_info_with_reg_file_;
260+
}
276261

277262
bool hasZeroRegSource() const
278263
{
@@ -284,7 +269,7 @@ namespace olympia
284269
bool hasZeroRegDest() const
285270
{
286271
return std::any_of(getDestOpInfoList().begin(), getDestOpInfoList().end(),
287-
[](const mavis::OperandInfo::Element & elem)
272+
[](const auto & elem)
288273
{ return elem.field_value == 0; });
289274
}
290275

@@ -318,9 +303,57 @@ namespace olympia
318303
}
319304
}
320305

306+
void setDataRegister(RenameData::Reg && reg)
307+
{
308+
if (!reg.op_info.is_x0)
309+
{
310+
getDataRegisterBitMask(reg.op_info.reg_file).set(reg.phys_reg);
311+
}
312+
getRenameData().setDataReg(std::forward<RenameData::Reg>(reg));
313+
}
314+
315+
void setDestRegisterBitWithScoreboardUpdate(const RenameData::Reg & reg,
316+
sparta::Scoreboard* const scoreboard)
317+
{
318+
auto & bitmask = getDestRegisterBitMask(reg.op_info.reg_file);
319+
bitmask.set(reg.phys_reg);
320+
321+
// clear scoreboard for the PRF we are allocating
322+
scoreboard->clearBits(bitmask);
323+
}
324+
325+
void addDestRegister(RenameData::Reg && reg)
326+
{
327+
getRenameData().addDestination(std::forward<RenameData::Reg>(reg));
328+
}
329+
330+
void addDestRegisterWithScoreboardUpdate(RenameData::Reg && reg,
331+
sparta::Scoreboard* const scoreboard)
332+
{
333+
if (!reg.op_info.is_x0)
334+
{
335+
setDestRegisterBitWithScoreboardUpdate(reg, scoreboard);
336+
}
337+
338+
addDestRegister(std::forward<RenameData::Reg>(reg));
339+
}
340+
341+
void addSrcRegister(RenameData::Reg && reg)
342+
{
343+
if (!reg.op_info.is_x0)
344+
{
345+
getSrcRegisterBitMask(reg.op_info.reg_file).set(reg.phys_reg);
346+
}
347+
348+
getRenameData().addSource(std::forward<RenameData::Reg>(reg));
349+
}
350+
351+
321352
// Static instruction information
322353
bool isStoreInst() const { return is_store_; }
323354

355+
bool isLoadInst() const { return is_load_; }
356+
324357
bool isLoadStoreInst() const { return inst_arch_info_->isLoadStore(); }
325358

326359
uint32_t getExecuteTime() const { return inst_arch_info_->getExecutionTime(); }
@@ -357,6 +390,14 @@ namespace olympia
357390

358391
bool isCoF() const { return is_cof_; }
359392

393+
bool isMove() const { return is_move_; }
394+
395+
// Is a load the producer for one or more of this inst's operands?
396+
bool hasLoadProducer() const { return has_load_producer_; }
397+
398+
// This instruction is fed by a load
399+
void setLoadProducer(bool load_producer) { has_load_producer_ = load_producer; }
400+
360401
// Rename information
361402
core_types::RegisterBitMask & getSrcRegisterBitMask(const core_types::RegFile rf)
362403
{
@@ -433,6 +474,11 @@ namespace olympia
433474
mavis::OpcodeInfo::PtrType opcode_info_;
434475
InstArchInfo::PtrType inst_arch_info_;
435476

477+
// Handy list that extends Mavis' opcode info with register
478+
// file type.
479+
RenameData::DestOpInfoWithRegfileList dest_opcode_info_with_reg_file_;
480+
RenameData::SrcOpInfoWithRegfileList src_opcode_info_with_reg_file_;
481+
436482
sparta::memory::addr_t inst_pc_ = 0; // Instruction's PC
437483
sparta::memory::addr_t target_vaddr_ =
438484
0; // Instruction's Target PC (for branches, loads/stores)
@@ -443,6 +489,8 @@ namespace olympia
443489
uint64_t program_id_increment_ = 1;
444490
bool is_speculative_ = false; // Is this instruction soon to be flushed?
445491
const bool is_store_;
492+
const bool is_load_;
493+
const bool is_move_;
446494
const bool is_transfer_; // Is this a transfer instruction (F2I/I2F)
447495
const bool is_branch_;
448496
const bool is_condbranch_;
@@ -453,6 +501,11 @@ namespace olympia
453501
bool is_cof_ = false;
454502
const bool has_immediate_;
455503

504+
// Is this instruction just retired? (Dynamically assigned)
505+
bool rob_targeted_ = false;
506+
507+
bool has_load_producer_ = false;
508+
456509
// Vector
457510
const bool is_vector_;
458511
const bool is_vector_whole_reg_;
@@ -489,7 +542,9 @@ namespace olympia
489542
};
490543

491544
using InstPtr = Inst::PtrType;
545+
using InstWeakPtr = Inst::WeakPtrType;
492546
using InstQueue = sparta::Queue<InstPtr>;
547+
using InstBuffer = sparta::Buffer<InstPtr>;
493548

494549
inline std::ostream & operator<<(std::ostream & os, const Inst::Status & status)
495550
{

core/InstArchInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace olympia
3131
{"vload", InstArchInfo::TargetPipe::VLOAD},
3232
{"vstore", InstArchInfo::TargetPipe::VSTORE},
3333
{"vset", InstArchInfo::TargetPipe::VSET},
34+
{"rob", InstArchInfo::TargetPipe::ROB},
3435
{"sys", InstArchInfo::TargetPipe::SYS},
3536
{"?", InstArchInfo::TargetPipe::UNKNOWN}};
3637

@@ -60,6 +61,7 @@ namespace olympia
6061
{InstArchInfo::TargetPipe::VLOAD, "VLOAD"},
6162
{InstArchInfo::TargetPipe::VSTORE, "VSTORE"},
6263
{InstArchInfo::TargetPipe::VSET, "VSET"},
64+
{InstArchInfo::TargetPipe::ROB, "ROB"},
6365
{InstArchInfo::TargetPipe::SYS, "SYS"},
6466
{InstArchInfo::TargetPipe::UNKNOWN, "?"}};
6567

core/InstArchInfo.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace olympia
6262
VLOAD,
6363
VSTORE,
6464
VSET,
65+
ROB,
6566
SYS,
6667
UNKNOWN
6768
};

0 commit comments

Comments
 (0)