Skip to content

Commit

Permalink
wreduce: Adjust naming and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
povik committed Jan 3, 2025
1 parent 0877891 commit be35188
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions passes/opt/wreduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ struct WreduceWorker
bool port_a_signed = false;
bool port_b_signed = false;

// Under certain conditions we are free to choose the signedness of the operands
// For some operations if the output is no wider than either of the inputs
// we are free to choose the signedness of the operands
if (cell->type.in(ID($mul), ID($add), ID($sub)) &&
max_port_a_size == GetSize(sig) &&
max_port_b_size == GetSize(sig)) {
Expand All @@ -318,24 +319,24 @@ struct WreduceWorker
sig_a.extend_u0(max_port_a_size);
sig_b.extend_u0(max_port_b_size);

int signed_size, unsigned_size;
int signed_cost, unsigned_cost;
if (cell->type == ID($mul)) {
signed_size = reduced_opsize(sig_a, true) * reduced_opsize(sig_b, true);
unsigned_size = reduced_opsize(sig_a, false) * reduced_opsize(sig_b, false);
signed_cost = reduced_opsize(sig_a, true) * reduced_opsize(sig_b, true);
unsigned_cost = reduced_opsize(sig_a, false) * reduced_opsize(sig_b, false);
} else {
signed_size = max(reduced_opsize(sig_a, true), reduced_opsize(sig_b, true));
unsigned_size = max(reduced_opsize(sig_a, false), reduced_opsize(sig_b, false));
signed_cost = max(reduced_opsize(sig_a, true), reduced_opsize(sig_b, true));
unsigned_cost = max(reduced_opsize(sig_a, false), reduced_opsize(sig_b, false));
}

if (!port_a_signed && !port_b_signed && signed_size < unsigned_size) {
if (!port_a_signed && !port_b_signed && signed_cost < unsigned_cost) {
log("Converting cell %s.%s (%s) from unsigned to signed.\n",
log_id(module), log_id(cell), log_id(cell->type));
cell->setParam(ID::A_SIGNED, 1);
cell->setParam(ID::B_SIGNED, 1);
port_a_signed = true;
port_b_signed = true;
did_something = true;
} else if (port_a_signed && port_b_signed && unsigned_size < signed_size) {
} else if (port_a_signed && port_b_signed && unsigned_cost < signed_cost) {
log("Converting cell %s.%s (%s) from signed to unsigned.\n",
log_id(module), log_id(cell), log_id(cell->type));
cell->setParam(ID::A_SIGNED, 0);
Expand Down

0 comments on commit be35188

Please sign in to comment.