frontend_params.py
1 from amaranth import * 2 from amaranth_types import ValueLike 3 4 from coreblocks.params import GenParams 5 6 __all__ = ["FrontendParams"] 7 8 9 class FrontendParams: 10 def __init__(self, gen_params: GenParams): 11 self.gp = gen_params 12 13 def fb_addr(self, pc: ValueLike) -> Value: 14 """Returns the fetch block address of a given PC.""" 15 return Value.cast(pc)[self.gp.fetch_block_bytes_log :] 16 17 def fb_instr_idx(self, pc: ValueLike) -> Value: 18 """Returns the index of an instruction in a fetch block for a given instruction PC.""" 19 return Value.cast(pc)[self.gp.min_instr_width_bytes_log : self.gp.fetch_block_bytes_log] 20 21 def pc_from_fb(self, fb_addr: ValueLike, fb_instr_idx: int | Value) -> Value: 22 """For a given fetch block address and an instruction index, returns the instruction's PC.""" 23 if isinstance(fb_instr_idx, int): 24 fb_instr_idx = C(fb_instr_idx, self.gp.fetch_width_log) 25 assert len(fb_instr_idx) == self.gp.fetch_width_log 26 return Cat(C(0, self.gp.min_instr_width_bytes_log), fb_instr_idx, fb_addr)