From 2704f2c1ef7f05d9ab5b93d4510a5ccb5e18e095 Mon Sep 17 00:00:00 2001 From: lekcyjna123 <34948061+lekcyjna123@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:17:21 +0200 Subject: [PATCH] Fix pipeline (#461) --- coreblocks/params/instr.py | 3 +++ coreblocks/structs_common/exception.py | 4 +++- coreblocks/utils/utils.py | 4 ++-- requirements.txt | 2 +- stubs/amaranth/hdl/ast.pyi | 9 ++++++++- stubs/amaranth/hdl/ir.pyi | 2 +- stubs/amaranth/lib/data.pyi | 8 +++----- test/transactions/test_transaction_lib.py | 12 ++++++------ 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/coreblocks/params/instr.py b/coreblocks/params/instr.py index 722bf804b..5e77763fa 100644 --- a/coreblocks/params/instr.py +++ b/coreblocks/params/instr.py @@ -28,6 +28,9 @@ def pack(self) -> Value: def as_value(self): return self.pack() + def shape(self): + return self.as_value().shape() + class RTypeInstr(RISCVInstr): def __init__( diff --git a/coreblocks/structs_common/exception.py b/coreblocks/structs_common/exception.py index 22677fc63..4d23c6461 100644 --- a/coreblocks/structs_common/exception.py +++ b/coreblocks/structs_common/exception.py @@ -68,7 +68,9 @@ def _(cause, rob_id): m.d.comb += should_write.eq(should_update_prioriy(m, current_cause=self.cause, new_cause=cause)) with m.Elif(self.valid): rob_start_idx = self.rob_get_indices(m).start - m.d.comb += should_write.eq((rob_id - rob_start_idx) < (self.rob_id - rob_start_idx)) + m.d.comb += should_write.eq( + (rob_id - rob_start_idx).as_unsigned() < (self.rob_id - rob_start_idx).as_unsigned() + ) with m.Else(): m.d.comb += should_write.eq(1) diff --git a/coreblocks/utils/utils.py b/coreblocks/utils/utils.py index acbe3134e..11a0df1b1 100644 --- a/coreblocks/utils/utils.py +++ b/coreblocks/utils/utils.py @@ -138,7 +138,7 @@ def assign_arg_fields(val: AssignArg) -> Optional[set[str]]: elif isinstance(val, Record): return set(val.fields) elif isinstance(val, data.View): - layout = data.Layout.cast(data.Layout.of(val)) + layout = val.shape() if isinstance(layout, data.StructLayout): return set(k for k, _ in layout) elif isinstance(val, dict): @@ -349,7 +349,7 @@ def flatten_signals(signals: SignalBundle) -> Iterable[Signal]: for x in signals.fields.values(): yield from flatten_signals(x) elif isinstance(signals, data.View): - for x, _ in data.Layout.cast(data.Layout.of(signals)): + for x, _ in signals.shape(): yield from flatten_signals(signals[x]) else: yield signals diff --git a/requirements.txt b/requirements.txt index 1d6449f0a..1bd4e5cc4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ amaranth-yosys==0.10.0.dev46 -git+https://github.com/amaranth-lang/amaranth@f96604f667516ba9fbf125db8dff8b3742f61f1d +git+https://github.com/amaranth-lang/amaranth@ccf7aaf00db54c7647b2f0f0cfdf34835c16fa8f diff --git a/stubs/amaranth/hdl/ast.pyi b/stubs/amaranth/hdl/ast.pyi index 5e2498eca..abb57120c 100644 --- a/stubs/amaranth/hdl/ast.pyi +++ b/stubs/amaranth/hdl/ast.pyi @@ -516,7 +516,14 @@ class ValueCastable: def lowermethod(func): # -> (self: Unknown, *args: Unknown, **kwargs: Unknown) -> Unknown: """Decorator to memoize lowering me""" ... - + + @abstractmethod + def as_value(self) -> Value: + ... + + @abstractmethod + def shape(self) -> ShapeLike: + ... @final diff --git a/stubs/amaranth/hdl/ir.pyi b/stubs/amaranth/hdl/ir.pyi index 4606d4543..f5c7ba509 100644 --- a/stubs/amaranth/hdl/ir.pyi +++ b/stubs/amaranth/hdl/ir.pyi @@ -10,7 +10,7 @@ from coreblocks.utils import HasElaborate __all__ = ["Elaboratable", "DriverConflict", "Fragment", "Instance"] -class Elaboratable(metaclass=ABCMeta): +class Elaboratable(): @abstractmethod def elaborate(self, platform) -> HasElaborate: ... diff --git a/stubs/amaranth/lib/data.pyi b/stubs/amaranth/lib/data.pyi index da041285a..84ea4684f 100644 --- a/stubs/amaranth/lib/data.pyi +++ b/stubs/amaranth/lib/data.pyi @@ -47,11 +47,6 @@ class Layout(ShapeCastable[View[Self]], metaclass=ABCMeta): """Cast a shape-castable object to a layout.""" ... - @staticmethod - def of(obj: View[_T_ShapeCastable]) -> _T_ShapeCastable: - """Extract the layout from a view.""" - ... - @abstractmethod def __iter__(self) -> Iterator[tuple[int | str, Field]]: """Iterate the layout, yielding ``(key, field)`` pairs. Keys may be strings or integers.""" @@ -191,6 +186,9 @@ class View(ValueCastable, Generic[_T_ShapeCastable]): def as_value(self) -> Value: ... + def shape(self) -> Layout: + ... + def eq(self, other: ValueLike) -> Assign: ... diff --git a/test/transactions/test_transaction_lib.py b/test/transactions/test_transaction_lib.py index d9f427934..71491ac62 100644 --- a/test/transactions/test_transaction_lib.py +++ b/test/transactions/test_transaction_lib.py @@ -157,30 +157,30 @@ def random_wait(rand: int): yield from self.tick(random.randrange(rand) + 1) def writer(): - for i in range(test_count): + for cycle in range(test_count): d = random.randrange(2**data_width) a = random.randrange(max_addr) yield from m.write.call(data=d, addr=a) - for i in range(2): + for _ in range(2): yield Settle() data_dict[a] = d yield from random_wait(writer_rand) def reader_req(): - for i in range(test_count): + for cycle in range(test_count): a = random.randrange(max_addr) yield from m.read_req.call(addr=a) - for i in range(1): + for _ in range(1): yield Settle() if safe_writes: d = data_dict[a] read_req_queue.append(d) else: - addr_queue.append((i, a)) + addr_queue.append((cycle, a)) yield from random_wait(reader_req_rand) def reader_resp(): - for i in range(test_count): + for cycle in range(test_count): while not read_req_queue: yield from random_wait(reader_resp_rand) d = read_req_queue.popleft()