diff --git a/incl/iss/arch/riscv_hart_m_p.h b/incl/iss/arch/riscv_hart_m_p.h index 36d31c9..b50b990 100644 --- a/incl/iss/arch/riscv_hart_m_p.h +++ b/incl/iss/arch/riscv_hart_m_p.h @@ -201,7 +201,7 @@ public: void disass_output(uint64_t pc, const std::string instr) override { CLOG(INFO, disass) << fmt::format("0x{:016x} {:40} [s:0x{:x};c:{}]", - pc, instr, (reg_t)state.mstatus, this->reg.icount); + pc, instr, (reg_t)state.mstatus, this->reg.icount + cycle_offset); }; iss::instrumentation_if *get_instrumentation_if() override { return &instr_if; } diff --git a/incl/iss/arch/riscv_hart_msu_vp.h b/incl/iss/arch/riscv_hart_msu_vp.h index 5ac10f1..196cae5 100644 --- a/incl/iss/arch/riscv_hart_msu_vp.h +++ b/incl/iss/arch/riscv_hart_msu_vp.h @@ -307,7 +307,7 @@ public: void disass_output(uint64_t pc, const std::string instr) override { CLOG(INFO, disass) << fmt::format("0x{:016x} {:40} [p:{};s:0x{:x};c:{}]", - pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->reg.ccount); + pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->reg.ccount + cycle_offset); }; iss::instrumentation_if *get_instrumentation_if() override { return &instr_if; } diff --git a/incl/iss/arch/riscv_hart_mu_p.h b/incl/iss/arch/riscv_hart_mu_p.h index 99d1803..754ea1c 100644 --- a/incl/iss/arch/riscv_hart_mu_p.h +++ b/incl/iss/arch/riscv_hart_mu_p.h @@ -216,7 +216,7 @@ public: void disass_output(uint64_t pc, const std::string instr) override { CLOG(INFO, disass) << fmt::format("0x{:016x} {:40} [p:{};s:0x{:x};c:{}]", - pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->reg.icount); + pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->reg.icount + cycle_offset); }; iss::instrumentation_if *get_instrumentation_if() override { return &instr_if; } diff --git a/incl/iss/plugin/cycle_estimate.h b/incl/iss/plugin/cycle_estimate.h index 3f35dc7..0c2cc15 100644 --- a/incl/iss/plugin/cycle_estimate.h +++ b/incl/iss/plugin/cycle_estimate.h @@ -49,11 +49,13 @@ class cycle_estimate: public iss::vm_plugin { BEGIN_BF_DECL(instr_desc, uint32_t) BF_FIELD(taken, 24, 8) BF_FIELD(not_taken, 16, 8) - BF_FIELD(size, 0, 16) - instr_desc(uint32_t size, uint32_t taken, uint32_t not_taken): instr_desc() { + BF_FIELD(is_branch, 8, 8) + BF_FIELD(size, 0, 8) + instr_desc(uint32_t size, uint32_t taken, uint32_t not_taken, bool branch): instr_desc() { this->size=size; this->taken=taken; this->not_taken=not_taken; + this->is_branch=branch; } END_BF_DECL(); diff --git a/src/plugin/cycle_estimate.cpp b/src/plugin/cycle_estimate.cpp index d2bcdad..88e275a 100644 --- a/src/plugin/cycle_estimate.cpp +++ b/src/plugin/cycle_estimate.cpp @@ -75,10 +75,14 @@ bool iss::plugin::cycle_estimate::registration(const char* const version, vm_if& auto& name = (*it)["name"]; auto& size = (*it)["size"]; auto& delay = (*it)["delay"]; + auto& branch = (*it)["branch"]; if(delay.IsArray()) { - delays.push_back(instr_desc{size.Get(), delay[0].Get(), delay[1].Get()}); + auto dt = delay[0].Get(); + auto dnt = delay[1].Get(); + delays.push_back(instr_desc{size.Get(), dt, dnt, branch.Get()}); } else if(delay.Is()) { - delays.push_back(instr_desc{size.Get(), delay.Get(), 0}); + auto d = delay.Get(); + delays.push_back(instr_desc{size.Get(), d, d, branch.Get()}); } else throw runtime_error("JSON parse error"); } @@ -103,11 +107,11 @@ bool iss::plugin::cycle_estimate::registration(const char* const version, vm_if& } -void iss::plugin::cycle_estimate::callback(instr_info_t instr_info, exec_info const&) { +void iss::plugin::cycle_estimate::callback(instr_info_t instr_info, exec_info const& exc_info) { assert(arch_instr && "No instrumentation interface available but callback executed"); auto entry = delays[instr_info.instr_id]; - bool taken = (arch_instr->get_next_pc()-arch_instr->get_pc()) != (entry.size/8); - if (taken && entry.taken > 1) + bool taken = exc_info.branch_taken; + if (exc_info.branch_taken && entry.taken > 1) arch_instr->set_curr_instr_cycles(entry.taken); else if (entry.not_taken > 1) arch_instr->set_curr_instr_cycles(entry.not_taken); diff --git a/src/sysc/core_complex.cpp b/src/sysc/core_complex.cpp index c89f61f..8ec288d 100644 --- a/src/sysc/core_complex.cpp +++ b/src/sysc/core_complex.cpp @@ -136,7 +136,8 @@ public: if (!owner->disass_output(pc, instr)) { std::stringstream s; s << "[p:" << lvl[this->reg.PRIV] << ";s:0x" << std::hex << std::setfill('0') - << std::setw(sizeof(reg_t) * 2) << (reg_t)this->state.mstatus << std::dec << ";c:" << this->reg.icount << "]"; + << std::setw(sizeof(reg_t) * 2) << (reg_t)this->state.mstatus << std::dec << ";c:" + << this->reg.icount + this->cycle_offset << "]"; SCCDEBUG(owner->name())<<"disass: " << "0x" << std::setw(16) << std::right << std::setfill('0') << std::hex << pc << "\t\t" << std::setw(40) << std::setfill(' ') << std::left << instr << s.str();