fxu.c 7.89 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
/**CFile****************************************************************

  FileName    [fxu.c]

  PackageName [MVSIS 2.0: Multi-valued logic synthesis system.]

  Synopsis    [The entrance into the fast extract module.]

  Author      [MVSIS Group]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - February 1, 2003.]

  Revision    [$Id: fxu.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]

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

#include "fxuInt.h" 
#include "fxu.h"

22 23 24
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
25 26 27 28 29 30 31 32 33 34 35 36
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

/*===== fxuCreate.c ====================================================*/
extern Fxu_Matrix * Fxu_CreateMatrix( Fxu_Data_t * pData );
extern void         Fxu_CreateCovers( Fxu_Matrix * p, Fxu_Data_t * pData );

static int s_MemoryTotal;
static int s_MemoryPeak;

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
37
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
38 39 40 41 42 43
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Performs fast_extract on a set of covers.]

Alan Mishchenko committed
44 45 46 47 48
  Description [All the covers are given in the array p->vSops. 
  The resulting covers are returned in the array p->vSopsNew.
  The entries in these arrays correspond to objects in the network.
  The entries corresponding to the PI and objects with trivial covers are NULL.
  The number of extracted covers (not exceeding p->nNodesExt) is returned. 
Alan Mishchenko committed
49
  Two other things are important for the correct operation of this procedure:
Alan Mishchenko committed
50
  (1) The input covers do not have duplicated fanins and are SCC-free. 
Alan Mishchenko committed
51
  (2) The fanins array contains the numbers of the fanin objects.]
Alan Mishchenko committed
52 53 54 55 56 57 58 59
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Fxu_FastExtract( Fxu_Data_t * pData )
{
60
    int fScrollLines = 0;
Alan Mishchenko committed
61 62 63 64
    Fxu_Matrix * p;
    Fxu_Single * pSingle;
    Fxu_Double * pDouble;
    int Weight1, Weight2, Weight3;
Alan Mishchenko committed
65
    int Counter = 0;
Alan Mishchenko committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

    s_MemoryTotal = 0;
    s_MemoryPeak  = 0;

    // create the matrix
    p = Fxu_CreateMatrix( pData );
    if ( p == NULL )
        return -1;
//    if ( pData->fVerbose )
//        printf( "Memory usage after construction: Total = %d. Peak = %d.\n", s_MemoryTotal, s_MemoryPeak );
//Fxu_MatrixPrint( NULL, p );

    if ( pData->fOnlyS )
    {
        pData->nNodesNew = 0;
        do
        {
            Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
            if ( pData->fVerbose )
85
                printf( "Div %5d : Best single = %5d.%s", Counter++, Weight1, fScrollLines?"\n":"\r" );
86
            if ( Weight1 > pData->WeightMin || (Weight1 == 0 && pData->fUse0) )
Alan Mishchenko committed
87 88 89 90 91 92 93 94 95 96 97 98 99
                Fxu_UpdateSingle( p );
            else
                break;
        }
        while ( ++pData->nNodesNew < pData->nNodesExt );
    }
    else if ( pData->fOnlyD )
    {
        pData->nNodesNew = 0;
        do
        {
            Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );
            if ( pData->fVerbose )
100
                printf( "Div %5d : Best double = %5d.%s", Counter++, Weight2, fScrollLines?"\n":"\r" );
101
            if ( Weight2 > pData->WeightMin || (Weight2 == 0 && pData->fUse0) )
Alan Mishchenko committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
                Fxu_UpdateDouble( p );
            else
                break;
        }
        while ( ++pData->nNodesNew < pData->nNodesExt );
    }
    else if ( !pData->fUseCompl )
    {
        pData->nNodesNew = 0;
        do
        {
            Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
            Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );

            if ( pData->fVerbose )
117
                printf( "Div %5d : Best double = %5d. Best single = %5d.%s", Counter++, Weight2, Weight1, fScrollLines?"\n":"\r" );
Alan Mishchenko committed
118 119 120 121
//Fxu_Select( p, &pSingle, &pDouble );

            if ( Weight1 >= Weight2 )
            {
122
                if ( Weight1 > pData->WeightMin || (Weight1 == 0 && pData->fUse0) )
Alan Mishchenko committed
123 124 125 126 127 128
                    Fxu_UpdateSingle( p );
                else
                    break;
            }
            else
            {
129
                if ( Weight2 > pData->WeightMin || (Weight2 == 0 && pData->fUse0) )
Alan Mishchenko committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
                    Fxu_UpdateDouble( p );
                else
                    break;
            }
        }
        while ( ++pData->nNodesNew < pData->nNodesExt );
    }
    else
    { // use the complement
        pData->nNodesNew = 0;
        do
        {
            Weight1 = Fxu_HeapSingleReadMaxWeight( p->pHeapSingle );
            Weight2 = Fxu_HeapDoubleReadMaxWeight( p->pHeapDouble );

            // select the best single and double
            Weight3 = Fxu_Select( p, &pSingle, &pDouble );
            if ( pData->fVerbose )
148 149
                printf( "Div %5d : Best double = %5d. Best single = %5d. Best complement = %5d.%s", 
                    Counter++, Weight2, Weight1, Weight3, fScrollLines?"\n":"\r" );
Alan Mishchenko committed
150

151
            if ( Weight3 > pData->WeightMin || (Weight3 == 0 && pData->fUse0) )
Alan Mishchenko committed
152 153 154 155 156 157 158 159
                Fxu_Update( p, pSingle, pDouble );
            else
                break;
        }
        while ( ++pData->nNodesNew < pData->nNodesExt );
    }

    if ( pData->fVerbose )
