summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman2015-10-26 13:38:23 -0700
committerAndrew Waterman2015-10-26 13:38:23 -0700
commit48747c7e44f949bcb454e3b2393b013522a09b4d (patch)
tree670d13502c89aa35c6e7a6905c211d8d2eb0999d
parenta0a693c668596bdeb5efa39d5ce5953d728b7775 (diff)
Make all the log2 functions take BigInt (in addition to Int)
-rw-r--r--src/main/scala/Chisel/Utils.scala17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main/scala/Chisel/Utils.scala b/src/main/scala/Chisel/Utils.scala
index 68005f7f..4d642a47 100644
--- a/src/main/scala/Chisel/Utils.scala
+++ b/src/main/scala/Chisel/Utils.scala
@@ -24,30 +24,35 @@ object Enum {
/** Compute the log2 rounded up with min value of 1 */
object log2Up {
- def apply(in: Int): Int = 1 max BigInt(in-1).bitLength
+ def apply(in: BigInt): Int = 1 max (in-1).bitLength
+ def apply(in: Int): Int = apply(BigInt(in))
}
/** Compute the log2 rounded up */
object log2Ceil {
- def apply(in: Int): Int = {
+ def apply(in: BigInt): Int = {
require(in > 0)
- BigInt(in-1).bitLength
+ (in-1).bitLength
}
+ def apply(in: Int): Int = apply(BigInt(in))
}
/** Compute the log2 rounded down with min value of 1 */
object log2Down {
- def apply(in: Int): Int = log2Up(in) - (if (isPow2(in)) 0 else 1)
+ def apply(in: BigInt): Int = log2Up(in) - (if (isPow2(in)) 0 else 1)
+ def apply(in: Int): Int = apply(BigInt(in))
}
/** Compute the log2 rounded down */
object log2Floor {
- def apply(in: Int): Int = log2Ceil(in) - (if (isPow2(in)) 0 else 1)
+ def apply(in: BigInt): Int = log2Ceil(in) - (if (isPow2(in)) 0 else 1)
+ def apply(in: Int): Int = apply(BigInt(in))
}
/** Check if an Integer is a power of 2 */
object isPow2 {
- def apply(in: Int): Boolean = in > 0 && ((in & (in-1)) == 0)
+ def apply(in: BigInt): Boolean = in > 0 && ((in & (in-1)) == 0)
+ def apply(in: Int): Boolean = apply(BigInt(in))
}
object FillInterleaved