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.
class PartitionedSignal:
def __init__(self, mask, *args, **kwargs):
self.sig = Signal(*args, **kwargs)
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
# create partition points
if isinstance(mask, PartitionPoints):
self.partpoints = mask
op1 = getsig(op1)
if isinstance(op2, Const) or isinstance(op2, Signal):
scalar = True
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)
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:
setattr(self.m.submodules, self.get_modname('ls'), pa)
comb = self.m.d.comb
if scalar:
def add_op(self, op1, op2, carry):
op1 = getsig(op1)
op2 = getsig(op2)
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)
setattr(self.m.submodules, self.get_modname('add'), pa)
comb = self.m.d.comb
comb += pa.a.eq(op1)
def sub_op(self, op1, op2, carry=~0):
op1 = getsig(op1)
op2 = getsig(op2)
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)
setattr(self.m.submodules, self.get_modname('add'), pa)
comb = self.m.d.comb
comb += pa.a.eq(op1)
return pa.output
def __eq__(self, other):
return pa.output
def __eq__(self, other):
- width = self.sig.shape()[0]
return self._compare(width, self, other, "eq", PartitionedEqGtGe.EQ)
def __ne__(self, other):
return self._compare(width, self, other, "eq", PartitionedEqGtGe.EQ)
def __ne__(self, other):
- width = self.sig.shape()[0]
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):
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]
return self._compare(width, self, other, "gt", PartitionedEqGtGe.GT)
def __lt__(self, other):
return self._compare(width, self, other, "gt", PartitionedEqGtGe.GT)
def __lt__(self, other):
- width = self.sig.shape()[0]
# swap operands, use gt to do lt
return self._compare(width, other, self, "gt", PartitionedEqGtGe.GT)
def __ge__(self, other):
# 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]
return self._compare(width, self, other, "ge", PartitionedEqGtGe.GE)
def __le__(self, other):
return self._compare(width, self, other, "ge", PartitionedEqGtGe.GE)
def __le__(self, other):
- width = self.sig.shape()[0]
# swap operands, use ge to do le
return self._compare(width, other, self, "ge", PartitionedEqGtGe.GE)
# swap operands, use ge to do le
return self._compare(width, other, self, "ge", PartitionedEqGtGe.GE)
{8: mask[0], 16: mask[1], 24: mask[2], .... 56: mask[6]}
"""
ppoints = {}
{8: mask[0], 16: mask[1], 24: mask[2], .... 56: mask[6]}
"""
ppoints = {}
ppos = mlen
midx = 0
while ppos < width and midx < mlen: # -1, ignore last bit
ppos = mlen
midx = 0
while ppos < width and midx < mlen: # -1, ignore last bit
def PMux(m, mask, sel, a, b):
global modcount
modcount += 1
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)
part_pts = make_partition(mask, width) # create partition points
pm = PartitionedMux(width, part_pts)
m.d.comb += pm.a.eq(a.sig)
bl.append(bit)
# XXX ARGH, really annoying: simulation bug, can't use Cat(*bl).
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()))
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()))
# the size of the partition varies dynamically.
shifter_masks = []
for i in range(len(b_intervals)):
# 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<<min_bits)-1, bwid))
bitwid = pwid-i
if bitwid == 0:
shifter_masks.append(C((1<<min_bits)-1, bwid))
shiftbits = math.ceil(math.log2(reswid+1))+1 # hmmm...
print ("partial", reswid, width, intervals[i], shiftbits)
s, e = intervals[i]
shiftbits = math.ceil(math.log2(reswid+1))+1 # hmmm...
print ("partial", reswid, width, intervals[i], shiftbits)
s, e = intervals[i]
- pr = PartialResult(pwid, b_intervals[i].shape()[0], reswid)
+ pr = PartialResult(pwid, len(b_intervals[i]), reswid)
setattr(m.submodules, "pr%d" % i, pr)
comb += pr.gate.eq(gate_br.output[i-1])
comb += pr.b.eq(shift_amounts[i])
setattr(m.submodules, "pr%d" % i, pr)
comb += pr.gate.eq(gate_br.output[i-1])
comb += pr.b.eq(shift_amounts[i])