3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-07-15 03:35:40 +00:00

stat bugfix

This commit is contained in:
Akash Levy 2026-06-28 20:28:23 -07:00
parent d0380bf8f0
commit 77cd9e1edc
2 changed files with 52 additions and 4 deletions

View file

@ -772,13 +772,17 @@ statdata_t hierarchy_builder(const RTLIL::Design *design, const RTLIL::Module *t
mod_data.local_area_cells_by_type.erase(cell->type);
} else {
// deal with blackbox cells
// The read_liberty/read_liberty2json frontends store the cell
// area as a string attribute, so parse it as a floating point
// value rather than reinterpreting the raw attribute bits.
if (design->module(cell->type)->attributes.count(ID::area) &&
design->module(cell->type)->attributes.at(ID::area).size() == 0) {
design->module(cell->type)->attributes.at(ID::area).size() != 0) {
double blackbox_area =
atof(design->module(cell->type)->attributes.at(ID::area).decode_string().c_str());
mod_data.num_submodules_by_type[cell->type]++;
mod_data.num_submodules++;
mod_data.submodules_area_by_type[cell->type] +=
double(design->module(cell->type)->attributes.at(ID::area).as_int());
mod_data.area += double(design->module(cell->type)->attributes.at(ID::area).as_int());
mod_data.submodules_area_by_type[cell->type] += blackbox_area;
mod_data.area += blackbox_area;
mod_data.unknown_cell_area.erase(cell->type);
mod_data.num_cells -=
(mod_data.num_cells_by_type.count(cell->type) != 0) ? mod_data.num_cells_by_type.at(cell->type) : 0;

View file

@ -0,0 +1,44 @@
# Regression test: `stat` must account for the area of blackbox cells whose
# area comes from the module's `area` attribute (rather than from a `-liberty`
# file passed to `stat` itself).
#
# Both the `read_liberty` (-lib) and `read_liberty2json` frontends attach the
# cell area to the blackbox module as a STRING attribute:
# frontends/liberty/liberty.cc: module->attributes[ID::area] = area->value; // raw liberty string, e.g. "1.500000"
# passes/silimate/l2j_frontend.cc: set_string_attribute(ID(area), std::to_string(area)); // e.g. "1.500000"
#
# The blackbox-area branch in stat.cc's hierarchy_builder() previously guarded
# on `attributes.at(ID::area).size() == 0` and read the value with `.as_int()`.
# A string-valued area Const has size() != 0, so the branch never ran, and even
# if it had, `.as_int()` reinterprets the raw bits instead of parsing "1.5".
# The fix guards on size() != 0 and parses the string area as a double.
#
# This test recreates exactly what the frontends produce (a blackbox module
# with a string `area` attribute) and checks that stat counts it. `-hierarchy`
# is used because the blackbox-area branch accounts the cell as a submodule,
# and only the hierarchical view reports submodule area.
read_rtlil << EOT
attribute \blackbox 1
attribute \area "1.500000"
module \blackbox_cell
wire input 1 \A
wire output 2 \Y
end
module \top
wire input 1 \A
wire output 2 \Y
cell \blackbox_cell \inst
connect \A \A
connect \Y \Y
end
end
EOT
# The single blackbox instance has area 1.5, so the top module's hierarchical
# chip area must be 1.5, reported as one submodule.
logger -expect log "Chip area for module '\\top': 1.500000" 1
logger -expect log "1.5.*blackbox_cell" 1
logger -expect-no-warnings
stat -hierarchy