Skip to content

Commit cc795a3

Browse files
committed
Support $lut cells. Both C++ and SMT tests pass
1 parent 3dad680 commit cc795a3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

kernel/functionalir.cc

+24-2
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,31 @@ class CellSimplifier {
248248
return extend(factory.unsigned_div(a, b, width), width, y_width, false);
249249
}
250250
} else if(cellType == ID($pow)) {
251-
return handle_pow(inputs.at(ID(A)), a_width, inputs.at(ID(B)), b_width, y_width, a_signed && b_signed);
251+
return handle_pow(inputs.at(ID(A)), a_width, inputs.at(ID(B)), b_width, y_width, a_signed && b_signed);
252+
} else if (cellType == ID($lut)) {
253+
int width = parameters.at(ID(WIDTH)).as_int();
254+
Const lut_table = parameters.at(ID(LUT));
255+
T a = inputs.at(ID(A));
256+
257+
// Output initialization
258+
T y = factory.constant(Const(0, 1));
259+
260+
// Iterate over each possible input combination
261+
for (int i = 0; i < (1 << width); ++i) {
262+
// Create a constant representing the value of i
263+
T i_val = factory.constant(Const(i, width));
264+
// Check if the input matches this value
265+
T match = factory.equal(a, i_val, width);
266+
// Get the corresponding LUT value
267+
bool lut_val = lut_table.bits[i] == State::S1;
268+
T lut_output = factory.constant(Const(lut_val, 1));
269+
// Use a multiplexer to select the correct output based on the match
270+
y = factory.mux(y, lut_output, match, 1);
271+
}
272+
273+
return y;
252274
} else{
253-
log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str());
275+
log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str());
254276
}
255277
}
256278
};

0 commit comments

Comments
 (0)