OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [rev_86/] [rtl/] [VHDL/] [bit_funcs.vhd] - Blame information for rev 128

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 65 davidgb
library IEEE;
2
   use IEEE.std_logic_1164.all;
3
   use IEEE.std_logic_arith.all;
4
   use IEEE.std_logic_unsigned.all;
5
 
6
package bit_funcs is
7
   function log2(v: in natural) return natural;
8
   function pow2(v: in natural) return natural;
9
end package bit_funcs;
10
 
11
package body bit_funcs is
12
   function log2(v: in natural) return natural is
13
      variable i: natural;
14
      variable n: natural;
15
      variable logn: natural;
16
   begin
17
      n := 1;
18
      for i in 0 to 128 loop
19
         logn := i;
20
         exit when (n>=v);
21
         n := n * 2;
22
      end loop;
23
      return logn;
24
   end function log2;
25
 
26
   function pow2(v: in natural) return natural is
27
      variable i: natural;
28
      variable pown: natural;
29
   begin
30
      pown := 1;
31
      for i in 0 to v loop
32
         exit when (i=v);
33
         pown := pown * 2;
34
      end loop;
35
      return pown;
36
   end function pow2;
37
 
38
end package body bit_funcs;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.