Initial commit

This commit is contained in:
Davide Depau 2019-06-05 17:02:42 +02:00
commit 4cb06efc04
Signed by: depau
GPG key ID: C7D999B6A55EFE86
2 changed files with 79 additions and 0 deletions

43
bench_generator.py Normal file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from random import randint
point_mask = randint(0, 0xFF)
points = [(randint(0, 0xFF), randint(0, 0xFF)) for i in range(8)]
x0, y0 = (randint(0, 0xFF), randint(0, 0xFF))
tmp_out_mask = 0
cur_pt_mask = 1
min_dist = 0xFF
if __name__ == "__main__":
for x, y in points:
if not cur_pt_mask & point_mask:
cur_pt_mask <<= 1
continue
dist = abs(x - x0) + abs(y - y0)
if dist < min_dist:
min_dist = dist
tmp_out_mask = cur_pt_mask
elif dist == min_dist:
tmp_out_mask |= cur_pt_mask
cur_pt_mask <<= 1
print("signal RAM: ram_type := (0 => std_logic_vector(to_unsigned({}, 8)),".format(point_mask))
for i in range(1, 17):
if i % 2 == 1:
val = points[(i-1)//2][0]
else:
val = points[(i-1)//2][1]
print(" {} => std_logic_vector(to_unsigned({}, 8)),".format(i, val))
print(" 17 => std_logic_vector(to_unsigned({}, 8)),".format(x0))
print(" 18 => std_logic_vector(to_unsigned({}, 8)),".format(y0))
print(" others => (others =>'0'));")
print()
print()
print(bin(tmp_out_mask), tmp_out_mask, min_dist)

36
project_simulator.py Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
point_mask = 0b11100000
points = [
(75, 32),
(111, 213),
(79, 33),
(1, 33),
(80, 35),
(12, 254),
(215, 78),
(211, 121)
]
x0, y0 = (78, 33)
tmp_out_mask = 0
cur_pt_mask = 1
min_dist = 0xFF
if __name__ == "__main__":
for x, y in points:
if not cur_pt_mask & point_mask:
cur_pt_mask <<= 1
continue
dist = abs(x - x0) + abs(y - y0)
if dist < min_dist:
min_dist = dist
tmp_out_mask = cur_pt_mask
elif dist == min_dist:
tmp_out_mask |= cur_pt_mask
cur_pt_mask <<= 1