summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Waterman2017-02-24 00:08:18 -0800
committerJack Koenig2017-03-08 11:27:04 -0600
commit9cad9ec21ac7a9a8c463e2c694b6285269982a84 (patch)
tree03afab0e61f6891f9269d68d56a8ef0b13d3b31f /src
parent246c2e8336c19d39bfb92dc8f2ee730a2ac4c55b (diff)
Improve Reverse's exception behavior; avoid log2Up
Provide a better error message when length < 0. Change log2Up in log2Ceil, which has no effect, since the argument is always at least 2.
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/chisel3/util/Bitwise.scala13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/main/scala/chisel3/util/Bitwise.scala b/src/main/scala/chisel3/util/Bitwise.scala
index fec4be9a..387fd109 100644
--- a/src/main/scala/chisel3/util/Bitwise.scala
+++ b/src/main/scala/chisel3/util/Bitwise.scala
@@ -90,10 +90,10 @@ object Fill {
* }}}
*/
object Reverse {
- private def doit(in: UInt, length: Int): UInt = {
- if (length == 1) {
- in
- } else if (isPow2(length) && length >= 8 && length <= 64) {
+ private def doit(in: UInt, length: Int): UInt = length match {
+ case _ if length < 0 => throw new IllegalArgumentException(s"length (=$length) must be nonnegative integer.")
+ case _ if length <= 1 => in
+ case _ if isPow2(length) && length >= 8 && length <= 64 =>
// This esoterica improves simulation performance
var res = in
var shift = length >> 1
@@ -104,10 +104,9 @@ object Reverse {
shift = shift >> 1
} while (shift > 0)
res
- } else {
- val half = (1 << log2Up(length))/2
+ case _ =>
+ val half = (1 << log2Ceil(length))/2
Cat(doit(in(half-1,0), half), doit(in(length-1,half), length-half))
- }
}
def apply(in: UInt): UInt = doit(in, in.getWidth)