latch into FPNumIn within module
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 20 Feb 2019 04:54:41 +0000 (04:54 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 20 Feb 2019 04:54:41 +0000 (04:54 +0000)
src/add/fpbase.py
src/add/nmigen_add_experiment.py

index 592a3f72a34cb7dd0a1163b0474971af17f66a8c..962dfcf661aa4ba285b0562254f8c118dc815b49 100644 (file)
@@ -177,12 +177,18 @@ class FPNumIn(FPNumBase):
         (m[-1]) is effectively a carry-overflow.  The other three are
         guard (m[2]), round (m[1]), and sticky (m[0])
     """
-    def __init__(self, width, m_extra=True):
+    def __init__(self, op, width, m_extra=True):
         FPNumBase.__init__(self, width, m_extra)
+        self.latch_in = Signal()
+        self.op = op
 
     def elaborate(self, platform):
         m = FPNumBase.elaborate(self, platform)
 
+        m.d.comb += self.latch_in.eq(self.op.ack & self.op.stb)
+        with m.If(self.latch_in):
+            m.d.sync += self.decode(self.v)
+
         return m
 
     def decode(self, v):
@@ -291,7 +297,7 @@ class FPBase:
         with m.If((op.ack) & (op.stb)):
             m.next = next_state
             m.d.sync += [
-                v.decode(op.v),
+                # op is latched in from FPNumIn class on same ack/stb
                 op.ack.eq(0)
             ]
         with m.Else():
index b1e633ebf79286952346a18aa49ec685ad563396..184aa91ee03216985254c2c1e1d2a6ab14d31955 100644 (file)
@@ -25,14 +25,17 @@ class FPADD(FPBase):
         m = Module()
 
         # Latches
-        a = FPNumIn(self.width)
-        b = FPNumIn(self.width)
+        a = FPNumIn(self.in_a, self.width)
+        b = FPNumIn(self.in_b, self.width)
         z = FPNumOut(self.width, False)
 
         m.submodules.fpnum_a = a
         m.submodules.fpnum_b = b
         m.submodules.fpnum_z = z
 
+        m.d.comb += a.v.eq(self.in_a.v)
+        m.d.comb += b.v.eq(self.in_b.v)
+
         w = z.m_width + 4
         tot = Signal(w, reset_less=True) # sticky/round/guard, {mantissa} result, 1 overflow