Skip to content

Commit 90a8836

Browse files
committed
Added clogb2 function
1 parent e3cba6a commit 90a8836

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

clogb2.svh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//------------------------------------------------------------------------------
2+
// clogb2.svh
3+
// published as part of https://github.com/pConst/basic_verilog
4+
// Konstantin Pavlov, [email protected]
5+
//------------------------------------------------------------------------------
6+
7+
// INFO ------------------------------------------------------------------------
8+
// Calculates counter/address width based on specified vector/RAM depth
9+
//
10+
// Function should be instantiated inside a module
11+
// But you are free to call it from anywhere by its hierarchical name
12+
//
13+
// To add clogb2 function to your module:
14+
// `include "clogb2.svh"
15+
//
16+
17+
function integer clogb2;
18+
input integer depth;
19+
20+
for( clogb2=0; depth>0; clogb2=clogb2+1 ) begin
21+
depth = depth >> 1;
22+
end
23+
endfunction
24+

0 commit comments

Comments
 (0)