From a7b3cbd15c9c6e94eed532afc41612a5829ad82e Mon Sep 17 00:00:00 2001 From: cl-liao <2357605737@qq.com> Date: Sun, 23 Apr 2023 18:25:58 -0700 Subject: [PATCH 1/3] new submit --- src/commands/ps2.hpp | 508 +++++++++++++++++++++++++++++++++++ src/core/ps2_implemented.hpp | 332 +++++++++++++++++++++++ 2 files changed, 840 insertions(+) create mode 100644 src/commands/ps2.hpp create mode 100644 src/core/ps2_implemented.hpp diff --git a/src/commands/ps2.hpp b/src/commands/ps2.hpp new file mode 100644 index 0000000..cea95ed --- /dev/null +++ b/src/commands/ps2.hpp @@ -0,0 +1,508 @@ +/* also: Advanced Logic Synthesis and Optimization tool + * Copyright (C) 2019- Ningbo University, Ningbo, China */ + +/** + * @file fanin_histogram.hpp + * + * @brief statistic fanin_histogram + * + * @author Chunliu Liao + * @since 0.1 + */ + +#ifndef PS2 +#define PS2 +#include +#include +#include <../core/ps2_ implemented.hpp> +namespace alice{ + using namespace mockturtle; + class ps2_command : public command{ + public: + explicit ps2_command(const environment::ptr &env) + :command(env,"Show statistics in the stored network."){ + add_flag("--aig,-a", "Display stats for stored AIG"); + add_flag("--mig,-m", "Display stats for stored MIG"); + add_flag("--xag,-x", "Display stats for stored XAG"); + add_flag("--xmg,-g", "Display stats for stored XMG"); + add_flag("--criti,-c","Display critical path node index and gate"); + add_flag("--fanout,-f","Display fanout histogram"); + add_flag("--cone,-o","Dispaly logic cones from PO to PI(only for AIG)"); + add_flag("--level,-l","Display level histigram"); + add_flag("--skip,-k","Display skip histogram"); + } + + template + void dump_stats(std::string name){ + if ( store().empty() ) + { + env->err() << name << " network not stored\n"; + return; + } + auto ntk = store().current(); + mockturtle::depth_view dag_depth{ntk}; + + /*critical_path*/ + also::critical_node_view> critical{ ntk }; + auto critical_path = critical.get_critical_path(); + auto critical_nums = critical.get_critical_nums(); + // also::function_counts counts = also::node_functions(ntk); + also::function_counts counts; + for ( auto curr_node : critical_path ) + { + update_counts( counts, ntk, curr_node ); + } + + /*fanin_histogram*/ + mockturtle::fanout_view fanout{ ntk }; + uint32_t times = 0; + fanout.foreach_node( [&]( auto node ) + { + bool pure = true; + fanout.foreach_fanin(node,[&](auto fi){ + uint32_t focount = 0; + auto node = fanout.get_node(fi); + fanout.foreach_fanout(node,[&](auto fo){ + focount++; + }); + bool isolated_fanin = (focount == 1)? 1 : 0; + pure = pure && (fanout.is_constant(node) || isolated_fanin); + }); + if (!pure) + times++; } ); + + /*fanout_histogram*/ + //mockturtle::fanout_view fanout{ ntk }; + std::vector fanout_histogram( 33, 0 ); + std::vector fanout_vec; + int max_fanout = 0; + double average_fanout = 0; + fanout.foreach_node( [&]( auto node ) + { + uint32_t foc = 0; + fanout.foreach_fanout(node,[&](auto fo){ + foc++; + }); + fanout_vec.emplace_back(foc); + if (foc > max_fanout){ + max_fanout = foc; + } + if (foc >= fanout_histogram.size() - 1){ + fanout_histogram[fanout_histogram.size() - 1]++; + } + else { + fanout_histogram[foc]++; + } } ); + average_fanout = std::accumulate(fanout_vec.begin(),fanout_vec.end(),0.0,[](double acc,int i){return acc + static_cast(i);}) / fanout_vec.size(); + // for ( int i = 0; i < fanout_histogram.size() - 1; i++ ) + // { + // env->out() << i << "\t" << fanout_histogram[i] << std::endl; + // } + // env->out() << ">=" << ( fanout_histogram.size() - 1 ) << "\t" + // << fanout_histogram[fanout_histogram.size() - 1] << std::endl; + + /*function_stats*/ + also::function_counts counts1 = also::node_functions(ntk); + + /*get_cones*/ + + /*skip_histogram*/ + + std::vector skip_histogram( dag_depth.depth(), 0 ); + uint32_t mismatch_levels = 0; + fanout.foreach_node( [&]( auto node ){ + uint32_t last_level = 0; + bool mismatched = false; + fanout.foreach_fanout(node,[&](auto f){ + if (last_level != 0 && last_level != dag_depth.level(f)){ + mismatched = true; + } + last_level = dag_depth.level(f); + uint32_t skip = dag_depth.level(f) - dag_depth.level(node); + skip_histogram[skip]++; + }); + if (mismatched){ + mismatch_levels++; + } } ); + int max_skip = 0; + double average_skip = 0.0; + double dividend = 0.0; + double divisor = 0.0; + // env->out() << "Nodes whose fanout skip levels\t" << mismatch_levels << std::endl; + // env->out() << "Skip Levels\tNodes" << std::endl; + for ( int i = 0; i < skip_histogram.size(); i++ ) + { + dividend += i*skip_histogram[i]; + divisor += skip_histogram[i]; + } + average_skip = dividend / divisor; + max_skip = skip_histogram.size() - 1; + + env->out() << "*******************************************************************************\n" + << "* Statistic information *\n" + << "*******************************************************************************\n" + << std::setw( 2 ) << std::left << " " << std::setw( 70 ) << std::left << "Total size of critical path nodes : " << std::setw( 5 ) << std::left << critical_path.size() << "\n" + << std::setw( 2 ) << std::left << " " << std::setw( 70 ) << std::left << "Number of critical paths : " << std::setw( 5 ) << std::left << critical_nums << "\n" + << std::setw( 2 ) << std::left << " " << std::setw( 70 ) << std::left << "Number of pure nodes(at least one child node has multiple fanouts) : " << std::setw( 5 ) << std::left << times << "\n" + << "-------------------------------------------------------------------------------\n" + << " +Node fanout : " + << "\n" + << std::setw( 3 ) << std::left << " " + << "| Max Fanout | = " << max_fanout << std::setw( 10 ) << " " + << "| Average Fanout | = " << average_fanout << "\n" + << "-------------------------------------------------------------------------------\n" + << " +Function_statistic : " + << "\n"; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 61 ) << "" << std::setfill( ' ' ) << std::endl; + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 4 ) << "Name" + << " |" << std::setw( 4 ) << "MAJ" + << " |" << std::setw( 4 ) << "AND" + << " |" << std::setw( 4 ) << "OR" + << " |" << std::setw( 4 ) << "XOR3" + << " |" << std::setw( 4 ) << "XOR" + << " |" << std::setw( 4 ) << "XNOR" + << " |" << std::setw( 7 ) << "Unknown" + << " |" << std::setw( 7 ) << "Input" + << " |" << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 61 ) << "" << std::setfill( ' ' ) << std::endl; + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 4 ) << "nums" + << " |" << std::setw( 4 ) << ( counts1.maj_num == 0 ? " / " : std::to_string( counts1.maj_num ) ) << " |" << std::setw( 4 ) << ( counts1.and_num == 0 ? " /" : std::to_string( counts1.and_num ) ) << " |" << std::setw( 4 ) << ( counts1.or_num == 0 ? " /" : std::to_string( counts1.or_num ) ) << " |" << std::setw( 4 ) << ( counts1.xor3_num == 0 ? " /" : std::to_string( counts1.xor3_num ) ) << " |" << std::setw( 4 ) << ( counts1.xor_num == 0 ? " /" : std::to_string( counts1.xor_num ) ) << " |" << std::setw( 4 ) << ( counts1.xnor_num == 0 ? " /" : std::to_string( counts1.xnor_num ) ) << " |" << std::setw( 7 ) << ( counts1.unknown_num == 0 ? " /" : std::to_string( counts1.unknown_num ) ) << " |" << std::setw( 7 ) << ( counts1.input_num == 0 ? " /" : std::to_string( counts1.input_num ) ) << " |" << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 61 ) << "" << std::setfill( ' ' ) << std::endl; + std::cout<<"-------------------------------------------------------------------------------\n"; + std::cout << " +Skip level : " + << "\n" + << " | Number of nodes with inconsistent levels of fanout nodes(skip) : "< + void critical_path(std::string name) + { + if ( store().empty() ) + return; + auto ntk = store().current(); + also::critical_node_view> c{ntk}; + auto cp = c.get_critical_path(); + also::function_counts cou; + for (auto it : cp){ + update_counts(cou,ntk,it); + } + std::cout << " +Node in critical paths : "<< "\n"; + for (auto it : cp){ + std::cout< + void fanout_histogram(std::string name){ + if ( store().empty() ) + return; + auto ntk = store().current(); + mockturtle::fanout_view fanoutP{ntk}; + int max_fanout = 0; + std::vector fanout_histogram( 33, 0 ); + fanoutP.foreach_node( [&]( auto node ) + { + uint32_t foc = 0; + fanoutP.foreach_fanout(node,[&](auto fo){ + foc++; + }); + if ( foc > max_fanout ) + { + max_fanout = foc; + } + if (foc >= fanout_histogram.size() - 1){ + fanout_histogram[fanout_histogram.size() - 1]++; + } + else { + fanout_histogram[foc]++; + } } ); + std::vector fanout_histogram1( fanout_histogram.begin(), fanout_histogram.begin() + max_fanout + 1 ); + std::cout << " +Node counts by number of fanouts." << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 10 ) << "Fanout" + << std::right << " | " << std::setw( 5 ) << "Nodes" + << " |" << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + for ( int i = 0; i < fanout_histogram1.size(); i++ ) + { + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 10 ) << i + << std::right << " | " << std::setw( 5 ) << fanout_histogram1[i] + << " |" << std::endl; + } + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + } + template + void get_cones(std::string name){ + if ( !store().empty() ) + { + auto aig = store().current(); + // map with number of nodes in each logical cone + std::unordered_map po_nodes; + // number of inputs for each cone + std::unordered_map po_ins; + // first processing logical cones for POs + std::cout << " +Logic cones from PO2PI." << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 44 ) << "" << std::setfill( ' ' ) << std::endl; + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 10 ) << "Name" + << std::right << " | " << std::setw( 5 ) << "Index" + << " |" << std::setw( 5 ) << "Nodes" + << " |" << std::setw( 5 ) << "Level" + << " |" << std::setw( 6 ) << "Inputs" + << " |" << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 44 ) << "" << std::setfill( ' ' ) << std::endl; + for ( int outIndex = 0; outIndex < aig.num_pos(); outIndex++ ) + { + aig.foreach_node( [&]( auto node ) + { + //set all nodes as not visited + aig._storage->nodes[node].data[1].h1 = 0; } ); + // start counter for a given output index + po_nodes.insert( std::make_pair( outIndex, 0 ) ); + // starting the counter of inputs + po_ins.insert( std::make_pair( outIndex, 0 ) ); + // calculate the index of the node driving the output + auto inIdx = aig._storage->outputs[outIndex].data; + if ( aig._storage->outputs[outIndex].data & 1 ) + { + inIdx = aig._storage->outputs[outIndex].data - 1; + } + inIdx = inIdx >> 1; + // call DFS + also::compute_cone( aig, inIdx, po_nodes, outIndex, po_ins ); + aig.foreach_node( [&]( auto node ) + { + //set all nodes as not visited + aig._storage->nodes[node].data[1].h1 = 0; } ); + + int level = also::computeLevel( aig, inIdx ); + int nodes = 0; + int inputs = 0; + + // for each output prints index, nodes, depth and number of inputs, respectively + std::unordered_map::iterator it; + it = po_nodes.find( outIndex ); + + if ( it != po_nodes.end() ) + nodes = it->second; + + std::unordered_map::iterator init; + init = po_ins.find( outIndex ); + + if ( it != po_ins.end() ) + inputs = init->second; + + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 10 ) << "Output" + << std::right << " | " << std::setw( 5 ) << outIndex + << " |" << std::setw( 5 ) << nodes + << " |" <err() << "There is not an AIG network stored.\n"; + } + } + template + void level_size(std::string name ){ + if ( store().empty() ) + { + env->err() << name << " network not stored\n"; + return; + } + auto dag = store().current(); + mockturtle::depth_view dag_view( dag ); + std::vector levels( dag_view.depth() + 1, 0 ); + dag_view.foreach_node( [&]( auto node ) + { levels[dag_view.level( node )]++; } ); + std::cout << " +Nodes per level." << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 10 ) << "Level" + << std::right << " | " << std::setw( 5 ) << "Nodes" + << " |" << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + for ( int i = 0; i < levels.size(); i++ ) + { + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 10 ) << i + << std::right << " | " << std::setw( 5 ) << levels[i] + << " |" << std::endl; + } + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + } + template + void skip_histogram(std::string name){ + if ( !store().empty() ) + { + auto dag = store().current(); + mockturtle::depth_view dag_depth{ dag }; + mockturtle::fanout_view dag_fanout{ dag }; + std::vector skip_histogram( dag_depth.depth(), 0 ); + uint32_t mismatch_levels = 0; + dag_fanout.foreach_node( [&]( auto node ) + { + uint32_t last_level = 0; + bool mismatched = false; + dag_fanout.foreach_fanout(node,[&](auto f){ + if (last_level != 0 && last_level != dag_depth.level(f)){ + mismatched = true; + } + last_level = dag_depth.level(f); + uint32_t skip = dag_depth.level(f) - dag_depth.level(node); + skip_histogram[skip]++; + }); + if (mismatched){ + mismatch_levels++; + } } ); + + std::cout<< " +Nodes whose fanout skip levels : " << mismatch_levels << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 11 ) << "Skip_levels" + << std::right << " | " << std::setw( 5 ) << "Nodes" + << " |" << std::endl; + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + for ( int i = 0; i < skip_histogram.size(); i++ ) + { + std::cout << std::setw( 3 ) << " " + << "| " << std::left << std::setw( 11 ) << i + << std::right << " | " << std::setw( 5 ) << skip_histogram[i] + << " |" << std::endl; + } + std::cout << std::setw( 3 ) << " " << std::setfill( '-' ) << std::setw( 22 ) << "" << std::setfill( ' ' ) << std::endl; + } + else + { + env->err() << "There is not an " << name << " network stored.\n"; + } + } + + protected: + void execute() + { + if ( is_set( "mig" ) ) + { + dump_stats( "MIG" ); + if ( is_set( "criti" ) ) + { + critical_path( "MIG" ); + } + if ( is_set( "fanout" ) ) + { + fanout_histogram( "MIG" ); + } + if ( is_set( "level" ) ) + { + level_size( "MIG" ); + } + if ( is_set( "skip" ) ) + { + skip_histogram( "MIG" ); + } + return; + } + else if ( is_set( "xag" ) ) + { + dump_stats( "XAG" ); + if ( is_set( "criti" ) ) + { + critical_path( "XAG" ); + } + if ( is_set( "fanout" ) ) + { + fanout_histogram( "XAG" ); + } + if ( is_set( "level" ) ) + { + level_size( "XAG" ); + } + if ( is_set( "skip" ) ) + { + skip_histogram( "XAG" ); + } + return; + } + else if ( is_set( "xmg" ) ) + { + dump_stats( "XMG" ); + if ( is_set( "criti" ) ) + { + critical_path( "XMG" ); + } + if ( is_set( "fanout" ) ) + { + fanout_histogram( "XMG" ); + } + if ( is_set( "level" ) ) + { + level_size( "XMG" ); + } + if ( is_set( "skip" ) ) + { + skip_histogram( "XMG" ); + } + return; + } + else if ( is_set( "aig" ) ) + { + dump_stats( "AIG" ); + // if (is_set("criti")){ + // critical_path("AIG"); + // } + } + if ( is_set( "criti" ) ) + { + critical_path( "AIG" ); + } + if ( is_set( "fanout" ) ) + { + fanout_histogram( "AIG" ); + } + if (is_set("cone")){ + get_cones( "AIG" ); + } + if (is_set("level")){ + level_size( "AIG" ); + } + if (is_set("skip")){ + skip_histogram( "AIG" ); + } + // std::cout<<"You need to pass in parameters to display information, for example : ps2 -a."< +#include +#include +#include +namespace also +{ +using aig_names = mockturtle::names_view; +using mig_names = mockturtle::names_view; +using xag_names = mockturtle::names_view; +using xmg_names = mockturtle::names_view; + +struct function_counts +{ + int maj_num = 0; + int xor_num = 0; + int xnor_num = 0; + int xor3_num = 0; + int and_num = 0; + int or_num = 0; + int input_num = 0; + int unknown_num = 0; +}; +enum reconfig_function +{ + AND, + OR, + XOR, + XNOR, + XOR3, + MAJ, + INPUT, + UNKNOWN +}; +template +reconfig_function node_function( const network& ntk, const typename network::node& node ) +{ + + if ( ntk.is_pi( node ) || ntk.is_constant( node ) ) + { + return reconfig_function::INPUT; + } + else if ( ntk.is_and( node ) ) + { + return reconfig_function::AND; + } + else if ( ntk.is_or( node ) ) + { + return reconfig_function::OR; + } + else if ( ntk.is_xor( node ) ) + { + return reconfig_function::XOR; + } + else if ( ntk.is_maj( node ) ) + { + typename network::signal first_signal = ntk._storage->nodes[node].children[0]; + typename network::node first_fanin = ntk.get_node( first_signal ); + + if ( ntk.is_constant( first_fanin ) ) + { + if ( first_signal.complement ) + { + return reconfig_function::OR; + } + else + { + return reconfig_function::AND; + } + } + else + { + return reconfig_function::MAJ; + } + } + else if ( ntk.is_xor3( node ) ) + { + typename network::signal first_signal = ntk._storage->nodes[node].children[0]; + typename network::node first_fanin = ntk.get_node( first_signal ); + if ( ntk.is_constant( first_fanin ) ) + { + if ( first_signal.complement ) + { + return reconfig_function::XNOR; + } + else + { + return reconfig_function::XOR; + } + } + else + { + return reconfig_function::XOR3; + } + } + else + { + return reconfig_function::UNKNOWN; + } +} +template +void update_counts( function_counts& counts, const network& ntk, const typename network::node& node ) +{ + reconfig_function func = node_function( ntk, node ); + switch ( func ) + { + case AND: + counts.and_num++; + break; + case OR: + counts.or_num++; + break; + case XOR: + counts.xor_num++; + break; + case XNOR: + counts.xnor_num++; + break; + case XOR3: + counts.xor3_num++; + break; + case MAJ: + counts.maj_num++; + break; + case INPUT: + counts.input_num++; + break; + case UNKNOWN: + default: + counts.unknown_num++; + } +} +// template void update_counts( function_counts&, const aig_names&, const typename aig_names::node& ); +// template void update_counts( function_counts&, const mig_names&, const typename mig_names::node& ); +// template void update_counts( function_counts&, const xmg_names&, const typename xmg_names::node& ); +// template void update_counts( function_counts&, const xag_names&, const typename xag_names::node& ); +template +function_counts node_functions( const network& ntk ) +{ + function_counts counts; + ntk.foreach_node( [&]( auto node ) + { update_counts( counts, ntk, node ); } ); + return counts; +} +// template function_counts node_functions( const mig_names& ); +// template function_counts node_functions( const xmg_names& ); +// template function_counts node_functions( const aig_names& ); +// template function_counts node_functions( const xag_names& ); +template +class critical_node_view : public Ntk +{ +public: + using storage = typename Ntk::storage; + using node = typename Ntk::node; + using signal = typename Ntk::signal; + +public: + critical_node_view() {} + explicit critical_node_view( Ntk const& ntk ) : Ntk( ntk ), ntk( ntk ) + { + int depth = depth_ntk.depth(); + depth_ntk.clear_visited(); + nums_criti = 0; + depth_ntk.foreach_po( [&]( auto const& po, auto i ) + { + node pon = depth_ntk.get_node(po); + if (depth_ntk.level(pon) != depth) + return; + nums_criti++; + recursive(pon,critical_path,i); } ); + } + std::vector recursive( node& n, std::vector& critical, int i ) + { + if ( depth_ntk.visited( n ) != 0 ) + return critical; + depth_ntk.set_visited( n, i + 1 ); + critical.emplace_back( n ); + depth_ntk.foreach_fanin( n, [&]( auto fi ) + { + node fin = depth_ntk.get_node(fi); + int level = depth_ntk.level(n); + if (depth_ntk.level(fin) == level - 1){ + recursive(fin,critical,i); + } } ); + return critical; + } + std::vector get_critical_path() + { + return critical_path; + } + uint32_t get_critical_nums() + { + return nums_criti; + } + +private: + uint32_t nums_criti; + std::vector critical_path; + Ntk const& ntk; + mockturtle::depth_view depth_ntk{ ntk }; +}; +static void compute_cone( mockturtle::aig_network aig, uint64_t index, std::unordered_map& nodes, int outindex, std::unordered_map& ins ) +{ + if ( aig._storage->nodes[index].data[1].h1 == 0 ) + { + + // increment number of nodes in this cone + std::unordered_map::iterator it = nodes.find( outindex ); + + if ( it != nodes.end() && index > aig.num_pis() ) + { + // increment the number of nodes + it->second++; + } + + // set node as visited + aig._storage->nodes[index].data[1].h1 = 1; + + // traverse one side to the PIs + if ( !aig.is_pi( aig._storage->nodes[index].children[0].index ) && index > aig.num_pis() ) + { + if ( aig._storage->nodes[index].children[0].data & 1 ) + aig._storage->nodes[index].children[0].data = + aig._storage->nodes[index].children[0].data - 1; + + // calculate input node index + auto inIndex = aig._storage->nodes[index].children[0].data >> 1; + + // im ignoring latches + if ( inIndex > aig.num_pis() ) + { + // call recursion + compute_cone( aig, inIndex, nodes, outindex, ins ); + } + } + + // traverse the other side to the PIs + if ( !aig.is_pi( aig._storage->nodes[index].children[1].index ) && index > aig.num_pis() ) + { + if ( aig._storage->nodes[index].children[1].data & 1 ) + aig._storage->nodes[index].children[1].data = + aig._storage->nodes[index].children[1].data - 1; + + // calculate input node index + auto inIndex = aig._storage->nodes[index].children[1].data >> 1; + + // im ignoring latches + if ( inIndex > aig.num_pis() ) + { + // call recursion + compute_cone( aig, inIndex, nodes, outindex, ins ); + } + } + + // if my child is PI and was not visited yet, I increase the input counter + if ( aig.is_ci( aig._storage->nodes[index].children[0].index ) && aig._storage->nodes[aig._storage->nodes[index].children[0].index].data[1].h1 == 0 ) + { + aig._storage->nodes[aig._storage->nodes[index].children[0].index].data[1].h1 = + 1; + + std::unordered_map::iterator it = ins.find( outindex ); + if ( it != ins.end() ) + { + // increment the number of inputs + it->second++; + } + } + + // if my other child is PI and was not visited yet, I also increase the input counter + if ( aig.is_ci( aig._storage->nodes[index].children[1].index ) && aig._storage->nodes[aig._storage->nodes[index].children[1].index].data[1].h1 == 0 ) + { + aig._storage->nodes[aig._storage->nodes[index].children[1].index].data[1].h1 = + 1; + + std::unordered_map::iterator it = ins.find( outindex ); + if ( it != ins.end() ) + { + // increment the number of inputs + it->second++; + } + } + } +} +template +static int computeLevel( Ntk const& ntk, int index ) +{ + // if node not visited + if ( ntk._storage->nodes[index].data[1].h1 == 0 ) + { + + // set node as visited + ntk._storage->nodes[index].data[1].h1 = 1; + + // if is input + if ( ntk.is_ci( index ) ) + { + return 0; + } + + auto inIdx2 = ntk._storage->nodes[index].children[1].data; + if ( inIdx2 & 1 ) + inIdx2 = inIdx2 - 1; + + // calculate input node index + auto inNode1 = inIdx2 >> 1; + int levelNode1 = computeLevel( ntk, inNode1 ); + + auto inIdx = ntk._storage->nodes[index].children[0].data; + if ( inIdx & 1 ) + inIdx = inIdx - 1; + + // calculate input node index + auto inNode0 = inIdx >> 1; + int levelNode0 = computeLevel( ntk, inNode0 ); + + int level = 1 + std::max( levelNode0, levelNode1 ); + return level; + } + return 0; +} +} // namespace also -- Gitee From 71ec76ee24631b44b2abb741afbabb8c72a67c24 Mon Sep 17 00:00:00 2001 From: cl-liao <2357605737@qq.com> Date: Sun, 23 Apr 2023 18:58:22 -0700 Subject: [PATCH 2/3] modified --- src/also.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/also.cpp b/src/also.cpp index 4647298..5658b5e 100644 --- a/src/also.cpp +++ b/src/also.cpp @@ -67,5 +67,6 @@ #include "commands/sim.hpp" #include "commands/decomp_flow.hpp" #include "commands/rm_mp2.hpp" +#include "commands/ps2.hpp" ALICE_MAIN( also ) -- Gitee From 3b6caabc44568609387cccd77fd29a704caf245f Mon Sep 17 00:00:00 2001 From: cl-liao <2357605737@qq.com> Date: Sun, 23 Apr 2023 19:02:10 -0700 Subject: [PATCH 3/3] modify --- src/commands/ps2.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/ps2.hpp b/src/commands/ps2.hpp index cea95ed..a0a5181 100644 --- a/src/commands/ps2.hpp +++ b/src/commands/ps2.hpp @@ -14,7 +14,7 @@ #define PS2 #include #include -#include <../core/ps2_ implemented.hpp> +#include <../core/ps2_implemented.hpp> namespace alice{ using namespace mockturtle; class ps2_command : public command{ -- Gitee