summaryrefslogtreecommitdiffstats
path: root/src/map/mapper/mapperTruth.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2005-08-06 08:01:00 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2005-08-06 08:01:00 -0700
commitd0e834d1a615f8e0e9d04c2ac97811f63562bd0b (patch)
tree0973181bfb5ee7d556cc95bd640de16fee771e89 /src/map/mapper/mapperTruth.c
parent888e5bed5d7f56a5d86d91a6e8e88f3e5a3454dc (diff)
downloadabc-d0e834d1a615f8e0e9d04c2ac97811f63562bd0b.tar.gz
abc-d0e834d1a615f8e0e9d04c2ac97811f63562bd0b.tar.bz2
abc-d0e834d1a615f8e0e9d04c2ac97811f63562bd0b.zip
Version abc50806
Diffstat (limited to 'src/map/mapper/mapperTruth.c')
-rw-r--r--src/map/mapper/mapperTruth.c359
1 files changed, 69 insertions, 290 deletions
diff --git a/src/map/mapper/mapperTruth.c b/src/map/mapper/mapperTruth.c
index 9388b42f..67ef029b 100644
--- a/src/map/mapper/mapperTruth.c
+++ b/src/map/mapper/mapperTruth.c
@@ -22,20 +22,10 @@
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
-//static void Map_TruthsCutDcs( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] );
-static void Map_TruthsCut( Map_Man_t * pMan, Map_Cut_t * pCut );
-static void Map_TruthsCut_rec( Map_Cut_t * pCut, unsigned uTruth[] );
-static void Map_TruthsUnmark_rec( Map_Cut_t * pCut );
-
-/*
-static int s_Same = 0;
-static int s_Diff = 0;
-static int s_Same2 = 0;
-static int s_Diff2 = 0;
-static int s_Truth = 0;
-static int s_Isop1 = 0;
-static int s_Isop2 = 0;
-*/
+static void Map_TruthsCut( Map_Man_t * pMan, Map_Cut_t * pCut );
+static void Map_TruthsCutOne( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] );
+static void Map_CutsCollect_rec( Map_Cut_t * pCut, Map_NodeVec_t * vVisited );
+
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFITIONS ///
////////////////////////////////////////////////////////////////////////
@@ -85,10 +75,6 @@ void Map_MappingTruths( Map_Man_t * pMan )
Extra_ProgressBarUpdate( pProgress, i, "Tables ..." );
}
Extra_ProgressBarStop( pProgress );
-
-// printf( "Same = %6d. Diff = %6d.\n", s_Same, s_Diff );
-// printf( "Same2 = %6d. Diff2 = %6d.\n", s_Same2, s_Diff2 );
-// printf( "Truth = %6d. Isop1 = %6d. Isop2 = %6d.\n", s_Truth, s_Isop1, s_Isop2 );
}
/**Function*************************************************************
@@ -106,22 +92,11 @@ void Map_TruthsCut( Map_Man_t * p, Map_Cut_t * pCut )
{
unsigned uTruth[2], uCanon[2];
unsigned char uPhases[16];
- int i;
// generally speaking, 1-input cut can be matched into a wire!
if ( pCut->nLeaves == 1 )
return;
- // set the leaf truth tables
- for ( i = 0; i < pCut->nLeaves; i++ )
- {
- pCut->ppLeaves[i]->pCuts->uTruthTemp[0] = p->uTruths[i][0];
- pCut->ppLeaves[i]->pCuts->uTruthTemp[1] = p->uTruths[i][1];
- }
- // recursively compute the truth table
- pCut->nVolume = 0;
- Map_TruthsCut_rec( pCut, uTruth );
- // recursively unmark the visited cuts
- Map_TruthsUnmark_rec( pCut );
+ Map_TruthsCutOne( p, pCut, uTruth );
// compute the canonical form for the positive phase
Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
@@ -140,15 +115,11 @@ void Map_TruthsCut( Map_Man_t * p, Map_Cut_t * pCut )
// restore the truth table
uTruth[0] = ~uTruth[0];
uTruth[1] = ~uTruth[1];
- // enable don't-care computation
-// Map_TruthsCutDcs( p, pCut, uTruth );
}
-#if 0
-
/**Function*************************************************************
- Synopsis [Adds several other choices using SDCs.]
+ Synopsis [Computes the truth table of one cut.]
Description []
@@ -157,141 +128,79 @@ void Map_TruthsCut( Map_Man_t * p, Map_Cut_t * pCut )
SeeAlso []
***********************************************************************/
-void Map_TruthsCutDcs( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] )
+void Map_TruthsCutOne( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] )
{
- unsigned uIsop1[2], uIsop2[2], uCanon[2];
- unsigned char uPhases[16];
+ unsigned uTruth1[2], uTruth2[2];
+ Map_Cut_t * pTemp;
+ int i;
+ // mark the cut leaves
+ for ( i = 0; i < pCut->nLeaves; i++ )
+ {
+ pTemp = pCut->ppLeaves[i]->pCuts;
+ pTemp->fMark = 1;
+ pTemp->M[0].uPhaseBest = p->uTruths[i][0];
+ pTemp->M[1].uPhaseBest = p->uTruths[i][1];
+ }
+ assert( pCut->fMark == 0 );
- // add several other supergate classes derived using don't-cares
- if ( pCut->uTruthDc[0] )
+ // collect the cuts in the cut cone
+ p->vVisited->nSize = 0;
+ Map_CutsCollect_rec( pCut, p->vVisited );
+ assert( p->vVisited->nSize > 0 );
+ pCut->nVolume = p->vVisited->nSize;
+
+ // compute the tables and unmark
+ for ( i = 0; i < pCut->nLeaves; i++ )
+ {
+ pTemp = pCut->ppLeaves[i]->pCuts;
+ pTemp->fMark = 0;
+ }
+ for ( i = 0; i < p->vVisited->nSize; i++ )
{
- int nOnes;
- nOnes = Map_TruthCountOnes( pCut->uTruthDc, pCut->nLeaves );
- if ( nOnes == 1 )
+ // get the cut
+ pTemp = (Map_Cut_t *)p->vVisited->pArray[i];
+ pTemp->fMark = 0;
+ // get truth table of the first branch
+ if ( Map_CutIsComplement(pTemp->pOne) )
+ {
+ uTruth1[0] = ~Map_CutRegular(pTemp->pOne)->M[0].uPhaseBest;
+ uTruth1[1] = ~Map_CutRegular(pTemp->pOne)->M[1].uPhaseBest;
+ }
+ else
+ {
+ uTruth1[0] = Map_CutRegular(pTemp->pOne)->M[0].uPhaseBest;
+ uTruth1[1] = Map_CutRegular(pTemp->pOne)->M[1].uPhaseBest;
+ }
+ // get truth table of the second branch
+ if ( Map_CutIsComplement(pTemp->pTwo) )
+ {
+ uTruth2[0] = ~Map_CutRegular(pTemp->pTwo)->M[0].uPhaseBest;
+ uTruth2[1] = ~Map_CutRegular(pTemp->pTwo)->M[1].uPhaseBest;
+ }
+ else
{
- uTruth[0] ^= pCut->uTruthDc[0];
- uTruth[1] ^= pCut->uTruthDc[1];
-
- // compute the canonical form for the positive phase
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[1].uPhase = uPhases[0];
- p->nCanons++;
-
- // compute the canonical form for the negative phase
- uTruth[0] = ~uTruth[0];
- uTruth[1] = ~uTruth[1];
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[0].uPhase = uPhases[0];
- p->nCanons++;
+ uTruth2[0] = Map_CutRegular(pTemp->pTwo)->M[0].uPhaseBest;
+ uTruth2[1] = Map_CutRegular(pTemp->pTwo)->M[1].uPhaseBest;
}
- else if ( nOnes == 2 )
+ // get the truth table of the output
+ if ( !pTemp->Phase )
{
- int Num1, Num2, RetValue;
- RetValue = Map_TruthDetectTwoFirst( pCut->uTruthDc, pCut->nLeaves );
- Num1 = RetValue & 255;
- Num2 = (RetValue >> 8) & 255;
-
- // add the first bit
- Map_InfoFlipVar( uTruth, Num1 );
-
- // compute the canonical form for the positive phase
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[1].uPhase = uPhases[0];
- p->nCanons++;
-
- // compute the canonical form for the negative phase
- uTruth[0] = ~uTruth[0];
- uTruth[1] = ~uTruth[1];
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[0].uPhase = uPhases[0];
- p->nCanons++;
-
- // add the first bit
- Map_InfoFlipVar( uTruth, Num2 );
-
- // compute the canonical form for the positive phase
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[1].uPhase = uPhases[0];
- p->nCanons++;
-
- // compute the canonical form for the negative phase
- uTruth[0] = ~uTruth[0];
- uTruth[1] = ~uTruth[1];
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[0].uPhase = uPhases[0];
- p->nCanons++;
-
- // add the first bit
- Map_InfoFlipVar( uTruth, Num1 );
-
- // compute the canonical form for the positive phase
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[1].uPhase = uPhases[0];
- p->nCanons++;
-
- // compute the canonical form for the negative phase
- uTruth[0] = ~uTruth[0];
- uTruth[1] = ~uTruth[1];
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uTruth, uPhases, uCanon );
- pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[0].uPhase = uPhases[0];
- p->nCanons++;
+ pTemp->M[0].uPhaseBest = uTruth1[0] & uTruth2[0];
+ pTemp->M[1].uPhaseBest = uTruth1[1] & uTruth2[1];
}
else
{
- // compute the ISOPs
- uIsop1[0] = Map_ComputeIsop_rec( p, uTruth[0] & ~pCut->uTruthDc[0], uTruth[0] | pCut->uTruthDc[0], 0, pCut->nLeaves, 0 );
- uIsop1[1] = uIsop1[0];
- if ( uIsop1[0] != uTruth[0] )
- {
- // compute the canonical form for the positive phase
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uIsop1, uPhases, uCanon );
- pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[1].uPhase = uPhases[0];
- p->nCanons++;
-
- // compute the canonical form for the negative phase
- uIsop1[0] = ~uIsop1[0];
- uIsop1[1] = ~uIsop1[1];
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uIsop1, uPhases, uCanon );
- pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[0].uPhase = uPhases[0];
- p->nCanons++;
- }
-
- uIsop2[0] = Map_ComputeIsop_rec( p, uTruth[0] & ~pCut->uTruthDc[0], uTruth[0] | pCut->uTruthDc[0], pCut->nLeaves-1, pCut->nLeaves, 1 );
- uIsop2[1] = uIsop2[0];
- if ( uIsop2[0] != uTruth[0] && uIsop2[0] != uIsop1[0] )
- {
- // compute the canonical form for the positive phase
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uIsop2, uPhases, uCanon );
- pCut->M[1].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- p->nCanons++;
-
- // compute the canonical form for the negative phase
- uIsop2[0] = ~uIsop2[0];
- uIsop2[1] = ~uIsop2[1];
- Map_CanonComputeSlow( p->uTruths, p->nVarsMax, pCut->nLeaves, uIsop2, uPhases, uCanon );
- pCut->M[0].pSupers = Map_SuperTableLookupC( p->pSuperLib, uCanon );
- pCut->M[0].uPhase = uPhases[0];
- p->nCanons++;
- }
+ pTemp->M[0].uPhaseBest = ~(uTruth1[0] & uTruth2[0]);
+ pTemp->M[1].uPhaseBest = ~(uTruth1[1] & uTruth2[1]);
}
}
+ uTruth[0] = pTemp->M[0].uPhaseBest;
+ uTruth[1] = pTemp->M[1].uPhaseBest;
}
-#endif
-
/**Function*************************************************************
- Synopsis [Recursively derives the truth table for the cut.]
+ Synopsis [Recursively collect the cuts.]
Description []
@@ -300,147 +209,17 @@ void Map_TruthsCutDcs( Map_Man_t * p, Map_Cut_t * pCut, unsigned uTruth[] )
SeeAlso []
***********************************************************************/
-void Map_TruthsCut_rec( Map_Cut_t * pCut, unsigned uTruthRes[] )
+void Map_CutsCollect_rec( Map_Cut_t * pCut, Map_NodeVec_t * vVisited )
{
- unsigned uTruth1[2], uTruth2[2];
- // if this is the elementary cut, its truth table is already available
- if ( pCut->nLeaves == 1 )
- {
- uTruthRes[0] = pCut->uTruthTemp[0];
- uTruthRes[1] = pCut->uTruthTemp[1];
- return;
- }
- // if this node was already visited, return its computed truth table
if ( pCut->fMark )
- {
- uTruthRes[0] = pCut->uTruthTemp[0];
- uTruthRes[1] = pCut->uTruthTemp[1];
return;
- }
+ Map_CutsCollect_rec( Map_CutRegular(pCut->pOne), vVisited );
+ Map_CutsCollect_rec( Map_CutRegular(pCut->pTwo), vVisited );
+ assert( pCut->fMark == 0 );
pCut->fMark = 1;
- pCut->nVolume++;
-
- assert( !Map_IsComplement(pCut) );
- Map_TruthsCut_rec( Map_CutRegular(pCut->pOne), uTruth1 );
- if ( Map_CutIsComplement(pCut->pOne) )
- {
- uTruth1[0] = ~uTruth1[0];
- uTruth1[1] = ~uTruth1[1];
- }
- Map_TruthsCut_rec( Map_CutRegular(pCut->pTwo), uTruth2 );
- if ( Map_CutIsComplement(pCut->pTwo) )
- {
- uTruth2[0] = ~uTruth2[0];
- uTruth2[1] = ~uTruth2[1];
- }
- if ( !pCut->Phase )
- {
- uTruthRes[0] = pCut->uTruthTemp[0] = uTruth1[0] & uTruth2[0];
- uTruthRes[1] = pCut->uTruthTemp[1] = uTruth1[1] & uTruth2[1];
- }
- else
- {
- uTruthRes[0] = pCut->uTruthTemp[0] = ~(uTruth1[0] & uTruth2[0]);
- uTruthRes[1] = pCut->uTruthTemp[1] = ~(uTruth1[1] & uTruth2[1]);
- }
-}
-
-/**Function*************************************************************
-
- Synopsis [Recursively derives the truth table for the cut.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-void Map_TruthsUnmark_rec( Map_Cut_t * pCut )
-{
- if ( pCut->nLeaves == 1 )
- return;
- // if this node was already visited, return its computed truth table
- if ( pCut->fMark == 0 )
- return;
- pCut->fMark = 0;
- Map_TruthsUnmark_rec( Map_CutRegular(pCut->pOne) );
- Map_TruthsUnmark_rec( Map_CutRegular(pCut->pTwo) );
+ Map_NodeVecPush( vVisited, (Map_Node_t *)pCut );
}
-/**Function*************************************************************
-
- Synopsis [Returns the truth table of the don't-care set.]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-int Map_TruthsCutDontCare( Map_Man_t * pMan, Map_Cut_t * pCut, unsigned * uTruthDc )
-{
- if ( pCut->pOne || (pCut->uTruthZero[0] == 0 && pCut->uTruthZero[1] == 0) )
- return 0;
- assert( (pCut->uTruthTemp[0] & pCut->uTruthZero[0]) == 0 );
- assert( (pCut->uTruthTemp[1] & pCut->uTruthZero[1]) == 0 );
- uTruthDc[0] = ((~0) & (~pCut->uTruthTemp[0]) & (~pCut->uTruthZero[0]));
- uTruthDc[1] = ((~0) & (~pCut->uTruthTemp[1]) & (~pCut->uTruthZero[1]));
- if ( uTruthDc[0] == 0 && uTruthDc[1] == 0 )
- return 0;
- return 1;
-}
-
-/**Function*************************************************************
-
- Synopsis [Expand the truth table]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-int Map_TruthCountOnes( unsigned * uTruth, int nLeaves )
-{
- int i, nMints, Counter;
- nMints = (1 << nLeaves);
- Counter = 0;
- for ( i = 0; i < nMints; i++ )
- Counter += Map_InfoReadVar( uTruth, i );
- return Counter;
-}
-
-/**Function*************************************************************
-
- Synopsis [Expand the truth table]
-
- Description []
-
- SideEffects []
-
- SeeAlso []
-
-***********************************************************************/
-int Map_TruthDetectTwoFirst( unsigned * uTruth, int nLeaves )
-{
- int i, nMints, Num1 = -1, Num2 = -1;
- nMints = (1 << nLeaves);
- for ( i = 0; i < nMints; i++ )
- if ( Map_InfoReadVar( uTruth, i ) )
- {
- if ( Num1 == -1 )
- Num1 = i;
- else if ( Num2 == -1 )
- Num2 = i;
- else
- break;
- }
- assert( Num1 != -1 && Num2 != -1 );
- return (Num1 << 8) | Num2;
-}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///