1
0

Don't allow multiple entries for same PC in BTB

Necessary for RVC forward-progress guarantee.
This commit is contained in:
Andrew Waterman
2016-10-06 09:41:46 -07:00
parent 9b8e8a8b9e
commit 5980dc160f
2 changed files with 22 additions and 0 deletions

View File

@ -41,4 +41,21 @@ package object util {
// this one's snagged from scalaz
def option[T](z: => T): Option[T] = if (x) Some(z) else None
}
object PopCountAtLeast {
private def two(x: UInt): (Bool, Bool) = x.getWidth match {
case 1 => (Bool(true), Bool(false))
case n =>
val half = x.getWidth / 2
val (leftOne, leftTwo) = two(x(half - 1, 0))
val (rightOne, rightTwo) = two(x(x.getWidth - 1, half))
(leftOne || rightOne, leftTwo || rightTwo || (leftOne && rightOne))
}
def apply(x: UInt, n: Int): Bool = n match {
case 0 => Bool(true)
case 1 => x.orR
case 2 => two(x)._2
case 3 => PopCount(x) >= UInt(n)
}
}
}