From 94ef0c14aa77ee0f99b3f9fa6b782adb9e051c1a Mon Sep 17 00:00:00 2001 From: Cesar Strauss Date: Sun, 10 Jan 2021 14:47:26 -0300 Subject: [PATCH] Use len(sig) instead of sig.shape()[0] In latest nMigen, Shape is no longer a tuple. On the other hand, len(sig) worked since the last stable nMigen release, so it should not break for anyone. --- src/ieee754/part/partsig.py | 26 +++++++++----------- src/ieee754/part_mul_add/partpoints.py | 2 +- src/ieee754/part_mux/part_mux.py | 2 +- src/ieee754/part_shift/part_shift_dynamic.py | 6 ++--- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/ieee754/part/partsig.py b/src/ieee754/part/partsig.py index df2fee09..53561d4b 100644 --- a/src/ieee754/part/partsig.py +++ b/src/ieee754/part/partsig.py @@ -39,7 +39,7 @@ def applyop(op1, op2, op): class PartitionedSignal: def __init__(self, mask, *args, **kwargs): self.sig = Signal(*args, **kwargs) - width = self.sig.shape()[0] # get signal width + width = len(self.sig) # get signal width # create partition points if isinstance(mask, PartitionPoints): self.partpoints = mask @@ -100,13 +100,11 @@ class PartitionedSignal: op1 = getsig(op1) if isinstance(op2, Const) or isinstance(op2, Signal): scalar = True - shape = op1.shape() - pa = PartitionedScalarShift(shape[0], self.partpoints) + pa = PartitionedScalarShift(len(op1), self.partpoints) else: scalar = False op2 = getsig(op2) - shape = op1.shape() - pa = PartitionedDynamicShift(shape[0], self.partpoints) + pa = PartitionedDynamicShift(len(op1), self.partpoints) setattr(self.m.submodules, self.get_modname('ls'), pa) comb = self.m.d.comb if scalar: @@ -142,8 +140,7 @@ class PartitionedSignal: def add_op(self, op1, op2, carry): op1 = getsig(op1) op2 = getsig(op2) - shape = op1.shape() - pa = PartitionedAdder(shape[0], self.partpoints) + pa = PartitionedAdder(len(op1), self.partpoints) setattr(self.m.submodules, self.get_modname('add'), pa) comb = self.m.d.comb comb += pa.a.eq(op1) @@ -154,8 +151,7 @@ class PartitionedSignal: def sub_op(self, op1, op2, carry=~0): op1 = getsig(op1) op2 = getsig(op2) - shape = op1.shape() - pa = PartitionedAdder(shape[0], self.partpoints) + pa = PartitionedAdder(len(op1), self.partpoints) setattr(self.m.submodules, self.get_modname('add'), pa) comb = self.m.d.comb comb += pa.a.eq(op1) @@ -236,31 +232,31 @@ class PartitionedSignal: return pa.output def __eq__(self, other): - width = self.sig.shape()[0] + width = len(self.sig) return self._compare(width, self, other, "eq", PartitionedEqGtGe.EQ) def __ne__(self, other): - width = self.sig.shape()[0] + width = len(self.sig) eq = self._compare(width, self, other, "eq", PartitionedEqGtGe.EQ) ne = Signal(eq.width) self.m.d.comb += ne.eq(~eq) return ne def __gt__(self, other): - width = self.sig.shape()[0] + width = len(self.sig) return self._compare(width, self, other, "gt", PartitionedEqGtGe.GT) def __lt__(self, other): - width = self.sig.shape()[0] + width = len(self.sig) # swap operands, use gt to do lt return self._compare(width, other, self, "gt", PartitionedEqGtGe.GT) def __ge__(self, other): - width = self.sig.shape()[0] + width = len(self.sig) return self._compare(width, self, other, "ge", PartitionedEqGtGe.GE) def __le__(self, other): - width = self.sig.shape()[0] + width = len(self.sig) # swap operands, use ge to do le return self._compare(width, other, self, "ge", PartitionedEqGtGe.GE) diff --git a/src/ieee754/part_mul_add/partpoints.py b/src/ieee754/part_mul_add/partpoints.py index e138490b..f7fbd2cb 100644 --- a/src/ieee754/part_mul_add/partpoints.py +++ b/src/ieee754/part_mul_add/partpoints.py @@ -15,7 +15,7 @@ def make_partition(mask, width): {8: mask[0], 16: mask[1], 24: mask[2], .... 56: mask[6]} """ ppoints = {} - mlen = mask.shape()[0] + mlen = len(mask) ppos = mlen midx = 0 while ppos < width and midx < mlen: # -1, ignore last bit diff --git a/src/ieee754/part_mux/part_mux.py b/src/ieee754/part_mux/part_mux.py index c354e6c8..ecc6b2c5 100644 --- a/src/ieee754/part_mux/part_mux.py +++ b/src/ieee754/part_mux/part_mux.py @@ -21,7 +21,7 @@ modcount = 0 # global for now def PMux(m, mask, sel, a, b): global modcount modcount += 1 - width = a.sig.shape()[0] # get width + width = len(a.sig) # get width part_pts = make_partition(mask, width) # create partition points pm = PartitionedMux(width, part_pts) m.d.comb += pm.a.eq(a.sig) diff --git a/src/ieee754/part_shift/part_shift_dynamic.py b/src/ieee754/part_shift/part_shift_dynamic.py index eac00bc2..b5738d9d 100644 --- a/src/ieee754/part_shift/part_shift_dynamic.py +++ b/src/ieee754/part_shift/part_shift_dynamic.py @@ -53,7 +53,7 @@ class ShifterMask(Elaboratable): bl.append(bit) # XXX ARGH, really annoying: simulation bug, can't use Cat(*bl). - for j in range(bits.shape()[0]): + for j in range(len(bits)): comb += bits[j].eq(bl[j]) comb += self.mask.eq(C(0, self.mask.shape())) comb += self.mask.eq(Cat(minm, bits) & C(maxm, self.mask.shape())) @@ -160,7 +160,7 @@ class PartitionedDynamicShift(Elaboratable): # the size of the partition varies dynamically. shifter_masks = [] for i in range(len(b_intervals)): - bwid = b_intervals[i].shape()[0] + bwid = len(b_intervals[i]) bitwid = pwid-i if bitwid == 0: shifter_masks.append(C((1<