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
))
80 class FPGet2OpMod(PrevControl
):
81 def __init__(self
, width
, id_wid
, op_wid
=None):
82 PrevControl
.__init
__(self
)
85 self
.data_i
= self
.ispec()
90 return FPBaseData(self
.width
, self
.id_wid
, self
.op_wid
)
93 return FPBaseData(self
.width
, self
.id_wid
, self
.op_wid
)
98 def elaborate(self
, platform
):
99 m
= PrevControl
.elaborate(self
, platform
)
100 with m
.If(self
.trigger
):
102 self
.o
.eq(self
.data_i
),