ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
kitty Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  dynamic_truth_table
 
struct  static_truth_table
 
struct  static_truth_table< NumVars, false >
 
struct  static_truth_table< NumVars, true >
 

Functions

template<typename TT, typename Fn>
TT unary_operation (const TT &tt, Fn &&op)
 Perform bitwise unary operation on truth table.
 
template<typename TT, typename Fn>
TT binary_operation (const TT &first, const TT &second, Fn &&op)
 Perform bitwise binary operation on two truth tables.
 
template<typename TT, typename Fn>
bool binary_predicate (const TT &first, const TT &second, Fn &&op)
 Computes a predicate based on two truth tables.
 
template<typename TT, typename Fn>
void assign_operation (TT &tt, Fn &&op)
 Assign computed values to bits.
 
template<typename TT, typename Fn>
void for_each_block (const TT &tt, Fn &&op)
 Iterates through each block of a truth table.
 
template<typename TT, typename Fn>
void for_each_block_reversed (const TT &tt, Fn &&op)
 Iterates through each block of a truth table in reverse order.
 
template<typename TT>
TT create (unsigned num_vars)
 Creates truth table with number of variables.
 
template<typename TT>
void create_nth_var (TT &tt, uint8_t var_index, bool complement=false)
 Constructs projections (single-variable functions)
 
template<typename TT>
TT unary_not_if (const TT &tt, bool cond)
 
template<typename TT>
TT unary_not (const TT &tt)
 Inverts all bits in a truth table.
 
template<typename TT>
TT binary_and (const TT &first, const TT &second)
 Bitwise AND of two truth tables.
 
template<typename TT>
TT binary_or (const TT &first, const TT &second)
 Bitwise OR of two truth tables.
 
template<typename TT>
void swap_inplace (TT &tt, uint8_t var_index1, uint8_t var_index2)
 Swaps two variables in a truth table.
 
template<uint32_t NumVars>
void swap_inplace (static_truth_table< NumVars, true > &tt, uint8_t var_index1, uint8_t var_index2)
 
template<typename TT, typename TTFrom>
void extend_to_inplace (TT &tt, const TTFrom &from)
 Extends smaller truth table to larger one.
 
template<uint32_t NumVars, typename TTFrom>
static_truth_table< NumVars > extend_to (const TTFrom &from)
 Extends smaller truth table to larger static one.
 
template<typename TT>
bool has_var (const TT &tt, uint8_t var_index)
 Checks whether truth table depends on given variable index.
 
template<typename TT>
bool has_var (const TT &tt, const TT &care, uint8_t var_index)
 Checks whether truth table depends on given variable index.
 
template<typename TT, typename TTFrom>
void shrink_to_inplace (TT &tt, const TTFrom &from)
 Shrinks larger truth table to smaller one.
 
template<typename TTFrom>
dynamic_truth_table shrink_to (const TTFrom &from, unsigned num_vars)
 Shrinks larger truth table to smaller dynamic one.
 
template<typename TT>
void print_hex (const TT &tt, std::ostream &os=std::cout)
 Prints truth table in hexadecimal representation.
 
dynamic_truth_table operator~ (const dynamic_truth_table &tt)
 Operator for unary_not.
 
template<uint32_t NumVars>
static_truth_table< NumVars > operator~ (const static_truth_table< NumVars > &tt)
 Operator for unary_not.
 
dynamic_truth_table operator& (const dynamic_truth_table &first, const dynamic_truth_table &second)
 Operator for binary_and.
 
template<uint32_t NumVars>
static_truth_table< NumVars > operator& (const static_truth_table< NumVars > &first, const static_truth_table< NumVars > &second)
 Operator for binary_and.
 
void operator&= (dynamic_truth_table &first, const dynamic_truth_table &second)
 Operator for binary_and and assign.
 
template<uint32_t NumVars>
void operator&= (static_truth_table< NumVars > &first, const static_truth_table< NumVars > &second)
 Operator for binary_and and assign.
 
