Skip to content

Commit

Permalink
Creating feature branch for seed partitioner development
Browse files Browse the repository at this point in the history
  • Loading branch information
maustin8 authored and srtemp committed Jun 11, 2019
1 parent 2bced68 commit 7a67356
Show file tree
Hide file tree
Showing 21 changed files with 88,339 additions and 345 deletions.
1,095 changes: 802 additions & 293 deletions core/lstools.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* mockturtle: C++ logic network library
* Copyright (C) 2018 EPFL
* Copyright (C) 2018-2019 EPFL
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -80,11 +80,8 @@ struct xag_npn_resynthesis_stats
* 4.
*
\verbatim embed:rst
Example
.. code-block:: c++
const aig_network aig = ...;
xag_npn_resynthesis<aig_network> resyn;
cut_rewriting( aig, resyn );
Expand All @@ -106,6 +103,7 @@ class xag_npn_resynthesis
static_assert( has_get_constant_v<Ntk>, "Ntk does not implement the get_constant method" );
static_assert( has_create_and_v<Ntk>, "Ntk does not implement the create_and method" );
static_assert( has_create_xor_v<Ntk>, "Ntk does not implement the create_xor method" );
static_assert( has_create_not_v<Ntk>, "Ntk does not implement the create_not method" );

static_assert( is_network_type_v<DatabaseNtk>, "DatabaseNtk is not a network type" );
static_assert( has_get_node_v<DatabaseNtk>, "DatabaseNtk does not implement the get_node method" );
Expand Down Expand Up @@ -159,32 +157,37 @@ class xag_npn_resynthesis
std::vector<signal<Ntk>> pis( 4, ntk.get_constant( false ) );
std::copy( begin, end, pis.begin() );

std::vector<signal<Ntk>> pis_perm( 4 );
std::vector<signal<Ntk>> pis_perm;
auto perm = std::get<2>( config );
for ( auto i = 0; i < 4; ++i )
{
pis_perm[i] = pis[perm[i]];
pis_perm.push_back( pis[perm[i]] );
}

const auto& phase = std::get<1>( config );
for ( auto i = 0; i < 4; ++i )
{
if ( ( phase >> perm[i] ) & 1 )
{
pis_perm[i] = !pis_perm[i];
pis_perm[i] = ntk.create_not( pis_perm[i] );
}
}

for ( auto const& cand : it->second )
{
std::unordered_map<node<DatabaseNtk>, signal<Ntk>> db_to_ntk;
db_to_ntk[0] = ntk.get_constant( false );

db_to_ntk.insert( {0, ntk.get_constant( false )} );
for ( auto i = 0; i < 4; ++i )
{
db_to_ntk[i + 1] = pis_perm[i];
db_to_ntk.insert( {i + 1, pis_perm[i]} );
}
auto f = copy_db_entry( ntk, _db.get_node( cand ), db_to_ntk );
if ( _db.is_complemented( cand ) != ( ( phase >> 4 ) & 1 ) )
{
f = ntk.create_not( f );
}
const auto f = copy_db_entry( ntk, _db.get_node( cand ), db_to_ntk ) ^ _db.is_complemented( cand );
if ( !fn( ( ( phase >> 4 ) & 1 ) ? !f : f ) )
if ( !fn( f ) )
{
return;
}
Expand All @@ -200,13 +203,20 @@ class xag_npn_resynthesis
return it->second;
}

std::array<signal<Ntk>, 2> fanin;
_db.foreach_fanin( n, [&]( auto const& f, auto i ) {
fanin[i] = copy_db_entry( ntk, _db.get_node( f ), db_to_ntk ) ^ _db.is_complemented( f );
std::vector<signal<Ntk>> fanin;
//std::array<signal<Ntk>, 2> fanin;
_db.foreach_fanin( n, [&]( auto const& f ) {
auto ntk_f = copy_db_entry( ntk, _db.get_node( f ), db_to_ntk );
if ( _db.is_complemented( f ) )
{
ntk_f = ntk.create_not( ntk_f );
}
fanin.push_back( ntk_f );
} );

const auto f = _db.is_xor( n ) ? ntk.create_xor( fanin[0], fanin[1] ) : ntk.create_and( fanin[0], fanin[1] );
return db_to_ntk[n] = f;
db_to_ntk.insert( {n, f} );
return f;
}

void build_classes()
Expand Down
12 changes: 12 additions & 0 deletions lib/mockturtle/include/mockturtle/networks/aig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,18 @@ class aig_network

return maj;
}

