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
13 from ieee754
.fpcommon
.getop
import FPADDBaseData
14 from ieee754
.fpcommon
.denorm
import FPSCData
15 from ieee754
.fpcommon
.pack
import FPPackData
16 from ieee754
.fpcommon
.normtopack
import FPNormToPack
17 from ieee754
.fpadd
.specialcases
import FPAddSpecialCasesDeNorm
18 from ieee754
.fpadd
.addstages
import FPAddAlignSingleAdd
22 return int(log(n
) / log(2))
24 class FPADDInMuxPipe(PriorityCombMuxInPipe
):
25 def __init__(self
, num_rows
, iospecfn
):
26 self
.num_rows
= num_rows
27 stage
= PassThroughStage(iospecfn
)
28 PriorityCombMuxInPipe
.__init
__(self
, stage
, p_len
=self
.num_rows
)
31 class FPADDMuxOutPipe(CombMuxOutPipe
):
32 def __init__(self
, num_rows
, iospecfn
):
33 self
.num_rows
= num_rows
34 stage
= PassThroughStage(iospecfn
)
35 CombMuxOutPipe
.__init
__(self
, stage
, n_len
=self
.num_rows
)
38 class ReservationStations
:
39 """ Reservation-Station pipeline
41 Input: num_rows - number of input and output Reservation Stations
43 Requires: the addition of an "alu" object, an i_specfn and an o_specfn
45 * fan-in on inputs (an array of FPADDBaseData: a,b,mid)
47 * fan-out on outputs (an array of FPPackData: z,mid)
49 Fan-in and Fan-out are combinatorial.
51 def __init__(self
, num_rows
):
52 self
.num_rows
= num_rows
53 self
.inpipe
= FPADDInMuxPipe(num_rows
, self
.i_specfn
) # fan-in
54 self
.outpipe
= FPADDMuxOutPipe(num_rows
, self
.o_specfn
) # fan-out
56 self
.p
= self
.inpipe
.p
# kinda annoying,
57 self
.n
= self
.outpipe
.n
# use pipe in/out as this class in/out
58 self
._ports
= self
.inpipe
.ports() + self
.outpipe
.ports()
60 def elaborate(self
, platform
):
62 m
.submodules
.inpipe
= self
.inpipe
63 m
.submodules
.alu
= self
.alu
64 m
.submodules
.outpipe
= self
.outpipe
66 m
.d
.comb
+= self
.inpipe
.n
.connect_to_next(self
.alu
.p
)
67 m
.d
.comb
+= self
.alu
.connect_to_next(self
.outpipe
)