dynamic_truth_table operator| (const dynamic_truth_table &first, const dynamic_truth_table &second)
 Operator for binary_or.
 
template<uint32_t NumVars>
static_truth_table< NumVars > operator| (const static_truth_table< NumVars > &first, const static_truth_table< NumVars > &second)
 Operator for binary_or.
 
void operator|= (dynamic_truth_table &first, const dynamic_truth_table &second)
 Operator for binary_or and assign.
 
template<uint32_t NumVars>
void operator|= (static_truth_table< NumVars, true > &first, const static_truth_table< NumVars, true > &second)
 Operator for binary_or and assign.
 
template<uint32_t NumVars>
void operator|= (static_truth_table< NumVars, false > &first, const static_truth_table< NumVars, false > &second)
 Operator for binary_or and assign.
 

Function Documentation

◆ assign_operation()

template<typename TT, typename Fn>
void kitty::assign_operation ( TT & tt,
Fn && op )

Assign computed values to bits.

The functor op computes bits which are assigned to the bits of the truth table.

Parameters
ttTruth table
opUnary operation that takes no input and returns a word (uint64_t)

Definition at line 85 of file kitty_algorithm.hpp.

86{
87 std::generate( tt.begin(), tt.end(), op );
88 tt.mask_bits();
89}

◆ binary_and()

template<typename TT>
TT kitty::binary_and ( const TT & first,
const TT & second )
inline

Bitwise AND of two truth tables.

Definition at line 48 of file kitty_operations.hpp.

49{
50 return binary_operation( first, second, std::bit_and<uint64_t>() );
51}
TT binary_operation(const TT &first, const TT &second, Fn &&op)
Perform bitwise binary operation on two truth tables.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ binary_operation()

template<typename TT, typename Fn>
TT kitty::binary_operation ( const TT & first,
const TT & second,
Fn && op )

Perform bitwise binary operation on two truth tables.

The dimensions of first and second must match. This is ensured at compile-time for static truth tables, but at run-time for dynamic truth tables.

Parameters
firstFirst truth table
secondSecond truth table
opBinary operation that takes as input two words (uint64_t) and returns a word
Returns
new constructed truth table of same type and dimensions

Definition at line 46 of file kitty_algorithm.hpp.

47{
48 assert( first.num_vars() == second.num_vars() );
49
50 TT result = first.construct();
51 std::transform( first.cbegin(), first.cend(), second.cbegin(), result.begin(), op );
52 result.mask_bits();
53 return result;
54}
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ binary_or()

template<typename TT>
TT kitty::binary_or ( const TT & first,
const TT & second )
inline

Bitwise OR of two truth tables.

Definition at line 55 of file kitty_operations.hpp.

56{
57 return binary_operation( first, second, std::bit_or<uint64_t>() );
58}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ binary_predicate()

template<typename TT, typename Fn>
bool kitty::binary_predicate ( const TT & first,
const TT & second,
Fn && op )

Computes a predicate based on two truth tables.

The dimensions of first and second must match. This is ensured at compile-time for static truth tables, but at run-time for dynamic truth tables.

Parameters
firstFirst truth table
secondSecond truth table
opBinary operation that takes as input two words (uint64_t) and returns a Boolean
Returns
true or false based on the predicate

Definition at line 69 of file kitty_algorithm.hpp.

70{
71 assert( first.num_vars() == second.num_vars() );
72
73 return std::equal( first.begin(), first.end(), second.begin(), op );
74}

◆ create()

template<typename TT>
TT kitty::create ( unsigned num_vars)
inline

Creates truth table with number of variables.

If some truth table instance is given, one can create a truth table with the same type by calling the construct() method on it. This function helps if only the number of variables is known and the base type and uniforms the creation of static and dynamic truth tables. Note, however, that for static truth tables num_vars must be consistent to the number of variables in the truth table type.

Parameters
num_varsNumber of variables