signal create_maj_part(signal const& a, signal const& b, signal const& c)
{
// signal left1 = create_and(a,b);
// signal right1 = create_and(a,c);
// signal left = create_or(left1,right1);
// signal right = create_and(b,c);
// signal final = create_or(left, right);
auto maj = create_or(create_or(create_and(a, b ),create_and(a, c )),create_and(b, c ));

return maj;
}
#pragma endregion

#pragma region Create arbitrary functions
Expand Down
26 changes: 12 additions & 14 deletions lib/mockturtle/include/mockturtle/networks/mig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class mig_network
return {0, static_cast<uint64_t>( value ? 1 : 0 )};
}

void create_in_name(unsigned index, const std::string& name){
void create_in_name(unsigned index, const std::string& name){
// std::cout << "input index " << (int)index << " name " << name << "\n";
_storage->inputNames[index] = name;
}
Expand Down Expand Up @@ -395,32 +395,30 @@ class mig_network
return ( a.complement == b.complement ) ? a : c;
}

/* complemented edges minimization */
auto node_complement = false;
if ( static_cast<unsigned>( a.complement ) + static_cast<unsigned>( b.complement ) +
static_cast<unsigned>( c.complement ) >=
2u )
{
node_complement = true;
a.complement = !a.complement;
b.complement = !b.complement;
c.complement = !c.complement;
}

storage::element_type::node_type node;
node.children[0] = a;
node.children[1] = b;
node.children[2] = c;

/* structural hashing */
const auto it = _storage->hash.find( node );
if ( it != _storage->hash.end() )
{
return {it->second, 0};
}

const auto index = _storage->nodes.size();

if ( index >= .9 * _storage->nodes.capacity() )
{
_storage->nodes.reserve( static_cast<uint64_t>( 3.1415f * index ) );
_storage->hash.reserve( static_cast<uint64_t>( 3.1415f * index ) );
}

_storage->nodes.push_back( node );

_storage->hash[node] = index;

/* increase ref-count to children */
_storage->nodes[a.index].data[0].h1++;
_storage->nodes[b.index].data[0].h1++;
Expand All @@ -431,7 +429,7 @@ class mig_network
fn( index );
}

return {index, node_complement};
return {index, 0};
}

signal create_and( signal const& a, signal const& b )
Expand Down
14 changes: 14 additions & 0 deletions lib/mockturtle/include/mockturtle/networks/xag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ class xag_network
return {0, static_cast<uint64_t>( value ? 1 : 0 )};
}

void create_in_name(unsigned index, const std::string& name){
// std::cout << "input index " << (int)index << " name " << name << "\n";
_storage->inputNames[index] = name;
}
void create_out_name(unsigned index, const std::string& name){
// std::cout << "output index " << (int)index << " name " << name << "\n";
_storage->outputNames[index] = name;
}

signal create_pi( std::string const& name = {} )
{
(void)name;
Expand Down Expand Up @@ -630,6 +639,11 @@ class xag_network
return _storage->data.num_pis;
}

uint32_t num_latches() const
{
return _storage->data.latches.size();
}

auto num_pos() const
{
return _storage->data.num_pos;
Expand Down
4 changes: 4 additions & 0 deletions lib/mockturtle/include/mockturtle/views/topo_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class topo_view<Ntk, false> : public immutable_view<Ntk>
fn );
}

std::vector<node> get_node_vec(){
return topo_order;
}

/*! \brief Reimplementation of `foreach_po`.
*
* If `start_signal` is provided in constructor, only this is returned as
Expand Down
Loading

0 comments on commit 7a67356

Please sign in to comment.