1
0

Support non-power-of-2 BTBs; prefer invalid entries

This commit is contained in:
Andrew Waterman
2013-08-24 17:33:11 -07:00
parent daf23b8f79
commit 3895b75a56
2 changed files with 27 additions and 7 deletions

View File

@ -130,3 +130,21 @@ case class WideCounter(width: Int, inc: Bool = Bool(true))
if (isWide) large := (if (w < smallWidth) UInt(0) else x(w.min(width)-1,smallWidth))
}
}
object Random
{
def apply(mod: Int, inc: Bool = Bool(true)): UInt = {
if (isPow2(mod)) {
require(mod <= 65536)
LFSR16(inc)(log2Up(mod)-1,0).toUInt
} else {
val max = 1 << log2Up(mod*8)
val rand_pow2 = apply(max, inc)
var res = UInt(mod-1)
for (i <- mod-1 to 1 by -1)
res = Mux(rand_pow2 < UInt(i*max/mod), UInt(i-1), res)
res
}
}
}