システムタスク $bits を使います。bit 幅 (integer) を返します。
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
reg [7:0] r; | |
$display($bits(r)); // $bits(r): 8 | |
$display($bits(1 << 8)); // $bits(1 << 8): 32 | |
$display($bits(logic)); // $bits(logic): 1 |
4値の場合 1bit を返し、ツールの実装で実際に使われるメモリサイズではありません。
コンパイル時に値が決定されるものに使えます。そのため、reg, wire の宣言などに使えます。
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
reg [$bits(r)-1:0] d; |