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

Subversion Repositories hive

[/] [hive/] [trunk/] [v01.09/] [functions.h] - Blame information for rev 3

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

Line No. Rev Author Line
1 2 ericw
/*
2
--------------------------------------------------------------------------------
3
--
4
-- Module : functions.h
5
--
6
--------------------------------------------------------------------------------
7
--
8
-- Function:
9
-- - A bunch of functions for a stack processor.
10
--
11
-- Instantiates:
12
-- - Nothing.
13
--
14
--------------------------------------------------------------------------------
15
*/
16
 
17
 
18
        /*
19
        ---------------
20
        -- functions --
21
        ---------------
22
        */
23
 
24
 
25
        // returns safe ceiling value of log2(n)
26
        // (for vector sizing we never want less than 1)
27
        // examples: 
28
        // clog2(0 thru 2)  = 1,
29
        // clog2(3 & 4)     = 2,
30
        // clog2(5 thru 8)  = 3,
31
        // clog2(9 thru 16) = 4, etc.
32
        function integer clog2;
33
        input integer n;
34
                begin
35
                        clog2 = 1;
36
                        while ( n > 2 ) begin
37
                                n = ( n + 1 ) / 2;
38
                                clog2 = clog2 + 1;
39
                        end
40
                end
41
        endfunction
42
 
43
 
44
        // returns the max of 2 values
45
        function integer max_of_2;
46
        input integer a, b;
47
                begin
48
                        if ( a > b ) begin
49
                                max_of_2 = a;
50
                        end else begin
51
                                max_of_2 = b;
52
                        end
53
                end
54
        endfunction
55
 

powered by: WebSVN 2.1.0

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