diff options
| author | Andrew Waterman | 2016-04-14 11:52:42 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2016-04-14 11:52:42 -0700 |
| commit | a55309514ef9a89e5c830b1f1fe6d9719e986422 (patch) | |
| tree | 195fe016200ee9f27cbe7d4fa6f9ecf8c3e32bee /src | |
| parent | 635f98dd174e62151c82d20d4fca35272a85c146 (diff) | |
Reject log2Up on negative inputs
Mathematically, we should also reject 0, like log2Ceil does. But accepting
0 and returning 1 is more in the spirit of the special case for widths.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/Chisel/util/Math.scala | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/main/scala/Chisel/util/Math.scala b/src/main/scala/Chisel/util/Math.scala index 270301f0..5f8212d8 100644 --- a/src/main/scala/Chisel/util/Math.scala +++ b/src/main/scala/Chisel/util/Math.scala @@ -7,7 +7,10 @@ package Chisel /** Compute the log2 rounded up with min value of 1 */ object log2Up { - def apply(in: BigInt): Int = 1 max (in-1).bitLength + def apply(in: BigInt): Int = { + require(in >= 0) + 1 max (in-1).bitLength + } def apply(in: Int): Int = apply(BigInt(in)) } |
