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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [verify/] [common_pkg/] [common_pkg_body.vhd] - Blame information for rev 12

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

Line No. Rev Author Line
1 9 ring0_mipt
---------------------------------------------------------------------
2
-- Common package for LXP32 testbenches
3
--
4
-- Part of the LXP32 verification environment
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
---------------------------------------------------------------------
8
 
9
library ieee;
10
use ieee.std_logic_1164.all;
11
use ieee.numeric_std.all;
12
use ieee.math_real.all;
13
 
14
package body common_pkg is
15
        procedure rand(variable st: inout rng_state_type; a,b: integer; variable x: out integer) is
16
                variable r: real;
17
        begin
18
                assert a<=b report "Invalid range" severity failure;
19
                uniform(st.seed1,st.seed2,r);
20
                r:=r*real(b-a+1);
21
                x:=a+integer(floor(r));
22
        end procedure;
23
 
24
        function hex_string(x: std_logic_vector) return string is
25
                variable xx: std_logic_vector(x'length-1 downto 0);
26
                variable i: integer:=0;
27
                variable ii: integer;
28
                variable c: integer;
29
                variable high_index: integer;
30
                variable s: string(x'length downto 1);
31
        begin
32
                xx:=x;
33
                loop
34
                        ii:=i*4;
35
                        exit when ii>xx'high;
36
                        if ii+3<=xx'high then
37
                                high_index:=ii+3;
38
                        else
39
                                high_index:=xx'high;
40
                        end if;
41
 
42
                        if is_x(xx(high_index downto ii)) then
43
                                c:=-1;
44
                        else
45
                                c:=to_integer(unsigned(xx(high_index downto ii)));
46
                        end if;
47
 
48
                        case c is
49
                        when 0 => s(i+1):='0';
50
                        when 1 => s(i+1):='1';
51
                        when 2 => s(i+1):='2';
52
                        when 3 => s(i+1):='3';
53
                        when 4 => s(i+1):='4';
54
                        when 5 => s(i+1):='5';
55
                        when 6 => s(i+1):='6';
56
                        when 7 => s(i+1):='7';
57
                        when 8 => s(i+1):='8';
58
                        when 9 => s(i+1):='9';
59
                        when 10 => s(i+1):='A';
60
                        when 11 => s(i+1):='B';
61
                        when 12 => s(i+1):='C';
62
                        when 13 => s(i+1):='D';
63
                        when 14 => s(i+1):='E';
64
                        when 15 => s(i+1):='F';
65
                        when others => s(i+1):='X';
66
                        end case;
67
 
68
                        i:=i+1;
69
                end loop;
70
                return s(i downto 1);
71
        end function;
72
end package body;

powered by: WebSVN 2.1.0

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