1
0

Make Int -> Bool conversions explicit

This commit is contained in:
Andrew Waterman 2014-03-24 04:36:53 -07:00
parent 1b030777ce
commit 6465e2df14
2 changed files with 10 additions and 7 deletions

View File

@ -57,7 +57,7 @@ class SECCode extends Code
val y = for (i <- 1 to n) yield { val y = for (i <- 1 to n) yield {
if (isPow2(i)) { 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)) yield x(mapping(j))
r reduce (_^_) r reduce (_^_)
} else } else
@ -71,7 +71,7 @@ class SECCode extends Code
val p2 = for (i <- 0 until log2Up(n)) yield 1 << i val p2 = for (i <- 0 until log2Up(n)) yield 1 << i
val syndrome = p2 map { 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) yield y(j-1)
r reduce (_^_) r reduce (_^_)
} }

View File

@ -3,15 +3,18 @@ package rocket
import Chisel._ import Chisel._
import scala.math._ 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 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 booleanToBool(x: Boolean): Bits = Bool(x)
implicit def intSeqToUIntSeq(x: Iterable[Int]): Iterable[UInt] = x.map(UInt(_)) implicit def intSeqToUIntSeq(x: Iterable[Int]): Iterable[UInt] = x.map(UInt(_))
implicit def wcToUInt(c: WideCounter): UInt = c.value 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 object AVec