-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_pop.py
24 lines (20 loc) · 895 Bytes
/
test_pop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from bit_vector import BitVector
import magma as m
from mantle.util.compressor.pop import DefinePopCount
from magma.testing import check_files_equal
from magma.scope import Scope
from magma.simulator.coreir_simulator import CoreIRSimulator
def test_pop_count():
PopCount8 = DefinePopCount(8)
m.compile('build/popcount8', PopCount8, output="coreir")
assert check_files_equal(__file__,
"build/popcount8.json", "gold/popcount8.json")
scope = Scope()
sim = CoreIRSimulator(PopCount8, None)
for I, expected_O in [(1, 1), (2, 1), (3, 2)]:
sim.set_value(PopCount8.I, BitVector(I, 8), scope)
sim.evaluate()
assert BitVector(sim.get_value(PopCount8.O, scope), 8).as_int() == expected_O
m.compile('build/popcount8', PopCount8, output="verilog")
assert check_files_equal(__file__,
"build/popcount8.v", "gold/popcount8.v")