fclass test
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 28 Jul 2019 09:50:26 +0000 (10:50 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 28 Jul 2019 09:50:26 +0000 (10:50 +0100)
src/ieee754/fclass/pipeline.py
src/ieee754/fclass/test/test_fclass_pipe.py
src/ieee754/fpcommon/fpbase.py
src/ieee754/fpcommon/test/fpmux.py

index 348b82344f9ede0697da4ad06afddcf5654b3265..6a3ddb381c145a7f9858afcca9b21ab7a236f4f7 100644 (file)
@@ -72,8 +72,13 @@ class FPClassMod(Elaboratable):
         # FCLASS: work out the "type" of the FP number
 
         finite_nzero = Signal(reset_less=True)
+        msbzero = Signal(reset_less=True)
+        is_sig_nan = Signal(reset_less=True)
+        # XXX use *REAL* mantissa width to detect msb
+        m.d.comb += msbzero.eq(a1.m[a1.rmw-1] == 0) # sigh, 1 extra msb bit
         m.d.comb += finite_nzero.eq(~a1.is_nan & ~a1.is_inf & ~a1.is_zero)
-        subnormal = a1.exp_lt_n126
+        m.d.comb += is_sig_nan.eq(a1.exp_128 & (msbzero) & (~a1.m_zero))
+        subnormal = a1.exp_n127
 
         m.d.comb += self.o.z.eq(Cat(
                     a1.s   & a1.is_inf,                 # | −inf.
@@ -84,8 +89,8 @@ class FPClassMod(Elaboratable):
                     ~a1.s & finite_nzero &  subnormal,  # | +subnormal number.
                     ~a1.s & finite_nzero & ~subnormal,  # | +normal number.
                     ~a1.s & a1.is_inf,                  # | +inf.
-                    a1.is_denormalised,                 # | a signaling NaN.
-                    a1.is_nan & ~a1.is_denormalised))   # | a quiet NaN
+                    is_sig_nan,                         # | a signaling NaN.
+                    a1.is_nan & ~is_sig_nan))           # | a quiet NaN
 
         m.d.comb += self.o.ctx.eq(self.i.ctx)
 
index ec239c4db989a576760baa7601fae33fc9d29be7..8c4726b82378756ef5f488c0e7759a75d9a8690c 100644 (file)
@@ -11,6 +11,9 @@ from sfpy import Float64, Float32, Float16
 def fclass(wid, x):
     x = x.bits
     fmt = FPFormat.standard(wid)
+    print (hex(x), "exp", fmt.get_exponent(x), fmt.emax,
+                    "m", hex(fmt.get_mantissa(x)),
+                    fmt.get_mantissa(x) & (1<<fmt.m_width-1))
     if fmt.is_inf(x):
         if fmt.get_sign(x):
             return 1<<0
@@ -21,7 +24,7 @@ def fclass(wid, x):
             return 1<<3
         else:
             return 1<<4
-    if fmt.get_exponent(x) == fmt.emax:
+    if fmt.get_exponent(x) == fmt.emax and fmt.get_mantissa(x) != 0:
         if fmt.is_nan_signalling(x):
             return 1<<8
         else:
index ef2a065cc6e76a1a1275469e80e3338ca9c2302c..fb1c6d48b6fff9ee011456cf1a4ee26164afea6d 100644 (file)
@@ -119,17 +119,21 @@ class FPFormat:
     def is_nan(self, x):
         """ returns true if x is nan
         """
-        highbit = 1<<self.m_width
+        highbit = 1<<(self.m_width-1)
         return (self.get_exponent(x) == self.emax and
                 self.get_mantissa(x) != 0 and
-                self.get_mantissa(x) & highbit == 0)
+                self.get_mantissa(x) & highbit != 0)
 
     def is_nan_signalling(self, x):
         """ returns true if x is a signalling nan
         """
-        highbit = 1<<self.m_width
-        return (self.get_exponent(x) == self.emax and
-                self.get_mantissa(x) & highbit != 0)
+        highbit = 1<<(self.m_width-1)
+        print ("m", self.get_mantissa(x), self.get_mantissa(x) != 0,
+                self.get_mantissa(x) & highbit)
+
+        return ((self.get_exponent(x) == self.emax) and
+                (self.get_mantissa(x) != 0) and
+                (self.get_mantissa(x) & highbit) == 0)
 
     @property
     def width(self):
@@ -480,6 +484,8 @@ class FPNumBase(FPNumBaseRecord, Elaboratable):
         return self.exp_gt127
 
     def _is_denormalised(self):
+        # XXX NOT to be used for "official" quiet NaN tests!
+        # particularly when the MSB has been extended
         return (self.exp_n126) & (self.m_msbzero)
 
 
index 86f808e1de34a82e669573dc0fa7f43e0b298275..45eb6226a53091e0633711b90f0bf354d2fcaa6c 100644 (file)
@@ -185,7 +185,15 @@ def create_random(num_rows, width, single_op=False, n_vals=10):
                 # f2int
                 #op1 = 0x4dc0
                 #op1 = 0x3b81
-                op1 = 0xfcb6
+                #op1 = 0xfcb6
+
+                # FCLASS
+                #op1 = 0x87d1
+                #op1 = 0x75e
+                #op1 = 0x7f8c
+                #op1 = 0x7c57
+                #op1 = 0xfea8
+                #op1 = 0xfd57
 
                 vals.append((op1,))
             else: