From b57ffad7d0b9bbce79b4cf8e2d238c55c34f56f7 Mon Sep 17 00:00:00 2001 From: nick Date: Fri, 14 Aug 2026 10:08:40 -0600 Subject: [PATCH] Adding test to demonstrate techmap failure with lut_cmp --- tests/Makefile | 1 + tests/lut/generate_mk.py | 8 ++++ tests/lut/lut.sh | 26 ++++++++++++ tests/lut/map_cmp.v | 85 +++++++++++++++++++++++++++++----------- tests/lut/run-test.sh | 11 ------ 5 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 tests/lut/generate_mk.py create mode 100755 tests/lut/lut.sh delete mode 100755 tests/lut/run-test.sh diff --git a/tests/Makefile b/tests/Makefile index 26446f156..6b9466c73 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -66,6 +66,7 @@ MK_TEST_DIRS += ./arch MK_TEST_DIRS += ./rpc MK_TEST_DIRS += ./memfile MK_TEST_DIRS += ./fmt +MK_TEST_DIRS += ./lut MK_TEST_DIRS += ./cxxrtl MK_TEST_DIRS += ./liberty #ifeq ($(ENABLE_FUNCTIONAL_TESTS),1) diff --git a/tests/lut/generate_mk.py b/tests/lut/generate_mk.py new file mode 100644 index 000000000..10ced96dc --- /dev/null +++ b/tests/lut/generate_mk.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import sys +sys.path.append("..") + +import gen_tests_makefile + +gen_tests_makefile.generate(["--bash"]) diff --git a/tests/lut/lut.sh b/tests/lut/lut.sh new file mode 100755 index 000000000..255743bfa --- /dev/null +++ b/tests/lut/lut.sh @@ -0,0 +1,26 @@ +set -e +DIR=$(cd "$(dirname "$0")" && pwd) + +run_cmp_test() +{ + cmp=$1 + log=${DIR}/map_cmp_${cmp}_eq.log + + echo "Running ${DIR}/map_cmp.v with CMP=4'd${cmp}.." + ${YOSYS} -D "CMP_VALUE=4'd${cmp}" -q -s ${DIR}/check_map.ys -l ${log} -f verilog ${DIR}/map_cmp.v +} + +cmp=0 +while [ ${cmp} -lt 16 ]; do + run_cmp_test ${cmp} + cmp=$((cmp + 1)) +done + +for x in ${DIR}/*.v; do + echo "Running $x.." + ${YOSYS} -q -s ${DIR}/check_map.ys -l ${x%.v}.log -f verilog $x +done +for x in ${DIR}/map_cmp.v; do + echo "Running $x.." + ${YOSYS} -q -s ${DIR}/check_map_lut6.ys -l ${x%.v}_lut6.log -f verilog $x +done diff --git a/tests/lut/map_cmp.v b/tests/lut/map_cmp.v index 0014eb9ac..fa1a4a8c6 100644 --- a/tests/lut/map_cmp.v +++ b/tests/lut/map_cmp.v @@ -1,30 +1,71 @@ +`ifndef CMP_VALUE +`define CMP_VALUE {(LUT_WIDTH/2){2'b10}} +`endif + module top(...); parameter LUT_WIDTH = 4; // Multiples of 2 only + input [LUT_WIDTH-1:0] a; - output o1_1 = {(LUT_WIDTH/2){2'b10}} <= a; - output o1_2 = {(LUT_WIDTH/2){2'b10}} < a; - output o1_3 = {(LUT_WIDTH/2){2'b10}} >= a; - output o1_4 = {(LUT_WIDTH/2){2'b10}} > a; - output o1_5 = {(LUT_WIDTH/2){2'b10}} == a; - output o1_6 = {(LUT_WIDTH/2){2'b10}} != a; + output o1_1 = $unsigned(`CMP_VALUE) <= $unsigned(a); + output o1_2 = $unsigned(`CMP_VALUE) < $unsigned(a); + output o1_3 = $unsigned(`CMP_VALUE) >= $unsigned(a); + output o1_4 = $unsigned(`CMP_VALUE) > $unsigned(a); + output o1_5 = $unsigned(`CMP_VALUE) == $unsigned(a); + output o1_6 = $unsigned(`CMP_VALUE) != $unsigned(a); - output o2_1 = a <= {(LUT_WIDTH/2){2'b10}}; - output o2_2 = a < {(LUT_WIDTH/2){2'b10}}; - output o2_3 = a >= {(LUT_WIDTH/2){2'b10}}; - output o2_4 = a > {(LUT_WIDTH/2){2'b10}}; - output o2_5 = a == {(LUT_WIDTH/2){2'b10}}; - output o2_6 = a != {(LUT_WIDTH/2){2'b10}}; + output o2_1 = $unsigned(a) <= $unsigned(`CMP_VALUE); + output o2_2 = $unsigned(a) < $unsigned(`CMP_VALUE); + output o2_3 = $unsigned(a) >= $unsigned(`CMP_VALUE); + output o2_4 = $unsigned(a) > $unsigned(`CMP_VALUE); + output o2_5 = $unsigned(a) == $unsigned(`CMP_VALUE); + output o2_6 = $unsigned(a) != $unsigned(`CMP_VALUE); - output o3_1 = {(LUT_WIDTH/2){2'sb01}} <= $signed(a); - output o3_2 = {(LUT_WIDTH/2){2'sb01}} < $signed(a); - output o3_3 = {(LUT_WIDTH/2){2'sb01}} >= $signed(a); - output o3_4 = {(LUT_WIDTH/2){2'sb01}} > $signed(a); - output o3_5 = {(LUT_WIDTH/2){2'sb01}} == $signed(a); - output o3_6 = {(LUT_WIDTH/2){2'sb01}} != $signed(a); + // ######################## - output o4_1 = $signed(a) <= {LUT_WIDTH{1'sb0}}; - output o4_2 = $signed(a) < {LUT_WIDTH{1'sb0}}; - output o4_3 = $signed(a) >= {LUT_WIDTH{1'sb0}}; - output o4_4 = $signed(a) > {LUT_WIDTH{1'sb0}}; + output o3_1 = $signed(`CMP_VALUE) <= $unsigned(a); + output o3_2 = $signed(`CMP_VALUE) < $unsigned(a); + output o3_3 = $signed(`CMP_VALUE) >= $unsigned(a); + output o3_4 = $signed(`CMP_VALUE) > $unsigned(a); + output o3_5 = $signed(`CMP_VALUE) == $unsigned(a); + output o3_6 = $signed(`CMP_VALUE) != $unsigned(a); + + output o4_1 = $unsigned(a) <= $signed(`CMP_VALUE); + output o4_2 = $unsigned(a) < $signed(`CMP_VALUE); + output o4_3 = $unsigned(a) >= $signed(`CMP_VALUE); + output o4_4 = $unsigned(a) > $signed(`CMP_VALUE); + output o4_5 = $unsigned(a) == $signed(`CMP_VALUE); + output o4_6 = $unsigned(a) != $signed(`CMP_VALUE); + + // ######################## + + output o5_1 = $unsigned(`CMP_VALUE) <= $signed(a); + output o5_2 = $unsigned(`CMP_VALUE) < $signed(a); + output o5_3 = $unsigned(`CMP_VALUE) >= $signed(a); + output o5_4 = $unsigned(`CMP_VALUE) > $signed(a); + output o5_5 = $unsigned(`CMP_VALUE) == $signed(a); + output o5_6 = $unsigned(`CMP_VALUE) != $signed(a); + + output o6_1 = $signed(a) <= $unsigned(`CMP_VALUE); + output o6_2 = $signed(a) < $unsigned(`CMP_VALUE); + output o6_3 = $signed(a) >= $unsigned(`CMP_VALUE); + output o6_4 = $signed(a) > $unsigned(`CMP_VALUE); + output o6_5 = $signed(a) == $unsigned(`CMP_VALUE); + output o6_6 = $signed(a) != $unsigned(`CMP_VALUE); + + // ######################## + + output o7_1 = $signed(`CMP_VALUE) <= $signed(a); + output o7_2 = $signed(`CMP_VALUE) < $signed(a); + output o7_3 = $signed(`CMP_VALUE) >= $signed(a); + output o7_4 = $signed(`CMP_VALUE) > $signed(a); + output o7_5 = $signed(`CMP_VALUE) == $signed(a); + output o7_6 = $signed(`CMP_VALUE) != $signed(a); + + output o8_1 = $signed(a) <= $signed(`CMP_VALUE); + output o8_2 = $signed(a) < $signed(`CMP_VALUE); + output o8_3 = $signed(a) >= $signed(`CMP_VALUE); + output o8_4 = $signed(a) > $signed(`CMP_VALUE); + output o8_5 = $signed(a) == $signed(`CMP_VALUE); + output o8_6 = $signed(a) != $signed(`CMP_VALUE); endmodule diff --git a/tests/lut/run-test.sh b/tests/lut/run-test.sh deleted file mode 100755 index a10559cac..000000000 --- a/tests/lut/run-test.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -e -for x in *.v; do - echo "Running $x.." - ../../yosys -q -s check_map.ys -l ${x%.v}.log $x -done - -for x in map_cmp.v; do - echo "Running $x.." - ../../yosys -q -s check_map_lut6.ys -l ${x%.v}_lut6.log $x -done