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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [VHDL/] [bit_funcs.vhd] - Blame information for rev 113

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

Line No. Rev Author Line
1 99 davidgb
--===========================================================================--
2
--                                                                           --
3
--  bit_funcs.vhd - Power2 & Log2 Funtions Package                           --
4
--                                                                           --
5
--===========================================================================--
6
--
7
--  File name      : bit_funcs.vhd
8
--
9
--  Purpose        : Implements power2 and log2 functions.
10
--                  
11
--  Dependencies   : ieee.std_logic_1164
12
--                   ieee.std_logic_arith
13
--                   ieee.std_logic_unsigned
14
--
15
--  Author         : John E. Kent
16
--
17
--  Email          : dilbert57@opencores.org      
18
--
19
--  Web            : http://opencores.org/project,system09
20
--
21
--  bit_func.vhd is a VHDL functions package for calulating power2 and log2.
22
-- 
23
--  Copyright (C) 2003 - 2010 John Kent
24
--
25
--  This program is free software: you can redistribute it and/or modify
26
--  it under the terms of the GNU General Public License as published by
27
--  the Free Software Foundation, either version 3 of the License, or
28
--  (at your option) any later version.
29
--
30
--  This program is distributed in the hope that it will be useful,
31
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
32
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33
--  GNU General Public License for more details.
34
--
35
--  You should have received a copy of the GNU General Public License
36
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
37
--
38
--===========================================================================--
39
--                                                                           --
40
--                              Revision  History                            --
41
--                                                                           --
42
--===========================================================================--
43
--
44
-- Revision Name          Date             Description
45
-- 0.1      John E. Kent  unknown          Initial version
46
-- 1.0      John E. Kent  30th May 2010    Added GPL Header
47
--
48
 
49 65 davidgb
library IEEE;
50
   use IEEE.std_logic_1164.all;
51
   use IEEE.std_logic_arith.all;
52
   use IEEE.std_logic_unsigned.all;
53 99 davidgb
 
54 65 davidgb
package bit_funcs is
55
   function log2(v: in natural) return natural;
56
   function pow2(v: in natural) return natural;
57 99 davidgb
end package bit_funcs;
58 65 davidgb
 
59 99 davidgb
package body bit_funcs is
60
 
61
 
62
   function log2 (v : in natural) return natural is
63
   variable temp, log: natural;
64
   begin
65
      temp := v / 2;
66
      log := 0;
67
      while (temp /= 0) loop
68
        temp := temp/2;
69
        log := log + 1;
70
      end loop;
71
      return log;
72
   end function log2;
73
 
74 65 davidgb
   function pow2(v: in natural) return natural is
75
      variable i: natural;
76
      variable pown: natural;
77
   begin
78
      pown := 1;
79
      for i in 0 to v loop
80
         exit when (i=v);
81
         pown := pown * 2;
82
      end loop;
83
      return pown;
84
   end function pow2;
85
 
86
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.