1 |
2 |
mikel262 |
--------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- V H D L F I L E --
|
4 |
|
|
-- COPYRIGHT (C) 2006 --
|
5 |
|
|
-- --
|
6 |
|
|
--------------------------------------------------------------------------------
|
7 |
|
|
--
|
8 |
|
|
-- Title : DCT1D
|
9 |
|
|
-- Design : MDCT Core
|
10 |
|
|
-- Author : Michal Krepa
|
11 |
|
|
--
|
12 |
|
|
--------------------------------------------------------------------------------
|
13 |
|
|
--
|
14 |
|
|
-- File : DCT1D.VHD
|
15 |
|
|
-- Created : Sat Mar 5 7:37 2006
|
16 |
|
|
--
|
17 |
|
|
--------------------------------------------------------------------------------
|
18 |
|
|
--
|
19 |
|
|
-- Description : 1D Discrete Cosine Transform (1st stage)
|
20 |
|
|
--
|
21 |
|
|
--------------------------------------------------------------------------------
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
library IEEE;
|
25 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
26 |
|
|
use IEEE.NUMERIC_STD.all;
|
27 |
|
|
|
28 |
|
|
library WORK;
|
29 |
|
|
use WORK.MDCT_PKG.all;
|
30 |
|
|
|
31 |
|
|
--------------------------------------------------------------------------------
|
32 |
|
|
-- ENTITY
|
33 |
|
|
--------------------------------------------------------------------------------
|
34 |
|
|
entity DCT1D is
|
35 |
|
|
port(
|
36 |
|
|
clk : in STD_LOGIC;
|
37 |
|
|
rst : in std_logic;
|
38 |
|
|
dcti : in std_logic_vector(IP_W-1 downto 0);
|
39 |
|
|
idv : in STD_LOGIC;
|
40 |
|
|
romedatao0 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
41 |
|
|
romedatao1 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
42 |
|
|
romedatao2 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
43 |
|
|
romedatao3 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
44 |
|
|
romedatao4 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
45 |
|
|
romedatao5 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
46 |
|
|
romedatao6 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
47 |
|
|
romedatao7 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
48 |
|
|
romedatao8 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
49 |
|
|
romodatao0 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
50 |
|
|
romodatao1 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
51 |
|
|
romodatao2 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
52 |
|
|
romodatao3 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
53 |
|
|
romodatao4 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
54 |
|
|
romodatao5 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
55 |
|
|
romodatao6 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
56 |
|
|
romodatao7 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
57 |
|
|
romodatao8 : in STD_LOGIC_VECTOR(ROMDATA_W-1 downto 0);
|
58 |
|
|
reqwrfail : in STD_LOGIC;
|
59 |
|
|
|
60 |
|
|
ready : out STD_LOGIC; -- read from FIFO
|
61 |
|
|
odv : out STD_LOGIC;
|
62 |
|
|
dcto : out std_logic_vector(OP_W-1 downto 0);
|
63 |
|
|
romeaddro0 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
64 |
|
|
romeaddro1 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
65 |
|
|
romeaddro2 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
66 |
|
|
romeaddro3 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
67 |
|
|
romeaddro4 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
68 |
|
|
romeaddro5 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
69 |
|
|
romeaddro6 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
70 |
|
|
romeaddro7 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
71 |
|
|
romeaddro8 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
72 |
|
|
romoaddro0 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
73 |
|
|
romoaddro1 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
74 |
|
|
romoaddro2 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
75 |
|
|
romoaddro3 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
76 |
|
|
romoaddro4 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
77 |
|
|
romoaddro5 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
78 |
|
|
romoaddro6 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
79 |
|
|
romoaddro7 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
80 |
|
|
romoaddro8 : out STD_LOGIC_VECTOR(ROMADDR_W-1 downto 0);
|
81 |
|
|
ramwaddro : out STD_LOGIC_VECTOR(RAMADRR_W-1 downto 0);
|
82 |
|
|
ramdatai : out STD_LOGIC_VECTOR(RAMDATA_W-1 downto 0);
|
83 |
|
|
ramwe : out STD_LOGIC;
|
84 |
|
|
requestwr : out STD_LOGIC;
|
85 |
|
|
releasewr : out STD_LOGIC
|
86 |
|
|
);
|
87 |
|
|
end DCT1D;
|
88 |
|
|
|
89 |
|
|
--------------------------------------------------------------------------------
|
90 |
|
|
-- ARCHITECTURE
|
91 |
|
|
--------------------------------------------------------------------------------
|
92 |
|
|
architecture RTL of DCT1D is
|
93 |
|
|
|
94 |
|
|
type STATE_T is
|
95 |
|
|
(
|
96 |
|
|
IDLE,
|
97 |
|
|
GET_ROM,
|
98 |
|
|
SUM,
|
99 |
|
|
WRITE_ODD
|
100 |
|
|
);
|
101 |
|
|
|
102 |
|
|
type ISTATE_T is
|
103 |
|
|
(
|
104 |
|
|
IDLE_I,
|
105 |
|
|
ACQUIRE_1ROW,
|
106 |
|
|
WAITF
|
107 |
|
|
);
|
108 |
|
|
|
109 |
|
|
type INPUT_DATA is array (N-1 downto 0) of SIGNED(IP_W downto 0);
|
110 |
|
|
|
111 |
|
|
signal ready_reg : STD_LOGIC;
|
112 |
|
|
signal databuf_reg : INPUT_DATA;
|
113 |
|
|
signal latchbuf_reg : INPUT_DATA;
|
114 |
|
|
signal col_reg : UNSIGNED(RAMADRR_W/2-1 downto 0);
|
115 |
|
|
signal row_reg : UNSIGNED(RAMADRR_W/2-1 downto 0);
|
116 |
|
|
signal inpcnt_reg : UNSIGNED(2 downto 0);
|
117 |
|
|
signal state_reg : STATE_T;
|
118 |
|
|
signal istate_reg : ISTATE_T;
|
119 |
|
|
signal cnt_reg : UNSIGNED(3 downto 0);
|
120 |
|
|
signal ramdatai_s : STD_LOGIC_VECTOR(RAMDATA_W-1 downto 0);
|
121 |
|
|
signal ramwe_s : STD_LOGIC;
|
122 |
|
|
signal latch_done_reg : STD_LOGIC;
|
123 |
|
|
signal requestwr_reg : STD_LOGIC;
|
124 |
|
|
signal releasewr_reg : STD_LOGIC;
|
125 |
|
|
signal ready_prev_reg : STD_LOGIC;
|
126 |
|
|
signal completed_reg : STD_LOGIC;
|
127 |
|
|
signal col_tmp_reg : UNSIGNED(RAMADRR_W/2-1 downto 0);
|
128 |
|
|
begin
|
129 |
|
|
|
130 |
|
|
ready_sg:
|
131 |
|
|
ready <= ready_reg;
|
132 |
|
|
|
133 |
|
|
ramwe_sg:
|
134 |
|
|
ramwe <= ramwe_s;
|
135 |
|
|
|
136 |
|
|
ramdatai_sg:
|
137 |
|
|
ramdatai <= ramdatai_s;
|
138 |
|
|
|
139 |
|
|
-- temporary
|
140 |
|
|
odv_sg:
|
141 |
|
|
odv <= ramwe_s;
|
142 |
|
|
dcto_sg:
|
143 |
|
|
dcto <= ramdatai_s(RAMDATA_W-1) & ramdatai_s(RAMDATA_W-1) & ramdatai_s;
|
144 |
|
|
|
145 |
|
|
releasewr_sg:
|
146 |
|
|
releasewr <= releasewr_reg;
|
147 |
|
|
requestwr_sg:
|
148 |
|
|
requestwr <= requestwr_reg;
|
149 |
|
|
|
150 |
|
|
--------------------------------------
|
151 |
|
|
-- PROCESS
|
152 |
|
|
--------------------------------------
|
153 |
|
|
GET_PROC : process(rst,clk)
|
154 |
|
|
begin
|
155 |
|
|
if rst = '1' then
|
156 |
|
|
inpcnt_reg <= (others => '0');
|
157 |
|
|
ready_reg <= '0';
|
158 |
|
|
latchbuf_reg <= (others => (others => '0'));
|
159 |
|
|
istate_reg <= IDLE_I;
|
160 |
|
|
latch_done_reg <= '0';
|
161 |
|
|
requestwr_reg <= '0';
|
162 |
|
|
ready_prev_reg <= '0';
|
163 |
|
|
elsif clk = '1' and clk'event then
|
164 |
|
|
|
165 |
|
|
ready_prev_reg <= ready_reg;
|
166 |
|
|
|
167 |
|
|
case istate_reg is
|
168 |
|
|
|
169 |
|
|
when IDLE_I =>
|
170 |
|
|
if idv = '1' then
|
171 |
|
|
requestwr_reg <= '1';
|
172 |
|
|
end if;
|
173 |
|
|
if requestwr_reg = '1' then
|
174 |
|
|
requestwr_reg <= '0';
|
175 |
|
|
istate_reg <= ACQUIRE_1ROW;
|
176 |
|
|
end if;
|
177 |
|
|
|
178 |
|
|
when ACQUIRE_1ROW =>
|
179 |
|
|
|
180 |
|
|
if idv = '1' then
|
181 |
|
|
-- read next data from input FIFO
|
182 |
|
|
ready_reg <= '1';
|
183 |
|
|
|
184 |
|
|
if ready_reg = '1' then
|
185 |
|
|
-- right shift input data
|
186 |
|
|
latchbuf_reg(N-2 downto 0) <= latchbuf_reg(N-1 downto 1);
|
187 |
|
|
latchbuf_reg(N-1) <= SIGNED('0' & dcti) - LEVEL_SHIFT;
|
188 |
|
|
|
189 |
|
|
inpcnt_reg <= inpcnt_reg + 1;
|
190 |
|
|
|
191 |
|
|
if inpcnt_reg = N-1 then
|
192 |
|
|
latch_done_reg <= '1';
|
193 |
|
|
ready_reg <= '0';
|
194 |
|
|
istate_reg <= WAITF;
|
195 |
|
|
end if;
|
196 |
|
|
end if;
|
197 |
|
|
else
|
198 |
|
|
ready_reg <= '0';
|
199 |
|
|
end if;
|
200 |
|
|
|
201 |
|
|
-- failure to allocate any memory buffer
|
202 |
|
|
if reqwrfail = '1' then
|
203 |
|
|
-- restart allocation procedure
|
204 |
|
|
istate_reg <= IDLE_I;
|
205 |
|
|
ready_reg <= '0';
|
206 |
|
|
end if;
|
207 |
|
|
|
208 |
|
|
when WAITF =>
|
209 |
|
|
-- wait until DCT1D_PROC process 1D DCT computation
|
210 |
|
|
-- before latching new 8 input words
|
211 |
|
|
if state_reg = IDLE then
|
212 |
|
|
latch_done_reg <= '0';
|
213 |
|
|
if completed_reg = '1' then
|
214 |
|
|
istate_reg <= IDLE_I;
|
215 |
|
|
else
|
216 |
|
|
istate_reg <= ACQUIRE_1ROW;
|
217 |
|
|
end if;
|
218 |
|
|
end if;
|
219 |
|
|
when others =>
|
220 |
|
|
istate_reg <= IDLE_I;
|
221 |
|
|
end case;
|
222 |
|
|
end if;
|
223 |
|
|
end process;
|
224 |
|
|
|
225 |
|
|
--------------------------------------
|
226 |
|
|
-- PROCESS
|
227 |
|
|
--------------------------------------
|
228 |
|
|
DCT1D_PROC: process(rst, clk)
|
229 |
|
|
begin
|
230 |
|
|
if rst = '1' then
|
231 |
|
|
col_reg <= (others => '0');
|
232 |
|
|
row_reg <= (others => '0');
|
233 |
|
|
state_reg <= IDLE;
|
234 |
|
|
cnt_reg <= (others => '0');
|
235 |
|
|
databuf_reg <= (others => (others => '0'));
|
236 |
|
|
romeaddro0 <= (others => '0');
|
237 |
|
|
romeaddro1 <= (others => '0');
|
238 |
|
|
romeaddro2 <= (others => '0');
|
239 |
|
|
romeaddro3 <= (others => '0');
|
240 |
|
|
romeaddro4 <= (others => '0');
|
241 |
|
|
romeaddro5 <= (others => '0');
|
242 |
|
|
romeaddro6 <= (others => '0');
|
243 |
|
|
romeaddro7 <= (others => '0');
|
244 |
|
|
romeaddro8 <= (others => '0');
|
245 |
|
|
romoaddro0 <= (others => '0');
|
246 |
|
|
romoaddro1 <= (others => '0');
|
247 |
|
|
romoaddro2 <= (others => '0');
|
248 |
|
|
romoaddro3 <= (others => '0');
|
249 |
|
|
romoaddro4 <= (others => '0');
|
250 |
|
|
romoaddro5 <= (others => '0');
|
251 |
|
|
romoaddro6 <= (others => '0');
|
252 |
|
|
romoaddro7 <= (others => '0');
|
253 |
|
|
romoaddro8 <= (others => '0');
|
254 |
|
|
ramwaddro <= (others => '0');
|
255 |
|
|
ramdatai_s <= (others => '0');
|
256 |
|
|
ramwe_s <= '0';
|
257 |
|
|
releasewr_reg <= '0';
|
258 |
|
|
completed_reg <= '0';
|
259 |
|
|
col_tmp_reg <= (others => '0');
|
260 |
|
|
elsif rising_edge(clk) then
|
261 |
|
|
|
262 |
|
|
case state_reg is
|
263 |
|
|
|
264 |
|
|
----------------------
|
265 |
|
|
-- wait for input data
|
266 |
|
|
----------------------
|
267 |
|
|
when IDLE =>
|
268 |
|
|
|
269 |
|
|
releasewr_reg <= '0';
|
270 |
|
|
ramwe_s <= '0';
|
271 |
|
|
-- wait until 8 input words are latched in latchbuf_reg
|
272 |
|
|
-- by GET_PROC
|
273 |
|
|
if latch_done_reg = '1' then
|
274 |
|
|
completed_reg <= '0';
|
275 |
|
|
-- after this sum databuf_reg is in range of -256 to 254 (min to max)
|
276 |
|
|
databuf_reg(0) <= latchbuf_reg(0)+latchbuf_reg(7);
|
277 |
|
|
databuf_reg(1) <= latchbuf_reg(1)+latchbuf_reg(6);
|
278 |
|
|
databuf_reg(2) <= latchbuf_reg(2)+latchbuf_reg(5);
|
279 |
|
|
databuf_reg(3) <= latchbuf_reg(3)+latchbuf_reg(4);
|
280 |
|
|
databuf_reg(4) <= latchbuf_reg(0)-latchbuf_reg(7);
|
281 |
|
|
databuf_reg(5) <= latchbuf_reg(1)-latchbuf_reg(6);
|
282 |
|
|
databuf_reg(6) <= latchbuf_reg(2)-latchbuf_reg(5);
|
283 |
|
|
databuf_reg(7) <= latchbuf_reg(3)-latchbuf_reg(4);
|
284 |
|
|
state_reg <= GET_ROM;
|
285 |
|
|
end if;
|
286 |
|
|
|
287 |
|
|
----------------------
|
288 |
|
|
-- get MAC results from ROM even and ROM odd memories
|
289 |
|
|
----------------------
|
290 |
|
|
when GET_ROM =>
|
291 |
|
|
|
292 |
|
|
ramwe_s <='0';
|
293 |
|
|
|
294 |
|
|
-- read precomputed MAC results from LUT
|
295 |
|
|
romeaddro0 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
296 |
|
|
databuf_reg(0)(0) &
|
297 |
|
|
databuf_reg(1)(0) &
|
298 |
|
|
databuf_reg(2)(0) &
|
299 |
|
|
databuf_reg(3)(0);
|
300 |
|
|
romeaddro1 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
301 |
|
|
databuf_reg(0)(1) &
|
302 |
|
|
databuf_reg(1)(1) &
|
303 |
|
|
databuf_reg(2)(1) &
|
304 |
|
|
databuf_reg(3)(1);
|
305 |
|
|
romeaddro2 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
306 |
|
|
databuf_reg(0)(2) &
|
307 |
|
|
databuf_reg(1)(2) &
|
308 |
|
|
databuf_reg(2)(2) &
|
309 |
|
|
databuf_reg(3)(2);
|
310 |
|
|
romeaddro3 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
311 |
|
|
databuf_reg(0)(3) &
|
312 |
|
|
databuf_reg(1)(3) &
|
313 |
|
|
databuf_reg(2)(3) &
|
314 |
|
|
databuf_reg(3)(3);
|
315 |
|
|
romeaddro4 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
316 |
|
|
databuf_reg(0)(4) &
|
317 |
|
|
databuf_reg(1)(4) &
|
318 |
|
|
databuf_reg(2)(4) &
|
319 |
|
|
databuf_reg(3)(4);
|
320 |
|
|
romeaddro5 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
321 |
|
|
databuf_reg(0)(5) &
|
322 |
|
|
databuf_reg(1)(5) &
|
323 |
|
|
databuf_reg(2)(5) &
|
324 |
|
|
databuf_reg(3)(5);
|
325 |
|
|
romeaddro6 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
326 |
|
|
databuf_reg(0)(6) &
|
327 |
|
|
databuf_reg(1)(6) &
|
328 |
|
|
databuf_reg(2)(6) &
|
329 |
|
|
databuf_reg(3)(6);
|
330 |
|
|
romeaddro7 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
331 |
|
|
databuf_reg(0)(7) &
|
332 |
|
|
databuf_reg(1)(7) &
|
333 |
|
|
databuf_reg(2)(7) &
|
334 |
|
|
databuf_reg(3)(7);
|
335 |
|
|
romeaddro8 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
336 |
|
|
databuf_reg(0)(8) &
|
337 |
|
|
databuf_reg(1)(8) &
|
338 |
|
|
databuf_reg(2)(8) &
|
339 |
|
|
databuf_reg(3)(8);
|
340 |
|
|
|
341 |
|
|
state_reg <= SUM;
|
342 |
|
|
|
343 |
|
|
---------------------
|
344 |
|
|
-- do distributed arithmetic sum on even part,
|
345 |
|
|
-- write even part to RAM
|
346 |
|
|
---------------------
|
347 |
|
|
when SUM =>
|
348 |
|
|
|
349 |
|
|
ramdatai_s <= STD_LOGIC_VECTOR(RESIZE
|
350 |
|
|
(RESIZE(SIGNED(romedatao0),DA_W) +
|
351 |
|
|
(RESIZE(SIGNED(romedatao1),DA_W-1) & '0') +
|
352 |
|
|
(RESIZE(SIGNED(romedatao2),DA_W-2) & "00") +
|
353 |
|
|
(RESIZE(SIGNED(romedatao3),DA_W-3) & "000") +
|
354 |
|
|
(RESIZE(SIGNED(romedatao4),DA_W-4) & "0000") +
|
355 |
|
|
(RESIZE(SIGNED(romedatao5),DA_W-5) & "00000") +
|
356 |
|
|
(RESIZE(SIGNED(romedatao6),DA_W-6) & "000000") +
|
357 |
|
|
(RESIZE(SIGNED(romedatao7),DA_W-7) & "0000000") -
|
358 |
|
|
(RESIZE(SIGNED(romedatao8),DA_W-8) & "00000000"),DA_W)(DA_W-1 downto 12));
|
359 |
|
|
|
360 |
|
|
-- write even part
|
361 |
|
|
ramwe_s <= '1';
|
362 |
|
|
-- reverse col/row order for transposition purpose
|
363 |
|
|
ramwaddro <= STD_LOGIC_VECTOR(col_reg & row_reg);
|
364 |
|
|
|
365 |
|
|
col_reg <= col_reg + 1;
|
366 |
|
|
col_tmp_reg <= col_reg + 2;
|
367 |
|
|
|
368 |
|
|
romoaddro0 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
369 |
|
|
databuf_reg(4)(0) &
|
370 |
|
|
databuf_reg(5)(0) &
|
371 |
|
|
databuf_reg(6)(0) &
|
372 |
|
|
databuf_reg(7)(0);
|
373 |
|
|
romoaddro1 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
374 |
|
|
databuf_reg(4)(1) &
|
375 |
|
|
databuf_reg(5)(1) &
|
376 |
|
|
databuf_reg(6)(1) &
|
377 |
|
|
databuf_reg(7)(1);
|
378 |
|
|
romoaddro2 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
379 |
|
|
databuf_reg(4)(2) &
|
380 |
|
|
databuf_reg(5)(2) &
|
381 |
|
|
databuf_reg(6)(2) &
|
382 |
|
|
databuf_reg(7)(2);
|
383 |
|
|
romoaddro3 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
384 |
|
|
databuf_reg(4)(3) &
|
385 |
|
|
databuf_reg(5)(3) &
|
386 |
|
|
databuf_reg(6)(3) &
|
387 |
|
|
databuf_reg(7)(3);
|
388 |
|
|
romoaddro4 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
389 |
|
|
databuf_reg(4)(4) &
|
390 |
|
|
databuf_reg(5)(4) &
|
391 |
|
|
databuf_reg(6)(4) &
|
392 |
|
|
databuf_reg(7)(4);
|
393 |
|
|
romoaddro5 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
394 |
|
|
databuf_reg(4)(5) &
|
395 |
|
|
databuf_reg(5)(5) &
|
396 |
|
|
databuf_reg(6)(5) &
|
397 |
|
|
databuf_reg(7)(5);
|
398 |
|
|
romoaddro6 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
399 |
|
|
databuf_reg(4)(6) &
|
400 |
|
|
databuf_reg(5)(6) &
|
401 |
|
|
databuf_reg(6)(6) &
|
402 |
|
|
databuf_reg(7)(6);
|
403 |
|
|
romoaddro7 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
404 |
|
|
databuf_reg(4)(7) &
|
405 |
|
|
databuf_reg(5)(7) &
|
406 |
|
|
databuf_reg(6)(7) &
|
407 |
|
|
databuf_reg(7)(7);
|
408 |
|
|
romoaddro8 <= STD_LOGIC_VECTOR(col_reg(RAMADRR_W/2-1 downto 1)) &
|
409 |
|
|
databuf_reg(4)(8) &
|
410 |
|
|
databuf_reg(5)(8) &
|
411 |
|
|
databuf_reg(6)(8) &
|
412 |
|
|
databuf_reg(7)(8);
|
413 |
|
|
state_reg <= WRITE_ODD;
|
414 |
|
|
|
415 |
|
|
---------------------
|
416 |
|
|
-- do distributed arithmetic sum on odd part,
|
417 |
|
|
-- write odd part to RAM
|
418 |
|
|
---------------------
|
419 |
|
|
when WRITE_ODD =>
|
420 |
|
|
|
421 |
|
|
-- write odd part
|
422 |
|
|
--ramwe_s <= '1';
|
423 |
|
|
|
424 |
|
|
ramdatai_s <= STD_LOGIC_VECTOR(RESIZE
|
425 |
|
|
(RESIZE(SIGNED(romodatao0),DA_W) +
|
426 |
|
|
(RESIZE(SIGNED(romodatao1),DA_W-1) & '0') +
|
427 |
|
|
(RESIZE(SIGNED(romodatao2),DA_W-2) & "00") +
|
428 |
|
|
(RESIZE(SIGNED(romodatao3),DA_W-3) & "000") +
|
429 |
|
|
(RESIZE(SIGNED(romodatao4),DA_W-4) & "0000") +
|
430 |
|
|
(RESIZE(SIGNED(romodatao5),DA_W-5) & "00000") +
|
431 |
|
|
(RESIZE(SIGNED(romodatao6),DA_W-6) & "000000") +
|
432 |
|
|
(RESIZE(SIGNED(romodatao7),DA_W-7) & "0000000") -
|
433 |
|
|
(RESIZE(SIGNED(romodatao8),DA_W-8) & "00000000"),
|
434 |
|
|
DA_W)(DA_W-1 downto 12));
|
435 |
|
|
|
436 |
|
|
-- write odd part
|
437 |
|
|
-- reverse col/row order for transposition purpose
|
438 |
|
|
ramwaddro <= STD_LOGIC_VECTOR(col_reg & row_reg);
|
439 |
|
|
|
440 |
|
|
-- move to next column
|
441 |
|
|
col_reg <= col_reg + 1;
|
442 |
|
|
|
443 |
|
|
-- finished processing one input row
|
444 |
|
|
if col_reg = N - 1 then
|
445 |
|
|
row_reg <= row_reg + 1;
|
446 |
|
|
col_reg <= (others => '0');
|
447 |
|
|
if row_reg = N - 1 then
|
448 |
|
|
releasewr_reg <= '1';
|
449 |
|
|
completed_reg <= '1';
|
450 |
|
|
end if;
|
451 |
|
|
state_reg <= IDLE;
|
452 |
|
|
else
|
453 |
|
|
|
454 |
|
|
-- read precomputed MAC results from LUT
|
455 |
|
|
romeaddro0 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
456 |
|
|
databuf_reg(0)(0) &
|
457 |
|
|
databuf_reg(1)(0) &
|
458 |
|
|
databuf_reg(2)(0) &
|
459 |
|
|
databuf_reg(3)(0);
|
460 |
|
|
romeaddro1 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
461 |
|
|
databuf_reg(0)(1) &
|
462 |
|
|
databuf_reg(1)(1) &
|
463 |
|
|
databuf_reg(2)(1) &
|
464 |
|
|
databuf_reg(3)(1);
|
465 |
|
|
romeaddro2 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
466 |
|
|
databuf_reg(0)(2) &
|
467 |
|
|
databuf_reg(1)(2) &
|
468 |
|
|
databuf_reg(2)(2) &
|
469 |
|
|
databuf_reg(3)(2);
|
470 |
|
|
romeaddro3 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
471 |
|
|
databuf_reg(0)(3) &
|
472 |
|
|
databuf_reg(1)(3) &
|
473 |
|
|
databuf_reg(2)(3) &
|
474 |
|
|
databuf_reg(3)(3);
|
475 |
|
|
romeaddro4 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
476 |
|
|
databuf_reg(0)(4) &
|
477 |
|
|
databuf_reg(1)(4) &
|
478 |
|
|
databuf_reg(2)(4) &
|
479 |
|
|
databuf_reg(3)(4);
|
480 |
|
|
romeaddro5 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
481 |
|
|
databuf_reg(0)(5) &
|
482 |
|
|
databuf_reg(1)(5) &
|
483 |
|
|
databuf_reg(2)(5) &
|
484 |
|
|
databuf_reg(3)(5);
|
485 |
|
|
romeaddro6 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
486 |
|
|
databuf_reg(0)(6) &
|
487 |
|
|
databuf_reg(1)(6) &
|
488 |
|
|
databuf_reg(2)(6) &
|
489 |
|
|
databuf_reg(3)(6);
|
490 |
|
|
romeaddro7 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
491 |
|
|
databuf_reg(0)(7) &
|
492 |
|
|
databuf_reg(1)(7) &
|
493 |
|
|
databuf_reg(2)(7) &
|
494 |
|
|
databuf_reg(3)(7);
|
495 |
|
|
romeaddro8 <= STD_LOGIC_VECTOR(col_tmp_reg(RAMADRR_W/2-1 downto 1)) &
|
496 |
|
|
databuf_reg(0)(8) &
|
497 |
|
|
databuf_reg(1)(8) &
|
498 |
|
|
databuf_reg(2)(8) &
|
499 |
|
|
databuf_reg(3)(8);
|
500 |
|
|
|
501 |
|
|
state_reg <= SUM;
|
502 |
|
|
|
503 |
|
|
end if;
|
504 |
|
|
--------------------------------
|
505 |
|
|
-- OTHERS
|
506 |
|
|
--------------------------------
|
507 |
|
|
when others =>
|
508 |
|
|
state_reg <= IDLE;
|
509 |
|
|
end case;
|
510 |
|
|
end if;
|
511 |
|
|
end process;
|
512 |
|
|
|
513 |
|
|
end RTL;
|
514 |
|
|
--------------------------------------------------------------------------------
|