Add Tercel PHY reset synchronization
[microwatt.git] / glibc_random.vhdl
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5 library work;
6 use work.glibc_random_helpers.all;
7
8 package glibc_random is
9 function pseudorand(a: integer) return std_ulogic_vector;
10 function pseudorand1 return std_ulogic;
11 end package glibc_random;
12
13 package body glibc_random is
14 function pseudorand(a: integer) return std_ulogic_vector is
15 variable tmp1, tmp2, tmp3, tmp4: std_ulogic_vector(31 downto 0);
16 variable ret: std_ulogic_vector(63 downto 0);
17 begin
18 tmp1 := std_ulogic_vector(to_unsigned(random, 32));
19 tmp2 := std_ulogic_vector(to_unsigned(random, 32));
20 if a <= 32 then
21 ret := tmp1 & tmp2;
22 else
23 tmp3 := std_ulogic_vector(to_unsigned(random, 32));
24 tmp4 := std_ulogic_vector(to_unsigned(random, 32));
25
26 ret := tmp1(15 downto 0) & tmp2(15 downto 0) & tmp3(15 downto 0) & tmp4(15 downto 0);
27 end if;
28
29 return ret((a-1) downto 0);
30 end;
31
32 function pseudorand1 return std_ulogic is
33 variable tmp: std_ulogic_vector(31 downto 0);
34 begin
35 tmp := std_ulogic_vector(to_unsigned(random, 32));
36 return tmp(0);
37 end;
38 end package body glibc_random;