From 9ccd597d9d9c28599343b1a1f2e6c45b24688d36 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 2 Oct 2021 18:17:19 +0100 Subject: [PATCH] add PartitionedAll operator, based on PartitionedBase --- src/ieee754/part_bits/all.py | 69 +++++++++++++++++++ .../part_cmp/experiments/eq_combiner.py | 4 ++ 2 files changed, 73 insertions(+) create mode 100644 src/ieee754/part_bits/all.py diff --git a/src/ieee754/part_bits/all.py b/src/ieee754/part_bits/all.py new file mode 100644 index 00000000..94c97633 --- /dev/null +++ b/src/ieee754/part_bits/all.py @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# See Notices.txt for copyright information + +""" +Copyright (C) 2020 Luke Kenneth Casson Leighton + +dynamically-partitionable "all" class, directly equivalent +to Signal.allb() except SIMD-partitionable + +See: + +* http://libre-riscv.org/3d_gpu/architecture/dynamic_simd/logicops +* http://bugs.libre-riscv.org/show_bug.cgi?id=176 +""" + +from nmigen import Signal, Module, Elaboratable, Cat, C +from nmigen.back.pysim import Simulator, Settle +from nmigen.cli import rtlil +from nmutil.ripple import RippleLSB + +from ieee754.part_mul_add.partpoints import PartitionPoints +from ieee754.part_cmp.experiments.eq_combiner import AllCombiner +from ieee754.part_bits.base import PartitionedBase + + + +class PartitionedAll(PartitionedBase): + + def __init__(self, width, partition_points): + """Create a ``PartitionedAll`` operator + """ + super().__init__(width, partition_points, AllCombiner, "all") + + +if __name__ == "__main__": + + from ieee754.part_mul_add.partpoints import make_partition + m = Module() + mask = Signal(4) + m.submodules.allb = allb = PartitionedAll(16, make_partition(mask, 16)) + + vl = rtlil.convert(allb, ports=allb.ports()) + with open("part_allb.il", "w") as f: + f.write(vl) + + sim = Simulator(m) + + def process(): + yield mask.eq(0b010) + yield allb.a.eq(0x8c14) + yield Settle() + out = yield allb.output + m = yield mask + print("out", bin(out), "mask", bin(m)) + yield mask.eq(0b111) + yield Settle() + out = yield allb.output + m = yield mask + print("out", bin(out), "mask", bin(m)) + yield mask.eq(0b010) + yield Settle() + out = yield allb.output + m = yield mask + print("out", bin(out), "mask", bin(m)) + + sim.add_process(process) + with sim.write_vcd("part_allb.vcd", "part_allb.gtkw", traces=allb.ports()): + sim.run() + diff --git a/src/ieee754/part_cmp/experiments/eq_combiner.py b/src/ieee754/part_cmp/experiments/eq_combiner.py index 7af39f16..7ee6cf8b 100644 --- a/src/ieee754/part_cmp/experiments/eq_combiner.py +++ b/src/ieee754/part_cmp/experiments/eq_combiner.py @@ -64,6 +64,10 @@ class EQCombiner(Combiner): Combiner.__init__(self, operator.or_, width) +class AllCombiner(Combiner): + def __init__(self, width): + Combiner.__init__(self, operator.and_, width) + class XORCombiner(Combiner): def __init__(self, width): Combiner.__init__(self, operator.xor, width) -- 2.30.2