simSym.c 4.96 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    [simSym.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: simSym.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                              ///
////////////////////////////////////////////////////////////////////////
 
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
32
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
33 34 35 36 37 38 39 40 41 42 43 44 45
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Computes two variable symmetries.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
46
int Sim_ComputeTwoVarSymms( Abc_Ntk_t * pNtk, int fVerbose )
Alan Mishchenko committed
47 48 49 50
{
    Sym_Man_t * p;
    Vec_Ptr_t * vResult;
    int Result;
51
    int i;
52
    abctime clk, clkTotal = Abc_Clock();
Alan Mishchenko committed
53 54 55 56

    srand( 0xABC );

    // start the simulation manager
Alan Mishchenko committed
57 58 59 60 61
    p = Sym_ManStart( pNtk, fVerbose );
    p->nPairsTotal = p->nPairsRem = Sim_UtilCountAllPairs( p->vSuppFun, p->nSimWords, p->vPairsTotal );
    if ( fVerbose )
        printf( "Total = %8d.  Sym = %8d.  NonSym = %8d.  Remaining = %8d.\n", 
               p->nPairsTotal, p->nPairsSymm, p->nPairsNonSymm, p->nPairsRem );
Alan Mishchenko committed
62 63

    // detect symmetries using circuit structure
64
clk = Abc_Clock();
Alan Mishchenko committed
65
    Sim_SymmsStructCompute( pNtk, p->vMatrSymms, p->vSuppFun );
66
p->timeStruct = Abc_Clock() - clk;
Alan Mishchenko committed
67

Alan Mishchenko committed
68 69 70 71 72
    Sim_UtilCountPairsAll( p );
    p->nPairsSymmStr = p->nPairsSymm;
    if ( fVerbose )
        printf( "Total = %8d.  Sym = %8d.  NonSym = %8d.  Remaining = %8d.\n", 
            p->nPairsTotal, p->nPairsSymm, p->nPairsNonSymm, p->nPairsRem );
Alan Mishchenko committed
73 74 75 76 77

    // detect symmetries using simulation
    for ( i = 1; i <= 1000; i++ )
    {
        // simulate this pattern
Alan Mishchenko committed
78
        Sim_UtilSetRandom( p->uPatRand, p->nSimWords );
Alan Mishchenko committed
79
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
Alan Mishchenko committed
80
        if ( i % 50 != 0 )
Alan Mishchenko committed
81
            continue;
Alan Mishchenko committed
82 83
        // check disjointness
        assert( Sim_UtilMatrsAreDisjoint( p ) );
Alan Mishchenko committed
84
        // count the number of pairs
Alan Mishchenko committed
85 86 87 88 89 90 91
        Sim_UtilCountPairsAll( p );
        if ( i % 500 != 0 )
            continue;
        if ( fVerbose )
            printf( "Total = %8d.  Sym = %8d.  NonSym = %8d.  Remaining = %8d.\n", 
                p->nPairsTotal, p->nPairsSymm, p->nPairsNonSymm, p->nPairsRem );
    }
Alan Mishchenko committed
92

Alan Mishchenko committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    // detect symmetries using SAT
    for ( i = 1; Sim_SymmsGetPatternUsingSat( p, p->uPatRand ); i++ )
    {
        // simulate this pattern in four polarities
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
        Sim_XorBit( p->uPatRand, p->iVar1 );
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
        Sim_XorBit( p->uPatRand, p->iVar2 );
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
        Sim_XorBit( p->uPatRand, p->iVar1 );
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
        Sim_XorBit( p->uPatRand, p->iVar2 );
/*
        // try the previuos pair
        Sim_XorBit( p->uPatRand, p->iVar1Old );
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
        Sim_XorBit( p->uPatRand, p->iVar2Old );
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
        Sim_XorBit( p->uPatRand, p->iVar1Old );
        Sim_SymmsSimulate( p, p->uPatRand, p->vMatrNonSymms );
*/
        if ( i % 10 != 0 )
            continue;
        // check disjointness
        assert( Sim_UtilMatrsAreDisjoint( p ) );
        // count the number of pairs
        Sim_UtilCountPairsAll( p );
        if ( i % 50 != 0 )
            continue;
        if ( fVerbose )
            printf( "Total = %8d.  Sym = %8d.  NonSym = %8d.  Remaining = %8d.\n", 
                p->nPairsTotal, p->nPairsSymm, p->nPairsNonSymm, p->nPairsRem );
Alan Mishchenko committed
125 126
    }

Alan Mishchenko committed
127 128 129 130 131
    // count the number of pairs
    Sim_UtilCountPairsAll( p );
    if ( fVerbose )
        printf( "Total = %8d.  Sym = %8d.  NonSym = %8d.  Remaining = %8d.\n", 
            p->nPairsTotal, p->nPairsSymm, p->nPairsNonSymm, p->nPairsRem );
Alan Mishchenko committed
132
//    Sim_UtilCountPairsAllPrint( p );
Alan Mishchenko committed
133

Alan Mishchenko committed
134 135
    Result = p->nPairsSymm;
    vResult = p->vMatrSymms;  
136
p->timeTotal = Abc_Clock() - clkTotal;
Alan Mishchenko committed
137 138 139 140 141 142 143 144 145 146
    //  p->vMatrSymms = NULL;
    Sym_ManStop( p );
    return Result;
}

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


147 148
ABC_NAMESPACE_IMPL_END