From 3775b1a4aaecb869540191d21e63f26256c3cbc6 Mon Sep 17 00:00:00 2001 From: Catherine Date: Sat, 25 Nov 2023 01:47:02 +0000 Subject: [PATCH 1/2] Implement RFC 5: Remove `Const.normalize`. Closes #754. --- amaranth/hdl/ast.py | 10 ---------- docs/changes.rst | 11 +++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/amaranth/hdl/ast.py b/amaranth/hdl/ast.py index c698f0c20..af5746522 100644 --- a/amaranth/hdl/ast.py +++ b/amaranth/hdl/ast.py @@ -711,16 +711,6 @@ class Const(Value): """ src_loc = None - # TODO(amaranth-0.5): remove - @staticmethod - @deprecated("instead of `Const.normalize(value, shape)`, use `Const(value, shape).value`") - def normalize(value, shape): - mask = (1 << shape.width) - 1 - value &= mask - if shape.signed and value >> (shape.width - 1): - value |= ~mask - return value - @staticmethod def cast(obj): """Converts ``obj`` to an Amaranth constant. diff --git a/docs/changes.rst b/docs/changes.rst index cafa934db..1d900f5a5 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,17 @@ Changelog This document describes changes to the public interfaces in the Amaranth language and standard library. It does not include most bug fixes or implementation changes. +Version 0.5 (unreleased) +======================== + +Language changes +---------------- + +.. currentmodule:: amaranth.hdl + +* Removed: (deprecated in 0.4) :meth:`Const.normalize`. (`RFC 5`_) + + Version 0.4 =========== From e397f7cd09d532c3de4768dd3394d3f5b31082dc Mon Sep 17 00:00:00 2001 From: Catherine Date: Sat, 25 Nov 2023 01:32:03 +0000 Subject: [PATCH 2/2] Implement RFC 19: Remove `amaranth.lib.scheduler`. Closes #874. --- amaranth/lib/scheduler.py | 67 ------------------------- docs/changes.rst | 8 +++ tests/test_lib_scheduler.py | 99 ------------------------------------- 3 files changed, 8 insertions(+), 166 deletions(-) delete mode 100644 amaranth/lib/scheduler.py delete mode 100644 tests/test_lib_scheduler.py diff --git a/amaranth/lib/scheduler.py b/amaranth/lib/scheduler.py deleted file mode 100644 index 84799b340..000000000 --- a/amaranth/lib/scheduler.py +++ /dev/null @@ -1,67 +0,0 @@ -import warnings - -warnings.warn("the `amaranth.lib.scheduler` module will be removed without a replacement; " - "copy the module into your project to continue using it", - DeprecationWarning, stacklevel=2) - - -from .. import * - - -__all__ = ["RoundRobin"] - - -class RoundRobin(Elaboratable): - """Round-robin scheduler. - - For a given set of requests, the round-robin scheduler will - grant one request. Once it grants a request, if any other - requests are active, it grants the next active request with - a greater number, restarting from zero once it reaches the - highest one. - - Use :class:`EnableInserter` to control when the scheduler - is updated. - - Parameters - ---------- - count : int - Number of requests. - - Attributes - ---------- - requests : Signal(count), in - Set of requests. - grant : Signal(range(count)), out - Number of the granted request. Does not change if there are no - active requests. - valid : Signal(), out - Asserted if grant corresponds to an active request. Deasserted - otherwise, i.e. if no requests are active. - """ - def __init__(self, *, count): - if not isinstance(count, int) or count < 0: - raise ValueError("Count must be a non-negative integer, not {!r}" - .format(count)) - self.count = count - - self.requests = Signal(count) - self.grant = Signal(range(count)) - self.valid = Signal() - - def elaborate(self, platform): - m = Module() - - with m.Switch(self.grant): - for i in range(self.count): - with m.Case(i): - for pred in reversed(range(i)): - with m.If(self.requests[pred]): - m.d.sync += self.grant.eq(pred) - for succ in reversed(range(i + 1, self.count)): - with m.If(self.requests[succ]): - m.d.sync += self.grant.eq(succ) - - m.d.sync += self.valid.eq(self.requests.any()) - - return m diff --git a/docs/changes.rst b/docs/changes.rst index 1d900f5a5..93716d771 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -15,6 +15,14 @@ Language changes * Removed: (deprecated in 0.4) :meth:`Const.normalize`. (`RFC 5`_) +Standard library changes +------------------------ + +.. currentmodule:: amaranth.lib + +* Removed: (deprecated in 0.4) :mod:`amaranth.lib.scheduler`. (`RFC 19`_) + + Version 0.4 =========== diff --git a/tests/test_lib_scheduler.py b/tests/test_lib_scheduler.py deleted file mode 100644 index ebfdc74fb..000000000 --- a/tests/test_lib_scheduler.py +++ /dev/null @@ -1,99 +0,0 @@ -# amaranth: UnusedElaboratable=no - -import unittest -import warnings - -from amaranth.hdl import * -from amaranth.asserts import * -from amaranth.sim import * -with warnings.catch_warnings(): - warnings.filterwarnings(action="ignore", category=DeprecationWarning) - from amaranth.lib.scheduler import * - -from .utils import * - - -class RoundRobinTestCase(unittest.TestCase): - def test_count(self): - dut = RoundRobin(count=32) - self.assertEqual(dut.count, 32) - self.assertEqual(len(dut.requests), 32) - self.assertEqual(len(dut.grant), 5) - - def test_wrong_count(self): - with self.assertRaisesRegex(ValueError, r"Count must be a non-negative integer, not 'foo'"): - dut = RoundRobin(count="foo") - with self.assertRaisesRegex(ValueError, r"Count must be a non-negative integer, not -1"): - dut = RoundRobin(count=-1) - - -class RoundRobinSimulationTestCase(unittest.TestCase): - def test_count_one(self): - dut = RoundRobin(count=1) - sim = Simulator(dut) - def process(): - yield dut.requests.eq(0) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 0) - self.assertFalse((yield dut.valid)) - - yield dut.requests.eq(1) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 0) - self.assertTrue((yield dut.valid)) - sim.add_sync_process(process) - sim.add_clock(1e-6) - with sim.write_vcd("test.vcd"): - sim.run() - - def test_transitions(self): - dut = RoundRobin(count=3) - sim = Simulator(dut) - def process(): - yield dut.requests.eq(0b111) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 1) - self.assertTrue((yield dut.valid)) - - yield dut.requests.eq(0b110) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 2) - self.assertTrue((yield dut.valid)) - - yield dut.requests.eq(0b010) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 1) - self.assertTrue((yield dut.valid)) - - yield dut.requests.eq(0b011) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 0) - self.assertTrue((yield dut.valid)) - - yield dut.requests.eq(0b001) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 0) - self.assertTrue((yield dut.valid)) - - yield dut.requests.eq(0b101) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 2) - self.assertTrue((yield dut.valid)) - - yield dut.requests.eq(0b100) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 2) - self.assertTrue((yield dut.valid)) - - yield dut.requests.eq(0b000) - yield; yield Delay(1e-8) - self.assertFalse((yield dut.valid)) - - yield dut.requests.eq(0b001) - yield; yield Delay(1e-8) - self.assertEqual((yield dut.grant), 0) - self.assertTrue((yield dut.valid)) - sim.add_sync_process(process) - sim.add_clock(1e-6) - with sim.write_vcd("test.vcd"): - sim.run()