diff --git a/.gitignore b/.gitignore index 505680bc9..4329e653d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ examples/ docs/_build docs/doxyxml +.vs diff --git a/include/mockturtle/algorithms/cleanup.hpp b/include/mockturtle/algorithms/cleanup.hpp index 57a7d7c13..f1bf32543 100644 --- a/include/mockturtle/algorithms/cleanup.hpp +++ b/include/mockturtle/algorithms/cleanup.hpp @@ -268,7 +268,7 @@ NtkDest cleanup_dangling( NtkSrc const& ntk ) std::vector> pis; ntk.foreach_pi( [&]( auto ) { pis.push_back( dest.create_pi() ); - } ); + } ); // record all the primiary inputs of ntk in pis for ( auto f : cleanup_dangling( ntk, dest, pis.begin(), pis.end() ) ) { diff --git a/include/mockturtle/algorithms/simulation.hpp b/include/mockturtle/algorithms/simulation.hpp index 2c43d88b3..d475002b4 100644 --- a/include/mockturtle/algorithms/simulation.hpp +++ b/include/mockturtle/algorithms/simulation.hpp @@ -111,7 +111,7 @@ class default_simulator { public: default_simulator() = delete; - default_simulator( unsigned num_vars ) : num_vars( num_vars ) {} + default_simulator( unsigned num_vars) : num_vars( num_vars ){} kitty::dynamic_truth_table compute_constant( bool value ) const { @@ -121,10 +121,11 @@ class default_simulator kitty::dynamic_truth_table compute_pi( uint32_t index ) const { - kitty::dynamic_truth_table tt( num_vars ); - kitty::create_nth_var( tt, index ); - return tt; - } + kitty::dynamic_truth_table tt( num_vars ); + kitty::create_nth_var( tt, index ); + return tt; + } + kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const& value ) const { @@ -133,6 +134,8 @@ class default_simulator private: unsigned num_vars; + bool isMiter; + uint32_t round, split_var; }; /*! \brief Simulates truth tables. @@ -522,7 +525,6 @@ node_map simulate_nodes( Ntk const& ntk, Simulator const& s } ); node_to_value[n] = ntk.compute( n, fanin_values.begin(), fanin_values.end() ); } ); - return node_to_value; } diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index 2b8cce16c..b2915f4fe 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -40,6 +40,8 @@ #include "miter.hpp" #include "simulation.hpp" +#include // used for printing + namespace mockturtle { @@ -56,6 +58,46 @@ struct simulation_cec_stats namespace detail { +class cec_simulator +{ +public: + cec_simulator(unsigned num_vars, uint32_t split_var, uint32_t round) : num_vars( num_vars ), split_var(split_var), + round(round) {} + + kitty::dynamic_truth_table compute_constant( bool value ) const + { + kitty::dynamic_truth_table tt( split_var ); + return value ? ~tt : tt; + } + + kitty::dynamic_truth_table compute_pi( uint32_t index ) const + { + kitty::dynamic_truth_table tt( split_var ); + if ( index < split_var ) + { + kitty::create_nth_var( tt, index ); + } + else{ + bool flag = round >> ( index - split_var ) & 1; + if ( !flag ) + { + tt = ~tt; + } + } + return tt; + } + + kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const& value ) const + { + return ~value; + } + +private: + unsigned int num_vars; + uint32_t round, split_var; +}; + + template class simulation_cec_impl { @@ -74,16 +116,48 @@ class simulation_cec_impl bool run() { /* TODO: write your implementation here */ - return false; + // computing splitting_var and rounds + gen_st(); + // create the pattern with truth table + + for ( auto i = 0; i < _st.rounds; i++ ) + { + std::cout << "[running] round " << i << std::endl; + cec_simulator sim( _ntk.num_pis(), _st.split_var, i ); + const std::vector res = simulate( _ntk, sim ); + + for ( auto& po : res ) + { + if ( !kitty::is_const0( po ) ) + { + return false; + } + } + return true; + } } - private: /* you can add additional methods here */ - -private: Ntk& _ntk; simulation_cec_stats& _st; /* you can add other attributes here */ + + void gen_st() + { + auto n = _ntk.num_pis(); + if ( n <= 6 ) + { + _st.split_var = n; + } + else + { + auto v = _ntk.size(); + int max_m = std::log2l( std::pow( 2, 29 ) / v - 32 ) + 3; + _st.split_var = max_m > n ? n : max_m; + } + + _st.rounds = std::pow( 2, n - _st.split_var ); + } }; } // namespace detail diff --git a/lib/kitty/kitty/constructors.hpp b/lib/kitty/kitty/constructors.hpp index a60b8c45f..e3b6d02b8 100644 --- a/lib/kitty/kitty/constructors.hpp +++ b/lib/kitty/kitty/constructors.hpp @@ -109,7 +109,7 @@ void create_nth_var( TT& tt, uint8_t var_index, bool complement = false ) tt.mask_bits(); return; } - } + } // if partial_truth_table else { if ( tt.num_vars() <= 6 ) @@ -123,13 +123,13 @@ void create_nth_var( TT& tt, uint8_t var_index, bool complement = false ) } } - if ( var_index < 6 ) - { + if ( var_index < 6 ) // if index smaller than six + { // fill in all the bits with the same projection std::fill( std::begin( tt._bits ), std::end( tt._bits ), complement ? ~detail::projections[var_index] : detail::projections[var_index] ); } - else + else { - const auto c = 1 << ( var_index - 6 ); + const auto c = 1 << ( var_index - 6 ); // var_index 7, c 2 const auto zero = uint64_t( 0 ); const auto one = ~zero; auto block = uint64_t( 0u ); @@ -150,7 +150,8 @@ void create_nth_var( TT& tt, uint8_t var_index, bool complement = false ) /*! \cond PRIVATE */ template -void create_nth_var( static_truth_table& tt, uint8_t var_index, bool complement = false ) +void create_nth_var( static_truth_table& tt, uint8_t var_index, bool complement = false ) +// cast to static truth table, can only have up to six varialbes { /* assign from precomputed table */ tt._bits = complement ? ~detail::projections[var_index] : detail::projections[var_index]; diff --git a/lib/kitty/kitty/detail/constants.hpp b/lib/kitty/kitty/detail/constants.hpp index 326044a3c..e5a985ae0 100644 --- a/lib/kitty/kitty/detail/constants.hpp +++ b/lib/kitty/kitty/detail/constants.hpp @@ -43,8 +43,8 @@ namespace detail { static constexpr uint64_t projections[] = { - UINT64_C( 0xaaaaaaaaaaaaaaaa ), - UINT64_C( 0xcccccccccccccccc ), + UINT64_C( 0xaaaaaaaaaaaaaaaa ), // 10101010... + UINT64_C( 0xcccccccccccccccc ), // 11001100... UINT64_C( 0xf0f0f0f0f0f0f0f0 ), UINT64_C( 0xff00ff00ff00ff00 ), UINT64_C( 0xffff0000ffff0000 ), diff --git a/lib/kitty/kitty/dynamic_truth_table.hpp b/lib/kitty/kitty/dynamic_truth_table.hpp index 9963db4bd..05cd985f5 100644 --- a/lib/kitty/kitty/dynamic_truth_table.hpp +++ b/lib/kitty/kitty/dynamic_truth_table.hpp @@ -58,7 +58,7 @@ struct dynamic_truth_table \param num_vars Number of variables */ explicit dynamic_truth_table( uint32_t num_vars ) - : _bits( ( num_vars <= 6 ) ? 1u : ( 1u << ( num_vars - 6 ) ) ), + : _bits( ( num_vars <= 6 ) ? 1u : ( 1u << ( num_vars - 6 ) ) ), // initialize length of _bits _num_vars( num_vars ) { }