summaryrefslogtreecommitdiff
path: root/testsuite/gna/bug18810/DMEM.vhd
blob: 4eb5fe2fc51ae881aff3b79f3146b11a27064670 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
-- NOTE: http://www.eecg.toronto.edu/~steffan/papers/laforest_fpga10.pdf

library ieee;
use ieee.std_logic_1164.all;

package DMEM_PRIM_PKG is

	component DMEM_PRIM is
		generic (
			log2A : integer range 0 to integer'high := 4;
			DW    : integer range 1 to integer'high := 8;
			ZERO  : boolean                         := false
		);
		port (
			iWCLK  : in  std_logic;
			iWE    : in  std_logic;
			iWA    : in  integer range 0 to 2**log2A-1;
			iWD    : in  std_logic_vector(DW-1 downto 0);

			iRA0   : in  integer range 0 to 2**log2A-1;
			iRA1   : in  integer range 0 to 2**log2A-1;
			iRA2   : in  integer range 0 to 2**log2A-1;
			oRD0   : out std_logic_vector(DW-1 downto 0);
			oRD1   : out std_logic_vector(DW-1 downto 0);
			oRD2   : out std_logic_vector(DW-1 downto 0)
		);
	end component DMEM_PRIM;

	constant cDMEM_PRIM_W_LATENCY  : integer := 1;
	constant cDMEM_PRIM_R0_LATENCY : integer := 0;
	constant cDMEM_PRIM_R1_LATENCY : integer := 0;
	constant cDMEM_PRIM_R2_LATENCY : integer := 0;

end package DMEM_PRIM_PKG;

package body DMEM_PRIM_PKG is

	-- NOTE: This body should keep to be empty to stub.

end package body DMEM_PRIM_PKG;

library ieee;
use ieee.std_logic_1164.all;

entity DMEM_PRIM is
	generic (
		log2A : integer range 0 to integer'high := 4;
		DW    : integer range 1 to integer'high := 8;
		ZERO  : boolean                         := false
	);
	port (
		iWCLK  : in  std_logic;
		iWE    : in  std_logic;
		iWA    : in  integer range 0 to 2**log2A-1;
		iWD    : in  std_logic_vector(DW-1 downto 0);

		iRA0   : in  integer range 0 to 2**log2A-1;
		iRA1   : in  integer range 0 to 2**log2A-1;
		iRA2   : in  integer range 0 to 2**log2A-1;
		oRD0   : out std_logic_vector(DW-1 downto 0);
		oRD1   : out std_logic_vector(DW-1 downto 0);
		oRD2   : out std_logic_vector(DW-1 downto 0)
	);
begin
end entity DMEM_PRIM;

architecture RTL of DMEM_PRIM is

	type tDMEM_PRIM is array (0 to 2**log2A-1) of std_logic_vector(DW-1 downto 0);
	signal aDMEM_PRIM0 : tDMEM_PRIM := (0 to 2**log2A-1 => (DW-1 downto 0 => '0'));
	signal aDMEM_PRIM1 : tDMEM_PRIM := (0 to 2**log2A-1 => (DW-1 downto 0 => '0'));
	signal aDMEM_PRIM2 : tDMEM_PRIM := (0 to 2**log2A-1 => (DW-1 downto 0 => '0'));

begin

	P_DMEM_PRIM : process (iWCLK)
	begin
		if (rising_edge(iWCLK)) then
			if (iWE = '1') then
				aDMEM_PRIM0(iWA) <= iWD;
				aDMEM_PRIM1(iWA) <= iWD;
				aDMEM_PRIM2(iWA) <= iWD;
			end if;
		end if;
	end process P_DMEM_PRIM;

	oRD0 <= (DW-1 downto 0 => '0') when (ZERO = true and iRA0 = 0) else aDMEM_PRIM0(iRA0);
	oRD1 <= (DW-1 downto 0 => '0') when (ZERO = true and iRA1 = 0) else aDMEM_PRIM1(iRA1);
	oRD2 <= (DW-1 downto 0 => '0') when (ZERO = true and iRA2 = 0) else aDMEM_PRIM2(iRA2);

end architecture RTL;

library ieee;
use ieee.std_logic_1164.all;
use work.DMEM_PRIM_PKG.all;

package DMEM_PKG is

	component DMEM is
		generic (
			log2DADDR : integer range 0 to integer'high := 4;
			DW        : integer range 1 to integer'high := 8;
			ZERO      : boolean                         := false
		);
		port (
			iDCLK  : in  std_logic;
			iDWE   : in  std_logic;
			iDADDR : in  integer range 0 to 2**log2DADDR-1;
			iDDATA : in  std_logic_vector(DW-1 downto 0);
			oDDATA : out std_logic_vector(DW-1 downto 0);

			iCLK   : in  std_logic;
			iAADDR : in  integer range 0 to 2**log2DADDR-1;
			oADATA : out std_logic_vector(DW-1 downto 0);
			iBWE   : in  std_logic;
			iBADDR : in  integer range 0 to 2**log2DADDR-1;
			iBDATA : in  std_logic_vector(DW-1 downto 0);
			oBDATA : out std_logic_vector(DW-1 downto 0)
		);
	end component DMEM;

	constant cDMEM_DW_LATENCY : integer := cDMEM_PRIM_W_LATENCY;
	constant cDMEM_DR_LATENCY : integer := cDMEM_PRIM_R0_LATENCY;
	constant cDMEM_AR_LATENCY : integer := cDMEM_PRIM_R1_LATENCY;
	constant cDMEM_BW_LATENCY : integer := cDMEM_PRIM_W_LATENCY;
	constant cDMEM_BR_LATENCY : integer := cDMEM_PRIM_R2_LATENCY;

