From 0b55c0b02be4396ea5730d61f4e313ea79c3b4b6 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 14:06:31 +0100 Subject: [PATCH 01/10] Major testing refactor (sorry for massive commit) --- hdl/rtl/alu/posit32_alu.sv | 39 ----- hdl/rtl/alu/posit64_alu.sv | 23 --- .../{typedef/common.sv => include/common.svh} | 5 + .../posit_types.svh} | 5 + hdl/rtl/{ => src}/alu/adder/mantissa_adder.sv | 0 hdl/rtl/{ => src}/alu/adder/normalise.sv | 0 hdl/rtl/{ => src}/alu/adder/posit_adder.sv | 0 hdl/rtl/{ => src}/alu/alu_ctrl.sv | 2 +- hdl/rtl/{ => src}/alu/comparator.sv | 3 +- hdl/rtl/{ => src}/alu/ops/posit32_add.sv | 0 hdl/rtl/{ => src}/alu/ops/posit32_sub.sv | 0 hdl/rtl/{ => src}/alu/ops/posit64_add.sv | 0 hdl/rtl/{ => src}/alu/ops/posit64_sub.sv | 0 hdl/rtl/{ => src}/alu/posit_32b_add.sv | 2 + hdl/rtl/{ => src}/alu/posit_32b_sub.sv | 2 + hdl/rtl/{ => src}/alu/posit_7b_add.sv | 2 + hdl/rtl/{ => src}/alu/posit_7b_sub.sv | 2 + hdl/rtl/{ => src}/alu/two_comp.sv | 2 + .../henry_decoder/posit32_count_regime.sv | 2 + .../decode/henry_decoder/posit32_decode.sv | 4 +- .../decode/henry_decoder/posit64_decode.sv | 4 +- .../posit_variable_count_regime.sv | 20 +-- .../henry_decoder/posit_variable_decode.sv | 4 +- .../decode/henry_decoder/util/mux.sv | 0 .../henry_decoder/util/priority_encoders.sv | 0 .../decode/luke_decoder/count_lead_one.sv | 0 .../decode/luke_decoder/count_lead_one_24.sv | 0 .../decode/luke_decoder/count_lead_zero.sv | 0 .../decode/luke_decoder/count_tail_one.sv | 0 .../decode/luke_decoder/count_tail_zero.sv | 0 .../decode/luke_decoder/find_first_n_ones.sv | 2 + .../decode/luke_decoder/find_first_one.sv | 2 + .../decode/luke_decoder/format_decoder.sv | 2 + hdl/rtl/{ => src/dff}/dff.sv | 1 - hdl/rtl/{ => src}/encode/format_encoder.sv | 2 + .../tests/arithmetic/test_arithmetic.py | 61 +------ .../{luke_decoder => }/dff/cocotb_test_dff.py | 3 - hdl/verif/cocotb/tests/dff/test_dff.py | 7 + .../cocotb_test_pyposit_module.py | 40 ----- .../count_regime/posit32_count_regime_tb.sv | 16 -- .../priority_encoder_16_tb.sv | 14 -- .../tests/henry_decoder/test_henry_decoder.py | 53 ++----- .../tests/luke_decoder/test_luke_decoder.py | 150 +++++------------- setup.sh | 1 + softmodels/src/coco_wrapper.py | 81 ++++++++++ softmodels/src/coco_wrapper/__init__.py | 1 - softmodels/src/coco_wrapper/coco_wrapper.py | 43 ----- 47 files changed, 190 insertions(+), 410 deletions(-) delete mode 100644 hdl/rtl/alu/posit32_alu.sv delete mode 100644 hdl/rtl/alu/posit64_alu.sv rename hdl/rtl/{typedef/common.sv => include/common.svh} (52%) rename hdl/rtl/{typedef/posit_types.sv => include/posit_types.svh} (90%) rename hdl/rtl/{ => src}/alu/adder/mantissa_adder.sv (100%) rename hdl/rtl/{ => src}/alu/adder/normalise.sv (100%) rename hdl/rtl/{ => src}/alu/adder/posit_adder.sv (100%) rename hdl/rtl/{ => src}/alu/alu_ctrl.sv (92%) rename hdl/rtl/{ => src}/alu/comparator.sv (98%) rename hdl/rtl/{ => src}/alu/ops/posit32_add.sv (100%) rename hdl/rtl/{ => src}/alu/ops/posit32_sub.sv (100%) rename hdl/rtl/{ => src}/alu/ops/posit64_add.sv (100%) rename hdl/rtl/{ => src}/alu/ops/posit64_sub.sv (100%) rename hdl/rtl/{ => src}/alu/posit_32b_add.sv (94%) rename hdl/rtl/{ => src}/alu/posit_32b_sub.sv (96%) rename hdl/rtl/{ => src}/alu/posit_7b_add.sv (94%) rename hdl/rtl/{ => src}/alu/posit_7b_sub.sv (96%) rename hdl/rtl/{ => src}/alu/two_comp.sv (92%) rename hdl/rtl/{ => src}/decode/henry_decoder/posit32_count_regime.sv (99%) rename hdl/rtl/{ => src}/decode/henry_decoder/posit32_decode.sv (90%) rename hdl/rtl/{ => src}/decode/henry_decoder/posit64_decode.sv (89%) rename hdl/rtl/{ => src}/decode/henry_decoder/posit_variable_count_regime.sv (73%) rename hdl/rtl/{ => src}/decode/henry_decoder/posit_variable_decode.sv (90%) rename hdl/rtl/{ => src}/decode/henry_decoder/util/mux.sv (100%) rename hdl/rtl/{ => src}/decode/henry_decoder/util/priority_encoders.sv (100%) rename hdl/rtl/{ => src}/decode/luke_decoder/count_lead_one.sv (100%) rename hdl/rtl/{ => src}/decode/luke_decoder/count_lead_one_24.sv (100%) rename hdl/rtl/{ => src}/decode/luke_decoder/count_lead_zero.sv (100%) rename hdl/rtl/{ => src}/decode/luke_decoder/count_tail_one.sv (100%) rename hdl/rtl/{ => src}/decode/luke_decoder/count_tail_zero.sv (100%) rename hdl/rtl/{ => src}/decode/luke_decoder/find_first_n_ones.sv (96%) rename hdl/rtl/{ => src}/decode/luke_decoder/find_first_one.sv (93%) rename hdl/rtl/{ => src}/decode/luke_decoder/format_decoder.sv (99%) rename hdl/rtl/{ => src/dff}/dff.sv (99%) rename hdl/rtl/{ => src}/encode/format_encoder.sv (99%) rename hdl/verif/cocotb/tests/{luke_decoder => }/dff/cocotb_test_dff.py (92%) create mode 100644 hdl/verif/cocotb/tests/dff/test_dff.py delete mode 100644 hdl/verif/cocotb/tests/henry_decoder/count_regime/cocotb_test_pyposit_module.py delete mode 100644 hdl/verif/cocotb/tests/henry_decoder/count_regime/posit32_count_regime_tb.sv delete mode 100644 hdl/verif/cocotb/tests/henry_decoder/priority_encoder/priority_encoder_16_tb.sv create mode 100644 softmodels/src/coco_wrapper.py delete mode 100644 softmodels/src/coco_wrapper/__init__.py delete mode 100644 softmodels/src/coco_wrapper/coco_wrapper.py diff --git a/hdl/rtl/alu/posit32_alu.sv b/hdl/rtl/alu/posit32_alu.sv deleted file mode 100644 index ecb127a..0000000 --- a/hdl/rtl/alu/posit32_alu.sv +++ /dev/null @@ -1,39 +0,0 @@ -import posit/posit_types::* -import alu/operations::* - -module posit32_alu #( - parameter int unsigned es = 2 -) ( - input posit32_t p1, p2, - input operations_t op, - - output posit32_t o -); - - /* Example of how maybe to construct the posit ALU/testbench? - * We really just need to create the decode hardware for each input - * and then the arithmetic modules can just operate on their decoded - * intermediaries. - */ - - posit32_decode i_posit32_decode_1( - .p(p1), - //... - ); - - posit32_decode i_posit32_decode_2( - .p(p1), - //... - ); - - // ... - - // arithmetic modules (e.g. add, sub) go here - - // ... - - // this might feature a quire to posit converter or similar? - - // then finally an encoder connected to the output - -endmodule \ No newline at end of file diff --git a/hdl/rtl/alu/posit64_alu.sv b/hdl/rtl/alu/posit64_alu.sv deleted file mode 100644 index 9692c60..0000000 --- a/hdl/rtl/alu/posit64_alu.sv +++ /dev/null @@ -1,23 +0,0 @@ -import posit/posit_types::* -import alu/operations::* - -module posit64_alu #( - parameter int unsigned es = 2 -) ( - input posit64_t p1, p2, - input operations_t op, - - output posit64_t o -); - - posit32_decode i_posit64_decode_1( - .p(p1), - //... - ); - - posit32_decode i_posit64_decode_2( - .p(p1), - //... - ); - -endmodule \ No newline at end of file diff --git a/hdl/rtl/typedef/common.sv b/hdl/rtl/include/common.svh similarity index 52% rename from hdl/rtl/typedef/common.sv rename to hdl/rtl/include/common.svh index 098f81a..702386d 100644 --- a/hdl/rtl/typedef/common.sv +++ b/hdl/rtl/include/common.svh @@ -1,3 +1,8 @@ +`ifndef _COMMON_VH_ +`define _COMMON_VH_ + package common; typedef enum logic { POS, NEG } sign_t; endpackage + +`endif // _COMMON_VH_ diff --git a/hdl/rtl/typedef/posit_types.sv b/hdl/rtl/include/posit_types.svh similarity index 90% rename from hdl/rtl/typedef/posit_types.sv rename to hdl/rtl/include/posit_types.svh index f3047d2..9723824 100644 --- a/hdl/rtl/typedef/posit_types.sv +++ b/hdl/rtl/include/posit_types.svh @@ -1,3 +1,6 @@ +`ifndef _POSIT_VH_ +`define _POSIT_VH_ + package posit_types; /* handy logic type for sign bit */ @@ -21,3 +24,5 @@ package posit_types; } posit64_t; endpackage + +`endif // _POSIT_VH_ diff --git a/hdl/rtl/alu/adder/mantissa_adder.sv b/hdl/rtl/src/alu/adder/mantissa_adder.sv similarity index 100% rename from hdl/rtl/alu/adder/mantissa_adder.sv rename to hdl/rtl/src/alu/adder/mantissa_adder.sv diff --git a/hdl/rtl/alu/adder/normalise.sv b/hdl/rtl/src/alu/adder/normalise.sv similarity index 100% rename from hdl/rtl/alu/adder/normalise.sv rename to hdl/rtl/src/alu/adder/normalise.sv diff --git a/hdl/rtl/alu/adder/posit_adder.sv b/hdl/rtl/src/alu/adder/posit_adder.sv similarity index 100% rename from hdl/rtl/alu/adder/posit_adder.sv rename to hdl/rtl/src/alu/adder/posit_adder.sv diff --git a/hdl/rtl/alu/alu_ctrl.sv b/hdl/rtl/src/alu/alu_ctrl.sv similarity index 92% rename from hdl/rtl/alu/alu_ctrl.sv rename to hdl/rtl/src/alu/alu_ctrl.sv index c6d3448..f3441b6 100644 --- a/hdl/rtl/alu/alu_ctrl.sv +++ b/hdl/rtl/src/alu/alu_ctrl.sv @@ -4,4 +4,4 @@ package alu_ctrl; ADD, SUB } operations_t; -endpackage \ No newline at end of file +endpackage diff --git a/hdl/rtl/alu/comparator.sv b/hdl/rtl/src/alu/comparator.sv similarity index 98% rename from hdl/rtl/alu/comparator.sv rename to hdl/rtl/src/alu/comparator.sv index 309a61a..ec21f3f 100644 --- a/hdl/rtl/alu/comparator.sv +++ b/hdl/rtl/src/alu/comparator.sv @@ -1,3 +1,5 @@ +`include "common.svh" + import common::*; module comparator #( @@ -44,4 +46,3 @@ module comparator #( endmodule : comparator - diff --git a/hdl/rtl/alu/ops/posit32_add.sv b/hdl/rtl/src/alu/ops/posit32_add.sv similarity index 100% rename from hdl/rtl/alu/ops/posit32_add.sv rename to hdl/rtl/src/alu/ops/posit32_add.sv diff --git a/hdl/rtl/alu/ops/posit32_sub.sv b/hdl/rtl/src/alu/ops/posit32_sub.sv similarity index 100% rename from hdl/rtl/alu/ops/posit32_sub.sv rename to hdl/rtl/src/alu/ops/posit32_sub.sv diff --git a/hdl/rtl/alu/ops/posit64_add.sv b/hdl/rtl/src/alu/ops/posit64_add.sv similarity index 100% rename from hdl/rtl/alu/ops/posit64_add.sv rename to hdl/rtl/src/alu/ops/posit64_add.sv diff --git a/hdl/rtl/alu/ops/posit64_sub.sv b/hdl/rtl/src/alu/ops/posit64_sub.sv similarity index 100% rename from hdl/rtl/alu/ops/posit64_sub.sv rename to hdl/rtl/src/alu/ops/posit64_sub.sv diff --git a/hdl/rtl/alu/posit_32b_add.sv b/hdl/rtl/src/alu/posit_32b_add.sv similarity index 94% rename from hdl/rtl/alu/posit_32b_add.sv rename to hdl/rtl/src/alu/posit_32b_add.sv index 68b8b1c..2256813 100644 --- a/hdl/rtl/alu/posit_32b_add.sv +++ b/hdl/rtl/src/alu/posit_32b_add.sv @@ -1,3 +1,5 @@ +`include "common.svh" + import common::*; module posit_32b_add ( diff --git a/hdl/rtl/alu/posit_32b_sub.sv b/hdl/rtl/src/alu/posit_32b_sub.sv similarity index 96% rename from hdl/rtl/alu/posit_32b_sub.sv rename to hdl/rtl/src/alu/posit_32b_sub.sv index f51ef13..253b0cd 100644 --- a/hdl/rtl/alu/posit_32b_sub.sv +++ b/hdl/rtl/src/alu/posit_32b_sub.sv @@ -1,3 +1,5 @@ +`include "common.svh" + import common::*; module posit_32b_sub ( diff --git a/hdl/rtl/alu/posit_7b_add.sv b/hdl/rtl/src/alu/posit_7b_add.sv similarity index 94% rename from hdl/rtl/alu/posit_7b_add.sv rename to hdl/rtl/src/alu/posit_7b_add.sv index 873d85c..093bb0e 100644 --- a/hdl/rtl/alu/posit_7b_add.sv +++ b/hdl/rtl/src/alu/posit_7b_add.sv @@ -1,3 +1,5 @@ +`include "common.svh" + import common::*; module posit_7b_add ( diff --git a/hdl/rtl/alu/posit_7b_sub.sv b/hdl/rtl/src/alu/posit_7b_sub.sv similarity index 96% rename from hdl/rtl/alu/posit_7b_sub.sv rename to hdl/rtl/src/alu/posit_7b_sub.sv index a9b80ce..1ee9977 100644 --- a/hdl/rtl/alu/posit_7b_sub.sv +++ b/hdl/rtl/src/alu/posit_7b_sub.sv @@ -1,3 +1,5 @@ +`include "common.svh" + import common::*; module posit_7b_sub ( diff --git a/hdl/rtl/alu/two_comp.sv b/hdl/rtl/src/alu/two_comp.sv similarity index 92% rename from hdl/rtl/alu/two_comp.sv rename to hdl/rtl/src/alu/two_comp.sv index a95369c..06713b9 100644 --- a/hdl/rtl/alu/two_comp.sv +++ b/hdl/rtl/src/alu/two_comp.sv @@ -1,4 +1,6 @@ // takes a logic bus and reports the twos complement of it +`include "common.svh" + import common::*; module two_comp #( diff --git a/hdl/rtl/decode/henry_decoder/posit32_count_regime.sv b/hdl/rtl/src/decode/henry_decoder/posit32_count_regime.sv similarity index 99% rename from hdl/rtl/decode/henry_decoder/posit32_count_regime.sv rename to hdl/rtl/src/decode/henry_decoder/posit32_count_regime.sv index 02ddf16..c5f4799 100644 --- a/hdl/rtl/decode/henry_decoder/posit32_count_regime.sv +++ b/hdl/rtl/src/decode/henry_decoder/posit32_count_regime.sv @@ -1,3 +1,5 @@ +`include "posit_types.svh" + import posit_types::*; module count_regime_16 ( diff --git a/hdl/rtl/decode/henry_decoder/posit32_decode.sv b/hdl/rtl/src/decode/henry_decoder/posit32_decode.sv similarity index 90% rename from hdl/rtl/decode/henry_decoder/posit32_decode.sv rename to hdl/rtl/src/decode/henry_decoder/posit32_decode.sv index 335b406..bebc29f 100644 --- a/hdl/rtl/decode/henry_decoder/posit32_decode.sv +++ b/hdl/rtl/src/decode/henry_decoder/posit32_decode.sv @@ -1,4 +1,6 @@ -import posit/posit_types::* +`include "posit_types.svh" + +import posit_types::*; module posit32_decode #( parameter int unsigned es = 2 diff --git a/hdl/rtl/decode/henry_decoder/posit64_decode.sv b/hdl/rtl/src/decode/henry_decoder/posit64_decode.sv similarity index 89% rename from hdl/rtl/decode/henry_decoder/posit64_decode.sv rename to hdl/rtl/src/decode/henry_decoder/posit64_decode.sv index 905423c..f72c767 100644 --- a/hdl/rtl/decode/henry_decoder/posit64_decode.sv +++ b/hdl/rtl/src/decode/henry_decoder/posit64_decode.sv @@ -1,6 +1,6 @@ -import posit/posit_types::* +import posit_types::*; -module posit32_decode #( +module posit64_decode #( parameter int unsigned es = 2 ) ( input posit64_t p, diff --git a/hdl/rtl/decode/henry_decoder/posit_variable_count_regime.sv b/hdl/rtl/src/decode/henry_decoder/posit_variable_count_regime.sv similarity index 73% rename from hdl/rtl/decode/henry_decoder/posit_variable_count_regime.sv rename to hdl/rtl/src/decode/henry_decoder/posit_variable_count_regime.sv index d308834..f519805 100644 --- a/hdl/rtl/decode/henry_decoder/posit_variable_count_regime.sv +++ b/hdl/rtl/src/decode/henry_decoder/posit_variable_count_regime.sv @@ -1,5 +1,5 @@ module count_regime #( - parameter int unsigned width = 31, + parameter int unsigned width = 31 ) ( input bit [width-1:0] v, output integer unsigned c @@ -26,14 +26,14 @@ module count_regime #( logic [width-2:0] v_enc; - generate - for (genvar i = 0; i < (width-1) / 2; i++) begin - count_leading_encoder(leading = b) i_count_leading_encoder ( - .leading_bit(v[width-1]), - .i(v[2*i + 1: 2*i]), - .o(v_enc[2*i + 1: 2*i]) - ) - end - endgenerate + // generate + // for (genvar i = 0; i < (width-1) / 2; i++) begin + // count_leading_encoder(leading = b) i_count_leading_encoder ( + // .leading_bit(v[width-1]), + // .i(v[2*i + 1: 2*i]), + // .o(v_enc[2*i + 1: 2*i]) + // ) + // end + // endgenerate endmodule \ No newline at end of file diff --git a/hdl/rtl/decode/henry_decoder/posit_variable_decode.sv b/hdl/rtl/src/decode/henry_decoder/posit_variable_decode.sv similarity index 90% rename from hdl/rtl/decode/henry_decoder/posit_variable_decode.sv rename to hdl/rtl/src/decode/henry_decoder/posit_variable_decode.sv index 7676979..f8be13c 100644 --- a/hdl/rtl/decode/henry_decoder/posit_variable_decode.sv +++ b/hdl/rtl/src/decode/henry_decoder/posit_variable_decode.sv @@ -1,4 +1,6 @@ -import posit/posit_types::sign_t +`include "posit_types.svh" + +import posit_types::sign_t; module posit_variable_decode #( parameter int unsigned width = 32, diff --git a/hdl/rtl/decode/henry_decoder/util/mux.sv b/hdl/rtl/src/decode/henry_decoder/util/mux.sv similarity index 100% rename from hdl/rtl/decode/henry_decoder/util/mux.sv rename to hdl/rtl/src/decode/henry_decoder/util/mux.sv diff --git a/hdl/rtl/decode/henry_decoder/util/priority_encoders.sv b/hdl/rtl/src/decode/henry_decoder/util/priority_encoders.sv similarity index 100% rename from hdl/rtl/decode/henry_decoder/util/priority_encoders.sv rename to hdl/rtl/src/decode/henry_decoder/util/priority_encoders.sv diff --git a/hdl/rtl/decode/luke_decoder/count_lead_one.sv b/hdl/rtl/src/decode/luke_decoder/count_lead_one.sv similarity index 100% rename from hdl/rtl/decode/luke_decoder/count_lead_one.sv rename to hdl/rtl/src/decode/luke_decoder/count_lead_one.sv diff --git a/hdl/rtl/decode/luke_decoder/count_lead_one_24.sv b/hdl/rtl/src/decode/luke_decoder/count_lead_one_24.sv similarity index 100% rename from hdl/rtl/decode/luke_decoder/count_lead_one_24.sv rename to hdl/rtl/src/decode/luke_decoder/count_lead_one_24.sv diff --git a/hdl/rtl/decode/luke_decoder/count_lead_zero.sv b/hdl/rtl/src/decode/luke_decoder/count_lead_zero.sv similarity index 100% rename from hdl/rtl/decode/luke_decoder/count_lead_zero.sv rename to hdl/rtl/src/decode/luke_decoder/count_lead_zero.sv diff --git a/hdl/rtl/decode/luke_decoder/count_tail_one.sv b/hdl/rtl/src/decode/luke_decoder/count_tail_one.sv similarity index 100% rename from hdl/rtl/decode/luke_decoder/count_tail_one.sv rename to hdl/rtl/src/decode/luke_decoder/count_tail_one.sv diff --git a/hdl/rtl/decode/luke_decoder/count_tail_zero.sv b/hdl/rtl/src/decode/luke_decoder/count_tail_zero.sv similarity index 100% rename from hdl/rtl/decode/luke_decoder/count_tail_zero.sv rename to hdl/rtl/src/decode/luke_decoder/count_tail_zero.sv diff --git a/hdl/rtl/decode/luke_decoder/find_first_n_ones.sv b/hdl/rtl/src/decode/luke_decoder/find_first_n_ones.sv similarity index 96% rename from hdl/rtl/decode/luke_decoder/find_first_n_ones.sv rename to hdl/rtl/src/decode/luke_decoder/find_first_n_ones.sv index 9ae6df6..2ad0ee6 100644 --- a/hdl/rtl/decode/luke_decoder/find_first_n_ones.sv +++ b/hdl/rtl/src/decode/luke_decoder/find_first_n_ones.sv @@ -1,4 +1,6 @@ // returns the input with only the MSB 1 set +`include "common.svh" + import common::*; module find_first_n_ones #( diff --git a/hdl/rtl/decode/luke_decoder/find_first_one.sv b/hdl/rtl/src/decode/luke_decoder/find_first_one.sv similarity index 93% rename from hdl/rtl/decode/luke_decoder/find_first_one.sv rename to hdl/rtl/src/decode/luke_decoder/find_first_one.sv index b17b511..1b02412 100644 --- a/hdl/rtl/decode/luke_decoder/find_first_one.sv +++ b/hdl/rtl/src/decode/luke_decoder/find_first_one.sv @@ -1,4 +1,6 @@ // returns the input with only the MSB 1 set +`include "common.svh" + import common::*; module find_first_one #( diff --git a/hdl/rtl/decode/luke_decoder/format_decoder.sv b/hdl/rtl/src/decode/luke_decoder/format_decoder.sv similarity index 99% rename from hdl/rtl/decode/luke_decoder/format_decoder.sv rename to hdl/rtl/src/decode/luke_decoder/format_decoder.sv index 470f9b9..fd0d2af 100644 --- a/hdl/rtl/decode/luke_decoder/format_decoder.sv +++ b/hdl/rtl/src/decode/luke_decoder/format_decoder.sv @@ -1,5 +1,7 @@ // takes a posit bus and extracts the relevant // regions as digital signed byte values +`include "common.svh" + import common::*; // Comb diff --git a/hdl/rtl/dff.sv b/hdl/rtl/src/dff/dff.sv similarity index 99% rename from hdl/rtl/dff.sv rename to hdl/rtl/src/dff/dff.sv index 338ac03..8f7aca9 100644 --- a/hdl/rtl/dff.sv +++ b/hdl/rtl/src/dff/dff.sv @@ -19,4 +19,3 @@ end // end // `endif endmodule : dff - diff --git a/hdl/rtl/encode/format_encoder.sv b/hdl/rtl/src/encode/format_encoder.sv similarity index 99% rename from hdl/rtl/encode/format_encoder.sv rename to hdl/rtl/src/encode/format_encoder.sv index b2a11b7..f6eea32 100644 --- a/hdl/rtl/encode/format_encoder.sv +++ b/hdl/rtl/src/encode/format_encoder.sv @@ -1,3 +1,5 @@ +`include "common.svh" + import common::*; module format_encoder #( diff --git a/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py b/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py index 151c63c..c228b39 100644 --- a/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py +++ b/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py @@ -1,64 +1,11 @@ -import sys, os -import glob - -try: - import coco_wrapper.coco_wrapper -except ModuleNotFoundError: - sys.exit("Error: incorrect configuration!") - - -CWD = os.path.dirname(os.path.realpath(__file__)) - -############################################################################### - -SRC = ( - [ - f"{coco_wrapper.RTL_TOP}/typedef/common.sv", - f"{coco_wrapper.RTL_TOP}/alu/comparator.sv", - f"{coco_wrapper.RTL_TOP}/alu/two_comp.sv", - f"{coco_wrapper.RTL_TOP}/alu/posit_32b_add.sv", - f"{coco_wrapper.RTL_TOP}/alu/posit_32b_sub.sv", - f"{coco_wrapper.RTL_TOP}/alu/posit_7b_add.sv", - f"{coco_wrapper.RTL_TOP}/alu/posit_7b_sub.sv" - ] - + glob.glob(f"{coco_wrapper.RTL_TOP}/decode/luke_decoder/*.sv") - + glob.glob(f"{coco_wrapper.RTL_TOP}/encode/*.sv") - + glob.glob(f"{coco_wrapper.RTL_TOP}/alu/adder/*.sv") -) +from coco_wrapper import cocotb_test_wrapper def test_posit_adder(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="posit_adder", - - modulepath=f"{CWD}/posit_adder", - modules=[ - "cocotb_test_posit_adder" - ] - ) + cocotb_test_wrapper( toplevel='posit_adder' ).test('posit_adder') def test_posit_7b_add(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="posit_7b_add", - - modulepath=f"{CWD}/posit_7b_add", - modules=[ - "cocotb_test_posit_7b_add" - ] - ) + cocotb_test_wrapper( toplevel='posit_7b_add' ).test('posit_7b_add') def test_posit_32b_add(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="posit_32b_add", - - modulepath=f"{CWD}/posit_32b_add", - modules=[ - "cocotb_test_posit_32b_add" - ] - ) + cocotb_test_wrapper( toplevel='posit_32b_add' ).test('posit_32b_add') diff --git a/hdl/verif/cocotb/tests/luke_decoder/dff/cocotb_test_dff.py b/hdl/verif/cocotb/tests/dff/cocotb_test_dff.py similarity index 92% rename from hdl/verif/cocotb/tests/luke_decoder/dff/cocotb_test_dff.py rename to hdl/verif/cocotb/tests/dff/cocotb_test_dff.py index 13c9826..5febf8b 100644 --- a/hdl/verif/cocotb/tests/luke_decoder/dff/cocotb_test_dff.py +++ b/hdl/verif/cocotb/tests/dff/cocotb_test_dff.py @@ -1,11 +1,8 @@ ## test_dff.py -import random import cocotb from cocotb.clock import Clock from cocotb.triggers import RisingEdge, FallingEdge, ReadOnly -from cocotb.types import LogicArray -from cocotb.clock import Timer @cocotb.test() diff --git a/hdl/verif/cocotb/tests/dff/test_dff.py b/hdl/verif/cocotb/tests/dff/test_dff.py new file mode 100644 index 0000000..0ce3b3c --- /dev/null +++ b/hdl/verif/cocotb/tests/dff/test_dff.py @@ -0,0 +1,7 @@ +from coco_wrapper import cocotb_test_wrapper + +def test_dff(): + cocotb_test_wrapper( + src='dff', + toplevel='dff' + ).test('.') diff --git a/hdl/verif/cocotb/tests/henry_decoder/count_regime/cocotb_test_pyposit_module.py b/hdl/verif/cocotb/tests/henry_decoder/count_regime/cocotb_test_pyposit_module.py deleted file mode 100644 index c370ddc..0000000 --- a/hdl/verif/cocotb/tests/henry_decoder/count_regime/cocotb_test_pyposit_module.py +++ /dev/null @@ -1,40 +0,0 @@ -import cocotb -from cocotb.triggers import Timer -from cocotb.binary import BinaryValue - -from pyposit.decode import count_regime - -async def test_value(dut, bin_str): - - valid = ( - (bin_str[1] == '0' and '1' in bin_str) or - (bin_str[1] == '1' and '0' in bin_str) - ) - - expected = count_regime(bin_str) - dut.i.value = BinaryValue(bin_str) - - await Timer(1, "ns") - - dut._log.info(f"Input: {bin_str}") - - dut._log.info(f"Valid: {dut.valid.value}") - assert dut.valid.value == valid - - if valid: - dut._log.info(f"Output: {dut.c.value} (should be {expected})") - assert dut.c.value == expected - - dut._log.info("\n") - - -@cocotb.test() -async def test_count_regime(dut): - dut._log.warning(f"Test {__name__} Starting...") - - await test_value(dut, "10001000100010001000100010001000") - await test_value(dut, "00001000100010001000100010001000") - await test_value(dut, "00000000100010001000100010001000") - await test_value(dut, "00000000000000000000000000000000") - await test_value(dut, "11001000100010001000100010001000") - await test_value(dut, "11111111111111111111111111111111") diff --git a/hdl/verif/cocotb/tests/henry_decoder/count_regime/posit32_count_regime_tb.sv b/hdl/verif/cocotb/tests/henry_decoder/count_regime/posit32_count_regime_tb.sv deleted file mode 100644 index b5d21a2..0000000 --- a/hdl/verif/cocotb/tests/henry_decoder/count_regime/posit32_count_regime_tb.sv +++ /dev/null @@ -1,16 +0,0 @@ -module posit32_count_regime_tb ( - input logic [31:0] i, - - output logic [4:0] c, - output logic valid -); - - posit32_t tmp; - - assign tmp = i; - - posit32_count_regime i_posit32_count_regime( - .i(tmp), .c(c), .valid(valid) - ); - -endmodule diff --git a/hdl/verif/cocotb/tests/henry_decoder/priority_encoder/priority_encoder_16_tb.sv b/hdl/verif/cocotb/tests/henry_decoder/priority_encoder/priority_encoder_16_tb.sv deleted file mode 100644 index 5055e14..0000000 --- a/hdl/verif/cocotb/tests/henry_decoder/priority_encoder/priority_encoder_16_tb.sv +++ /dev/null @@ -1,14 +0,0 @@ -module priority_encoder_16_tb ( - input logic leading_bit, - input logic [15:0] i, - - output logic [3:0] c, - output logic valid -); - - count_regime_16 i_count_regime_16( - .leading_bit(leading_bit), .i(i), - .c(c), .valid(valid) - ); - -endmodule diff --git a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py index b6c25bd..6e0dbd7 100644 --- a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py +++ b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py @@ -1,48 +1,13 @@ -import sys, os - -try: - import coco_wrapper.coco_wrapper -except ModuleNotFoundError: - sys.exit("Error: incorrect configuration! " - "Please run `source setup.sh` from verif/cocotb.") - - -CWD = os.path.dirname(os.path.realpath(__file__)) - -############################################################################### +from coco_wrapper import cocotb_test_wrapper def test_priority_encoder(): - coco_wrapper.cocotb_test_module( - src=[ - f"{coco_wrapper.RTL_TOP}/typedef/posit_types.sv", - f"{coco_wrapper.RTL_TOP}/decode/henry_decoder/util/mux.sv", - f"{coco_wrapper.RTL_TOP}/decode/henry_decoder/util/priority_encoders.sv", - f"{coco_wrapper.RTL_TOP}/decode/henry_decoder/posit32_count_regime.sv", - f"{CWD}/priority_encoder/priority_encoder_16_tb.sv", - ], - - toplevel="priority_encoder_16_tb", - - modulepath=f"{CWD}/priority_encoder", - modules=[ - "cocotb_test_pe_16b" - ] - ) + cocotb_test_wrapper( + src='decode/henry_decoder', + toplevel='count_regime_16' + ).test('priority_encoder') def test_count_regime(): - coco_wrapper.cocotb_test_module( - src=[ - f"{coco_wrapper.RTL_TOP}/typedef/posit_types.sv", - f"{coco_wrapper.RTL_TOP}/decode/henry_decoder/util/mux.sv", - f"{coco_wrapper.RTL_TOP}/decode/henry_decoder/util/priority_encoders.sv", - f"{coco_wrapper.RTL_TOP}/decode/henry_decoder/posit32_count_regime.sv", - f"{CWD}/count_regime/posit32_count_regime_tb.sv", - ], - - toplevel="posit32_count_regime_tb", - - modulepath=f"{CWD}/count_regime", - modules=[ - "cocotb_test_count_regime" - ] - ) + cocotb_test_wrapper( + src='decode/henry_decoder', + toplevel='posit32_count_regime' + ).test('count_regime') diff --git a/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py b/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py index c74aec7..dbd69cc 100644 --- a/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py +++ b/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py @@ -1,130 +1,54 @@ -import sys, os -import glob +from coco_wrapper import cocotb_test_wrapper -try: - import coco_wrapper.coco_wrapper -except ModuleNotFoundError: - sys.exit("Error: incorrect configuration! " - "Please run `source setup.sh` from verif/cocotb.") - - -CWD = os.path.dirname(os.path.realpath(__file__)) - -############################################################################### - -SRC = ( - [ - f"{coco_wrapper.RTL_TOP}/typedef/common.sv", - f"{coco_wrapper.RTL_TOP}/alu/comparator.sv", - f"{coco_wrapper.RTL_TOP}/alu/two_comp.sv" - ] - + glob.glob(f"{coco_wrapper.RTL_TOP}/decode/luke_decoder/*.sv") -) - -def test_dff(): - coco_wrapper.cocotb_test_module( - src=[f"{coco_wrapper.RTL_TOP}/dff.sv"], - - toplevel="dff", - - modulepath=f"{CWD}/dff", - modules=[ - "cocotb_test_dff" - ] - ) +src_dirs = [ + 'decode/luke_decoder', + 'alu' +] def test_clo(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="count_lead_one", - - modulepath=f"{CWD}/clo", - modules=[ - "cocotb_test_clo" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='count_lead_one' + ).test('clo') def test_clo_24(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="count_lead_one_24", - - modulepath=f"{CWD}/count_lead_one_24", - modules=[ - "cocotb_test_count_lead_one_24" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='count_lead_one_24' + ).test('count_lead_one_24') def test_clz(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="count_lead_zero", - - modulepath=f"{CWD}/clz", - modules=[ - "cocotb_test_clz" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='count_lead_zero' + ).test('clz') def test_cto(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="count_tail_one", - - modulepath=f"{CWD}/cto", - modules=[ - "cocotb_test_cto" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='count_tail_one' + ).test('cto') def test_ctz(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="count_tail_zero", - - modulepath=f"{CWD}/ctz", - modules=[ - "cocotb_test_ctz" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='count_tail_zero' + ).test('ctz') def test_decoder(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="format_decoder", - - modulepath=f"{CWD}/decoder", - modules=[ - "cocotb_test_decoder" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='format_decoder' + ).test('decoder') def test_ffo(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="find_first_one", - - modulepath=f"{CWD}/ffo", - modules=[ - "cocotb_test_ffo" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='find_first_one' + ).test('ffo') def test_ffno(): - coco_wrapper.cocotb_test_module( - src=SRC, - - toplevel="find_first_n_ones", - - modulepath=f"{CWD}/ffno", - modules=[ - "cocotb_test_ffno" - ] - ) + cocotb_test_wrapper( + src=src_dirs, + toplevel='find_first_n_ones' + ).test('ffno') diff --git a/setup.sh b/setup.sh index 964279e..6138c0d 100755 --- a/setup.sh +++ b/setup.sh @@ -33,5 +33,6 @@ export COCOTB_HDL_TIMEPRECISION=1ps export TOPLEVEL_LANG=verilog export SIM=verilator export SIM_BUILD_ARGS="--trace --trace-fst --trace-structs --coverage" + echo "Environment activated" echo diff --git a/softmodels/src/coco_wrapper.py b/softmodels/src/coco_wrapper.py new file mode 100644 index 0000000..c809617 --- /dev/null +++ b/softmodels/src/coco_wrapper.py @@ -0,0 +1,81 @@ +import os +import sys +import inspect +from pathlib import Path + +from cocotb.runner import get_runner + + +# Acquire environment variables +# TODO: check if these are empty and throw error +COCOTB_TOP = Path(str(os.getenv("COCOTB_TOP"))) +HDL_TOP = Path(str(os.getenv("RTL_TOP"))) +RTL_TOP = Path(str(os.getenv("RTL_TOP"))) +SRC_TOP = RTL_TOP / 'src' + + +_default_sim = "verilator" +_default_sim_args = [ + "--trace", + "--trace-fst", + "--trace-structs", + "--coverage" +] + +class cocotb_test_wrapper(): + def __init__(self, *, + src=None, + inc=[f"{RTL_TOP}/include"], + toplevel, + sim=_default_sim, + sim_args=_default_sim_args): + + self.runner = get_runner(sim) + + if src is None: + src_files = SRC_TOP.resolve().glob('**/*.sv') + elif isinstance(src, list): + src_files = [] + for src_dir in src: + src_path = ( SRC_TOP / src_dir ).resolve() + src_files.extend( src_path.glob('**/*.sv') ) + else: + src_path = ( SRC_TOP / src ).resolve() + + src_files = src_path.glob('**/*.sv') + + self.runner.build( + always=True, + verilog_sources=src_files, + includes=inc, + hdl_toplevel=toplevel, + build_args=sim_args, + build_dir=str( COCOTB_TOP / f'sim_build/{toplevel}' ) + ) + + self._toplevel = toplevel + + def test(self, search_path: str): + caller_path = Path((inspect.stack()[1])[1]) + caller_dir = caller_path.parent + full_path = (caller_dir / search_path).resolve() + + modules = full_path.glob( + '**/cocotb_test_*.py' + ) + + for module_path in modules: + folder_path = str(module_path.parent) + module_name = module_path.stem + + print("DEBUG:", folder_path, module_name) + + sys.path.append(folder_path) + + self.runner.test( + hdl_toplevel=self._toplevel, + test_module=module_name + ) + + sys.path.remove(folder_path) + diff --git a/softmodels/src/coco_wrapper/__init__.py b/softmodels/src/coco_wrapper/__init__.py deleted file mode 100644 index a0f7852..0000000 --- a/softmodels/src/coco_wrapper/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .coco_wrapper import * diff --git a/softmodels/src/coco_wrapper/coco_wrapper.py b/softmodels/src/coco_wrapper/coco_wrapper.py deleted file mode 100644 index cbbad88..0000000 --- a/softmodels/src/coco_wrapper/coco_wrapper.py +++ /dev/null @@ -1,43 +0,0 @@ -import os, sys -from cocotb.runner import get_runner - -# Acquire environment variables -COCOTB_TOP = os.getenv("COCOTB_TOP") -HDL_TOP = os.getenv("RTL_TOP") -RTL_TOP = os.getenv("RTL_TOP") - -COCOTB_HDL_TIMEUNIT = os.getenv("COCOTB_HDL_TIMEUNIT") -COCOTB_HDL_TIMEPRECISION = os.getenv("COCOTB_HDL_TIMEPREVISION") - -TOPLEVEL_LANG = os.getenv("TOPLEVEL_LANG") -VERILOG_SOURCES = os.getenv("VERILOG_SOURCES", "").split(" ") - -SIM = os.getenv("SIM") - -if SIM is None: - sys.exit("Error: SIM undefined!") - -SIM_BUILD_ARGS=os.getenv("SIM_BUILD_ARGS", "").split(" ") - -# FIXME: could we share runner per import to improve runtime? -# i.e. call runner=get_runner(SIM) up here, then -# just reference it within the function? - - -def cocotb_test_module(src, toplevel, modulepath, modules): - sys.path.append(modulepath) - - subpath = modulepath.replace(f"{COCOTB_TOP}/tests/", "") - - runner = get_runner(SIM) - runner.build( - verilog_sources=src, - hdl_toplevel=toplevel, - always=True, - build_args=SIM_BUILD_ARGS, - build_dir=f"{COCOTB_TOP}/sim_build/{subpath}" - ) - - runner.test(hdl_toplevel=toplevel, test_module=modules) - - sys.path.remove(modulepath) From d5333fbc31b172c0899edbdd74bfc36f3536fc3c Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 14:15:42 +0100 Subject: [PATCH 02/10] Update github actions build steps --- .github/workflows/verif.yml | 6 +++--- .vscode/settings.json | 3 ++- cocotb_env | 8 -------- .../cocotb/tests/arithmetic/test_arithmetic.py | 8 ++++---- hdl/verif/cocotb/tests/dff/test_dff.py | 4 ++-- .../tests/henry_decoder/test_henry_decoder.py | 6 +++--- .../tests/luke_decoder/test_luke_decoder.py | 18 +++++++++--------- hdl/verif/cocotb/workflow_cfg.sh | 17 ----------------- setup.sh | 7 ------- softmodels/src/coco_wrapper.py | 6 +++++- 10 files changed, 28 insertions(+), 55 deletions(-) delete mode 100755 hdl/verif/cocotb/workflow_cfg.sh diff --git a/.github/workflows/verif.yml b/.github/workflows/verif.yml index 3b9b8c7..469f3eb 100644 --- a/.github/workflows/verif.yml +++ b/.github/workflows/verif.yml @@ -26,14 +26,14 @@ jobs: - name: Install dependencies run: | - pip --disable-pip-version-check install -r requirements.txt + ./setup.sh HOMEBREW_NO_INSTALL_CLEANUP=1 brew install verilator - name: Verify with cocotb & verilator working-directory: ./hdl/verif/cocotb run: | - source workflow_cfg.sh - pytest --junitxml=pytest_report.xml --report-log=logs/pytest.log -n auto + pytest --junitxml=pytest_report.xml --report-log=logs/pytest.log \ + -n auto -W ignore::UserWarning - name: Generate report if: always() diff --git a/.vscode/settings.json b/.vscode/settings.json index b8f5074..6be0282 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,8 @@ "python.testing.pytestArgs": [ "hdl/verif/cocotb", "softmodels/tests", - "-n=auto" + "-n=auto", + "-W ignore::UserWarning" ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, diff --git a/cocotb_env b/cocotb_env index 42036af..81aabe5 100644 --- a/cocotb_env +++ b/cocotb_env @@ -1,11 +1,3 @@ COCOTB_TOP="hdl/verif/cocotb" HDL_TOP="hdl" RTL_TOP="hdl/rtl" - -COCOTB_HDL_TIMEUNIT=1ns -COCOTB_HDL_TIMEPRECISION=1ps - -TOPLEVEL_LANG=verilog - -SIM=verilator -SIM_BUILD_ARGS="--trace --trace-fst --trace-structs --coverage" diff --git a/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py b/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py index c228b39..b6d6927 100644 --- a/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py +++ b/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py @@ -1,11 +1,11 @@ -from coco_wrapper import cocotb_test_wrapper +from coco_wrapper import TestWrapper def test_posit_adder(): - cocotb_test_wrapper( toplevel='posit_adder' ).test('posit_adder') + TestWrapper( toplevel='posit_adder' ).test('posit_adder') def test_posit_7b_add(): - cocotb_test_wrapper( toplevel='posit_7b_add' ).test('posit_7b_add') + TestWrapper( toplevel='posit_7b_add' ).test('posit_7b_add') def test_posit_32b_add(): - cocotb_test_wrapper( toplevel='posit_32b_add' ).test('posit_32b_add') + TestWrapper( toplevel='posit_32b_add' ).test('posit_32b_add') diff --git a/hdl/verif/cocotb/tests/dff/test_dff.py b/hdl/verif/cocotb/tests/dff/test_dff.py index 0ce3b3c..5600221 100644 --- a/hdl/verif/cocotb/tests/dff/test_dff.py +++ b/hdl/verif/cocotb/tests/dff/test_dff.py @@ -1,7 +1,7 @@ -from coco_wrapper import cocotb_test_wrapper +from coco_wrapper import TestWrapper def test_dff(): - cocotb_test_wrapper( + TestWrapper( src='dff', toplevel='dff' ).test('.') diff --git a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py index 6e0dbd7..64b3a85 100644 --- a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py +++ b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py @@ -1,13 +1,13 @@ -from coco_wrapper import cocotb_test_wrapper +from coco_wrapper import TestWrapper def test_priority_encoder(): - cocotb_test_wrapper( + TestWrapper( src='decode/henry_decoder', toplevel='count_regime_16' ).test('priority_encoder') def test_count_regime(): - cocotb_test_wrapper( + TestWrapper( src='decode/henry_decoder', toplevel='posit32_count_regime' ).test('count_regime') diff --git a/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py b/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py index dbd69cc..fe2d9ca 100644 --- a/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py +++ b/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py @@ -1,4 +1,4 @@ -from coco_wrapper import cocotb_test_wrapper +from coco_wrapper import TestWrapper src_dirs = [ 'decode/luke_decoder', @@ -6,49 +6,49 @@ ] def test_clo(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='count_lead_one' ).test('clo') def test_clo_24(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='count_lead_one_24' ).test('count_lead_one_24') def test_clz(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='count_lead_zero' ).test('clz') def test_cto(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='count_tail_one' ).test('cto') def test_ctz(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='count_tail_zero' ).test('ctz') def test_decoder(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='format_decoder' ).test('decoder') def test_ffo(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='find_first_one' ).test('ffo') def test_ffno(): - cocotb_test_wrapper( + TestWrapper( src=src_dirs, toplevel='find_first_n_ones' ).test('ffno') diff --git a/hdl/verif/cocotb/workflow_cfg.sh b/hdl/verif/cocotb/workflow_cfg.sh deleted file mode 100755 index 295c875..0000000 --- a/hdl/verif/cocotb/workflow_cfg.sh +++ /dev/null @@ -1,17 +0,0 @@ -# DO NOT REMOVE - CONFIGURE ENV FOR GH ACTIONS -# USERS CALL THE TOP-LEVEL SCRIPT BUT GH REQUIRES -# THIS DIRECTORY BECAUSE SOMETIMES WE CANT HAVE -# NICE THINGS - -export COCOTB_TOP=$( realpath . ) -export HDL_TOP=$( realpath $COCOTB_TOP/../.. ) -export RTL_TOP=$( realpath $HDL_TOP/rtl ) - -export COCOTB_HDL_TIMEUNIT=1ns -export COCOTB_HDL_TIMEPRECISION=1ps - -export TOPLEVEL_LANG=verilog -export SIM=verilator -export SIM_BUILD_ARGS="--trace --trace-fst --trace-structs --coverage" - -if [ -f setup.user.sh ]; then source setup.user.sh ; fi diff --git a/setup.sh b/setup.sh index 6138c0d..b821fbe 100755 --- a/setup.sh +++ b/setup.sh @@ -27,12 +27,5 @@ echo "Installing env variables" export COCOTB_TOP=$( realpath ./hdl/verif/cocotb ) export HDL_TOP=$( realpath $COCOTB_TOP/../.. ) export RTL_TOP=$( realpath $HDL_TOP/rtl ) - -export COCOTB_HDL_TIMEUNIT=1ns -export COCOTB_HDL_TIMEPRECISION=1ps -export TOPLEVEL_LANG=verilog -export SIM=verilator -export SIM_BUILD_ARGS="--trace --trace-fst --trace-structs --coverage" - echo "Environment activated" echo diff --git a/softmodels/src/coco_wrapper.py b/softmodels/src/coco_wrapper.py index c809617..69cc0d8 100644 --- a/softmodels/src/coco_wrapper.py +++ b/softmodels/src/coco_wrapper.py @@ -22,7 +22,11 @@ "--coverage" ] -class cocotb_test_wrapper(): +# TODO: include these exports in class +# export COCOTB_HDL_TIMEUNIT=1ns +# export COCOTB_HDL_TIMEPRECISION=1ps + +class TestWrapper(): def __init__(self, *, src=None, inc=[f"{RTL_TOP}/include"], From 2e05d387659c08de2bb9d7ee9ce8ca0ba10b68d7 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 14:18:03 +0100 Subject: [PATCH 03/10] Using the existing setup.sh didn't work :( --- .github/workflows/verif.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verif.yml b/.github/workflows/verif.yml index 469f3eb..c73cf65 100644 --- a/.github/workflows/verif.yml +++ b/.github/workflows/verif.yml @@ -26,14 +26,18 @@ jobs: - name: Install dependencies run: | - ./setup.sh + pip --disable-pip-version-check install -r requirements.txt HOMEBREW_NO_INSTALL_CLEANUP=1 brew install verilator - name: Verify with cocotb & verilator working-directory: ./hdl/verif/cocotb run: | + source workflow_cfg.sh + export COCOTB_TOP=$( realpath . ) + export HDL_TOP=$( realpath $COCOTB_TOP/../.. ) + export RTL_TOP=$( realpath $HDL_TOP/rtl ) pytest --junitxml=pytest_report.xml --report-log=logs/pytest.log \ - -n auto -W ignore::UserWarning + -n auto -W ignore::UserWarning - name: Generate report if: always() From 89799415875798763c2ded6e4b25a87993316454 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 14:20:18 +0100 Subject: [PATCH 04/10] Oops --- .github/workflows/verif.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/verif.yml b/.github/workflows/verif.yml index c73cf65..cded086 100644 --- a/.github/workflows/verif.yml +++ b/.github/workflows/verif.yml @@ -32,7 +32,6 @@ jobs: - name: Verify with cocotb & verilator working-directory: ./hdl/verif/cocotb run: | - source workflow_cfg.sh export COCOTB_TOP=$( realpath . ) export HDL_TOP=$( realpath $COCOTB_TOP/../.. ) export RTL_TOP=$( realpath $HDL_TOP/rtl ) From 36a9d5061d260688c8dfa977944ead6e8c9a3f30 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 14:36:38 +0100 Subject: [PATCH 05/10] Catch environment errors --- setup.sh | 12 +++++++----- softmodels/src/coco_wrapper.py | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/setup.sh b/setup.sh index b821fbe..ea8a991 100755 --- a/setup.sh +++ b/setup.sh @@ -7,8 +7,10 @@ echo Run sudo apt install python3.10-venv # create environment in ./env # you can change this path if you want, so long as it's in .gitignore -echo "Creating virtual environment in ./env..." -python3 -m venv env +if [ ! -d "env" ]; then + echo "Creating virtual environment in ./env..." + python3 -m venv env +fi # install requirements echo "Activating environment..." @@ -24,8 +26,8 @@ echo "Virtual environment setup complete!" echo echo "Installing env variables" -export COCOTB_TOP=$( realpath ./hdl/verif/cocotb ) -export HDL_TOP=$( realpath $COCOTB_TOP/../.. ) -export RTL_TOP=$( realpath $HDL_TOP/rtl ) +export HDL_TOP=$( realpath ./hdl ) +export RTL_TOP="$HDL_TOP/rtl" +export COCOTB_TOP="$HDL_TOP/verif/cocotb" echo "Environment activated" echo diff --git a/softmodels/src/coco_wrapper.py b/softmodels/src/coco_wrapper.py index 69cc0d8..5ed0f32 100644 --- a/softmodels/src/coco_wrapper.py +++ b/softmodels/src/coco_wrapper.py @@ -7,11 +7,21 @@ # Acquire environment variables -# TODO: check if these are empty and throw error -COCOTB_TOP = Path(str(os.getenv("COCOTB_TOP"))) -HDL_TOP = Path(str(os.getenv("RTL_TOP"))) -RTL_TOP = Path(str(os.getenv("RTL_TOP"))) + +_ENV_RTL_TOP = os.getenv("RTL_TOP") +_ENV_COCOTB_TOP = os.getenv("COCOTB_TOP") + +if _ENV_RTL_TOP is None: + raise EnvironmentError("Incorrect config, RTL_TOP not set!") + +if _ENV_COCOTB_TOP is None: + raise EnvironmentError("Incorrect config, COCOTB_TOP not set!") + +COCOTB_TOP = Path(str(_ENV_COCOTB_TOP)) + +RTL_TOP = Path(_ENV_RTL_TOP) SRC_TOP = RTL_TOP / 'src' +INC_TOP = RTL_TOP / 'include' _default_sim = "verilator" @@ -22,14 +32,16 @@ "--coverage" ] -# TODO: include these exports in class +# TODO: include these env vars in class # export COCOTB_HDL_TIMEUNIT=1ns # export COCOTB_HDL_TIMEPRECISION=1ps class TestWrapper(): + __test__ = False + def __init__(self, *, src=None, - inc=[f"{RTL_TOP}/include"], + inc=[INC_TOP], toplevel, sim=_default_sim, sim_args=_default_sim_args): From 972fef416e3edda0be0c425500a16c67fd44fb98 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 14:44:47 +0100 Subject: [PATCH 06/10] Allow environment path to be changed --- setup.sh | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/setup.sh b/setup.sh index ea8a991..7335dcb 100755 --- a/setup.sh +++ b/setup.sh @@ -2,24 +2,33 @@ # Welcome to the Python virtual environment setup script. # Luke this one's just for you :) -echo On Debian based systems, python3-venv must be installed -echo Run sudo apt install python3.10-venv +# print warning if running on Linux +if [ "$(uname -s)" = "Linux" ]; then + echo On Debian based systems, python3-venv must be installed + echo Run sudo apt install python3.10-venv +fi # create environment in ./env # you can change this path if you want, so long as it's in .gitignore -if [ ! -d "env" ]; then - echo "Creating virtual environment in ./env..." - python3 -m venv env -fi +envpath="env" -# install requirements -echo "Activating environment..." -source env/bin/activate +# only create environment if it doesn't exist +if [ -d "$envpath" ]; then + # actiavet only + echo "Found environment $envpath, activating..." + source "$envpath/bin/activate" +else + echo "Creating virtual environment in $envpath..." + python3 -m venv "$envpath" -# install requirements -echo "Installing python requirements..." -python3 -m pip install -q --upgrade pip -python3 -m pip install -q -r requirements.txt + echo "Activating environment..." + source "$envpath/bin/activate" + + # install requirements + echo "Installing Python requirements..." + python3 -m pip install -q --upgrade pip + python3 -m pip install -q -r requirements.txt +fi echo echo "Virtual environment setup complete!" From e680a2648e538ca074b625ac8c5abb8510297454 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 14:46:19 +0100 Subject: [PATCH 07/10] Print error message in github summary --- hdl/verif/cocotb/postrun_util/process_results.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hdl/verif/cocotb/postrun_util/process_results.py b/hdl/verif/cocotb/postrun_util/process_results.py index fc3c289..3a5e643 100644 --- a/hdl/verif/cocotb/postrun_util/process_results.py +++ b/hdl/verif/cocotb/postrun_util/process_results.py @@ -72,8 +72,9 @@ try: test_tree = ET.parse(test['filename']) - except: + except Exception as e: print("
Internal error displaying test results.
") + print(f"
Error message: {e}.
") continue test_root = test_tree.getroot() From 851dc47a601230b8d68db52da94d24357cb0e096 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 19:03:33 +0100 Subject: [PATCH 08/10] Refactor tests to play better with github actions --- .../cocotb/postrun_util/process_results.py | 25 +++-- .../tests/arithmetic/test_arithmetic.py | 17 +++- hdl/verif/cocotb/tests/dff/test_dff.py | 6 +- .../tests/henry_decoder/test_henry_decoder.py | 25 +++-- .../tests/luke_decoder/test_luke_decoder.py | 58 ++++++----- softmodels/src/coco_wrapper.py | 99 +++++++++---------- 6 files changed, 130 insertions(+), 100 deletions(-) diff --git a/hdl/verif/cocotb/postrun_util/process_results.py b/hdl/verif/cocotb/postrun_util/process_results.py index 3a5e643..a184078 100644 --- a/hdl/verif/cocotb/postrun_util/process_results.py +++ b/hdl/verif/cocotb/postrun_util/process_results.py @@ -1,12 +1,18 @@ import xml.etree.ElementTree as ET -tree = ET.parse('../pytest_report.xml') +from pathlib import Path + + +root_filepath = (Path(__file__).parent / '..').resolve() + +tree = ET.parse(root_filepath / 'pytest_report.xml') root = tree.getroot() print('# Test Results') -## GENERATE SUMMARY -################### +###################### +## GENERATE SUMMARY ## +###################### modules = {} failures = {} @@ -30,9 +36,9 @@ split_idx = module_name.rindex('.') mod_path = module_name[:split_idx].replace('.', '/') mod_name = module_name[split_idx+1:] - dir_name = test_name.replace('test_', '') - result_filename = ( - f"../sim_build/{mod_path}/{dir_name}/{test_name}.results.xml" + result_filename = str( + root_filepath / + f"sim_build/{mod_name}/{test_name}/{test_name}.results.xml" ) if mod_path not in modules: @@ -73,8 +79,7 @@ try: test_tree = ET.parse(test['filename']) except Exception as e: - print("
Internal error displaying test results.
") - print(f"
Error message: {e}.
") + print(f"
Internal error displaying test results: {e}.
") continue test_root = test_tree.getroot() @@ -84,7 +89,9 @@ errors = {} to_process = {} - with open(f"../logs/generated/{item}/{test['test_name']}.log") as logfile: + log_filepath = root_filepath / f"logs/generated/{item}/{test['test_name']}.log" + + with open(log_filepath) as logfile: for i, line in enumerate(logfile): if 'failed' in line: test_name = line.split(' ')[-2] diff --git a/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py b/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py index b6d6927..799f199 100644 --- a/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py +++ b/hdl/verif/cocotb/tests/arithmetic/test_arithmetic.py @@ -1,11 +1,20 @@ -from coco_wrapper import TestWrapper +from coco_wrapper import cocotb_test_wrapper def test_posit_adder(): - TestWrapper( toplevel='posit_adder' ).test('posit_adder') + cocotb_test_wrapper( + toplevel='posit_adder', + test_search_path='posit_adder' + ) def test_posit_7b_add(): - TestWrapper( toplevel='posit_7b_add' ).test('posit_7b_add') + cocotb_test_wrapper( + toplevel='posit_7b_add', + test_search_path='posit_7b_add' + ) def test_posit_32b_add(): - TestWrapper( toplevel='posit_32b_add' ).test('posit_32b_add') + cocotb_test_wrapper( + toplevel='posit_32b_add', + test_search_path='posit_32b_add' + ) diff --git a/hdl/verif/cocotb/tests/dff/test_dff.py b/hdl/verif/cocotb/tests/dff/test_dff.py index 5600221..7fde89d 100644 --- a/hdl/verif/cocotb/tests/dff/test_dff.py +++ b/hdl/verif/cocotb/tests/dff/test_dff.py @@ -1,7 +1,7 @@ -from coco_wrapper import TestWrapper +from coco_wrapper import cocotb_test_wrapper def test_dff(): - TestWrapper( + cocotb_test_wrapper( src='dff', toplevel='dff' - ).test('.') + ) diff --git a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py index 64b3a85..bb42f34 100644 --- a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py +++ b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py @@ -1,13 +1,20 @@ -from coco_wrapper import TestWrapper +import pytest +from coco_wrapper import cocotb_test_wrapper + +src_dirs = [ + 'decode/henry_decoder' +] def test_priority_encoder(): - TestWrapper( - src='decode/henry_decoder', - toplevel='count_regime_16' - ).test('priority_encoder') + cocotb_test_wrapper( + src=src_dirs, + toplevel='count_regime_16', + test_search_path='priority_encoder' + ) def test_count_regime(): - TestWrapper( - src='decode/henry_decoder', - toplevel='posit32_count_regime' - ).test('count_regime') + cocotb_test_wrapper( + src=src_dirs, + toplevel='posit32_count_regime', + test_search_path='count_regime' + ) diff --git a/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py b/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py index fe2d9ca..ccabf1c 100644 --- a/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py +++ b/hdl/verif/cocotb/tests/luke_decoder/test_luke_decoder.py @@ -1,4 +1,4 @@ -from coco_wrapper import TestWrapper +from coco_wrapper import cocotb_test_wrapper src_dirs = [ 'decode/luke_decoder', @@ -6,49 +6,57 @@ ] def test_clo(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='count_lead_one' - ).test('clo') + toplevel='count_lead_one', + test_search_path='clo' + ) def test_clo_24(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='count_lead_one_24' - ).test('count_lead_one_24') + toplevel='count_lead_one_24', + test_search_path='count_lead_one_24' + ) def test_clz(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='count_lead_zero' - ).test('clz') + toplevel='count_lead_zero', + test_search_path='clz' + ) def test_cto(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='count_tail_one' - ).test('cto') + toplevel='count_tail_one', + test_search_path='cto' + ) def test_ctz(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='count_tail_zero' - ).test('ctz') + toplevel='count_tail_zero', + test_search_path='ctz' + ) def test_decoder(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='format_decoder' - ).test('decoder') + toplevel='format_decoder', + test_search_path='decoder' + ) def test_ffo(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='find_first_one' - ).test('ffo') + toplevel='find_first_one', + test_search_path='ffo' + ) def test_ffno(): - TestWrapper( + cocotb_test_wrapper( src=src_dirs, - toplevel='find_first_n_ones' - ).test('ffno') + toplevel='find_first_n_ones', + test_search_path='ffno' + ) diff --git a/softmodels/src/coco_wrapper.py b/softmodels/src/coco_wrapper.py index 5ed0f32..f41a1e0 100644 --- a/softmodels/src/coco_wrapper.py +++ b/softmodels/src/coco_wrapper.py @@ -36,62 +36,61 @@ # export COCOTB_HDL_TIMEUNIT=1ns # export COCOTB_HDL_TIMEPRECISION=1ps -class TestWrapper(): - __test__ = False +def cocotb_test_wrapper( + *, + src=None, + inc=[INC_TOP], + toplevel, + sim=_default_sim, + sim_args=_default_sim_args, + test_search_path='.'): + runner = get_runner(sim) + + if src is None: + src_files = SRC_TOP.resolve().glob('**/*.sv') + elif isinstance(src, list): + src_files = [] + for src_dir in src: + src_path = ( SRC_TOP / src_dir ).resolve() + src_files.extend( src_path.glob('**/*.sv') ) + else: + src_path = ( SRC_TOP / src ).resolve() + + src_files = src_path.glob('**/*.sv') + + prev_stack = inspect.stack()[1] + test_name = prev_stack.function + test_module = Path(prev_stack[1]).stem - def __init__(self, *, - src=None, - inc=[INC_TOP], - toplevel, - sim=_default_sim, - sim_args=_default_sim_args): - - self.runner = get_runner(sim) - - if src is None: - src_files = SRC_TOP.resolve().glob('**/*.sv') - elif isinstance(src, list): - src_files = [] - for src_dir in src: - src_path = ( SRC_TOP / src_dir ).resolve() - src_files.extend( src_path.glob('**/*.sv') ) - else: - src_path = ( SRC_TOP / src ).resolve() - - src_files = src_path.glob('**/*.sv') - - self.runner.build( - always=True, - verilog_sources=src_files, - includes=inc, - hdl_toplevel=toplevel, - build_args=sim_args, - build_dir=str( COCOTB_TOP / f'sim_build/{toplevel}' ) - ) - - self._toplevel = toplevel + runner.build( + always=True, + verilog_sources=src_files, + includes=inc, + hdl_toplevel=toplevel, + build_args=sim_args, + build_dir=str(COCOTB_TOP / f'sim_build/{test_module}/{test_name}') + ) - def test(self, search_path: str): - caller_path = Path((inspect.stack()[1])[1]) - caller_dir = caller_path.parent - full_path = (caller_dir / search_path).resolve() + caller_path = Path((inspect.stack()[1])[1]) + caller_dir = caller_path.parent + full_path = (caller_dir / test_search_path).resolve() - modules = full_path.glob( - '**/cocotb_test_*.py' - ) + modules = full_path.glob( + '**/cocotb_test_*.py' + ) - for module_path in modules: - folder_path = str(module_path.parent) - module_name = module_path.stem + for module_path in modules: + folder_path = str(module_path.parent) + module_name = module_path.stem - print("DEBUG:", folder_path, module_name) + print("DEBUG:", folder_path, module_name) - sys.path.append(folder_path) + sys.path.append(folder_path) - self.runner.test( - hdl_toplevel=self._toplevel, - test_module=module_name - ) + runner.test( + hdl_toplevel=toplevel, + test_module=module_name + ) - sys.path.remove(folder_path) + sys.path.remove(folder_path) From 7f66f921e8d2d17a971e1f5ae0e40e3a83d8bfcc Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Sun, 17 Sep 2023 19:10:38 +0100 Subject: [PATCH 09/10] Remove stray pytest import --- hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py index bb42f34..7028672 100644 --- a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py +++ b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py @@ -1,4 +1,3 @@ -import pytest from coco_wrapper import cocotb_test_wrapper src_dirs = [ From 069430b27064b04cb26605f38aab7fc89031c394 Mon Sep 17 00:00:00 2001 From: Henry Franks Date: Wed, 20 Sep 2023 19:22:31 +0100 Subject: [PATCH 10/10] Fix things I broke in the tests and clean up --- .vscode/settings.json | 3 +- .../decode/henry_decoder/posit32_decode.sv | 26 ------------- .../decode/henry_decoder/posit64_decode.sv | 24 ------------ .../posit_variable_count_regime.sv | 39 ------------------- .../henry_decoder/posit_variable_decode.sv | 25 ------------ .../tests/henry_decoder/test_henry_decoder.py | 8 +--- softmodels/src/coco_wrapper.py | 27 ++++++++++--- 7 files changed, 26 insertions(+), 126 deletions(-) delete mode 100644 hdl/rtl/src/decode/henry_decoder/posit32_decode.sv delete mode 100644 hdl/rtl/src/decode/henry_decoder/posit64_decode.sv delete mode 100644 hdl/rtl/src/decode/henry_decoder/posit_variable_count_regime.sv delete mode 100644 hdl/rtl/src/decode/henry_decoder/posit_variable_decode.sv diff --git a/.vscode/settings.json b/.vscode/settings.json index 6be0282..7f67102 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,8 @@ "hdl/verif/cocotb", "softmodels/tests", "-n=auto", - "-W ignore::UserWarning" + "-W ignore::UserWarning", + "-s" ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, diff --git a/hdl/rtl/src/decode/henry_decoder/posit32_decode.sv b/hdl/rtl/src/decode/henry_decoder/posit32_decode.sv deleted file mode 100644 index bebc29f..0000000 --- a/hdl/rtl/src/decode/henry_decoder/posit32_decode.sv +++ /dev/null @@ -1,26 +0,0 @@ -`include "posit_types.svh" - -import posit_types::*; - -module posit32_decode #( - parameter int unsigned es = 2 -) ( - input posit32_t p, - - output sign_t sign, - output logic signed [31:0] regime, exponent, - output logic unsigned [31:0] fraction -); - - /* setting the sign bit is trivial */ - always_comb sign = p.sign; - - posit_variable_decode #(32, es) i_posit_variable_decode( - .p(p), - .sign(sign), - .regime(regime), - .exponent(exponent), - .fraction(fraction) - ); - -endmodule diff --git a/hdl/rtl/src/decode/henry_decoder/posit64_decode.sv b/hdl/rtl/src/decode/henry_decoder/posit64_decode.sv deleted file mode 100644 index f72c767..0000000 --- a/hdl/rtl/src/decode/henry_decoder/posit64_decode.sv +++ /dev/null @@ -1,24 +0,0 @@ -import posit_types::*; - -module posit64_decode #( - parameter int unsigned es = 2 -) ( - input posit64_t p, - - output sign_t sign, - output logic signed [63:0] regime, exponent, - output logic unsigned [63:0] fraction -); - - /* setting the sign bit is trivial */ - always_comb sign = p.sign; - - posit_variable_decode #(64, es) i_posit_variable_decode( - .p(p), - .sign(sign), - .regime(regime), - .exponent(exponent), - .fraction(fraction) - ); - -endmodule diff --git a/hdl/rtl/src/decode/henry_decoder/posit_variable_count_regime.sv b/hdl/rtl/src/decode/henry_decoder/posit_variable_count_regime.sv deleted file mode 100644 index f519805..0000000 --- a/hdl/rtl/src/decode/henry_decoder/posit_variable_count_regime.sv +++ /dev/null @@ -1,39 +0,0 @@ -module count_regime #( - parameter int unsigned width = 31 -) ( - input bit [width-1:0] v, - output integer unsigned c -); - - /* COUNT THE NUMBER OF LEADING ZEROS/ONES TO FIND THE REGIME LENGTH */ - - /* Using the below method, we can slice off the leading bit and feed that - * to the encoders. Then the rest of the architecture stays identical but - * the encoder mapping between 0/1 changes to detect 1s instead of 0s. - */ - - /* Count leading zeros method stolen from here: - * https://electronics.stackexchange.com/questions/196914/verilog-synthesize-high-speed-leading-zero-count - * (also see https://en.wikipedia.org/wiki/Find_first_set) - */ - - /* To apply this method, consider a 32b posit: - * We have 1 sign bit and 31 bits which together make all of R, E, & F. - * Slicing off the msb tells us whether we're counting leading ones or - * zeros, leaving an even 30 bits to work with. These bits can be divided - * into pairs and then counted accordingly. - */ - - logic [width-2:0] v_enc; - - // generate - // for (genvar i = 0; i < (width-1) / 2; i++) begin - // count_leading_encoder(leading = b) i_count_leading_encoder ( - // .leading_bit(v[width-1]), - // .i(v[2*i + 1: 2*i]), - // .o(v_enc[2*i + 1: 2*i]) - // ) - // end - // endgenerate - -endmodule \ No newline at end of file diff --git a/hdl/rtl/src/decode/henry_decoder/posit_variable_decode.sv b/hdl/rtl/src/decode/henry_decoder/posit_variable_decode.sv deleted file mode 100644 index f8be13c..0000000 --- a/hdl/rtl/src/decode/henry_decoder/posit_variable_decode.sv +++ /dev/null @@ -1,25 +0,0 @@ -`include "posit_types.svh" - -import posit_types::sign_t; - -module posit_variable_decode #( - parameter int unsigned width = 32, - parameter int unsigned es = 2 -) ( - input logic [width-1:0] p, - - output sign_t sign, - output logic signed [width-2:0] regime, exponent, - output logic unsigned [width-2:0] fraction -); - - /* DECODE A VARIABLE WIDTH POSIT - * Any fixed/standard posit types (e.g. 32- or 64-bit) - * just need to be wrappers around this. - */ - - always_comb sign = p[width-1]; - - // start with a leading zeros/ones counter - -endmodule diff --git a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py index 7028672..baede24 100644 --- a/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py +++ b/hdl/verif/cocotb/tests/henry_decoder/test_henry_decoder.py @@ -1,19 +1,15 @@ from coco_wrapper import cocotb_test_wrapper -src_dirs = [ - 'decode/henry_decoder' -] - def test_priority_encoder(): cocotb_test_wrapper( - src=src_dirs, + src='decode/henry_decoder', toplevel='count_regime_16', test_search_path='priority_encoder' ) def test_count_regime(): cocotb_test_wrapper( - src=src_dirs, + src='decode/henry_decoder', toplevel='posit32_count_regime', test_search_path='count_regime' ) diff --git a/softmodels/src/coco_wrapper.py b/softmodels/src/coco_wrapper.py index f41a1e0..0fb2d42 100644 --- a/softmodels/src/coco_wrapper.py +++ b/softmodels/src/coco_wrapper.py @@ -17,7 +17,7 @@ if _ENV_COCOTB_TOP is None: raise EnvironmentError("Incorrect config, COCOTB_TOP not set!") -COCOTB_TOP = Path(str(_ENV_COCOTB_TOP)) +COCOTB_TOP = Path(_ENV_COCOTB_TOP) RTL_TOP = Path(_ENV_RTL_TOP) SRC_TOP = RTL_TOP / 'src' @@ -44,6 +44,22 @@ def cocotb_test_wrapper( sim=_default_sim, sim_args=_default_sim_args, test_search_path='.'): + """Utility function for easier cocotb testing. + + See docs/verif/README.md for more info. + + Args: + src: [str] - source file paths to search for .sv files + inc: [str] - include directories (passed straight to -I) + toplevel: str - the name of the top-level module + sim: str - the simulator to use + sim_args: [str] - any arguments to pass to the simulator + test_search_path: str - path to recursively search for test modules + + Returns: + None + """ + runner = get_runner(sim) if src is None: @@ -61,17 +77,19 @@ def cocotb_test_wrapper( prev_stack = inspect.stack()[1] test_name = prev_stack.function test_module = Path(prev_stack[1]).stem + + build_dir = str(COCOTB_TOP / f'sim_build/{test_module}/{test_name}') runner.build( always=True, - verilog_sources=src_files, + verilog_sources=src_files, # type: ignore includes=inc, hdl_toplevel=toplevel, build_args=sim_args, - build_dir=str(COCOTB_TOP / f'sim_build/{test_module}/{test_name}') + build_dir=build_dir ) - caller_path = Path((inspect.stack()[1])[1]) + caller_path = Path(prev_stack[1]) caller_dir = caller_path.parent full_path = (caller_dir / test_search_path).resolve() @@ -93,4 +111,3 @@ def cocotb_test_wrapper( ) sys.path.remove(folder_path) -