1 ----------------------------------------------------
2 -- PACKAGE FOR DIGITAL ENGINEERING LABS
7 -- - Use "Add copy" to add to Xilinx project
8 -- - Add "use work.DigEng.all" on top of entity
10 ----------------------------------------------------
14 function log2
(x
: natural
) return natural
;
15 function size
(x
: natural
) return natural
;
19 package body DigEng
is
21 ----------------------------------------------------
22 -- LOG BASE 2 FUNCTION
23 -- returns the ceiling of log base 2 of a (non-zero) integer
24 -- (1->0; 2->1; 3->2; 4->2; 5->3 ...)
26 -- This function is NOT SYNTHESIZABLE
27 -- should be used for indices, not circuit description
30 -- - signal A : STD_LOGIC_VECTOR(log2(data_size)-1 downto 0);
32 ----------------------------------------------------
33 function log2
( x
: natural
) return natural
is
34 variable temp
: natural
:= x
;
35 variable n
: natural
:= 0 ;
47 ----------------------------------------------------
49 -- returns the size of a vector that can encode a (non-zero) integer
50 -- (1->1; 2->2; 3->2; 4->3; 5->3 ...)
52 -- This function is NOT SYNTHESIZABLE
53 -- should be used for indices, not circuit description
56 -- - signal A : STD_LOGIC_VECTOR(size(n)-1 downto 0);
58 ----------------------------------------------------
59 function size
( x
: natural
) return natural
is
60 variable temp
: natural
:= x
;
61 variable n
: natural
:= 0 ;