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

CEC #51

Open
wants to merge 3 commits into
base: v2021-cec
Choose a base branch
from
Open

CEC #51

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
70 changes: 67 additions & 3 deletions include/mockturtle/algorithms/simulation_cec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

EPFL CS-472 2021 Final Project Option 2
*/

#pragma once

#include <kitty/constructors.hpp>
Expand All @@ -55,7 +55,38 @@ struct simulation_cec_stats

namespace detail
{
class my_simulator
{
public:
uint32_t split_var;
uint32_t rounds;
uint32_t num_var;
my_simulator() = delete;
my_simulator (uint32_t split_var, uint32_t num_var, uint32_t rounds) : split_var(split_var), num_var(num_var), rounds(rounds) {}

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 {
uint64_t temp = rounds;
if ((temp >> (index - split_var)) & 1)
tt= ~tt;
}
return tt;
}
kitty::dynamic_truth_table compute_not( kitty::dynamic_truth_table const& value) const
{
return ~value;
}

};
template<class Ntk>
class simulation_cec_impl
{
Expand All @@ -74,12 +105,45 @@ class simulation_cec_impl
bool run()
{
/* TODO: write your implementation here */
return false;
_st.split_var = split_calculate(_ntk.num_pis());
_st.rounds = round_calculate(_st.split_var, _ntk.num_pis());
for( uint32_t i = 0; i < _st.rounds; i++)
{
my_simulator sim(_st.split_var, _ntk.num_pis(), i);
const std::vector<kitty::dynamic_truth_table> results = simulate<kitty::dynamic_truth_table>(_ntk, sim);
for(auto& out : results)
{
if(!kitty::is_const0(out))
{
return false;
}
}
}
return true;

}

private:
/* you can add additional methods here */

uint32_t split_calculate(uint32_t num_var)
{
if (num_var <= 6)
{
return num_var;
} else {
uint32_t temp = 0;
for (uint32_t i = 7; ((i <= _ntk.num_pis()) & (((32 + (1 << i-3)) * _ntk.size()) <= (1 << 29))); i++)
{
temp = i;
}
return temp;
}
}
uint32_t round_calculate( uint32_t split_var, uint32_t num_var)
{
uint32_t difference = num_var - split_var;
return (1 << difference);
}
private:
Ntk& _ntk;
simulation_cec_stats& _st;
Expand Down