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 3

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

Line No. Rev Author Line
1 2 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
use std.textio.all;
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
use ieee.numeric_std.all;
14
 
15
package body common_pkg is
16
        impure function rand return integer is
17
                variable r: unsigned(63 downto 0);
18
        begin
19
                r:=rand_state*to_unsigned(1103515245,32)+12345;
20
                rand_state:=r(rand_state'range);
21
                return to_integer(rand_state(30 downto 16));
22
        end function;
23
 
24
        impure function rand(a: integer; b: integer) return integer is
25
        begin
26
                assert a<=b report "Invalid range" severity failure;
27
                return (rand mod (b-a+1))+a;
28
        end function;
29
 
30
        function hex_string(x: std_logic_vector) return string is
31
                variable xx: std_logic_vector(x'length-1 downto 0);
32
                variable i: integer:=0;
33
                variable ii: integer;
34
                variable c: integer;
35
                variable s: string(x'length downto 1);
36
        begin
37
                xx:=x;
38
                loop
39
                        ii:=i*4;
40
                        exit when ii>xx'high;
41
                        if ii+3<=xx'high then
42
                                c:=to_integer(unsigned(xx(ii+3 downto ii)));
43
                        else
44
                                c:=to_integer(unsigned(xx(xx'high downto ii)));
45
                        end if;
46
 
47
                        case c is
48
                        when 0 => s(i+1):='0';
49
                        when 1 => s(i+1):='1';
50
                        when 2 => s(i+1):='2';
51
                        when 3 => s(i+1):='3';
52
                        when 4 => s(i+1):='4';
53
                        when 5 => s(i+1):='5';
54
                        when 6 => s(i+1):='6';
55
                        when 7 => s(i+1):='7';
56
                        when 8 => s(i+1):='8';
57
                        when 9 => s(i+1):='9';
58
                        when 10 => s(i+1):='A';
59
                        when 11 => s(i+1):='B';
60
                        when 12 => s(i+1):='C';
61
                        when 13 => s(i+1):='D';
62
                        when 14 => s(i+1):='E';
63
                        when 15 => s(i+1):='F';
64
                        when others => s(i+1):='X';
65
                        end case;
66
 
67
                        i:=i+1;
68
                end loop;
69
                return s(i downto 1);
70
        end function;
71
end package body;

powered by: WebSVN 2.1.0

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