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 code formatting and update deprecations #105

Open
wants to merge 2 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.6.4

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")
16 changes: 8 additions & 8 deletions src/main/scala/gcd/DecoupledGCD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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)
}

/**
Expand All @@ -27,18 +27,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
15 changes: 7 additions & 8 deletions src/main/scala/gcd/GCD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ import chisel3._
*/
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
13 changes: 7 additions & 6 deletions src/test/scala/gcd/GCDSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
package gcd

import chisel3._
import chisel3.tester._
import org.scalatest.FreeSpec
import chiseltest._
import chisel3.experimental.BundleLiterals._
import org.scalatest.freespec.AnyFreeSpec

/**
* This is a trivial example of how to run this Specification
Expand All @@ -18,7 +18,7 @@ import chisel3.experimental.BundleLiterals._
* sbt 'testOnly gcd.GcdDecoupledTester'
* }}}
*/
class GCDSpec extends FreeSpec with ChiselScalatestTester {
class GCDSpec extends AnyFreeSpec with ChiselScalatestTester {

"Gcd should calculate proper greatest common denominator" in {
test(new DecoupledGcd(16)) { dut =>
Expand All @@ -27,10 +27,11 @@ 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 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)
val resultSeq = testValues.map {
case (x, y) =>
(new GcdOutputBundle(16)).Lit(_.value1 -> x.U, _.value2 -> y.U, _.gcd -> BigInt(x).gcd(BigInt(y)).U)
}

fork {
Expand Down