FP16 DIV seems to be working
[ieee754fpu.git] / src / ieee754 / fpdiv / pipeline.py
index 40bdedf64749adc6e4eb3b438c6096f79b9887a3..f9ad69e35dbe0431c8d1f8a171b7063f2356f26a 100644 (file)
@@ -89,7 +89,8 @@ class FPDIVBasePipe(ControlBase):
         # XXX BUG - subtracting 4 from number of stages stops assert
         # probably related to having to add 4 in FPDivMuxInOut
         radix = pspec.log2_radix
-        n_stages = pspec.core_config.bit_width // (max_n_comb_stages * radix)
+        n_stages = pspec.core_config.n_stages // max_n_comb_stages
+        print ("n_stages", pspec.core_config.n_stages, n_stages)
         stage_idx = 0
 
         for i in range(n_stages):
@@ -135,6 +136,9 @@ class FPDIVBasePipe(ControlBase):
 
         return m
 
+def roundup(x, mod):
+    return x if x % mod == 0 else x + mod - x % mod
+
 
 class FPDIVMuxInOut(ReservationStations):
     """ Reservation-Station version of FPDIV pipeline.
@@ -149,17 +153,19 @@ class FPDIVMuxInOut(ReservationStations):
                    then be used to change the behaviour of the pipeline.
     """
 
-    def __init__(self, width, num_rows, op_wid=0):
+    def __init__(self, width, num_rows, op_wid=1):
         self.id_wid = num_bits(width)
         self.pspec = PipelineSpec(width, self.id_wid, op_wid)
         # get the standard mantissa width, store in the pspec HOWEVER...
         fmt = FPFormat.standard(width)
-        # ...4 extra bits on the mantissa: MSB is zero, MSB-1 is 1
-        # then there is guard and round at the LSB end
-        fmt.m_width += 4
-        # TODO: make fmt.m_width a modulo of log2_radix
         log2_radix = 2
 
+        # ...5 extra bits on the mantissa: MSB is zero, MSB-1 is 1
+        # then there is guard, round and sticky at the LSB end.
+        # also: round up to nearest radix
+        fmt.m_width = roundup(fmt.m_width + 5, log2_radix)
+        print ("width", fmt.m_width)
+
         cfg = DivPipeCoreConfig(fmt.m_width, fmt.fraction_width, log2_radix)
 
         self.pspec.fpformat = fmt