URL
https://opencores.org/ocsvn/lxp32/lxp32/trunk
Subversion Repositories lxp32
Compare Revisions
- This comparison shows the changes necessary to convert path
/lxp32/trunk/verify/common_pkg
- from Rev 2 to Rev 6
- ↔ Reverse comparison
Rev 2 → Rev 6
/common_pkg.vhd
4,10 → 4,6
-- Part of the LXP32 verification environment |
-- |
-- Copyright (c) 2016 by Alex I. Kuznetsov |
-- |
-- Note: the "rand" function declared in this package implements |
-- a linear congruent pseudo-random number generator as defined in |
-- the ISO/IEC 9899:1999 standard. |
--------------------------------------------------------------------- |
|
library ieee; |
15,10 → 11,16
use ieee.numeric_std.all; |
|
package common_pkg is |
shared variable rand_state: unsigned(31 downto 0):=to_unsigned(1,32); |
type rng_state_type is record |
seed1: positive; |
seed2: positive; |
end record; |
|
-- Generate a pseudo-random value of integer type from [a;b] range |
-- Output is stored in x |
procedure rand(variable st: inout rng_state_type; a,b: integer; variable x: out integer); |
|
impure function rand return integer; |
impure function rand(a: integer; b: integer) return integer; |
|
-- Convert std_logic_vector to a hexadecimal string (similar to |
-- the "to_hstring" function from VHDL-2008 |
function hex_string(x: std_logic_vector) return string; |
end package; |
/common_pkg_body.vhd
6,26 → 6,20
-- Copyright (c) 2016 by Alex I. Kuznetsov |
--------------------------------------------------------------------- |
|
use std.textio.all; |
|
library ieee; |
use ieee.std_logic_1164.all; |
use ieee.numeric_std.all; |
use ieee.math_real.all; |
|
package body common_pkg is |
impure function rand return integer is |
variable r: unsigned(63 downto 0); |
procedure rand(variable st: inout rng_state_type; a,b: integer; variable x: out integer) is |
variable r: real; |
begin |
r:=rand_state*to_unsigned(1103515245,32)+12345; |
rand_state:=r(rand_state'range); |
return to_integer(rand_state(30 downto 16)); |
end function; |
|
impure function rand(a: integer; b: integer) return integer is |
begin |
assert a<=b report "Invalid range" severity failure; |
return (rand mod (b-a+1))+a; |
end function; |
uniform(st.seed1,st.seed2,r); |
r:=r*real(b-a+1); |
x:=a+integer(floor(r)); |
end procedure; |
|
function hex_string(x: std_logic_vector) return string is |
variable xx: std_logic_vector(x'length-1 downto 0); |