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

Subversion Repositories scalable_arbiter

[/] [scalable_arbiter/] [trunk/] [rtl/] [verilog/] [functions.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 kendallc
/*
2
 * Copyright (c) 2008, Kendall Correll
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
 
17
function integer min (
18
        input integer a, b
19
);
20
begin
21
        min = a < b ? a : b;
22
end
23
endfunction
24
 
25
function integer max (
26
        input integer a, b
27
);
28
begin
29
        max = a > b ? a : b;
30
end
31
endfunction
32
 
33
// compute the log base 2 of a number, rounded down to the
34
// nearest whole number
35
function integer flog2 (
36
        input integer number
37
);
38
integer i;
39
integer count;
40
begin
41
        flog2 = 0;
42
        for(i = 0; i < 32; i = i + 1)
43
        begin
44
                if(number&(1<<i))
45
                        flog2 = i;
46
        end
47
end
48
endfunction
49
 
50
// compute the log base 2 of a number, rounded up to the
51
// nearest whole number
52
function integer clog2 (
53
        input integer number
54
);
55
integer i;
56
integer count;
57
begin
58
        clog2 = 0;
59
        count = 0;
60
        for(i = 0; i < 32; i = i + 1)
61
        begin
62
                if(number&(1<<i))
63
                begin
64
                        clog2 = i;
65
                        count = count + 1;
66
                end
67
        end
68
        // clog2 holds the largest set bit position and count
69
        // holds the number of bits set. More than one bit set
70
        // indicates that the input was not an even power of 2,
71
        // so round the result up.
72
        if(count > 1)
73
                clog2 = clog2 + 1;
74
end
75
endfunction
76
 
77
// compute the size of the interconnect for the arbiter's
78
// 'select' muxes
79
function integer mux_sum (
80
        input integer width, select_width
81
);
82
integer i, number;
83
begin
84
        mux_sum = 0;
85
        number = 1;
86
        for(i = select_width; i > 0 && number <= width; i = i - 1)
87
        begin
88
                mux_sum = mux_sum + i*(number);
89
                number = number * 2;
90
        end
91
end
92
endfunction

powered by: WebSVN 2.1.0

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