Giter Club home page Giter Club logo

difftest's Introduction

DiffTest

DiffTest (差分测试): a modern co-simulation framework for RISC-V processors.

Generate Example Verilog

DiffTest interfaces are provided in Chisel bundles and expected to be integrated into Chisel designs with auto-generated C++ interfaces. However, we also provide examples of the generated Verilog modules.

make difftest_verilog NOOP_HOME=$(pwd)

Example Usage

  1. Add this submodule to your design.

In your Git project:

git submodule add https://github.com/OpenXiangShan/difftest.git

In Mill build.sc:

import $file.difftest.build

// We recommend using a fixed Chisel version.
object difftest extends millbuild.difftest.build.CommonDiffTest {
  def crossValue: String = "3.5.6"

  override def millSourcePath = os.pwd / "difftest"
}

// This is for advanced users only. All supported Chisel versions are listed in `build.sc`.
// To pass a cross value to difftest:
object difftest extends Cross[millbuild.difftest.build.CommonDiffTest](chiselVersions) {
  override def millSourcePath = os.pwd / "difftest"
}

In Makefile:

emu: sim-verilog
	@$(MAKE) -C difftest emu WITH_CHISELDB=0 WITH_CONSTANTIN=0
  1. Add difftest modules (in Chisel or Verilog) to your design.
import difftest._

val difftest = DifftestModule(new DiffInstrCommit, delay = 1, dontCare = true)
difftest.valid  := io.in.valid
difftest.pc     := SignExt(io.in.bits.decode.cf.pc, AddrBits)
difftest.instr  := io.in.bits.decode.cf.instr
difftest.skip   := io.in.bits.isMMIO
difftest.isRVC  := io.in.bits.decode.cf.instr(1, 0)=/="b11".U
difftest.rfwen  := io.wb.rfWen && io.wb.rfDest =/= 0.U
difftest.wdest  := io.wb.rfDest
difftest.wpdest := io.wb.rfDest
  1. Call val difftesst = DifftestModule.finish(cpu: String) at the top module whose name should be SimTop. The variable name difftest must be used to ensure DiffTest could capture the input signals.

An optional UART input/output can be connected to DiffTest. DiffTest will automatically DontCare it internally.

val difftest = DifftestModule.finish("Demo")

// Optional UART connections. Remove this line if UART is not needed.
difftest.uart <> mmio.io.uart
  1. Generate verilog files for simulation.

  2. make emu and start simulating & debugging!

We provide example designs, including:

APIs

Currently we are supporting the RISC-V base ISA as well as some extensions, including Float/Double, Debug, and Vector. We also support checking the cache coherence via RefillTest.

Probe Name Descriptions Mandatory
DiffArchEvent Exceptions and interrupts Yes
DiffInstrCommit Executed instructions Yes
DiffTrapEvent Simulation environment call Yes
DiffArchIntRegState General-purpose registers Yes
DiffArchFpRegState Floating-point registers No
DiffArchVecRegState Floating-point registers No
DiffCSRState Control and status registers Yes
DiffVecCSRState Control and status registers No
DiffDebugMode Debug mode registers No
DiffIntWriteback General-purpose writeback operations No
DiffFpWriteback Floating-point writeback operations No
DiffArchIntDelayedUpdate Delayed general-purpose writeback No
DiffArchFpDelayedUpdate Delayed floating-point writeback No
DiffStoreEvent Store operations No
DiffSbufferEvent Store buffer operations No
DiffLoadEvent Load operations No
DiffAtomicEvent Atomic operations No
DiffL1TLBEvent L1 TLB operations No
DiffL2TLBEvent L2 TLB operations No
DiffRefillEvent Cache refill operations No
DiffLrScEvent Executed LR/SC instructions No

The DiffTest framework comes with a simulation framework with some top-level IOs.

  • LogCtrlIO
  • PerfCtrlIO
  • UARTIO

These IOs can be used along with the controller wrapper at src/main/scala/common/LogPerfControl.scala.

For compatibility on different platforms, the CPU should access a C++ memory via DPI-C interfaces. This memory will be initialized in C++.

val mem = DifftestMem(memByte, 8)
when (wen) {
    mem.write(
    addr = wIdx,
    data = in.w.bits.data.asTypeOf(Vec(DataBytes, UInt(8.W))),
    mask = in.w.bits.strb.asBools
    )
}
val rdata = mem.readAndHold(rIdx, ren).asUInt

To use DiffTest, please include all necessary modules and top-level IOs in your design. It's worth noting the Chisel Bundles may have arguments with default values. Please set the correct parameters for the interfaces.

Further reference

difftest's People

Contributors

poemonsense avatar augustuswilliswang avatar ljwljwljwljw avatar sashimi-yzh avatar lemover avatar lingrui98 avatar jinyue110 avatar njuallen avatar linjuanz avatar wakafa1 avatar zoujr avatar fwzhang avatar yikezhou avatar bigwhitedog avatar klin02 avatar wonicon avatar good-circle avatar guo-hy avatar tang-haojin avatar ict-tangdan avatar notlqr avatar 5265325 avatar sequencer avatar shili2017 avatar maxpicca-li avatar sktt1ryze avatar happy-lx avatar xyyy1420 avatar sinofp avatar liushiqi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.