generated from riscv-software-src/template-riscv-code
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
433 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
namespace olympia | ||
{ | ||
class PredictionInput | ||
{ | ||
public: | ||
uint64_t PC; | ||
uint8_t instType; | ||
}; | ||
|
||
class PredictionOutput | ||
{ | ||
public: | ||
bool predDirection; | ||
uint64_t predPC; | ||
}; | ||
|
||
class UpdateInput | ||
{ | ||
public: | ||
uint64_t instrPC; | ||
bool correctedDirection; | ||
uint64_t correctedPC; | ||
}; | ||
|
||
enum class branchType { | ||
CONDITIONAL_BRANCH, | ||
JMP, | ||
RET | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "Bpu_unit.hpp" | ||
#include "sparta/utils/LogUtils.hpp" | ||
|
||
namespace olympia | ||
{ | ||
Bpu_unit::Bpu_unit(sparta::TreeNode* node, const Bpu_unitParameterSet* p) : | ||
sparta::Unit(node), | ||
ghr_size_(p->ghr_size), | ||
pht_size_(p->pht_size), | ||
pht_ctr_bits_(p->pht_ctr_bits) | ||
{ | ||
in_bpu_predInput_.registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(receivePredictionInput_, PredictionInput)); | ||
in_bpu_sinkCredits_.registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(receiveSinkCredits_, uint32_t)); | ||
in_dut_flush_.registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA()); | ||
|
||
sparta::StartupEvent(node, CREATE_SPARTA_HANDLER()); | ||
} | ||
// function definitions below | ||
void Bpu_unit::sendInitialCredits_() { | ||
out_src_credits_.send(1); | ||
} | ||
void Bpu_unit::receivePredictionInput_(const PredictionInput & pred_input) { | ||
predInput_buffer_.push_back(pred_input); | ||
} | ||
uint8_t Bpu_unit::predictBranch(int idx) { | ||
|
||
} | ||
|
||
PredictionOutput genOutput(uint8_t pred) { | ||
PredictionOutput temp; | ||
temp.predDirection = pred; | ||
} | ||
|
||
void Bpu_unit::receiveSinkCredits_(const uint32_t & credits) { | ||
sink_credits_ += credits; | ||
|
||
// put some mechanism to send prediction output to sink below this | ||
} | ||
void sendPrediction_() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#pragma once | ||
|
||
#include "FlushManager.hpp" | ||
#include "InstGroup.hpp" | ||
#include "BPTypes.hpp" | ||
|
||
#include "sparta/ports/DataPort.hpp" | ||
#include "sparta/events/UniqueEvent.hpp" | ||
#include "sparta/simulation/Unit.hpp" | ||
#include "sparta/simulation/TreeNode.hpp" | ||
#include "sparta/simulation/ParameterSet.hpp" | ||
|
||
#include <vector> | ||
#include <map> | ||
|
||
namespace olympia | ||
{ | ||
class Bpu_unit : public sparta::Unit | ||
{ | ||
public: | ||
class Bpu_unitParameterSet : public sparta::ParameterSet | ||
{ | ||
public: | ||
Bpu_unitParameterSet(sparta::TreeNode *n) : sparta::ParameterSet(n) | ||
{} | ||
|
||
PARAMETER(uint32_t, ghr_size, 1000, "Size of GHR") | ||
PARAMETER(uint32_t, pht_size, 1024, "Size of PHT") | ||
PARAMETER(uint32_t, pht_ctr_bits, 2, "Counter bits of PHT") | ||
}; | ||
Bpu_unit(sparta::TreeNode* node, const Bpu_unitParameterSet* p); | ||
|
||
static constexpr char name[] = "Bpu_unit"; | ||
|
||
private: | ||
// Input port to BPU from source | ||
sparta::DataInPort<PredictionInput> in_bpu_predInput_{&unit_port_set_, "in_bpu_predInput", 1}; | ||
// Output port of BPU to send credit to source | ||
sparta::DataOutPort<uint32_t> out_src_credits_{&unit_port_set_, "out_src_credits"}; | ||
|
||
// output port to sink from BPU | ||
sparta::DataOutPort<PredictionOutput> out_sink_predOutput_{&unit_port_set_, "out_sink_predOutput"}; | ||
// input port of BPU to receive credit from sink | ||
sparta::DataInPort<uint32_t> in_bpu_sinkCredits_{&unit_port_set_, "in_bpu_sinkCredits", sparta::SchedulingPhase::Tick, 0}; | ||
|
||
// for flush | ||
sparta::DataInPort<FlushManager::FlushingCriteria> in_dut_flush_{&unit_port_set_, "in_dut_flush", sparta::SchedulingPhase::Flush, 1}; | ||
|
||
// TODO: put events here | ||
|
||
// send credits from BPU to source | ||
void sendInitialCredits_(); | ||
// receive prediction input from source | ||
void receivePredictionInput_(const PredictionInput & pred_input); | ||
// mechanism to make prediction | ||
uint8_t predictBranch(int idx); | ||
// generate prediction output | ||
PredictionOutput genOutput(uint8_t pred); | ||
// receive credits from sink | ||
void receiveSinkCredits_(const uint32_t & credits); | ||
// send prediction output to sink | ||
void sendPrediction_(); | ||
|
||
uint32_t sink_credits_ = 0; | ||
uint32_t ghr_size_; | ||
uint32_t pht_size_; | ||
uint32_t pht_ctr_bits_; | ||
std::vector<PredictionInput> predInput_buffer_; | ||
|
||
std::map<uint32_t idx, uint8_t ctr> pattern_history_table_; | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
set(PRJ "Bpu_test") | ||
set(EXE "${PRJ}_exec") | ||
|
||
# sanity check | ||
set(TST1, "${PRJ}_test") | ||
#zstf input file | ||
set(TST2, "${PRJ}_stf_test") | ||
|
||
# test args | ||
set(STF ./traces/bpu_basic_test.stf) | ||
|
||
# configuration | ||
set(CFG config/config.yaml) | ||
|
||
project(${PRJ}) | ||
|
||
add_executable(${EXE} Bpu_test.cpp Bpu_unit.cpp src.cpp sink.cpp) | ||
target_include_directories(${EXE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
target_link_libraries(${EXE} core common_test ${STF_LINK_LIBS} mavis SPARTA::sparta) | ||
|
||
|
||
file(CREATE_LINK ${SIM_BASE}/mavis/json ${CMAKE_CURRENT_BINARY_DIR}/mavis_isa_files SYMBOLIC) | ||
file(CREATE_LINK ${SIM_BASE}/arches ${CMAKE_CURRENT_BINARY_DIR}/arches SYMBOLIC) | ||
file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/config ${CMAKE_CURRENT_BINARY_DIR}/config SYMBOLIC) | ||
file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/json ${CMAKE_CURRENT_BINARY_DIR}/json SYMBOLIC) | ||
file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/traces ${CMAKE_CURRENT_BINARY_DIR}/traces SYMBOLIC) | ||
file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/expected_output ${CMAKE_CURRENT_BINARY_DIR}/expected_output SYMBOLIC) | ||
|
||
sparta_named_test(${TST1} ${EXE} tb.out -c ${CFG}) | ||
sparta_named_test(${TST2} ${EXE} tb_stf.out --input_file ${STF} -c ${CFG}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "sink.hpp" | ||
|
||
namespace olympia | ||
{ | ||
sink::sink(sparta::TreeNode* n, const sinkParameterSet* p) : | ||
sparta::Unit(n), | ||
{ | ||
// register handle all ports | ||
in_bpu_predOutput_.registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(receivePrediction_, PredictionOutput)); | ||
} | ||
|
||
void sink::sendCreditsToBPU_() { | ||
out_bpu_sinkCredits_.send(1); | ||
} | ||
|
||
void sink::receivePrediction_(const PredictionOutput & pred_output) { | ||
pred_output_buffer_.push_back(pred_output); | ||
} | ||
} |
Oops, something went wrong.