Skip to content

Commit

Permalink
wt_icache: Fix for speculative accesses to NI address (#536)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcelo Orenes <movera@princeton.edu>

Co-authored-by: Marcelo Orenes <movera@princeton.edu>
  • Loading branch information
zarubaf and morenes committed Oct 2, 2020
1 parent 9de0800 commit 9650890
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/ariane_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ package ariane_pkg;
logic req; // we request a new word
logic kill_s1; // kill the current request
logic kill_s2; // kill the last request
logic spec; // request is speculative
logic [riscv::VLEN-1:0] vaddr; // 1st cycle: 12 bit index is taken for lookup
} icache_dreq_i_t;

Expand Down
5 changes: 3 additions & 2 deletions src/cache_subsystem/wt_icache.sv
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ end else begin : gen_piton_offset
///////////////////////////////////////////////////////
// main control logic
///////////////////////////////////////////////////////

logic addr_ni;
assign addr_ni = is_inside_nonidempotent_regions(ArianeCfg, areq_i.fetch_paddr);
always_comb begin : p_fsm
// default assignment
state_d = state_q;
Expand Down Expand Up @@ -226,7 +227,7 @@ end else begin : gen_piton_offset
// readout speculatively
cache_rden = cache_en_q;

if (areq_i.fetch_valid) begin
if (areq_i.fetch_valid && (!dreq_i.spec || !addr_ni) ) begin
// check if we have to flush
if (flush_d) begin
state_d = IDLE;
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/frontend.sv
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ module frontend import ariane_pkg::*; #(
bht_update_t bht_update;
btb_update_t btb_update;

// assert on branch, deassert when resolved
logic speculative_q,speculative_d;
assign speculative_d = (speculative_q && !resolved_branch_i.valid || |is_branch || |is_return || |is_jalr) && !flush_i;
assign icache_dreq_o.spec = speculative_d;

assign bht_update.valid = resolved_branch_i.valid
& (resolved_branch_i.cf_type == ariane_pkg::Branch);
assign bht_update.pc = resolved_branch_i.pc;
Expand Down Expand Up @@ -328,6 +333,7 @@ module frontend import ariane_pkg::*; #(
if (!rst_ni) begin
npc_rst_load_q <= 1'b1;
npc_q <= '0;
speculative_q <= '0;
icache_data_q <= '0;
icache_valid_q <= 1'b0;
icache_vaddr_q <= 'b0;
Expand All @@ -337,6 +343,7 @@ module frontend import ariane_pkg::*; #(
end else begin
npc_rst_load_q <= 1'b0;
npc_q <= npc_d;
speculative_q <= speculative_d;
icache_valid_q <= icache_dreq_i.valid;
if (icache_dreq_i.valid) begin
icache_data_q <= icache_data;
Expand Down

0 comments on commit 9650890

Please sign in to comment.