mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Initial FMA commit
This commit is contained in:
parent
b38900c07b
commit
e0980bbcd9
23
examples/exercises/fma16/fma.do
Normal file
23
examples/exercises/fma16/fma.do
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# fma.do
|
||||||
|
#
|
||||||
|
# run with vsim -do "do fma.do"
|
||||||
|
# add -c before -do for batch simulation
|
||||||
|
|
||||||
|
onbreak {resume}
|
||||||
|
|
||||||
|
# create library
|
||||||
|
vlib worklib
|
||||||
|
|
||||||
|
vlog -lint -sv -work worklib fma16.sv testbench.sv
|
||||||
|
vopt +acc worklib.testbench_fma16 -work worklib -o testbenchopt
|
||||||
|
vsim -lib worklib testbenchopt
|
||||||
|
|
||||||
|
add wave sim:/testbench_fma16/clk
|
||||||
|
add wave sim:/testbench_fma16/reset
|
||||||
|
add wave sim:/testbench_fma16/x
|
||||||
|
add wave sim:/testbench_fma16/y
|
||||||
|
add wave sim:/testbench_fma16/z
|
||||||
|
add wave sim:/testbench_fma16/result
|
||||||
|
add wave sim:/testbench_fma16/rexpected
|
||||||
|
|
||||||
|
run -all
|
13
examples/exercises/fma16/lint-fma
Executable file
13
examples/exercises/fma16/lint-fma
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# check for warnings in Verilog code
|
||||||
|
# The verilator lint tool is faster and better than Questa so it is best to run this first.
|
||||||
|
export PATH=$PATH:/usr/local/bin/
|
||||||
|
verilator=`which verilator`
|
||||||
|
|
||||||
|
basepath=$(dirname $0)/..
|
||||||
|
if ($verilator --lint-only --top-module fma16 fma16.sv); then
|
||||||
|
echo "fma16 passed lint"
|
||||||
|
else
|
||||||
|
echo "fma16 failed lint"
|
||||||
|
fi
|
||||||
|
|
2
examples/exercises/fma16/sim-fma
Executable file
2
examples/exercises/fma16/sim-fma
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
vsim -do "do fma.do"
|
||||||
|
|
1
examples/exercises/fma16/sim-fma-batch
Executable file
1
examples/exercises/fma16/sim-fma-batch
Executable file
@ -0,0 +1 @@
|
|||||||
|
vsim -c -do "do fma.do"
|
52
examples/exercises/fma16/testbench.sv
Normal file
52
examples/exercises/fma16/testbench.sv
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/* verilator lint_off STMTDLY */
|
||||||
|
module testbench_fma16;
|
||||||
|
logic clk, reset;
|
||||||
|
logic [15:0] x, y, z, rexpected, result;
|
||||||
|
logic [7:0] ctrl;
|
||||||
|
logic mul, add, negp, negz;
|
||||||
|
logic [1:0] roundmode;
|
||||||
|
logic [31:0] vectornum, errors;
|
||||||
|
logic [75:0] testvectors[10000:0];
|
||||||
|
logic [3:0] flags, flagsexpected; // Invalid, Overflow, Underflow, Inexact
|
||||||
|
|
||||||
|
// instantiate device under test
|
||||||
|
fma16 dut(x, y, z, mul, add, negp, negz, roundmode, result, flags);
|
||||||
|
|
||||||
|
// generate clock
|
||||||
|
always
|
||||||
|
begin
|
||||||
|
clk = 1; #5; clk = 0; #5;
|
||||||
|
end
|
||||||
|
|
||||||
|
// at start of test, load vectors and pulse reset
|
||||||
|
initial
|
||||||
|
begin
|
||||||
|
$readmemh("tests/fmul_2.tv", testvectors);
|
||||||
|
vectornum = 0; errors = 0;
|
||||||
|
reset = 1; #22; reset = 0;
|
||||||
|
end
|
||||||
|
|
||||||
|
// apply test vectors on rising edge of clk
|
||||||
|
always @(posedge clk)
|
||||||
|
begin
|
||||||
|
#1; {x, y, z, ctrl, rexpected, flagsexpected} = testvectors[vectornum];
|
||||||
|
{roundmode, mul, add, negp, negz} = ctrl[5:0];
|
||||||
|
end
|
||||||
|
|
||||||
|
// check results on falling edge of clk
|
||||||
|
always @(negedge clk)
|
||||||
|
if (~reset) begin // skip during reset
|
||||||
|
if (result !== rexpected | flags !== flagsexpected) begin // check result
|
||||||
|
$display("Error: inputs %h * %h + %h", x, y, z);
|
||||||
|
$display(" result = %h (%h expected) flags = %b (%b expected)",
|
||||||
|
result, rexpected, flags, flagsexpected);
|
||||||
|
errors = errors + 1;
|
||||||
|
end
|
||||||
|
vectornum = vectornum + 1;
|
||||||
|
if (testvectors[vectornum] === 'x) begin
|
||||||
|
$display("%d tests completed with %d errors",
|
||||||
|
vectornum, errors);
|
||||||
|
$stop;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
endmodule
|
5
examples/exercises/fma16/tests/fmul_0.tv
Normal file
5
examples/exercises/fma16/tests/fmul_0.tv
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Multiply with exponent of 0, significand of 1.0 and 1.1, RZ
|
||||||
|
3c00_3c00_0000_08_3c00_0 // 1.000000 * 1.000000 = 1.000000 NV: 0 OF: 0 UF: 0 NX: 0
|
||||||
|
3c00_3e00_0000_08_3e00_0 // 1.000000 * 1.500000 = 1.500000 NV: 0 OF: 0 UF: 0 NX: 0
|
||||||
|
3e00_3c00_0000_08_3e00_0 // 1.500000 * 1.000000 = 1.500000 NV: 0 OF: 0 UF: 0 NX: 0
|
||||||
|
3e00_3e00_0000_08_4080_0 // 1.500000 * 1.500000 = 2.250000 NV: 0 OF: 0 UF: 0 NX: 0
|
Loading…
Reference in New Issue
Block a user