@@ -248,9 +248,31 @@ class CellSimplifier {
248
248
return extend (factory.unsigned_div (a, b, width), width, y_width, false );
249
249
}
250
250
} 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;
252
274
} 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 ());
254
276
}
255
277
}
256
278
};
0 commit comments