RegField: separate UInt=>bytes and bytes=>regs
This commit is contained in:
committed by
Andrew Waterman
parent
943c36954d
commit
4b1de82c1d
@ -108,7 +108,7 @@ object RegField
|
||||
|
||||
// Split a large register into a sequence of byte fields
|
||||
// The bytes can be individually written, as they are one byte per field
|
||||
def bytes(x: UInt, base: Int = 0, beatBytes: Int = 4): Seq[RegField.Map] = {
|
||||
def bytes(x: UInt): Seq[RegField] = {
|
||||
require (x.getWidth % 8 == 0)
|
||||
val bytes = Seq.tabulate(x.getWidth/8) { i => x(8*(i+1)-1, 8*i) }
|
||||
val wires = bytes.map { b => Wire(init = b) }
|
||||
@ -118,10 +118,15 @@ object RegField
|
||||
when (valid) { wires(i) := data }
|
||||
Bool(true)
|
||||
})
|
||||
}.grouped(beatBytes).toSeq.zipWithIndex.map { case (reg, i) =>
|
||||
(i+base, reg)
|
||||
}
|
||||
}
|
||||
|
||||
// Divide a long sequence of RegFields into a maximum sized registers
|
||||
// Your input RegFields may not cross a beatBytes boundary!
|
||||
def split(fields: Seq[RegField], base: Int, beatBytes: Int = 4): Seq[RegField.Map] = {
|
||||
val offsets = fields.map(_.width).scanLeft(0)(_ + _).init
|
||||
(offsets zip fields).groupBy(_._1 / (beatBytes*8)).toList.map(r => (r._1 + base, r._2.map(_._2)))
|
||||
}
|
||||
}
|
||||
|
||||
trait HasRegMap
|
||||
|
Reference in New Issue
Block a user