2016-11-28 01:16:37 +01:00
|
|
|
// See LICENSE.SiFive for license details.
|
|
|
|
|
2016-09-01 01:45:18 +02:00
|
|
|
package uncore
|
|
|
|
|
|
|
|
import Chisel._
|
2016-10-04 00:17:36 +02:00
|
|
|
import diplomacy._
|
2016-09-01 01:45:18 +02:00
|
|
|
|
|
|
|
package object tilelink2
|
|
|
|
{
|
2016-10-27 04:54:47 +02:00
|
|
|
type TLInwardNode = InwardNodeHandle[TLClientPortParameters, TLManagerPortParameters, TLBundle]
|
2016-10-08 08:35:20 +02:00
|
|
|
type TLOutwardNode = OutwardNodeHandle[TLClientPortParameters, TLManagerPortParameters, TLBundle]
|
|
|
|
type TLAsyncOutwardNode = OutwardNodeHandle[TLAsyncClientPortParameters, TLAsyncManagerPortParameters, TLAsyncBundle]
|
2017-02-17 04:19:00 +01:00
|
|
|
type TLRationalOutwardNode = OutwardNodeHandle[TLRationalClientPortParameters, TLRationalManagerPortParameters, TLRationalBundle]
|
2016-10-08 08:35:20 +02:00
|
|
|
type IntOutwardNode = OutwardNodeHandle[IntSourcePortParameters, IntSinkPortParameters, Vec[Bool]]
|
2016-10-27 04:54:47 +02:00
|
|
|
|
2016-10-17 04:57:56 +02:00
|
|
|
def OH1ToOH(x: UInt) = (x << 1 | UInt(1)) & ~Cat(UInt(0, width=1), x)
|
|
|
|
def OH1ToUInt(x: UInt) = OHToUInt(OH1ToOH(x))
|
2016-09-07 08:46:44 +02:00
|
|
|
def UIntToOH1(x: UInt, width: Int) = ~(SInt(-1, width=width).asUInt << x)(width-1, 0)
|
2016-11-23 06:20:26 +01:00
|
|
|
def holdUnless[T <: Data](in : T, enable: Bool): T = Mux(!enable, RegEnable(in, enable), in)
|
2016-09-08 19:38:38 +02:00
|
|
|
def trailingZeros(x: Int) = if (x > 0) Some(log2Ceil(x & -x)) else None
|
2016-10-11 19:29:31 +02:00
|
|
|
// Fill 1s from low bits to high bits
|
|
|
|
def leftOR(x: UInt) = {
|
2016-09-22 20:33:40 +02:00
|
|
|
val w = x.getWidth
|
|
|
|
def helper(s: Int, x: UInt): UInt =
|
2016-09-23 00:13:35 +02:00
|
|
|
if (s >= w) x else helper(s+s, x | (x << s)(w-1,0))
|
2016-09-22 20:33:40 +02:00
|
|
|
helper(1, x)
|
|
|
|
}
|
2016-10-11 19:29:31 +02:00
|
|
|
// Fill 1s form high bits to low bits
|
|
|
|
def rightOR(x: UInt) = {
|
|
|
|
val w = x.getWidth
|
|
|
|
def helper(s: Int, x: UInt): UInt =
|
|
|
|
if (s >= w) x else helper(s+s, x | (x >> s))
|
|
|
|
helper(1, x)
|
|
|
|
}
|
2016-10-06 09:36:38 +02:00
|
|
|
// This gets used everywhere, so make the smallest circuit possible ...
|
|
|
|
def maskGen(addr_lo: UInt, lgSize: UInt, beatBytes: Int): UInt = {
|
|
|
|
val lgBytes = log2Ceil(beatBytes)
|
|
|
|
val sizeOH = UIntToOH(lgSize, log2Up(beatBytes))
|
|
|
|
def helper(i: Int): Seq[(Bool, Bool)] = {
|
|
|
|
if (i == 0) {
|
|
|
|
Seq((lgSize >= UInt(lgBytes), Bool(true)))
|
|
|
|
} else {
|
|
|
|
val sub = helper(i-1)
|
|
|
|
val size = sizeOH(lgBytes - i)
|
|
|
|
val bit = addr_lo(lgBytes - i)
|
|
|
|
val nbit = !bit
|
|
|
|
Seq.tabulate (1 << i) { j =>
|
|
|
|
val (sub_acc, sub_eq) = sub(j/2)
|
|
|
|
val eq = sub_eq && (if (j % 2 == 1) bit else nbit)
|
|
|
|
val acc = sub_acc || (size && eq)
|
|
|
|
(acc, eq)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Cat(helper(lgBytes).map(_._1).reverse)
|
|
|
|
}
|
2016-09-01 01:45:18 +02:00
|
|
|
}
|