From 48747c7e44f949bcb454e3b2393b013522a09b4d Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 26 Oct 2015 13:38:23 -0700 Subject: Make all the log2 functions take BigInt (in addition to Int) --- src/main/scala/Chisel/Utils.scala | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') 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 -- cgit v1.2.3