fix speculation ignoring for PC fetching

This commit is contained in:
Noah Boorstin 2021-01-25 19:45:26 -05:00
parent b7988e536f
commit 05d4f2d33d
2 changed files with 17 additions and 10 deletions

View File

@ -43,6 +43,9 @@ add wave -divider
add wave -hex /testbench_busybear/pcExpected add wave -hex /testbench_busybear/pcExpected
add wave -hex /testbench_busybear/dut/dp/PCF add wave -hex /testbench_busybear/dut/dp/PCF
add wave -hex /testbench_busybear/dut/dp/InstrF add wave -hex /testbench_busybear/dut/dp/InstrF
add wave /testbench_busybear/lastInstrF
add wave /testbench_busybear/speculative
add wave /testbench_busybear/lastPC2
add wave -divider add wave -divider
# registers! # registers!
add wave -hex /testbench_busybear/rfExpected add wave -hex /testbench_busybear/rfExpected

View File

@ -115,22 +115,26 @@ module testbench_busybear();
end end
end end
logic speculative, nextSpec; logic speculative;
initial begin initial begin
speculative = 0; speculative = 0;
nextSpec = 0; speculative = 0;
end end
logic [63:0] lastInstrF, lastPC, lastPC2;
integer instrs; integer instrs;
initial begin initial begin
instrs = 0; instrs = 0;
end end
always @(PCF) begin always @(PCF) begin
speculative <= nextSpec; lastInstrF = InstrF;
if (speculative) begin lastPC <= PCF;
nextSpec <= (PCF != pcExpected); lastPC2 <= lastPC;
if (speculative && lastPC != pcExpected) begin
speculative = (PCF != pcExpected);
end end
if (~speculative) begin else begin
//if (~speculative) begin
// first read instruction // first read instruction
scan_file_PC = $fscanf(data_file_PC, "%x\n", InstrF); scan_file_PC = $fscanf(data_file_PC, "%x\n", InstrF);
// then expected PC value // then expected PC value
@ -142,17 +146,17 @@ module testbench_busybear();
$stop; $stop;
end end
// are we at a branch/jump? // are we at a branch/jump?
case (InstrF[6:0]) //todo: add C versions of these case (lastInstrF[6:0]) //todo: add C versions of these
7'b1101111, //JAL 7'b1101111, //JAL
7'b1100111, //JALR 7'b1100111, //JALR
7'b1100011: //B 7'b1100011: //B
nextSpec <= 1; speculative = 1;
default: default:
nextSpec <= 0; speculative = 0;
endcase endcase
//check things! //check things!
if ((~nextSpec) && (PCF !== pcExpected)) begin if ((~speculative) && (PCF !== pcExpected)) begin
$display("%t ps: PC does not equal PC expected: %x, %x", $time, PCF, pcExpected); $display("%t ps: PC does not equal PC expected: %x, %x", $time, PCF, pcExpected);
// $stop; // $stop;
end end