- comb += self.o.z.eq(self.i.z)
- # tot[-1] (MSB) gets set when the sum overflows. shift result down
- with m.If(~self.i.out_do_z):
- with m.If(self.i.tot[-1]):
- comb += [
- self.o.z.m.eq(self.i.tot[4:]),
- self.o.of.m0.eq(self.i.tot[4]),
- self.o.of.guard.eq(self.i.tot[3]),
- self.o.of.round_bit.eq(self.i.tot[2]),
- self.o.of.sticky.eq(self.i.tot[1] | self.i.tot[0]),
- self.o.z.e.eq(self.i.z.e + 1)
- ]
- # tot[-1] (MSB) zero case
- with m.Else():
- comb += [
- self.o.z.m.eq(self.i.tot[3:]),
- self.o.of.m0.eq(self.i.tot[3]),
- self.o.of.guard.eq(self.i.tot[2]),
- self.o.of.round_bit.eq(self.i.tot[1]),
- self.o.of.sticky.eq(self.i.tot[0])
- ]
+ # this works by adding an extra zero LSB if the MSB is *not* set
+ comb += [
+ self.o.z.m.eq(to[4:]),
+ self.o.of.m0.eq(to[4]),
+ self.o.of.guard.eq(to[3]),
+ self.o.of.round_bit.eq(to[2]),
+ # sticky sourced from LSB and shifted if MSB hi, else unshifted
+ self.o.of.sticky.eq(Mux(msb, to[1] | tot[0], to[1]))
+ ]