Alan Mishchenko committed
160 161
        printf( "Total single = %3d. Total double = %3d. Total compl = %3d.                    \n", 
        p->nDivs1, p->nDivs2, p->nDivs3 );
Alan Mishchenko committed
162 163 164 165 166

    // create the new covers
    if ( pData->nNodesNew )
        Fxu_CreateCovers( p, pData );
    Fxu_MatrixDelete( p );
Alan Mishchenko committed
167
//    printf( "Memory usage after deallocation:   Total = %d. Peak = %d.\n", s_MemoryTotal, s_MemoryPeak );
Alan Mishchenko committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    if ( pData->nNodesNew == pData->nNodesExt )
        printf( "Warning: The limit on the number of extracted divisors has been reached.\n" );
    return pData->nNodesNew;
}


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

  Synopsis    [Unmarks the cubes in the ring.]

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fxu_MatrixRingCubesUnmark( Fxu_Matrix * p )
{
    Fxu_Cube * pCube, * pCube2;
    // unmark the cubes
    Fxu_MatrixForEachCubeInRingSafe( p, pCube, pCube2 )
        pCube->pOrder = NULL;
    Fxu_MatrixRingCubesReset( p );
}


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

  Synopsis    [Unmarks the vars in the ring.]

  Description []

  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fxu_MatrixRingVarsUnmark( Fxu_Matrix * p )
{
    Fxu_Var * pVar, * pVar2;
    // unmark the vars
    Fxu_MatrixForEachVarInRingSafe( p, pVar, pVar2 )
        pVar->pOrder = NULL;
    Fxu_MatrixRingVarsReset( p );
}


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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
char * Fxu_MemFetch( Fxu_Matrix * p, int nBytes )
{
    s_MemoryTotal += nBytes;
    if ( s_MemoryPeak < s_MemoryTotal )
        s_MemoryPeak = s_MemoryTotal;
Alan Mishchenko committed
232
//    return ABC_ALLOC( char, nBytes );
Alan Mishchenko committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
    return Extra_MmFixedEntryFetch( p->pMemMan );
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fxu_MemRecycle( Fxu_Matrix * p, char * pItem, int nBytes )
{
    s_MemoryTotal -= nBytes;
Alan Mishchenko committed
250
//    ABC_FREE( pItem );
Alan Mishchenko committed
251 252 253 254 255 256 257 258
    Extra_MmFixedEntryRecycle( p->pMemMan, pItem );
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


259 260
ABC_NAMESPACE_IMPL_END