From a459eb70a9271efc472dc047198c9722445780fe Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Sun, 7 Jul 2024 23:16:34 +0200 Subject: [PATCH] bmux works for SMT, simulation fails for C++ --- kernel/functionalir.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/kernel/functionalir.cc b/kernel/functionalir.cc index 6498ef63629..eb427d2ed55 100644 --- a/kernel/functionalir.cc +++ b/kernel/functionalir.cc @@ -249,8 +249,30 @@ class CellSimplifier { } } else if(cellType == ID($pow)) { return handle_pow(inputs.at(ID(A)), a_width, inputs.at(ID(B)), b_width, y_width, a_signed && b_signed); + } else if (cellType == ID($bmux)) { + int width = parameters.at(ID(WIDTH)).as_int(); + int s_width = parameters.at(ID(S_WIDTH)).as_int(); + T a = inputs.at(ID(A)); + T s = inputs.at(ID(S)); + + // Initialize the result with the first slice of A + T result = factory.slice(a, 0, width, width); + + for (int i = 1; i < (1 << s_width); i++) { + // Compute the current slice of A + T current_slice = factory.slice(a, i * width, width, width); + + // Compute the select signal for the current slice + RTLIL::Const const_i(i, s_width); + T current_select = factory.equal(s, factory.constant(const_i), s_width); + + // Update the result based on the current select signal + result = factory.mux(result, current_slice, current_select, width); + } + + return result; } else{ - log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str()); + log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str()); } } };