correct FPRSQRT specialcases messy-div-pipe-works
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 25 Jul 2019 08:57:14 +0000 (09:57 +0100)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 25 Jul 2019 13:21:30 +0000 (06:21 -0700)
src/ieee754/fpdiv/specialcases.py

index 932f6b0844b2ef08549fcbf4345ef3f1f6433e2d..75721de27ee9508e06e8b57ea30ef82d3c1673ba 100644 (file)
@@ -130,25 +130,26 @@ class FPDIVSpecialCasesMod(Elaboratable):
 
         with m.If(self.i.ctx.op == 2):  # RSQRT
 
-            # if a is zero return NaN
-            with m.If(a1.is_zero):
+            # if a is NaN return canonical NaN
+            with m.If(a1.is_nan):
                 m.d.comb += self.o.out_do_z.eq(1)
                 m.d.comb += self.o.z.nan(0)
 
-            # -ve number is NaN
+            # if a is +/- zero return +/- INF
+            with m.Elif(a1.is_zero):
+                m.d.comb += self.o.out_do_z.eq(1)
+                # this includes the "weird" case 1/sqrt(-0) == -Inf
+                m.d.comb += self.o.z.inf(a1.s)
+
+            # -ve number is canonical NaN
             with m.Elif(a1.s):
                 m.d.comb += self.o.out_do_z.eq(1)
                 m.d.comb += self.o.z.nan(0)
 
-            # if a is inf return zero
+            # if a is inf return zero (-ve already excluded, above)
             with m.Elif(a1.is_inf):
                 m.d.comb += self.o.out_do_z.eq(1)
-                m.d.comb += self.o.z.zero(sabx)
-
-            # if a is NaN return NaN
-            with m.Elif(a1.is_nan):
-                m.d.comb += self.o.out_do_z.eq(1)
-                m.d.comb += self.o.z.nan(0)
+                m.d.comb += self.o.z.zero(0)
 
             # Denormalised Number checks next, so pass a/b data through
             with m.Else():