[otbn] Fix logic for detecting branch/jumps at end of loop
The previous code wouldn't trigger if there was a branch that wasn't
taken.
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/hw/ip/otbn/rtl/otbn_controller.sv b/hw/ip/otbn/rtl/otbn_controller.sv
index 400765c..a1dafb7 100644
--- a/hw/ip/otbn/rtl/otbn_controller.sv
+++ b/hw/ip/otbn/rtl/otbn_controller.sv
@@ -136,6 +136,7 @@
logic stall;
logic ispr_stall;
logic mem_stall;
+ logic jump_or_branch;
logic branch_taken;
logic insn_executing;
logic [ImemAddrWidth-1:0] branch_target;
@@ -224,6 +225,9 @@
assign done_complete = (insn_valid_i && insn_dec_shared_i.ecall_insn);
assign done_o = done_complete | err;
+ assign jump_or_branch = (insn_valid_i &
+ (insn_dec_shared_i.branch_insn | insn_dec_shared_i.jump_insn));
+
// Branch taken when there is a valid branch instruction and comparison passes or a valid jump
// instruction (which is always taken)
assign branch_taken = insn_valid_i &
@@ -384,7 +388,7 @@
.loop_jump_addr_o (loop_jump_addr),
.loop_err_o (loop_err),
- .branch_taken_i (branch_taken),
+ .jump_or_branch_i (jump_or_branch),
.otbn_stall_i (stall)
);
diff --git a/hw/ip/otbn/rtl/otbn_loop_controller.sv b/hw/ip/otbn/rtl/otbn_loop_controller.sv
index 0ea8363..49d2beb 100644
--- a/hw/ip/otbn/rtl/otbn_loop_controller.sv
+++ b/hw/ip/otbn/rtl/otbn_loop_controller.sv
@@ -25,7 +25,7 @@
output [ImemAddrWidth-1:0] loop_jump_addr_o,
output loop_err_o,
- input branch_taken_i,
+ input jump_or_branch_i,
input otbn_stall_i
);
// The loop controller has a current loop and then a stack of outer loops, this sets the size of
@@ -118,7 +118,7 @@
assign loop_jump_addr_o = current_loop_q.loop_start;
assign loop_iteration_err = (loop_iterations_i == '0) & loop_start_req_i;
- assign loop_branch_err = at_current_loop_end_insn & branch_taken_i;
+ assign loop_branch_err = at_current_loop_end_insn & jump_or_branch_i;
assign loop_stack_overflow_err = loop_stack_push_req & loop_stack_full;
assign loop_at_end_err = at_current_loop_end_insn & loop_start_req_i;