Definition at line 32 of file kitty_constructors.hpp.

33{
34 (void)num_vars;
35 TT tt;
36 assert( tt.num_vars() == num_vars );
37 return tt;
38}
Here is the caller graph for this function:

◆ create_nth_var()

template<typename TT>
void kitty::create_nth_var ( TT & tt,
uint8_t var_index,
bool complement = false )

Constructs projections (single-variable functions)

Parameters
ttTruth table
var_indexIndex of the variable, must be smaller than the truth table's number of variables
complementIf true, realize inverse projection

Definition at line 55 of file kitty_constructors.hpp.

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}
pcover complement(pcube *T)
Definition compl.c:49
pcover complement()
Here is the call graph for this function:

◆ extend_to()

template<uint32_t NumVars, typename TTFrom>
static_truth_table< NumVars > kitty::extend_to ( const TTFrom & from)
inline

Extends smaller truth table to larger static one.

This is an out-of-place version of extend_to_inplace that has the truth table as a return value. It only works for creating static truth tables. The template parameter NumVars must be equal or larger to the number of variables in from.

Parameters
fromSmaller truth table to copy from

Definition at line 198 of file kitty_operations.hpp.

199{
201 extend_to_inplace( tt, from );
202 return tt;
203}
void extend_to_inplace(TT &tt, const TTFrom &from)
Extends smaller truth table to larger one.
Here is the call graph for this function:

◆ extend_to_inplace()

template<typename TT, typename TTFrom>
void kitty::extend_to_inplace ( TT & tt,
const TTFrom & from )

Extends smaller truth table to larger one.

The most significant variables will not be in the functional support of the resulting truth table, but the method is helpful to align a truth table when being used with another one.

Parameters
ttLarger truth table to create
fromSmaller truth table to copy from

Definition at line 163 of file kitty_operations.hpp.

164{
165 assert( tt.num_vars() >= from.num_vars() );
166
167 if ( from.num_vars() < 6 )
168 {
169 auto mask = *from.begin();
170
171 for ( auto i = from.num_vars(); i < std::min<uint8_t>( 6, tt.num_vars() ); ++i )
172 {
173 mask |= ( mask << ( 1 << i ) );
174 }
175
176 std::fill( tt.begin(), tt.end(), mask );
177 }
178 else
179 {
180 auto it = tt.begin();
181 while ( it != tt.end() )
182 {
183 it = std::copy( from.cbegin(), from.cend(), it );
184 }
185 }
186}
Here is the caller graph for this function:

◆ for_each_block()

template<typename TT, typename Fn>
void kitty::for_each_block ( const TT & tt,
Fn && op )

Iterates through each block of a truth table.

The functor op is called for every block of the truth table.

Parameters
ttTruth table
opUnary operation that takes as input a word (uint64_t) and returns void

Definition at line 99 of file kitty_algorithm.hpp.

100{
101 std::for_each( tt.cbegin(), tt.cend(), op );
102}

◆ for_each_block_reversed()

template<typename TT, typename Fn>
void kitty::for_each_block_reversed ( const TT & tt,
Fn && op )

Iterates through each block of a truth table in reverse order.

The functor op is called for every block of the truth table in reverse order.

Parameters
ttTruth table
opUnary operation that takes as input a word (uint64_t) and returns void

Definition at line 114 of file kitty_algorithm.hpp.

115{
116 std::for_each( tt.crbegin(), tt.crend(), op );
117}
Here is the caller graph for this function:

◆ has_var() [1/2]

template<typename TT>
bool kitty::has_var ( const TT & tt,
const TT & care,
uint8_t var_index )

Checks whether truth table depends on given variable index.

Parameters
ttTruth table
careCare set
var_indexVariable index

Definition at line 244 of file kitty_operations.hpp.

