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

Add scalafmt #84

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version = 2.7.5

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

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

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

verticalMultiline.atDefnSite = true

optIn.annotationNewlines = true

rewrite.rules = [SortImports, PreferCurlyFors, AvoidInfix]
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
logLevel := Level.Warn

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
19 changes: 9 additions & 10 deletions src/main/scala/gcd/DecoupledGCD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ class GcdInputBundle(val w: Int) extends Bundle {
class GcdOutputBundle(val w: Int) extends Bundle {
val value1 = UInt(w.W)
val value2 = UInt(w.W)
val gcd = UInt(w.W)
val gcd = UInt(w.W)
}

/**
* Compute Gcd using subtraction method.
/** 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.
Expand All @@ -27,18 +26,18 @@ class DecoupledGcd(width: Int) extends MultiIOModule {
val input = IO(Flipped(Decoupled(new GcdInputBundle(width))))
val output = IO(Decoupled(new GcdOutputBundle(width)))

val xInitial = Reg(UInt())
val yInitial = Reg(UInt())
val x = Reg(UInt())
val y = Reg(UInt())
val busy = RegInit(false.B)
val xInitial = Reg(UInt())
val yInitial = Reg(UInt())
val x = Reg(UInt())
val y = Reg(UInt())
val busy = RegInit(false.B)
val resultValid = RegInit(false.B)

input.ready := ! busy
input.ready := !busy
output.valid := resultValid
output.bits := DontCare

when(busy) {
when(busy) {
when(x > y) {
x := x - y
}.otherwise {
Expand Down
18 changes: 8 additions & 10 deletions src/main/scala/gcd/GCD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ package gcd

import chisel3._

/**
* Compute GCD using subtraction method.
/** 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 {
val value1 = Input(UInt(16.W))
val value2 = Input(UInt(16.W))
val value1 = Input(UInt(16.W))
val value2 = Input(UInt(16.W))
val loadingValues = Input(Bool())
val outputGCD = Output(UInt(16.W))
val outputValid = Output(Bool())
val outputGCD = Output(UInt(16.W))
val outputValid = Output(Bool())
})

val x = Reg(UInt())
val y = Reg(UInt())
val x = Reg(UInt())
val y = Reg(UInt())

when(x > y) { x := x - y }
.otherwise { y := y - x }
when(x > y) { x := x - y }.otherwise { y := y - x }

when(io.loadingValues) {
x := io.value1
Expand Down
9 changes: 4 additions & 5 deletions src/test/scala/gcd/GCDSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import chisel3.tester._
import org.scalatest.FreeSpec
import chisel3.experimental.BundleLiterals._

/**
* This is a trivial example of how to run this Specification
/** This is a trivial example of how to run this Specification
* From within sbt use:
* {{{
* testOnly gcd.GcdDecoupledTester
Expand All @@ -27,10 +26,10 @@ class GCDSpec extends FreeSpec with ChiselScalatestTester {
dut.output.initSink()
dut.output.setSinkClock(dut.clock)

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 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)
new GcdOutputBundle(16).Lit(_.value1 -> x.U, _.value2 -> y.U, _.gcd -> BigInt(x).gcd(BigInt(y)).U)
}

fork {
Expand Down