diff --git a/t1/src/decoder/InstructionDocumentation.scala b/t1/src/decoder/InstructionDocumentation.scala index dbeec2a89..4b1c2a750 100644 --- a/t1/src/decoder/InstructionDocumentation.scala +++ b/t1/src/decoder/InstructionDocumentation.scala @@ -1,12 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 Jiuyang Liu -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 { diff --git a/t1/src/decoder/T1DecodePattern.scala b/t1/src/decoder/T1DecodePattern.scala index 0470a73e9..5552d0fe6 100644 --- a/t1/src/decoder/T1DecodePattern.scala +++ b/t1/src/decoder/T1DecodePattern.scala @@ -1,15 +1,17 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2022 Jiuyang Liu -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 { @@ -46,38 +48,6 @@ 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. @@ -85,97 +55,10 @@ case class UseLaneExecOM(value: String) extends StringDecodeAttribute { 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] = { @@ -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 diff --git a/t1/src/decoder/attribute/isVector.scala b/t1/src/decoder/attribute/isVector.scala new file mode 100644 index 000000000..7ef1d746d --- /dev/null +++ b/t1/src/decoder/attribute/isVector.scala @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 Jiuyang Liu + +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." +} diff --git a/t1/src/decoder/attribute/package.scala b/t1/src/decoder/attribute/package.scala new file mode 100644 index 000000000..08a9ea1c7 --- /dev/null +++ b/t1/src/decoder/attribute/package.scala @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 Jiuyang Liu + +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] +} + +