aboutsummaryrefslogtreecommitdiffstats
path: root/testsuite/synth/issue1165/bug.vhdl
blob: 8dd9c04e18a22e876910726db2b3c99e82473d0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity bug is
	generic(
		ADDR_WIDTH   : positive := 32;
		BUS_WIDTH    : positive := 4;
		QUEUE_LENGTH : positive := 32
	);
	port(
		clk          : in std_ulogic;
		reset_n      : in std_ulogic
	);
end bug;

architecture behav of bug is
	signal write_start_addr : unsigned(ADDR_WIDTH-1 downto 0);
	signal num_words        : integer range 0 to QUEUE_LENGTH-1;

	function non_4k_crossing_length(start_addr : unsigned(ADDR_WIDTH-1 downto 0);
	                                max_length : integer range 0 to QUEUE_LENGTH-1) return integer is
		constant words_per_page : integer := 4096/BUS_WIDTH;
		constant diff : integer range 0 to words_per_page := (words_per_page-(to_integer(start_addr)/BUS_WIDTH mod words_per_page));
	begin
		return minimum(diff, max_length);
	end function;

begin

	process(clk, reset_n)
		variable aligned_start_addr : unsigned(ADDR_WIDTH-1 downto 0);
		variable write_length       : integer range 0 to QUEUE_LENGTH-1;
	begin
		if reset_n = '0' then
		elsif rising_edge(clk) then
			aligned_start_addr := resize(write_start_addr/BUS_WIDTH*BUS_WIDTH, ADDR_WIDTH);
			write_length := non_4k_crossing_length(aligned_start_addr, num_words);			
		end if;
	end process;

end architecture;