-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.pkg
More file actions
executable file
·44 lines (37 loc) · 1.27 KB
/
common.pkg
File metadata and controls
executable file
·44 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//******************************************************************************
//*
//* Project: Any
//*
//* Description: Common code definitions file
//*
//* Version 1.0
//*
//* Copyright (c) 2008-2010, Harry E. Zhurov
//*
//* $Revision: 37 $
//* $Date:: 2010-07-28 20:56:24 #$
//*
//------------------------------------------------------------------------------
`ifndef COMMON_H
`define COMMON_H
package common;
//------------------------------------------------------------------------------
function integer clog2 (input integer num); // this function calculates ceil(log2(num))
begin
num = num - 1; // without this statement clog2(32) will be 6 but must be 5
for (clog2 = 0; num > 0; clog2 = clog2 + 1)
num = num >> 1;
end
endfunction
//------------------------------------------------------------------------------
function int max(input int x, input int y);
return x > y ? x : y;
endfunction
//------------------------------------------------------------------------------
function int bits(input int x);
return ( x == (1 << clog2(x)) ) ? clog2(x)+1 : clog2(x);
endfunction
//------------------------------------------------------------------------------
endpackage
import common::*;
`endif // COMMON_H