# Copyright (C) Jonathan P Dawson 2013
# 2013-12-12
-from nmigen import Module, Signal, Cat, Const
+from nmigen import Module, Signal, Cat, Const, Elaboratable
from nmigen.cli import main, verilog
from math import log
-from fpbase import FPNumDecode
+from ieee754.fpcommon.fpbase import FPNumDecode
from nmutil.singlepipe import SimpleHandshake, StageChain
-from fpbase import FPState, FPID
+from ieee754.fpcommon.fpbase import FPState, FPID, FPNumBaseRecord
from ieee754.fpcommon.getop import FPADDBaseData
from ieee754.fpcommon.denorm import (FPSCData, FPAddDeNormMod)
-class FPAddSpecialCasesMod:
+class FPAddSpecialCasesMod(Elaboratable):
""" special cases: NaNs, infs, zeros, denormalised
NOTE: some of these are unique to add. see "Special Operations"
https://steve.hollasch.net/cgindex/coding/ieeefloat.html
"""
- def __init__(self, width, id_wid):
- self.width = width
- self.id_wid = id_wid
+ def __init__(self, pspec):
+ self.pspec = pspec
self.i = self.ispec()
self.o = self.ospec()
def ispec(self):
- return FPADDBaseData(self.width, self.id_wid)
+ return FPADDBaseData(self.pspec)
def ospec(self):
- return FPSCData(self.width, self.id_wid)
+ return FPSCData(self.pspec, True)
def setup(self, m, i):
""" links module to inputs and outputs
def elaborate(self, platform):
m = Module()
- m.submodules.sc_out_z = self.o.z
+ #m.submodules.sc_out_z = self.o.z
# decode: XXX really should move to separate stage
- a1 = FPNumDecode(None, self.width)
- b1 = FPNumDecode(None, self.width)
- m.submodules.sc_decode_a = a1
- m.submodules.sc_decode_b = b1
+ width = self.pspec['width']
+ a1 = FPNumBaseRecord(width)
+ b1 = FPNumBaseRecord(width)
+ m.submodules.sc_decode_a = a1 = FPNumDecode(None, a1)
+ m.submodules.sc_decode_b = b1 = FPNumDecode(None, b1)
m.d.comb += [a1.v.eq(self.i.a),
b1.v.eq(self.i.b),
self.o.a.eq(a1),
m.d.comb += self.o.out_do_z.eq(0)
m.d.comb += self.o.oz.eq(self.o.z.v)
- m.d.comb += self.o.mid.eq(self.i.mid)
+ m.d.comb += self.o.ctx.eq(self.i.ctx)
return m
"""
self.mod.setup(m, i, self.out_do_z)
m.d.sync += self.out_z.v.eq(self.mod.out_z.v) # only take the output
- m.d.sync += self.out_z.mid.eq(self.mod.o.mid) # (and mid)
+ m.d.sync += self.out_z.ctx.eq(self.mod.o.ctx) # (and mid)
def action(self, m):
self.idsync(m)
https://steve.hollasch.net/cgindex/coding/ieeefloat.html
"""
- def __init__(self, width, id_wid):
+ def __init__(self, pspec):
FPState.__init__(self, "special_cases")
- self.width = width
- self.id_wid = id_wid
+ self.pspec = pspec
SimpleHandshake.__init__(self, self) # pipe is its own stage
self.out = self.ospec()
def ispec(self):
- return FPADDBaseData(self.width, self.id_wid) # SpecialCases ispec
+ return FPADDBaseData(self.pspec) # SC ispec
def ospec(self):
- return FPSCData(self.width, self.id_wid) # DeNorm ospec
+ return FPSCData(self.pspec, True) # DeNorm
def setup(self, m, i):
""" links module to inputs and outputs
"""
- smod = FPAddSpecialCasesMod(self.width, self.id_wid)
- dmod = FPAddDeNormMod(self.width, self.id_wid)
+ smod = FPAddSpecialCasesMod(self.pspec)
+ dmod = FPAddDeNormMod(self.pspec, True)
chain = StageChain([smod, dmod])
chain.setup(m, i)