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
8 class CordicInitialData
:
10 def __init__(self
, pspec
):
12 self
.z0
= Signal(range(-ZMAX
, ZMAX
), name
="z") # denormed result
18 return [self
.z0
.eq(i
.z0
)]
21 class CordicOutputData
:
23 def __init__(self
, pspec
, e_extra
=False):
25 self
.x
= FPNumBaseRecord(width
, False, e_extra
, name
="x")
26 self
.y
= FPNumBaseRecord(width
, False, e_extra
, name
="y")
27 self
.ctx
= FPPipeContext(pspec
)
28 self
.muxid
= self
.ctx
.muxid
36 return [self
.x
.eq(i
.x
), self
.y
.eq(i
.y
),
42 def __init__(self
, pspec
):
46 self
.x
= Signal(range(-M
, M
+1), name
="x") # operand a
47 self
.y
= Signal(range(-M
, M
+1), name
="y") # operand b
48 self
.z
= Signal(range(-ZMAX
, ZMAX
), name
="z") # denormed result
56 ret
= [self
.z
.eq(i
.z
), self
.x
.eq(i
.x
), self
.y
.eq(i
.y
)]
61 def __init__(self
, fracbits
, rounds_per_stage
):
62 self
.fracbits
= fracbits
63 # Number of cordic operations per pipeline stage
64 self
.rounds_per_stage
= rounds_per_stage
65 self
.M
= (1 << fracbits
)
66 self
.ZMAX
= int(round(self
.M
* math
.pi
/2))
67 zm
= Const(-self
.ZMAX
)
68 self
.iterations
= zm
.width
- 1
70 self
.pipekls
= SimpleHandshakeRedir