summaryrefslogtreecommitdiff
path: root/rtl/core/fetch/fetch.sv
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2022-11-10 18:00:43 -0600
committerAlejandro Soto <alejandro@34project.org>2022-11-10 18:00:43 -0600
commit028ab74e28a08982d0ef5fea9cdf0225c7daeac3 (patch)
tree8658fe516c51234797796f56da1ae6682b3107fc /rtl/core/fetch/fetch.sv
parentba5557c0b9096716bf6b1e3d102979ebec82b51a (diff)
Fix fetch discard glitches on flush
Diffstat (limited to 'rtl/core/fetch/fetch.sv')
-rw-r--r--rtl/core/fetch/fetch.sv9
1 files changed, 7 insertions, 2 deletions
diff --git a/rtl/core/fetch/fetch.sv b/rtl/core/fetch/fetch.sv
index 1853ee0..63cb936 100644
--- a/rtl/core/fetch/fetch.sv
+++ b/rtl/core/fetch/fetch.sv
@@ -23,16 +23,19 @@ module core_fetch
);
ptr next_pc, hold_addr, target;
- logic fetched_valid, discard;
+ logic prefetch_ready, fetched_valid, discard, pending, next_pending;
+ assign fetch = prefetch_ready && !discard;
assign flush = branch || prefetch_flush;
assign target = wr_pc ? wr_current[31:2] : branch_target; //TODO: alignment exception
+ assign next_pending = fetch || (pending && !fetched);
assign fetched_valid = fetched && !discard;
core_prefetch #(.ORDER(PREFETCH_ORDER)) prefetch
(
.head(fetch_head),
.fetched(fetched_valid),
+ .fetch(prefetch_ready),
.*
);
@@ -54,10 +57,12 @@ module core_fetch
always_ff @(posedge clk or negedge rst_n)
if(!rst_n) begin
+ pending <= 0;
discard <= 0;
hold_addr <= 0;
end else begin
- discard <= discard ? !fetched : flush && fetch;
+ pending <= next_pending;
+ discard <= next_pending && (discard || flush);
hold_addr <= addr;
end