From 1b88f61734dc279e3ee396fba7f5085dccf2b403 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 24 Sep 2021 14:59:01 +0100 Subject: [PATCH] add first cut at PartitionedSignal "Cat" --- src/ieee754/part_cat/cat.py | 159 +++++++++++++++++++++++++ src/ieee754/part_mul_add/partpoints.py | 23 ++++ 2 files changed, 182 insertions(+) create mode 100644 src/ieee754/part_cat/cat.py diff --git a/src/ieee754/part_cat/cat.py b/src/ieee754/part_cat/cat.py new file mode 100644 index 00000000..aceafbb1 --- /dev/null +++ b/src/ieee754/part_cat/cat.py @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# See Notices.txt for copyright information + +""" +Copyright (C) 2021 Luke Kenneth Casson Leighton + +dynamically-partitionable "cat" class, directly equivalent +to nmigen Cat + +See: + +* http://libre-riscv.org/3d_gpu/architecture/dynamic_simd/cat +* http://bugs.libre-riscv.org/show_bug.cgi?id=707 + +m.Switch() +for pbits cases: 0b000 to 0b111 + output = [] + # set up some yielders which will retain where they each got to + # then when called below in the inner nested loop they give + # the relevant sequential chunk + yielders = [Yielder(a), Yielder(b), ....] + runlist = split pbits into runs of zeros + for y in yielders: # for each signal a b c d ... + for i in runlist: # for each partition + for _ in range(i)+1: # for the length of each partition + thing = yield from y # grab sequential chunks + output.append(thing) + with m.Case(pbits): + comb += out.eq(Cat(*output) + +""" + +from nmigen import Signal, Module, Elaboratable, Cat, C +from nmigen.back.pysim import Simulator, Settle + +from ieee754.part_mul_add.partpoints import PartitionPoints +from ieee754.part.partsig import PartitionedSignal +from ieee754.part.test.test_partsig import create_simulator + + + +def get_runlengths(pbit, size): + res = [] + count = 1 + # identify where the 1s are, which indicates "start of a new partition" + # we want a list of the lengths of all partitions + for i in range(size): + if pbit & (1<