diff options
| author | Jack | 2022-01-12 04:27:19 +0000 |
|---|---|---|
| committer | Jack | 2022-01-12 04:27:19 +0000 |
| commit | 29df513e348cc809876893f650af8180f0190496 (patch) | |
| tree | 06daaea954b4e5af7113f06e4bdbb78b33515cb3 /src/main/scala/chisel3/util/Math.scala | |
| parent | 5242ce90659decb9058ee75db56e5c188029fbf9 (diff) | |
| parent | 747d16311bdf185d2e98e452b14cb5d8ccca004c (diff) | |
Merge branch 'master' into 3.5-release
Diffstat (limited to 'src/main/scala/chisel3/util/Math.scala')
| -rw-r--r-- | src/main/scala/chisel3/util/Math.scala | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main/scala/chisel3/util/Math.scala b/src/main/scala/chisel3/util/Math.scala index 2a833e80..6eab9241 100644 --- a/src/main/scala/chisel3/util/Math.scala +++ b/src/main/scala/chisel3/util/Math.scala @@ -47,7 +47,7 @@ object log2Up { object log2Ceil { def apply(in: BigInt): Int = { require(in > 0) - (in-1).bitLength + (in - 1).bitLength } def apply(in: Int): Int = apply(BigInt(in)) } @@ -82,7 +82,7 @@ object log2Down { */ object log2Floor { def apply(in: BigInt): Int = log2Ceil(in) - (if (isPow2(in)) 0 else 1) - def apply(in: Int): Int = apply(BigInt(in)) + def apply(in: Int): Int = apply(BigInt(in)) } /** Returns whether a Scala integer is a power of two. @@ -95,12 +95,12 @@ object log2Floor { * }}} */ object isPow2 { - def apply(in: BigInt): Boolean = in > 0 && ((in & (in-1)) == 0) - def apply(in: Int): Boolean = apply(BigInt(in)) + def apply(in: BigInt): Boolean = in > 0 && ((in & (in - 1)) == 0) + def apply(in: Int): Boolean = apply(BigInt(in)) } - object unsignedBitLength { + /** Return the number of bits required to encode a specific value, assuming no sign bit is required. * * Basically, `n.bitLength`. NOTE: This will return 0 for a value of 0. @@ -115,6 +115,7 @@ object unsignedBitLength { } object signedBitLength { + /** Return the number of bits required to encode a specific value, assuming a sign bit is required. * * Basically, 0 for 0, 1 for -1, and `n.bitLength` + 1 for everything else. @@ -124,9 +125,9 @@ object signedBitLength { */ def apply(in: BigInt): Int = { in.toInt match { - case 0 => 0 + case 0 => 0 case -1 => 1 - case _ => in.bitLength + 1 + case _ => in.bitLength + 1 } } |