245{
246 assert( var_index < tt.num_vars() );
247 assert( tt.num_vars() == care.num_vars() );
248
249 if ( tt.num_vars() <= 6 || var_index < 6 )
250 {
251 auto it_tt = std::begin( tt._bits );
252 auto it_care = std::begin( care._bits );
253 while ( it_tt != std::end( tt._bits ) )
254 {
255 if ( ( ( ( *it_tt >> ( uint64_t( 1 ) << var_index ) ) ^ *it_tt ) & detail::projections_neg[var_index]
256 & ( *it_care >> ( uint64_t( 1 ) << var_index ) ) & *it_care ) != 0 )
257 {
258 return true;
259 }
260 ++it_tt;
261 ++it_care;
262 }
263
264 return false;
265 }
266
267 const auto step = 1 << ( var_index - 6 );
268 for ( auto i = 0u; i < static_cast<uint32_t>( tt.num_blocks() ); i += 2 * step )
269 {
270 for ( auto j = 0; j < step; ++j )
271 {
272 if ( ( ( tt._bits[i + j] ^ tt._bits[i + j + step] ) & care._bits[i + j] & care._bits[i + j + step] ) != 0 )
273 {
274 return true;
275 }
276 }
277 }
278 return false;
279}

◆ has_var() [2/2]

template<typename TT>
bool kitty::has_var ( const TT & tt,
uint8_t var_index )

Checks whether truth table depends on given variable index.

Parameters
ttTruth table
var_indexVariable index

Definition at line 211 of file kitty_operations.hpp.

212{
213 assert( var_index < tt.num_vars() );
214
215 if ( tt.num_vars() <= 6 || var_index < 6 )
216 {
217 return std::any_of( std::begin( tt._bits ), std::end( tt._bits ),
218 [var_index]( uint64_t word )
219 { return ( ( word >> ( uint64_t( 1 ) << var_index ) ) & detail::projections_neg[var_index] ) !=
220 ( word & detail::projections_neg[var_index] ); } );
221 }
222
223 const auto step = 1 << ( var_index - 6 );
224 for ( auto i = 0u; i < static_cast<uint32_t>( tt.num_blocks() ); i += 2 * step )
225 {
226 for ( auto j = 0; j < step; ++j )
227 {
228 if ( tt._bits[i + j] != tt._bits[i + j + step] )
229 {
230 return true;
231 }
232 }
233 }
234 return false;
235}
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36

◆ operator&() [1/2]

dynamic_truth_table kitty::operator& ( const dynamic_truth_table & first,
const dynamic_truth_table & second )
inline

Operator for binary_and.

Definition at line 34 of file kitty_operators.hpp.

35{
36 return binary_and( first, second );
37}
TT binary_and(const TT &first, const TT &second)
Bitwise AND of two truth tables.
Here is the call graph for this function:

◆ operator&() [2/2]

template<uint32_t NumVars>
static_truth_table< NumVars > kitty::operator& ( const static_truth_table< NumVars > & first,
const static_truth_table< NumVars > & second )
inline

Operator for binary_and.

Definition at line 41 of file kitty_operators.hpp.

42{
43 return binary_and( first, second );
44}
Here is the call graph for this function:

◆ operator&=() [1/2]

void kitty::operator&= ( dynamic_truth_table & first,
const dynamic_truth_table & second )
inline

Operator for binary_and and assign.

Definition at line 47 of file kitty_operators.hpp.

48{
49 first = binary_and( first, second );
50}
Here is the call graph for this function:

◆ operator&=() [2/2]

template<uint32_t NumVars>
void kitty::operator&= ( static_truth_table< NumVars > & first,
const static_truth_table< NumVars > & second )
inline

Operator for binary_and and assign.

Definition at line 54 of file kitty_operators.hpp.

55{
56 first = binary_and( first, second );
57}
Here is the call graph for this function:

◆ operator|() [1/2]

dynamic_truth_table kitty::operator| ( const dynamic_truth_table & first,
const dynamic_truth_table & second )
inline

Operator for binary_or.

Definition at line 60 of file kitty_operators.hpp.

