cutTruth.c 7.32 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**CFile****************************************************************

  FileName    [cutTruth.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [K-feasible cut computation package.]

  Synopsis    [Incremental truth table computation.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: cutTruth.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "cutInt.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31
/* 
    Truth tables computed in this package are represented as bit-strings
    stored in the cut data structure. Cuts of any number of inputs have 
    the truth table with 2^k bits, where k is the max number of cut inputs.
*/

Alan Mishchenko committed
32 33 34 35
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
36 37 38 39
// used in abcCut.c
int nTotal = 0;
int nGood  = 0;
int nEqual = 0;
Alan Mishchenko committed
40

Alan Mishchenko committed
41
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
42
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
43 44 45 46
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

Alan Mishchenko committed
47
  Synopsis    [Computes the stretching phase of the cut w.r.t. the merged cut.]
Alan Mishchenko committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
static inline unsigned Cut_TruthPhase( Cut_Cut_t * pCut, Cut_Cut_t * pCut1 )
{
    unsigned uPhase = 0;
    int i, k;
    for ( i = k = 0; i < (int)pCut->nLeaves; i++ )
    {
        if ( k == (int)pCut1->nLeaves )
            break;
        if ( pCut->pLeaves[i] < pCut1->pLeaves[k] )
            continue;
        assert( pCut->pLeaves[i] == pCut1->pLeaves[k] );
        uPhase |= (1 << i);
        k++;
    }
    return uPhase;
}

/**Function*************************************************************

  Synopsis    [Performs truth table computation.]

Alan Mishchenko committed
77 78
  Description [This procedure cannot be used while recording oracle
  because it will overwrite Num0 and Num1.]
Alan Mishchenko committed
79 80 81 82 83 84
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
85
void Cut_TruthNCanonicize( Cut_Cut_t * pCut )
Alan Mishchenko committed
86
{
Alan Mishchenko committed
87 88 89 90
    unsigned uTruth;
    unsigned * uCanon2;
    char * pPhases2;
    assert( pCut->nVarsMax < 6 );
Alan Mishchenko committed
91

Alan Mishchenko committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
    // get the direct truth table
    uTruth = *Cut_CutReadTruth(pCut);

    // compute the direct truth table
    Extra_TruthCanonFastN( pCut->nVarsMax, pCut->nLeaves, &uTruth, &uCanon2, &pPhases2 );
//    uCanon[0] = uCanon2[0];
//    uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
//    uPhases[0] = pPhases2[0];
    pCut->uCanon0 = uCanon2[0];
    pCut->Num0    = pPhases2[0];

    // get the complemented truth table
    uTruth = ~*Cut_CutReadTruth(pCut);

    // compute the direct truth table
    Extra_TruthCanonFastN( pCut->nVarsMax, pCut->nLeaves, &uTruth, &uCanon2, &pPhases2 );
//    uCanon[0] = uCanon2[0];
//    uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
//    uPhases[0] = pPhases2[0];
    pCut->uCanon1 = uCanon2[0];
    pCut->Num1    = pPhases2[0];
Alan Mishchenko committed
113 114
}

Alan Mishchenko committed
115 116 117 118
/**Function*************************************************************

  Synopsis    [Performs truth table computation.]

Alan Mishchenko committed
119
  Description []
Alan Mishchenko committed
120 121 122 123 124 125
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
126
void Cut_TruthComputeOld( Cut_Cut_t * pCut, Cut_Cut_t * pCut0, Cut_Cut_t * pCut1, int fCompl0, int fCompl1 )
Alan Mishchenko committed
127
{
Alan Mishchenko committed
128 129 130 131
    static unsigned uTruth0[8], uTruth1[8];
    int nTruthWords = Cut_TruthWords( pCut->nVarsMax );
    unsigned * pTruthRes;
    int i, uPhase;
Alan Mishchenko committed
132

Alan Mishchenko committed
133 134 135 136 137 138 139 140
    // permute the first table
    uPhase = Cut_TruthPhase( pCut, pCut0 );
    Extra_TruthExpand( pCut->nVarsMax, nTruthWords, Cut_CutReadTruth(pCut0), uPhase, uTruth0 );
    if ( fCompl0 ) 
    {
        for ( i = 0; i < nTruthWords; i++ )
            uTruth0[i] = ~uTruth0[i];
    }
Alan Mishchenko committed
141

Alan Mishchenko committed
142 143 144 145 146 147 148 149
    // permute the second table
    uPhase = Cut_TruthPhase( pCut, pCut1 );
    Extra_TruthExpand( pCut->nVarsMax, nTruthWords, Cut_CutReadTruth(pCut1), uPhase, uTruth1 );
    if ( fCompl1 ) 
    {
        for ( i = 0; i < nTruthWords; i++ )
            uTruth1[i] = ~uTruth1[i];
    }
Alan Mishchenko committed
150

Alan Mishchenko committed
151 152
    // write the resulting table
    pTruthRes = Cut_CutReadTruth(pCut);
Alan Mishchenko committed
153

Alan Mishchenko committed
154
    if ( pCut->fCompl )
Alan Mishchenko committed
155 156 157 158 159 160 161 162 163
    {
        for ( i = 0; i < nTruthWords; i++ )
            pTruthRes[i] = ~(uTruth0[i] & uTruth1[i]);
    }
    else
    {
        for ( i = 0; i < nTruthWords; i++ )
            pTruthRes[i] = uTruth0[i] & uTruth1[i];
    }
Alan Mishchenko committed
164 165 166
}

/**Function*************************************************************
Alan Mishchenko committed
167

Alan Mishchenko committed
168
  Synopsis    [Performs truth table computation.]
Alan Mishchenko committed
169

Alan Mishchenko committed
170 171 172
  Description []
               
  SideEffects []
Alan Mishchenko committed
173

Alan Mishchenko committed
174
  SeeAlso     []
Alan Mishchenko committed
175

Alan Mishchenko committed
176
***********************************************************************/
Alan Mishchenko committed
177
void Cut_TruthCompute( Cut_Man_t * p, Cut_Cut_t * pCut, Cut_Cut_t * pCut0, Cut_Cut_t * pCut1, int fCompl0, int fCompl1 )
Alan Mishchenko committed
178
{
Alan Mishchenko committed
179 180 181 182 183 184 185 186 187 188 189 190 191
    // permute the first table
    if ( fCompl0 ) 
        Extra_TruthNot( p->puTemp[0], Cut_CutReadTruth(pCut0), pCut->nVarsMax );
    else
        Extra_TruthCopy( p->puTemp[0], Cut_CutReadTruth(pCut0), pCut->nVarsMax );
    Extra_TruthStretch( p->puTemp[2], p->puTemp[0], pCut0->nLeaves, pCut->nVarsMax, Cut_TruthPhase(pCut, pCut0) );
    // permute the second table
    if ( fCompl1 ) 
        Extra_TruthNot( p->puTemp[1], Cut_CutReadTruth(pCut1), pCut->nVarsMax );
    else
        Extra_TruthCopy( p->puTemp[1], Cut_CutReadTruth(pCut1), pCut->nVarsMax );
    Extra_TruthStretch( p->puTemp[3], p->puTemp[1], pCut1->nLeaves, pCut->nVarsMax, Cut_TruthPhase(pCut, pCut1) );
    // produce the resulting table
Alan Mishchenko committed
192
    if ( pCut->fCompl )
Alan Mishchenko committed
193 194 195
        Extra_TruthNand( Cut_CutReadTruth(pCut), p->puTemp[2], p->puTemp[3], pCut->nVarsMax );
    else
        Extra_TruthAnd( Cut_CutReadTruth(pCut), p->puTemp[2], p->puTemp[3], pCut->nVarsMax );
Alan Mishchenko committed
196

Alan Mishchenko committed
197
//    Ivy_TruthTestOne( *Cut_CutReadTruth(pCut) );
Alan Mishchenko committed
198

Alan Mishchenko committed
199 200 201
    // quit if no fancy computation is needed
    if ( !p->pParams->fFancy )
        return;
Alan Mishchenko committed
202

Alan Mishchenko committed
203 204
    if ( pCut->nLeaves != 7 )
        return;
Alan Mishchenko committed
205

Alan Mishchenko committed
206 207
    // count the total number of truth tables computed
    nTotal++;
Alan Mishchenko committed
208

Alan Mishchenko committed
209 210 211 212 213
    // MAPPING INTO ALTERA 6-2 LOGIC BLOCKS
    // call this procedure to find the minimum number of common variables in the cofactors
    // if this number is less or equal than 3, the cut can be implemented using the 6-2 logic block
    if ( Extra_TruthMinCofSuppOverlap( Cut_CutReadTruth(pCut), pCut->nVarsMax, NULL ) <= 4 )
        nGood++;
Alan Mishchenko committed
214

Alan Mishchenko committed
215 216 217 218 219 220 221 222
    // MAPPING INTO ACTEL 2x2 CELLS
    // call this procedure to see if a semi-canonical form can be found in the lookup table 
    // (if it exists, then a two-level 3-input LUT implementation of the cut exists)
    // Before this procedure is called, cell manager should be defined by calling
    // Cut_CellLoad (make sure file "cells22_daomap_iwls.txt" is available in the working dir)
//    if ( Cut_CellIsRunning() && pCut->nVarsMax <= 9 )
//        nGood += Cut_CellTruthLookup( Cut_CutReadTruth(pCut), pCut->nVarsMax );
}
Alan Mishchenko committed
223 224 225



Alan Mishchenko committed
226 227 228 229 230
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


231 232
ABC_NAMESPACE_IMPL_END