@@ -60,6 +60,7 @@ inline TT unary_not_if( const TT& tt, bool cond )
60
60
61
61
/* ! \brief Bitwise AND of two truth tables */
62
62
template <typename TT>
63
+
63
64
inline TT binary_and ( const TT& first, const TT& second )
64
65
{
65
66
return binary_operation ( first, second, std::bit_and<>() );
@@ -700,7 +701,7 @@ void extend_to( TT& tt, const TTFrom& from )
700
701
701
702
/* ! \brief Extends smaller truth table to larger static one
702
703
703
- This is a special version of extend_to that has the truth table as a return
704
+ This is a special version of ` extend_to` that has the truth table as a return
704
705
value. It only works for creating static truth tables. The template
705
706
parameter `NumVars` must be equal or larger to the number of variables in
706
707
`from`.
@@ -715,6 +716,45 @@ inline static_truth_table<NumVars> extend_to( const TTFrom& from )
715
716
return tt;
716
717
}
717
718
719
+ /* ! \brief Shrinks larger truth table to smaller one
720
+
721
+ The function expects that the most significant bits, which are cut off, are
722
+ not in the functional support of the original function. Only then it is
723
+ ensured that the resulting function is equivalent.
724
+
725
+ \param tt Smaller truth table to create
726
+ \param from Larger truth table to copy from
727
+ */
728
+ template <typename TT, typename TTFrom>
729
+ void shrink_to ( TT& tt, const TTFrom& from )
730
+ {
731
+ assert ( tt.num_vars () <= from.num_vars () );
732
+
733
+ std::copy ( from.begin (), from.begin () + tt.num_blocks (), tt.begin () );
734
+
735
+ if ( tt.num_vars () < 6 )
736
+ {
737
+ tt.mask_bits ();
738
+ }
739
+ }
740
+
741
+ /* ! \brief Shrinks larger truth table to smaller static one
742
+
743
+ This is a special version of `shrink_to` that has the truth table as a return
744
+ value. It only works for creating static truth tables. The template
745
+ parameter `NumVars` must be equal or smaller to the number of variables in
746
+ `from`.
747
+
748
+ \param from Smaller truth table to copy from
749
+ */
750
+ template <int NumVars, typename TTFrom>
751
+ inline static_truth_table<NumVars> shrink_to ( const TTFrom& from )
752
+ {
753
+ static_truth_table<NumVars> tt;
754
+ shrink_to ( tt, from );
755
+ return tt;
756
+ }
757
+
718
758
/* ! \brief Left-shift truth table
719
759
720
760
Drops overflowing most-significant bits and fills up least-significant bits
0 commit comments