From e36c90af03c07122fc18d7fae10d350b3e55e0b2 Mon Sep 17 00:00:00 2001 From: Charles Papon Date: Mon, 13 Mar 2017 16:17:57 +0100 Subject: [PATCH] Add decoder bench --- sim/cmd.txt | 4 --- sim/tester.cpp | 40 ----------------------- src/main/scala/SpinalRiscv/TopLevel.scala | 32 ++++++++++++++---- src/test/cpp/testA/main.cpp | 2 +- src/test/{cpp/testA => hex}/testA.hex | 0 5 files changed, 26 insertions(+), 52 deletions(-) delete mode 100644 sim/cmd.txt delete mode 100644 sim/tester.cpp rename src/test/{cpp/testA => hex}/testA.hex (100%) diff --git a/sim/cmd.txt b/sim/cmd.txt deleted file mode 100644 index 3b4e3a4..0000000 --- a/sim/cmd.txt +++ /dev/null @@ -1,4 +0,0 @@ - - -verilator -cc ../VexRiscv.v --trace -Wno-WIDTH --exe tester.cpp -make -j -C obj_dir/ -f VVexRiscv.mk VVexRiscv \ No newline at end of file diff --git a/sim/tester.cpp b/sim/tester.cpp deleted file mode 100644 index 69bd5ca..0000000 --- a/sim/tester.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "VVexRiscv.h" -#include "verilated.h" -#include "verilated_vcd_c.h" -#include - -int main(int argc, char **argv, char **env) { - int i; - int clk; - printf("start\n"); - Verilated::commandArgs(argc, argv); - // init top verilog instance - VVexRiscv* top = new VVexRiscv; - // init trace dump - Verilated::traceEverOn(true); - VerilatedVcdC* tfp = new VerilatedVcdC; - top->trace (tfp, 99); - tfp->open ("sim.vcd"); - // initialize simulation inputs - top->clk = 1; - // top->rst = 1; - // top->cen = 0; - // top->wen = 0; - // top->dat = 0x55; - // run simulation for 100 clock periods - for (i=0; i<20; i++) { - // top->rst = (i < 2); - // dump variables into VCD file and toggle clock - for (clk=0; clk<2; clk++) { - tfp->dump (2*i+clk); - top->clk = !top->clk; - top->eval (); - } - // top->cen = (i > 5); - // top->wen = (i == 10); - if (Verilated::gotFinish()) exit(0); - } - tfp->close(); - printf("done\n"); - exit(0); -} diff --git a/src/main/scala/SpinalRiscv/TopLevel.scala b/src/main/scala/SpinalRiscv/TopLevel.scala index 2561689..38b244e 100644 --- a/src/main/scala/SpinalRiscv/TopLevel.scala +++ b/src/main/scala/SpinalRiscv/TopLevel.scala @@ -151,6 +151,11 @@ trait DecoderService{ def addDefault(key : Stageable[_ <: Data], value : Any) } + +case class Node(val value : BigInt,val careAbout : BigInt){ + +} + class DecoderSimplePlugin extends Plugin[VexRiscv] with DecoderService { override def add(encoding: Seq[(MaskedLiteral, Seq[(Stageable[_ <: Data], Any)])]): Unit = encoding.foreach(e => this.add(e._1,e._2)) override def add(key: MaskedLiteral, values: Seq[(Stageable[_ <: Data], Any)]): Unit = { @@ -177,6 +182,9 @@ class DecoderSimplePlugin extends Plugin[VexRiscv] with DecoderService { import pipeline.config._ val stageables = encodings.flatMap(_._2.map(_._1)).toSet + + + stageables.foreach(e => if(defaults.contains(e.asInstanceOf[Stageable[Data]])) insert(e.asInstanceOf[Stageable[Data]]) := defaults(e.asInstanceOf[Stageable[Data]]) else @@ -194,6 +202,17 @@ class DecoderSimplePlugin extends Plugin[VexRiscv] with DecoderService { } } } + + def bench(toplevel : VexRiscv): Unit ={ + toplevel.rework{ + import toplevel.config._ + toplevel.getAllIo.toList.foreach(_.asDirectionLess()) + toplevel.decode.input(INSTRUCTION) := Delay((in Bits(32 bits)).setName("instruction"),2) + val stageables = encodings.flatMap(_._2.map(_._1)).toSet + stageables.foreach(e => out(Delay(toplevel.decode.insert(e),2)).setName(e.getName)) + toplevel.getAdditionalNodesRoot.clear() + } + } } class NoPredictionBranchPlugin extends Plugin[VexRiscv]{ @@ -817,13 +836,13 @@ class FullBarrielShifterPlugin extends Plugin[VexRiscv]{ object TopLevel { def main(args: Array[String]) { - SpinalVerilog{ + SpinalVerilog { val config = VexRiscvConfig( pcWidth = 32 ) config.plugins ++= List( - new PcManagerSimplePlugin(0,true), + new PcManagerSimplePlugin(0, true), new IBusSimplePlugin, new DecoderSimplePlugin, new RegFilePlugin(SYNC), @@ -831,16 +850,15 @@ object TopLevel { new SrcPlugin, new FullBarrielShifterPlugin, new DBusSimplePlugin, -// new HazardSimplePlugin(true,true,true,true), - new HazardSimplePlugin(false,false,false,false), + // new HazardSimplePlugin(true,true,true,true), + new HazardSimplePlugin(false, false, false, false), new NoPredictionBranchPlugin -// new OutputAluResult + // new OutputAluResult ) val toplevel = new VexRiscv(config) -// val iBus = toplevel.service(classOf[IBusSimplePlugin]) -// val dBus = toplevel.service(classOf[DBusSimplePlugin]) +// toplevel.service(classOf[DecoderSimplePlugin]).bench(toplevel) toplevel diff --git a/src/test/cpp/testA/main.cpp b/src/test/cpp/testA/main.cpp index fba584e..f3ee2f4 100644 --- a/src/test/cpp/testA/main.cpp +++ b/src/test/cpp/testA/main.cpp @@ -93,7 +93,7 @@ int main(int argc, char **argv, char **env) { int clk; int error = 0; printf("start\n"); - loadHex("testA.hex"); + loadHex("../../hex/testA.hex"); Verilated::commandArgs(argc, argv); // init top verilog instance VVexRiscv* top = new VVexRiscv; diff --git a/src/test/cpp/testA/testA.hex b/src/test/hex/testA.hex similarity index 100% rename from src/test/cpp/testA/testA.hex rename to src/test/hex/testA.hex