diff --git a/src/target-sc/ilator.cc b/src/target-sc/ilator.cc index 4f76ffc93..cb6d95965 100644 --- a/src/target-sc/ilator.cc +++ b/src/target-sc/ilator.cc @@ -574,9 +574,17 @@ bool Ilator::GenerateGlobalHeader(const std::string& dir) { "#include \n" #ifdef ILATOR_PRECISE_MEM "#include \n" + "#include \n" #else "#include \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" @@ -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<{data_width}>>", + // "std::map, 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<{data_width}>>", + "std::unordered_map, MemAddrHashFunc>", fmt::arg("addr_width", sort->addr_width()), fmt::arg("data_width", sort->data_width())); #else diff --git a/src/target-sc/ilator_dfs.cc b/src/target-sc/ilator_dfs.cc index 34d8466a6..7624db274 100644 --- a/src/target-sc/ilator_dfs.cc +++ b/src/target-sc/ilator_dfs.cc @@ -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 @@ -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