Skip to content

Commit

Permalink
cost: saturating add
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Tywoniak authored and Emil Tywoniak committed Apr 18, 2024
1 parent 2c930d2 commit 63b4a20
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/cost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ int CellCosts::get(RTLIL::Module *mod)
return mod_cost_cache_.at(mod->name);

int module_cost = 1;
for (auto c : mod->cells())
module_cost += get(c);
for (auto c : mod->cells()) {
int new_cost = module_cost + get(c);
module_cost = new_cost >= module_cost ? new_cost : INT_MAX;
}

mod_cost_cache_[mod->name] = module_cost;
return module_cost;
Expand Down

0 comments on commit 63b4a20

Please sign in to comment.