1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
5 from nmigen
import Module
, Signal
, Cat
, Mux
, Array
, Const
, Elaboratable
6 from nmigen
.lib
.coding
import PriorityEncoder
7 from nmigen
.cli
import main
, verilog
10 from fpbase
import FPNumIn
, FPNumOut
, FPOpIn
, Overflow
, FPBase
, FPNumBase
11 from fpbase
import MultiShiftRMerge
, Trigger
12 from singlepipe
import (ControlBase
, StageChain
, SimpleHandshake
,
13 PassThroughStage
, PrevControl
)
14 from multipipe
import CombMuxOutPipe
15 from multipipe
import PriorityCombMuxInPipe
17 from fpbase
import FPState
20 class FPGetOpMod(Elaboratable
):
21 def __init__(self
, width
):
22 self
.in_op
= FPOpIn(width
)
23 self
.in_op
.data_i
= Signal(width
)
24 self
.out_op
= Signal(width
)
25 self
.out_decode
= Signal(reset_less
=True)
27 def elaborate(self
, platform
):
29 m
.d
.comb
+= self
.out_decode
.eq((self
.in_op
.ready_o
) & \
30 (self
.in_op
.valid_i_test
))
31 m
.submodules
.get_op_in
= self
.in_op
32 #m.submodules.get_op_out = self.out_op
33 with m
.If(self
.out_decode
):
35 self
.out_op
.eq(self
.in_op
.v
),
40 class FPGetOp(FPState
):
44 def __init__(self
, in_state
, out_state
, in_op
, width
):
45 FPState
.__init
__(self
, in_state
)
46 self
.out_state
= out_state
47 self
.mod
= FPGetOpMod(width
)
49 self
.out_op
= Signal(width
)
50 self
.out_decode
= Signal(reset_less
=True)
52 def setup(self
, m
, in_op
):
53 """ links module to inputs and outputs
55 setattr(m
.submodules
, self
.state_from
, self
.mod
)
56 m
.d
.comb
+= self
.mod
.in_op
.eq(in_op
)
57 m
.d
.comb
+= self
.out_decode
.eq(self
.mod
.out_decode
)
60 with m
.If(self
.out_decode
):
61 m
.next
= self
.out_state
63 self
.in_op
.ready_o
.eq(0),
64 self
.out_op
.eq(self
.mod
.out_op
)
67 m
.d
.sync
+= self
.in_op
.ready_o
.eq(1)
72 def __init__(self
, width
, id_wid
, m_extra
=True):
73 self
.a
= FPNumBase(width
, m_extra
)
74 self
.b
= FPNumBase(width
, m_extra
)
75 self
.mid
= Signal(id_wid
, reset_less
=True)
78 return [self
.a
.eq(i
.a
), self
.b
.eq(i
.b
), self
.mid
.eq(i
.mid
)]
81 return [self
.a
, self
.b
, self
.mid
]
86 def __init__(self
, width
, id_wid
):
89 self
.a
= Signal(width
)
90 self
.b
= Signal(width
)
91 self
.mid
= Signal(id_wid
, reset_less
=True)
94 return [self
.a
.eq(i
.a
), self
.b
.eq(i
.b
), self
.mid
.eq(i
.mid
)]
97 return [self
.a
, self
.b
, self
.mid
]
100 class FPGet2OpMod(PrevControl
):
101 def __init__(self
, width
, id_wid
):
102 PrevControl
.__init
__(self
)
105 self
.data_i
= self
.ispec()
107 self
.o
= self
.ospec()
110 return FPADDBaseData(self
.width
, self
.id_wid
)
113 return FPADDBaseData(self
.width
, self
.id_wid
)
115 def process(self
, i
):
118 def elaborate(self
, platform
):
119 m
= PrevControl
.elaborate(self
, platform
)
120 with m
.If(self
.trigger
):
122 self
.o
.eq(self
.data_i
),
127 class FPGet2Op(FPState
):
131 def __init__(self
, in_state
, out_state
, width
, id_wid
):
132 FPState
.__init
__(self
, in_state
)
133 self
.out_state
= out_state
134 self
.mod
= FPGet2OpMod(width
, id_wid
)
135 self
.o
= self
.ospec()
136 self
.in_stb
= Signal(reset_less
=True)
137 self
.out_ack
= Signal(reset_less
=True)
138 self
.out_decode
= Signal(reset_less
=True)
141 return self
.mod
.ispec()
144 return self
.mod
.ospec()
146 def trigger_setup(self
, m
, in_stb
, in_ack
):
149 m
.d
.comb
+= self
.mod
.valid_i
.eq(in_stb
)
150 m
.d
.comb
+= in_ack
.eq(self
.mod
.ready_o
)
152 def setup(self
, m
, i
):
153 """ links module to inputs and outputs
155 m
.submodules
.get_ops
= self
.mod
156 m
.d
.comb
+= self
.mod
.i
.eq(i
)
157 m
.d
.comb
+= self
.out_ack
.eq(self
.mod
.ready_o
)
158 m
.d
.comb
+= self
.out_decode
.eq(self
.mod
.trigger
)
160 def process(self
, i
):
164 with m
.If(self
.out_decode
):
165 m
.next
= self
.out_state
167 self
.mod
.ready_o
.eq(0),
168 self
.o
.eq(self
.mod
.o
),
171 m
.d
.sync
+= self
.mod
.ready_o
.eq(1)