[Libre-soc-bugs] [Bug 713] PartitionedSignal enhancement to add partition-context-aware lengths

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed Oct 6 22:03:43 BST 2021


--- Comment #20 from Jacob Lifshay <programmerjake at gmail.com> ---
wip layout demo script:
from collections.abc import Mapping
from pprint import pprint
# stuff to let it run as stand-alone script
class Shape:
    def cast(v):
        if isinstance(v, Shape):
            return v
        assert isinstance(v, int)
        return Shape(v, False)

    def __init__(self, width=1, signed=False):
        self.width = width
        self.signed = signed

    def __repr__(self):
        if self.signed:
            return f"signed({self.width})"
        return f"unsigned({self.width})"

def signed(w):
    return Shape(w, True)

def unsigned(w):
    return Shape(w, False)

def PartitionPoints(pp):
    return pp

# main fn
def layout(elwid, part_counts, lane_shapes):
    if not isinstance(lane_shapes, Mapping):
        lane_shapes = {i: lane_shapes for i in part_counts}
    lane_shapes = {i: Shape.cast(lane_shapes[i]) for i in part_counts}
    signed = lane_shapes[0].signed
    assert all(i.signed == signed for i in lane_shapes.values())
    part_wid = -min(-lane_shapes[i].width // c for i, c in part_counts.items())
    part_count = max(part_counts.values())
    width = part_wid * part_count
    points = {}
    for i, c in part_counts.items():
        def add_p(p):
            points[p] = points.get(p, False) | (elwid == i)
        for start in range(0, part_count, c):
            add_p(start * part_wid) # start of lane
            add_p(start * part_wid + lane_shapes[i].width) # start of padding
    points.pop(0, None)
    points.pop(width, None)
    return (PartitionPoints(points), Shape(width, signed), lane_shapes,
        part_wid, part_count)

part_counts = {
    0: 1,
    1: 1,
    2: 2,
    3: 4,

for i in range(4):
    pprint((i, layout(i, part_counts, unsigned(3))))

for i in range(4):
    l = {0: signed(5), 1: signed(6), 2: signed(12), 3: signed(24)}
    pprint((i, layout(i, part_counts, l)))

You are receiving this mail because:
You are on the CC list for the bug.

More information about the libre-soc-bugs mailing list