@@ -14,69 +14,67 @@ USING_YOSYS_NAMESPACE
1414PRIVATE_NAMESPACE_BEGIN
1515
1616struct ArithStats : public Pass {
17- ArithStats ()
18- : Pass(" arith_stats" ,
19- " Print out information about arithmetic operators in design." ) {}
17+ ArithStats () : Pass(" arith_stats" , " Print out information about arithmetic operators in design." ) {}
2018
21- void help () override {
22- // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
23- log (" \n " );
24- log (" arith_stats\n " );
25- log (" \n " );
26- log (" Print out information about arithmetic operators in design.\n " );
27- log (" \n " );
28- }
19+ void help () override
20+ {
21+ // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
22+ log (" \n " );
23+ log (" arith_stats\n " );
24+ log (" \n " );
25+ log (" Print out information about arithmetic operators in design.\n " );
26+ log (" \n " );
27+ }
2928
30- void execute (std::vector<std::string> args, RTLIL::Design *design) override {
31- (void )args; // no args / not used
32- log (" Executing 'arith_stats' command." );
33- for (const RTLIL::Module *module : design->selected_modules ()) {
34- std::map<RTLIL::IdString, std::map<int , int >> histos_by_type;
35- std::map<RTLIL::IdString, int > tot_counts;
29+ void execute (std::vector<std::string> args, RTLIL::Design *design) override
30+ {
31+ (void )args; // no args / not used
32+ log (" Executing 'arith_stats' command." );
33+ for (const RTLIL::Module *module : design->selected_modules ()) {
34+ std::map<RTLIL::IdString, std::map<int , int >> histos_by_type;
35+ std::map<RTLIL::IdString, int > tot_counts;
3636
37- // === COLLECT data for this module
38- for (const RTLIL::Cell *cell : module ->selected_cells ()) {
39- if (!cell->type .in (ID ($add), ID ($sub), ID ($neg), ID ($alu), ID ($fa),
40- ID ($macc), ID ($mul), ID ($div), ID ($lt), ID ($le),
41- ID ($gt), ID ($ge))) {
42- continue ;
43- }
37+ // === COLLECT data for this module
38+ for (const RTLIL::Cell *cell : module ->selected_cells ()) {
39+ if (!cell->type .in (ID ($add), ID ($sub), ID ($neg), ID ($alu), ID ($fa), ID ($macc), ID ($mul), ID ($div), ID ($lt), ID ($le), ID ($gt),
40+ ID ($ge))) {
41+ continue ;
42+ }
4443
45- // Get the width of the arith cell
46- int width = 0 ;
47- if (cell->type .in (ID ($fa))) {
48- width = std::max (width, cell->parameters .at (ID::WIDTH).as_int ());
49- } else {
50- width = std::max (width, cell->parameters .at (ID::A_WIDTH).as_int ());
51- if (!cell->type .in (ID ($neg))) {
52- width = std::max (width, cell->parameters .at (ID::B_WIDTH).as_int ());
53- }
54- width = std::max (width, cell->parameters .at (ID::Y_WIDTH).as_int ());
55- }
44+ // Get the width of the arith cell
45+ int width = 0 ;
46+ if (cell->type .in (ID ($fa))) {
47+ width = std::max (width, cell->parameters .at (ID::WIDTH).as_int ());
48+ } else {
49+ width = std::max (width, cell->parameters .at (ID::A_WIDTH).as_int ());
50+ if (!cell->type .in (ID ($neg))) {
51+ width = std::max (width, cell->parameters .at (ID::B_WIDTH).as_int ());
52+ }
53+ width = std::max (width, cell->parameters .at (ID::Y_WIDTH).as_int ());
54+ }
5655
57- // update total counts by type
58- const auto typ = cell->type ;
59- tot_counts[typ] = (tot_counts.count (typ) ? tot_counts[typ] : 0 ) + 1 ;
56+ // update total counts by type
57+ const auto typ = cell->type ;
58+ tot_counts[typ] = (tot_counts.count (typ) ? tot_counts[typ] : 0 ) + 1 ;
6059
61- // update width historgram
62- auto &histo = histos_by_type[typ];
63- histo[width] = (histo.count (width) ? histo[width] : 0 ) + 1 ;
64- }
60+ // update width historgram
61+ auto &histo = histos_by_type[typ];
62+ histo[width] = (histo.count (width) ? histo[width] : 0 ) + 1 ;
63+ }
6564
66- // === DISPLAY info for this module
67- if (!histos_by_type.empty ()) {
68- log (" \n Counting arithmetic cells in module %s:\n " ,
69- module ->name .c_str ());
70- }
71- for (const auto &[typ, histo] : histos_by_type) {
72- log (" \n %s: total %d instances\n " , typ.c_str (), tot_counts[typ]);
73- log (" %10s : %-10s\n " , " bitwidth" , " count" );
74- for (const auto &[width, count] : histo) {
75- log (" %10d : %-10d\n " , width, count);
65+ // === DISPLAY info for this module
66+ if (!histos_by_type.empty ()) {
67+ log (" \n Counting arithmetic cells in module %s:\n " , module ->name .c_str ());
68+ }
69+ for (const auto &[typ, histo] : histos_by_type) {
70+ log (" \n %s: total %d instances\n " , typ.c_str (), tot_counts[typ]);
71+ log (" %10s : %-10s\n " , " bitwidth" , " count" );
72+ for (const auto &[width, count] : histo) {
73+ log (" %10d : %-10d\n " , width, count);
74+ }
75+ }
7676 }
77- }
7877 }
79- }
8078};
8179
8280static struct ArithStats *instance = new struct ArithStats ();
0 commit comments