remove Shape, signed and unsigned from layout experiment,
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 10 Oct 2021 13:35:05 +0000 (14:35 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 10 Oct 2021 13:35:05 +0000 (14:35 +0100)
idea is to sub-class from ast.Shape() and therefore that provides
the full and complete understanding and specification of signed,
not layout()

src/ieee754/part/layout_experiment.py

index ec57083f3681bdf3c292c55ef0fd504e9cd3440e..e60953e7e887d16c15f3be54a8a19ed30634795c 100644 (file)
@@ -7,41 +7,16 @@ Links: https://bugs.libre-soc.org/show_bug.cgi?id=713#c20
 
 from collections.abc import Mapping
 from pprint import pprint
-# stuff to let it run as stand-alone script
-class Shape:
-    @staticmethod
-    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)
 
+# stuff to let it run as stand-alone script
 def PartitionPoints(pp):
     return pp
 
 # main fn
-def layout(elwid, part_counts, lane_shapes):
+def layout(elwid, signed, 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_wid = -min(-lane_shapes[i] // c for i, c in part_counts.items())
     part_count = max(part_counts.values())
     width = part_wid * part_count
     points = {}
@@ -50,10 +25,10 @@ def layout(elwid, part_counts, lane_shapes):
             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
+            add_p(start * part_wid + lane_shapes[i]) # start of padding
     points.pop(0, None)
     points.pop(width, None)
-    return (PartitionPoints(points), Shape(width, signed), lane_shapes,
+    return (PartitionPoints(points), width, lane_shapes,
         part_wid, part_count)
 
 if __name__ == '__main__':
@@ -65,8 +40,8 @@ if __name__ == '__main__':
     }
 
     for i in range(4):
-        pprint((i, layout(i, part_counts, unsigned(3))))
+        pprint((i, layout(i, True, part_counts, 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)))
+        l = {0: 5, 1: 6, 2: 12, 3: 24}
+        pprint((i, layout(i, False, part_counts, l)))