ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
kitty_constructors.hpp
Go to the documentation of this file.
1#ifndef _KITTY_CONSTRUCT_TT_H_
2#define _KITTY_CONSTRUCT_TT_H_
3#pragma once
4
5#include <cctype>
6#include <chrono>
7#include <istream>
8#include <random>
9#include <stack>
10
11#include "kitty_constants.hpp"
12#include "kitty_dynamic_tt.hpp"
13#include "kitty_static_tt.hpp"
14
16
17namespace kitty
18{
19
31template<typename TT>
32inline TT create( unsigned num_vars )
33{
34 (void)num_vars;
35 TT tt;
36 assert( tt.num_vars() == num_vars );
37 return tt;
38}
39
41template<>
42inline dynamic_truth_table create<dynamic_truth_table>( unsigned num_vars )
43{
44 return dynamic_truth_table( num_vars );
45}
47
54template<typename TT>
55void create_nth_var( TT& tt, uint8_t var_index, bool complement = false )
56{
57 if ( tt.num_vars() <= 6 )
58 {
59 /* assign from precomputed table */
60 tt._bits[0] = complement ? ~detail::projections[var_index] : detail::projections[var_index];
61
62 /* mask if truth table does not require all bits */
63 tt.mask_bits();
64 return;
65 }
66
67 if ( var_index < 6 )
68 {
69 std::fill( std::begin( tt._bits ), std::end( tt._bits ), complement ? ~detail::projections[var_index] : detail::projections[var_index] );
70 }
71 else
72 {
73 const auto c = 1 << ( var_index - 6 );
74 const auto zero = uint64_t( 0 );
75 const auto one = ~zero;
76 auto block = uint64_t( 0u );
77
78 while ( block < tt.num_blocks() )
79 {
80 for ( auto i = 0; i < c; ++i )
81 {
82 tt._bits[block++] = complement ? one : zero;
83 }
84 for ( auto i = 0; i < c; ++i )
85 {
86 tt._bits[block++] = complement ? zero : one;
87 }
88 }
89 }
90}
91
92} // namespace kitty
93
95
96#endif // _KITTY_CONSTRUCT_TT_H_
ABC_NAMESPACE_HEADER_START typedef unsigned char uint8_t
Definition Fxch.h:31
#define ABC_NAMESPACE_CXX_HEADER_START
#define ABC_NAMESPACE_CXX_HEADER_END
pcover complement(pcube *T)
Definition compl.c:49
void create_nth_var(TT &tt, uint8_t var_index, bool complement=false)
Constructs projections (single-variable functions)
TT create(unsigned num_vars)
Creates truth table with number of variables.
#define assert(ex)
Definition util_old.h:213