From ff53f3d2b6e267358cf4c3d08574416c79441ef9 Mon Sep 17 00:00:00 2001 From: Merry Date: Wed, 13 Dec 2023 12:02:30 +0000 Subject: [PATCH] cxxrtl: Fix value::shl --- Makefile | 1 + backends/cxxrtl/runtime/cxxrtl/cxxrtl.h | 1 + tests/cxxrtl/.gitignore | 1 + tests/cxxrtl/run-test.sh | 12 ++++++++++++ tests/cxxrtl/test_value.cc | 15 +++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 tests/cxxrtl/.gitignore create mode 100755 tests/cxxrtl/run-test.sh create mode 100644 tests/cxxrtl/test_value.cc diff --git a/Makefile b/Makefile index 8f3e473ea..8a72e3c70 100644 --- a/Makefile +++ b/Makefile @@ -888,6 +888,7 @@ endif +cd tests/verilog && bash run-test.sh +cd tests/xprop && bash run-test.sh $(SEEDOPT) +cd tests/fmt && bash run-test.sh + +cd tests/cxxrtl && bash run-test.sh @echo "" @echo " Passed \"make test\"." @echo "" diff --git a/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h b/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h index 2d5451287..635c867ae 100644 --- a/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h @@ -419,6 +419,7 @@ struct value : public expr_base> { carry = (shift_bits == 0) ? 0 : data[n] >> (chunk::bits - shift_bits); } + result.data[result.chunks - 1] &= result.msb_mask; return result; } diff --git a/tests/cxxrtl/.gitignore b/tests/cxxrtl/.gitignore new file mode 100644 index 000000000..91caee986 --- /dev/null +++ b/tests/cxxrtl/.gitignore @@ -0,0 +1 @@ +cxxrtl-test-* diff --git a/tests/cxxrtl/run-test.sh b/tests/cxxrtl/run-test.sh new file mode 100755 index 000000000..473a5a349 --- /dev/null +++ b/tests/cxxrtl/run-test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -ex + +run_subtest () { + local subtest=$1; shift + + ${CC:-gcc} -std=c++11 -o cxxrtl-test-${subtest} -I../../backends/cxxrtl/runtime test_${subtest}.cc -lstdc++ + ./cxxrtl-test-${subtest} +} + +run_subtest value diff --git a/tests/cxxrtl/test_value.cc b/tests/cxxrtl/test_value.cc new file mode 100644 index 000000000..ca05b89ab --- /dev/null +++ b/tests/cxxrtl/test_value.cc @@ -0,0 +1,15 @@ +#include +#include + +#include "cxxrtl/cxxrtl.h" + +int main() +{ + { + // shl exceeding Bits should be masked + cxxrtl::value<6> a(1u); + cxxrtl::value<6> b(8u); + cxxrtl::value<6> c = a.shl(b); + assert(c.get() == 0); + } +} \ No newline at end of file