From 4cb06efc04e69489034a60853a1aeffe220f905b Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Wed, 5 Jun 2019 17:02:42 +0200 Subject: [PATCH] Initial commit --- bench_generator.py | 43 +++++++++++++++++++++++++++++++++++++++++++ project_simulator.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 bench_generator.py create mode 100644 project_simulator.py diff --git a/bench_generator.py b/bench_generator.py new file mode 100644 index 0000000..28df8bc --- /dev/null +++ b/bench_generator.py @@ -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) \ No newline at end of file diff --git a/project_simulator.py b/project_simulator.py new file mode 100644 index 0000000..b23305d --- /dev/null +++ b/project_simulator.py @@ -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 +