Skip to content

Commit

Permalink
Support $lut cells. Both C++ and SMT tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
RCoeurjoly committed Jul 7, 2024
1 parent 3dad680 commit cc795a3
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions kernel/functionalir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
};
Expand Down

0 comments on commit cc795a3

Please sign in to comment.