Add in FPPipeContext to the cordic pipeline
[ieee754fpu.git] / src / ieee754 / cordic / pipe_data.py
1 from nmigen import Signal, Const
2 from nmutil.dynamicpipe import SimpleHandshakeRedir
3 from ieee754.fpcommon.fpbase import Overflow, FPNumBaseRecord
4 from ieee754.fpcommon.getop import FPPipeContext
5 import math
6
7
8 class CordicInitialData:
9
10 def __init__(self, pspec):
11 ZMAX = pspec.ZMAX
12 self.z0 = Signal(range(-ZMAX, ZMAX), name="z") # denormed result
13 self.ctx = FPPipeContext(pspec)
14 self.muxid = self.ctx.muxid
15
16 def __iter__(self):
17 yield self.z0
18 yield from self.ctx
19
20 def eq(self, i):
21 return [self.z0.eq(i.z0), self.ctx.eq(i.ctx)]
22
23
24 class CordicOutputData:
25
26 def __init__(self, pspec, e_extra=False):
27 width = pspec.width
28 self.x = Signal(width)
29 self.y = Signal(width)
30 self.ctx = FPPipeContext(pspec)
31 self.muxid = self.ctx.muxid
32
33 def __iter__(self):
34 yield self.x
35 yield self.y
36 yield from self.ctx
37
38 def eq(self, i):
39 return [self.x.eq(i.x), self.y.eq(i.y),
40 self.ctx.eq(i.ctx)]
41
42
43 class CordicData:
44
45 def __init__(self, pspec):
46
47 M = pspec.M
48 ZMAX = pspec.ZMAX
49 self.x = Signal(range(-M, M+1), name="x") # operand a
50 self.y = Signal(range(-M, M+1), name="y") # operand b
51 self.z = Signal(range(-ZMAX, ZMAX), name="z") # denormed result
52 self.ctx = FPPipeContext(pspec)
53 self.muxid = self.ctx.muxid
54
55 def __iter__(self):
56 yield self.x
57 yield self.y
58 yield self.z
59 yield from self.ctx
60
61 def eq(self, i):
62 ret = [self.z.eq(i.z), self.x.eq(i.x), self.y.eq(i.y),
63 self.ctx.eq(i.ctx)]
64 return ret
65
66
67 class CordicPipeSpec:
68 def __init__(self, fracbits, rounds_per_stage):
69 self.fracbits = fracbits
70 # Number of cordic operations per pipeline stage
71 self.rounds_per_stage = rounds_per_stage
72 self.M = (1 << fracbits)
73 self.ZMAX = int(round(self.M * math.pi/2))
74 zm = Const(-self.ZMAX)
75 self.iterations = zm.width - 1
76
77 self.pipekls = SimpleHandshakeRedir
78 self.stage = None