1 # SPDX-License-Identifier: LGPL-2.1-or-later
2 # See Notices.txt for copyright information
5 Copyright (C) 2020 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
7 dynamically-partitionable "comparison" class, directly equivalent
8 to Signal.__eq__ except SIMD-partitionable
12 * http://libre-riscv.org/3d_gpu/architecture/dynamic_simd/eq
13 * http://bugs.libre-riscv.org/show_bug.cgi?id=132
16 from nmigen
import Signal
, Module
, Elaboratable
, Cat
, C
, Mux
, Repl
17 from nmigen
.cli
import main
19 from ieee754
.part_mul_add
.partpoints
import PartitionPoints
20 from ieee754
.part_cmp
.experiments
.eq_combiner
import EQCombiner
23 class PartitionedEq(Elaboratable
):
25 def __init__(self
, width
, partition_points
):
26 """Create a ``PartitionedEq`` operator
29 self
.a
= Signal(width
, reset_less
=True)
30 self
.b
= Signal(width
, reset_less
=True)
31 self
.partition_points
= PartitionPoints(partition_points
)
32 self
.mwidth
= len(self
.partition_points
)+1
33 self
.output
= Signal(self
.mwidth
, reset_less
=True)
34 if not self
.partition_points
.fits_in_width(width
):
35 raise ValueError("partition_points doesn't fit in width")
37 def elaborate(self
, platform
):
40 m
.submodules
.eqc
= eqc
= EQCombiner(self
.mwidth
)
42 # make a series of "not-eqs", splitting a and b into partition chunks
43 nes
= Signal(self
.mwidth
, reset_less
=True)
45 keys
= list(self
.partition_points
.keys()) + [self
.width
]
47 for i
in range(len(keys
)):
49 nel
.append(self
.a
[start
:end
] != self
.b
[start
:end
])
50 start
= end
# for next time round loop
51 comb
+= nes
.eq(Cat(*nel
))
53 comb
+= eqc
.gates
.eq(self
.partition_points
.as_sig())
54 comb
+= eqc
.neqs
.eq(nes
)
55 comb
+= self
.output
.eq(eqc
.outputs
)