OpenCores
URL https://opencores.org/ocsvn/mytwoqcache/mytwoqcache/trunk

Subversion Repositories mytwoqcache

[/] [mytwoqcache/] [trunk/] [2QCache.vhd] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 gerhardhoh
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    07:41:47 12/14/2010 
6
-- Design Name: 
7
-- Module Name:    Cache - Rtl 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE, work;
21
use IEEE.std_logic_1164.all;
22
use IEEE.std_logic_arith.all;
23
use work.global.all;
24 6 gerhardhoh
 
25 8 gerhardhoh
---- Uncomment the following library declaration if instantiating
26
---- any Xilinx primitives in this code.
27
--library UNISIM;
28
--use UNISIM.VComponents.all;
29 6 gerhardhoh
 
30 8 gerhardhoh
entity Cache is
31
  generic( constant blocksizeld: integer := 11;
32
                          constant ldways: integer := 1;
33
                          constant ldCachedWords: integer := 2);
34
  port( nReset: in std_ulogic;                                          -- System reset active low
35
        Clock: in std_ulogic;                                           -- System Clock
36
                  AddressIn: in std_ulogic_vector(RAMrange'high + 1 downto 0);    -- Address of memory fetch
37
                  DataIn: in std_ulogic_vector( 31 downto 0);                     -- Data to write
38
             IOCode: in std_ulogic_vector(2 downto 0);                                           -- operation
39
                                                                                  -- Bit
40
                                                                                                                                                                                                --  2    0 read
41
                                                                                                                                                                                                --       1 write
42
                                                                                                                                                                                                -- 1 0   11 word
43
                                                                                                                                                                                                --       10 halfword
44
                                                                                                                                                                                                --       01 single byte
45
                                                                                                                                                                                                --       00 no operation
46
                  DataOut: out std_ulogic_vector( 31 downto 0);                   -- Data read
47
                  done: out std_ulogic;
48
                  -- memory interface
49
                  AddressOut: out std_ulogic_vector(RAMrange'high downto 0);        -- memory address
50
                  DataBlockIn: in std_ulogic_vector( 2 ** ldCachedWords * 32 - 1 downto 0);   -- data from memory
51
                  reads: out std_ulogic;                                                      -- read memory
52
                  DataBlockOut: out std_ulogic_vector( 2 ** ldCachedWords * 32 - 1 downto 0); -- data to memory
53
                  Mask: out std_ulogic_vector( 2 ** ldCachedWords * 4 - 1 downto 0);          -- enables for each byte active low
54
                  writes: out std_ulogic;                                                     -- write memory
55
                  ack: in std_ulogic                                                          -- acknowledge from memory
56
                );
57
end Cache;
58 6 gerhardhoh
 
59 8 gerhardhoh
architecture Rtl of Cache is
60
constant ways: integer := 2 ** ldways;
61
constant ldram: integer := blocksizeld + ldways - 1;
62
constant ldqueuelength: integer := ldram;
63
 
64
type IOType is ( Start, busy);
65
type tType is ( inittag, startt, startt1, tagtest, tagwait, stateget, stateget1, finish, finished);
66
type rType is ( raminit, ramstart, ramstart1, ramcheck, ramcheck1, ramcheck2, ramread, ramread1, ramupdate,
67
                ramupdate1, ramupdate2, ramupdate3, ramflush, ramflush1, ramwait, ramwait1, ramclean, ramclean1);
68
type fType is ( queuestart, queuewait, queuewaitAm1, queuewaitAm2, queuewaitA11, queuewaitA12, queueelim);
69
subtype myint is natural range 15 downto 0;
70
type TagRAMType is record
71
  cacheAddr: std_ulogic_vector( ldram - 1 downto 0);
72
  cacheValid: std_ulogic;
73
  Tag: std_ulogic_vector( RAMrange'high downto 2 + ldCachedWords + blocksizeld);
74
  TagValid: std_ulogic;
75
end record;
76
type WordType is record
77
  Word: std_ulogic_vector(31 downto 0);
78
  Modified: std_ulogic_vector( 3 downto 0);
79
end record;
80
type WordArray is array ( 2 ** ldCachedWords - 1 downto 0) of WordType;
81
type CacheType is record
82
  Words: WordArray;
83
  FiFoaddr: std_ulogic_vector( ldqueuelength - 1 downto 0);
84
  Am: std_ulogic;                                                        -- redifined and renamed
85
end record;
86
type FiFoType is record
87
  Word: std_ulogic_vector( blocksizeld - 1 downto 0);
88
  way: std_ulogic_vector( ldways downto 0);
89
  valid: std_ulogic;
90
end record;
91
 
92
type TagRAMarray is array ( ways - 1 downto 0) of TagRAMType;
93
type TagBuffer is array ( ways - 1 downto 0) of std_ulogic_vector( RAMrange'high - ldCachedWords - blocksizeld - 2 + ldram + 2 downto 0);
94
type TagFile is array ( 2 ** blocksizeld - 1 downto 0) of std_ulogic_vector( RAMrange'high - ldCachedWords - blocksizeld - 2 + ldram + 2 downto 0);
95
type TagFiles is array ( ways - 1 downto 0) of TagFile;
96
 
97
type RAMFile is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( 35 downto 0);
98
type RAMFiles is array ( 2 ** ldCachedWords - 1 downto 0) of RAMFile;
99
type RAMBuffer is array ( 2 ** ldCachedWords - 1 downto 0) of std_ulogic_vector( 35 downto 0);
100
type AFile is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( ldqueuelength downto 0); -- redimensioned
101
 
102
type myarrayf is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( ldram - 1 downto 0);
103
type myarrayA is array ( 2 ** ldram - 1 downto 0) of std_ulogic_vector( blocksizeld + ldways + 1 downto 0);
104
 
105
signal RAMs: RAMFiles;
106
signal Ax: AFile;
107
signal tagRAM: TagFiles;
108
signal tagdummy, tagBuff, TagRAMIn, TagRAMOut: TagRAMarray;
109
signal RecBuff, CacheIn, CacheOut: CacheType;
110
signal blockIn, blockOut: WordArray;
111
signal DataInh: std_ulogic_vector( 31 downto 0);
112
signal A1In, A1Out, AmIn, AmOut: FiFoType;
113
signal putA1, removeA1, getA1, emptyA1, fullA1: std_ulogic;
114
signal putAm, removeAm, getAm, emptyAm, fullAm: std_ulogic;
115
signal A1Inaddr, A1Outaddr, AmInaddr, AmOutaddr: std_ulogic_vector( ldqueuelength - 1 downto 0);
116
signal emptyf, getf, putf: std_ulogic;
117
signal cindex, FreeOut, FreeIn: std_ulogic_vector( ldram - 1 downto 0);
118
signal ramf: myarrayf;
119
signal counterf: unsigned( ldram downto 0);
120
signal firstf, lastf: unsigned( ldram - 1 downto 0);
121
signal newFiFoAddr: std_ulogic_vector( ldqueuelength - 1 downto 0);
122
signal newAm: std_ulogic;  -- redifined and renamed
123
signal initcount: unsigned( blocksizeld - 1 downto 0);
124
signal initcount1: unsigned( ldram - 1 downto 0);
125
signal ramA1: myarrayA;
126
signal counterA1: unsigned( ldqueuelength downto 0);
127
signal firstA1, lastA1: unsigned( ldqueuelength - 1 downto 0);
128
signal ramAm: myarrayA;
129
signal counterAm: unsigned( ldqueuelength downto 0);
130
signal firstAm, lastAm: unsigned( ldqueuelength - 1 downto 0);
131
 
132
signal AddressInh: std_ulogic_vector( AddressIn'high -1 downto 0);
133
signal IOCodeh: std_ulogic_vector( IOCode'range);
134
signal toFlush, AddressInt: std_ulogic_vector( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
135
signal found, free, elim, del: myint;
136
signal stateIO: IOType;
137
signal statetag: tType;
138
signal stateram: rType;
139
signal statequeue: fType;
140
signal enableram, enablequeue, queuedone, readsh, writesh, doneh, preempted,
141
       interrupt, readb, writeb, writec, writet, accdone, accqueue, accinterrupt: std_ulogic;
142 6 gerhardhoh
 
143 8 gerhardhoh
begin
144
 
145
 
146
 
147
  blockIO: process( nReset, Clock, readb, writeb) is
148
  variable s: std_ulogic;
149
  begin
150
    if nReset /= '1' then
151
           writesh <= '0';
152
                readsh <= '0';
153
                stateIO <= start;
154
    elsif rising_edge(Clock) then
155
           case stateIO is
156
                when start =>
157
                  if readb = '1' then
158
                         Mask <= ( others => '1');
159
                         readsh <= '1';
160
                    stateIO <= busy;
161
                  elsif writeb = '1' then
162
                    s := '0';
163
 
164
                    for i in blockOut'range loop
165
                      DataBlockOut( ( i + 1) * 32 - 1 downto i * 32) <= blockOut( i).word;
166
                           Mask( ( i + 1) * 4 - 1 downto i * 4) <= not blockOut( i).Modified;
167
                                s := s or blockOut( i).Modified(0) or blockOut( i).Modified(1) or
168
                                          blockOut( i).Modified(2) or blockOut( i).Modified(3);
169
                         end loop;
170
 
171
                         writesh <= s;
172
 
173
                         if s = '1' then
174
                      stateIO <= busy;
175
                         end if;
176
                  end if;
177
                when busy =>
178
                  if ack = '1' then
179
                    stateIO <= start;
180
 
181
                    if readsh = '1' then
182
                           for i in blockIn'range loop
183
                        blockIn( i).word <= DataBlockIn( ( i + 1) * 32 - 1 downto i * 32);
184
                                  blockIn( i).Modified <= ( others => '0');
185
                                end loop;
186
                    end if;
187
 
188
                    readsh <= '0';
189
                    writesh <= '0';
190
                  end if;
191
                end case;
192
         end if;
193
  end process blockIO;
194
 
195
  writes <= writesh;
196
  reads <= readsh;
197
 
198
  tagrams: process ( nReset, Clock) is
199
  variable a, b, d: myint;
200
  variable DataInTag, DataOutTag: TagBuffer;
201
  begin
202
  if rising_edge(Clock) then
203
    if nReset /= '1' then
204
           statetag <= inittag;
205
                writet <= '0';
206
                enableram <= '0';
207
                found <= 15;
208
                free <= 15;
209
                done <= '0'; -- NEW
210
                initcount <= ( others => '0');
211
                AddressInt <= ( others => '0');
212
                IOCodeh <= ( others => '0');
213
                AddressInh <= ( others => '0');
214
         else
215
 
216
           case statetag is
217
                  when inittag =>
218
                    for i in tagRAMIn'range loop
219
                           tagRAMIn(i).tagValid <= '0';
220
                           tagRAMIn(i).tag <= ( others => '0');
221
                           tagRAMIn(i).cacheValid <= '0';
222
                           tagRAMIn(i).cacheAddr <= ( others => '0');
223
                         end loop;
224
                         AddressInt <= std_ulogic_vector(initcount);
225
                         initcount <= initcount + 1;
226
                         if unsigned( not AddressInt) = 0 then
227
                      statetag <= startt;
228
                           writet <= '0';
229
                         else
230
                           writet <= '1';
231
                         end if;
232
                  when startt =>
233
                    if IOCode( 1 downto 0) /= "00" and AddressIn( AddressIn'high) = '0' then
234
                      -- request encountered
235
                                AddressInh <= AddressIn(AddressInh'range);
236
                                IOCodeh <= IOCode;
237
                      AddressInt <= AddressIn( AddressInt'range);
238
                                DataInh <= DataIn;
239
                      statetag <= startt1;
240
                    end if;
241
                  when startt1 =>
242
                    statetag <= tagtest;
243
                  when tagtest =>
244
          a := 15;
245
                    b := 15;
246
 
247
               for i in 0 to TagRAMarray'high loop
248
                      if tagRAMOut( i).tagValid = '1' then
249
                   if AddressInh(tagRAMout( i).tag'range) = tagRAMout( i).tag then
250
                          a := i; -- present
251
                                  end if;
252
                      else
253
                             b := i; -- free entry
254
                      end if;
255
               end loop;
256
 
257
                    found <= a;
258
                    free <= b;
259
 
260
                    if stateram = ramstart then
261
                      enableram <= '1';
262
                      statetag <= tagwait;
263
                         end if;
264
                  when tagwait =>
265
                    writet <= '0';
266
 
267
                    if interrupt = '1' then
268
                      enableram <= '0';
269
                           AddressInt <= toFlush;
270
                                statetag <= stateget;
271
                         elsif queuedone = '1' then
272
                      enableram <= '0';
273
                           statetag <= finish;
274
                         end if;
275
                  when stateget =>
276
                         statetag <= stateget1;
277
                  when stateget1 =>
278
                    enableram <= '1';
279
                         tagDummy <= tagRAMOut;
280
 
281
                         for i in tagRAMIn'range loop
282
                           if del = i then
283
                        tagRAMIn( i).tagvalid <= '0';
284
                             tagRAMIn( i).cacheValid <= '0';
285
                             tagRAMIn( i).tag <= ( others => '0');
286
                             tagRAMIn( i).cacheAddr <= ( others => '0');
287
                                  writet <= '1';
288
                           else
289
                             tagRAMIn( i) <= tagRAMOut( i);
290
                           end if;
291
                         end loop;
292
 
293
                         statetag <= tagwait;
294
                  when finish =>
295
                    if doneh = '1' then
296
                           tagRAMIn <= tagBuff;
297
                                writet <= '1';
298
                      AddressInt <= AddressInh( AddressInt'range);
299
                                done <= '1';
300
                      statetag <= finished;
301
                    end if;
302
                  when finished => -- NEW
303
                    writet <= '0';
304
                    done <= '0';
305
                    statetag <= startt;
306
                end case;
307
 
308
         for i in tagRAM'range loop
309
      DataInTag( i) := TagRAMIn( i).TagValid & TagRAMIn( i).Tag & TagRAMIn( i).cacheValid & TagRAMIn( i).cacheAddr;
310
 
311
           if writet = '1' then
312
                  tagRAM(i)(to_integer( AddressInt)) <= DataInTag( i);
313
                else
314
                  DataOutTag( i) := tagRAM(i)(to_integer( AddressInt));
315
 
316
             TagRAMOut( i).cacheAddr <= DataOutTag( i)( ldram - 1 downto 0);
317
             TagRAMOut( i).cacheValid <= DataOutTag( i)( ldram);
318
             TagRAMOut( i).Tag <= DataOutTag( i)( DataOutTag( 0)'high - 1 downto ldram + 1);
319
             TagRAMOut( i).TagValid <= DataOutTag( i)( DataOutTag( 0)'high);
320
                end if;
321
         end loop;
322
         end if;
323
  end if;
324
  end Process tagrams;
325
 
326
  dataram: process (nReset, Clock, enableram) is
327
  variable en, acc, hi: std_ulogic;
328
  variable f, g: std_ulogic_vector( CacheIn.FiFoAddr'length downto 0);
329
  variable a, b: RAMBuffer;
330
  variable index, index1: integer;
331
 
332
  variable address: std_ulogic_vector( ldram - 1 downto 0);
333
  variable uaddress: unsigned( ldram - 1 downto 0);
334
  variable datum:  std_ulogic_vector( FreeIn'range);
335
  variable w: std_ulogic;
336
  begin
337
  if rising_edge(Clock) then
338
    if nReset /= '1' then
339
           enablequeue <= '0';
340
           stateram <= raminit;
341
                writec <= '0';
342
                writeb <= '0';
343
                readb <= '0';
344
                getf <= '0';
345
                putf <= '0'; -- NEW inserted
346
                doneh <= '0';
347
                elim <= 15;
348
                accinterrupt <= '0';
349
                accqueue <= '0';
350
                initcount1 <= ( others => '0');
351
                FreeIn <= ( others => '0');
352
                firstf <= ( others => '0');
353
                lastf <= ( others => '0');
354
                counterf <= ( others => '0');
355
         else
356
           hi := accinterrupt or interrupt;
357
                acc := accqueue or queuedone;
358
                en := enablequeue and ( hi nor acc);
359
 
360
                if ldCachedWords = 0 then
361
                  index := 0;
362
                else
363
                  index := to_integer( AddressInh( ldCachedWords + 1 downto 2));
364
                end if;
365
 
366
           case stateram is
367
                  when raminit =>
368
                         FreeIn <= std_ulogic_vector( initcount1);
369
          initcount1    <= initcount1 + 1;
370
 
371
                         if unsigned( not FreeIn) = 0 then
372
                           stateram <= ramstart;
373
                           putf <= '0';
374
                         else
375
                           putf <= '1';
376
                         end if;
377
                  when ramstart =>
378
                    if enableram = '1' then -- UPDATE
379
                           tagBuff <= tagRAMOut;
380
                                elim <= 15;
381
                                stateram <= ramstart1;
382
                         end if;
383
                  when ramstart1 =>
384
                    if enableram = '1' then
385
                                if found /= 15 then
386
                                  cindex <= tagBuff( found).cacheAddr;
387
                                  stateram <= ramupdate;
388
                                elsif free /= 15 then
389
                                  en := '1';
390
                                  stateram <= ramwait;
391
                                else
392
                                  elim <= 0;
393
                                  stateram <= ramcheck;
394
                                end if;
395
                         end if;
396
                  when ramcheck =>
397
                         cindex <= tagBuff( elim).cacheAddr;
398
                    stateram <= ramcheck1;
399
                  when ramcheck1 =>
400
                    stateram <= ramcheck2;
401
                  when ramcheck2 =>
402
                    if cacheOut.Am = '0' or elim = ways - 1 then
403
                           RecBuff <= cacheOut;
404
                                en := '1';
405
                      stateram <= ramwait;
406
                         else
407
                           elim <= elim + 1;
408
                      stateram <= ramcheck;
409
                         end if;
410
                  when ramupdate =>
411
                    stateram <= ramupdate1;
412
                  when ramupdate1 =>
413
                    cacheIn <= cacheOut;
414
                         blockOut <= cacheOut.Words;
415
                         RecBuff <= cacheOut;
416
                         en := '1';
417
                         stateram <= ramwait;
418
                  when ramwait =>
419
                         doneh <= '0';
420
 
421
                    if hi = '1' then
422
                                stateram <= ramwait1;
423
                         elsif acc = '1' then
424
                           if found /= 15 then
425
                                  cindex <= tagBuff( found).cacheAddr;
426
                                  cacheIn <= RecBuff;
427
                                  blockOut <= RecBuff.Words;
428
                                  stateram <= ramupdate2;
429
                                elsif free /= 15 then
430
                                  cindex <= FreeOut;
431
                                  tagBuff( free).cacheAddr <= FreeOut;
432
                                  tagBuff( free).cacheValid <= '1';
433
                                  tagBuff( free).tag <= AddressInh( tagBuff( free).tag'range);
434
                                  tagBuff( free).tagValid <= '1';
435
                                  getf <= '1';
436
                                  if IOCodeh = "111" and ldCachedWords = 0 then
437
                                    stateram <= ramupdate2;
438
                                  else
439
                                    readb <= '1';
440
                               AddressOut <= AddressInh( AddressOut'range);
441
                                    stateram <= ramread;
442
                                  end if;
443
                                else
444
                                  cindex <= tagBuff( elim).cacheAddr;
445
                                  cacheIn <= RecBuff;
446
                                  blockOut <= RecBuff.Words;
447
                                  AddressOut <= tagBuff( elim).tag & AddressInh( AddressInt'range) & ( ldCachedWords + 1 downto 0 => '0');
448
                        writeb <= '1';
449
                                  stateram <= ramflush;
450
                                end if;
451
                         end if;
452
                  when ramwait1 =>
453
                         if del /= 15 and enableram = '1' then
454
                           cindex <= tagdummy( del).cacheAddr;
455
                                FreeIn <= tagdummy( del).cacheAddr;
456
                                putf <= tagdummy( del).cacheValid;
457
                           stateram <= ramclean;
458
                         end if;
459
                  when ramread =>
460
                    readb <= '0';
461
                         getf <= '0';
462
                    stateram <= ramread1;
463
                  when ramread1 =>
464
                    if readsh = '0' then
465
                           for i in blockIn'range loop
466
                                  cacheIn.Words( i) <= blockIn( i);
467
                                end loop;
468
                      stateram <= ramupdate2;
469
                         end if;
470
                  when ramupdate2 =>
471
                    if IOCodeh(2) = '1' then
472
                           if IOCodeh(1) = '1' then
473
                                  If IOCodeh(0) = '1' then
474
                                    cacheIn.Words( index).Word <= DataInh;
475
                                         cacheIn.Words( index).Modified <= "1111";
476
                                  elsif AddressInh(1) = '1' then
477
                                    cacheIn.Words( index).Word( 31 downto 16) <= DataInh( 15 downto 0);
478
                                         cacheIn.Words( index).Modified( 3 downto 2) <= "11";
479
                                  else
480
                                    cacheIn.Words( index).Word( 15 downto 0) <= DataInh( 15 downto 0);
481
                                         cacheIn.Words( index).Modified( 1 downto 0) <= "11";
482
                                  end if;
483
                                else
484
                                  if AddressInh(1) = '0' then
485
                                    if AddressInh(0) = '0' then
486
                                           cacheIn.Words( index).Word( 7 downto 0) <= DataInh( 7 downto 0);
487
                                                cacheIn.Words( index).Modified(0) <= '1';
488
                                    else
489
                                           cacheIn.Words( index).Word( 15 downto 8) <= DataInh( 7 downto 0);
490
                                                cacheIn.Words( index).Modified(1) <= '1';
491
                                         end if;
492
                                  else
493
                                    if AddressInh(0) = '0' then
494
                                           cacheIn.Words( index).Word( 23 downto 16) <= DataInh( 7 downto 0);
495
                                                cacheIn.Words( index).Modified(2) <= '1';
496
                                    else
497
                                           cacheIn.Words( index).Word( 31 downto 24) <= DataInh( 7 downto 0);
498
                                                cacheIn.Words( index).Modified(3) <= '1';
499
                                         end if;
500
                                  end if;
501
                                end if;
502
                         else
503
                           DataOut <= cacheIn.Words( index).Word;
504
                         end if;
505
 
506
                         cacheIn.FiFoAddr <= newFiFoAddr;
507
                         cacheIn.Am <= newAm;
508
 
509
                         getf <= '0';
510
                         writec <= '1';
511
                         doneh <= '1';
512
 
513
                         stateram <= ramupdate3;
514
                  when ramupdate3 =>
515
                    hi := '0';
516
                         acc := '0';
517
                         en := '0';
518
                         writec <= '0';
519
                    doneh <= '0';
520
                         stateram <= ramstart;
521
                  when ramclean =>
522
                    putf <= '0';
523
                    stateram <= ramclean1;
524
                  when ramclean1 =>
525
                         if del /= 15 then
526
                           blockOut <= cacheOut.words;
527
                                writeb <= tagdummy( del).tagValid;
528
                                AddressOut <= tagdummy( del).tag & toFlush & ( ldCachedWords + 1 downto 0 => '0');
529
                           stateram <= ramflush;
530
                         end if;
531
                  when ramflush =>
532
                    writeb <= '0';
533
                         for i in blockIn'range loop
534
                      cacheIn.Words( i).Word <= ( others => '0');
535
                           cacheIn.Words( i).Modified <= ( others => '0');
536
                         end loop;
537
 
538
                         stateram <= ramflush1;
539
                  when ramflush1 =>
540
                         if writesh = '0' then
541
                           if del /= 15 and hi = '1' then
542
                                  doneh <= '1';
543
                                  en := '1';
544
                                  hi := '0';
545
                             stateram <= ramwait;
546
                                else
547
                                  tagBuff( elim).tag <= AddressInh( tagBuff( elim).tag'range);
548
                                  tagBuff( elim).tagValid <= '1';
549
                                  if IOCodeh = "111" and ldCachedWords = 0 then
550
                                    stateram <= ramupdate2;
551
                                  else
552
                                    readb <= '1';
553
                                    AddressOut <= AddressInh( AddressOut'range);
554
                                    stateram <= ramread;
555
                                  end if;
556
                                end if;
557
                         end if;
558
                end case;
559
 
560
                accinterrupt <= hi;
561
                enablequeue <= en;
562
                accqueue <= acc;
563
 
564
         f := CacheIn.Am & CacheIn.FiFoAddr;
565
         if writec = '1' then
566
           Ax( to_integer( cindex)) <= f;
567
         else
568
           g := Ax( to_integer( cindex));
569
                CacheOut.FiFoAddr <= g( g'high - 1 downto g'low);
570
                CacheOut.Am <= g( g'high);
571
         end if;
572
 
573
         for i in RAMBuffer'range loop
574
           a( i) := CacheIn.Words( i).Modified & CacheIn.Words( i).Word;
575
                if writec = '1' then
576
                  RAMs( i)( to_integer( cindex)) <= a( i);
577
                else
578
                  b( i) := RAMs( i)( to_integer( cindex));
579
                  CacheOut.Words( i).Word <= b( i)( 31 downto 0);
580
                  CacheOut.Words( i).Modified <= b( i)( 35 downto 32);
581
                end if;
582
         end loop;
583
 
584
         if putf = '1' then
585
           address := std_ulogic_vector( firstf);
586
                datum := FreeIn;
587
                firstf <= firstf + 1;
588
                counterf <= counterf + 1;
589
                w := '1';
590
         else
591
           uaddress := lastf;
592
           if getf = '1' and counterf /= 0 then
593
             counterf <= counterf - 1;
594
                  uaddress := uaddress + 1;
595
           end if;
596
                lastf <= uaddress;
597
                address := std_ulogic_vector( uaddress);
598
                w := '0';
599
         end if;
600
 
601
         if w = '1' then
602
           ramf( to_integer( address)) <= datum;
603
         else
604
           FreeOut <= ramf( to_integer( address));
605
         end if;
606
 
607
         end if;
608
  end if;
609
  end process dataram;
610
 
611
  emptyf <= '1' when counterf = 0 else '0';
612
 
613
  queues: process( nReset, Clock, enablequeue) is
614
  variable acc, hi: std_ulogic;
615
  variable A1OutBuff, AmOutBuff: std_ulogic_vector( blocksizeld + ldways + 1 downto 0);
616
  variable addressA1: std_ulogic_vector( ldqueuelength - 1 downto 0);
617
  variable diff, uaddressA1: unsigned( ldqueuelength - 1 downto 0);
618
  variable datumA1:  std_ulogic_vector( A1OutBuff'range);
619
  variable wA1: std_ulogic;
620
  variable addressAm: std_ulogic_vector( ldqueuelength - 1 downto 0);
621
  variable uaddressAm: unsigned( ldqueuelength - 1 downto 0);
622
  variable datumAm:  std_ulogic_vector( AmOutBuff'range);
623
  variable wAm: std_ulogic;
624
  begin
625
  if rising_edge(Clock) then
626
    if nReset /= '1' then
627
                del <= 15;
628
           statequeue <= queuestart;
629
           queuedone <= '0';
630
                interrupt <= '0';
631
                accdone <= '0';
632
                preempted <= '0';
633
                firstA1 <= ( others => '0');
634
                A1Outaddr <= ( others => '0');
635
                lastA1 <= ( others => '0');
636
                counterA1 <= ( others => '0');
637
                firstAm <= ( others => '0');
638
                AmOutaddr <= ( others => '0');
639
                lastAm <= ( others => '0');
640
                counterAm <= ( others => '0');
641
                getA1 <= '0'; -- NEW
642
                getAm <= '0'; -- NEW
643
                removeA1 <= '0'; -- NEW
644
                removeAm <= '0'; -- NEW
645
                putA1 <= '0'; -- NEW
646
                putAm <= '0'; -- NEW
647
         else
648
           hi := '0';
649
                acc := accdone or doneh;
650
 
651
                diff := firstA1 - unsigned( RecBuff.FiFoAddr);
652
 
653
           case statequeue is
654
                  when queuestart =>
655
                         getA1 <= '0';
656
 
657
                    if enablequeue = '1' then
658
                           if found /= 15 then
659
                                  if RecBuff.Am = '1' or                                -- in Am
660
                                    ( RecBuff.Am = '0' and diff( diff'high) = '0') then -- in lower half of A1
661
                                    queuedone <= '1';
662
                                         newFiFoAddr <= RecBuff.FiFoAddr;
663
                                         newAm <= RecBuff.Am;
664
                               statequeue <= queuewait;
665
                                  elsif fullAm = '1' then
666
                                    -- Am full
667
                                         if AmOut.valid = '1' then
668
                                           del <= to_integer( AmOut.way);
669
                                                toFlush <= AmOut.word;
670
                                                getAm <= '1';
671
                                           hi := '1';
672
                                           statequeue <= queuewait;
673
                                         end if;
674
                                  else
675
                                    AmIn.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
676
                                         AmIn.way <= std_ulogic_vector(to_unsigned( found, ldways + 1));
677
                                         AmIn.valid <= '1';
678
                                         putAm <= '1';
679
                                         A1Inaddr <= RecBuff.FiFoAddr;
680
                                         removeA1 <= '1';
681
                                         statequeue <= queuewaitAm1;
682
                                  end if;
683
                                elsif free /= 15 then
684
                                  if fullA1 = '1' or (emptyf = '1' and emptyA1 = '0') then
685
                                    -- remove last entry from A1
686
                                         if A1Out.valid = '1' then
687
                                           del <= to_integer( A1Out.way);
688
                                           toFlush <= A1Out.word;
689
                                           getA1 <= '1';
690
                                           hi := '1';
691
                                           statequeue <= queuewait;
692
                                         end if;
693
                                  elsif fullAm = '1' and emptyf = '1' then
694
                                    -- remove last entry from Am
695
                                         if AmOut.valid = '1' then
696
                                           del <= to_integer( AmOut.way);
697
                                           toFlush <= AmOut.word;
698
                                           getAm <= '1';
699
                                           hi := '1';
700
                                           statequeue <= queuewait;
701
                                         end if;
702
                                  else
703
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
704
                                         A1In.way <= std_ulogic_vector(to_unsigned( free, ldways + 1));
705
                                         A1In.valid <= '1';
706
                                         putA1 <= '1';
707
                                         statequeue <= queuewaitA11;
708
                                  end if;
709
                                elsif elim /= 15 then
710
                                  if fullA1 = '1' then
711
                                    if A1Out.valid = '1' then
712
                                           if not ( to_integer( A1Out.way) = elim and
713
                                                        A1Out.word = AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords)) then
714
                                             del <= to_integer( A1Out.way);
715
                                             toFlush <= A1Out.word;
716
                                             statequeue <= queueelim;
717
                                           end if;
718
 
719
                                           getA1 <= '1';
720
                                         end if;
721
                                  else
722
                                         getA1 <= '0'; -- NEW, inserted the only bug!!!!!!!!!!!!!!
723
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
724
                                         A1In.way <= std_ulogic_vector(to_unsigned( elim, ldways + 1));
725
                                         A1In.valid <= '1';
726
                                         putA1 <= '1';
727
                                         statequeue <= queueelim;
728
                                  end if;
729
                                end if;
730
                         end if;
731
                  when queuewait =>
732
                         removeA1 <= '0';
733
                         removeAm <= '0';
734
                    getAm <= '0';
735
                    getA1 <= '0';
736
                         queuedone <= '0';
737
 
738
               if acc = '1' then
739
                           acc := '0';
740
                                del <= 15;
741
                           statequeue <= queuestart;
742
                         end if;
743
                  when queuewaitAm1 =>
744
                    putAm <= '0';
745
                         removeA1 <= '0';
746
                         statequeue <= queuewaitAm2;
747
                  when queuewaitAm2 =>
748
                         newFiFoAddr <= AmOutAddr;
749
                         newAm <= '1';
750
                         queuedone <= '1';
751
                         statequeue <= queuewait;
752
                  when queuewaitA11 =>
753
                    putA1 <= '0';
754
                         statequeue <= queuewaitA12;
755
                  when queuewaitA12 =>
756
                         newFiFoAddr <= A1OutAddr;
757
                         newAm <= '0';
758
                         removeA1 <= '0';
759
                         removeAm <= '0';
760
                         queuedone <= '1';
761
                    preempted <= '0';
762
                         statequeue <= queuewait;
763
                  when queueelim =>
764
                    putA1 <= '0';
765
                         getA1 <= '0';
766
 
767
                         if RecBuff.Am = '1' and preempted = '0' then
768
                           AmInAddr <= RecBuff.FiFoAddr;
769
                           removeAm <= '1';
770
                         elsif preempted = '0' then
771
                           A1InAddr <= RecBuff.FiFoAddr;
772
                           removeA1 <= '1';
773
                         end if;
774
 
775
                         if getA1 = '1' then
776
                           hi := '1';
777
                                preempted <= '1';
778
                           statequeue <= queuewait;
779
                         else
780
                           statequeue <= queuewaitA12;
781
                         end if;
782
                end case;
783
 
784
                interrupt <= hi;
785
                accdone <= acc;
786
 
787
         if putA1 = '1' or removeA1 = '1' then
788
           if removeA1 = '0' then
789
             addressA1 := std_ulogic_vector( firstA1);
790
                  datumA1 := A1In.valid & A1In.way & A1In.Word;
791
                  firstA1 <= firstA1 + 1;
792
                  counterA1 <= counterA1 + 1;
793
                  A1Outaddr <= std_ulogic_vector( firstA1);
794
                else
795
                  addressA1 := A1Inaddr( addressA1'range);
796
                  datumA1 := ( others => '0');
797
                end if;
798
                wA1 := '1';
799
         else
800
           uaddressA1 := lastA1;
801
           if (getA1 = '1' or A1Out.valid = '0') and counterA1 /= 0 then
802
             counterA1 <= counterA1 - 1;
803
             uaddressA1 := uaddressA1 + 1;
804
           end if;
805
           lastA1 <= uaddressA1;
806
           addressA1 := std_ulogic_vector( uaddressA1);
807
           wA1 := '0';
808
         end if;
809
 
810
         if wA1 = '1' then
811
           ramA1( to_integer( addressA1)) <= datumA1;
812
         else
813
           A1OutBuff := ramA1( to_integer( addressA1));
814
 
815
      A1Out.Word <= A1OutBuff( blocksizeld - 1 downto 0);
816
      A1Out.way <= A1OutBuff( blocksizeld + ldways downto blocksizeld);
817
                A1Out.valid <= A1OutBuff( blocksizeld + ldways + 1);
818
         end if;
819
 
820
         if putAm = '1' or removeAm = '1' then
821
           if removeAm = '0' then
822
             addressAm := std_ulogic_vector( firstAm);
823
                  datumAm := AmIn.valid & AmIn.way & AmIn.Word;
824
                  firstAm <= firstAm + 1;
825
                  counterAm <= counterAm + 1;
826
                  AmOutaddr <= std_ulogic_vector( firstAm);
827
                else
828
                  addressAm := AmInaddr( addressAm'range);
829
                  datumAm := ( others => '0');
830
                end if;
831
                wAm := '1';
832
         else
833
           uaddressAm := lastAm;
834
           if (getAm = '1' or AmOut.valid = '0') and counterAm /= 0 then
835
             counterAm <= counterAm - 1;
836
             uaddressAm := uaddressAm + 1;
837
           end if;
838
           lastAm <= uaddressAm;
839
           addressAm := std_ulogic_vector( uaddressAm);
840
           wAm := '0';
841
         end if;
842
 
843
         if wAm = '1' then
844
           ramAm( to_integer( addressAm)) <= datumAm;
845
         else
846
           AmOutBuff := ramAm( to_integer( addressAm));
847
 
848
      AmOut.Word <= AmOutBuff( blocksizeld - 1 downto 0);
849
      AmOut.way <= AmOutBuff( blocksizeld + ldways downto blocksizeld);
850
                AmOut.valid <= AmOutBuff( blocksizeld + ldways + 1);
851
         end if;
852
         end if;
853
  end if;
854
  end process queues;
855
 
856
  fullA1 <= counterA1( counterA1'high);
857
  emptyA1 <= '1' when counterA1 = 0 else '0';
858
 
859
  fullAm <= counterAm( counterAm'high);
860
  emptyAm <= '1' when counterAm = 0 else '0';
861
 
862
end Rtl;
863 6 gerhardhoh
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.