URL
https://opencores.org/ocsvn/System09/System09/trunk
[/] [System09/] [rev_86/] [rtl/] [VHDL/] [bit_funcs.vhd] - Diff between revs 66 and 112
Go to most recent revision |
Only display areas with differences |
Details |
Blame |
View Log
Rev 66 |
Rev 112 |
library IEEE;
|
library IEEE;
|
use IEEE.std_logic_1164.all;
|
use IEEE.std_logic_1164.all;
|
use IEEE.std_logic_arith.all;
|
use IEEE.std_logic_arith.all;
|
use IEEE.std_logic_unsigned.all;
|
use IEEE.std_logic_unsigned.all;
|
|
|
package bit_funcs is
|
package bit_funcs is
|
function log2(v: in natural) return natural;
|
function log2(v: in natural) return natural;
|
function pow2(v: in natural) return natural;
|
function pow2(v: in natural) return natural;
|
end package bit_funcs;
|
end package bit_funcs;
|
|
|
package body bit_funcs is
|
package body bit_funcs is
|
function log2(v: in natural) return natural is
|
function log2(v: in natural) return natural is
|
variable i: natural;
|
variable i: natural;
|
variable n: natural;
|
variable n: natural;
|
variable logn: natural;
|
variable logn: natural;
|
begin
|
begin
|
n := 1;
|
n := 1;
|
for i in 0 to 128 loop
|
for i in 0 to 128 loop
|
logn := i;
|
logn := i;
|
exit when (n>=v);
|
exit when (n>=v);
|
n := n * 2;
|
n := n * 2;
|
end loop;
|
end loop;
|
return logn;
|
return logn;
|
end function log2;
|
end function log2;
|
|
|
function pow2(v: in natural) return natural is
|
function pow2(v: in natural) return natural is
|
variable i: natural;
|
variable i: natural;
|
variable pown: natural;
|
variable pown: natural;
|
begin
|
begin
|
pown := 1;
|
pown := 1;
|
for i in 0 to v loop
|
for i in 0 to v loop
|
exit when (i=v);
|
exit when (i=v);
|
pown := pown * 2;
|
pown := pown * 2;
|
end loop;
|
end loop;
|
return pown;
|
return pown;
|
end function pow2;
|
end function pow2;
|
|
|
end package body bit_funcs;
|
end package body bit_funcs;
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.