From 1bf29821ee5143ef8ba51e3dc0a92002c8a9d3e0 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 16 Jun 2019 07:07:32 +0100 Subject: [PATCH] create FPNumBaseRecord --- src/ieee754/fpcommon/denorm.py | 4 ++-- src/ieee754/fpcommon/fpbase.py | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/ieee754/fpcommon/denorm.py b/src/ieee754/fpcommon/denorm.py index 2653e335..44d5461a 100644 --- a/src/ieee754/fpcommon/denorm.py +++ b/src/ieee754/fpcommon/denorm.py @@ -6,8 +6,8 @@ from nmigen import Module, Signal, Elaboratable from nmigen.cli import main, verilog from math import log -from ieee754.fpcommon.fpbase import FPNumIn, FPNumOut, FPNumBase -from ieee754.fpcommon.fpbase import FPState +from ieee754.fpcommon.fpbase import FPNumIn, FPNumOut, FPNumBaseRecord +from ieee754.fpcommon.fpbase import FPState, FPNumBase class FPSCData: diff --git a/src/ieee754/fpcommon/fpbase.py b/src/ieee754/fpcommon/fpbase.py index 198ce036..4889407f 100644 --- a/src/ieee754/fpcommon/fpbase.py +++ b/src/ieee754/fpcommon/fpbase.py @@ -60,7 +60,7 @@ class MultiShift: return res -class FPNumBase: #(Elaboratable): +class FPNumBaseRecord: """ Floating-point Base Number Class """ def __init__(self, width, m_extra=True): @@ -96,6 +96,22 @@ class FPNumBase: #(Elaboratable): self.N127 = Const(-(e_max-1), (e_width, True)) self.N126 = Const(-(e_max-2), (e_width, True)) + def __iter__(self): + yield self.s + yield self.e + yield self.m + + def eq(self, inp): + return [self.s.eq(inp.s), self.e.eq(inp.e), self.m.eq(inp.m)] + + +class FPNumBase(FPNumBaseRecord): # Elaboratable + """ Floating-point Base Number Class + """ + def __init__(self, width, m_extra=True): + FPNumBaseRecord.__init__(self, width, m_extra) + e_width = self.e_width + self.is_nan = Signal(reset_less=True) self.is_zero = Signal(reset_less=True) self.is_inf = Signal(reset_less=True) @@ -145,14 +161,6 @@ class FPNumBase: #(Elaboratable): def _is_denormalised(self): return (self.exp_n126) & (self.m_msbzero) - def __iter__(self): - yield self.s - yield self.e - yield self.m - - def eq(self, inp): - return [self.s.eq(inp.s), self.e.eq(inp.e), self.m.eq(inp.m)] - class FPNumOut(FPNumBase): """ Floating-point Number Class -- 2.30.2