diff options
| author | Alejandro Soto <alejandro@34project.org> | 2022-09-27 15:12:02 -0600 |
|---|---|---|
| committer | Alejandro Soto <alejandro@34project.org> | 2022-09-27 15:12:02 -0600 |
| commit | 7fe23c697af81c08b69c0b30f1db48ed16493662 (patch) | |
| tree | 63a8678c5da7a974b8be3c455aaec0fadf86f419 /rtl/core/fetch/fetch.sv | |
| parent | 47b3b68aa25fb571a14cba9f5cc788ae500a9e84 (diff) | |
Implement branching in fetch stage
Diffstat (limited to '')
| -rw-r--r-- | rtl/core/fetch/fetch.sv | 33 |
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 |
