📄 fpu_tb.v
字号:
//----------------------------------------------------------------------------
//
// File Name: fpu_tb.v
//
// Type: Test bench
//
// Description: This is the test bench for the 32-bit fpu module. The test
// bench excercises the following instructions:
//
// ABS_fmt, ADD_fmt, DIV_fmt, MUL_fmt, NEG_fmt, SUB_fmt
//
// Most instructions operate on two sources and produce a result.
//
// Author: Luis Salazar V.
//
//----------------------------------------------------------------------------
// Release history
//
// Version Date Description
// 1.0 07/10/07 File created
//
//----------------------------------------------------------------------------
//
// Keywords: FPU test bench
//
//----------------------------------------------------------------------------
//
// Include the design under test below
`include "fpu.v"
//
// Test bench code starts here
//
module fpu_tb();
// Declare inputs as regs and outputs as wires
reg [31:0] AInput, BInput;
reg [5:0] OpCode;
reg Clock;
reg Reset;
wire [31:0] Output;
wire Overfow;
wire Zero;
//
// Include the definition of some the FPU operations
//
`include "OperationsFP.v"
// Initialize all variables
initial begin
$dumpfile ("fpu.vcd");
// For now, dump all variables of the design
$dumpvars;
Clock = 1'b1; // initial value of clock
Reset = 1'b1;
//OpCode = NOP;
#10 Reset = 1'b0;
//
// Test the ABS instruction
//
#20 OpCode = C_ABS_fmt;
AInput = 32'hC3A41333;
BInput = 32'h00000000;
//
// Test the ABS instruction
//
#20 OpCode = C_ABS_fmt;
$display ("ABS\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h3AF5C28F;
BInput = 32'h00000000;
//
// Test the NEG instruction
//
#20 OpCode = C_NEG_fmt;
$display ("ABS\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'hC3A41333;
BInput = 32'h00000000;
//
// Test the NEG instruction
//
#20 OpCode = C_NEG_fmt;
$display ("NEG\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h3AF5C28F;
BInput = 32'h00000000;
//
// Test an overflow condition in the SUB instruction
//
#20 OpCode = C_MUL_fmt;
$display ("NEG\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'hC14570A4; //AInput = 32'h7F800000;
BInput = 32'h3EDC28F6; //BInput = 32'h7D900000;
//
// Test the SUBU instruction
//
#20 OpCode = C_DIV_fmt;
$display ("MUL\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'hC14570A4; //AInput = 32'h3F800000;
BInput = 32'h3EDC28F6; //BInput = 32'h3EFFFFFF;
//
// Test the MULT instruction
//
#20 OpCode = C_ADD_fmt;
$display ("DIV\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'hBBE56042;
BInput = 32'hC3464B44;
//
// Test the overflow condition in the MULT instruction
//
#20 OpCode = C_SUB_fmt;
$display ("ADD\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'hBBE56042;
BInput = 32'hC3464B44;
//
// Test the MULTU instruction
//
#20 OpCode = C_ABS_fmt;
$display ("SUB\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000000A;
BInput = 32'h0001000A;
//
// Test the DIV instruction
//
#20 OpCode = C_ABS_fmt;
$display ("MULTU\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'hFFFFFFFA;
BInput = 32'h00000002;
//
// Test the DIV instruction
//
#20 OpCode = C_ABS_fmt;
$display ("DIV\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0FFFFFFA;
BInput = 32'hFFFFFFFE;
//
// Test the DIVU instruction
//
#20 OpCode = C_ABS_fmt;
$display ("DIV\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000000A;
BInput = 32'h00000002;
//
// Test the AND instruction
//
#20 OpCode = C_ABS_fmt;
$display ("DIVU\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000000A;
BInput = 32'h0001000A;
//
// Test the OR instruction
//
#20 OpCode = C_ABS_fmt;
$display ("AND\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000000A;
BInput = 32'hF0F0F0F0;
//
// Test the XOR instruction
//
#20 OpCode = C_ABS_fmt;
$display ("OR\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000000A;
BInput = 32'hF0F0F0F2;
//
// Test the NOR instruction
//
#20 OpCode = C_ABS_fmt;
$display ("XOR\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000000A;
BInput = 32'hF001F00A;
//
// Test the SLL instruction
//
#20 OpCode = C_ABS_fmt;
$display ("NOR\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000A00A;
BInput = 32'h00000004;
//
// Test the SRL instruction
//
#20 OpCode = C_ABS_fmt;
$display ("SLL\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h0000A00A;
BInput = 32'h00000004;
//
// Test the SRA instruction
//
#20 OpCode = C_ABS_fmt;
$display ("SRL\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
AInput = 32'h8000A00A;
BInput = 32'h00000004;
#20 $display ("SRA\t%h %h: %h Ov:%b Z:%b", AInput, BInput, Output, Overflow,
Zero);
#40 $finish; // Terminate simulation
end
// Clock generator
always begin
#5 Clock = ~Clock; // Toggle clock every 5 ticks
end
// Connect DUT to test bench
FPU32 U_FPU (AInput,
BInput,
OpCode,
Clock,
Reset,
Output,
Overflow,
Zero);
endmodule
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -