summaryrefslogtreecommitdiff
path: root/rtl/core/fetch/fetch.sv
diff options
context:
space:
mode:
Diffstat (limited to 'rtl/core/fetch/fetch.sv')
-rw-r--r--rtl/core/fetch/fetch.sv33
1 files changed, 27 insertions, 6 deletions
diff --git a/rtl/core/fetch/fetch.sv b/rtl/core/fetch/fetch.sv
index e8f4832..a57c679 100644
--- a/rtl/core/fetch/fetch.sv
+++ b/rtl/core/fetch/fetch.sv
@@ -5,6 +5,7 @@ module core_fetch
(
input logic clk,
stall,
+ branch,
flush,
fetched,
input word fetch_data,
@@ -16,19 +17,39 @@ module core_fetch
addr
);
- ptr next_pc;
+ ptr next_pc, head;
+ logic fetched_valid, do_flush, discard;
+
+ assign do_flush = branch | flush;
+ assign fetched_valid = fetched & ~discard;
core_prefetch #(.ORDER(PREFETCH_ORDER)) prefetch
(
+ .flush(do_flush),
+ .fetched(fetched_valid),
.*
);
- always_ff @(posedge clk)
- if(flush)
- addr <= next_pc;
- else if(fetched)
+ always_comb
+ if(branch)
+ head = target;
+ else if(flush)
+ head = next_pc;
+ else
+ head = {30{1'bx}};
+
+ always_ff @(posedge clk) begin
+ if(do_flush)
+ addr <= head;
+ else if(fetched_valid)
addr <= addr + 1;
- initial addr = 0;
+ discard <= discard ? ~fetched : do_flush & fetch;
+ end
+
+ initial begin
+ addr = 0;
+ discard = 0;
+ end
endmodule