61{
62 return binary_or( first, second );
63}
TT binary_or(const TT &first, const TT &second)
Bitwise OR of two truth tables.
Here is the call graph for this function:

◆ operator|() [2/2]

template<uint32_t NumVars>
static_truth_table< NumVars > kitty::operator| ( const static_truth_table< NumVars > & first,
const static_truth_table< NumVars > & second )
inline

Operator for binary_or.

Definition at line 67 of file kitty_operators.hpp.

68{
69 return binary_or( first, second );
70}
Here is the call graph for this function:

◆ operator|=() [1/3]

void kitty::operator|= ( dynamic_truth_table & first,
const dynamic_truth_table & second )
inline

Operator for binary_or and assign.

Definition at line 73 of file kitty_operators.hpp.

74{
75 first = binary_or( first, second );
76}
Here is the call graph for this function:

◆ operator|=() [2/3]

template<uint32_t NumVars>
void kitty::operator|= ( static_truth_table< NumVars, false > & first,
const static_truth_table< NumVars, false > & second )
inline

Operator for binary_or and assign.

Definition at line 90 of file kitty_operators.hpp.

91{
92 // first = binary_or( first, second );
93 /* runtime improved version */
94 if ( NumVars == 7 )
95 {
96 first._bits[0] |= second._bits[0];
97 first._bits[1] |= second._bits[1];
98 }
99 else if ( NumVars == 8 )
100 {
101 first._bits[0] |= second._bits[0];
102 first._bits[1] |= second._bits[1];
103 first._bits[2] |= second._bits[2];
104 first._bits[3] |= second._bits[3];
105 }
106 else if ( NumVars == 9 )
107 {
108 first._bits[0] |= second._bits[0];
109 first._bits[1] |= second._bits[1];
110 first._bits[2] |= second._bits[2];
111 first._bits[3] |= second._bits[3];
112 first._bits[4] |= second._bits[4];
113 first._bits[5] |= second._bits[5];
114 first._bits[6] |= second._bits[6];
115 first._bits[7] |= second._bits[7];
116 }
117 else
118 {
119 for ( uint32_t i = 0; i < first.num_blocks(); ++i )
120 {
121 first._bits[i] |= second._bits[i];
122 }
123 }
124}
unsigned int uint32_t
Definition Fxch.h:32

◆ operator|=() [3/3]

template<uint32_t NumVars>
void kitty::operator|= ( static_truth_table< NumVars, true > & first,
const static_truth_table< NumVars, true > & second )
inline

Operator for binary_or and assign.

Definition at line 80 of file kitty_operators.hpp.

81{
82 // first = binary_or( first, second );
83 /* runtime improved version */
84 first._bits |= second._bits;
85 first.mask_bits();
86}

◆ operator~() [1/2]

dynamic_truth_table kitty::operator~ ( const dynamic_truth_table & tt)
inline

Operator for unary_not.

Definition at line 21 of file kitty_operators.hpp.

22{
23 return unary_not( tt );
24}
TT unary_not(const TT &tt)
Inverts all bits in a truth table.
Here is the call graph for this function:

◆ operator~() [2/2]

template<uint32_t NumVars>
static_truth_table< NumVars > kitty::operator~ ( const static_truth_table< NumVars > & tt)
inline

Operator for unary_not.

Definition at line 28 of file kitty_operators.hpp.

29{
30 return unary_not( tt );
31}
Here is the call graph for this function:

◆ print_hex()

template<typename TT>
void kitty::print_hex ( const TT & tt,
std::ostream & os = std::cout )

Prints truth table in hexadecimal representation.

The most-significant bit will be the first character of the string.

Parameters
ttTruth table
osOutput stream

Definition at line 327 of file kitty_operations.hpp.

