mirror of https://github.com/YosysHQ/abc.git
Cleaning and generalizing code
This commit is contained in:
parent
64fea5c4c2
commit
32bc1d4ab2
|
|
@ -19700,7 +19700,7 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
globalUtilOptind++;
|
||||
if ( strlen(pPars->pLutStruct) != 2 && strlen(pPars->pLutStruct) != 3 )
|
||||
{
|
||||
Abc_Print( -1, "Command line switch \"-J\" should be followed by a 2- or 3-char string (e.g. \"66\" or \"666\").\n" );
|
||||
Abc_Print( -1, "Command line switch \"-J\" should be followed by a 2-char string (e.g. \"44\" or \"66\" \").\n" );
|
||||
goto usage;
|
||||
}
|
||||
break;
|
||||
|
|
@ -19883,7 +19883,7 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
}
|
||||
if ( pPars->fEnableStructN )
|
||||
{
|
||||
pPars->pFuncCell = pPars->fDelayOptLut ? NULL : If_CutPerformCheck66;
|
||||
pPars->pFuncCell = pPars->fDelayOptLut ? NULL : If_CutPerformCheckXX;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
#include "ac_wrapper.h"
|
||||
#include "ac_decomposition.hpp"
|
||||
#include "acd66.hpp"
|
||||
#include "acd666.hpp"
|
||||
#include "acdXX.hpp"
|
||||
|
||||
ABC_NAMESPACE_IMPL_START
|
||||
|
||||
|
|
@ -113,61 +113,49 @@ int acd_decompose( word * pTruth, unsigned nVars, int lutSize, unsigned *pdelay,
|
|||
}
|
||||
}
|
||||
|
||||
int acd66_evaluate( word * pTruth, unsigned nVars, int compute_decomposition )
|
||||
inline int acd66_decompose( word * pTruth, unsigned nVars, unsigned char *decomposition )
|
||||
{
|
||||
using namespace acd;
|
||||
|
||||
acd66_impl acd( nVars, true, false );
|
||||
|
||||
if ( acd.run( pTruth ) == 0 )
|
||||
return 0;
|
||||
|
||||
if ( !compute_decomposition )
|
||||
if ( decomposition == NULL )
|
||||
return 1;
|
||||
|
||||
int val = acd.compute_decomposition();
|
||||
if ( val != 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
acd.get_decomposition( decomposition );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int acd66_decompose( word * pTruth, unsigned nVars, unsigned char *decomposition )
|
||||
int acdXX_decompose( word * pTruth, unsigned lutSize, unsigned nVars, unsigned char *decomposition )
|
||||
{
|
||||
using namespace acd;
|
||||
|
||||
acd66_impl acd( nVars, true, false );
|
||||
acd.run( pTruth );
|
||||
|
||||
int val = acd.compute_decomposition();
|
||||
if ( val != 0 )
|
||||
if ( lutSize == 6 )
|
||||
{
|
||||
return -1;
|
||||
return acd66_decompose( pTruth, nVars, decomposition );
|
||||
}
|
||||
|
||||
acd.get_decomposition( decomposition );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int acd666_evaluate( word * pTruth, unsigned nVars, int compute_decomposition )
|
||||
{
|
||||
using namespace acd;
|
||||
|
||||
acd666_impl acd( nVars, false );
|
||||
|
||||
acdXX_params ps;
|
||||
ps.lut_size = lutSize;
|
||||
ps.max_shared_vars = lutSize - 2;
|
||||
acdXX_impl acd( nVars, ps );
|
||||
|
||||
if ( acd.run( pTruth ) == 0 )
|
||||
return 0;
|
||||
|
||||
if ( !compute_decomposition )
|
||||
if ( decomposition == NULL )
|
||||
return 1;
|
||||
|
||||
int val = acd.compute_decomposition();
|
||||
if ( val != 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
acd.get_decomposition( decomposition );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,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 acdXX_evaluate( word * pTruth, unsigned lutSize, unsigned nVars, int compute_decomposition );
|
||||
int acd66_decompose( word * pTruth, unsigned nVars, unsigned char *decomposition );
|
||||
int acdXX_decompose( word * pTruth, unsigned lutSize, unsigned nVars, unsigned char *decomposition );
|
||||
|
||||
int acd666_evaluate( word * pTruth, unsigned nVars, int compute_decomposition );
|
||||
|
||||
ABC_NAMESPACE_HEADER_END
|
||||
|
||||
#endif
|
||||
|
|
@ -215,7 +215,7 @@ private:
|
|||
local_extend_to( start_tt, num_vars );
|
||||
}
|
||||
|
||||
uint32_t column_multiplicity( STT const& tt, uint32_t free_set_size )
|
||||
uint32_t column_multiplicity( STT const& tt, uint32_t const free_set_size )
|
||||
{
|
||||
assert( free_set_size <= 5 );
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ private:
|
|||
return size;
|
||||
}
|
||||
|
||||
uint32_t column_multiplicity2( STT const& tt, uint32_t free_set_size, uint32_t const limit )
|
||||
uint32_t column_multiplicity2( STT const& tt, uint32_t const free_set_size, uint32_t const limit )
|
||||
{
|
||||
assert( free_set_size <= 5 );
|
||||
|
||||
|
|
@ -1198,8 +1198,6 @@ private:
|
|||
private:
|
||||
uint32_t best_multiplicity{ UINT32_MAX };
|
||||
uint32_t best_free_set{ UINT32_MAX };
|
||||
uint32_t best_multiplicity0{ UINT32_MAX };
|
||||
uint32_t best_multiplicity1{ UINT32_MAX };
|
||||
uint32_t bs_support_size{ UINT32_MAX };
|
||||
uint32_t num_shared_vars{ 0 };
|
||||
STT best_tt;
|
||||
|
|
|
|||
|
|
@ -46,8 +46,13 @@ namespace acd
|
|||
|
||||
struct acdXX_params
|
||||
{
|
||||
/* Nymber of inputs of the LUT */
|
||||
uint32_t lut_size{ 6 };
|
||||
|
||||
/* Maximum number of variables in the shared set */
|
||||
uint32_t max_shared_vars{ 4 };
|
||||
|
||||
/* Run verification */
|
||||
bool verify{ false };
|
||||
};
|
||||
|
||||
|
|
@ -228,7 +233,7 @@ private:
|
|||
local_extend_to( start_tt, num_vars );
|
||||
}
|
||||
|
||||
uint32_t column_multiplicity( STT const& tt, uint32_t free_set_size )
|
||||
uint32_t column_multiplicity( STT const& tt, uint32_t const free_set_size )
|
||||
{
|
||||
assert( free_set_size <= 5 );
|
||||
|
||||
|
|
@ -264,7 +269,7 @@ private:
|
|||
return size;
|
||||
}
|
||||
|
||||
uint32_t column_multiplicity2( STT const& tt, uint32_t free_set_size, uint32_t const limit )
|
||||
uint32_t column_multiplicity2( STT const& tt, uint32_t const free_set_size, uint32_t const limit )
|
||||
{
|
||||
assert( free_set_size <= 5 );
|
||||
|
||||
|
|
@ -412,9 +417,6 @@ private:
|
|||
bool find_decomposition_bs_offset( uint32_t free_set_size, uint32_t offset )
|
||||
{
|
||||
STT tt = best_tt;
|
||||
|
||||
/* works up to 11 input truth tables */
|
||||
assert( num_vars <= 11 );
|
||||
best_free_set = free_set_size;
|
||||
|
||||
/* special case */
|
||||
|
|
@ -504,9 +506,6 @@ private:
|
|||
{
|
||||
STT tt = start_tt;
|
||||
|
||||
/* works up to 11 input truth tables */
|
||||
assert( num_vars <= 11 );
|
||||
|
||||
/* init combinations */
|
||||
uint32_t pComb[11], pInvPerm[11], shared_set[4];
|
||||
for ( uint32_t i = 0; i < num_vars; ++i )
|
||||
|
|
@ -1225,8 +1224,6 @@ private:
|
|||
private:
|
||||
uint32_t best_multiplicity{ UINT32_MAX };
|
||||
uint32_t best_free_set{ UINT32_MAX };
|
||||
uint32_t best_multiplicity0{ UINT32_MAX };
|
||||
uint32_t best_multiplicity1{ UINT32_MAX };
|
||||
uint32_t bs_support_size{ UINT32_MAX };
|
||||
uint32_t num_shared_vars{ 0 };
|
||||
STT best_tt;
|
||||
|
|
|
|||
|
|
@ -552,7 +552,7 @@ extern int If_CutPerformCheck07( If_Man_t * p, unsigned * pTruth, in
|
|||
extern int If_CutPerformCheck08( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
extern int If_CutPerformCheck10( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
extern int If_CutPerformCheck16( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
extern int If_CutPerformCheck66( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
extern int If_CutPerformCheckXX( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
extern int If_CutPerformCheck45( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
extern int If_CutPerformCheck54( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
extern int If_CutPerformCheck75( If_Man_t * p, unsigned * pTruth, int nVars, int nLeaves, char * pStr );
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
ABC_NAMESPACE_IMPL_START
|
||||
|
||||
#define CLU_VAR_MAX 16
|
||||
#define CLU_VAR_MAX 11
|
||||
#define CLU_MEM_MAX 1000 // 1 GB
|
||||
#define CLU_UNUSED 0xff
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ unsigned * If_CluHashLookup2( If_Man_t * p, word * pTruth, int t )
|
|||
}
|
||||
|
||||
// returns if successful
|
||||
int If_CluCheck66( If_Man_t * p, word * pTruth0, int nVars, int fHashing )
|
||||
int If_CluCheckXX( If_Man_t * p, word * pTruth0, int lutSize, int nVars, int fHashing )
|
||||
{
|
||||
If_Grp_t G1 = {0};
|
||||
unsigned * pHashed = NULL;
|
||||
|
|
@ -267,32 +267,7 @@ int If_CluCheck66( If_Man_t * p, word * pTruth0, int nVars, int fHashing )
|
|||
/* new entry */
|
||||
if ( G1.nVars == 0 )
|
||||
{
|
||||
G1.nVars = acd66_evaluate( pTruth0, nVars, 0 );
|
||||
}
|
||||
|
||||
if ( pHashed )
|
||||
*pHashed = If_CluGrp2Uns2( &G1 );
|
||||
|
||||
return G1.nVars;
|
||||
}
|
||||
|
||||
// returns if successful
|
||||
int If_CluCheck666( If_Man_t * p, word * pTruth0, int nVars, int fHashing )
|
||||
{
|
||||
If_Grp_t G1 = {0};
|
||||
unsigned * pHashed = NULL;
|
||||
|
||||
if ( p && fHashing )
|
||||
{
|
||||
pHashed = If_CluHashLookup2( p, pTruth0, 0 );
|
||||
if ( pHashed && *pHashed != CLU_UNUSED )
|
||||
If_CluUns2Grp2( *pHashed, &G1 );
|
||||
}
|
||||
|
||||
/* new entry */
|
||||
if ( G1.nVars == 0 )
|
||||
{
|
||||
G1.nVars = acd666_evaluate( pTruth0, nVars, 0 );
|
||||
G1.nVars = acdXX_decompose( pTruth0, lutSize, nVars, NULL );
|
||||
}
|
||||
|
||||
if ( pHashed )
|
||||
|
|
@ -312,12 +287,11 @@ int If_CluCheck666( If_Man_t * p, word * pTruth0, int nVars, int fHashing )
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int If_CutPerformCheck66( If_Man_t * p, unsigned * pTruth0, int nVars, int nLeaves, char * pStr )
|
||||
int If_CutPerformCheckXX( If_Man_t * p, unsigned * pTruth0, int nVars, int nLeaves, char * pStr )
|
||||
{
|
||||
unsigned pTruth[IF_MAX_FUNC_LUTSIZE > 5 ? 1 << (IF_MAX_FUNC_LUTSIZE - 5) : 1];
|
||||
int i, Length;
|
||||
int Length;
|
||||
// stretch the truth table
|
||||
assert( nVars >= 6 );
|
||||
memcpy( pTruth, pTruth0, sizeof(word) * Abc_TtWordNum(nVars) );
|
||||
Abc_TtStretch6( (word *)pTruth, nLeaves, p->pPars->nLutSize );
|
||||
|
||||
|
|
@ -327,35 +301,30 @@ int If_CutPerformCheck66( If_Man_t * p, unsigned * pTruth0, int nVars, int nLeav
|
|||
|
||||
// quit if parameters are wrong
|
||||
Length = strlen(pStr);
|
||||
if ( Length != 2 && Length != 3 )
|
||||
if ( Length != 2 )
|
||||
{
|
||||
printf( "Wrong LUT struct (%s)\n", pStr );
|
||||
return 0;
|
||||
}
|
||||
for ( i = 0; i < Length; i++ )
|
||||
|
||||
int lutSize = pStr[0] - '0';
|
||||
if ( lutSize < 3 || lutSize > 6 )
|
||||
{
|
||||
if ( pStr[i] != '6' )
|
||||
{
|
||||
printf( "The LUT size (%d) should belong to {6}.\n", pStr[i] - '0' );
|
||||
return 0;
|
||||
}
|
||||
printf( "The LUT size (%d) should belong to {3,4,5,6}.\n", lutSize );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( ( Length == 2 && nLeaves > 11 ) || ( Length == 3 && nLeaves > 16 ) )
|
||||
if ( nLeaves >= 2 * lutSize )
|
||||
{
|
||||
printf( "The cut size (%d) is too large for the LUT structure %s.\n", nLeaves, pStr );
|
||||
return 0;
|
||||
}
|
||||
|
||||
// consider easy case
|
||||
if ( nLeaves <= 6 )
|
||||
// consider trivial case
|
||||
if ( nLeaves <= lutSize )
|
||||
return 1;
|
||||
|
||||
// derive the decomposition
|
||||
if ( Length == 2 )
|
||||
return If_CluCheck66(p, (word*)pTruth, nVars, 1);
|
||||
else
|
||||
return If_CluCheck666(p, (word*)pTruth, nVars, 1);
|
||||
return If_CluCheckXX(p, (word*)pTruth, lutSize, nVars, 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
Loading…
Reference in New Issue