1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
6 from nmigen
import Module
7 from nmigen
.cli
import main
, verilog
9 from nmutil
.singlepipe
import PassThroughStage
10 from nmutil
.multipipe
import CombMuxOutPipe
11 from nmutil
.multipipe
import PriorityCombMuxInPipe
15 return int(log(n
) / log(2))
17 class FPADDInMuxPipe(PriorityCombMuxInPipe
):
18 def __init__(self
, num_rows
, iospecfn
):
19 self
.num_rows
= num_rows
20 stage
= PassThroughStage(iospecfn
)
21 PriorityCombMuxInPipe
.__init
__(self
, stage
, p_len
=self
.num_rows
)
24 class FPADDMuxOutPipe(CombMuxOutPipe
):
25 def __init__(self
, num_rows
, iospecfn
):
26 self
.num_rows
= num_rows
27 stage
= PassThroughStage(iospecfn
)
28 CombMuxOutPipe
.__init
__(self
, stage
, n_len
=self
.num_rows
)
31 class ReservationStations
:
32 """ Reservation-Station pipeline
34 Input: num_rows - number of input and output Reservation Stations
36 Requires: the addition of an "alu" object, an i_specfn and an o_specfn
38 * fan-in on inputs (an array of FPADDBaseData: a,b,mid)
40 * fan-out on outputs (an array of FPPackData: z,mid)
42 Fan-in and Fan-out are combinatorial.
44 def __init__(self
, num_rows
):
45 self
.num_rows
= num_rows
46 self
.inpipe
= FPADDInMuxPipe(num_rows
, self
.i_specfn
) # fan-in
47 self
.outpipe
= FPADDMuxOutPipe(num_rows
, self
.o_specfn
) # fan-out
49 self
.p
= self
.inpipe
.p
# kinda annoying,
50 self
.n
= self
.outpipe
.n
# use pipe in/out as this class in/out
51 self
._ports
= self
.inpipe
.ports() + self
.outpipe
.ports()
53 def elaborate(self
, platform
):
55 m
.submodules
.inpipe
= self
.inpipe
56 m
.submodules
.alu
= self
.alu
57 m
.submodules
.outpipe
= self
.outpipe
59 m
.d
.comb
+= self
.inpipe
.n
.connect_to_next(self
.alu
.p
)
60 m
.d
.comb
+= self
.alu
.connect_to_next(self
.outpipe
)