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

Subversion Repositories mytwoqcache

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

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

Line No. Rev Author Line
1 10 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
 
25
---- Uncomment the following library declaration if instantiating
26
---- any Xilinx primitives in this code.
27
--library UNISIM;
28
--use UNISIM.VComponents.all;
29
 
30
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
 
59
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
 
143
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
                           if toflush = AddressInh( toflush'range) then -- inserted, tagline could match flushing tagline !!!!
455
                        tagBuff( del).tagvalid <= '0';
456
                             tagBuff( del).cacheValid <= '0';
457
                             tagBuff( del).tag <= ( others => '0');
458
                             tagBuff( del).cacheAddr <= ( others => '0');
459
                                end if;
460
                           cindex <= tagdummy( del).cacheAddr;
461
                                FreeIn <= tagdummy( del).cacheAddr;
462
                                putf <= tagdummy( del).cacheValid;
463
                           stateram <= ramclean;
464
                         end if;
465
                  when ramread =>
466
                    readb <= '0';
467
                         getf <= '0';
468
                    stateram <= ramread1;
469
                  when ramread1 =>
470
                    if readsh = '0' then
471
                           for i in blockIn'range loop
472
                                  cacheIn.Words( i) <= blockIn( i);
473
                                end loop;
474
                      stateram <= ramupdate2;
475
                         end if;
476
                  when ramupdate2 =>
477
                    if IOCodeh(2) = '1' then
478
                           if IOCodeh(1) = '1' then
479
                                  If IOCodeh(0) = '1' then
480
                                    cacheIn.Words( index).Word <= DataInh;
481
                                         cacheIn.Words( index).Modified <= "1111";
482
                                  elsif AddressInh(1) = '1' then
483
                                    cacheIn.Words( index).Word( 31 downto 16) <= DataInh( 15 downto 0);
484
                                         cacheIn.Words( index).Modified( 3 downto 2) <= "11";
485
                                  else
486
                                    cacheIn.Words( index).Word( 15 downto 0) <= DataInh( 15 downto 0);
487
                                         cacheIn.Words( index).Modified( 1 downto 0) <= "11";
488
                                  end if;
489
                                else
490
                                  if AddressInh(1) = '0' then
491
                                    if AddressInh(0) = '0' then
492
                                           cacheIn.Words( index).Word( 7 downto 0) <= DataInh( 7 downto 0);
493
                                                cacheIn.Words( index).Modified(0) <= '1';
494
                                    else
495
                                           cacheIn.Words( index).Word( 15 downto 8) <= DataInh( 7 downto 0);
496
                                                cacheIn.Words( index).Modified(1) <= '1';
497
                                         end if;
498
                                  else
499
                                    if AddressInh(0) = '0' then
500
                                           cacheIn.Words( index).Word( 23 downto 16) <= DataInh( 7 downto 0);
501
                                                cacheIn.Words( index).Modified(2) <= '1';
502
                                    else
503
                                           cacheIn.Words( index).Word( 31 downto 24) <= DataInh( 7 downto 0);
504
                                                cacheIn.Words( index).Modified(3) <= '1';
505
                                         end if;
506
                                  end if;
507
                                end if;
508
                         else
509
                           DataOut <= cacheIn.Words( index).Word;
510
                         end if;
511
 
512
                         cacheIn.FiFoAddr <= newFiFoAddr;
513
                         cacheIn.Am <= newAm;
514
 
515
                         getf <= '0';
516
                         writec <= '1';
517
                         doneh <= '1';
518
 
519
                         stateram <= ramupdate3;
520
                  when ramupdate3 =>
521
                    hi := '0';
522
                         acc := '0';
523
                         en := '0';
524
                         writec <= '0';
525
                    doneh <= '0';
526
                         stateram <= ramstart;
527
                  when ramclean =>
528
                    putf <= '0';
529
                    stateram <= ramclean1;
530
                  when ramclean1 =>
531
                         if del /= 15 then
532
                           blockOut <= cacheOut.words;
533
                                writeb <= tagdummy( del).tagValid;
534
                                AddressOut <= tagdummy( del).tag & toFlush & ( ldCachedWords + 1 downto 0 => '0');
535
                           stateram <= ramflush;
536
                         end if;
537
                  when ramflush =>
538
                    writeb <= '0';
539
                         for i in blockIn'range loop
540
                      cacheIn.Words( i).Word <= ( others => '0');
541
                           cacheIn.Words( i).Modified <= ( others => '0');
542
                         end loop;
543
 
544
                         stateram <= ramflush1;
545
                  when ramflush1 =>
546
                         if writesh = '0' then
547
                           if del /= 15 and hi = '1' then
548
                                  doneh <= '1';
549
                                  en := '1';
550
                                  hi := '0';
551
                             stateram <= ramwait;
552
                                else
553
                                  tagBuff( elim).tag <= AddressInh( tagBuff( elim).tag'range);
554
                                  tagBuff( elim).tagValid <= '1';
555
                                  if IOCodeh = "111" and ldCachedWords = 0 then
556
                                    stateram <= ramupdate2;
557
                                  else
558
                                    readb <= '1';
559
                                    AddressOut <= AddressInh( AddressOut'range);
560
                                    stateram <= ramread;
561
                                  end if;
562
                                end if;
563
                         end if;
564
                end case;
565
 
566
                accinterrupt <= hi;
567
                enablequeue <= en;
568
                accqueue <= acc;
569
 
570
         f := CacheIn.Am & CacheIn.FiFoAddr;
571
         if writec = '1' then
572
           Ax( to_integer( cindex)) <= f;
573
         else
574
           g := Ax( to_integer( cindex));
575
                CacheOut.FiFoAddr <= g( g'high - 1 downto g'low);
576
                CacheOut.Am <= g( g'high);
577
         end if;
578
 
579
         for i in RAMBuffer'range loop
580
           a( i) := CacheIn.Words( i).Modified & CacheIn.Words( i).Word;
581
                if writec = '1' then
582
                  RAMs( i)( to_integer( cindex)) <= a( i);
583
                else
584
                  b( i) := RAMs( i)( to_integer( cindex));
585
                  CacheOut.Words( i).Word <= b( i)( 31 downto 0);
586
                  CacheOut.Words( i).Modified <= b( i)( 35 downto 32);
587
                end if;
588
         end loop;
589
 
590
         if putf = '1' then
591
           address := std_ulogic_vector( firstf);
592
                datum := FreeIn;
593
                firstf <= firstf + 1;
594
                counterf <= counterf + 1;
595
                w := '1';
596
         else
597
           uaddress := lastf;
598
           if getf = '1' and counterf /= 0 then
599
             counterf <= counterf - 1;
600
                  uaddress := uaddress + 1;
601
           end if;
602
                lastf <= uaddress;
603
                address := std_ulogic_vector( uaddress);
604
                w := '0';
605
         end if;
606
 
607
         if w = '1' then
608
           ramf( to_integer( address)) <= datum;
609
         else
610
           FreeOut <= ramf( to_integer( address));
611
         end if;
612
 
613
         end if;
614
  end if;
615
  end process dataram;
616
 
617
  emptyf <= '1' when counterf = 0 else '0';
618
 
619
  queues: process( nReset, Clock, enablequeue) is
620
  variable acc, hi: std_ulogic;
621
  variable A1OutBuff, AmOutBuff: std_ulogic_vector( blocksizeld + ldways + 1 downto 0);
622
  variable addressA1: std_ulogic_vector( ldqueuelength - 1 downto 0);
623
  variable diff, uaddressA1: unsigned( ldqueuelength - 1 downto 0);
624
  variable datumA1:  std_ulogic_vector( A1OutBuff'range);
625
  variable wA1: std_ulogic;
626
  variable addressAm: std_ulogic_vector( ldqueuelength - 1 downto 0);
627
  variable uaddressAm: unsigned( ldqueuelength - 1 downto 0);
628
  variable datumAm:  std_ulogic_vector( AmOutBuff'range);
629
  variable wAm: std_ulogic;
630
  begin
631
  if rising_edge(Clock) then
632
    if nReset /= '1' then
633
                del <= 15;
634
           statequeue <= queuestart;
635
           queuedone <= '0';
636
                interrupt <= '0';
637
                accdone <= '0';
638
                preempted <= '0';
639
                firstA1 <= ( others => '0');
640
                A1Outaddr <= ( others => '0');
641
                lastA1 <= ( others => '0');
642
                counterA1 <= ( others => '0');
643
                firstAm <= ( others => '0');
644
                AmOutaddr <= ( others => '0');
645
                lastAm <= ( others => '0');
646
                counterAm <= ( others => '0');
647
                getA1 <= '0'; -- NEW
648
                getAm <= '0'; -- NEW
649
                removeA1 <= '0'; -- NEW
650
                removeAm <= '0'; -- NEW
651
                putA1 <= '0'; -- NEW
652
                putAm <= '0'; -- NEW
653
         else
654
           hi := '0';
655
                acc := accdone or doneh;
656
 
657
                diff := firstA1 - unsigned( RecBuff.FiFoAddr);
658
 
659
           case statequeue is
660
                  when queuestart =>
661
                         getA1 <= '0';
662
 
663
                    if enablequeue = '1' then
664
                           if found /= 15 then
665
                                  if RecBuff.Am = '1' or                                -- in Am
666
                                    ( RecBuff.Am = '0' and diff( diff'high) = '0') then -- in lower half of A1
667
                                    queuedone <= '1';
668
                                         newFiFoAddr <= RecBuff.FiFoAddr;
669
                                         newAm <= RecBuff.Am;
670
                               statequeue <= queuewait;
671
                                  elsif fullAm = '1' then
672
                                    -- Am full
673
                                         if AmOut.valid = '1' then
674
                                           del <= to_integer( AmOut.way);
675
                                                toFlush <= AmOut.word;
676
                                                getAm <= '1';
677
                                           hi := '1';
678
                                           statequeue <= queuewait;
679
                                         end if;
680
                                  else
681
                                    AmIn.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
682
                                         AmIn.way <= std_ulogic_vector(to_unsigned( found, ldways + 1));
683
                                         AmIn.valid <= '1';
684
                                         putAm <= '1';
685
                                         A1Inaddr <= RecBuff.FiFoAddr;
686
                                         removeA1 <= '1';
687
                                         statequeue <= queuewaitAm1;
688
                                  end if;
689
                                elsif free /= 15 then
690
                                  if fullA1 = '1' or (emptyf = '1' and emptyA1 = '0') then
691
                                    -- remove last entry from A1
692
                                         if A1Out.valid = '1' then
693
                                           del <= to_integer( A1Out.way);
694
                                           toFlush <= A1Out.word;
695
                                           getA1 <= '1';
696
                                           hi := '1';
697
                                           statequeue <= queuewait;
698
                                         end if;
699
                                  elsif fullAm = '1' and emptyf = '1' then
700
                                    -- remove last entry from Am
701
                                         if AmOut.valid = '1' then
702
                                           del <= to_integer( AmOut.way);
703
                                           toFlush <= AmOut.word;
704
                                           getAm <= '1';
705
                                           hi := '1';
706
                                           statequeue <= queuewait;
707
                                         end if;
708
                                  else
709
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
710
                                         A1In.way <= std_ulogic_vector(to_unsigned( free, ldways + 1));
711
                                         A1In.valid <= '1';
712
                                         putA1 <= '1';
713
                                         statequeue <= queuewaitA11;
714
                                  end if;
715
                                elsif elim /= 15 then
716
                                  if fullA1 = '1' then
717
                                    if A1Out.valid = '1' then
718
                                           if not ( to_integer( A1Out.way) = elim and
719
                                                        A1Out.word = AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords)) then
720
                                             del <= to_integer( A1Out.way);
721
                                             toFlush <= A1Out.word;
722
                                             statequeue <= queueelim;
723
                                           end if;
724
 
725
                                           getA1 <= '1';
726
                                         end if;
727
                                  else
728
                                         getA1 <= '0'; -- NEW, inserted the only bug!!!!!!!!!!!!!!
729
                                    A1In.word <= AddressInh( 2 + ldCachedWords + blocksizeld - 1 downto 2 + ldCachedWords);
730
                                         A1In.way <= std_ulogic_vector(to_unsigned( elim, ldways + 1));
731
                                         A1In.valid <= '1';
732
                                         putA1 <= '1';
733
                                         statequeue <= queueelim;
734
                                  end if;
735
                                end if;
736
                         end if;
737
                  when queuewait =>
738
                         removeA1 <= '0';
739
                         removeAm <= '0';
740
                    getAm <= '0';
741
                    getA1 <= '0';
742
                         queuedone <= '0';
743
 
744
               if acc = '1' then
745
                           acc := '0';
746
                                del <= 15;
747
                           statequeue <= queuestart;
748
                         end if;
749
                  when queuewaitAm1 =>
750
                    putAm <= '0';
751
                         removeA1 <= '0';
752
                         statequeue <= queuewaitAm2;
753
                  when queuewaitAm2 =>
754
                         newFiFoAddr <= AmOutAddr;
755
                         newAm <= '1';
756
                         queuedone <= '1';
757
                         statequeue <= queuewait;
758
                  when queuewaitA11 =>
759
                    putA1 <= '0';
760
                         statequeue <= queuewaitA12;
761
                  when queuewaitA12 =>
762
                         newFiFoAddr <= A1OutAddr;
763
                         newAm <= '0';
764
                         removeA1 <= '0';
765
                         removeAm <= '0';
766
                         queuedone <= '1';
767
                    preempted <= '0';
768
                         statequeue <= queuewait;
769
                  when queueelim =>
770
                    putA1 <= '0';
771
                         getA1 <= '0';
772
 
773
                         if RecBuff.Am = '1' and preempted = '0' then
774
                           AmInAddr <= RecBuff.FiFoAddr;
775
                           removeAm <= '1';
776
                         elsif preempted = '0' then
777
                           A1InAddr <= RecBuff.FiFoAddr;
778
                           removeA1 <= '1';
779
                         end if;
780
 
781
                         if getA1 = '1' then
782
                           hi := '1';
783
                                preempted <= '1';
784
                           statequeue <= queuewait;
785
                         else
786
                           statequeue <= queuewaitA12;
787
                         end if;
788
                end case;
789
 
790
                interrupt <= hi;
791
                accdone <= acc;
792
 
793
         if putA1 = '1' or removeA1 = '1' then
794
           if removeA1 = '0' then
795
             addressA1 := std_ulogic_vector( firstA1);
796
                  datumA1 := A1In.valid & A1In.way & A1In.Word;
797
                  firstA1 <= firstA1 + 1;
798
                  counterA1 <= counterA1 + 1;
799
                  A1Outaddr <= std_ulogic_vector( firstA1);
800
                else
801
                  addressA1 := A1Inaddr( addressA1'range);
802
                  datumA1 := ( others => '0');
803
                end if;
804
                wA1 := '1';
805
         else
806
           uaddressA1 := lastA1;
807
           if (getA1 = '1' or A1Out.valid = '0') and counterA1 /= 0 then
808
             counterA1 <= counterA1 - 1;
809
             uaddressA1 := uaddressA1 + 1;
810
           end if;
811
           lastA1 <= uaddressA1;
812
           addressA1 := std_ulogic_vector( uaddressA1);
813
           wA1 := '0';
814
         end if;
815
 
816
         if wA1 = '1' then
817
           ramA1( to_integer( addressA1)) <= datumA1;
818
         else
819
           A1OutBuff := ramA1( to_integer( addressA1));
820
 
821
      A1Out.Word <= A1OutBuff( blocksizeld - 1 downto 0);
822
      A1Out.way <= A1OutBuff( blocksizeld + ldways downto blocksizeld);
823
                A1Out.valid <= A1OutBuff( blocksizeld + ldways + 1);
824
         end if;
825
 
826
         if putAm = '1' or removeAm = '1' then
827
           if removeAm = '0' then
828
             addressAm := std_ulogic_vector( firstAm);
829
                  datumAm := AmIn.valid & AmIn.way & AmIn.Word;
830
                  firstAm <= firstAm + 1;
831
                  counterAm <= counterAm + 1;
832
                  AmOutaddr <= std_ulogic_vector( firstAm);
833
                else
834
                  addressAm := AmInaddr( addressAm'range);
835
                  datumAm := ( others => '0');
836
                end if;
837
                wAm := '1';
838
         else
839
           uaddressAm := lastAm;
840
           if (getAm = '1' or AmOut.valid = '0') and counterAm /= 0 then
841
             counterAm <= counterAm - 1;
842
             uaddressAm := uaddressAm + 1;
843
           end if;
844
           lastAm <= uaddressAm;
845
           addressAm := std_ulogic_vector( uaddressAm);
846
           wAm := '0';
847
         end if;
848
 
849
         if wAm = '1' then
850
           ramAm( to_integer( addressAm)) <= datumAm;
851
         else
852
           AmOutBuff := ramAm( to_integer( addressAm));
853
 
854
      AmOut.Word <= AmOutBuff( blocksizeld - 1 downto 0);
855
      AmOut.way <= AmOutBuff( blocksizeld + ldways downto blocksizeld);
856
                AmOut.valid <= AmOutBuff( blocksizeld + ldways + 1);
857
         end if;
858
         end if;
859
  end if;
860
  end process queues;
861
 
862
  fullA1 <= counterA1( counterA1'high);
863
  emptyA1 <= '1' when counterA1 = 0 else '0';
864
 
865
  fullAm <= counterAm( counterAm'high);
866
  emptyAm <= '1' when counterAm = 0 else '0';
867
 
868
end Rtl;
869
 

powered by: WebSVN 2.1.0

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