328{
329 auto const chunk_size =
330 std::min<uint64_t>( tt.num_vars() <= 1 ? 1 : ( tt.num_bits() >> 2 ), 16 );
331
332 for_each_block_reversed( tt, [&os, chunk_size]( uint64_t word )
333 {
334 std::string chunk( chunk_size, '0' );
335
336 auto it = chunk.rbegin();
337 while (word && it != chunk.rend()) {
338 auto hex = word & 0xf;
339 if (hex < 10) {
340 *it = '0' + static_cast<char>(hex);
341 } else {
342 *it = 'a' + static_cast<char>(hex - 10);
343 }
344 ++it;
345 word >>= 4;
346 }
347 os << chunk; } );
348}
void for_each_block_reversed(const TT &tt, Fn &&op)
Iterates through each block of a truth table in reverse order.
Here is the call graph for this function:

◆ shrink_to()

template<typename TTFrom>
dynamic_truth_table kitty::shrink_to ( const TTFrom & from,
unsigned num_vars )
inline

Shrinks larger truth table to smaller dynamic one.

This is an out-of-place version of shrink_to that has the truth table as a return value. It only works for creating dynamic tables. The parameter num_vars must be equal or smaller to the number of variables in from.

Parameters
fromSmaller truth table to copy from

Definition at line 312 of file kitty_operations.hpp.

313{
314 auto tt = create<dynamic_truth_table>( num_vars );
315 shrink_to_inplace( tt, from );
316 return tt;
317}
TT create(unsigned num_vars)
Creates truth table with number of variables.
void shrink_to_inplace(TT &tt, const TTFrom &from)
Shrinks larger truth table to smaller one.
Here is the call graph for this function:

◆ shrink_to_inplace()

template<typename TT, typename TTFrom>
void kitty::shrink_to_inplace ( TT & tt,
const TTFrom & from )

Shrinks larger truth table to smaller one.

The function expects that the most significant bits, which are cut off, are not in the functional support of the original function. Only then it is ensured that the resulting function is equivalent.

Parameters
ttSmaller truth table to create
fromLarger truth table to copy from

Definition at line 291 of file kitty_operations.hpp.

292{
293 assert( tt.num_vars() <= from.num_vars() );
294
295 std::copy( from.begin(), from.begin() + tt.num_blocks(), tt.begin() );
296
297 if ( tt.num_vars() < 6 )
298 {
299 tt.mask_bits();
300 }
301}
Here is the caller graph for this function:

◆ swap_inplace() [1/2]

template<uint32_t NumVars>
void kitty::swap_inplace ( static_truth_table< NumVars, true > & tt,
uint8_t var_index1,
uint8_t var_index2 )
inline

Definition at line 136 of file kitty_operations.hpp.

137{
138 if ( var_index1 == var_index2 )
139 {
140 return;
141 }
142
143 if ( var_index1 > var_index2 )
144 {
145 std::swap( var_index1, var_index2 );
146 }
147
148 const auto& pmask = detail::ppermutation_masks[var_index1][var_index2];
149 const auto shift = ( 1 << var_index2 ) - ( 1 << var_index1 );
150 tt._bits = ( tt._bits & pmask[0] ) | ( ( tt._bits & pmask[1] ) << shift ) | ( ( tt._bits & pmask[2] ) >> shift );
151}

◆ swap_inplace() [2/2]

template<typename TT>
void kitty::swap_inplace ( TT & tt,
uint8_t var_index1,
uint8_t var_index2 )

Swaps two variables in a truth table.

The function swaps variable var_index1 with var_index2. The function will change tt in-place. If tt should not be changed, one can use swap instead.

Parameters
ttTruth table
var_index1First variable
var_index2Second variable

Definition at line 71 of file kitty_operations.hpp.

