Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mill source layout and bump Chisel #10

Merged
merged 3 commits into from
Nov 30, 2024
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
28 changes: 10 additions & 18 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
version = 2.6.4
version = "3.7.15"
runner.dialect = scala213

maxColumn = 120
align = most
continuationIndent.defnSite = 2
align.preset = most
indent.defnSite = 2
assumeStandardLibraryStripMargin = true
docstrings = ScalaDoc
docstrings.style = SpaceAsterisk
lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses = true
danglingParentheses.preset = true

align.tokens.add = [
{
code = ":"
},
{
code = ":="
},
{
code = "="
}

]
align.tokens."+" = [{
code = ":"
}]

newlines.alwaysBeforeCurlyBraceLambdaParams = false
newlines.beforeCurlyLambdaParams = "never"
newlines.alwaysBeforeMultilineDef = false
newlines.implicitParamListModifierForce = [before]

Expand Down
45 changes: 19 additions & 26 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,32 @@ import mill.scalalib._
// support BSP
import mill.bsp._

object playground extends SbtModule with ScalafmtModule { m =>
val useChisel3 = false
override def millSourcePath = os.pwd / "src"
override def scalaVersion = if (useChisel3) "2.13.10" else "2.13.14"
object playground extends ScalaModule with ScalafmtModule { m =>
override def scalaVersion = "2.13.15"

override def scalacOptions = Seq(
"-language:reflectiveCalls",
"-deprecation",
"-feature",
"-Xcheckinit"
)
override def sources = T.sources {
super.sources() ++ Seq(PathRef(millSourcePath / "main"))
}
override def ivyDeps = Agg(
if (useChisel3) ivy"edu.berkeley.cs::chisel3:3.6.0" else
ivy"org.chipsalliance::chisel:6.4.0"
)
override def scalacPluginIvyDeps = Agg(
if (useChisel3) ivy"edu.berkeley.cs:::chisel3-plugin:3.6.0" else
ivy"org.chipsalliance:::chisel-plugin:6.4.0"
)
object test extends SbtModuleTests with TestModule.ScalaTest with ScalafmtModule {
override def sources = T.sources {
super.sources() ++ Seq(PathRef(this.millSourcePath / "test"))
}
override def ivyDeps = super.ivyDeps() ++ Agg(
if (useChisel3) ivy"edu.berkeley.cs::chiseltest:0.6.0" else

override def ivyDeps = Agg(ivy"org.chipsalliance::chisel:6.6.0")
override def scalacPluginIvyDeps = Agg(ivy"org.chipsalliance:::chisel-plugin:6.6.0")

object test extends ScalaTests with TestModule.ScalaTest with ScalafmtModule {
override def ivyDeps = m.ivyDeps() ++ Agg(
ivy"org.scalatest::scalatest::3.2.19",
// for formal flow in future
ivy"edu.berkeley.cs::chiseltest:6.0.0"
)
}
def repositoriesTask = T.task { Seq(
coursier.MavenRepository("https://repo.scala-sbt.org/scalasbt/maven-releases"),
coursier.MavenRepository("https://oss.sonatype.org/content/repositories/releases"),
coursier.MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"),
) ++ super.repositoriesTask() }

def repositoriesTask = T.task {
Seq(
coursier.MavenRepository("https://repo.scala-sbt.org/scalasbt/maven-releases"),
coursier.MavenRepository("https://oss.sonatype.org/content/repositories/releases"),
coursier.MavenRepository("https://oss.sonatype.org/content/repositories/snapshots")
) ++ super.repositoriesTask()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ class GcdOutputBundle(val w: Int) extends Bundle {
val gcd = UInt(w.W)
}

/**
* Compute Gcd using subtraction method.
* Subtracts the smaller from the larger until register y is zero.
* value input register x is then the Gcd.
* Unless first input is zero then the Gcd is y.
* Can handle stalls on the producer or consumer side
/** Compute Gcd using subtraction method. Subtracts the smaller from the larger until register y is zero. value input
* register x is then the Gcd. Unless first input is zero then the Gcd is y. Can handle stalls on the producer or
* consumer side
*/
class DecoupledGcd(width: Int) extends Module {
val input = IO(Flipped(Decoupled(new GcdInputBundle(width))))
Expand Down
12 changes: 12 additions & 0 deletions playground/src/Elaborate.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object Elaborate extends App {
val firtoolOptions = Array(
"--lowering-options=" + List(
// make yosys happy
// see https://github.com/llvm/circt/blob/main/docs/VerilogGeneration.md
"disallowLocalVariables",
"disallowPackedArrays",
"locationInfoStyle=wrapInAtSquareBracket"
).reduce(_ + "," + _)
)
circt.stage.ChiselStage.emitSystemVerilogFile(new gcd.GCD(), args, firtoolOptions)
}
6 changes: 2 additions & 4 deletions src/main/GCD.scala → playground/src/GCD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package gcd

import chisel3._

/**
* Compute GCD using subtraction method.
* Subtracts the smaller from the larger until register y is zero.
* value in register x is then the GCD
/** Compute GCD using subtraction method. Subtracts the smaller from the larger until register y is zero. value in
* register x is then the GCD
*/
class GCD extends Module {
val io = IO(new Bundle {
Expand Down
13 changes: 7 additions & 6 deletions src/test/GCDSpec.scala → playground/test/src/GCDSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import chisel3.simulator.EphemeralSimulator._
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.must.Matchers

/**
* This is a trivial example of how to run this Specification
* From within sbt use:
/** This is a trivial example of how to run this Specification From within sbt use:
* {{{
* testOnly gcd.GCDSpec
* }}}
Expand All @@ -26,9 +24,12 @@ import org.scalatest.matchers.must.Matchers
class GCDSpec extends AnyFreeSpec with Matchers {
"Gcd should calculate proper greatest common denominator" in {
simulate(new DecoupledGcd(16)) { dut =>
val testValues = for { x <- 0 to 10; y <- 0 to 10} yield (x, y)
val inputSeq = testValues.map { case (x, y) => (new GcdInputBundle(16)).Lit(_.value1 -> x.U, _.value2 -> y.U) }
val resultSeq = testValues.map { case (x, y) =>
val testValues = for {
x <- 0 to 10
y <- 0 to 10
} yield (x, y)
val inputSeq = testValues.map { case (x, y) => (new GcdInputBundle(16)).Lit(_.value1 -> x.U, _.value2 -> y.U) }
val resultSeq = testValues.map { case (x, y) =>
(new GcdOutputBundle(16)).Lit(_.value1 -> x.U, _.value2 -> y.U, _.gcd -> BigInt(x).gcd(BigInt(y)).U)
}

Expand Down
10 changes: 0 additions & 10 deletions src/main/Elaborate.scala

This file was deleted.