use ObjectProxy in get_op
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 4 Apr 2019 07:29:53 +0000 (08:29 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 4 Apr 2019 07:29:53 +0000 (08:29 +0100)
src/add/fadd_state.py
src/add/fpbase.py

index 343f13ed21ab1b3ffa8e3d5dc42aa77a343aeebb..79a8723d9375771fb89a842ce14ad94af407cd7e 100644 (file)
@@ -7,6 +7,8 @@ from nmigen.cli import main, verilog
 
 from fpbase import FPNumIn, FPNumOut, FPOp, Overflow, FPBase
 
 
 from fpbase import FPNumIn, FPNumOut, FPOp, Overflow, FPBase
 
+from singlepipe import eq
+
 
 class FPADD(FPBase):
 
 
 class FPADD(FPBase):
 
@@ -49,13 +51,15 @@ class FPADD(FPBase):
             # gets operand a
 
             with m.State("get_a"):
             # gets operand a
 
             with m.State("get_a"):
-                self.get_op(m, self.in_a, a, "get_b")
+                res = self.get_op(m, self.in_a, a, "get_b")
+                m.d.sync += eq([a, self.in_a.ack], res)
 
             # ******
             # gets operand b
 
             with m.State("get_b"):
 
             # ******
             # gets operand b
 
             with m.State("get_b"):
-                self.get_op(m, self.in_b, b, "special_cases")
+                res = self.get_op(m, self.in_b, b, "special_cases")
+                m.d.sync += eq([b, self.in_b.ack], res)
 
             # ******
             # special cases: NaNs, infs, zeros, denormalised
 
             # ******
             # special cases: NaNs, infs, zeros, denormalised
index dc2c9020dd5fc3644da3a9f7f36e2532ea896619..b15c21cab1536d9954f37c07c674fc91cf52dc26 100644 (file)
@@ -7,6 +7,9 @@ from math import log
 from operator import or_
 from functools import reduce
 
 from operator import or_
 from functools import reduce
 
+from pipeline import ObjectProxy
+
+
 class MultiShiftR:
 
     def __init__(self, width):
 class MultiShiftR:
 
     def __init__(self, width):
@@ -353,6 +356,22 @@ class FPNumIn(FPNumBase):
         self.latch_in = Signal()
         self.op = op
 
         self.latch_in = Signal()
         self.op = op
 
+    def decode2(self, m):
+        """ decodes a latched value into sign / exponent / mantissa
+
+            bias is subtracted here, from the exponent.  exponent
+            is extended to 10 bits so that subtract 127 is done on
+            a 10-bit number
+        """
+        v = self.v
+        args = [0] * self.m_extra + [v[0:self.e_start]] # pad with extra zeros
+        #print ("decode", self.e_end)
+        res = ObjectProxy(m, pipemode=False)
+        res.m = Cat(*args)                             # mantissa
+        res.e = v[self.e_start:self.e_end] - self.P127 # exp
+        res.s = v[-1]                                  # sign
+        return res
+
     def decode(self, v):
         """ decodes a latched value into sign / exponent / mantissa
 
     def decode(self, v):
         """ decodes a latched value into sign / exponent / mantissa
 
@@ -509,15 +528,15 @@ class FPBase:
             when both stb and ack are 1.
             acknowledgement is sent by setting ack to ZERO.
         """
             when both stb and ack are 1.
             acknowledgement is sent by setting ack to ZERO.
         """
+        res = v.decode2(m)
+        ack = Signal()
         with m.If((op.ack) & (op.stb)):
             m.next = next_state
         with m.If((op.ack) & (op.stb)):
             m.next = next_state
-            m.d.sync += [
-                # op is latched in from FPNumIn class on same ack/stb
-                v.decode(op.v),
-                op.ack.eq(0)
-            ]
+            # op is latched in from FPNumIn class on same ack/stb
+            m.d.comb += ack.eq(0)
         with m.Else():
         with m.Else():
-            m.d.sync += op.ack.eq(1)
+            m.d.comb += ack.eq(1)
+        return [res, ack]
 
     def denormalise(self, m, a):
         """ denormalises a number.  this is probably the wrong name for
 
     def denormalise(self, m, a):
         """ denormalises a number.  this is probably the wrong name for