fix layout() to put in only the number of *requested* vector elements
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 13 Oct 2021 12:25:09 +0000 (13:25 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 13 Oct 2021 12:25:09 +0000 (13:25 +0100)
src/ieee754/part/layout_experiment.py

index 903b74e3cccc64f5c6a5173f93d3d83e3aaa9e89..cba74c91d58b71da0ce3905e465e4dd4fafe6728 100644 (file)
@@ -122,17 +122,18 @@ def layout(elwid, signed, vec_el_counts, lane_shapes=None, fixed_width=None):
             "calculated width not aligned multiples"
         width = fixed_width
         print("part_wid", part_wid, "count", part_count)
-    else:
-        # go with computed width
-        part_wid = cpart_wid
     # create the breakpoints dictionary.
     # do multi-stage version https://bugs.libre-soc.org/show_bug.cgi?id=713#c34
     # https://stackoverflow.com/questions/26367812/
     dpoints = defaultdict(list)  # if empty key, create a (empty) list
     for i, c in vec_el_counts.items():
+        # calculate part_wid based on overall width divided by number
+        # of elements.
+        part_wid = width // c
         def add_p(p):
             dpoints[p].append(i)  # auto-creates list if key non-existent
-        for start in range(0, part_count, c):
+        # for each elwidth, create the required number of vector elements
+        for start in range(c):
             add_p(start * part_wid)  # start of lane
             add_p(start * part_wid + lane_shapes[i])  # start of padding
     # do not need the breakpoints at the very start or the very end