From dd28e481e96f889e4c56fc41570b28363f24e4c4 Mon Sep 17 00:00:00 2001 From: Yasser Date: Wed, 22 Dec 2021 10:35:38 +0100 Subject: [PATCH 1/2] Update simulation_cec.hpp --- include/mockturtle/algorithms/simulation_cec.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index 2b8cce16c..abb09c49a 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -86,7 +86,7 @@ class simulation_cec_impl /* you can add other attributes here */ }; -} // namespace detail +} // namespace de /* Entry point for users to call */ From 7f33eea355305094128ba0211ce49da2b2a8f29f Mon Sep 17 00:00:00 2001 From: Yasser Date: Thu, 23 Dec 2021 23:25:15 +0100 Subject: [PATCH 2/2] yasser el aazdoudi cec --- .../mockturtle/algorithms/simulation_cec.hpp | 135 ++++++++++++++++-- 1 file changed, 127 insertions(+), 8 deletions(-) diff --git a/include/mockturtle/algorithms/simulation_cec.hpp b/include/mockturtle/algorithms/simulation_cec.hpp index abb09c49a..7b59e18dd 100644 --- a/include/mockturtle/algorithms/simulation_cec.hpp +++ b/include/mockturtle/algorithms/simulation_cec.hpp @@ -70,23 +70,142 @@ class simulation_cec_impl _st( st ) { } - + bool run() { - /* TODO: write your implementation here */ - return false; + _st.split_var = compute_splitting_var(_ntk); + //std::cout<< "st_split_var est" << _st.split_var << std::endl; + _st.rounds = compute_rounds(_ntk.num_pis(),_st.split_var); + //std::cout<< "_st.rounds est" << _st.rounds << std::endl; + + pattern_t patterns(_ntk); + init_patterns(_ntk, _st.split_var, patterns); + + /*simulate(_ntk,patterns,_st.split_var);*/ + + default_simulator sim(_st.split_var); + + simulate_nodes(_ntk,patterns,sim); + + + /*equivalent(_ntk,patterns);*/ + + if(!equivalent(_ntk,patterns)){ + return(false); + } + + //default_simulator sim(_st.split_var); + + for (uint32_t num_r = 1; num_r <_st.rounds; num_r++){ + free(patterns); + update_pattern(patterns,num_r); + simulate_nodes(_ntk,patterns, sim); + if(!equivalent(_ntk,patterns)){ + return(false); + } + } + + return true; } private: - /* you can add additional methods here */ + +uint32_t compute_splitting_var ( Ntk& _n) +{ + uint32_t n ,v; + + n= _n.num_pis(); + v= _n._storage->nodes.size(); + if(n<=6) + { + return n; + } + else + { + uint32_t z = log2((1<<29)/v - 32) + 3; + uint32_t split_var = std::min(n,z); + return split_var; + } +} + +uint32_t compute_rounds(uint32_t n,uint32_t m) +{ + uint32_t rounds = 1<<(n-m); + return rounds; +} + +void init_patterns(Ntk& _net, uint32_t n, pattern_t& patterns) +{ + /*pattern_t patterns(_net);*/ + + _net.foreach_pi([&]( auto const& m, auto k){ + kitty::dynamic_truth_table tt (n); + if (k sim(n); + simulate_nodes(_net,patterns,sim); +} +*/ + +bool equivalent(Ntk& _net,pattern_t& patterns){ + bool check = true; + _net.foreach_po([&](auto const& m){ + if (_net.is_complemented(m)) + { + if(!is_const0(~patterns[m])){ + check = false; + } + } + else + { + if(!is_const0(patterns[m])){ + check = false; + } + } + }); + return check; +} + +void update_pattern( pattern_t& patterns, uint32_t& num_r ){ + uint32_t nb_rounds= num_r; + _ntk.foreach_pi( [&]( auto const& m, auto k ) + { + if (k >= _st.split_var ){ + if (nb_rounds % 2 == 1) { + if ( is_const0(patterns[m]) ) patterns[m] = ~patterns[m]; + } + else { + if ( !is_const0(patterns[m]) ) patterns[m] = ~patterns[m]; + } + nb_rounds /= 2; + } + } ); + } + private: Ntk& _ntk; simulation_cec_stats& _st; + /* you can add other attributes here */ }; - -} // namespace de + +} // namespace detail /* Entry point for users to call */ @@ -95,7 +214,7 @@ class simulation_cec_impl * This function implements a simulation-based combinational equivalence checker. * The implementation creates a miter network and run several rounds of simulation * to verify the functional equivalence. For memory and speed reasons this approach - * is limited up to 40 input networks. It returns an optional which is `nullopt`, + * is limited up to 40 input networks. It returns an optional which is nullopt, * if the network has more than 40 inputs. */ template @@ -131,4 +250,4 @@ std::optional simulation_cec( Ntk const& ntk1, Ntk const& ntk2, simulation return result; } -} // namespace mockturtle +} // namespace mockturtle \ No newline at end of file