1
1
from amaranth import *
2
2
from amaranth .lib import enum , wiring
3
3
from amaranth .lib .wiring import In , Out , flipped
4
- from amaranth .utils import log2_int
4
+ from amaranth .utils import exact_log2
5
5
6
6
from ..memory import MemoryMap
7
7
@@ -273,7 +273,7 @@ def memory_map(self, memory_map):
273
273
if memory_map .data_width != self .granularity :
274
274
raise ValueError (f"Memory map has data width { memory_map .data_width } , which is "
275
275
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 )
277
277
effective_addr_width = self .addr_width + granularity_bits
278
278
if memory_map .addr_width != max (1 , effective_addr_width ):
279
279
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
318
318
super ().__init__ ({"bus" : In (Signature (addr_width = addr_width , data_width = data_width ,
319
319
granularity = granularity , features = features ))})
320
320
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 )),
322
322
data_width = granularity , alignment = alignment , name = name )
323
323
self ._subs = dict ()
324
324
@@ -382,7 +382,7 @@ def elaborate(self, platform):
382
382
sub_bus = self ._subs [sub_map ]
383
383
384
384
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 )),
386
386
sub_bus .dat_w .eq (self .bus .dat_w ),
387
387
sub_bus .sel .eq (Cat (sel .replicate (sub_ratio ) for sel in self .bus .sel )),
388
388
sub_bus .we .eq (self .bus .we ),
@@ -395,7 +395,7 @@ def elaborate(self, platform):
395
395
if hasattr (sub_bus , "bte" ):
396
396
m .d .comb += sub_bus .bte .eq (getattr (self .bus , "bte" , BurstTypeExt .LINEAR ))
397
397
398
- granularity_bits = log2_int (self .bus .data_width // self .bus .granularity )
398
+ granularity_bits = exact_log2 (self .bus .data_width // self .bus .granularity )
399
399
with m .Case (sub_pat [:- granularity_bits if granularity_bits > 0 else None ]):
400
400
m .d .comb += [
401
401
sub_bus .cyc .eq (self .bus .cyc ),
0 commit comments