11from amaranth import *
22from amaranth .lib import enum , wiring
33from amaranth .lib .wiring import In , Out , flipped
4- from amaranth .utils import log2_int
4+ from amaranth .utils import exact_log2
55
66from ..memory import MemoryMap
77
@@ -273,7 +273,7 @@ def memory_map(self, memory_map):
273273 if memory_map .data_width != self .granularity :
274274 raise ValueError (f"Memory map has data width { memory_map .data_width } , which is "
275275 f"not the same as bus interface granularity { self .granularity } " )
276- granularity_bits = log2_int (self .data_width // self .granularity )
276+ granularity_bits = exact_log2 (self .data_width // self .granularity )
277277 effective_addr_width = self .addr_width + granularity_bits
278278 if memory_map .addr_width != max (1 , effective_addr_width ):
279279 raise ValueError (f"Memory map has address width { memory_map .addr_width } , which is "
@@ -318,7 +318,7 @@ def __init__(self, *, addr_width, data_width, granularity=None, features=frozens
318318 super ().__init__ ({"bus" : In (Signature (addr_width = addr_width , data_width = data_width ,
319319 granularity = granularity , features = features ))})
320320 self .bus .memory_map = MemoryMap (
321- addr_width = max (1 , addr_width + log2_int (data_width // granularity )),
321+ addr_width = max (1 , addr_width + exact_log2 (data_width // granularity )),
322322 data_width = granularity , alignment = alignment , name = name )
323323 self ._subs = dict ()
324324
@@ -382,7 +382,7 @@ def elaborate(self, platform):
382382 sub_bus = self ._subs [sub_map ]
383383
384384 m .d .comb += [
385- sub_bus .adr .eq (self .bus .adr << log2_int (sub_ratio )),
385+ sub_bus .adr .eq (self .bus .adr << exact_log2 (sub_ratio )),
386386 sub_bus .dat_w .eq (self .bus .dat_w ),
387387 sub_bus .sel .eq (Cat (sel .replicate (sub_ratio ) for sel in self .bus .sel )),
388388 sub_bus .we .eq (self .bus .we ),
@@ -395,7 +395,7 @@ def elaborate(self, platform):
395395 if hasattr (sub_bus , "bte" ):
396396 m .d .comb += sub_bus .bte .eq (getattr (self .bus , "bte" , BurstTypeExt .LINEAR ))
397397
398- granularity_bits = log2_int (self .bus .data_width // self .bus .granularity )
398+ granularity_bits = exact_log2 (self .bus .data_width // self .bus .granularity )
399399 with m .Case (sub_pat [:- granularity_bits if granularity_bits > 0 else None ]):
400400 m .d .comb += [
401401 sub_bus .cyc .eq (self .bus .cyc ),
0 commit comments