72{
73 if ( var_index1 == var_index2 )
74 {
75 return;
76 }
77
78 if ( var_index1 > var_index2 )
79 {
80 std::swap( var_index1, var_index2 );
81 }
82
83 if ( tt.num_vars() <= 6 )
84 {
85 const auto& pmask = detail::ppermutation_masks[var_index1][var_index2];
86 const auto shift = ( 1 << var_index2 ) - ( 1 << var_index1 );
87 tt._bits[0] = ( tt._bits[0] & pmask[0] ) | ( ( tt._bits[0] & pmask[1] ) << shift ) | ( ( tt._bits[0] & pmask[2] ) >> shift );
88 }
89 else if ( var_index2 <= 5 )
90 {
91 const auto& pmask = detail::ppermutation_masks[var_index1][var_index2];
92 const auto shift = ( 1 << var_index2 ) - ( 1 << var_index1 );
93 std::transform( std::begin( tt._bits ), std::end( tt._bits ), std::begin( tt._bits ),
94 [shift, &pmask]( uint64_t word )
95 {
96 return ( word & pmask[0] ) | ( ( word & pmask[1] ) << shift ) | ( ( word & pmask[2] ) >> shift );
97 } );
98 }
99 else if ( var_index1 <= 5 ) /* in this case, var_index2 > 5 */
100 {
101 const auto step = 1 << ( var_index2 - 6 );
102 const auto shift = 1 << var_index1;
103 auto it = std::begin( tt._bits );
104 while ( it != std::end( tt._bits ) )
105 {
106 for ( auto i = decltype( step ){ 0 }; i < step; ++i )
107 {
108 const auto low_to_high = ( *( it + i ) & detail::projections[var_index1] ) >> shift;
109 const auto high_to_low = ( *( it + i + step ) << shift ) & detail::projections[var_index1];
110 *( it + i ) = ( *( it + i ) & ~detail::projections[var_index1] ) | high_to_low;
111 *( it + i + step ) = ( *( it + i + step ) & detail::projections[var_index1] ) | low_to_high;
112 }
113 it += 2 * step;
114 }
115 }
116 else
117 {
118 const auto step1 = 1 << ( var_index1 - 6 );
119 const auto step2 = 1 << ( var_index2 - 6 );
120 auto it = std::begin( tt._bits );
121 while ( it != std::end( tt._bits ) )
122 {
123 for ( auto i = 0; i < step2; i += 2 * step1 )
124 {
125 for ( auto j = 0; j < step1; ++j )
126 {
127 std::swap( *( it + i + j + step1 ), *( it + i + j + step2 ) );
128 }
129 }
130 it += 2 * step2;
131 }
132 }
133}

◆ unary_not()

template<typename TT>
TT kitty::unary_not ( const TT & tt)
inline

Inverts all bits in a truth table.

Definition at line 39 of file kitty_operations.hpp.

40{
41 return unary_operation( tt, []( uint64_t a )
42 { return ~a; } );
43}
TT unary_operation(const TT &tt, Fn &&op)
Perform bitwise unary operation on truth table.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unary_not_if()

template<typename TT>
TT kitty::unary_not_if ( const TT & tt,
bool cond )
inline

Inverts all bits in a truth table, based on a condition

Definition at line 23 of file kitty_operations.hpp.

24{
25#ifdef _MSC_VER
26#pragma warning( push )
27#pragma warning( disable : 4146 )
28#endif
29 const auto mask = -static_cast<uint64_t>( cond );
30#ifdef _MSC_VER
31#pragma warning( pop )
32#endif
33 return unary_operation( tt, [mask]( uint64_t a )
34 { return a ^ mask; } );
35}
Here is the call graph for this function:

◆ unary_operation()

template<typename TT, typename Fn>
TT kitty::unary_operation ( const TT & tt,
Fn && op )

Perform bitwise unary operation on truth table.

Parameters
ttTruth table
opUnary operation that takes as input a word (uint64_t) and returns a word
Returns
new constructed truth table of same type and dimensions

Definition at line 25 of file kitty_algorithm.hpp.

26{
27 TT result = tt.construct();
28 std::transform( tt.cbegin(), tt.cend(), result.begin(), op );
29 result.mask_bits();
30 return result;
31}
Here is the caller graph for this function: