Skip to content

Commit

Permalink
Merge branch 'master' into lekcyjna/autumn-cleaning-1
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk authored Oct 5, 2023
2 parents b896bfb + 2704f2c commit e63127f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
3 changes: 3 additions & 0 deletions coreblocks/params/instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
4 changes: 3 additions & 1 deletion coreblocks/structs_common/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions coreblocks/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion stubs/amaranth/hdl/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stubs/amaranth/hdl/ir.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
...
Expand Down
8 changes: 3 additions & 5 deletions stubs/amaranth/lib/data.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
...

Expand Down
12 changes: 6 additions & 6 deletions test/transactions/test_transaction_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e63127f

Please sign in to comment.