From: Luke Kenneth Casson Leighton Date: Mon, 25 Oct 2021 11:10:46 +0000 (+0100) Subject: add SimdScope.Shape redirector which switches from scalar to simd behaviour X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8cb1ccf1de1ca0166b0c62fcc46d5011df218eb2;p=ieee754fpu.git 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. --- 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)