Skip to content

Commit

Permalink
style: update scalafmt config and reformat the world
Browse files Browse the repository at this point in the history
Signed-off-by: unlsycn <[email protected]>
  • Loading branch information
unlsycn committed Nov 29, 2024
1 parent 0326e9a commit 936b3e1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 41 deletions.
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
9 changes: 3 additions & 6 deletions playground/src/DecoupledGCD.scala
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
16 changes: 9 additions & 7 deletions playground/src/Elaborate.scala
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 2 additions & 4 deletions 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 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

0 comments on commit 936b3e1

Please sign in to comment.