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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [verify/] [icache/] [src/] [tb/] [cpu_model.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
---------------------------------------------------------------------
2
-- CPU model
3
--
4
-- Part of the LXP32 instruction cache testbench
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
--
8
-- Requests data from cache
9
---------------------------------------------------------------------
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
use ieee.numeric_std.all;
14
use ieee.math_real.all;
15
 
16
use work.common_pkg.all;
17
use work.tb_pkg.all;
18
 
19
entity cpu_model is
20
        generic(
21
                BLOCKS: integer;
22
                VERBOSE: boolean
23
        );
24
        port(
25
                clk_i: in std_logic;
26
 
27
                lli_re_o: out std_logic;
28
                lli_adr_o: out std_logic_vector(29 downto 0);
29
                lli_dat_i: in std_logic_vector(31 downto 0);
30
                lli_busy_i: in std_logic;
31
 
32
                finish_o: out std_logic
33
        );
34
end entity;
35
 
36
architecture sim of cpu_model is
37
 
38
constant bursts: integer:=10000;
39
 
40
signal re: std_logic:='0';
41
signal lli_adr: std_logic_vector(29 downto 0);
42
 
43
signal request: std_logic:='0';
44
signal request_addr: std_logic_vector(29 downto 0);
45
 
46
signal finish: std_logic:='0';
47
 
48
signal current_latency: integer:=1;
49
signal max_latency: integer:=-1;
50
signal total_latency: integer:=0;
51
signal spurious_misses: integer:=0;
52
 
53
begin
54
 
55
process is
56
        variable b: integer:=1;
57
        variable start: integer;
58
        variable size: integer;
59
        variable addr: integer:=0;
60
        variable delay: integer;
61
        variable rng_state: rng_state_type;
62
        variable r: integer;
63
        variable total_requests: integer:=0;
64
begin
65
        while b<=BLOCKS loop
66
                rand(rng_state,1,10,r);
67
                if r=1 then -- insert large block occasionally
68
                        rand(rng_state,1,400,size);
69
                else -- small block
70
                        rand(rng_state,1,32,size);
71
                end if;
72
 
73
                rand(rng_state,0,1,r);
74
                if r=0 then -- long jump
75
                        rand(rng_state,0,1024,start);
76
                        addr:=start;
77
                        if VERBOSE then
78
                                report "Fetching block #"&integer'image(b)&" at address "&integer'image(addr)&
79
                                        " of size "&integer'image(size);
80
                        end if;
81
                else -- short jump
82
                        rand(rng_state,-10,10,r);
83
                        start:=addr+r;
84
                        if start<0 then
85
                                start:=0;
86
                        end if;
87
                        addr:=start;
88
                        if VERBOSE then
89
                                report "Fetching block #"&integer'image(b)&" at address "&integer'image(addr)&
90
                                        " of size "&integer'image(size)&" (short jump)";
91
                        end if;
92
                end if;
93
 
94
                while addr<start+size loop
95
                        re<='1';
96
                        total_requests:=total_requests+1;
97
                        lli_adr<=std_logic_vector(to_unsigned(addr,30));
98
                        wait until rising_edge(clk_i) and lli_busy_i='0';
99
                        re<='0';
100
                        addr:=addr+1;
101
                        rand(rng_state,0,4,delay);
102
                        if delay>0 then
103
                                for i in 1 to delay loop
104
                                        wait until rising_edge(clk_i);
105
                                end loop;
106
                        end if;
107
                end loop;
108
 
109
                if (b mod 10000)=0 then
110
                        report integer'image(b)&" BLOCKS PROCESSED";
111
                end if;
112
 
113
                b:=b+1;
114
        end loop;
115
 
116
        report "Number of requests: "&integer'image(total_requests);
117
        report "Maximum latency: "&integer'image(max_latency);
118
        report "Average latency: "&real'image(real(total_latency)/real(total_requests));
119
        report "Number of spurious misses: "&integer'image(spurious_misses);
120
 
121
        finish<='1';
122
        wait;
123
end process;
124
 
125
lli_re_o<=re;
126
lli_adr_o<=lli_adr;
127
 
128
process (clk_i) is
129
begin
130
        if rising_edge(clk_i) then
131
                if lli_busy_i='0' then
132
                        if request='1' then
133
                                assert lli_dat_i=(("00"&request_addr) xor xor_constant)
134
                                        report "Data mismatch: expected 0x"&
135
                                                hex_string(("00"&request_addr) xor xor_constant)&
136
                                                ", got 0x"&hex_string(lli_dat_i)
137
                                        severity failure;
138
                        end if;
139
 
140
                        request<=re;
141
                        request_addr<=lli_adr;
142
                end if;
143
        end if;
144
end process;
145
 
146
finish_o<=finish;
147
 
148
-- Measure latency
149
 
150
process (clk_i) is
151
begin
152
        if rising_edge(clk_i) then
153
                if lli_busy_i='0' then
154
                        if request='1' then
155
                                total_latency<=total_latency+current_latency;
156
                                if current_latency>max_latency then
157
                                        max_latency<=current_latency;
158
                                end if;
159
                        end if;
160
                        current_latency<=1;
161
                else
162
                        if lli_dat_i=(("00"&request_addr) xor xor_constant) and current_latency=1 then
163
                                spurious_misses<=spurious_misses+1;
164
                        end if;
165
                        current_latency<=current_latency+1;
166
                end if;
167
        end if;
168
end process;
169
 
170
process (clk_i) is
171
begin
172
        if rising_edge(clk_i) then
173
                assert lli_busy_i='0' or request='1'
174
                        report "LLI busy signal asserted without a request"
175
                        severity failure;
176
        end if;
177
end process;
178
 
179
end architecture;

powered by: WebSVN 2.1.0

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