From 389f9d8e7d4148b8744a8ee662e4a271e107df33 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Tue, 27 Jun 2023 14:57:26 -0700 Subject: [PATCH] Add messages to require statements in Math (#3385) * log2 functions * unsignedBitLength (cherry picked from commit 88fecfc1c6845595bc894561f2ce9bc6afb20143) # Conflicts: # src/main/scala/chisel3/util/Math.scala --- src/main/scala/chisel3/util/Math.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/scala/chisel3/util/Math.scala b/src/main/scala/chisel3/util/Math.scala index 6eab9241d8d..367070c06a8 100644 --- a/src/main/scala/chisel3/util/Math.scala +++ b/src/main/scala/chisel3/util/Math.scala @@ -27,7 +27,15 @@ object log2Up { // https://github.com/freechipsproject/chisel3/issues/847 //@chiselRuntimeDeprecated //@deprecated("Use log2Ceil instead", "chisel3") +<<<<<<< HEAD def apply(in: BigInt): Int = Chisel.log2Up(in) +======= + def apply(in: BigInt): Int = { + require(in >= 0, s"log2Up is only defined on integers >= 0, got $in") + 1.max((in - 1).bitLength) + } + def apply(in: Int): Int = apply(BigInt(in)) +>>>>>>> 88fecfc1c (Add messages to require statements in Math (#3385)) } /** Compute the log2 of a Scala integer, rounded up. @@ -46,7 +54,7 @@ object log2Up { */ object log2Ceil { def apply(in: BigInt): Int = { - require(in > 0) + require(in > 0, s"log2 is only defined on integers > 0, got $in") (in - 1).bitLength } def apply(in: Int): Int = apply(BigInt(in)) @@ -109,7 +117,7 @@ object unsignedBitLength { * @return - an Int representing the number of bits to encode. */ def apply(in: BigInt): Int = { - require(in >= 0) + require(in >= 0, s"Unsigned integers must be non-negative, got $in") in.bitLength } }