diff --git a/src/ariane.sv b/src/ariane.sv index a932a042ca911408047f81aac477d1b99d94a6e0..3e0591a5d61f1ddf176be5d823cc8e2c757468db 100644 --- a/src/ariane.sv +++ b/src/ariane.sv @@ -281,6 +281,7 @@ module ariane import ariane_pkg::*; #( .fetch_entry_ready_i ( fetch_ready_id_if ), .has_mem_access_o ( has_mem_access_if_verif ), .branch_speculation_o( bsp_if_perf ), + .enable_bp_i ( 1'b0 ), .* ); diff --git a/src/frontend/frontend.sv b/src/frontend/frontend.sv index 991db6561e8205fbc641e80476b390c316ebeb6f..1cb10c1d9d6c618d5819604052574245e2b9e50c 100644 --- a/src/frontend/frontend.sv +++ b/src/frontend/frontend.sv @@ -46,7 +46,9 @@ module frontend import ariane_pkg::*; #( input logic fetch_entry_ready_i, // ID acknowledged this instruction output logic has_mem_access_o, - output logic branch_speculation_o + output logic branch_speculation_o, + + input logic enable_bp_i ); // Instruction Cache Registers, from I$ logic [FETCH_WIDTH-1:0] icache_data_q; @@ -179,7 +181,7 @@ module frontend import ariane_pkg::*; #( 4'b0001: begin ras_pop = 1'b0; ras_push = 1'b0; - if (btb_prediction_shifted[i].valid) begin + if (btb_prediction_shifted[i].valid & enable_bp_i) begin predict_address = btb_prediction_shifted[i].target_address; cf_type[i] = ariane_pkg::JumpR; end @@ -195,26 +197,30 @@ module frontend import ariane_pkg::*; #( // return 4'b0100: begin // make sure to only alter the RAS if we actually consumed the instruction - ras_pop = ras_predict.valid & instr_queue_consumed[i]; ras_push = 1'b0; - predict_address = ras_predict.ra; - cf_type[i] = ariane_pkg::Return; + ras_pop = ras_predict.valid & instr_queue_consumed[i]; + if (enable_bp_i) begin + predict_address = ras_predict.ra; + cf_type[i] = ariane_pkg::Return; + end end // branch prediction 4'b1000: begin ras_pop = 1'b0; ras_push = 1'b0; - // if we have a valid dynamic prediction use it - if (bht_prediction_shifted[i].valid) begin - taken_rvi_cf[i] = rvi_branch[i] & bht_prediction_shifted[i].taken; - taken_rvc_cf[i] = rvc_branch[i] & bht_prediction_shifted[i].taken; - // otherwise default to static prediction - end else begin - // set if immediate is negative - static prediction - taken_rvi_cf[i] = rvi_branch[i] & rvi_imm[i][riscv::VLEN-1]; - taken_rvc_cf[i] = rvc_branch[i] & rvc_imm[i][riscv::VLEN-1]; + if (enable_bp_i) begin + // if we have a valid dynamic prediction use it + if (bht_prediction_shifted[i].valid) begin + taken_rvi_cf[i] = rvi_branch[i] & bht_prediction_shifted[i].taken; + taken_rvc_cf[i] = rvc_branch[i] & bht_prediction_shifted[i].taken; + // otherwise default to static prediction + end else begin + // set if immediate is negative - static prediction + taken_rvi_cf[i] = rvi_branch[i] & rvi_imm[i][riscv::VLEN-1]; + taken_rvc_cf[i] = rvc_branch[i] & rvc_imm[i][riscv::VLEN-1]; + end + if (taken_rvi_cf[i] || taken_rvc_cf[i]) cf_type[i] = ariane_pkg::Branch; end - if (taken_rvi_cf[i] || taken_rvc_cf[i]) cf_type[i] = ariane_pkg::Branch; end default:; // default: $error("Decoded more than one control flow"); @@ -227,7 +233,9 @@ module frontend import ariane_pkg::*; #( end // calculate the jump target address if (taken_rvc_cf[i] || taken_rvi_cf[i]) begin - predict_address = addr[i] + (taken_rvc_cf[i] ? rvc_imm[i] : rvi_imm[i]); + if (rvi_jump[i] || rvc_jump[i] || enable_bp_i) begin + predict_address = addr[i] + (taken_rvc_cf[i] ? rvc_imm[i] : rvi_imm[i]); + end end end end