From 8cb1ccf1de1ca0166b0c62fcc46d5011df218eb2 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 25 Oct 2021 12:10:46 +0100 Subject: [PATCH] add SimdScope.Shape redirector which switches from scalar to simd behaviour 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 | 5 ++++- src/ieee754/part/simd_scope.py | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/ieee754/part/layout_experiment.py b/src/ieee754/part/layout_experiment.py index 66117b3c..161d5cf5 100644 --- a/src/ieee754/part/layout_experiment.py +++ b/src/ieee754/part/layout_experiment.py @@ -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} diff --git a/src/ieee754/part/simd_scope.py b/src/ieee754/part/simd_scope.py index d64a942d..8e71a1c0 100644 --- a/src/ieee754/part/simd_scope.py +++ b/src/ieee754/part/simd_scope.py @@ -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) -- 2.30.2