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

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

  Description [The resulting numbers are stored in the array of ints, 
  whose length is 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 negative cofactor.]

Description [The resulting numbers are stored in the array of ints,
whose length is 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 negative cofactor . ] Description [ The resulting numbers are stored in the array of ints whose length is 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_TruthCountOnesInCofs0( unsigned * pTruth, int nVars, int * pStore )
{
    int nWords = Kit_TruthWordNum( nVars );
    int i, k, Counter;
    memset( pStore, 0, sizeof(int) * nVars );
    if ( nVars <= 5 )
    {
        if ( nVars > 0 )
            pStore[0] = Kit_WordCountOnes( pTruth[0] & 0x55555555 );
        if ( nVars > 1 )
            pStore[1] = Kit_WordCountOnes( pTruth[0] & 0x33333333 );
        if ( nVars > 2 )
            pStore[2] = Kit_WordCountOnes( pTruth[0] & 0x0F0F0F0F );
        if ( nVars > 3 )
            pStore[3] = Kit_WordCountOnes( pTruth[0] & 0x00FF00FF );
        if ( nVars > 4 )
            pStore[4] = Kit_WordCountOnes( pTruth[0] & 0x0000FFFF );
        return;
    }
    for ( k = 0; k < nWords; k++ )
    {
        Counter = Kit_WordCountOnes( pTruth[k] );
        for ( i = 5; i < nVars; i++ )
            if ( (k & (1 << (i-5))) == 0 )
                pStore[i] += Counter;
    }
    for ( k = 0; k < nWords/2; k++ )
    {
        pStore[0] += Kit_WordCountOnes( (pTruth[0] & 0x55555555) | ((pTruth[1] & 0x55555555) <<  1) );
        pStore[1] += Kit_WordCountOnes( (pTruth[0] & 0x33333333) | ((pTruth[1] & 0x33333333) <<  2) );
        pStore[2] += Kit_WordCountOnes( (pTruth[0] & 0x0F0F0F0F) | ((pTruth[1] & 0x0F0F0F0F) <<  4) );
        pStore[3] += Kit_WordCountOnes( (pTruth[0] & 0x00FF00FF) | ((pTruth[1] & 0x00FF00FF) <<  8) );
        pStore[4] += Kit_WordCountOnes( (pTruth[0] & 0x0000FFFF) | ((pTruth[1] & 0x0000FFFF) << 16) );
        pTruth += 2;
    }
}
void Kit_TruthCountOnesInCofs0 ( unsigned * pTruth , int nVars , int * pStore ) { int nWords = Kit_TruthWordNum ( nVars ) ; int i , k , Counter ; memset ( pStore , 0 , sizeof ( int ) * nVars ) ; if ( nVars <= 5 ) { if ( nVars > 0 ) pStore [ 0 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x55555555 ) ; if ( nVars > 1 ) pStore [ 1 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x33333333 ) ; if ( nVars > 2 ) pStore [ 2 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x0F0F0F0F ) ; if ( nVars > 3 ) pStore [ 3 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x00FF00FF ) ; if ( nVars > 4 ) pStore [ 4 ] = Kit_WordCountOnes ( pTruth [ 0 ] & 0x0000FFFF ) ; return ; } for ( k = 0 ; k < nWords ; k ++ ) { Counter = Kit_WordCountOnes ( pTruth [ k ] ) ; for ( i = 5 ; i < nVars ; i ++ ) if ( ( k & ( 1 << ( i - 5 ) ) ) == 0 ) pStore [ i ] += Counter ; } for ( k = 0 ; k < nWords / 2 ; k ++ ) { pStore [ 0 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x55555555 ) | ( ( pTruth [ 1 ] & 0x55555555 ) << 1 ) ) ; pStore [ 1 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x33333333 ) | ( ( pTruth [ 1 ] & 0x33333333 ) << 2 ) ) ; pStore [ 2 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x0F0F0F0F ) | ( ( pTruth [ 1 ] & 0x0F0F0F0F ) << 4 ) ) ; pStore [ 3 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x00FF00FF ) | ( ( pTruth [ 1 ] & 0x00FF00FF ) << 8 ) ) ; pStore [ 4 ] += Kit_WordCountOnes ( ( pTruth [ 0 ] & 0x0000FFFF ) | ( ( pTruth [ 1 ] & 0x0000FFFF ) << 16 ) ) ; pTruth += 2 ; } }
Function
Synopsis    [Counts the number of 1's in each negative cofactor.]
Function Synopsis [ Counts the number of 1 ' s in each negative cofactor . ]
// nVars >= 6 // count 1's for all other variables // count 1's for the first five variables