You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
730 B

3 years ago
from typing import Tuple
def branch_unit(
cur_pc: int, imm: int, jalr_sel: int, branch_taken: int, alu_result: int
) -> Tuple[int, int, int, int]: # 输入值为当前pcint立即数jalr信号是否跳转信号alu运算结果(全是int型)
3 years ago
# 输出为pc_plus_imm,pc_plus_4,branch_target,pc_sel(忘了这是啥了,需要回头再看)
branch_taken = int(branch_taken)
jalr_sel = int(jalr_sel)
pc_plus_4 = cur_pc + 4
3 years ago
pc_plus_imm = cur_pc + imm
pc_sel = jalr_sel | (branch_taken & (alu_result % 2))
if jalr_sel == 1:
3 years ago
branch_target = alu_result & (2 ** 32 - 2)
3 years ago
else:
3 years ago
branch_target = cur_pc + imm * 2
return pc_plus_imm, pc_plus_4, branch_target, pc_sel