| 1 |
|
| 2 |
|
| 3 |
import pytest |
| 4 |
import sys |
| 5 |
import gc |
| 6 |
|
| 7 |
try: |
| 8 |
import z3 |
| 9 |
from hypothesis import given, strategies, assume, example |
| 10 |
except ImportError: |
| 11 |
pytest.skip("please install z3 (z3-solver on pypi) and hypothesis") |
| 12 |
|
| 13 |
|
| 14 |
from rpython.rlib.rbigint import _bitcount64_ops |
| 15 |
|
| 16 |
def test_bitcount64_logic(): |
| 17 |
|
| 18 |
BITCOUNT_K1 = z3.BitVecVal(0x5555555555555555, 64) |
| 19 |
BITCOUNT_K2 = z3.BitVecVal(0x3333333333333333, 64) |
| 20 |
BITCOUNT_K4 = z3.BitVecVal(0x0f0f0f0f0f0f0f0f, 64) |
| 21 |
BITCOUNT_KF = z3.BitVecVal(0x0101010101010101, 64) |
| 22 |
|
| 23 |
x = z3.BitVec('x', 64) |
| 24 |
|
| 25 |
solver = z3.Solver() |
| 26 |
solver.add(x >= 0) |
| 27 |
solver.add(x <= 100000000) |
| 28 |
|
| 29 |
res = _bitcount64_ops(x, BITCOUNT_K1, BITCOUNT_K2, BITCOUNT_K4, BITCOUNT_KF) |
| 30 |
zero = z3.BitVecVal(0, 64) |
| 31 |
one = z3.BitVecVal(1, 64) |
| 32 |
correct_res = zero |
| 33 |
for i in range(64): |
| 34 |
correct_res += z3.If(z3.Extract(i, i, x) == 1, one, zero) |
| 35 |
status = solver.check(res != correct_res) |
| 36 |
assert status == z3.unsat |
| 37 |
|