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

Subversion Repositories udp_ipv4_for_10g_ethernet

[/] [udp_ipv4_for_10g_ethernet/] [trunk/] [src/] [hdl/] [math_pack.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 DFC
-------------------------------------------------------------------------------
2
--
3
-- (C) Copyright 2017 DFC Design, s.r.o., Brno, Czech Republic
4
-- Author: Marek Kvas (m.kvas@dfcdesign.cz)
5
--
6
-------------------------------------------------------------------------------
7
-- This file is part of UDP/IPv4 for 10 G Ethernet core.
8
-- 
9
-- UDP/IPv4 for 10 G Ethernet core is free software: you can 
10
-- redistribute it and/or modify it under the terms of 
11
-- the GNU Lesser General Public License as published by the Free 
12
-- Software Foundation, either version 3 of the License, or
13
-- (at your option) any later version.
14
-- 
15
-- UDP/IPv4 for 10 G Ethernet core is distributed in the hope that 
16
-- it will be useful, but WITHOUT ANY WARRANTY; without even 
17
-- the implied warranty of MERCHANTABILITY or FITNESS FOR A 
18
-- PARTICULAR PURPOSE.  See the GNU Lesser General Public License 
19
-- for more details.
20
-- 
21
-- You should have received a copy of the GNU Lesser General Public 
22
-- License along with UDP/IPv4 for 10 G Ethernet core.  If not, 
23
-- see <http://www.gnu.org/licenses/>.
24
-------------------------------------------------------------------------------
25
--
26
-- This is minimal package of commonly used math functions. It is not
27
-- meant for synthesis to hw operators. It is meant for use in signal and
28
-- port definitions as a convenient way to calculate vector widths.
29
--
30
-------------------------------------------------------------------------------
31
 
32
 
33
library ieee;
34
use ieee.std_logic_1164.all;
35
use ieee.numeric_std.all;
36
 
37
package math_pack is
38
   -- Return integer equal to or higher than 2 base logarithm of i
39
   function log2(i : natural) return integer;
40
 
41
   -- Return smaller of two integers
42
   function min(a : integer; b: integer) return integer;
43
   -- Return higher of two integers
44
   function max(a : integer; b: integer) return integer;
45
 
46
end package;
47
 
48
package body math_pack is
49
 
50
   function log2(i : natural) return integer is
51
      variable ret      : integer := 0;
52
   begin
53
 
54
      while 2**ret < i loop
55
         ret := ret + 1;
56
      end loop;
57
 
58
      return ret;
59
   end function;
60
 
61
   function min(a : integer; b: integer) return integer is
62
   begin
63
      if a > b then
64
         return b;
65
      else
66
         return a;
67
      end if;
68
   end function;
69
 
70
   function max(a : integer; b: integer) return integer is
71
   begin
72
      if a < b then
73
         return b;
74
      else
75
         return a;
76
      end if;
77
   end function;
78
 
79
end package body;

powered by: WebSVN 2.1.0

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