Skip to content

Instantly share code, notes, and snippets.

@chick
Created June 23, 2017 21:32
Show Gist options
  • Save chick/3e195883f1785740b553f585af4ba36a to your computer and use it in GitHub Desktop.
Save chick/3e195883f1785740b553f585af4ba36a to your computer and use it in GitHub Desktop.
Illustrates an investigation between the vcd output of verilator vs interpreter when reset is called
// See LICENSE for license details.
package examples
/**
* verilator and interpreter have inconsistent behavior around reset.
*/
import java.io.File
import chisel3._
import chisel3.iotesters.{Driver, PeekPokeTester, TesterOptionsManager}
import org.scalatest.{FreeSpec, Matchers}
class Accumulator extends Module {
val io = IO(new Bundle {
val enable = Input(Bool())
val in1 = Input(Bool())
val in2 = Input(UInt(4.W))
val in3 = Input(UInt(8.W))
val freeCount = Output(UInt(16.W))
val constrainedCount = Output(UInt(16.W))
})
// The registers are here to see when reset happens and when accumulation starts
val freeAccumulator = RegInit(0.U(16.W))
freeAccumulator := freeAccumulator + 1.U()
val constrainedAccumulator = RegInit(0.U(16.W))
when(io.enable) {
constrainedAccumulator := constrainedAccumulator + 1.U()
}
io.freeCount := freeAccumulator
io.constrainedCount := constrainedAccumulator
}
class AccumulatorTests(c: Accumulator) extends PeekPokeTester(c) {
poke(c.io.enable, 0)
step(2)
reset(2)
step(2)
poke(c.io.enable, 1)
step(2)
// The following poke will be lost by verilator.
poke(c.io.enable, 0)
reset(2)
poke(c.io.enable, 1)
poke(c.io.in1, 1)
poke(c.io.in2, 3)
poke(c.io.in3, 17)
step(2)
for(base <- Seq(1, 4)) {
poke(c.io.enable, 0)
step(1)
reset(base)
step(1)
poke(c.io.enable, 1)
step(base)
poke(c.io.enable, 0)
step(base)
poke(c.io.enable, 1)
step(base)
}
}
class AccumulatorTester extends FreeSpec with Matchers {
"working on differences between verilator and interpreter reset behavior" in {
val optionsManager = new TesterOptionsManager {
testerOptions = testerOptions.copy(backendName = "verilator",
waveform = Option(new File("A.vcd"))
)
}
Driver.execute(() => new Accumulator(), optionsManager)(c => new AccumulatorTests(c)) should be(true)
Driver.execute(Array("--fint-write-vcd"), () => new Accumulator())(c => new AccumulatorTests(c)) should be(true)
}
}
@oharboe
Copy link

oharboe commented Jun 23, 2017

Idea: add an io.enableOut := io.enable and add an expect(io.enableOut, ...) throughout....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment