From a55309514ef9a89e5c830b1f1fe6d9719e986422 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Thu, 14 Apr 2016 11:52:42 -0700 Subject: 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. --- src/main/scala/Chisel/util/Math.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') 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)) } -- cgit v1.2.3