From 29ed8eb31a698bf4e1e4d271e84a53c980e2e3cf Mon Sep 17 00:00:00 2001 From: Henry Cook Date: Tue, 17 Jan 2012 23:49:32 -0800 Subject: [PATCH] More utils for nbdcache --- rocket/src/main/scala/util.scala | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/rocket/src/main/scala/util.scala b/rocket/src/main/scala/util.scala index 1cbc7674..2e2dd20b 100644 --- a/rocket/src/main/scala/util.scala +++ b/rocket/src/main/scala/util.scala @@ -13,7 +13,7 @@ object foldR object log2up { - def apply(in: Int) = ceil(log(in)/log(2)).toInt + def apply(in: Int) = if (in == 1) 1 else ceil(log(in)/log(2)).toInt } object FillInterleaved @@ -38,6 +38,27 @@ object Reverse } } +object OHToUFix +{ + def apply(in: Bits): UFix = + { + var out = UFix(0) + for(i <- 0 until in.getWidth) + if(in(i) == Bits(1)) + out = UFix(i) + out + } +} + +object UFixToOH +{ + def apply(in: UFix, width: Int): Bits = + { + val out = Bits(1, width) + out << in + } +} + class Mux1H(n: Int, w: Int) extends Component { val io = new Bundle {