duplicate FPRound inside fcvt
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 6 Jul 2019 11:15:01 +0000 (12:15 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 6 Jul 2019 11:15:01 +0000 (12:15 +0100)
src/ieee754/fcvt/pipeline.py
src/ieee754/fpcommon/test/fpmux.py

index 632a51c798d353419e90275dda2ceda05ac038cc..129f4de84cd6c916ed1fafe3e1f303f7dc1a475e 100644 (file)
@@ -85,7 +85,7 @@ class FPCVTSpecialCasesMod(Elaboratable):
         # overflow
         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.sticky.eq(a1.m[:-self.o.z.rmw-1] != 0)
         m.d.comb += self.o.of.m0.eq(self.o.z.m[0])
 
         # if a zero, return zero (signed)
@@ -118,10 +118,16 @@ class FPCVTSpecialCasesMod(Elaboratable):
 
         # ok after all that, anything else should fit fine (whew)
         with m.Else():
+            # XXX TODO: this is basically duplicating FPRoundMod. hmmm...
             print ("alen", a1.e_start, z1.fp.N126, N126)
             print ("m1", self.o.z.rmw, a1.m[-self.o.z.rmw-1:])
+            mo = Signal(self.o.z.m_width-1)
+            m.d.comb += mo.eq(a1.m[-self.o.z.rmw-1:])
             with m.If(self.o.of.roundz):
-                m.d.comb += self.o.z.create(a1.s, a1.e, a1.m[-self.o.z.rmw-1:]+1)
+                with m.If((~mo == 0)): # all 1s
+                    m.d.comb += self.o.z.create(a1.s, a1.e+1, mo+1)
+                with m.Else():
+                    m.d.comb += self.o.z.create(a1.s, a1.e, mo+1)
             with m.Else():
                 m.d.comb += self.o.z.create(a1.s, a1.e, a1.m[-self.o.z.rmw-1:])
             m.d.comb += self.o.out_do_z.eq(1)
index c8869dcfb3296d7f7ca1aa489a871b69fe47201b..c604de566db818a2c4a4413eac6cbe0ec2aedb45 100644 (file)
@@ -131,8 +131,10 @@ class InputTestRandom(InputTest):
                     #op1 = 0x889cd8c
                     #op1 = 0xe98646d7
                     #op1 = 0x3340f2a7
-                    #op1 = 0x3a05de50
                     #op1 = 0xfff13f05
+                    #op1 = 0xc53eb000
+                    #op1 = 0x3a05de50
+                    #op1 = 0xc27ff989
                     vals.append((op1,))
                 else:
                     op1 = randint(0, (1<<width)-1)