Skip to content

Commit 9d51a2b

Browse files
committed
Upd clogb2 info
1 parent 93bb8db commit 9d51a2b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

clogb2.svh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77
// INFO ------------------------------------------------------------------------
88
// Calculates counter/address width based on specified vector/RAM depth
99
//
10+
// see also: http://www.sunburst-design.com/papers/CummingsHDLCON2001_Verilog2001.pdf
11+
//
12+
// Compared with system function $clog2():
13+
// =======================================
14+
// $clog2(0) = 0; clogb2(0) = 0;
15+
// $clog2(1) = 0; clogb2(1) = 1;
16+
// $clog2(2) = 1; clogb2(2) = 2;
17+
// $clog2(3) = 2; clogb2(3) = 2;
18+
// $clog2(4) = 2; clogb2(4) = 3;
19+
// $clog2(5) = 3; clogb2(5) = 3;
20+
// $clog2(6) = 3; clogb2(6) = 3;
21+
// $clog2(7) = 3; clogb2(7) = 3;
22+
// $clog2(8) = 3; clogb2(8) = 4;
23+
// $clog2(9) = 4; clogb2(9) = 4;
24+
// $clog2(10)= 4; clogb2(10)= 4;
25+
// $clog2(11)= 4; clogb2(11)= 4;
26+
// $clog2(12)= 4; clogb2(12)= 4;
27+
// $clog2(13)= 4; clogb2(13)= 4;
28+
// $clog2(14)= 4; clogb2(14)= 4;
29+
// $clog2(15)= 4; clogb2(15)= 4;
30+
// $clog2(16)= 4; clogb2(16)= 5;
31+
//
1032
// Function should be instantiated inside a module
1133
// But you are free to call it from anywhere by its hierarchical name
1234
//
@@ -15,10 +37,11 @@
1537
//
1638

1739
function integer clogb2;
18-
input integer depth;
40+
input [31:0] depth;
1941

2042
for( clogb2=0; depth>0; clogb2=clogb2+1 ) begin
2143
depth = depth >> 1;
2244
end
45+
2346
endfunction
2447

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy