add bwmux, bweqx, bmux, demux cells

This commit is contained in:
Emily Schmidt 2024-07-12 10:45:58 +01:00
parent 6e7ae88c6a
commit 9ad859fc0a
1 changed files with 56 additions and 24 deletions

View File

@ -96,6 +96,15 @@ private:
} }
return r; return r;
} }
T handle_bmux(T a, T s, int a_width, int a_offset, int width, int s_width, int sn) {
if(sn < 1)
return factory.slice(a, a_width, a_offset, width);
else {
T y0 = handle_bmux(a, s, a_width, a_offset, width, s_width, sn - 1);
T y1 = handle_bmux(a, s, a_width, a_offset + (width << (sn - 1)), width, s_width, sn - 1);
return factory.mux(y0, y1, factory.slice(s, s_width, sn - 1, 1), width);
}
}
public: public:
T handle(IdString cellType, dict<IdString, Const> parameters, dict<IdString, T> inputs) T handle(IdString cellType, dict<IdString, Const> parameters, dict<IdString, T> inputs)
{ {
@ -248,31 +257,54 @@ public:
return extend(factory.unsigned_div(a, b, width), width, y_width, false); return extend(factory.unsigned_div(a, b, width), width, y_width, false);
} }
} else if(cellType == ID($pow)) { } 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)) { } else if (cellType == ID($lut)) {
int width = parameters.at(ID(WIDTH)).as_int(); int width = parameters.at(ID(WIDTH)).as_int();
Const lut_table = parameters.at(ID(LUT)); Const lut_table = parameters.at(ID(LUT));
T a = inputs.at(ID(A)); T a = inputs.at(ID(A));
// Output initialization
// Output initialization T y = factory.constant(Const(0, 1));
T y = factory.constant(Const(0, 1)); // Iterate over each possible input combination
for (int i = 0; i < (1 << width); ++i) {
// Iterate over each possible input combination // Create a constant representing the value of i
for (int i = 0; i < (1 << width); ++i) { T i_val = factory.constant(Const(i, width));
// Create a constant representing the value of i // Check if the input matches this value
T i_val = factory.constant(Const(i, width)); T match = factory.equal(a, i_val, width);
// Check if the input matches this value // Get the corresponding LUT value
T match = factory.equal(a, i_val, width); bool lut_val = lut_table.bits[i] == State::S1;
// Get the corresponding LUT value T lut_output = factory.constant(Const(lut_val, 1));
bool lut_val = lut_table.bits[i] == State::S1; // Use a multiplexer to select the correct output based on the match
T lut_output = factory.constant(Const(lut_val, 1)); y = factory.mux(y, lut_output, match, 1);
// Use a multiplexer to select the correct output based on the match }
y = factory.mux(y, lut_output, match, 1); return y;
} } else if (cellType == ID($bwmux)) {
int width = parameters.at(ID(WIDTH)).as_int();
return y; T a = inputs.at(ID(A));
} else{ T b = inputs.at(ID(B));
log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str()); T s = inputs.at(ID(S));
return factory.bitwise_or(
factory.bitwise_and(a, factory.bitwise_not(s, width), width),
factory.bitwise_and(b, s, width), width);
} else if (cellType == ID($bweqx)) {
int width = parameters.at(ID(WIDTH)).as_int();
T a = inputs.at(ID(A));
T b = inputs.at(ID(B));
return factory.bitwise_not(factory.bitwise_xor(a, b, width), width);
} else if(cellType == ID($bmux)) {
int width = parameters.at(ID(WIDTH)).as_int();
int s_width = parameters.at(ID(S_WIDTH)).as_int();
return handle_bmux(inputs.at(ID(A)), inputs.at(ID(S)), width << s_width, 0, width, s_width, s_width);
} else if(cellType == ID($demux)) {
int width = parameters.at(ID(WIDTH)).as_int();
int s_width = parameters.at(ID(S_WIDTH)).as_int();
int y_width = width << s_width;
int b_width = ceil_log2(y_width + 1);
T a = extend(inputs.at(ID(A)), width, y_width, false);
T s = factory.extend(inputs.at(ID(S)), s_width, b_width, false);
T b = factory.mul(s, factory.constant(Const(width, b_width)), b_width);
return factory.logical_shift_left(a, b, y_width, b_width);
} else {
log_error("unhandled cell in CellSimplifier %s\n", cellType.c_str());
} }
} }
}; };