From c22c773674ff490ca55c2d1f2ee8700e80053c3c Mon Sep 17 00:00:00 2001 From: leikou01 Date: Sat, 7 Mar 2020 08:24:18 -0800 Subject: [PATCH] add SuperscalarEventSets into Events.scala --- src/main/scala/rocket/Events.scala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/scala/rocket/Events.scala b/src/main/scala/rocket/Events.scala index 18ba566d346..9c7da8a5a5f 100644 --- a/src/main/scala/rocket/Events.scala +++ b/src/main/scala/rocket/Events.scala @@ -48,3 +48,28 @@ class EventSets(val eventSets: Seq[EventSet]) { private def eventSetIdBits = 8 } + +class SuperscalarEventSets(eventSets: Seq[(Seq[EventSet], (UInt, UInt) => UInt)]) { + def evaluate(eventSel: UInt): UInt = { + val (set, mask) = decode(eventSel) + val sets = for ((sets, reducer) <- eventSets) + yield sets.map(_.check(mask)).reduce(reducer) + val zeroPadded = sets.padTo(1 << eventSetIdBits, 0.U) + zeroPadded(set) + } + + def toScalarEventSets: EventSets = new EventSets(eventSets.map(_._1.head)) + + def cover() { eventSets.foreach(_._1.foreach(_.withCovers)) } + + private def decode(counter: UInt): (UInt, UInt) = { + require(eventSetIdBits > 0) + (counter(eventSetIdBits-1, 0), counter >> maxEventSetIdBits) + } + + private def eventSetIdBits = log2Ceil(eventSets.size) + private def maxEventSetIdBits = 8 + + require(eventSets.forall(s => s._1.forall(_.size == s._1.head.size))) + require(eventSetIdBits <= maxEventSetIdBits) +}