diff options
| author | Andrew Waterman | 2016-07-07 00:37:34 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2016-07-07 00:37:34 -0700 |
| commit | a49e27d1247597de5997f0fe6f3d2ac594ec2e6b (patch) | |
| tree | 0333307a5f9ba11f04185c21440d1150621a405b /src/main/scala | |
| parent | bae5cbbbf64782ffe7a5a06981d94655bfc76089 (diff) | |
Improve Fill code generation
Diffstat (limited to 'src/main/scala')
| -rw-r--r-- | src/main/scala/chisel3/util/Bitwise.scala | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/main/scala/chisel3/util/Bitwise.scala b/src/main/scala/chisel3/util/Bitwise.scala index 7f295200..3134d043 100644 --- a/src/main/scala/chisel3/util/Bitwise.scala +++ b/src/main/scala/chisel3/util/Bitwise.scala @@ -29,22 +29,17 @@ object Fill { n match { case 0 => UInt(width=0) case 1 => x - case y if n > 1 => + case _ if x.width.known && x.getWidth == 1 => + Mux(x.toBool, UInt((BigInt(1) << n) - 1, n), UInt(0, n)) + case _ if n > 1 => val p2 = Array.ofDim[UInt](log2Up(n + 1)) p2(0) = x for (i <- 1 until p2.length) p2(i) = Cat(p2(i-1), p2(i-1)) - Cat((0 until log2Up(y + 1)).filter(i => (y & (1 << i)) != 0).map(p2(_))) + Cat((0 until log2Up(n + 1)).filter(i => (n & (1 << i)) != 0).map(p2(_))) case _ => throw new IllegalArgumentException(s"n (=$n) must be nonnegative integer.") } } - /** Fan out x n times */ - def apply(n: Int, x: Bool): UInt = - if (n > 1) { - UInt(0,n) - x - } else { - apply(n, x: UInt) - } } /** Litte/big bit endian convertion: reverse the order of the bits in a UInt. |
