bc60a55a9ce4db149b050635d180e6d9faac1702
1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
5 from nmigen
import Module
, Signal
, Elaboratable
6 from nmigen
.lib
.coding
import PriorityEncoder
7 from nmigen
.cli
import main
, verilog
10 from ieee754
.fpcommon
.fpbase
import FPOpIn
, FPBase
, FPNumBase
11 from nmutil
.singlepipe
import PrevControl
13 from nmutil
import nmoperator
16 class FPGetOpMod(Elaboratable
):
17 def __init__(self
, width
):
18 self
.in_op
= FPOpIn(width
)
19 self
.in_op
.data_i
= Signal(width
)
20 self
.out_op
= Signal(width
)
21 self
.out_decode
= Signal(reset_less
=True)
23 def elaborate(self
, platform
):
25 m
.d
.comb
+= self
.out_decode
.eq((self
.in_op
.ready_o
) & \
26 (self
.in_op
.valid_i_test
))
27 m
.submodules
.get_op_in
= self
.in_op
28 with m
.If(self
.out_decode
):
30 self
.out_op
.eq(self
.in_op
.v
),
37 def __init__(self
, width
, id_wid
, m_extra
=True):
38 self
.a
= FPNumBase(width
, m_extra
)
39 self
.b
= FPNumBase(width
, m_extra
)
40 self
.muxid
= Signal(id_wid
, reset_less
=True)
43 return [self
.a
.eq(i
.a
), self
.b
.eq(i
.b
), self
.muxid
.eq(i
.muxid
)]
46 return [self
.a
, self
.b
, self
.muxid
]
51 def __init__(self
, pspec
):
52 """ creates a pipeline context. currently: operator (op) and muxid
54 opkls (within pspec) - the class to create that will be the
55 "operator". instance must have an "eq"
58 self
.id_wid
= pspec
.id_wid
59 self
.op_wid
= pspec
.op_wid
60 self
.muxid
= Signal(self
.id_wid
, reset_less
=True) # RS multiplex ID
63 self
.op
= Signal(self
.op_wid
, reset_less
=True)
65 self
.op
= opkls(pspec
)
68 ret
= [self
.muxid
.eq(i
.muxid
)]
69 ret
.append(self
.op
.eq(i
.op
))
82 def __init__(self
, pspec
, n_ops
=2):
84 self
.ctx
= FPPipeContext(pspec
)
86 for i
in range(n_ops
):
87 name
= chr(ord("a")+i
)
88 operand
= Signal(width
, name
=name
)
89 setattr(self
, name
, operand
)
91 self
.muxid
= self
.ctx
.muxid
# make muxid available here: complicated
96 for op1
, op2
in zip(self
.ops
, i
.ops
):
97 ret
.append(op1
.eq(op2
))
98 ret
.append(self
.ctx
.eq(i
.ctx
))
110 class FPGet2OpMod(PrevControl
):
111 def __init__(self
, width
, id_wid
, op_wid
=None):
112 PrevControl
.__init
__(self
)
115 self
.data_i
= self
.ispec()
117 self
.o
= self
.ospec()
120 return FPADDBaseData(self
.width
, self
.id_wid
, self
.op_wid
)
123 return FPADDBaseData(self
.width
, self
.id_wid
, self
.op_wid
)
125 def process(self
, i
):
128 def elaborate(self
, platform
):
129 m
= PrevControl
.elaborate(self
, platform
)
130 with m
.If(self
.trigger
):
132 self
.o
.eq(self
.data_i
),