diff options
| author | Andrew Waterman | 2015-07-16 16:25:51 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-07-16 16:25:51 -0700 |
| commit | ecd6ba68f8f9dadab51691954713b1d07fc84599 (patch) | |
| tree | 2bc6656dac9d16a3477d71b1ee87a9ca6634fd80 | |
| parent | a52750db7f16116243d53455b7b3ad176cae6517 (diff) | |
Add missing Log2
| -rw-r--r-- | src/main/scala/utils.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main/scala/utils.scala b/src/main/scala/utils.scala index 0fb275d6..804ed12e 100644 --- a/src/main/scala/utils.scala +++ b/src/main/scala/utils.scala @@ -29,6 +29,16 @@ object isPow2 def apply(in: Int): Boolean = in > 0 && ((in & (in-1)) == 0) } +object Log2 { + def apply(x: UInt, width: Int): UInt = { + if (width < 2) UInt(0) + else Mux(x(width-1), UInt(width-1), apply(x, width-1)) + } + + // TODO: infer the width in the backend + def apply(x: UInt): UInt = apply(x, x.getWidth) +} + object FillInterleaved { def apply(n: Int, in: Bits): Bits = apply(n, in.toBools) |
