2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # See Notices.txt for copyright information
5 from nmigen
import Signal
, Module
, Elaboratable
6 from nmigen
.back
.pysim
import Simulator
, Delay
7 from nmigen
.cli
import rtlil
9 from ieee754
.part
.partsig
import PartitionedSignal
10 from ieee754
.part_mux
.part_mux
import PMux
13 # XXX this is for coriolis2 experimentation
14 class TestLS(Elaboratable
):
15 def __init__(self
, width
, partpoints
):
16 self
.partpoints
= partpoints
17 self
.a
= PartitionedSignal(partpoints
, width
, name
="a")
18 self
.b
= PartitionedSignal(partpoints
, width
, name
="b")
19 self
.ls_output
= Signal(width
) # left shift
20 self
.dummy_output
= Signal(width
)
21 self
.dummy_mask
= Signal(self
.partpoints
.shape())
23 def elaborate(self
, platform
):
30 wid
= len(self
.partpoints
)
31 sync
+= self
.dummy_mask
.eq(self
.partpoints
)
32 sync
+= self
.dummy_output
.eq(self
.b
.sig
+ self
.a
.sig
) # stops ignored
33 sync
+= self
.ls_output
.eq(self
.a
<< self
.b
)
34 ppts
= self
.partpoints
39 return [self
.a
.sig
, self
.b
.sig
,
45 # XXX this is for coriolis2 experimentation
46 class TestAddMod2(Elaboratable
):
47 def __init__(self
, width
, partpoints
):
48 self
.partpoints
= partpoints
49 self
.a
= PartitionedSignal(partpoints
, width
, name
="a")
50 self
.b
= PartitionedSignal(partpoints
, width
, name
="b")
51 self
.add_output
= Signal(width
)
52 self
.ls_output
= Signal(width
) # left shift
53 self
.sub_output
= Signal(width
)
54 self
.carry_in
= Signal(len(partpoints
)+1)
55 self
.add_carry_out
= Signal(len(partpoints
)+1)
56 self
.sub_carry_out
= Signal(len(partpoints
)+1)
57 self
.neg_output
= Signal(width
)
59 def elaborate(self
, platform
):
66 add_out
, add_carry
= self
.a
.add_op(self
.a
, self
.b
,
68 sync
+= self
.add_output
.eq(add_out
)
69 sync
+= self
.add_carry_out
.eq(add_carry
)
71 sub_out
, sub_carry
= self
.a
.sub_op(self
.a
, self
.b
,
73 sync
+= self
.sub_output
.eq(sub_out
)
74 sync
+= self
.sub_carry_out
.eq(sub_carry
)
76 sync
+= self
.neg_output
.eq(-self
.a
)
78 sync
+= self
.ls_output
.eq(self
.a
<< self
.b
)
79 ppts
= self
.partpoints
84 return [self
.a
.sig
, self
.b
.sig
,