add SimdScope.Shape redirector which switches from scalar to simd behaviour
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 25 Oct 2021 11:10:46 +0000 (12:10 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 25 Oct 2021 11:10:46 +0000 (12:10 +0100)
depending on context.

for compatibility with nmigen Shape() the width parameter is passed
through to widths_at_elwid in SimdShape, allowing the layout() function
the opportunity to turn a scalar width into fixed element widths at
all elwids.

src/ieee754/part/layout_experiment.py
src/ieee754/part/simd_scope.py

index 66117b3c49437054e2fedb7b6004966a193ce0c1..161d5cf5449ef31607a81c546577dd54ffce3720 100644 (file)
@@ -113,7 +113,10 @@ def layout(elwid,            # comes from SimdScope constructor
 
     # identify if the lane_shapes is a mapping (dict, etc.)
     # if not, then assume that it is an integer (width) that
-    # needs to be requested across all partitions
+    # needs to be requested across all partitions.
+    # Note: back in SimdScope.Shape(), this is how code that was
+    # formerly scalar can be "converted" to "look like" it is
+    # still scalar, by not altering the width at any of the elwids.
     if not isinstance(lane_shapes, Mapping):
         lane_shapes = {i: lane_shapes for i in vec_el_counts}
 
index d64a942dab74f3a9fb0272dac4d4feac87c6dbd3..8e71a1c0518bf027134fd33eaa9519adba36d908 100644 (file)
@@ -186,8 +186,16 @@ class SimdScope:
             # simd mode.
 
     # XXX TODO
-    def Shape(self): pass
-        #if self.scalar:
+    def Shape(self, width=1, signed=False):
+        if self.scalar:
             # scalar mode, just return nmigen Shape.  THIS IS IMPORTANT.
-        # else
-            # simd mode.
+            return Shape(width, signed)
+        else:
+            # SIMD mode. NOTE: for compatibility with Shape, the width
+            # is assumed to be the widths_at_elwid parameter NOT the
+            # fixed width.  this ensures that code that is converted
+            # straight from scalar to SIMD will have the exact same
+            # width at all elwidths, because layout() detects the integer
+            # case and converts it, preserving the width at all elwidths
+            return SimdShape(self, width=None, signed=signed,
+                                   widths_at_elwid=width)