Skip to content

Commit ea9ead0

Browse files
committed
back.rtlil: set read port init to all-x.
This is an unfortunate necessity needed to fix memory inference regressions introduced when we switched to using v2 cells. A better approach, compatible with RFC 54, will need to be figured out for Amaranth 0.6. Fixes #1011.
1 parent 14929b9 commit ea9ead0

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

amaranth/back/rtlil.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@
2020
})
2121

2222

23+
# Special hack to emit 'x consts for memory read port init.
24+
class Undef:
25+
def __init__(self, width):
26+
self.width = width
27+
28+
2329
def _signed(value):
2430
if isinstance(value, str):
2531
return False
2632
elif isinstance(value, int):
2733
return value < 0
2834
elif isinstance(value, _ast.Const):
2935
return value.shape().signed
36+
elif isinstance(value, Undef):
37+
return False
3038
else:
3139
assert False, f"Invalid constant {value!r}"
3240

@@ -45,6 +53,8 @@ def _const(value):
4553
elif isinstance(value, _ast.Const):
4654
value_twos_compl = value.value & ((1 << len(value)) - 1)
4755
return "{}'{:0{}b}".format(len(value), value_twos_compl, len(value))
56+
elif isinstance(value, Undef):
57+
return f"{value.width}'" + "x" * value.width
4858
else:
4959
assert False, f"Invalid constant {value!r}"
5060

@@ -1070,9 +1080,9 @@ def emit_read_port(self, cell_idx, cell):
10701080
"WIDTH": cell.width,
10711081
"TRANSPARENCY_MASK": _ast.Const(transparency_mask, memory_info.num_write_ports),
10721082
"COLLISION_X_MASK": _ast.Const(0, memory_info.num_write_ports),
1073-
"ARST_VALUE": _ast.Const(0, cell.width),
1074-
"SRST_VALUE": _ast.Const(0, cell.width),
1075-
"INIT_VALUE": _ast.Const(0, cell.width),
1083+
"ARST_VALUE": Undef(cell.width),
1084+
"SRST_VALUE": Undef(cell.width),
1085+
"INIT_VALUE": Undef(cell.width),
10761086
"CE_OVER_SRST": False,
10771087
}
10781088
if isinstance(cell, _nir.AsyncReadPort):

tests/test_back_rtlil.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,9 +1643,9 @@ def test_async_read(self):
16431643
parameter \WIDTH 8
16441644
parameter \TRANSPARENCY_MASK 1'0
16451645
parameter \COLLISION_X_MASK 1'0
1646-
parameter \ARST_VALUE 8'00000000
1647-
parameter \SRST_VALUE 8'00000000
1648-
parameter \INIT_VALUE 8'00000000
1646+
parameter \ARST_VALUE 8'xxxxxxxx
1647+
parameter \SRST_VALUE 8'xxxxxxxx
1648+
parameter \INIT_VALUE 8'xxxxxxxx
16491649
parameter \CE_OVER_SRST 0
16501650
parameter \CLK_ENABLE 0
16511651
parameter \CLK_POLARITY 1
@@ -1725,9 +1725,9 @@ def test_sync_read(self):
17251725
parameter \WIDTH 8
17261726
parameter \TRANSPARENCY_MASK 1'1
17271727
parameter \COLLISION_X_MASK 1'0
1728-
parameter \ARST_VALUE 8'00000000
1729-
parameter \SRST_VALUE 8'00000000
1730-
parameter \INIT_VALUE 8'00000000
1728+
parameter \ARST_VALUE 8'xxxxxxxx
1729+
parameter \SRST_VALUE 8'xxxxxxxx
1730+
parameter \INIT_VALUE 8'xxxxxxxx
17311731
parameter \CE_OVER_SRST 0
17321732
parameter \CLK_ENABLE 1
17331733
parameter \CLK_POLARITY 1

0 commit comments

Comments
 (0)