z1 = self.o.z
print ("z1", z1.width, z1.rmw, z1.e_width, z1.e_start, z1.e_end)
- # set sign
- m.d.comb += self.o.z.s.eq(a1.s)
-
# intermediaries
exp_sub_n126 = Signal((a1.e_width, True), reset_less=True)
exp_gt127 = Signal(reset_less=True)
# if a range outside z's min range (-126)
with m.Elif(exp_sub_n126 < 0):
+ m.d.comb += self.o.z.s.eq(a1.s)
m.d.comb += self.o.z.e.eq(a1.e)
m.d.comb += self.o.z.m.eq(a1.m[-self.o.z.rmw-1:])
m.d.comb += self.o.of.guard.eq(a1.m[-self.o.z.rmw-2])
m.d.comb += self.o.of.round_bit.eq(a1.m[-self.o.z.rmw-3])
m.d.comb += self.o.of.sticky.eq(a1.m[:-self.o.z.rmw-3] != 0)
+ m.d.comb += self.o.of.m0.eq(self.o.z.m[0])
# if a is inf return inf
with m.Elif(a1.is_inf):
# if a mantissa greater than 127, return inf
with m.Elif(exp_gt127):
+ print ("inf", self.o.z.inf(a1.s))
m.d.comb += self.o.z.inf(a1.s)
m.d.comb += self.o.out_do_z.eq(1)
# ok after all that, anything else should fit fine (whew)
with m.Else():
- m.d.comb += self.o.z.e.eq(a1.e)
print ("alen", a1.e_start, z1.fp.N126, N126)
print ("m1", self.o.z.rmw, a1.m[-self.o.z.rmw-1:])
m.d.comb += self.o.z.create(a1.s, a1.e, a1.m[-self.o.z.rmw-1:])
def create(self, s, e, m):
""" creates a value from sign / exponent / mantissa
- bias is added here, to the exponent
+ bias is added here, to the exponent.
+
+ NOTE: order is important, because e_start/e_end can be
+ a bit too long (overwriting s).
"""
return [
- self.v[-1].eq(s), # sign
+ self.v[0:self.e_start].eq(m), # mantissa
self.v[self.e_start:self.e_end].eq(e + self.fp.P127), # (add on bias)
- self.v[0:self.e_start].eq(m) # mantissa
+ self.v[-1].eq(s), # sign
]
def _nan(self, s):