システムタスク $clog2 が使えます。2 を底とする対数の天井関数の結果が得られます。
$clog2 の結果 + 1 が必要な bit 幅です。使えるのは、Verilog 2005 からかな?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module m #(max_size = 1023) ( | |
input clk, | |
input rst_n, | |
input [$clog2(max_count):0] in, | |
output [$clog2(max_count):0] out | |
); | |
endmodule |
See Also
- IEEE Std 1364™-2005: 17.11.1 Integer math functions
- IEEE Std 1800™-2012: 20.8.1 Integer math functions