From e8924e5534878acddb0f6005d20fbf45c85a0077 Mon Sep 17 00:00:00 2001 From: aletempiac Date: Thu, 11 Apr 2024 15:44:52 +0200 Subject: [PATCH] Fixes and improvements --- src/map/if/acd/ac_wrapper.cpp | 145 ++++++++++++++++++---------------- src/map/if/acd/ac_wrapper.h | 3 +- src/map/if/acd/acd66.hpp | 17 +++- src/map/if/acd/acdXX.hpp | 19 ++++- 4 files changed, 106 insertions(+), 78 deletions(-) diff --git a/src/map/if/acd/ac_wrapper.cpp b/src/map/if/acd/ac_wrapper.cpp index 7914bbd42..ad923edd2 100644 --- a/src/map/if/acd/ac_wrapper.cpp +++ b/src/map/if/acd/ac_wrapper.cpp @@ -23,94 +23,99 @@ ABC_NAMESPACE_IMPL_START -static constexpr bool use_generic_acd = true; - int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost, int try_no_late_arrival ) { using namespace acd; - if ( use_generic_acd ) + ac_decomposition_params ps; + ps.lut_size = lutSize; + ps.use_first = false; + ps.try_no_late_arrival = static_cast( try_no_late_arrival ); + ac_decomposition_stats st; + + ac_decomposition_impl acd( nVars, ps, &st ); + int val = acd.run( pTruth, *pdelay ); + + if ( val < 0 ) { - ac_decomposition_params ps; - ps.lut_size = lutSize; - ps.use_first = false; - ps.try_no_late_arrival = static_cast( try_no_late_arrival ); - ac_decomposition_stats st; - - ac_decomposition_impl acd( nVars, ps, &st ); - int val = acd.run( pTruth, *pdelay ); - - if ( val < 0 ) - { - *pdelay = 0; - return -1; - } - - *pdelay = acd.get_profile(); - *cost = st.num_luts; - - return val; + *pdelay = 0; + return -1; } - else - { - acd66_impl acd( nVars ); - int val = acd.run( pTruth, *pdelay ); - if ( val == 0 ) - { - *pdelay = 0; - return -1; - } + *pdelay = acd.get_profile(); + *cost = st.num_luts; - *pdelay = acd.get_profile(); - *cost = 2; - - return val; - } + return val; } int acd_decompose( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned char *decomposition ) { using namespace acd; - if ( use_generic_acd ) + ac_decomposition_params ps; + ps.lut_size = lutSize; + ps.use_first = true; + ac_decomposition_stats st; + + ac_decomposition_impl acd( nVars, ps, &st ); + acd.run( pTruth, *pdelay ); + int val = acd.compute_decomposition(); + + if ( val < 0 ) { - ac_decomposition_params ps; - ps.lut_size = lutSize; - ps.use_first = true; - ac_decomposition_stats st; - - ac_decomposition_impl acd( nVars, ps, &st ); - acd.run( pTruth, *pdelay ); - int val = acd.compute_decomposition(); - - if ( val < 0 ) - { - *pdelay = 0; - return -1; - } - - *pdelay = acd.get_profile(); - acd.get_decomposition( decomposition ); - return 0; + *pdelay = 0; + return -1; } - else + + *pdelay = acd.get_profile(); + acd.get_decomposition( decomposition ); + return 0; +} + +int acd2_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost, int try_no_late_arrival ) +{ + using namespace acd; + + acdXX_params ps; + ps.lut_size = lutSize; + ps.max_shared_vars = lutSize - 2; + acdXX_impl acd( nVars, ps ); + int val = acd.run( pTruth, *pdelay ); + + if ( val == 0 ) { - acd66_impl acd( nVars ); - acd.run( pTruth, *pdelay ); - int val = acd.compute_decomposition(); - - if ( val != 0 ) - { - *pdelay = 0; - return -1; - } - - *pdelay = acd.get_profile(); - - acd.get_decomposition( decomposition ); - return 0; + *pdelay = 0; + return -1; } + + acd.compute_decomposition(); + *pdelay = acd.get_profile(); + *cost = 2; + + return val; +} + +int acd2_decompose( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned char *decomposition ) +{ + using namespace acd; + + acdXX_params ps; + ps.lut_size = lutSize; + ps.max_shared_vars = lutSize - 2; + acdXX_impl acd( nVars, ps ); + acd.run( pTruth, *pdelay ); + int val = acd.compute_decomposition(); + + if ( val != 0 ) + { + *pdelay = 0; + return -1; + } + + *pdelay = acd.get_profile(); + + acd.get_decomposition( decomposition ); + return 0; } inline int acd66_decompose( word * pTruth, unsigned nVars, unsigned char *decomposition ) diff --git a/src/map/if/acd/ac_wrapper.h b/src/map/if/acd/ac_wrapper.h index a4c4bff9b..edb45ca7f 100644 --- a/src/map/if/acd/ac_wrapper.h +++ b/src/map/if/acd/ac_wrapper.h @@ -34,8 +34,9 @@ ABC_NAMESPACE_HEADER_START int acd_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost, int try_no_late_arrival ); int acd_decompose( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned char *decomposition ); +int acd2_evaluate( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned *cost, int try_no_late_arrival ); +int acd2_decompose( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay, unsigned char *decomposition ); -int acd66_decompose( word * pTruth, unsigned nVars, unsigned char *decomposition ); int acdXX_decompose( word * pTruth, unsigned lutSize, unsigned nVars, unsigned char *decomposition ); ABC_NAMESPACE_HEADER_END diff --git a/src/map/if/acd/acd66.hpp b/src/map/if/acd/acd66.hpp index 500dab361..ea7bfe951 100644 --- a/src/map/if/acd/acd66.hpp +++ b/src/map/if/acd/acd66.hpp @@ -138,9 +138,20 @@ public: if ( best_multiplicity == UINT32_MAX ) return -1; - for ( uint32_t i = 0; i < best_free_set; ++i ) + if ( bs_support_size == UINT32_MAX ) { - profile |= 1 << permutations[i]; + for ( uint32_t i = 0; i < best_free_set; ++i ) + { + profile |= 1 << permutations[i]; + } + } + else + { + for ( uint32_t i = 0; i < bs_support_size; ++i ) + { + profile |= 1 << permutations[bs_support[i] + best_free_set]; + } + profile = ~profile & ( ( 1u << num_vars ) - 1 ); } return profile; @@ -1074,7 +1085,7 @@ private: ++bytes; /* write support */ - for ( uint32_t i = best_free_set; i < best_free_set; ++i ) + for ( uint32_t i = 0; i < best_free_set; ++i ) { *pArray = (unsigned char)permutations[i]; pArray++; diff --git a/src/map/if/acd/acdXX.hpp b/src/map/if/acd/acdXX.hpp index 74d5df8d9..8dabc725e 100644 --- a/src/map/if/acd/acdXX.hpp +++ b/src/map/if/acd/acdXX.hpp @@ -155,10 +155,21 @@ public: if ( best_multiplicity == UINT32_MAX ) return -1; - - for ( uint32_t i = 0; i < best_free_set; ++i ) + + if ( bs_support_size == UINT32_MAX ) { - profile |= 1 << permutations[i]; + for ( uint32_t i = 0; i < best_free_set; ++i ) + { + profile |= 1 << permutations[i]; + } + } + else + { + for ( uint32_t i = 0; i < bs_support_size; ++i ) + { + profile |= 1 << permutations[bs_support[i] + best_free_set]; + } + profile = ~profile & ( ( 1u << num_vars ) - 1 ); } return profile; @@ -1101,7 +1112,7 @@ private: ++bytes; /* write support */ - for ( uint32_t i = best_free_set; i < best_free_set; ++i ) + for ( uint32_t i = 0; i < best_free_set; ++i ) { *pArray = (unsigned char)permutations[i]; pArray++;