Skip to content

Commit

Permalink
Bump to Chisel 6, migrate to svsim (#122)
Browse files Browse the repository at this point in the history
Bump the template to Chisel 6.  Drop the ChiselTest dependency and migrate
to svsim.

Signed-off-by: Schuyler Eldridge <[email protected]>
  • Loading branch information
seldridge authored Jan 31, 2024
1 parent 6d298bd commit 2a5cb5f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 28 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
branches: ['main']
pull_request:

env:
verilator-version: v5.012
verilator-install-dir: verilator-install

jobs:
ci:
name: ci
Expand All @@ -22,6 +26,32 @@ jobs:
with:
jvm: adopt:11
apps: sbt mill
- name: Setup Dependencies
run: |
sudo apt-get install ccache
- name: Get Cached Verilator
id: get-cached-verilator
uses: actions/cache@v4
with:
path: ${{ env.verilator-install-dir }}
key: verilator-${{ env.verilator-version }}
- name: Install Verilator
if: steps.get-cached-verilator.outputs.cache-hit != 'true'
run: |
sudo apt-get install git help2man perl python3 make autoconf g++ flex bison numactl perl-doc libfl-dev
git clone https://github.com/verilator/verilator
unset VERILATOR_ROOT
cd verilator
git checkout ${{ env.verilator-version }}
autoconf
./configure --prefix=$(pwd)/../${{ env.verilator-install-dir }}
make
make install
- name: Set PATH
run: |
echo "$(pwd)/${{ env.verilator-install-dir }}/bin" >> $GITHUB_PATH
echo VERILATOR_ROOT="$(pwd)/${{ env.verilator-install-dir }}/share/verilator" >> $GITHUB_ENV
ln -s $(pwd)/${{ env.verilator-install-dir }}/bin/verilator_bin $(pwd)/${{ env.verilator-install-dir }}/share/verilator/verilator_bin
- name: SBT Test
run: sbt test
- name: mill Test
Expand Down
5 changes: 2 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ ThisBuild / scalaVersion := "2.13.12"
ThisBuild / version := "0.1.0"
ThisBuild / organization := "%ORGANIZATION%"

val chiselVersion = "5.1.0"
val chiselVersion = "6.0.0"

lazy val root = (project in file("."))
.settings(
name := "%NAME%",
libraryDependencies ++= Seq(
"org.chipsalliance" %% "chisel" % chiselVersion,
"edu.berkeley.cs" %% "chiseltest" % "5.0.2" % "test"
"org.scalatest" %% "scalatest" % "3.2.16" % "test",
),
scalacOptions ++= Seq(
"-language:reflectiveCalls",
Expand All @@ -22,4 +22,3 @@ lazy val root = (project in file("."))
),
addCompilerPlugin("org.chipsalliance" % "chisel-plugin" % chiselVersion cross CrossVersion.full),
)

6 changes: 3 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ object %NAME% extends SbtModule { m =>
"-Xcheckinit",
)
override def ivyDeps = Agg(
ivy"org.chipsalliance::chisel:5.1.0",
ivy"org.chipsalliance::chisel:6.0.0",
)
override def scalacPluginIvyDeps = Agg(
ivy"org.chipsalliance:::chisel-plugin:5.1.0",
ivy"org.chipsalliance:::chisel-plugin:6.0.0",
)
object test extends SbtModuleTests with TestModule.ScalaTest {
override def ivyDeps = m.ivyDeps() ++ Agg(
ivy"edu.berkeley.cs::chiseltest:5.0.2"
ivy"org.scalatest::scalatest::3.2.16"
)
}
}
56 changes: 34 additions & 22 deletions src/test/scala/gcd/GCDSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
package gcd

import chisel3._
import chiseltest._
import org.scalatest.freespec.AnyFreeSpec
import chisel3.experimental.BundleLiterals._
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
Expand All @@ -22,35 +23,46 @@ import chisel3.experimental.BundleLiterals._
* mill %NAME%.test.testOnly gcd.GCDSpec
* }}}
*/
class GCDSpec extends AnyFreeSpec with ChiselScalatestTester {
class GCDSpec extends AnyFreeSpec with Matchers {

"Gcd should calculate proper greatest common denominator" in {
test(new DecoupledGcd(16)) { dut =>
dut.input.initSource()
dut.input.setSourceClock(dut.clock)
dut.output.initSink()
dut.output.setSinkClock(dut.clock)

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

fork {
// push inputs into the calculator, stall for 11 cycles one third of the way
val (seq1, seq2) = inputSeq.splitAt(resultSeq.length / 3)
dut.input.enqueueSeq(seq1)
dut.clock.step(11)
dut.input.enqueueSeq(seq2)
}.fork {
// retrieve computations from the calculator, stall for 10 cycles one half of the way
val (seq1, seq2) = resultSeq.splitAt(resultSeq.length / 2)
dut.output.expectDequeueSeq(seq1)
dut.clock.step(10)
dut.output.expectDequeueSeq(seq2)
}.join()
dut.reset.poke(true.B)
dut.clock.step()
dut.reset.poke(false.B)
dut.clock.step()

var sent, received, cycles: Int = 0
while (sent != 100 && received != 100) {
assert(cycles <= 1000, "timeout reached")

if (sent < 100) {
dut.input.valid.poke(true.B)
dut.input.bits.value1.poke(testValues(sent)._1.U)
dut.input.bits.value2.poke(testValues(sent)._2.U)
if (dut.input.ready.peek().litToBoolean) {
sent += 1
}
}

if (received < 100) {
dut.output.ready.poke(true.B)
if (dut.output.valid.peekValue().asBigInt == 1) {
dut.output.bits.gcd.expect(BigInt(testValues(received)._1).gcd(testValues(received)._2))
received += 1
}
}

// Step the simulation forward.
dut.clock.step()
cycles += 1
}
}
}
}

0 comments on commit 2a5cb5f

Please sign in to comment.