chore: `__builtin_popcount` to replace BitCount8

This replaces all occurrences of the `BitCount8` static array with the
`__builtin_popcount`. It is a rather simple and small PR.

Fixes #308.
This commit is contained in:
coastalwhite 2024-07-24 21:46:03 +02:00
parent 6262dcffa9
commit fe3b5bf5fe
8 changed files with 11 additions and 79 deletions

View File

@ -225,7 +225,7 @@ void Nf_StoCreateGateAdd( Vec_Mem_t * vTtMem, Vec_Wec_t * vTt2Match, Mio_Cell2_t
if ( fPinQuick ) // reduce the number of matches agressively
{
Vec_IntForEachEntryDouble( vArray, GateId, Entry, i )
if ( GateId == (int)pCell->Id && Abc_TtBitCount8[Nf_Int2Cfg(Entry).Phase] == Abc_TtBitCount8[Mat.Phase] )
if ( GateId == (int)pCell->Id && __builtin_popcount( Nf_Int2Cfg(Entry).Phase & 0xff ) == __builtin_popcount( Mat.Phase & 0xff ) )
return;
}
else // reduce the number of matches less agressively

View File

@ -80,18 +80,6 @@ void ExorVar( Cube * pC, int Var, varvalue Val );
/// STATIC VARIABLES ///
////////////////////////////////////////////////////////////////////////
// the bit count for the first 256 integer numbers
static unsigned char BitCount8[256] = {
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
};
static int SparseNumbers[163] = {
0,1,4,5,16,17,20,21,64,65,68,69,80,81,84,85,256,257,260,
261,272,273,276,277,320,321,324,325,336,337,340,1024,1025,
@ -158,7 +146,7 @@ void PrepareBitSetModule()
nLimit = FULL16BITS;
for ( i = 0; i < nLimit; i++ )
{
BitCount[i] = BitCount8[ i & 0xff ] + BitCount8[ i>>8 ];
BitCount[i] = __builtin_popcount( i & 0xffff );
BitGroupNumbers[i] = MARKNUMBER;
}
// prepare bit groups

View File

@ -460,18 +460,6 @@ void Experiment2( BFunc * pFunc )
/// SINGLE OUTPUT FUNCTION ///
////////////////////////////////////////////////////////////////////////
// the bit count for the first 256 integer numbers
//static unsigned char BitCount8[256] = {
// 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
// 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
// 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
// 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
// 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
// 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
// 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
// 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
//};
/////////////////////////////////////////////////////////////
static int s_SuppSize[MAXOUTPUTS];
int CompareSupports( int *ptrX, int *ptrY )

View File

@ -29,17 +29,6 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
// the bit count for the first 256 integer numbers
static int BitCount8[256] = {
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
};
// variable swapping code
static word PMasks[5][3] = {
{ ABC_CONST(0x9999999999999999), ABC_CONST(0x2222222222222222), ABC_CONST(0x4444444444444444) },
@ -208,7 +197,7 @@ static inline int If_Dec6CofCount2( word t )
int i, Mask = 0;
for ( i = 0; i < 16; i++ )
Mask |= (1 << ((t >> (i<<2)) & 15));
return BitCount8[((unsigned char*)&Mask)[0]] + BitCount8[((unsigned char*)&Mask)[1]];
return __builtin_popcount( Mask & 0xffff );
}
// count the number of unique cofactors (up to 3)
static inline int If_Dec7CofCount3( word t[2] )
@ -696,7 +685,7 @@ static inline word If_Dec5CofCount2( word t, int x, int y, int * Pla2Var, word t
for ( Mask = i = 0; i < 16; i++ )
if ( ((i >> x) & 1) == ((m >> 0) & 1) && ((i >> y) & 1) == ((m >> 1) & 1) )
Mask |= (1 << ((t >> (i<<1)) & 3));
if ( BitCount8[Mask & 0xF] > 2 )
if ( __builtin_popcount( Mask & 0xF ) > 2 )
return 0;
}
// Kit_DsdPrintFromTruth( (unsigned *)&t, 5 ); printf( "\n" );
@ -726,12 +715,12 @@ static inline word If_Dec5CofCount2( word t, int x, int y, int * Pla2Var, word t
if ( ((i >> x) & 1) == ((m >> 0) & 1) && ((i >> y) & 1) == ((m >> 1) & 1) )
Mask |= (1 << ((t >> (i<<1)) & 3));
// find the values
if ( BitCount8[Mask & 0xF] == 1 )
if ( __builtin_popcount( Mask & 0xF ) == 1 )
{
C2[m] = F[Abc_Tt6FirstBit( Mask )];
D2[m] = ~(word)0;
}
else if ( BitCount8[Mask & 0xF] == 2 )
else if ( __builtin_popcount( Mask & 0xF ) == 2 )
{
int Bit0 = Abc_Tt6FirstBit( Mask );
int Bit1 = Abc_Tt6FirstBit( Mask ^ (((word)1)<<Bit0) );

View File

@ -29,17 +29,6 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
// the bit count for the first 256 integer numbers
static int BitCount8[256] = {
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
};
// variable swapping code
static word PMasks[5][3] = {
{ ABC_CONST(0x9999999999999999), ABC_CONST(0x2222222222222222), ABC_CONST(0x4444444444444444) },
@ -374,7 +363,7 @@ void If_Dec08Cofactors( word * pF, int nVars, int iVar, word * pCof0, word * pCo
static inline int If_Dec08Count16( int Num16 )
{
assert( Num16 < (1<<16)-1 );
return BitCount8[Num16 & 255] + BitCount8[(Num16 >> 8) & 255];
return __builtin_popcount( Num16 & 0xffff );
}
static inline void If_DecVerifyPerm( int Pla2Var[10], int Var2Pla[10], int nVars )
{

View File

@ -29,17 +29,6 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
// the bit count for the first 256 integer numbers
static int BitCount8[256] = {
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
};
// variable swapping code
static word PMasks[5][3] = {
{ ABC_CONST(0x9999999999999999), ABC_CONST(0x2222222222222222), ABC_CONST(0x4444444444444444) },
@ -371,7 +360,7 @@ void If_Dec10Cofactors( word * pF, int nVars, int iVar, word * pCof0, word * pCo
static inline int If_Dec10Count16( int Num16 )
{
assert( Num16 < (1<<16)-1 );
return BitCount8[Num16 & 255] + BitCount8[(Num16 >> 8) & 255];
return __builtin_popcount( Num16 & 0xffff );
}
static inline void If_DecVerifyPerm( int Pla2Var[10], int Var2Pla[10], int nVars )
{

View File

@ -129,18 +129,7 @@ static word s_PPMasks[5][6][3] = {
}
};
// the bit count for the first 256 integer numbers
static int Abc_TtBitCount8[256] = {
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
};
static inline int Abc_TtBitCount16( int i ) { return Abc_TtBitCount8[i & 0xFF] + Abc_TtBitCount8[i >> 8]; }
static inline int Abc_TtBitCount16( int i ) { return __builtin_popcount( i & 0xffff ); }
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///

View File

@ -380,7 +380,7 @@ static int Abc_TtScc6(word wTruth, int ck)
if (!wTruth) return 0;
for (i = 0; i < 64; i++)
if (wTruth & (word)1 << i) {
int ci = Abc_TtBitCount8[i] + ck;
int ci = __builtin_popcount( i & 0xff ) + ck;
sum += shiftFunc(ci);
}
return sum;
@ -406,7 +406,7 @@ static inline void Abc_TtSccInCofs6(word wTruth, int nVars, int ck, int * pStore
{
if (wTruth & (word)1 << j)
{
int ci = Abc_TtBitCount8[i] + ck;
int ci = __builtin_popcount( i & 0xff ) + ck;
sum += shiftFunc(ci);
}
i++;