m_width += self.m_extra
else:
self.m_extra = 0
- print (m_width, e_width, e_max, self.rmw, self.m_extra)
+ #print (m_width, e_width, e_max, self.rmw, self.m_extra)
self.m_width = m_width
self.e_width = e_width
self.e_start = self.rmw - 1
a 10-bit number
"""
args = [0] * self.m_extra + [v[0:self.e_start]] # pad with extra zeros
- print ("decode", self.e_end)
+ #print ("decode", self.e_end)
return [self.m.eq(Cat(*args)), # mantissa
self.e.eq(v[self.e_start:self.e_end] - self.P127), # exp
self.s.eq(v[-1]), # sign
class FPADD(FPBase):
- def __init__(self, width):
+ def __init__(self, width, single_cycle=False):
FPBase.__init__(self)
self.width = width
+ self.single_cycle = single_cycle
self.in_a = FPOp(width)
self.in_b = FPOp(width)
self.denormalise(m, b)
# ******
- # align. NOTE: this does *not* do single-cycle multi-shifting,
- # it *STAYS* in the align state until the exponents match
+ # align.
with m.State("align"):
- # exponent of a greater than b: increment b exp, shift b mant
- with m.If(a.e > b.e):
- m.d.sync += b.shift_down()
- # exponent of b greater than a: increment a exp, shift a mant
- with m.Elif(a.e < b.e):
- m.d.sync += a.shift_down()
- # exponents equal: move to next stage.
- with m.Else():
+ if not self.single_cycle:
+ # NOTE: this does *not* do single-cycle multi-shifting,
+ # it *STAYS* in the align state until exponents match
+
+ # exponent of a greater than b: shift b down
+ with m.If(a.e > b.e):
+ m.d.sync += b.shift_down()
+ # exponent of b greater than a: shift a down
+ with m.Elif(a.e < b.e):
+ m.d.sync += a.shift_down()
+ # exponents equal: move to next stage.
+ with m.Else():
+ m.next = "add_0"
+ else:
+ # This one however (single-cycle) will do the shift
+ # in one go.
+
+ ediff = Signal((len(a.e), True))
+ ediffr = Signal((len(a.e), True))
+ m.d.comb += ediff.eq(a.e - b.e)
+ m.d.comb += ediffr.eq(b.e - a.e)
+ with m.If(ediff > 0):
+ m.d.sync += b.shift_down_multi(ediff)
+ # exponent of b greater than a: shift a down
+ with m.Elif(ediff < 0):
+ m.d.sync += a.shift_down_multi(ediffr)
+
m.next = "add_0"
# ******
#yield from check_case(dut, 1, 1, 1)
if __name__ == '__main__':
- dut = FPADD(width=32)
+ dut = FPADD(width=32, single_cycle=True)
run_simulation(dut, testbench(dut), vcd_name="test_add.vcd")