-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement and test $mul. Use return, not exit in tests
- Loading branch information
1 parent
761055a
commit 03ae4c5
Showing
33 changed files
with
273 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#include <cstdio> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <random> | ||
|
||
#include <cxxrtl/cxxrtl_vcd.h> | ||
|
||
#include "my_module_cxxrtl.cc" | ||
#include "my_module_functional_cxx.cc" | ||
|
||
struct DumpHeader { | ||
std::ofstream &ofs; | ||
DumpHeader(std::ofstream &ofs) : ofs(ofs) {} | ||
template <size_t n> | ||
void operator()(const char *name, Signal<n> value) { | ||
ofs << "$var wire " << n << " " << name[0] << " " << name << " $end\n"; | ||
} | ||
}; | ||
|
||
struct Dump { | ||
std::ofstream &ofs; | ||
Dump(std::ofstream &ofs) : ofs(ofs) {} | ||
template <size_t n> | ||
void operator()(const char *name, Signal<n> value) { | ||
// Bit | ||
if (n == 1) { | ||
ofs << (value[0] ? '1' : '0'); | ||
ofs << name[0] << "\n"; | ||
return; | ||
} | ||
// vector (multi-bit) signals | ||
ofs << "b"; | ||
for (size_t i = n; i-- > 0;) | ||
ofs << (value[i] ? '1' : '0'); | ||
ofs << " " << name[0] << "\n"; | ||
} | ||
}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if (argc != 3) { | ||
std::cerr << "Usage: " << argv[0] << " <functional_vcd_filename> <cxxrtl_vcd_filename>\n"; | ||
return 1; | ||
} | ||
|
||
const std::string functional_vcd_filename = argv[1]; | ||
const std::string cxxrtl_vcd_filename = argv[2]; | ||
|
||
constexpr int steps = 10; | ||
constexpr int number_timescale = 1; | ||
const std::string units_timescale = "us"; | ||
my_module_Inputs inputs; | ||
my_module_Outputs outputs; | ||
my_module_State state; | ||
my_module_State next_state; | ||
|
||
std::ofstream vcd_file(functional_vcd_filename); | ||
|
||
vcd_file << "$timescale " << number_timescale << " " << units_timescale << " $end\n"; | ||
{ | ||
DumpHeader d(vcd_file); | ||
inputs.dump(d); | ||
outputs.dump(d); | ||
state.dump(d); | ||
} | ||
vcd_file << "$enddefinitions $end\n$dumpvars\n"; | ||
|
||
cxxrtl_design::p_my__module top; | ||
|
||
cxxrtl::debug_items all_debug_items; | ||
cxxrtl::debug_scope debug_scope; | ||
top.debug_info(&all_debug_items, nullptr, ""); | ||
|
||
cxxrtl::vcd_writer vcd; | ||
vcd.timescale(number_timescale, units_timescale); | ||
vcd.add_without_memories(all_debug_items); | ||
|
||
std::ofstream waves(cxxrtl_vcd_filename); | ||
|
||
top.p_a.set<8>(false); | ||
top.p_b.set<8>(false); | ||
top.step(); | ||
|
||
vcd.sample(0); | ||
vcd_file << "#0\n"; | ||
inputs.a = $const<8>(false); | ||
inputs.b = $const<8>(false); | ||
my_module(inputs, outputs, state, next_state); | ||
{ | ||
Dump d(vcd_file); | ||
inputs.dump(d); | ||
outputs.dump(d); | ||
state.dump(d); | ||
} | ||
|
||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::bernoulli_distribution dist(0.5); | ||
|
||
for (int step = 0; step < steps; ++step) { | ||
const bool a_value = dist(gen); | ||
const bool b_value = dist(gen); | ||
|
||
// cxxrtl | ||
top.p_a.set<bool>(a_value); | ||
top.p_b.set<bool>(b_value); | ||
top.step(); | ||
vcd.sample(step + 1); | ||
|
||
waves << vcd.buffer; | ||
vcd.buffer.clear(); | ||
|
||
// Functional backend cxx | ||
vcd_file << "#" << (step + 1) << "\n"; | ||
inputs.a = $const<8>(a_value); | ||
inputs.b = $const<8>(b_value); | ||
|
||
my_module(inputs, outputs, state, next_state); | ||
{ | ||
Dump d(vcd_file); | ||
inputs.dump(d); | ||
outputs.dump(d); | ||
state.dump(d); | ||
} | ||
|
||
state = next_state; | ||
} | ||
|
||
vcd_file.close(); | ||
waves.close(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module my_module( | ||
input [7:0] a, | ||
input [7:0] b, | ||
output [7:0] y | ||
); | ||
// Perform bitwise AND | ||
assign y = a & b; | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
# Initialize an array to store the names of failing Verilog files and their failure types | ||
declare -A failing_files | ||
|
||
# Function to run the test on a given Verilog file | ||
run_test() { | ||
# Define the common variable for the relative path | ||
BASE_PATH="../../../" | ||
|
||
local verilog_file=$1 | ||
|
||
# Extract the base name without extension | ||
local base_name=$(basename "$verilog_file" .v) | ||
|
||
# Run yosys to process each Verilog file | ||
if ${BASE_PATH}yosys -p "read_verilog $verilog_file; write_cxxrtl my_module_cxxrtl.cc; write_functional_cxx my_module_functional_cxx.cc"; then | ||
echo "Yosys processed $verilog_file successfully." | ||
|
||
# Compile the generated C++ files with vcd_harness.cpp | ||
${CXX:-g++} -g -fprofile-arcs -ftest-coverage vcd_harness.cpp -I ${BASE_PATH}backends/functional/cxx_runtime/ -I ${BASE_PATH}backends/cxxrtl/runtime/ -o vcd_harness | ||
|
||
# Generate VCD files with base_name | ||
if ./vcd_harness ${base_name}_functional_cxx.vcd ${base_name}_cxxrtl.vcd ; then | ||
# Run vcdiff and capture the output | ||
local output=$(vcdiff ${base_name}_functional_cxx.vcd ${base_name}_cxxrtl.vcd) | ||
|
||
# Check if there is any output | ||
if [ -n "$output" ]; then | ||
echo "Differences detected in $verilog_file:" | ||
echo "$output" | ||
failing_files["$verilog_file"]="Differences detected" | ||
else | ||
echo "No differences detected in $verilog_file." | ||
fi | ||
else | ||
echo "Failed to generate VCD files for $verilog_file." | ||
failing_files["$verilog_file"]="VCD generation failure" | ||
fi | ||
else | ||
echo "Yosys failed to process $verilog_file." | ||
failing_files["$verilog_file"]="Yosys failure" | ||
fi | ||
} | ||
|
||
# Main function to run all tests | ||
run_all_tests() { | ||
# Loop through all Verilog files in the verilog directory | ||
for verilog_file in verilog/*.v; do | ||
run_test "$verilog_file" | ||
done | ||
|
||
# Check if the array of failing files is empty | ||
if [ ${#failing_files[@]} -eq 0 ]; then | ||
echo "All files passed." | ||
return 0 | ||
else | ||
echo "The following files failed:" | ||
for file in "${!failing_files[@]}"; do | ||
echo "$file: ${failing_files[$file]}" | ||
done | ||
return 1 | ||
fi | ||
} | ||
|
||
# If the script is being sourced, do not execute the tests | ||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
run_all_tests | ||
fi |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[probability] | ||
expr.binary = 5 | ||
expr.concatenation = 5 | ||
expr.number = 1 | ||
expr.rangeselect = 5 | ||
expr.signed = 5 | ||
expr.string = 0 | ||
expr.ternary = 5 | ||
expr.unary = 5 | ||
expr.unsigned = 5 | ||
expr.variable = 5 | ||
moditem.assign = 2 | ||
moditem.combinational = 0 | ||
moditem.instantiation = 0 | ||
moditem.sequential = 3 | ||
statement.blocking = 0 | ||
statement.conditional = 1 | ||
statement.forloop = 0 | ||
statement.nonblocking = 2 | ||
|
||
[property] | ||
module.depth = 2 | ||
module.max = 5 | ||
size = 20 | ||
statement.depth = 7 | ||
sample.method = "hat" | ||
sample.size = 10 | ||
|
||
[[synthesiser]] | ||
name = "yosys" | ||
description = "yosys_nix" | ||
output = "yosys_nix.v" | ||
bin = "/nix/store/fzqckbn2ajj6illgrbcja6fj8qzrbacb-yosys/bin/" |