-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_functions.vhd
67 lines (54 loc) · 1.52 KB
/
common_functions.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
package common_functions is
function log2 (v: natural) return natural;
function append_zero (
DI: std_logic_vector;
size: natural)
return std_logic_vector;
function prepend_zero (
DI: std_logic_vector;
size: natural)
return std_logic_vector;
end;
package body common_functions is
function log2 (v : natural) return natural is
variable tmp : natural := v;
variable ret : natural := 0;
begin
while tmp > 1 loop
ret := ret + 1;
tmp := tmp / 2;
end loop;
return ret;
end function;
-- ----- ----- ----- ----- ----- -----
function append_zeros (
DI : std_logic_vector;
size : natural)
return std_logic_vector is
variable tmp_s : std_logic_vector(size-1 downto 0) := (others => '0');
begin
if DI'length > size then
tmp_s := DI(DI'length-1 downto DI'length - size);
else
tmp_s(size-1 downto size-DI'length) := DI;
end if;
return tmp_s;
end function;
-- ----- ----- ----- ----- ----- -----
function prepend_zeros (
DI : std_logic_vector;
size : natural)
return std_logic_vector is
variable tmp_s : std_logic_vector(size-1 downto 0) := (others => '0');
begin
if DI'length > size then
tmp_s := DI(size-1 downto 0);
else
tmp_s(DI'length-1 downto 0) := DI;
end if;
return tmp_s;
end function;
end package body;