put in (unused) code for SimdShape.__mul__ when both LHS and RHS
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 28 Oct 2021 11:30:55 +0000 (12:30 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 28 Oct 2021 11:30:55 +0000 (12:30 +0100)
are SimdShapes.  this is unused at present, needs review

src/ieee754/part/partsig.py

index baf7f6300eee4000d22e5abae4a7d3ca67e985b6..d5acb6c42adcd68e39db151cd9ee736c78d43844 100644 (file)
@@ -224,12 +224,50 @@ class SimdShape(Shape):
             # wheww, got everything.
             return SimdShape(self.scope,              # same scope
                              width=lane_shapes,       # widths_at_elwid
-                             signed=self.signed,      # same sign
+                             signed=self.signed,      # same sign? hmmm XXX
                              fixed_width=fixed_width) # overall width
         else:
             raise NotImplementedError(
                 f"Multiplying a SimdShape by {type(other)} isn't implemented")
 
+            # TODO (and go over examples, sigh).  this is deliberately *after*
+            # the raise NotImplementedError because it needs review.
+
+            # also probably TODO: potentially the other argument could be
+            # a Shape() not a SimdShape().  sigh.
+
+            # for SimdShape-to-SimdShape multiply, the rules are slightly
+            # different: both sides have to be PRIORITY_FIXED for a
+            # PRIORITY_FIXED result to be returned.  if either (or both)
+            # of the LHS and RHS were given elwidths (lane_shapes != None)
+            # then tough luck: the return result is still PRIORITY_ELWID.
+            # TODO: review that.  it *might* be the case (again, due to
+            # a coincidence of multiply, that when PRIORITY_BOTH is set
+            # it is possible to return a PRIORITY_BOTH result. but..
+            # it is unlikely)
+
+            fixed_width = None
+            lane_shapes = None
+
+            # first, check if this is fixed_width mode.  this is *only*
+            # possible if *both* LHS *and* RHS are PRIORITY_FIXED.
+            if (self.mode_flag == PRIORITY_FIXED and
+                other.mode_flag == PRIORITY_FIXED):
+                fixed_width = self.width * other.width
+            else:
+                # (XXX assume other is SimdShape) - when PRIORITY_ELWID
+                # the result *has* to be a PRIORITY_ELWID (FIXED is *IGNORED*)
+                # use *either* the computed *or* the given lane_shapes
+                lane_shapes = {k: v * other.lane_shapes[k] \
+                                  for k, v in self.lane_shapes}
+
+            # wheww, got everything.
+            return SimdShape(self.scope,              # same scope
+                             width=lane_shapes,       # widths_at_elwid
+                             signed=self.signed,      # same sign? hmmm XXX
+                             fixed_width=fixed_width) # overall width
+
+
     def __rmul__(self, other):
         return self.__mul__(other)