simSymSim.c 5.62 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
/**CFile****************************************************************

  FileName    [simSymSim.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Simulation to determine two-variable symmetries.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

21
#include "base/abc/abc.h"
Alan Mishchenko committed
22 23
#include "sim.h"

24 25 26
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
27 28 29 30 31
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

static void Sim_SymmsCreateSquare( Sym_Man_t * p, unsigned * pPat );
Alan Mishchenko committed
32
static void Sim_SymmsDeriveInfo( Sym_Man_t * p, unsigned * pPat, Abc_Obj_t * pNode, Vec_Ptr_t * vMatrsNonSym, int Output );
Alan Mishchenko committed
33 34

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
35
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Detects non-symmetric pairs using one pattern.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sim_SymmsSimulate( Sym_Man_t * p, unsigned * pPat, Vec_Ptr_t * vMatrsNonSym )
{
    Abc_Obj_t * pNode;
Alan Mishchenko committed
52
    int i, nPairsTotal, nPairsSym, nPairsNonSym;
53
    clock_t clk;
Alan Mishchenko committed
54

Alan Mishchenko committed
55 56 57
    // create the simulation matrix
    Sim_SymmsCreateSquare( p, pPat );
    // simulate each node in the DFS order
Alan Mishchenko committed
58
clk = clock();
59
    Vec_PtrForEachEntry( Abc_Obj_t *, p->vNodes, pNode, i )
Alan Mishchenko committed
60
    {
Alan Mishchenko committed
61 62 63
//        if ( Abc_NodeIsConst(pNode) )
//            continue;
        Sim_UtilSimulateNodeOne( pNode, p->vSim, p->nSimWords, 0 );
Alan Mishchenko committed
64
    }
Alan Mishchenko committed
65
p->timeSim += clock() - clk;
Alan Mishchenko committed
66
    // collect info into the CO matrices
Alan Mishchenko committed
67
clk = clock();
Alan Mishchenko committed
68 69 70
    Abc_NtkForEachCo( p->pNtk, pNode, i )
    {
        pNode = Abc_ObjFanin0(pNode);
Alan Mishchenko committed
71 72
//        if ( Abc_ObjIsCi(pNode) || Abc_AigNodeIsConst(pNode) )
//            continue;
Alan Mishchenko committed
73 74 75 76 77
        nPairsTotal  = Vec_IntEntry(p->vPairsTotal, i);
        nPairsSym    = Vec_IntEntry(p->vPairsSym,   i);
        nPairsNonSym = Vec_IntEntry(p->vPairsNonSym,i);
        assert( nPairsTotal >= nPairsSym + nPairsNonSym ); 
        if ( nPairsTotal == nPairsSym + nPairsNonSym )
Alan Mishchenko committed
78
            continue;
Alan Mishchenko committed
79
        Sim_SymmsDeriveInfo( p, pPat, pNode, vMatrsNonSym, i );
Alan Mishchenko committed
80
    }
Alan Mishchenko committed
81
p->timeMatr += clock() - clk;
Alan Mishchenko committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
}

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

  Synopsis    [Creates the square matrix of simulation info.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sim_SymmsCreateSquare( Sym_Man_t * p, unsigned * pPat )
{
    unsigned * pSimInfo;
    Abc_Obj_t * pNode;
    int i, w;
    // for each PI var copy the pattern
    Abc_NtkForEachCi( p->pNtk, pNode, i )
    {
103
        pSimInfo = (unsigned *)Vec_PtrEntry( p->vSim, pNode->Id );
Alan Mishchenko committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        if ( Sim_HasBit(pPat, i) )
        {
            for ( w = 0; w < p->nSimWords; w++ )
                pSimInfo[w] = SIM_MASK_FULL;
        }
        else
        {
            for ( w = 0; w < p->nSimWords; w++ )
                pSimInfo[w] = 0;
        }
        // flip one bit
        Sim_XorBit( pSimInfo, i );
    }
}

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

  Synopsis    [Transfers the info to the POs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
130
void Sim_SymmsDeriveInfo( Sym_Man_t * p, unsigned * pPat, Abc_Obj_t * pNode, Vec_Ptr_t * vMatrsNonSym, int Output )
Alan Mishchenko committed
131
{
Alan Mishchenko committed
132 133 134
    Extra_BitMat_t * pMat;
    Vec_Int_t * vSupport;
    unsigned * pSupport;
Alan Mishchenko committed
135
    unsigned * pSimInfo;
Alan Mishchenko committed
136 137
    int i, w, Index;
    // get the matrix, the support, and the simulation info
138
    pMat = (Extra_BitMat_t *)Vec_PtrEntry( vMatrsNonSym, Output );
139
    vSupport = Vec_VecEntryInt( p->vSupports, Output );
140 141
    pSupport = (unsigned *)Vec_PtrEntry( p->vSuppFun, Output );
    pSimInfo = (unsigned *)Vec_PtrEntry( p->vSim, pNode->Id );
Alan Mishchenko committed
142 143 144
    // generate vectors A1 and A2
    for ( w = 0; w < p->nSimWords; w++ )
    {
Alan Mishchenko committed
145 146
        p->uPatCol[w] = pSupport[w] & pPat[w] &  pSimInfo[w];
        p->uPatRow[w] = pSupport[w] & pPat[w] & ~pSimInfo[w];
Alan Mishchenko committed
147 148
    }
    // add two dimensions
Alan Mishchenko committed
149
    Vec_IntForEachEntry( vSupport, i, Index )
Alan Mishchenko committed
150 151 152
        if ( Sim_HasBit( p->uPatCol, i ) )
            Extra_BitMatrixOr( pMat, i, p->uPatRow );
    // add two dimensions
Alan Mishchenko committed
153
    Vec_IntForEachEntry( vSupport, i, Index )
Alan Mishchenko committed
154 155 156 157 158
        if ( Sim_HasBit( p->uPatRow, i ) )
            Extra_BitMatrixOr( pMat, i, p->uPatCol );
    // generate vectors B1 and B2
    for ( w = 0; w < p->nSimWords; w++ )
    {
Alan Mishchenko committed
159 160
        p->uPatCol[w] = pSupport[w] & ~pPat[w] &  pSimInfo[w];
        p->uPatRow[w] = pSupport[w] & ~pPat[w] & ~pSimInfo[w];
Alan Mishchenko committed
161 162
    }
    // add two dimensions
Alan Mishchenko committed
163
    Vec_IntForEachEntry( vSupport, i, Index )
Alan Mishchenko committed
164 165 166
        if ( Sim_HasBit( p->uPatCol, i ) )
            Extra_BitMatrixOr( pMat, i, p->uPatRow );
    // add two dimensions
Alan Mishchenko committed
167
    Vec_IntForEachEntry( vSupport, i, Index )
Alan Mishchenko committed
168 169 170 171 172 173 174 175 176
        if ( Sim_HasBit( p->uPatRow, i ) )
            Extra_BitMatrixOr( pMat, i, p->uPatCol );
}

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


177 178
ABC_NAMESPACE_IMPL_END