Skip to content

Commit

Permalink
[doc] refactor and add an example for decoder attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed May 26, 2024
1 parent 4348e91 commit a877927
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 126 deletions.
4 changes: 3 additions & 1 deletion t1/src/decoder/InstructionDocumentation.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.rtl
package org.chipsalliance.t1.rtl.decoder

import org.chipsalliance.rvdecoderdb.Instruction
import org.chipsalliance.t1.rtl.T1Parameter

/** Generate documentation for each instructions for T1.
* The documentation should contain the behavior for instruction in a specific configuration in T1.
* @todo should it be a post process at omreader?
*/
case class InstructionDocumentation(instruction: Instruction, t1Parameter: T1Parameter) {
override def toString: String = instruction.name match {
Expand Down
133 changes: 8 additions & 125 deletions t1/src/decoder/T1DecodePattern.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.rtl
package org.chipsalliance.t1.rtl.decoder

import chisel3._
import chisel3.experimental.hierarchy.core.Definition
import chisel3.experimental.hierarchy.{instantiable, public, Instantiate}
import chisel3.experimental.hierarchy.{Instantiate, instantiable, public}
import chisel3.properties.{Class, ClassType, Property}
import chisel3.util.BitPat
import chisel3.util.experimental.decode.DecodePattern
import org.chipsalliance.rvdecoderdb.Instruction
import org.chipsalliance.t1.rtl.T1Parameter
import org.chipsalliance.t1.rtl.decoder.attribute.isVector

@instantiable
class T1DecodeAttributeOM extends Class {
Expand Down Expand Up @@ -46,136 +48,17 @@ class T1InstructionOM extends Class {
attributes := attributesIn
}

/** Attribute that will be encode into object module.
* the Attribute is used to provide metadata for verifications.
*/
trait DecodeAttribute[T] {
val identifier: String = this.getClass.getSimpleName.replace("$", "")
val value: T
val description: String
// Property of this attribute
def om: Property[ClassType] = {
val obj = Instantiate(new T1DecodeAttributeOM)
obj.identifierIn := Property(identifier)
obj.descriptionIn := Property(description)
// Use toString to avoid type issues...
obj.valueIn := Property(value.toString)
obj.getPropertyReference
}
}

trait BooleanDecodeAttribute extends DecodeAttribute[Boolean]
trait StringDecodeAttribute extends DecodeAttribute[String]

// All Attributes expose to OM,
case class IsVectorOM(value: Boolean) extends BooleanDecodeAttribute {
override val description: String = "This instruction should be decode by T1."
}

case class UseLaneExecOM(value: String) extends StringDecodeAttribute {
require(Seq("logic", "adder", "shift", "multiplier", "divider").contains(value), s"invalid execution type: ${value}")
override val description: String =
"Types of Execution Unit used in T1, can be logic, adder, shift, multiplier, divider"
}

/** A case class that should wrap all Vector Instructions.
* This is used to store the attribute for Vector Instruction under the T1 uArch.
* It generates [[chisel3.util.experimental.decode.TruthTable]], as well as documentation field.
*/
case class T1DecodePattern(instruction: Instruction, t1Parameter: T1Parameter) extends DecodePattern {
override def bitPat: BitPat = BitPat("b" + instruction.encoding.toString)

private def documentation: String = InstructionDocumentation(instruction, t1Parameter).toString
// use the attribute w/ [[isVector.value]]
def isVector: isVector = attribute.isVector(this)

// Below is the Scala in-memory attributes queried from DecodeTable.
def isVector = instruction.instructionSet.name == "rv_v"

/** goes into the [[org.chipsalliance.t1.rtl.decoder.TableGenerator.LaneDecodeTable.LogicUnit]]. */
def isLogic = Seq(
"vand.vi",
"vand.vv",
"vand.vx",
"vmand.mm",
"vmandn.mm",
"vmnand.mm",
"vredand.vs",
"vmnor.mm",
"vmor.mm",
"vmorn.mm",
"vmxnor.mm",
"vmxor.mm",
"vor.vi",
"vor.vv",
"vor.vx",
"vredor.vs",
"vredxor.vs",
"vxor.vi",
"vxor.vv",
"vxor.vx"
).contains(instruction.name)

def isAdder = Seq(
"vaadd.vv",
"vaadd.vx",
"vaaddu.vv",
"vaaddu.vx",
"vadd.vi",
"vadd.vv",
"vadd.vx",
"vmadd.vv",
"vmadd.vx",
"vsadd.vi",
"vsadd.vv",
"vsadd.vx",
"vsaddu.vi",
"vsaddu.vv",
"vsaddu.vx",
"vwadd.vv",
"vwadd.vx",
"vwadd.wv",
"vwadd.wx",
"vwaddu.vv",
"vwaddu.vx",
"vwaddu.wv",
"vwaddu.wx",
"vasub.vv",
"vasub.vx",
"vasubu.vv",
"vasubu.vx",
"vfmsub.vf",
"vfmsub.vv",
"vfnmsub.vf",
"vfnmsub.vv",
"vfrsub.vf",
"vfsub.vf",
"vfsub.vv",
"vfwsub.vf",
"vfwsub.vv",
"vfwsub.wf",
"vfwsub.wv",
"vnmsub.vv",
"vnmsub.vx",
"vrsub.vi",
"vrsub.vx",
"vssub.vv",
"vssub.vx",
"vssubu.vv",
"vssubu.vx",
"vsub.vv",
"vsub.vx",
"vwsub.vv",
"vwsub.vx",
"vwsub.wv",
"vwsub.wx",
"vwsubu.vv",
"vwsubu.vx",
"vwsubu.wv",
"vwsubu.wx",
"vmslt.vv",
"vmslt.vx",
"vmsltu.vv",
"vmsltu.vx"
).contains(instruction.name)
private def documentation: String = InstructionDocumentation(instruction, t1Parameter).toString

// This is the OM for this instruction
def om: Property[ClassType] = {
Expand All @@ -190,7 +73,7 @@ case class T1DecodePattern(instruction: Instruction, t1Parameter: T1Parameter) e
// convert in-memory attributes to Chisel Property
obj.attributesIn :#= Property(
Seq(
IsVectorOM(isVector),
isVector,
).map(_.om.as(attributeClassTpe))
)
obj.getPropertyReference
Expand Down
36 changes: 36 additions & 0 deletions t1/src/decoder/attribute/isVector.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.rtl.decoder.attribute

import org.chipsalliance.t1.rtl.decoder.T1DecodePattern

object isVector {
def apply(t1DecodePattern: T1DecodePattern): isVector =
Seq(
y _ -> Y,
n _ -> N,
dc _ -> DC
).collectFirst {
case (fn, tri) if fn(t1DecodePattern) => isVector(tri)
}.get

def y(t1DecodePattern: T1DecodePattern): Boolean = {
val allMatched = t1DecodePattern.t1Parameter.allInstuctions.filter( i =>
i.instructionSets.map(_.name).contains("rv_v")
)
allMatched.contains(t1DecodePattern.instruction)
}
def n(t1DecodePattern: T1DecodePattern): Boolean = {
val allMatched = t1DecodePattern.t1Parameter.allInstuctions.filter( i =>
!(y(t1DecodePattern) || dc(t1DecodePattern))
)
allMatched.contains(t1DecodePattern.instruction)
}

def dc(t1DecodePattern: T1DecodePattern): Boolean = false
}

case class isVector(value: TriState) extends BooleanDecodeAttribute {
override val description: String = "This instruction should be decode by T1."
}
39 changes: 39 additions & 0 deletions t1/src/decoder/attribute/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.rtl.decoder

import chisel3.experimental.hierarchy.Instantiate
import chisel3.properties.{ClassType, Property}

package object attribute {
/** Attribute that will be encode the property of an instruction in the uarch
* and will be additional encode into the object module,
* which will be used to provide metadata for verifications.
*/
trait DecodeAttribute[T] {
val identifier: String = this.getClass.getSimpleName.replace("$", "")
val value: T
val description: String
// Property of this attribute
def om: Property[ClassType] = {
val obj = Instantiate(new T1DecodeAttributeOM)
obj.identifierIn := Property(identifier)
obj.descriptionIn := Property(description)
// Use toString to avoid type issues...
obj.valueIn := Property(value.toString)
obj.getPropertyReference
}
}

sealed trait TriState
case object Y extends TriState
case object N extends TriState
case object DC extends TriState

trait BooleanDecodeAttribute extends DecodeAttribute[TriState]
// TODO: we can add more scala type to avoid string type.
trait StringDecodeAttribute extends DecodeAttribute[String]
}


0 comments on commit a877927

Please sign in to comment.