# 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.
~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)
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
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:
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):
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)
# 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: