Utility data structures

Truth table cache

Header: mockturtle/utils/truth_table_cache.hpp

Method
Description

truth_table_cache

Creates a truth table cache and reserves memory.

insert

Inserts a truth table and returns a literal.

operator[]

Returns truth table for a given literal.

size

Returns number of normalized truth tables in the cache.
template<typename TT>
class truth_table_cache

Truth table cache.

A truth table cache is used to store truth tables. Many applications require to assign truth tables to nodes in a network. But since the truth tables often repeat, it is more convenient to store an index to a cache that stores the truth table. In order to reduce space, only one entry for a truth table and its complement are stored in the cache. To distinguish between both versions, the index to an entry in the truth table cache is represented as literal. The truth table whose function maps the input assignment \(0, \dots, 0\) to \(0\) is considered the normal truth table, while its complement is considered the complemented version. Only the normal truth table is stored at some index \(i\). A positive literal \(2i\) points to the normal truth table at index \(i\). A negative literal \(2i + 1\) points to the same truth table but returns its complement.

Example

truth_table_cache cache;

kitty::dynamic_truth_table maj( 3 );
kitty::create_majority( maj );
auto l1 = cache.insert( maj );  // index is 0

auto tt = cache[l1 ^ 1]; // tt is ~maj
auto l2 = cache.insert( tt ); // index is 1

auto s = cache.size(); // size is 1

Public Functions

truth_table_cache(uint32_t capacity = 1000u)

Creates a truth table cache and reserves memory.

uint32_t insert(TT tt)

Inserts a truth table and returns a literal.

To save space, only normal functions are stored in the truth table cache. A function is normal, if the input pattern \(0, \dots, 0\) maps to \(0\). If a function is not normal, its complement is inserted into the cache and a negative literal is returned.

The default convention for literals is assumed. That is an index \(i\) (starting) from \(0\) has positive literal \(2i\) and negative literal \(2i + 1\).

Parameters:

tt – Truth table to insert

Returns:

Literal of position in cache

TT operator[](uint32_t lit) const

Returns truth table for a given literal.

The function requires that lit is smaller than size().

inline auto size() const

Returns number of normalized truth tables in the cache.

void resize(uint32_t capacity)

Resizes the cache.

Reserve additional space for cache and data.

Node map

Header: mockturtle/utils/node_map.hpp

This group of containers helps to store and access values associated to nodes in a network.

Three implementations are provided, two using std::vector and one using std::unordered_map as internal storage. Using std::vector, the default implementation of node_map pre-allocates memory for all nodes and provides a fast way to access the data. When only a subset of nodes are associated with values, both unordered_node_map and incomplete_node_map provide interfaces to check whether a value is available. Using std::unordered_map, the former uses less memory but has a slower access speed; the latter uses std::vector together with validity tags to trade efficiency with memory.

Example

aig_network aig = ...
node_map<std::string, aig_network> node_names( aig );
aig.foreach_node( [&]( auto n ) {
  node_names[n] = "some string";
} );
template<class T, class Ntk, class Impl = std::vector<T>>
class node_map

Associative container network nodes.

This container helps to store and access values associated to nodes in a network.

Two implementations are provided, one using std::vector and another using std::unordered_map as internal storage. The former implementation can be pre-allocated and provides a fast way to access the data. The later implementation offers a way to associate values to a subset of nodes and to check whether a value is available.

template<class T, class Ntk>
class incomplete_node_map

Vector-based node map with validity query.

This container is initialized with a network to derive the size according to the number of nodes. The container can be accessed via nodes, or indirectly via signals, from which the corresponding node is derived.

The implementation uses a vector as underlying data structure, so that it benefits from fast access. It is supplemented with an additional validity field such that it can be used like an unordered_node_map.

Required network functions:

  • size

  • get_node

  • node_to_index

Public Functions

inline explicit incomplete_node_map(Ntk const &ntk)

Default constructor.

inline incomplete_node_map(Ntk const &ntk, T const &init_value)

Constructor with default value.

Initializes all values in the container to init_value.

inline auto size() const

Number of keys stored in the data structure.

inline bool has(node const &n) const

Check if a key is already defined.

template<typename _Ntk = Ntk, typename = std::enable_if_t<!std::is_same_v<typename _Ntk::signal, typename _Ntk::node>>>
inline bool has(signal const &f) const

Check if a key is already defined.

inline void erase(node const &n)

Erase a key (if it exists).

template<typename _Ntk = Ntk, typename = std::enable_if_t<!std::is_same_v<typename _Ntk::signal, typename _Ntk::node>>>
inline void erase(signal const &f)

Erase a key (if it exists).

inline T &operator[](node const &n)

Mutable access to value by node.

inline T const &operator[](node const &n) const

Constant access to value by node.

template<typename _Ntk = Ntk, typename = std::enable_if_t<!std::is_same_v<typename _Ntk::signal, typename _Ntk::node>>>
inline T &operator[](signal const &f)

Mutable access to value by signal.

This method derives the node from the signal. If the node and signal type are the same in the network implementation, this method is disabled.

template<typename _Ntk = Ntk, typename = std::enable_if_t<!std::is_same_v<typename _Ntk::signal, typename _Ntk::node>>>
inline T const &operator[](signal const &f) const

Constant access to value by signal.

This method derives the node from the signal. If the node and signal type are the same in the network implementation, this method is disabled.

inline void reset()

Resets the size of the map.

This function should be called, if the network changed in size. Then, the map is cleared, and resized to the current network’s size. All values are initialized with the place holder (empty) element.

inline void reset(T const &init_value)

Resets the size of the map.

This function should be called, if the network changed in size. Then, the map is cleared, and resized to the current network’s size. All values are initialized with init_value.

Parameters:

init_value – Initialization value after resize

inline void resize()

Resizes the map.

This function should be called, if the node_map’s size needs to be changed without clearing its data.

template<class NtkDest, class NtkSrc>
std::pair<NtkDest, node_map<signal<NtkDest>, NtkSrc>> mockturtle::initialize_copy_network(NtkSrc const &src)

Initializes a network for copying together with node map.

This utility function is helpful when creating a network from another one, a very common task. It creates the network of type NtkDest and already creates a node map to map nodes from the source network, of type NtkSrc to nodes of the new network. The function map constant inputs and creates and maps primary inputs.

Tech library

Header: mockturtle/utils/tech_library.hpp

Method
Description

get_supergates

Get the gates matching the function.

get_inverter_info

Get inverter information.

max_gate_size

Returns the maximum number of variables of the gates.

get_gates

Returns the original gates.
template<unsigned NInputs = 6u, classification_type Configuration = classification_type::np_configurations>
class tech_library

Library of gates for Boolean matching.

This class creates a technology library from a set of input gates. Each NP- or P-configuration of the gates are enumerated and inserted in the library.

The configuration is selected using the template parameter Configuration. P-configuration is suggested for big libraries with few symmetric gates. The template parameter NInputs selects the maximum number of variables allowed for a gate in the library.

The library can be generated also using supergates definitions.

Example

std::vector<gate> gates;
lorina::read_genlib( "file.genlib", genlib_reader( gates ) );
// standard library
mockturtle::tech_library lib( gates );

super_lib supergates_spec;
lorina::read_super( "file.super", super_reader( supergates_spec ) );
// library with supergates
mockturtle::tech_library lib_super( gates, supergates_spec );

Public Functions

inline const supergates_list_t *get_supergates(TT const &tt) const

Get the gates matching the function.

Returns a list of gates that match the function represented by the truth table.

inline const multi_supergates_list_t *get_multi_supergates(std::array<TT, max_multi_outputs> const &tts) const

Get the multi-output gates matching the function.

Returns a list of multi-output gates that match the function represented by the truth table.

inline uint64_t get_multi_function_id(uint64_t const &tt) const

Get the multi-output gate function ID for a single output.

Returns the function ID of a multi-output gate output if matched. This function supports up to 6 inputs. Returns zero in case of no match.

inline uint32_t get_pattern_id(uint32_t id1, uint32_t id2) const

Get the pattern ID for structural matching.

Returns a pattern ID if found, UINT32_MAX otherwise given the children IDs. This function works with only AND operators.

inline const supergates_list_t *get_supergates_pattern(uint32_t id, bool phase) const

Get the gates matching the pattern ID and phase.

Returns a list of gates that match the pattern ID and the given polarity.

inline const std::tuple<float, float, uint32_t> get_inverter_info() const

Get inverter information.

Returns area, delay, and ID of the smallest inverter.

inline const std::tuple<float, float, uint32_t> get_buffer_info() const

Get buffer information.

Returns area, delay, and ID of the smallest buffer.

inline unsigned max_gate_size()

Returns the maximum number of variables of the gates.

inline const std::vector<gate> get_gates() const

Returns the original gates.

inline const std::vector<standard_cell> &get_cells() const

Returns the standard cells.

inline const std::vector<std::vector<composed_gate<NInputs>>> &get_multioutput_gates() const

Returns multioutput gates.

inline const uint32_t num_multioutput_gates() const

Returns the number of multi-output gates loaded in the library.

inline const uint32_t num_structural_gates() const

Returns the number of gates for structural matching.

inline const uint32_t num_structural_large_gates() const

Returns the number of gates for structural matching with more than 6 inputs.

Exact library

Header: mockturtle/utils/tech_library.hpp

Method
Description

get_supergates

Get the structures matching the function.

get_supergates

Get the structures matching the function with DC.

get_database

Returns the NPN database of structures.

get_database

Returns the NPN database of structures.

get_inverter_info

Get inverter information.
template<typename Ntk, unsigned NInputs = 4u>
class exact_library

Library of graph structures for Boolean matching.

This class creates a technology library from a database of structures classified in NPN classes. Each NPN-entry in the database is stored in its NP class by removing the output inverter if present. The class creates supergates from the database computing area and delay information.

Example

mockturtle::mig_npn_resynthesis mig_resyn{ true };
mockturtle::exact_library<mockturtle::mig_network> lib( mig_resyn );

Public Functions

inline const supergates_list_t *get_supergates(TT const &tt) const

Get the structures matching the function.

Returns a list of graph structures that match the function represented by the truth table.

inline const supergates_list_t *get_supergates(TT const &tt, TT const &dc, uint32_t &phase, std::vector<uint8_t> &perm) const

Get the structures matching the function with DC.

Returns a list of graph structures that match the function represented by the truth table and its dont care set. This functions also updates the phase and permutation vector of the original NPN class to the new one obtained using don’t cares.

inline Ntk &get_database()

Returns the NPN database of structures.

inline const Ntk &get_database() const

Returns the NPN database of structures.

inline const std::tuple<float, float> get_inverter_info() const

Get inverter information.

Returns area, and delay cost of the inverter.

Supergates utils

Header: mockturtle/utils/super_utils.hpp

Method
Description

get_super_library

Get the all the supergates.

get_standard_library_size

Get the number of standard gates.
template<unsigned NInputs = 6u>
class super_utils

Utilities to generate supergates.

This class creates supergates starting from supergates specifications contained in supergates_spec extracted from a SUPER file.

Multi-output gates are also extracted from the list of GENLIB gates. However multi-output gates are currently not supported as supergates members.

This utility is called by tech_library to construct the library for technology mapping.

Public Functions

inline const std::deque<composed_gate<NInputs>> &get_super_library() const

Get the all the supergates.

Returns a list of supergates created accordingly to the standard library and the supergates specifications.

inline const uint32_t get_standard_library_size() const

Get the number of standard gates.

Returns the number of standard gates contained in the supergate library.

inline const std::vector<std::vector<composed_gate<NInputs>>> &get_multioutput_library() const

Get multi-output gates.

Returns a list of multioutput gates.

Struct library

Header: mockturtle/utils/struct_library.hpp

Method
Description

get_struct_library

Construct the structural library.

get_pattern_id

Get the pattern ID.

get_supergates_pattern

Get the gates matching the pattern ID.

print_and_table

Print and table.
template<unsigned NInputs = 9u>
class struct_library

Library of gates for structural matching.

This class creates a technology library from a set of input gates.

Gates are processed to derive rules in the AIG format. Then, every rule and subrule gets a unique id and the AND table is built. Every gate gets a unique label comprehensive of its rule id and whether it is positive or negative.

The template parameter NInputs selects the maximum number of variables allowed for a gate in the library.

By default, struct_library is used in tech_library when NInputs is greater than 6.

Example

std::vector<gate> gates;
lorina::read_genlib( "file.genlib", genlib_reader( gates ) );
// struct library
mockturtle::struct_library lib( gates );

Public Functions

inline void construct(uint32_t min_vars = 2u)

Construct the structural library.

Generates the patterns for structural matching. Variable min_vars defines the minimum number of gate inputs considered for the library creation. 0 < min_vars < UINT32_MAX

inline const map_label_gate &get_struct_library() const

Construct the structural library.

Generates the patterns for structural matching.

inline const uint32_t get_pattern_id(uint32_t id1, uint32_t id2) const

Get the pattern ID.

Parameters:
  • id1 – first pattern id.

  • id2 – second pattern id. Returns a pattern ID if found, UINT32_MAX otherwise given the children IDs. This function works with only AND operators.

inline const supergates_list_t *get_supergates_pattern(uint32_t id, bool phase) const

Get the gates matching the pattern ID.

Returns a list of gates that match the pattern ID.

inline const uint32_t get_num_large_gates() const

Returns the number of large gates.

Number of gates with more than 6 inputs.

inline void print_and_table()

Print and table.

struct dsd_node
struct label
struct signal
struct signal_hash
struct tuple_s_hash

Cuts

Header: mockturtle/utils/cuts.hpp

Method
Description

operator=

Assignment operator.

set_leaves

Sets leaves (using iterators).

set_leaves

Sets leaves (using container).

signature

Signature of the cut.

size

Returns the size of the cut (number of leaves).

begin

Begin iterator (constant).

begin

Begin iterator (mutable).

end

End iterator (constant).

end

End iterator (mutable).

operator->

Access to data (mutable).

operator->

Access to data (constant).

data

Access to data (mutable).

data

Access to data (constant).

merge

Merges two cuts.
template<int MaxLeaves, typename T = empty_cut_data>
class cut

A data-structure to hold a cut.

The cut class is specialized via two template arguments, MaxLeaves and T. MaxLeaves controls the maximum number of leaves a cut can hold. To guarantee an efficient implementation, this value should be \(k \cdot l\), where \(k\) is the maximum cut size and \(l\) is the maximum fanin size of a gate in the logic network. The second template argument T can be a type for which a data entry is created in the cut to store additional data, e.g., to compute the cost of a cut. It defaults to empty_cut_data, which is an empty struct that does not consume memory.

Example

std::vector<uint32_t> data{1, 2, 3, 4};

cut<10> cut1;
cut1.set_leaves( data.begin(), data.end() );

cut<10, uint32_t> cut2;
cut2.set_leaves( data.begin(), data.end() );
cut2.data() = 42u;

struct cut_data { uint32_t costs; };
cut<20, cut_data> c3;
c3.set_leaves( std::vector<uint32_t>{1, 2, 3} );
c3->costs = 37u;

Public Functions

cut() = default

Default constructor.

inline cut(cut const &other)

Copy constructor.

Copies leaves, length, signature, and data.

Parameters:

other – Other cut

cut &operator=(cut const &other)

Assignment operator.

Copies leaves, length, signature, and data.

Parameters:

other – Other cut

template<typename Iterator>
void set_leaves(Iterator begin, Iterator end)

Sets leaves (using iterators).

Parameters:
  • begin – Begin iterator to leaves

  • end – End iterator to leaves (exclusive)

template<typename Container>
void set_leaves(Container const &c)

Sets leaves (using container).

Convenience function, which extracts the begin and end iterators from the container.

template<typename Iterator>
void add_leaves(Iterator begin, Iterator end)

Add leaves (using iterators).

Parameters:
  • begin – Begin iterator to leaves

  • end – End iterator to leaves (exclusive)

inline auto signature() const

Signature of the cut.

inline auto size() const

Returns the size of the cut (number of leaves).

inline auto begin() const

Begin iterator (constant).

inline auto end() const

End iterator (constant).

inline auto begin()

Begin iterator (mutable).

inline auto end()

End iterator (mutable).

inline T *operator->()

Access to data (mutable).

inline T const *operator->() const

Access to data (constant).

inline T &data()

Access to data (mutable).

inline T const &data() const

Access to data (constant).

bool dominates(cut const &that) const

Checks whether the cut is a subset of another cut.

If \(L_1\) are the leaves of the current cut and \(L_2\) are the leaves of that, then this method returns true if and only if \(L_1 \subseteq L_2\).

Parameters:

that – Other cut

bool merge(cut const &that, cut &res, uint32_t cut_size) const

Merges two cuts.

This method merges two cuts and stores the result in res. The merge of two cuts is the union \(L_1 \cup L_2\) of the two leaf sets \(L_1\) of the cut and \(L_2\) of that. The merge is only successful if the union has not more than cut_size elements. In that case, the function returns false, otherwise true.

Parameters:
  • that – Other cut

  • res – Resulting cut

  • cut_size – Maximum cut size

Returns:

True, if resulting cut is small enough

Cut sets

Header: mockturtle/utils/cuts.hpp

Method
Description

cut_set

Standard constructor.

clear

Clears a cut set.

add_cut

Adds a cut to the end of the set.

insert

Inserts a cut into a set.

begin

Begin iterator (constant).

begin

Begin iterator (mutable).

end

End iterator (constant).

end

End iterator (mutable).

size

Number of cuts in the set.

operator[]

Returns reference to cut at index.

best

Returns the best cut, i.e., the first cut.

update_best

Updates the best cut.

limit

Resize the cut set, if it is too large.

operator<<

Prints a cut set.
template<typename CutType, int MaxCuts>
class cut_set

A data-structure to hold a set of cuts.

The aim of a cut set is to contain cuts and maintain two properties. First, all cuts are ordered according to the < operator, and second, all cuts are irredundant, i.e., no cut in the set dominates another cut in the set.

The cut set is defined using the CutType of cuts it should hold and a maximum number of cuts it can hold. No check is performed whether a cut set is full, and therefore the caller must not insert cuts into a full set.

Example

cut_set<cut<10>, 30> cuts;

cut<10> c1, c2, c3, c4;

c1.set_leaves( {1, 2, 3} );
c2.set_leaves( {4, 5} );
c3.set_leaves( {1, 2} );
c4.set_leaves( {1, 3, 4} );

cuts.insert( c1 );
cuts.insert( c2 );
cuts.insert( c3 );
cuts.insert( c4 );

assert( cuts.size() == 3 );

std::cout << cuts << std::endl;

// will print:
//   { 4, 5 }
//   { 1, 2 }
//   { 1, 3, 4 }

Public Functions

cut_set()

Standard constructor.

void clear()

Clears a cut set.

template<typename Iterator>
CutType &add_cut(Iterator begin, Iterator end)

Adds a cut to the end of the set.

This function should only be called to create a set of cuts which is known to be sorted and irredundant (i.e., no cut in the set dominates another cut).

Parameters:
  • begin – Begin iterator to leaf indexes

  • end – End iterator (exclusive) to leaf indexes

Returns:

Reference to the added cut

bool is_dominated(CutType const &cut) const

Checks whether cut is dominates by any cut in the set.

Parameters:

cut – Cut outside of the set

void insert(CutType const &cut)

Inserts a cut into a set.

This method will insert a cut into a set and maintain an order. Before the cut is inserted into the correct position, it will remove all cuts that are dominated by cut.

If cut is dominated by any of the cuts in the set, it will still be inserted. The caller is responsible to check whether cut is dominated before inserting it into the set.

Parameters:

cut – Cut to insert.

inline auto begin() const

Begin iterator (constant).

The iterator will point to a cut pointer.

inline auto end() const

End iterator (constant).

inline auto begin()

Begin iterator (mutable).

The iterator will point to a cut pointer.

inline auto end()

End iterator (mutable).

inline auto size() const

Number of cuts in the set.

inline auto const &operator[](uint32_t index) const

Returns reference to cut at index.

This function does not return the cut pointer but dereferences it and returns a reference. The function does not check whether index is in the valid range.

Parameters:

index – Index

inline auto const &best() const

Returns the best cut, i.e., the first cut.

void update_best(uint32_t index)

Updates the best cut.

This method will set the cut at index index to be the best cut. All cuts before index will be moved one position higher.

Parameters:

index – Index of new best cut

void limit(uint32_t size)

Resize the cut set, if it is too large.

This method will resize the cut set to size only if the cut set has more than size elements. Otherwise, the size will remain the same.

Friends

inline friend std::ostream &operator<<(std::ostream &os, cut_set const &set)

Prints a cut set.

Index list

Header: mockturtle/utils/index_list.hpp

struct mig_index_list

Index list for majority-inverter graphs.

Small network consisting of majority gates and inverters represented as a list of literals.

Example: The following index list creates the output function <<x1, x2, x3>, x2, x4> with 4 inputs, 1 output, and 2 gates: {4 | 1 << 8 | 2 << 16, 2, 4, 6, 4, 8, 10, 12}

template<typename Ntk>
void mockturtle::encode(mig_index_list &indices, Ntk const &ntk)

Generates a mig_index_list from a network.

The function requires ntk to consist of majority gates.

Required network functions:

  • foreach_fanin

  • foreach_gate

  • get_node

  • is_complemented

  • is_maj

  • node_to_index

  • num_gates

  • num_pis

  • num_pos

Parameters:
  • indices – An index list

  • ntk – A logic network

template<bool useSignal = true, typename Ntk, typename BeginIter, typename EndIter, typename Fn>
void mockturtle::insert(Ntk &ntk, BeginIter begin, EndIter end, mig_index_list const &indices, Fn &&fn)

Inserts a mig_index_list into an existing network.

Required network functions:

  • get_constant

  • create_maj

Parameters:
  • ntk – A logic network

  • begin – Begin iterator of signal inputs

  • end – End iterator of signal inputs

  • indices – An index list

  • fn – Callback function

inline std::string mockturtle::to_index_list_string(mig_index_list const &indices)

Converts an mig_index_list to a string.

Parameters:

indices – An index list

Returns:

A string representation of the index list

template<bool separate_header = false>
struct xag_index_list

Index list for xor-and graphs.

Small network represented as a list of literals. Supports XOR and AND gates. The list has the following 32-bit unsigned integer elements. It starts with a signature whose partitioned into | num_gates | num_pos | num_pis |, where num_gates accounts for the most-significant 16 bits, num_pos accounts for 8 bits, and num_pis accounts for the least-significant 8 bits. Afterwards, gates are defined as literal indexes (2 * i + c), where i is an index, with 0 indexing the constant 0, 1 to num_pis indexing the primary inputs, and all successive indexes for the gates. Gate literals come in pairs. If the first literal has a smaller value than the second one, an AND gate is created, otherwise, an XOR gate is created. Afterwards, all outputs are defined in terms of literals.

Example: The following index list creates the output function (x1 AND x2) XOR (x3 AND x4) with 4 inputs, 1 output, and 3 gates: {4 | 1 << 8 | 3 << 16, 2, 4, 6, 8, 12, 10, 14}

Note: if separate_header = true, the header will be split into 3 elements to support networks with larger number of PIs.

template<typename Ntk, bool separate_header = false>
void mockturtle::encode(xag_index_list<separate_header> &indices, Ntk const &ntk)

Generates a xag_index_list from a network.

The function requires ntk to consist of XOR and AND gates.

Required network functions:

  • foreach_fanin

  • foreach_gate

  • get_node

  • is_and

  • is_complemented

  • is_xor

  • node_to_index

  • num_gates

  • num_pis

  • num_pos

Parameters:
  • indices – An index list

  • ntk – A logic network

template<bool useSignal = true, typename Ntk, typename BeginIter, typename EndIter, typename Fn, bool separate_header = false>
void mockturtle::insert(Ntk &ntk, BeginIter begin, EndIter end, xag_index_list<separate_header> const &indices, Fn &&fn)

Inserts a xag_index_list into an existing network.

Required network functions:

  • create_and

  • create_xor

  • get_constant

Parameters:
  • ntk – A logic network

  • begin – Begin iterator of signal inputs

  • end – End iterator of signal inputs

  • indices – An index list

  • fn – Callback function

inline std::string mockturtle::to_index_list_string(xag_index_list<true> const &indices)
template<typename Ntk, typename IndexList>
void mockturtle::decode(Ntk &ntk, IndexList const &indices)

Generates a network from an index_list.

Required network functions:

  • create_pi

  • create_po

Parameters:
  • ntk – A logic network

  • indices – An index list

class aig_index_list_enumerator

Enumerate structured index_lists.

Enumerate concrete xag_index_lists from an abstract index list specification. The specifiation is provided in an extended index list format, where a -1 indicates an unspecified input.

The algorithm concretizes unspecified inputs and negates nodes.

The enumerator generates the following concrete index lists {2 | 1 << 8 | 1 << 16, 2, 4, 6} {2 | 1 << 8 | 1 << 16, 2, 4, 7} {2 | 1 << 8 | 1 << 16, 3, 4, 6} {2 | 1 << 8 | 1 << 16, 3, 4, 7} {2 | 1 << 8 | 1 << 16, 3, 5, 6} {2 | 1 << 8 | 1 << 16, 3, 5, 7} {2 | 1 << 8 | 1 << 16, 2, 5, 6} {2 | 1 << 8 | 1 << 16, 2, 5, 7} from the abstract index list specification { -1, -1, 6 }.

Example

aig_index_list_enumerator e( { -1, -1, -1, 6, 8 }, 2u, 2u, 1u );
e.run( [&]( xag_index_list const& il ) {
  aig_network aig;
  decode( aig, il );
} );

Stopwatch

Header: mockturtle/utils/stopwatch.hpp

Method
Description

stopwatch

Default constructor.

~stopwatch

Default deconstructor.
template<class Clock = std::chrono::steady_clock>
class stopwatch

Stopwatch interface.

This class implements a stopwatch interface to track time. It starts tracking time at construction and stops tracking time at deletion automatically. A reference to a duration object is passed to the constructor. After stopping the time the measured time interval is added to the durationr reference.

Example

stopwatch<>::duration time{0};

{ // some block
  stopwatch t( time );

  // do some work
} // stopwatch is stopped here

std::cout << fmt::format( "{:5.2f} seconds passed\n", to_seconds( time ) );

Public Functions

inline explicit stopwatch(duration &dur)

Default constructor.

Starts tracking time.

inline ~stopwatch()

Default deconstructor.

Stops tracking time and updates duration.

template<class Fn, class Clock = std::chrono::steady_clock>
std::invoke_result_t<Fn> mockturtle::call_with_stopwatch(typename Clock::duration &dur, Fn &&fn)

Calls a function and tracks time.

The function that is passed as second parameter can be any callable object that takes no parameters. This construction can be used to avoid pre-declaring the result type of a computation that should be tracked.

Example

stopwatch<>::duration time{0};

auto result = call_with_stopwatch( time, [&]() { return function( parameters ); } );

Parameters:
  • dur – Duration reference (time will be added to it)

  • fn – Callable object with no arguments

template<class T, class ...Args, class Clock = std::chrono::steady_clock>
T mockturtle::make_with_stopwatch(typename Clock::duration &dur, Args... args)

Constructs an object and calls time.

This function can track the time for the construction of an object and returns the constructed object.

Example

stopwatch<>::duration time{0};

// create vector with 100000 elements initialized to 42
auto result = make_with_stopwatch<std::vector<int>>( time, 100000, 42 );

template<class Duration>
inline double mockturtle::to_seconds(Duration const &dur)

Utility function to convert duration into seconds.

Progress bar

Header: mockturtle/utils/progress_bar.hpp

Method
Description

progress_bar

Constructor.

progress_bar

Constructor.

~progress_bar

Deconstructor.

operator()

Prints and updates the progress bar status.

done

Removes the progress bar.
class progress_bar

Prints progress bars.

Example

{ // some block
  progress_bar bar( 100, "|{0}| neg. index = {1}, index squared = {2}" );

  for ( auto i = 0; i < 100; ++i )
  {
    bar( i, -i, i * i );
  }
} // progress bar is deleted at exit of this block

Public Functions

inline progress_bar(uint32_t size, std::string const &fmt, bool enable = true, std::ostream &os = std::cout)

Constructor.

This constructor is used when a the total number of iterations is known, and the progress should be visually printed. When using this constructor, the current iteration must be provided to the operator() call.

Parameters:
  • size – Number of iterations (for progress bar)

  • fmt – Format strind; used with fmt::format, first placeholder {0} is used for progress bar, the others for the parameters passed to operator()

  • enable – If true, output is printed, otherwise not

  • os – Output stream

inline progress_bar(std::string const &fmt, bool enable = true, std::ostream &os = std::cout)

Constructor.

This constructor is used when a the total number of iterations is not known. In this case, the progress is not visually printed. When using this constructor, just pass the arguments for the fmt string.

Parameters:
  • fmt – Format strind; used with fmt::format, parameters are passed to operator()

  • enable – If true, output is printed, otherwise not

  • os – Output stream

inline ~progress_bar()

Deconstructor.

Will remove the last printed line and restore the cursor.

template<typename First, typename ...Args>
inline void operator()(First first, Args... args)

Prints and updates the progress bar status.

This updates the progress and re-prints the progress line. The previous print of the line is removed. If the progress bar has a progress segment the first argument must be an integer indicating the current progress with respect to the size parameter passed to the constructor.

Parameters:
  • first – Progress position or first argument

  • args – Vardiadic argument pack with values for format string

inline void done()

Removes the progress bar.

This method is automatically invoked when the progress bar is deleted. In some cases, one may wish to invoke this method manually.