Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to unordered_map to model memory in ILAtor #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/target-sc/ilator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,17 @@ bool Ilator::GenerateGlobalHeader(const std::string& dir) {
"#include <systemc.h>\n"
#ifdef ILATOR_PRECISE_MEM
"#include <map>\n"
"#include <unordered_map>\n"
#else
"#include <unordered_map>\n"
#endif
// add a customized hash function for unordered map
"struct MemAddrHashFunc {{\n"
" std::size_t operator() (int const& addr) const noexcept {{\n"
" return addr;\n"
" }}\n"
"}};\n"

"SC_MODULE({project}) {{\n"
// " extern int instr_cntr;\n"
" std::ofstream instr_log;\n"
Expand Down Expand Up @@ -840,7 +848,11 @@ std::string Ilator::GetCxxType(const SortPtr& sort) {
ILA_ASSERT(sort->is_mem());
#ifdef ILATOR_PRECISE_MEM
return fmt::format(
"std::map<sc_biguint<{addr_width}>, sc_biguint<{data_width}>>",
// "std::map<sc_biguint<{addr_width}>, sc_biguint<{data_width}>>",
// try to switch to unordered_map for memory type to improve access speed.
// sc_biguint seems unhashable
// "std::unordered_map<sc_biguint<{addr_width}>, sc_biguint<{data_width}>>",
"std::unordered_map<int, sc_biguint<{data_width}>, MemAddrHashFunc>",
fmt::arg("addr_width", sort->addr_width()),
fmt::arg("data_width", sort->data_width()));
#else
Expand Down
5 changes: 3 additions & 2 deletions src/target-sc/ilator_dfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Ilator::DfsOpMemory(const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut) {
if (auto uid = asthub::GetUidExprOp(expr); uid == AstUidExprOp::kStore) {
static const char* kMemStoreTemplate =
#ifdef ILATOR_PRECISE_MEM
"tmp_memory[{address}] = {data};\n";
"tmp_memory[{address}.to_int()] = {data};\n";
#else
"tmp_memory[{address}.to_int()] = {data}.to_int();\n";
#endif
Expand Down Expand Up @@ -156,7 +156,8 @@ void Ilator::DfsOpSpecial(const ExprPtr& expr, StrBuff& buff, ExprVarMap& lut) {
fmt::arg("memory_source", LookUp(expr->arg(0), lut)),
fmt::arg("address", LookUp(expr->arg(1), lut)),
#ifdef ILATOR_PRECISE_MEM
fmt::arg("mem_suffix", "")
// fmt::arg("mem_suffix", "")
fmt::arg("mem_suffix", ".to_int()")
#else
fmt::arg("mem_suffix", ".to_int()")
#endif
Expand Down