From 6465e2df143b74f8d34ea5fb49eaa880e8549cc8 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 24 Mar 2014 04:36:53 -0700 Subject: [PATCH] Make Int -> Bool conversions explicit --- rocket/src/main/scala/ecc.scala | 4 ++-- rocket/src/main/scala/util.scala | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rocket/src/main/scala/ecc.scala b/rocket/src/main/scala/ecc.scala index fc5e8773..01164e88 100644 --- a/rocket/src/main/scala/ecc.scala +++ b/rocket/src/main/scala/ecc.scala @@ -57,7 +57,7 @@ class SECCode extends Code val y = for (i <- 1 to n) yield { if (isPow2(i)) { - val r = for (j <- 1 to n; if j != i && (j & i)) + val r = for (j <- 1 to n; if j != i && (j & i).toBoolean) yield x(mapping(j)) r reduce (_^_) } else @@ -71,7 +71,7 @@ class SECCode extends Code val p2 = for (i <- 0 until log2Up(n)) yield 1 << i val syndrome = p2 map { i => - val r = for (j <- 1 to n; if j & i) + val r = for (j <- 1 to n; if (j & i).toBoolean) yield y(j-1) r reduce (_^_) } diff --git a/rocket/src/main/scala/util.scala b/rocket/src/main/scala/util.scala index 7735847c..d917a522 100644 --- a/rocket/src/main/scala/util.scala +++ b/rocket/src/main/scala/util.scala @@ -3,15 +3,18 @@ package rocket import Chisel._ import scala.math._ -object Util -{ +class BooleanToInt(x: Int) { + def toBoolean: Boolean = if (x != 0) true else false +} + +object Util { implicit def intToUInt(x: Int): UInt = UInt(x) - implicit def intToBoolean(x: Int): Boolean = if (x != 0) true else false - implicit def booleanToInt(x: Boolean): Int = if (x) 1 else 0 implicit def booleanToBool(x: Boolean): Bits = Bool(x) implicit def intSeqToUIntSeq(x: Iterable[Int]): Iterable[UInt] = x.map(UInt(_)) - implicit def wcToUInt(c: WideCounter): UInt = c.value + + implicit def booleanToInt(x: Boolean): Int = if (x) 1 else 0 + implicit def intToBooleanToInt(x: Int): BooleanToInt = new BooleanToInt(x) } object AVec