From 449e3dbbd361b13e56f19b5ee8250c5bb7a2e283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Wed, 13 Dec 2023 18:21:37 +0100 Subject: [PATCH] cxxrtl: Mask `bmux` result appropriately --- backends/cxxrtl/runtime/cxxrtl/cxxrtl.h | 1 + tests/cxxrtl/test_value.cc | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h b/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h index d861b7e07..78dbf3707 100644 --- a/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h @@ -475,6 +475,7 @@ struct value : public expr_base> { carry = (shift_bits == 0) ? 0 : data[result.chunks + shift_chunks - 1 - n] << (chunk::bits - shift_bits); } + result.data[result.chunks - 1] &= result.msb_mask; return result; } diff --git a/tests/cxxrtl/test_value.cc b/tests/cxxrtl/test_value.cc index 4d68372bb..0750d412e 100644 --- a/tests/cxxrtl/test_value.cc +++ b/tests/cxxrtl/test_value.cc @@ -42,4 +42,11 @@ int main() cxxrtl::value<32> a(0x00040000u); assert(a.ctlz() == 13); } + + { + // bmux clears top bits of result + cxxrtl::value<8> val(0x1fu); + cxxrtl::value<1> sel(0u); + assert(val.template bmux<4>(sel).get() == 0xfu); + } }