end package DMEM_PKG;

package body DMEM_PKG is

	-- NOTE: This body should keep to be empty to stub.

end package body DMEM_PKG;

library ieee;
use ieee.std_logic_1164.all;
use work.DMEM_PRIM_PKG.all;

entity DMEM is
	generic (
		log2DADDR : integer range 0 to integer'high := 4;
		DW        : integer range 1 to integer'high := 8;
		ZERO      : boolean                         := false
	);
	port (
		iDCLK  : in  std_logic;
		iDWE   : in  std_logic;
		iDADDR : in  integer range 0 to 2**log2DADDR-1;
		iDDATA : in  std_logic_vector(DW-1 downto 0);
		oDDATA : out std_logic_vector(DW-1 downto 0);

		iCLK   : in  std_logic;
		iAADDR : in  integer range 0 to 2**log2DADDR-1;
		oADATA : out std_logic_vector(DW-1 downto 0);
		iBWE   : in  std_logic;
		iBADDR : in  integer range 0 to 2**log2DADDR-1;
		iBDATA : in  std_logic_vector(DW-1 downto 0);
		oBDATA : out std_logic_vector(DW-1 downto 0)
	);
begin
end entity DMEM;

architecture RTL of DMEM is

	-- FIXME: ISE 13.2 does not support "protected"... :(
	type tBANK is (BANK_D, BANK_B);
	type tLVT is array (0 to 2**log2DADDR-1) of tBANK;
	shared variable aLVT : tLVT := (0 to 2**log2DADDR-1 => BANK_D);

	signal sDMEM_PRIM_D_oDDATA : std_logic_vector(DW-1 downto 0);
	signal sDMEM_PRIM_D_oADATA : std_logic_vector(DW-1 downto 0);
	signal sDMEM_PRIM_D_oBDATA : std_logic_vector(DW-1 downto 0);

	signal sDMEM_PRIM_B_oDDATA : std_logic_vector(DW-1 downto 0);
	signal sDMEM_PRIM_B_oADATA : std_logic_vector(DW-1 downto 0);
	signal sDMEM_PRIM_B_oBDATA : std_logic_vector(DW-1 downto 0);

begin

	P_LVT_D : process (iDCLK)
	begin
		if (rising_edge(iDCLK)) then
			if (iDWE = '1') then
				aLVT(iDADDR) := BANK_D;
			end if;
		end if;
	end process P_LVT_D;

	P_LVT_B : process (iCLK)
	begin
		if (rising_edge(iCLK)) then
			if (iBWE = '1') then
				aLVT(iBADDR) := BANK_B;
			end if;
		end if;
	end process P_LVT_B;

	U_DMEM_PRIM_D : DMEM_PRIM
	generic map (
		log2A => log2DADDR,
		DW    => DW,
		ZERO  => ZERO
	)
	port map (
		iWCLK  => iDCLK,
		iWE    => iDWE,
		iWA    => iDADDR,
		iWD    => iDDATA,

		iRA0   => iDADDR,
		iRA1   => iAADDR,
		iRA2   => iBADDR,
		oRD0   => sDMEM_PRIM_D_oDDATA,
		oRD1   => sDMEM_PRIM_D_oADATA,
		oRD2   => sDMEM_PRIM_D_oBDATA
	);

	U_DMEM_PRIM_B : DMEM_PRIM
	generic map (
		log2A => log2DADDR,
		DW    => DW,
		ZERO  => ZERO
	)
	port map (
		iWCLK  => iCLK,
		iWE    => iBWE,
		iWA    => iBADDR,
		iWD    => iBDATA,

		iRA0   => iDADDR,
		iRA1   => iAADDR,
		iRA2   => iBADDR,
		oRD0   => sDMEM_PRIM_B_oDDATA,
		oRD1   => sDMEM_PRIM_B_oADATA,
		oRD2   => sDMEM_PRIM_B_oBDATA
	);

	oDDATA <= sDMEM_PRIM_D_oDDATA when (aLVT(iDADDR) = BANK_D) else sDMEM_PRIM_B_oDDATA;
	oADATA <= sDMEM_PRIM_D_oADATA when (aLVT(iAADDR) = BANK_D) else sDMEM_PRIM_B_oADATA;
	oBDATA <= sDMEM_PRIM_D_oBDATA when (aLVT(iBADDR) = BANK_D) else sDMEM_PRIM_B_oBDATA;

end architecture RTL;