diff --git a/.scalafmt.conf b/.scalafmt.conf index 5b136d5..5bacc03 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -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] diff --git a/playground/src/DecoupledGCD.scala b/playground/src/DecoupledGCD.scala index 7ac8138..f661dd3 100644 --- a/playground/src/DecoupledGCD.scala +++ b/playground/src/DecoupledGCD.scala @@ -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)))) diff --git a/playground/src/Elaborate.scala b/playground/src/Elaborate.scala index c9fbb84..5f220f1 100644 --- a/playground/src/Elaborate.scala +++ b/playground/src/Elaborate.scala @@ -1,10 +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(_ + "," + _)) + 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) } diff --git a/playground/src/GCD.scala b/playground/src/GCD.scala index 34fd17e..0afe6d0 100644 --- a/playground/src/GCD.scala +++ b/playground/src/GCD.scala @@ -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 { diff --git a/playground/test/src/GCDSpec.scala b/playground/test/src/GCDSpec.scala index e6c65e1..4371432 100644 --- a/playground/test/src/GCDSpec.scala +++ b/playground/test/src/GCDSpec.scala @@ -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 * }}} @@ -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) }