2021 day1/vhdl: clean up

This commit is contained in:
Xiretza 2021-12-01 14:52:22 +01:00
parent 4e8d0e3f36
commit fc223c2746

View file

@ -23,7 +23,7 @@ entity top is
end entity;
architecture arch of top is
function get_window_size return positive is
function WINDOW_SIZE return positive is
begin
if STEP = 1 then
return 1;
@ -32,14 +32,13 @@ architecture arch of top is
end if;
end function;
constant WINDOW_SIZE : positive := get_window_size;
type number_t is array(MAX_INPUT_DIGITS-1 downto 0) of digit_t;
type window_t is array(0 to WINDOW_SIZE) of number_t;
type window_t is array(WINDOW_SIZE-1 downto 0) of number_t;
signal current_number : number_t;
signal window : window_t;
signal window_countdown : natural range WINDOW_SIZE downto 0 := 0;
signal window_count : natural range 0 to WINDOW_SIZE := 0;
begin
process(clk)
begin
@ -47,23 +46,24 @@ begin
if reset then
output <= (others => '0');
output_valid <= '1';
window_countdown <= 0;
window_count <= 0;
elsif input_valid then
output_valid <= '0';
if char = LF then
if window_countdown = WINDOW_SIZE then
if window(0) > window(window'high) then
if window_count = WINDOW_SIZE then
if current_number > window(window'high) then
output <= output + 1;
end if;
output_valid <= '1';
else
window_countdown <= window_countdown + 1;
window_count <= window_count + 1;
end if;
window <= number_t'(others => 0) & window(0 to window'high-1);
window <= window(window'high-1 downto 0) & current_number;
current_number <= (others => 0);
else
window(0) <= window(0)(MAX_INPUT_DIGITS-2 downto 0) & char_to_digit(char);
current_number <= current_number(current_number'left-1 downto 0) & char_to_digit(char);
end if;
end if;
end if;