00001
00021 #include "cutInt.h"
00022
00026
00027 #define CUT_CELL_MVAR 9
00028
00032
00044 static inline unsigned Cut_TruthPhase( Cut_Cut_t * pCut, Cut_Cut_t * pCut1 )
00045 {
00046 unsigned uPhase = 0;
00047 int i, k;
00048 for ( i = k = 0; i < (int)pCut->nLeaves; i++ )
00049 {
00050 if ( k == (int)pCut1->nLeaves )
00051 break;
00052 if ( pCut->pLeaves[i] < pCut1->pLeaves[k] )
00053 continue;
00054 assert( pCut->pLeaves[i] == pCut1->pLeaves[k] );
00055 uPhase |= (1 << i);
00056 k++;
00057 }
00058 return uPhase;
00059 }
00060
00078 void Cut_TruthCompose( Cut_Cut_t * pCutF, int Node, Cut_Cut_t * pCutT, Cut_Cut_t * pCutRes )
00079 {
00080 static unsigned uCof0[1<<(CUT_CELL_MVAR-5)];
00081 static unsigned uCof1[1<<(CUT_CELL_MVAR-5)];
00082 static unsigned uTemp[1<<(CUT_CELL_MVAR-5)];
00083 unsigned * pIn, * pOut, * pTemp;
00084 unsigned uPhase;
00085 int NodeIndex, i, k;
00086
00087
00088 assert( pCutF->nVarsMax == pCutT->nVarsMax );
00089 assert( pCutF->nVarsMax == pCutRes->nVarsMax );
00090 assert( pCutF->nVarsMax <= CUT_CELL_MVAR );
00091
00092 assert( pCutF->nLeaves <= pCutF->nVarsMax );
00093 for ( i = 0; i < (int)pCutF->nLeaves - 1; i++ )
00094 assert( pCutF->pLeaves[i] < pCutF->pLeaves[i+1] );
00095
00096 assert( pCutT->nLeaves <= pCutT->nVarsMax );
00097 for ( i = 0; i < (int)pCutT->nLeaves - 1; i++ )
00098 assert( pCutT->pLeaves[i] < pCutT->pLeaves[i+1] );
00099
00100 assert( pCutRes->nLeaves <= pCutRes->nVarsMax );
00101 for ( i = 0; i < (int)pCutRes->nLeaves - 1; i++ )
00102 assert( pCutRes->pLeaves[i] < pCutRes->pLeaves[i+1] );
00103
00104 for ( i = 0; i < (int)pCutF->nLeaves; i++ )
00105 {
00106 if ( pCutF->pLeaves[i] == Node )
00107 continue;
00108 for ( k = 0; k < (int)pCutRes->nLeaves; k++ )
00109 if ( pCutF->pLeaves[i] == pCutRes->pLeaves[k] )
00110 break;
00111 assert( k < (int)pCutRes->nLeaves );
00112 }
00113
00114 for ( i = 0; i < (int)pCutT->nLeaves; i++ )
00115 {
00116 for ( k = 0; k < (int)pCutRes->nLeaves; k++ )
00117 if ( pCutT->pLeaves[i] == pCutRes->pLeaves[k] )
00118 break;
00119 assert( k < (int)pCutRes->nLeaves );
00120 }
00121
00122
00123
00124 NodeIndex = -1;
00125 for ( NodeIndex = 0; NodeIndex < (int)pCutF->nLeaves; NodeIndex++ )
00126 if ( pCutF->pLeaves[NodeIndex] == Node )
00127 break;
00128 assert( NodeIndex >= 0 );
00129
00130
00131 Extra_TruthCopy( uTemp, Cut_CutReadTruth(pCutF), pCutF->nLeaves );
00132
00133
00134 pIn = uTemp; pOut = uCof0;
00135 for ( i = NodeIndex; i < (int)pCutF->nLeaves - 1; i++ )
00136 {
00137 Extra_TruthSwapAdjacentVars( pOut, pIn, pCutF->nLeaves, i );
00138 pTemp = pIn; pIn = pOut; pOut = pTemp;
00139 }
00140 if ( (pCutF->nLeaves - 1 - NodeIndex) & 1 )
00141 Extra_TruthCopy( pOut, pIn, pCutF->nLeaves );
00142
00143
00144
00145 Extra_TruthCopy( uCof0, uTemp, pCutF->nLeaves );
00146 Extra_TruthCofactor0( uCof0, pCutF->nLeaves, pCutF->nLeaves-1 );
00147 Extra_TruthCopy( uCof1, uTemp, pCutF->nLeaves );
00148 Extra_TruthCofactor1( uCof1, pCutF->nLeaves, pCutF->nLeaves-1 );
00149
00150
00151 for ( i = NodeIndex; i < (int)pCutF->nLeaves - 1; i++ )
00152 pCutF->pLeaves[i] = pCutF->pLeaves[i+1];
00153 pCutF->nLeaves--;
00154
00155
00156 uPhase = Cut_TruthPhase(pCutRes, pCutF);
00157 assert( Extra_WordCountOnes(uPhase) == (int)pCutF->nLeaves );
00158 Extra_TruthStretch( uTemp, uCof0, pCutF->nLeaves, pCutF->nVarsMax, uPhase );
00159 Extra_TruthCopy( uCof0, uTemp, pCutF->nVarsMax );
00160 Extra_TruthStretch( uTemp, uCof1, pCutF->nLeaves, pCutF->nVarsMax, uPhase );
00161 Extra_TruthCopy( uCof1, uTemp, pCutF->nVarsMax );
00162
00163
00164 uPhase = Cut_TruthPhase(pCutRes, pCutT);
00165 assert( Extra_WordCountOnes(uPhase) == (int)pCutT->nLeaves );
00166 Extra_TruthStretch( uTemp, Cut_CutReadTruth(pCutT), pCutT->nLeaves, pCutT->nVarsMax, uPhase );
00167
00168
00169 pTemp = Cut_CutReadTruth(pCutRes);
00170 for ( i = Extra_TruthWordNum(pCutRes->nLeaves)-1; i >= 0; i-- )
00171 pTemp[i] = (uCof0[i] & ~uTemp[i]) | (uCof1[i] & uTemp[i]);
00172
00173
00174 for ( i = (int)pCutF->nLeaves - 1; i >= NodeIndex; --i )
00175 pCutF->pLeaves[i+1] = pCutF->pLeaves[i];
00176 pCutF->pLeaves[NodeIndex] = Node;
00177 pCutF->nLeaves++;
00178 }
00179
00183
00184