Skip to content

Commit

Permalink
Merge pull request #1684 from riscv-software-src/simplify-zicfilp
Browse files Browse the repository at this point in the history
Avoid checking ELP before every instruction fetch
  • Loading branch information
aswaterman committed May 31, 2024
2 parents 3a70f84 + 7595995 commit 00dfa28
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions riscv/execute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ void processor_t::step(size_t n)
{
take_pending_interrupt();

check_if_lpad_required();

if (unlikely(slow_path()))
{
// Main simulation loop, slow path.
Expand Down Expand Up @@ -280,7 +282,6 @@ void processor_t::step(size_t n)

in_wfi = false;
insn_fetch_t fetch = mmu->load_insn(pc);
execute_insn_prehook(fetch.insn);
if (debug && !state.serialized)
disasm(fetch.insn);
pc = execute_insn_logged(this, pc, fetch);
Expand All @@ -292,7 +293,6 @@ void processor_t::step(size_t n)
// Main simulation loop, fast path.
for (auto ic_entry = _mmu->access_icache(pc); ; ) {
auto fetch = ic_entry->data;
execute_insn_prehook(fetch.insn);
pc = execute_insn_fast(this, pc, fetch);
ic_entry = ic_entry->next;
if (unlikely(ic_entry->tag != pc))
Expand Down
1 change: 1 addition & 0 deletions riscv/insns/c_jalr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ WRITE_REG(X_RA, tmp);

if (ZICFILP_xLPE(STATE.v, STATE.prv)) {
STATE.elp = ZICFILP_IS_LP_EXPECTED(insn.rvc_rs1());
serialize();
}
1 change: 1 addition & 0 deletions riscv/insns/c_jr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ set_pc(RVC_RS1 & ~reg_t(1));

if (ZICFILP_xLPE(STATE.v, STATE.prv)) {
STATE.elp = ZICFILP_IS_LP_EXPECTED(insn.rvc_rs1());
serialize();
}
1 change: 1 addition & 0 deletions riscv/insns/jalr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ WRITE_RD(tmp);

if (ZICFILP_xLPE(STATE.v, STATE.prv)) {
STATE.elp = ZICFILP_IS_LP_EXPECTED(insn.rs1());
serialize();
}
16 changes: 5 additions & 11 deletions riscv/processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ processor_t::~processor_t()
delete disassembler;
}

static void zicfilp_check_if_lpad_required(const elp_t elp, insn_t insn)
{
if (unlikely(elp == elp_t::LP_EXPECTED)) {
// also see riscv/lpad.h for more checks performed
software_check((insn.bits() & MASK_LPAD) == MATCH_LPAD, LANDING_PAD_FAULT);
}
}

static void bad_option_string(const char *option, const char *value,
const char *msg)
{
Expand Down Expand Up @@ -991,10 +983,12 @@ const char* processor_t::get_symbol(uint64_t addr)
return sim->get_symbol(addr);
}

void processor_t::execute_insn_prehook(insn_t insn)
void processor_t::check_if_lpad_required()
{
if (extension_enabled(EXT_ZICFILP)) {
zicfilp_check_if_lpad_required(state.elp, insn);
if (unlikely(state.elp == elp_t::LP_EXPECTED)) {
// also see insns/lpad.h for more checks performed
insn_fetch_t fetch = mmu->load_insn(state.pc);
software_check((fetch.insn.bits() & MASK_LPAD) == MATCH_LPAD, LANDING_PAD_FAULT);
}
}

Expand Down
2 changes: 1 addition & 1 deletion riscv/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class processor_t : public abstract_device_t
void clear_waiting_for_interrupt() { in_wfi = false; };
bool is_waiting_for_interrupt() { return in_wfi; };

void execute_insn_prehook(insn_t insn);
void check_if_lpad_required();

private:
const isa_parser_t * const isa;
Expand Down

0 comments on commit 00dfa28

Please sign in to comment.