Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2021 cec #55

Open
wants to merge 3 commits into
base: v2021-cec
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 126 additions & 7 deletions include/mockturtle/algorithms/simulation_cec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,141 @@ 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<kitty::dynamic_truth_table> sim(_st.split_var);

simulate_nodes(_ntk,patterns,sim);


/*equivalent(_ntk,patterns);*/

if(!equivalent(_ntk,patterns)){
return(false);
}

//default_simulator<kitty::dynamic_truth_table> 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<n)
{
kitty::create_nth_var(tt,k);
}
patterns[m]=tt;

});

}
void free( pattern_t& patterns ){
_ntk.foreach_gate( [&]( auto const& n )
{
patterns.erase(n);
} );
}
/*void simulate(Ntk& _net, pattern_t patterns,uint32_t n)
{
default_simulator<kitty::dynamic_truth_table> 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 detail

/* Entry point for users to call */
Expand All @@ -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<class Ntk>
Expand Down Expand Up @@ -131,4 +250,4 @@ std::optional<bool> simulation_cec( Ntk const& ntk1, Ntk const& ntk2, simulation
return result;
}

} // namespace mockturtle
} // namespace mockturtle