From 4b3b3f9d21d99be7dbd1e2d0a5d38df2ad89880e Mon Sep 17 00:00:00 2001 From: Jim Lawson Date: Fri, 17 Jul 2015 14:59:31 -0700 Subject: Restructure when() logic. --- src/main/scala/Chisel/ImplicitConversions.scala | 6 +++++ src/main/scala/Chisel/Log2.scala | 35 +++++++++++++++++++++++++ src/main/scala/ImplicitConversions.scala | 6 ----- src/main/scala/Log2.scala | 35 ------------------------- 4 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 src/main/scala/Chisel/ImplicitConversions.scala create mode 100644 src/main/scala/Chisel/Log2.scala delete mode 100644 src/main/scala/ImplicitConversions.scala delete mode 100644 src/main/scala/Log2.scala diff --git a/src/main/scala/Chisel/ImplicitConversions.scala b/src/main/scala/Chisel/ImplicitConversions.scala new file mode 100644 index 00000000..c67efb7e --- /dev/null +++ b/src/main/scala/Chisel/ImplicitConversions.scala @@ -0,0 +1,6 @@ +package Chisel + +object ImplicitConversions { + implicit def intToUInt(x: Int): UInt = UInt(x) + implicit def booleanToBool(x: Boolean): Bool = Bool(x) +} diff --git a/src/main/scala/Chisel/Log2.scala b/src/main/scala/Chisel/Log2.scala new file mode 100644 index 00000000..fe1c1372 --- /dev/null +++ b/src/main/scala/Chisel/Log2.scala @@ -0,0 +1,35 @@ +package Chisel + +// TODO: these operators should be backend nodes so their width can be +// inferred, rather than using getWidth. also, C++ perf would improve. + +object Log2 { + def apply(x: Bits, width: Int): UInt = { + if (width < 2) UInt(0) + else if (width == 2) x(1) + else Mux(x(width-1), UInt(width-1), apply(x, width-1)) + } + + def apply(x: Bits): UInt = apply(x, x.getWidth) +} + +object OHToUInt { + def apply(in: Seq[Bool]): UInt = apply(Vec(in)) + def apply(in: Vec[Bool]): UInt = apply(in.toBits, in.size) + def apply(in: Bits): UInt = apply(in, in.getWidth) + + def apply(in: Bits, width: Int): UInt = { + if (width <= 2) Log2(in, width) + else { + val mid = 1 << (log2Up(width)-1) + val hi = in(width-1, mid) + val lo = in(mid-1, 0) + Cat(hi.orR, apply(hi | lo, mid)) + } + } +} + +object PriorityEncoder { + def apply(in: Iterable[Bool]): UInt = PriorityMux(in, (0 until in.size).map(UInt(_))) + def apply(in: Bits): UInt = apply(in.toBools) +} diff --git a/src/main/scala/ImplicitConversions.scala b/src/main/scala/ImplicitConversions.scala deleted file mode 100644 index c67efb7e..00000000 --- a/src/main/scala/ImplicitConversions.scala +++ /dev/null @@ -1,6 +0,0 @@ -package Chisel - -object ImplicitConversions { - implicit def intToUInt(x: Int): UInt = UInt(x) - implicit def booleanToBool(x: Boolean): Bool = Bool(x) -} diff --git a/src/main/scala/Log2.scala b/src/main/scala/Log2.scala deleted file mode 100644 index fe1c1372..00000000 --- a/src/main/scala/Log2.scala +++ /dev/null @@ -1,35 +0,0 @@ -package Chisel - -// TODO: these operators should be backend nodes so their width can be -// inferred, rather than using getWidth. also, C++ perf would improve. - -object Log2 { - def apply(x: Bits, width: Int): UInt = { - if (width < 2) UInt(0) - else if (width == 2) x(1) - else Mux(x(width-1), UInt(width-1), apply(x, width-1)) - } - - def apply(x: Bits): UInt = apply(x, x.getWidth) -} - -object OHToUInt { - def apply(in: Seq[Bool]): UInt = apply(Vec(in)) - def apply(in: Vec[Bool]): UInt = apply(in.toBits, in.size) - def apply(in: Bits): UInt = apply(in, in.getWidth) - - def apply(in: Bits, width: Int): UInt = { - if (width <= 2) Log2(in, width) - else { - val mid = 1 << (log2Up(width)-1) - val hi = in(width-1, mid) - val lo = in(mid-1, 0) - Cat(hi.orR, apply(hi | lo, mid)) - } - } -} - -object PriorityEncoder { - def apply(in: Iterable[Bool]): UInt = PriorityMux(in, (0 until in.size).map(UInt(_))) - def apply(in: Bits): UInt = apply(in.toBools) -} -- cgit v1.2.3