From cc795a3f50c71960cf3e7cf365ce729def51aa41 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Mon, 8 Jul 2024 00:07:07 +0200 Subject: [PATCH] Support $lut cells. Both C++ and SMT tests pass --- kernel/functionalir.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/kernel/functionalir.cc b/kernel/functionalir.cc index 6498ef63629..c5406f41283 100644 --- a/kernel/functionalir.cc +++ b/kernel/functionalir.cc @@ -248,9 +248,31 @@ class CellSimplifier { return extend(factory.unsigned_div(a, b, width), width, y_width, false); } } 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); + 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($lut)) { + int width = parameters.at(ID(WIDTH)).as_int(); + Const lut_table = parameters.at(ID(LUT)); + T a = inputs.at(ID(A)); + + // Output initialization + T y = factory.constant(Const(0, 1)); + + // Iterate over each possible input combination + for (int i = 0; i < (1 << width); ++i) { + // Create a constant representing the value of i + T i_val = factory.constant(Const(i, width)); + // Check if the input matches this value + T match = factory.equal(a, i_val, width); + // Get the corresponding LUT value + bool lut_val = lut_table.bits[i] == State::S1; + T lut_output = factory.constant(Const(lut_val, 1)); + // Use a multiplexer to select the correct output based on the match + y = factory.mux(y, lut_output, match, 1); + } + + return y; } else{ - log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str()); + log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str()); } } };