abc/src/bool/kit/kitTruth.c
/**Function*************************************************************

  Synopsis    [Counts the number of 1's in each cofactor.]

  Description [The resulting numbers are stored in the array of ints, 
  whose length is 2*nVars. The number of 1's is counted in a different
  space than the original function. For example, if the function depends 
  on k variables, the cofactors are assumed to depend on k-1 variables.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Counts the number of 1's in each cofactor.]

Description [The resulting numbers are stored in the array of ints,
whose length is 2*nVars. The number of 1's is counted in a different
space than the original function. For example, if the function depends
on k variables, the cofactors are assumed to depend on k-1 variables.]




Function Synopsis [ Counts the number of 1 ' s in each cofactor . ] Description [ The resulting numbers are stored in the array of ints whose length is 2 * nVars . The number of 1 ' s is counted in a different space than the original function . For example if the function depends on k variables the cofactors are assumed to depend on k - 1 variables . ]
void Kit_TruthCountOnesInCofs( unsigned * pTruth, int nVars, int * pStore )
{
    int nWords = Kit_TruthWordNum( nVars );
    int i, k, Counter;
    memset( pStore, 0, sizeof(int) * 2 * nVars );
    if ( nVars <= 5 )
    {
        if ( nVars > 0 )
        {
            pStore[2*0+0] = Kit_WordCountOnes( pTruth[0] & 0x55555555 );
            pStore[2*0+1] = Kit_WordCountOnes( pTruth[0] & 0xAAAAAAAA );
        }
        if ( nVars > 1 )
        {
            pStore[2*1+0] = Kit_WordCountOnes( pTruth[0] & 0x33333333 );
            pStore[2*1+1] = Kit_WordCountOnes( pTruth[0] & 0xCCCCCCCC );
        }
        if ( nVars > 2 )
        {
            pStore[2*2+0] = Kit_WordCountOnes( pTruth[0] & 0x0F0F0F0F );
            pStore[2*2+1] = Kit_WordCountOnes( pTruth[0] & 0xF0F0F0F0 );
        }
        if ( nVars > 3 )
        {
            pStore[2*3+0] = Kit_WordCountOnes( pTruth[0] & 0x00FF00FF );
            pStore[2*3+1] = Kit_WordCountOnes( pTruth[0] & 0xFF00FF00 );
        }
        if ( nVars > 4 )
        {
            pStore[2*4+0] = Kit_WordCountOnes( pTruth[0] & 0x0000FFFF );
            pStore[2*4+1] = Kit_WordCountOnes( pTruth[0] & 0xFFFF0000 );
        }
        return;
    }
    for ( k = 0; k < nWords; k++ )
    {
        Counter = Kit_WordCountOnes( pTruth[k] );
        for ( i = 5; i < nVars; i++ )
            if ( k & (1 << (i-5)) )
                pStore[2*i+1] += Counter;
            else
                pStore[2*i+0] += Counter;
    }
    for ( k = 0; k < nWords/2; k++ )
    {
        pStore[2*0+0] += Kit_WordCountOnes( (pTruth[0] & 0x55555555) | ((pTruth[1] & 0x55555555) <<  1) );
        pStore[2*0+1] += Kit_WordCountOnes( (pTruth[0] & 0xAAAAAAAA) | ((pTruth[1] & 0xAAAAAAAA) >>  1) );
        pStore[2*1+0] += Kit_WordCountOnes( (pTruth[0] & 0x33333333) | ((pTruth[1] & 0x33333333) <<  2) );
        pStore[2*1+1] += Kit_WordCountOnes( (pTruth[0] & 0xCCCCCCCC) | ((pTruth[1] & 0xCCCCCCCC) >>  2) );
        pStore[2*2+0] += Kit_WordCountOnes( (pTruth[0] & 0x0F0F0F0F) | ((pTruth[1] & 0x0F0F0F0F) <<  4) );
        pStore[2*2+1] += Kit_WordCountOnes( (pTruth[0] & 0xF0F0F0F0) | ((pTruth[1] & 0xF0F0F0F0) >>  4) );
        pStore[2*3+0] += Kit_WordCountOnes( (pTruth[0] & 0x00FF00FF) | ((pTruth[1] & 0x00FF00FF) <<  8) );
        pStore[2*3+1] += Kit_WordCountOnes( (pTruth[0] & 0xFF00FF00) | ((pTruth[1] & 0xFF00FF00) >>  8) );
        pStore[2*4+0] += Kit_WordCountOnes( (pTruth[0] & 0x0000FFFF) | ((pTruth[1] & 0x0000FFFF) << 16) );
        pStore[2*4+1] += Kit_WordCountOnes( (pTruth[0] & 0xFFFF0000) | ((pTruth[1] & 0xFFFF0000) >> 16) );
        pTruth += 2;
    }
}
void Kit_TruthCountOnesInCofs ( unsigned * pTruth , int nVars , int * pStore ) { int nWords = Kit_TruthWordNum ( nVars ) ; int i , k , Counter ; memset ( pStore , 0 , sizeof ( int ) * 2 * nVars ) ; if ( nVars <= 5 ) { if ( nVars > 0 ) { pStore [ 2 * 0 + 0 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x55555555 ) ; pStore [ 2 * 0 + 1 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0xAAAAAAAA ) ; } if ( nVars > 1 ) { pStore [ 2 * 1 + 0 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x33333333 ) ; pStore [ 2 * 1 + 1 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0xCCCCCCCC ) ; } if ( nVars > 2 ) { pStore [ 2 * 2 + 0 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x0F0F0F0F ) ; pStore [ 2 * 2 + 1 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0xF0F0F0F0 ) ; } if ( nVars > 3 ) { pStore [ 2 * 3 + 0 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x00FF00FF ) ; pStore [ 2 * 3 + 1 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0xFF00FF00 ) ; } if ( nVars > 4 ) { pStore [ 2 * 4 + 0 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x0000FFFF ) ; pStore [ 2 * 4 + 1 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0xFFFF0000 ) ; } return ; } for ( k = 0 ; k < nWords ; k ++ ) { Counter = Kit_WordCountOnes ( pTruth [ k ] ) ; for ( i = 5 ; i < nVars ; i ++ ) if ( k & ( 1 << ( i - 5 ) ) ) pStore [ 2 * i + 1 ] += Counter ; else pStore [ 2 * i + 0 ] += Counter ; } for ( k = 0 ; k < nWords / 2 ; k ++ ) { pStore [ 2 * 0 + 0 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x55555555 ) | ( ( pTruth [ 1 ] & 0x55555555 ) << 1 ) ) ; pStore [ 2 * 0 + 1 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0xAAAAAAAA ) | ( ( pTruth [ 1 ] & 0xAAAAAAAA ) >> 1 ) ) ; pStore [ 2 * 1 + 0 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x33333333 ) | ( ( pTruth [ 1 ] & 0x33333333 ) << 2 ) ) ; pStore [ 2 * 1 + 1 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0xCCCCCCCC ) | ( ( pTruth [ 1 ] & 0xCCCCCCCC ) >> 2 ) ) ; pStore [ 2 * 2 + 0 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x0F0F0F0F ) | ( ( pTruth [ 1 ] & 0x0F0F0F0F ) << 4 ) ) ; pStore [ 2 * 2 + 1 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0xF0F0F0F0 ) | ( ( pTruth [ 1 ] & 0xF0F0F0F0 ) >> 4 ) ) ; pStore [ 2 * 3 + 0 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x00FF00FF ) | ( ( pTruth [ 1 ] & 0x00FF00FF ) << 8 ) ) ; pStore [ 2 * 3 + 1 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0xFF00FF00 ) | ( ( pTruth [ 1 ] & 0xFF00FF00 ) >> 8 ) ) ; pStore [ 2 * 4 + 0 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x0000FFFF ) | ( ( pTruth [ 1 ] & 0x0000FFFF ) << 16 ) ) ; pStore [ 2 * 4 + 1 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0xFFFF0000 ) | ( ( pTruth [ 1 ] & 0xFFFF0000 ) >> 16 ) ) ; pTruth += 2 ; } }
Function
Synopsis    [Counts the number of 1's in each cofactor.]
Function Synopsis [ Counts the number of 1 ' s in each cofactor . ]
// nVars >= 6 // count 1's for all other variables // count 1's for the first five variables