Skip to content

Commit

Permalink
attempt at clog_2 or 1 (#1975)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielnrn authored Mar 17, 2024
1 parent 9e4e47c commit 188dfcf
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions yxi/axi-calyx/axi-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ def add_read_channel(prog, mem):
name="mem_ref",
bitwidth=mem["width"],
len=mem["size"],
idx_size=clog2(mem["size"]),
idx_size=clog2_or_1(mem["size"]),
is_external=False,
is_ref=True,
)

# according to zipcpu, rready should be registered
rready = read_channel.reg("rready", 1)
curr_addr_internal_mem = read_channel.reg(
"curr_addr_internal_mem", clog2(mem["size"]), is_ref=True
"curr_addr_internal_mem", clog2_or_1(mem["size"]), is_ref=True
)
curr_addr_axi = read_channel.reg("curr_addr_axi", 64, is_ref=True)
# Registed because RLAST is high with laster transfer, not after
Expand Down Expand Up @@ -312,7 +312,7 @@ def add_write_channel(prog, mem):
name="mem_ref",
bitwidth=mem["width"],
len=mem["size"],
idx_size=clog2(mem["size"]),
idx_size=clog2_or_1(mem["size"]),
is_external=False,
is_ref=True,
)
Expand All @@ -322,7 +322,7 @@ def add_write_channel(prog, mem):
w_handshake_occurred = write_channel.reg("w_handshake_occurred", 1)
# internal calyx memory indexing
curr_addr_internal_mem = write_channel.reg(
"curr_addr_internal_mem", clog2(mem["size"]), is_ref=True
"curr_addr_internal_mem", clog2_or_1(mem["size"]), is_ref=True
)
# host indexing, must be 64 bits
curr_addr_axi = write_channel.reg("curr_addr_axi", 64, is_ref=True)
Expand Down Expand Up @@ -520,7 +520,7 @@ def add_main_comp(prog, mems):
# Cells
# Read stuff
curr_addr_internal_mem = wrapper_comp.reg(
f"curr_addr_internal_mem_{mem_name}", clog2(mem["size"])
f"curr_addr_internal_mem_{mem_name}", clog2_or_1(mem["size"])
)
curr_addr_axi = wrapper_comp.reg(f"curr_addr_axi_{mem_name}", 64)

Expand All @@ -533,7 +533,7 @@ def add_main_comp(prog, mems):
name=f"internal_mem_{mem_name}",
bitwidth=mem["width"],
len=mem["size"],
idx_size=clog2(mem["size"]),
idx_size=clog2_or_1(mem["size"]),
)


Expand Down Expand Up @@ -674,6 +674,10 @@ def clog2(x):
raise ValueError("x must be positive")
return (x - 1).bit_length()

def clog2_or_1(x):
"""Ceiling log2 or 1 if clog2(x) == 0"""
return max(1, clog2(x))


def build():
prog = Builder()
Expand Down

0 comments on commit 188dfcf

Please sign in to comment.