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 2

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

Line No. Rev Author Line
1 2 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
shared variable current_latency: integer:=1;
49
shared variable max_latency: integer:=-1;
50
shared variable total_latency: integer:=0;
51
shared variable total_requests: integer:=0;
52
shared variable spurious_misses: integer:=0;
53
 
54
begin
55
 
56
process is
57
        variable b: integer:=1;
58
        variable start: integer;
59
        variable size: integer;
60
        variable addr: integer:=0;
61
        variable delay: integer;
62
begin
63
        while b<=BLOCKS loop
64
                if rand(1,10)=1 then -- insert large block occasionally
65
                        size:=rand(1,400);
66
                else -- small block
67
                        size:=rand(1,32);
68
                end if;
69
 
70
                if rand(0,1)=0 then -- long jump
71
                        start:=rand(0,1024);
72
                        addr:=start;
73
                        if VERBOSE then
74
                                report "Fetching block #"&integer'image(b)&" at address "&integer'image(addr)&
75
                                        " of size "&integer'image(size);
76
                        end if;
77
                else -- short jump
78
                        start:=addr+rand(0,20)-10;
79
                        if start<0 then
80
                                start:=0;
81
                        end if;
82
                        addr:=start;
83
                        if VERBOSE then
84
                                report "Fetching block #"&integer'image(b)&" at address "&integer'image(addr)&
85
                                        " of size "&integer'image(size)&" (short jump)";
86
                        end if;
87
                end if;
88
 
89
                while addr<start+size loop
90
                        re<='1';
91
                        total_requests:=total_requests+1;
92
                        lli_adr<=std_logic_vector(to_unsigned(addr,30));
93
                        wait until rising_edge(clk_i) and lli_busy_i='0';
94
                        re<='0';
95
                        addr:=addr+1;
96
                        delay:=rand(0,4);
97
                        if delay>0 then
98
                                for i in 1 to delay loop
99
                                        wait until rising_edge(clk_i);
100
                                end loop;
101
                        end if;
102
                end loop;
103
 
104
                if (b mod 10000)=0 then
105
                        report integer'image(b)&" BLOCKS PROCESSED";
106
                end if;
107
 
108
                b:=b+1;
109
        end loop;
110
 
111
        report "Number of requests: "&integer'image(total_requests);
112
        report "Maximum latency: "&integer'image(max_latency);
113
        report "Average latency: "&real'image(real(total_latency)/real(total_requests));
114
        report "Number of spurious misses: "&integer'image(spurious_misses);
115
 
116
        finish<='1';
117
        wait;
118
end process;
119
 
120
lli_re_o<=re;
121
lli_adr_o<=lli_adr;
122
 
123
process (clk_i) is
124
begin
125
        if rising_edge(clk_i) then
126
                if lli_busy_i='0' then
127
                        if request='1' then
128
                                assert lli_dat_i=(("00"&request_addr) xor xor_constant)
129
                                        report "Data mismatch: expected 0x"&
130
                                                hex_string(("00"&request_addr) xor xor_constant)&
131
                                                ", got 0x"&hex_string(lli_dat_i)
132
                                        severity failure;
133
                        end if;
134
 
135
                        request<=re;
136
                        request_addr<=lli_adr;
137
                end if;
138
        end if;
139
end process;
140
 
141
finish_o<=finish;
142
 
143
-- Measure latency
144
 
145
process (clk_i) is
146
begin
147
        if rising_edge(clk_i) then
148
                if lli_busy_i='0' then
149
                        if request='1' then
150
                                total_latency:=total_latency+current_latency;
151
                                if current_latency>max_latency then
152
                                        max_latency:=current_latency;
153
                                end if;
154
                        end if;
155
                        current_latency:=1;
156
                else
157
                        if lli_dat_i=(("00"&request_addr) xor xor_constant) and current_latency=1 then
158
                                spurious_misses:=spurious_misses+1;
159
                        end if;
160
                        current_latency:=current_latency+1;
161
                end if;
162
        end if;
163
end process;
164
 
165
assert not rising_edge(clk_i) or lli_busy_i='0' or request='1'
166
        report "LLI busy signal asserted without a request"
167
        severity failure;
168
 
169
end architecture;

powered by: WebSVN 2.1.0

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