Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ permissions:
contents: read

env:
JDK_VERSION: 20
JDK_VERSION: 21
JDK_DIST: temurin
VERILATOR_REPO: https://github.com/verilator/verilator
VERILATOR_DIR: verilator
VERILATOR_VERSION_TAG: v4.228
FIRTOOL_VERSION: v1.62.0
FIRTOOL_VERSION_TAG: firtool-1.62.0
VERILATOR_VERSION_TAG: v5.042
FIRTOOL_VERSION_TAG: firtool-1.138.0

jobs:
test:
Expand All @@ -30,24 +29,39 @@ jobs:

steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JDK_VERSION }} (${{ env.JDK_DIST }})
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ env.JDK_VERSION }}
distribution: ${{ env.JDK_DIST }}
cache: 'sbt'
- name: Install firtool ${{ env.FIRTOOL_VERSION }}
- name: Install sbt
uses: sbt/setup-sbt@v1
- name: Install firtool ${{ env.FIRTOOL_VERSION_TAG }}
id: install-circt
uses: circt/install-circt@v1.1.1
with:
version: ${{ env.FIRTOOL_VERSION_TAG }}
- name: Set CHISEL_FIRTOOL_PATH
if: steps.install-circt.outcome == 'success'
run: |
dir=$(dirname $(which firtool))
echo "CHISEL_FIRTOOL_PATH=$dir" >> "$GITHUB_ENV"
- name: Print firtool version
if: steps.install-circt.outcome == 'success'
run: |
wget -q -O - "https://github.com/llvm/circt/releases/download/${{ env.FIRTOOL_VERSION_TAG }}/firrtl-bin-linux-x64.tar.gz" | tar -zx
sudo mv "${{ env.FIRTOOL_VERSION_TAG }}/bin/firtool" /usr/local/bin
echo "The CIRCT version used is:" >> $GITHUB_STEP_SUMMARY
echo \`\`\` >> $GITHUB_STEP_SUMMARY
$CHISEL_FIRTOOL_PATH/firtool -version >> $GITHUB_STEP_SUMMARY
echo \`\`\` >> $GITHUB_STEP_SUMMARY
- name: "Cache: Verilator ${{ env.VERILATOR_VERSION_TAG }}"
uses: actions/cache@v3
uses: actions/cache@v4
id: install-cache
with:
path: ${{ env.VERILATOR_DIR }}
key: ${{ runner.os }}-${{ runner.arch }}-verilator-${{ env.VERILATOR_VERSION_TAG }}

- name: Install Verilator ${{ env.VERILATOR_VERSION_TAG }} from cache
if: steps.install-cache.outputs.cache-hit == 'true'
run: |
Expand All @@ -58,7 +72,7 @@ jobs:
sudo apt-get install -my libfl2 || true # Ubuntu only (ignore if gives error)
sudo apt-get install -my libfl-dev || true # Ubuntu only (ignore if gives error)
sudo apt-get install -my zlibc zlib1g zlib1g-dev || true # Ubuntu only (ignore if gives error)

cd "$VERILATOR_DIR"
sudo make install
verilator --version
Expand All @@ -72,7 +86,7 @@ jobs:
sudo apt-get install -my libfl2 || true # Ubuntu only (ignore if gives error)
sudo apt-get install -my libfl-dev || true # Ubuntu only (ignore if gives error)
sudo apt-get install -my zlibc zlib1g zlib1g-dev || true # Ubuntu only (ignore if gives error)

git clone "$VERILATOR_REPO" "$VERILATOR_DIR"
cd "$VERILATOR_DIR"
git checkout "$VERILATOR_VERSION_TAG"
Expand All @@ -81,7 +95,7 @@ jobs:
make -j "$(nproc)"
sudo make install
verilator --version

- name: Check scalafmt
run: sbt scalafmtCheckAll
- name: Run tests
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
out/
build/
out/
generated/
/lib/firrtl.jar
.classpath
Expand Down
26 changes: 10 additions & 16 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
version = 2.6.4
version = 3.9.3
runner.dialect = scala213

maxColumn = 120
align = most
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = ScalaDoc
docstrings.style = SpaceAsterisk
docstrings.wrap = "no"
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses = true
newlines.selectChains.classicCanStartWithBraceApply = false

align.tokens.add = [
{
code = ":"
}
align.preset = more
align.tokens."+" = [
{ code = ":", owner = "Term.ApplyInfix" },
]

newlines.alwaysBeforeCurlyBraceLambdaParams = false
newlines.alwaysBeforeMultilineDef = false
newlines.implicitParamListModifierForce = [before]

verticalMultiline.atDefnSite = true

optIn.annotationNewlines = true
newlines.beforeCurlyLambdaParams = multiline
newlines.implicitParamListModifierPrefer = before

rewrite.rules = [SortImports, PreferCurlyFors, AvoidInfix]
15 changes: 8 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
scalaVersion := "2.13.14"
scalaVersion := "2.13.18"
scalacOptions += "-language:higherKinds"
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full)
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.4" cross CrossVersion.full)

scalacOptions += "-Ydelambdafy:inline"
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-encoding",
"UTF-8",
"-feature",
"-unchecked",
"-Xfatal-warnings",
"-language:reflectiveCalls",
"-Ymacro-annotations"
)
val chiselVersion = "6.5.0"
val chiselVersion = "7.5.0"
addCompilerPlugin("org.chipsalliance" %% "chisel-plugin" % chiselVersion cross CrossVersion.full)
libraryDependencies ++= Seq(
"org.chipsalliance" %% "chisel" % chiselVersion,
"org.scalatest" %% "scalatest" % "3.2.15" % "test",
"org.scalatestplus" %% "scalacheck-1-14" % "3.2.2.0" % "test",
"org.chipsalliance" %% "chisel" % chiselVersion,
"org.scalatest" %% "scalatest" % "3.2.19" % "test",
"org.scalatestplus" %% "scalacheck-1-18" % "3.2.19.0" % "test"
)

Test / parallelExecution := false
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.8.2
sbt.version=1.10.7
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
val scalafmtPluginVersion = "2.4.6"
val scalafmtPluginVersion = "2.5.4"
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % scalafmtPluginVersion)
20 changes: 10 additions & 10 deletions src/main/scala/fixedpoint/BinaryPoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,33 @@ trait HasBinaryPoint {

object BinaryPoint {
def apply(x: Int): BinaryPoint = KnownBinaryPoint(x)
def apply(): BinaryPoint = UnknownBinaryPoint
def apply(): BinaryPoint = UnknownBinaryPoint
}

sealed abstract class BinaryPoint {
type W = Int
def max(that: BinaryPoint): BinaryPoint = this.op(that, _ max _)
def +(that: BinaryPoint): BinaryPoint = this.op(that, _ + _)
def +(that: Int): BinaryPoint = this.op(this, (a, b) => a + that)
def shiftRight(that: Int): BinaryPoint = this.op(this, (a, b) => 0.max(a - that))
def max(that: BinaryPoint): BinaryPoint = this.op(that, _ max _)
def +(that: BinaryPoint): BinaryPoint = this.op(that, _ + _)
def +(that: Int): BinaryPoint = this.op(this, (a, b) => a + that)
def shiftRight(that: Int): BinaryPoint = this.op(this, (a, b) => 0.max(a - that))
def dynamicShiftLeft(that: BinaryPoint): BinaryPoint =
this.op(that, (a, b) => a + (1 << b) - 1)

def known: Boolean
def get: W
def get: W
protected def op(that: BinaryPoint, f: (W, W) => W): BinaryPoint
}

case object UnknownBinaryPoint extends BinaryPoint {
def known: Boolean = false
def get: Int = None.get
def known: Boolean = false
def get: Int = None.get
def op(that: BinaryPoint, f: (W, W) => W): BinaryPoint = this
override def toString: String = ""
override def toString: String = ""
}

sealed case class KnownBinaryPoint(value: Int) extends BinaryPoint {
def known: Boolean = true
def get: Int = value
def get: Int = value
def op(that: BinaryPoint, f: (W, W) => W): BinaryPoint = that match {
case KnownBinaryPoint(x) => KnownBinaryPoint(f(value, x))
case _ => that
Expand Down
29 changes: 15 additions & 14 deletions src/main/scala/fixedpoint/FixedPoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import chisel3.internal.sourceinfo.{SourceInfoTransform, SourceInfoWhiteboxTrans

import scala.collection.immutable.SeqMap
import scala.language.experimental.macros
import scala.math.BigDecimal.RoundingMode.RoundingMode
import chisel3.util.Cat

object FixedPoint extends NumObject {

/** Create a FixedPoint type with inferred width. */
def apply(): FixedPoint = apply(UnknownWidth(), BinaryPoint())
def apply(): FixedPoint = apply(UnknownWidth, BinaryPoint())

/** Create a FixedPoint type or port with fixed width. */
def apply(width: Width, binaryPoint: BinaryPoint): FixedPoint = new FixedPoint(width, binaryPoint)
Expand All @@ -42,15 +43,15 @@ object FixedPoint extends NumObject {
* Use PrivateObject to force users to specify width and binaryPoint by name
*/
def fromBigInt(value: BigInt, binaryPoint: BinaryPoint = 0.BP): FixedPoint = {
apply(value, UnknownWidth(), binaryPoint)
apply(value, UnknownWidth, binaryPoint)
}

/** Create a FixedPoint literal with inferred width from BigInt.
* Use PrivateObject to force users to specify width and binaryPoint by name
*/
def fromBigInt(value: BigInt, width: Int, binaryPoint: Int): FixedPoint =
if (width == -1) {
apply(value, UnknownWidth(), BinaryPoint(binaryPoint))
apply(value, UnknownWidth, BinaryPoint(binaryPoint))
} else {
apply(value, KnownWidth(width), BinaryPoint(binaryPoint))
}
Expand Down Expand Up @@ -87,7 +88,7 @@ object FixedPoint extends NumObject {
*/
private[fixedpoint] def fromData(
binaryPoint: BinaryPoint,
data: Data,
data: Data,
widthOption: Option[Width] = None
)(
implicit sourceInfo: SourceInfo
Expand All @@ -103,7 +104,7 @@ object FixedPoint extends NumObject {
}

private[fixedpoint] def recreateWidth[T <: Data](d: T): Width = {
d.widthOption.fold[Width](UnknownWidth())(_.W)
d.widthOption.fold[Width](UnknownWidth)(_.W)
}

/** Align all FixedPoints in a (possibly heterogeneous) sequence by width and binary point
Expand All @@ -121,7 +122,7 @@ object FixedPoint extends NumObject {
val maxBP = bps.fold(0.BP)(_.max(_))
val maxWidth = in.map {
case el: FixedPoint => recreateWidth(el) + (maxBP.get - el.binaryPoint.get)
case nonFp => recreateWidth(nonFp)
case nonFp => recreateWidth(nonFp)
}.fold(0.W)(_.max(_))

in.map {
Expand All @@ -145,7 +146,7 @@ object FixedPoint extends NumObject {

implicit class fromDoubleToLiteral(double: Double) {
def F(binaryPoint: BinaryPoint): FixedPoint = {
FixedPoint.fromDouble(double, UnknownWidth(), binaryPoint)
FixedPoint.fromDouble(double, UnknownWidth, binaryPoint)
}

def F(width: Width, binaryPoint: BinaryPoint): FixedPoint = {
Expand All @@ -155,7 +156,7 @@ object FixedPoint extends NumObject {

implicit class fromBigDecimalToLiteral(bigDecimal: BigDecimal) {
def F(binaryPoint: BinaryPoint): FixedPoint = {
FixedPoint.fromBigDecimal(bigDecimal, UnknownWidth(), binaryPoint)
FixedPoint.fromBigDecimal(bigDecimal, UnknownWidth, binaryPoint)
}

def F(width: Width, binaryPoint: BinaryPoint): FixedPoint = {
Expand All @@ -174,8 +175,8 @@ sealed class FixedPoint private[fixedpoint] (width: Width, private var _inferred
with Num[FixedPoint]
with HasBinaryPoint {
if (binaryPoint.known) require(binaryPoint.get >= 0, "Negative binary point is not supported")
private val data: SInt = SInt(width)
val elements: SeqMap[String, SInt] = SeqMap("" -> data)
private val data: SInt = SInt(width)
val elements: SeqMap[String, SInt] = SeqMap("" -> data)

def binaryPoint: BinaryPoint = _inferredBinaryPoint

Expand Down Expand Up @@ -223,8 +224,6 @@ sealed class FixedPoint private[fixedpoint] (width: Width, private var _inferred

def do_unary_-(implicit sourceInfo: SourceInfo): FixedPoint = FixedPoint.fromData(binaryPoint, -data)

def do_unary_-%(implicit sourceInfo: SourceInfo): FixedPoint = FixedPoint.fromData(binaryPoint, data.unary_-%)

override def do_*(that: FixedPoint)(implicit sourceInfo: SourceInfo): FixedPoint =
FixedPoint.fromData(binaryPoint + that.binaryPoint, data * that.data)

Expand Down Expand Up @@ -325,8 +324,10 @@ sealed class FixedPoint private[fixedpoint] (width: Width, private var _inferred

override def bulkConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit = connectOp(that, _ <> _)

override def connectFromBits(that: Bits)(implicit sourceInfo: SourceInfo): Unit = {
this.data := that.asTypeOf(this.data)
override protected def _fromUInt(that: UInt)(implicit sourceInfo: SourceInfo): Data = {
val _w = Wire(this.cloneType)
_w.data := that.asTypeOf(this.data)
_w
}

def apply(x: BigInt): Bool = data.apply(x)
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/fixedpoint/shadow/MuxDefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ object Mux extends SourceInfoDoc {

object Mux1H {
def apply[T <: Data](sel: Seq[Bool], in: Seq[T]): T = chisel3.util.Mux1H(sel, Util.processArgs(in))
def apply[T <: Data](in: Iterable[(Bool, T)]): T = chisel3.util.Mux1H(Util.processArgs(in))
def apply[T <: Data](sel: UInt, in: Seq[T]): T = chisel3.util.Mux1H(sel, Util.processArgs(in))
def apply(sel: UInt, in: UInt): Bool = chisel3.util.Mux1H(sel, in)
def apply[T <: Data](in: Iterable[(Bool, T)]): T = chisel3.util.Mux1H(Util.processArgs(in))
def apply[T <: Data](sel: UInt, in: Seq[T]): T = chisel3.util.Mux1H(sel, Util.processArgs(in))
def apply(sel: UInt, in: UInt): Bool = chisel3.util.Mux1H(sel, in)
}

///** Builds a Mux tree under the assumption that multiple select signals
Expand All @@ -35,9 +35,9 @@ object Mux1H {
// * Returns the output of the Mux tree.
// */
object PriorityMux {
def apply[T <: Data](in: Seq[(Bool, T)]): T = chisel3.util.PriorityMux(Util.processArgs[Bool, T](in))
def apply[T <: Data](in: Seq[(Bool, T)]): T = chisel3.util.PriorityMux(Util.processArgs[Bool, T](in))
def apply[T <: Data](sel: Seq[Bool], in: Seq[T]): T = chisel3.util.PriorityMux(sel, Util.processArgs(in))
def apply[T <: Data](sel: Bits, in: Seq[T]): T = chisel3.util.PriorityMux(sel, in)
def apply[T <: Data](sel: Bits, in: Seq[T]): T = chisel3.util.PriorityMux(sel, in)
}

///** Creates a cascade of n Muxs to search for a key value.
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/AsTypeOfTester.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: Apache-2.0

import chisel3.testers.BasicTester
import chisel3._
import chisel3.simulator.stimulus.RunUntilFinished
import fixedpoint._

class AsTypeOfBundleTester extends BasicTester {
class AsTypeOfBundleTester extends Module {
class MultiTypeBundle extends Bundle {
val u = UInt(4.W)
val s = SInt(4.W)
val u = UInt(4.W)
val s = SInt(4.W)
val fp = FixedPoint(4.W, 3.BP)
}

Expand All @@ -26,6 +26,6 @@ class AsTypeOfSpec extends ChiselFlatSpec {
behavior.of("asTypeOf")

it should "work with Bundles containing Bits Types" in {
assertTesterPasses { new AsTypeOfBundleTester }
simulate(new AsTypeOfBundleTester)(RunUntilFinished(1000))
}
}
Loading