ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcBm.c File Reference
#include "base/abc/abc.h"
#include "opt/sim/sim.h"
#include "sat/bsat/satSolver.h"
Include dependency graph for abcBm.c:

Go to the source code of this file.

Macros

#define FALSE   0
 
#define TRUE   1
 

Functions

int match1by1 (Abc_Ntk_t *pNtk1, Vec_Ptr_t **nodesInLevel1, Vec_Int_t **iMatch1, Vec_Int_t **iDep1, Vec_Int_t *matchedInputs1, int *iGroup1, Vec_Int_t **oMatch1, int *oGroup1, Abc_Ntk_t *pNtk2, Vec_Ptr_t **nodesInLevel2, Vec_Int_t **iMatch2, Vec_Int_t **iDep2, Vec_Int_t *matchedInputs2, int *iGroup2, Vec_Int_t **oMatch2, int *oGroup2, Vec_Int_t *matchedOutputs1, Vec_Int_t *matchedOutputs2, Vec_Int_t *oMatchedGroups, Vec_Int_t *iNonSingleton, int ii, int idx)
 
int Abc_NtkBmSat (Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, Vec_Ptr_t *iMatchPairs, Vec_Ptr_t *oMatchPairs, Vec_Int_t *mismatch, int mode)
 
void getDependencies (Abc_Ntk_t *pNtk, Vec_Int_t **iDep, Vec_Int_t **oDep)
 
void initMatchList (Abc_Ntk_t *pNtk, Vec_Int_t **iDep, Vec_Int_t **oDep, Vec_Int_t **iMatch, int *iLastItem, Vec_Int_t **oMatch, int *oLastItem, int *iGroup, int *oGroup, int p_equivalence)
 
void iSortDependencies (Abc_Ntk_t *pNtk, Vec_Int_t **iDep, int *oGroup)
 
void oSortDependencies (Abc_Ntk_t *pNtk, Vec_Int_t **oDep, int *iGroup)
 
int oSplitByDep (Abc_Ntk_t *pNtk, Vec_Int_t **oDep, Vec_Int_t **oMatch, int *oGroup, int *oLastItem, int *iGroup)
 
int iSplitByDep (Abc_Ntk_t *pNtk, Vec_Int_t **iDep, Vec_Int_t **iMatch, int *iGroup, int *iLastItem, int *oGroup)
 
Vec_Ptr_t ** findTopologicalOrder (Abc_Ntk_t *pNtk)
 
int * Abc_NtkSimulateOneNode (Abc_Ntk_t *pNtk, int *pModel, int input, Vec_Ptr_t **topOrder)
 
int refineIOBySimulation (Abc_Ntk_t *pNtk, Vec_Int_t **iMatch, int *iLastItem, int *iGroup, Vec_Int_t **iDep, Vec_Int_t **oMatch, int *oLastItem, int *oGroup, Vec_Int_t **oDep, char *vPiValues, int *observability, Vec_Ptr_t **topOrder)
 
Abc_Ntk_tAbc_NtkMiterBm (Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, Vec_Ptr_t *iCurrMatch, Vec_Ptr_t *oCurrMatch)
 
void Abc_NtkVerifyReportError (Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int *pModel, Vec_Int_t *mismatch)
 
int Abc_NtkMiterSatBm (Abc_Ntk_t *pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int fVerbose, ABC_INT64_T *pNumConfs, ABC_INT64_T *pNumInspects)
 
int checkEquivalence (Abc_Ntk_t *pNtk1, Vec_Int_t *matchedInputs1, Vec_Int_t *matchedOutputs1, Abc_Ntk_t *pNtk2, Vec_Int_t *matchedInputs2, Vec_Int_t *matchedOutputs2)
 
Abc_Ntk_tcomputeCofactor (Abc_Ntk_t *pNtk, Vec_Ptr_t **nodesInLevel, int *bitVector, Vec_Int_t *currInputs)
 
int matchNonSingletonOutputs (Abc_Ntk_t *pNtk1, Vec_Ptr_t **nodesInLevel1, Vec_Int_t **iMatch1, Vec_Int_t **iDep1, Vec_Int_t *matchedInputs1, int *iGroup1, Vec_Int_t **oMatch1, int *oGroup1, Abc_Ntk_t *pNtk2, Vec_Ptr_t **nodesInLevel2, Vec_Int_t **iMatch2, Vec_Int_t **iDep2, Vec_Int_t *matchedInputs2, int *iGroup2, Vec_Int_t **oMatch2, int *oGroup2, Vec_Int_t *matchedOutputs1, Vec_Int_t *matchedOutputs2, Vec_Int_t *oMatchedGroups, Vec_Int_t *iNonSingleton, Abc_Ntk_t *subNtk1, Abc_Ntk_t *subNtk2, Vec_Ptr_t *oMatchPairs, Vec_Int_t *oNonSingleton, int oI, int idx, int ii, int iidx)
 
float refineBySAT (Abc_Ntk_t *pNtk1, Vec_Int_t **iMatch1, int *iGroup1, Vec_Int_t **iDep1, int *iLastItem1, Vec_Int_t **oMatch1, int *oGroup1, Vec_Int_t **oDep1, int *oLastItem1, int *observability1, Abc_Ntk_t *pNtk2, Vec_Int_t **iMatch2, int *iGroup2, Vec_Int_t **iDep2, int *iLastItem2, Vec_Int_t **oMatch2, int *oGroup2, Vec_Int_t **oDep2, int *oLastItem2, int *observability2)
 
int checkListConsistency (Vec_Int_t **iMatch1, Vec_Int_t **oMatch1, Vec_Int_t **iMatch2, Vec_Int_t **oMatch2, int iLastItem1, int oLastItem1, int iLastItem2, int oLastItem2)
 
void bmGateWay (Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int p_equivalence)
 

Variables

int * pValues1__
 
int * pValues2__
 
FILE * matchFile
 

Macro Definition Documentation

◆ FALSE

#define FALSE   0

CFile****************************************************************

FileName [bm.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Boolean Matching package.]

Synopsis [Check P-equivalence and PP-equivalence of two circuits.]

Author [Hadi Katebi]

Affiliation [University of Michigan]

Date [Ver. 1.0. Started - January, 2009.]

Revision [No revisions so far]

Comments [This is the cleaned up version of the code I used for DATE 2010 publication.]
[If you have any question or if you find a bug, contact me at hadik.nosp@m.@umi.nosp@m.ch.ed.nosp@m.u.] [I don't guarantee that I can fix all the bugs, but I can definitely point you to the right direction so you can fix the bugs yourself].

Debugging [There are some part of the code that are commented out. Those parts mostly print the contents of the data structures to the standard output. Un-comment them if you find them useful for debugging.]

Definition at line 37 of file abcBm.c.

◆ TRUE

#define TRUE   1

Definition at line 38 of file abcBm.c.

Function Documentation

◆ Abc_NtkBmSat()

int Abc_NtkBmSat ( Abc_Ntk_t * pNtk1,
Abc_Ntk_t * pNtk2,
Vec_Ptr_t * iMatchPairs,
Vec_Ptr_t * oMatchPairs,
Vec_Int_t * mismatch,
int mode )

Definition at line 967 of file abcBm.c.

968{
969 extern Abc_Ntk_t * Abc_NtkMulti( Abc_Ntk_t * pNtk, int nThresh, int nFaninMax, int fCnf, int fMulti, int fSimple, int fFactor );
970
971 Abc_Ntk_t * pMiter = NULL;
972 Abc_Ntk_t * pCnf;
973 int RetValue = 0;
974
975 // get the miter of the two networks
976 if( mode == 0 )
977 {
978 //Abc_NtkDelete( pMiter );
979 pMiter = Abc_NtkMiterBm( pNtk1, pNtk2, iMatchPairs, oMatchPairs );
980 }
981 else if( mode == 1 ) // add new outputs
982 {
983 int i;
984 Abc_Obj_t * pObj;
985 Vec_Ptr_t * vPairs;
986 Abc_Obj_t * pNtkMiter;
987
988 vPairs = Vec_PtrAlloc( 100 );
989
990 Abc_NtkForEachCo( pMiter, pObj, i )
991 Abc_ObjRemoveFanins( pObj );
992
993 for(i = 0; i < Vec_PtrSize( oMatchPairs ); i += 2)
994 {
995 Vec_PtrPush( vPairs, Abc_ObjChild0Copy((Abc_Obj_t *)Vec_PtrEntry(oMatchPairs, i)) );
996 Vec_PtrPush( vPairs, Abc_ObjChild0Copy((Abc_Obj_t *)Vec_PtrEntry(oMatchPairs, i+1)) );
997 }
998 pNtkMiter = Abc_AigMiter( (Abc_Aig_t *)pMiter->pManFunc, vPairs, 0 );
999 Abc_ObjAddFanin( Abc_NtkPo(pMiter,0), pNtkMiter );
1000 Vec_PtrFree( vPairs);
1001 }
1002 else if( mode == 2 ) // add some outputs
1003 {
1004
1005 }
1006 else if( mode == 3) // remove all outputs
1007 {
1008 }
1009
1010 if ( pMiter == NULL )
1011 {
1012 printf("Miter computation has failed.");
1013 return -1;
1014 }
1015 RetValue = Abc_NtkMiterIsConstant( pMiter );
1016 if ( RetValue == 0)
1017 {
1018 /*printf("Networks are NOT EQUIVALENT after structural hashing."); */
1019 // report the error
1020 if(mismatch != NULL)
1021 {
1022 pMiter->pModel = Abc_NtkVerifyGetCleanModel( pMiter, 1 );
1023 Abc_NtkVerifyReportError( pNtk1, pNtk2, pMiter->pModel, mismatch );
1024 ABC_FREE( pMiter->pModel );
1025 }
1026 Abc_NtkDelete( pMiter );
1027 return RetValue;
1028 }
1029 if( RetValue == 1 )
1030 {
1031 /*printf("Networks are equivalent after structural hashing."); */
1032 Abc_NtkDelete( pMiter );
1033 return RetValue;
1034 }
1035
1036 // convert the miter into a CNF
1037 //if(mode == 0)
1038 pCnf = Abc_NtkMulti( pMiter, 0, 100, 1, 0, 0, 0 );
1039 Abc_NtkDelete( pMiter );
1040 if ( pCnf == NULL )
1041 {
1042 printf("Renoding for CNF has failed.");
1043 return -1;
1044 }
1045
1046 // solve the CNF using the SAT solver
1047 RetValue = Abc_NtkMiterSat( pCnf, (ABC_INT64_T)10000, (ABC_INT64_T)0, 0, NULL, NULL);
1048 /*if ( RetValue == -1 )
1049 printf("Networks are undecided (SAT solver timed out).");
1050 else if ( RetValue == 0 )
1051 printf("Networks are NOT EQUIVALENT after SAT.");
1052 else
1053 printf("Networks are equivalent after SAT."); */
1054 if ( mismatch != NULL && pCnf->pModel )
1055 Abc_NtkVerifyReportError( pNtk1, pNtk2, pCnf->pModel, mismatch );
1056
1057 ABC_FREE( pCnf->pModel );
1058 Abc_NtkDelete( pCnf );
1059
1060 return RetValue;
1061}
Abc_Ntk_t * Abc_NtkMiterBm(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, Vec_Ptr_t *iCurrMatch, Vec_Ptr_t *oCurrMatch)
Definition abcBm.c:700
void Abc_NtkVerifyReportError(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int *pModel, Vec_Int_t *mismatch)
Definition abcBm.c:810
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkMulti(Abc_Ntk_t *pNtk, int nThresh, int nFaninMax, int fCnf, int fMulti, int fSimple, int fFactor)
DECLARATIONS ///.
Definition abcMulti.c:650
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL int Abc_NtkMiterSat(Abc_Ntk_t *pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int fVerbose, ABC_INT64_T *pNumConfs, ABC_INT64_T *pNumInspects)
FUNCTION DEFINITIONS ///.
Definition abcSat.c:58
ABC_DLL int * Abc_NtkVerifyGetCleanModel(Abc_Ntk_t *pNtk, int nFrames)
Definition abcVerify.c:678
ABC_DLL void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
Definition abcFanio.c:141
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL Abc_Obj_t * Abc_AigMiter(Abc_Aig_t *pMan, Vec_Ptr_t *vPairs, int fImplic)
Definition abcAig.c:789
ABC_DLL int Abc_NtkMiterIsConstant(Abc_Ntk_t *pMiter)
Definition abcMiter.c:682
#define ABC_FREE(obj)
Definition abc_global.h:267
void * pManFunc
Definition abc.h:191
int * pModel
Definition abc.h:198
Definition mode.h:11
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkMiterBm()

Abc_Ntk_t * Abc_NtkMiterBm ( Abc_Ntk_t * pNtk1,
Abc_Ntk_t * pNtk2,
Vec_Ptr_t * iCurrMatch,
Vec_Ptr_t * oCurrMatch )

Definition at line 700 of file abcBm.c.

701{
702 char Buffer[1000];
703 Abc_Ntk_t * pNtkMiter;
704
705 pNtkMiter = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
706 sprintf( Buffer, "%s_%s_miter", pNtk1->pName, pNtk2->pName );
707 pNtkMiter->pName = Extra_UtilStrsav(Buffer);
708
709 //Abc_NtkMiterPrepare( pNtk1, pNtk2, pNtkMiter, fComb, nPartSize );
710 {
711 Abc_Obj_t * pObj, * pObjNew;
712 int i;
713
714 Abc_AigConst1(pNtk1)->pCopy = Abc_AigConst1(pNtkMiter);
715 Abc_AigConst1(pNtk2)->pCopy = Abc_AigConst1(pNtkMiter);
716
717 // create new PIs and remember them in the old PIs
718 if(iCurrMatch == NULL)
719 {
720 Abc_NtkForEachCi( pNtk1, pObj, i )
721 {
722 pObjNew = Abc_NtkCreatePi( pNtkMiter );
723 // remember this PI in the old PIs
724 pObj->pCopy = pObjNew;
725 pObj = Abc_NtkCi(pNtk2, i);
726 pObj->pCopy = pObjNew;
727 // add name
728 Abc_ObjAssignName( pObjNew, Abc_ObjName(pObj), NULL );
729 }
730 }
731 else
732 {
733 for(i = 0; i < Vec_PtrSize( iCurrMatch ); i += 2)
734 {
735 pObjNew = Abc_NtkCreatePi( pNtkMiter );
736 pObj = (Abc_Obj_t *)Vec_PtrEntry(iCurrMatch, i);
737 pObj->pCopy = pObjNew;
738 pObj = (Abc_Obj_t *)Vec_PtrEntry(iCurrMatch, i+1);
739 pObj->pCopy = pObjNew;
740 // add name
741 Abc_ObjAssignName( pObjNew, Abc_ObjName(pObj), NULL );
742 }
743 }
744
745 // create the only PO
746 pObjNew = Abc_NtkCreatePo( pNtkMiter );
747 // add the PO name
748 Abc_ObjAssignName( pObjNew, "miter", NULL );
749 }
750
751 // Abc_NtkMiterAddOne( pNtk1, pNtkMiter );
752 {
753 Abc_Obj_t * pNode;
754 int i;
755 assert( Abc_NtkIsDfsOrdered(pNtk1) );
756 Abc_AigForEachAnd( pNtk1, pNode, i )
757 pNode->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtkMiter->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild1Copy(pNode) );
758 }
759
760 // Abc_NtkMiterAddOne( pNtk2, pNtkMiter );
761 {
762 Abc_Obj_t * pNode;
763 int i;
764 assert( Abc_NtkIsDfsOrdered(pNtk2) );
765 Abc_AigForEachAnd( pNtk2, pNode, i )
766 pNode->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtkMiter->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild1Copy(pNode) );
767 }
768
769 // Abc_NtkMiterFinalize( pNtk1, pNtk2, pNtkMiter, fComb, nPartSize );
770 {
771 Vec_Ptr_t * vPairs;
772 Abc_Obj_t * pMiter;
773 int i;
774
775 vPairs = Vec_PtrAlloc( 100 );
776
777 // collect the CO nodes for the miter
778 if(oCurrMatch != NULL)
779 {
780 for(i = 0; i < Vec_PtrSize( oCurrMatch ); i += 2)
781 {
782 Vec_PtrPush( vPairs, Abc_ObjChild0Copy((Abc_Obj_t *)Vec_PtrEntry(oCurrMatch, i)) );
783 Vec_PtrPush( vPairs, Abc_ObjChild0Copy((Abc_Obj_t *)Vec_PtrEntry(oCurrMatch, i+1)) );
784 }
785 }
786 else
787 {
788 Abc_Obj_t * pNode;
789
790 Abc_NtkForEachCo( pNtk1, pNode, i )
791 {
792 Vec_PtrPush( vPairs, Abc_ObjChild0Copy(pNode) );
793 pNode = Abc_NtkCo( pNtk2, i );
794 Vec_PtrPush( vPairs, Abc_ObjChild0Copy(pNode) );
795 }
796 }
797
798 pMiter = Abc_AigMiter( (Abc_Aig_t *)pNtkMiter->pManFunc, vPairs, 0 );
799 Abc_ObjAddFanin( Abc_NtkPo(pNtkMiter,0), pMiter );
800 Vec_PtrFree(vPairs);
801 }
802
803 //Abc_AigCleanup(pNtkMiter->pManFunc);
804
805 return pNtkMiter;
806}
ABC_DLL int Abc_NtkIsDfsOrdered(Abc_Ntk_t *pNtk)
Definition abcDfs.c:698
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
#define Abc_AigForEachAnd(pNtk, pNode, i)
Definition abc.h:488
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition abcNames.c:69
@ ABC_NTK_STRASH
Definition abc.h:58
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:700
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
@ ABC_FUNC_AIG
Definition abc.h:67
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
char * Extra_UtilStrsav(const char *s)
char * pName
Definition abc.h:158
Abc_Obj_t * pCopy
Definition abc.h:148
#define assert(ex)
Definition util_old.h:213
char * sprintf()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkMiterSatBm()

int Abc_NtkMiterSatBm ( Abc_Ntk_t * pNtk,
ABC_INT64_T nConfLimit,
ABC_INT64_T nInsLimit,
int fVerbose,
ABC_INT64_T * pNumConfs,
ABC_INT64_T * pNumInspects )

Definition at line 871 of file abcBm.c.

872{
873 static sat_solver * pSat = NULL;
874 lbool status;
875 int RetValue = 0;
876 abctime clk;
877
878 extern int Abc_NodeAddClausesTop( sat_solver * pSat, Abc_Obj_t * pNode, Vec_Int_t * vVars );
879 extern Vec_Int_t * Abc_NtkGetCiSatVarNums( Abc_Ntk_t * pNtk );
880
881 if ( pNumConfs )
882 *pNumConfs = 0;
883 if ( pNumInspects )
884 *pNumInspects = 0;
885
886 assert( Abc_NtkLatchNum(pNtk) == 0 );
887
888// if ( Abc_NtkPoNum(pNtk) > 1 )
889// fprintf( stdout, "Warning: The miter has %d outputs. SAT will try to prove all of them.\n", Abc_NtkPoNum(pNtk) );
890
891 // load clauses into the sat_solver
892 clk = Abc_Clock();
893
894
895
896 pSat = (sat_solver *)Abc_NtkMiterSatCreate( pNtk, 0 );
897
898 if ( pSat == NULL )
899 return 1;
900//printf( "%d \n", pSat->clauses.size );
901//sat_solver_delete( pSat );
902//return 1;
903
904// printf( "Created SAT problem with %d variable and %d clauses. ", sat_solver_nvars(pSat), sat_solver_nclauses(pSat) );
905// PRT( "Time", Abc_Clock() - clk );
906
907 // simplify the problem
908 clk = Abc_Clock();
909 status = sat_solver_simplify(pSat);
910// printf( "Simplified the problem to %d variables and %d clauses. ", sat_solver_nvars(pSat), sat_solver_nclauses(pSat) );
911// PRT( "Time", Abc_Clock() - clk );
912 if ( status == 0 )
913 {
914 sat_solver_delete( pSat );
915// printf( "The problem is UNSATISFIABLE after simplification.\n" );
916 return 1;
917 }
918
919 // solve the miter
920 clk = Abc_Clock();
921 if ( fVerbose )
922 pSat->verbosity = 1;
923 status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)nInsLimit, (ABC_INT64_T)0, (ABC_INT64_T)0 );
924 if ( status == l_Undef )
925 {
926// printf( "The problem timed out.\n" );
927 RetValue = -1;
928 }
929 else if ( status == l_True )
930 {
931// printf( "The problem is SATISFIABLE.\n" );
932 RetValue = 0;
933 }
934 else if ( status == l_False )
935 {
936// printf( "The problem is UNSATISFIABLE.\n" );
937 RetValue = 1;
938 }
939 else
940 assert( 0 );
941// PRT( "SAT sat_solver time", Abc_Clock() - clk );
942// printf( "The number of conflicts = %d.\n", (int)pSat->sat_solver_stats.conflicts );
943
944 // if the problem is SAT, get the counterexample
945 if ( status == l_True )
946 {
947// Vec_Int_t * vCiIds = Abc_NtkGetCiIds( pNtk );
948 Vec_Int_t * vCiIds = Abc_NtkGetCiSatVarNums( pNtk );
949 pNtk->pModel = Sat_SolverGetModel( pSat, vCiIds->pArray, vCiIds->nSize );
950 Vec_IntFree( vCiIds );
951 }
952 // free the sat_solver
953 if ( fVerbose )
954 Sat_SolverPrintStats( stdout, pSat );
955
956 if ( pNumConfs )
957 *pNumConfs = (int)pSat->stats.conflicts;
958 if ( pNumInspects )
959 *pNumInspects = (int)pSat->stats.inspects;
960
961//sat_solver_store_write( pSat, "trace.cnf" );
962 sat_solver_store_free( pSat );
963 sat_solver_delete( pSat );
964 return RetValue;
965}
Vec_Int_t * Abc_NtkGetCiSatVarNums(Abc_Ntk_t *pNtk)
Definition abcSat.c:189
ABC_DLL void * Abc_NtkMiterSatCreate(Abc_Ntk_t *pNtk, int fAllPrimes)
Definition abcSat.c:664
ABC_INT64_T abctime
Definition abc_global.h:332
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_store_free(sat_solver *s)
Definition satSolver.c:2400
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int * Sat_SolverGetModel(sat_solver *p, int *pVars, int nVars)
Definition satUtil.c:270
void Sat_SolverPrintStats(FILE *pFile, sat_solver *p)
Definition satUtil.c:193
signed char lbool
Definition satVec.h:135
stats_t stats
Definition satSolver.h:163
ABC_INT64_T conflicts
Definition satVec.h:156
ABC_INT64_T inspects
Definition satVec.h:156
Here is the call graph for this function:

◆ Abc_NtkSimulateOneNode()

int * Abc_NtkSimulateOneNode ( Abc_Ntk_t * pNtk,
int * pModel,
int input,
Vec_Ptr_t ** topOrder )

Definition at line 449 of file abcBm.c.

450{
451 Abc_Obj_t * pNode;
452 Vec_Ptr_t * vNodes;
453 int * pValues, Value0, Value1, i;
454
455 vNodes = Vec_PtrAlloc( 50 );
456/*
457 printf( "Counter example: " );
458 Abc_NtkForEachCi( pNtk, pNode, i )
459 printf( " %d", pModel[i] );
460 printf( "\n" );
461*/
462 // increment the trav ID
463 Abc_NtkIncrementTravId( pNtk );
464 // set the CI values
465 Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)1;
466 pNode = Abc_NtkCi(pNtk, input);
467 pNode->iTemp = pModel[input];
468
469 // simulate in the topological order
470 for(i = Vec_PtrSize(topOrder[input])-1; i >= 0; i--)
471 {
472 pNode = (Abc_Obj_t *)Vec_PtrEntry(topOrder[input], i);
473
474 Value0 = ((int)(ABC_PTRUINT_T)Abc_ObjFanin0(pNode)->pCopy) ^ Abc_ObjFaninC0(pNode);
475 Value1 = ((int)(ABC_PTRUINT_T)Abc_ObjFanin1(pNode)->pCopy) ^ Abc_ObjFaninC1(pNode);
476
477 if( pNode->iTemp != (Value0 & Value1))
478 {
479 pNode->iTemp = (Value0 & Value1);
480 Vec_PtrPush(vNodes, pNode);
481 }
482
483 }
484 // fill the output values
485 pValues = ABC_ALLOC( int, Abc_NtkCoNum(pNtk) );
486 Abc_NtkForEachCo( pNtk, pNode, i )
487 pValues[i] = ((int)(ABC_PTRUINT_T)Abc_ObjFanin0(pNode)->pCopy) ^ Abc_ObjFaninC0(pNode);
488
489 pNode = Abc_NtkCi(pNtk, input);
490 if(pNode->pCopy == (Abc_Obj_t *)1)
491 pNode->pCopy = (Abc_Obj_t *)0;
492 else
493 pNode->pCopy = (Abc_Obj_t *)1;
494
495 for(i = 0; i < Vec_PtrSize(vNodes); i++)
496 {
497 pNode = (Abc_Obj_t *)Vec_PtrEntry(vNodes, i);
498
499 if(pNode->pCopy == (Abc_Obj_t *)1)
500 pNode->pCopy = (Abc_Obj_t *)0;
501 else
502 pNode->pCopy = (Abc_Obj_t *)1;
503 }
504
505 Vec_PtrFree( vNodes );
506
507 return pValues;
508}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
int iTemp
Definition abc.h:149
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkVerifyReportError()

void Abc_NtkVerifyReportError ( Abc_Ntk_t * pNtk1,
Abc_Ntk_t * pNtk2,
int * pModel,
Vec_Int_t * mismatch )

Definition at line 810 of file abcBm.c.

811{
812 Vec_Ptr_t * vNodes;
813 Abc_Obj_t * pNode;
814 int nErrors, nPrinted, i, iNode = -1;
815
816 assert( Abc_NtkCiNum(pNtk1) == Abc_NtkCiNum(pNtk2) );
817 assert( Abc_NtkCoNum(pNtk1) == Abc_NtkCoNum(pNtk2) );
818 // get the CO values under this model
819 pValues1__ = Abc_NtkVerifySimulatePattern( pNtk1, pModel );
820 pValues2__ = Abc_NtkVerifySimulatePattern( pNtk2, pModel );
821 // count the mismatches
822 nErrors = 0;
823 for ( i = 0; i < Abc_NtkCoNum(pNtk1); i++ )
824 nErrors += (int)( pValues1__[i] != pValues2__[i] );
825 //printf( "Verification failed for at least %d outputs: ", nErrors );
826 // print the first 3 outputs
827 nPrinted = 0;
828 for ( i = 0; i < Abc_NtkCoNum(pNtk1); i++ )
829 if ( pValues1__[i] != pValues2__[i] )
830 {
831 if ( iNode == -1 )
832 iNode = i;
833 //printf( " %s", Abc_ObjName(Abc_NtkCo(pNtk1,i)) );
834 if ( ++nPrinted == 3 )
835 break;
836 }
837 /*if ( nPrinted != nErrors )
838 printf( " ..." );
839 printf( "\n" );*/
840 // report mismatch for the first output
841 if ( iNode >= 0 )
842 {
843 /*printf( "Output %s: Value in Network1 = %d. Value in Network2 = %d.\n",
844 Abc_ObjName(Abc_NtkCo(pNtk1,iNode)), pValues1[iNode], pValues2[iNode] );
845 printf( "Input pattern: " );*/
846 // collect PIs in the cone
847 pNode = Abc_NtkCo(pNtk1,iNode);
848 vNodes = Abc_NtkNodeSupport( pNtk1, &pNode, 1 );
849 // set the PI numbers
850 Abc_NtkForEachCi( pNtk1, pNode, i )
851 pNode->iTemp = i;
852 // print the model
853 pNode = (Abc_Obj_t *)Vec_PtrEntry( vNodes, 0 );
854 if ( Abc_ObjIsCi(pNode) )
855 {
856 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
857 {
858 assert( Abc_ObjIsCi(pNode) );
859 //printf( " %s=%d", Abc_ObjName(pNode), pModel[(int)pNode->pCopy] );
860 Vec_IntPush(mismatch, Abc_ObjId(pNode)-1);
861 Vec_IntPush(mismatch, pModel[(int)(size_t)pNode->pCopy]);
862 }
863 }
864 //printf( "\n" );
865 Vec_PtrFree( vNodes );
866 }
867 free( pValues1__ );
868 free( pValues2__ );
869}
int * pValues2__
Definition abcBm.c:808
int * pValues1__
Definition abcBm.c:808
ABC_DLL Vec_Ptr_t * Abc_NtkNodeSupport(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition abcDfs.c:890
ABC_DLL int * Abc_NtkVerifySimulatePattern(Abc_Ntk_t *pNtk, int *pModel)
Definition abcVerify.c:696
VOID_HACK free()
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bmGateWay()

void bmGateWay ( Abc_Ntk_t * pNtk1,
Abc_Ntk_t * pNtk2,
int p_equivalence )

Definition at line 1779 of file abcBm.c.

1780{
1781 Vec_Int_t ** iDep1, ** oDep1;
1782 Vec_Int_t ** iDep2, ** oDep2;
1783 Vec_Int_t ** iMatch1, ** oMatch1;
1784 Vec_Int_t ** iMatch2, ** oMatch2;
1785 int * iGroup1, * oGroup1;
1786 int * iGroup2, * oGroup2;
1787 int iLastItem1, oLastItem1;
1788 int iLastItem2, oLastItem2;
1789 int i, j;
1790
1791 char * vPiValues1, * vPiValues2;
1792 int * observability1, * observability2;
1793 abctime clk = Abc_Clock();
1794 float initTime;
1795 float simulTime;
1796 float satTime;
1797 Vec_Ptr_t ** topOrder1 = NULL, ** topOrder2 = NULL;
1798
1799 extern void getDependencies(Abc_Ntk_t *pNtk, Vec_Int_t** iDep, Vec_Int_t** oDep);
1800 extern void initMatchList(Abc_Ntk_t *pNtk, Vec_Int_t** iDep, Vec_Int_t** oDep, Vec_Int_t** iMatch, int* iLastItem, Vec_Int_t** oMatch, int* oLastItem, int* iGroup, int* oGroup, int p_equivalence);
1801 extern void iSortDependencies(Abc_Ntk_t *pNtk, Vec_Int_t** iDep, int* oGroup);
1802 extern void oSortDependencies(Abc_Ntk_t *pNtk, Vec_Int_t** oDep, int* iGroup);
1803 extern int iSplitByDep(Abc_Ntk_t *pNtk, Vec_Int_t** iDep, Vec_Int_t** iMatch, int* iGroup, int* iLastItem, int* oGroup);
1804 extern int oSplitByDep(Abc_Ntk_t *pNtk, Vec_Int_t** oDep, Vec_Int_t** oMatch, int* oGroup, int* oLastItem, int* iGroup);
1805 extern Vec_Ptr_t ** findTopologicalOrder(Abc_Ntk_t * pNtk);
1806 extern int refineIOBySimulation(Abc_Ntk_t *pNtk, Vec_Int_t** iMatch, int* iLastItem, int * iGroup, Vec_Int_t** iDep, Vec_Int_t** oMatch, int* oLastItem, int * oGroup, Vec_Int_t** oDep, char * vPiValues, int * observability, Vec_Ptr_t ** topOrder);
1807 extern float refineBySAT(Abc_Ntk_t * pNtk1, Vec_Int_t ** iMatch1, int * iGroup1, Vec_Int_t ** iDep1, int* iLastItem1, Vec_Int_t ** oMatch1, int * oGroup1, Vec_Int_t ** oDep1, int* oLastItem1, int * observability1,
1808 Abc_Ntk_t * pNtk2, Vec_Int_t ** iMatch2, int * iGroup2, Vec_Int_t ** iDep2, int* iLastItem2, Vec_Int_t ** oMatch2, int * oGroup2, Vec_Int_t ** oDep2, int* oLastItem2, int * observability2);
1809 int checkListConsistency(Vec_Int_t ** iMatch1, Vec_Int_t ** oMatch1, Vec_Int_t ** iMatch2, Vec_Int_t ** oMatch2, int iLastItem1, int oLastItem1, int iLastItem2, int oLastItem2);
1810
1811 iDep1 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPiNum(pNtk1) );
1812 oDep1 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPoNum(pNtk1) );
1813
1814 iDep2 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPiNum(pNtk2) );
1815 oDep2 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPoNum(pNtk2) );
1816
1817 iMatch1 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPiNum(pNtk1) );
1818 oMatch1 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPoNum(pNtk1) );
1819
1820 iMatch2 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPiNum(pNtk2) );
1821 oMatch2 = ABC_ALLOC( Vec_Int_t*, (unsigned)Abc_NtkPoNum(pNtk2) );
1822
1823 iGroup1 = ABC_ALLOC( int, Abc_NtkPiNum(pNtk1) );
1824 oGroup1 = ABC_ALLOC( int, Abc_NtkPoNum(pNtk1) );
1825
1826 iGroup2 = ABC_ALLOC( int, Abc_NtkPiNum(pNtk2) );
1827 oGroup2 = ABC_ALLOC( int, Abc_NtkPoNum(pNtk2) );
1828
1829 vPiValues1 = ABC_ALLOC( char, Abc_NtkPiNum(pNtk1) + 1);
1830 vPiValues1[Abc_NtkPiNum(pNtk1)] = '\0';
1831
1832 vPiValues2 = ABC_ALLOC( char, Abc_NtkPiNum(pNtk2) + 1);
1833 vPiValues2[Abc_NtkPiNum(pNtk2)] = '\0';
1834
1835 observability1 = ABC_ALLOC(int, (unsigned)Abc_NtkPiNum(pNtk1));
1836 observability2 = ABC_ALLOC(int, (unsigned)Abc_NtkPiNum(pNtk2));
1837
1838 for(i = 0; i < Abc_NtkPiNum(pNtk1); i++)
1839 {
1840 iDep1[i] = Vec_IntAlloc( 1 );
1841 iMatch1[i] = Vec_IntAlloc( 1 );
1842
1843 iDep2[i] = Vec_IntAlloc( 1 );
1844 iMatch2[i] = Vec_IntAlloc( 1 );
1845
1846 vPiValues1[i] = '0';
1847 vPiValues2[i] = '0';
1848
1849 observability1[i] = 0;
1850 observability2[i] = 0;
1851 }
1852
1853 for(i = 0; i < Abc_NtkPoNum(pNtk1); i++)
1854 {
1855 oDep1[i] = Vec_IntAlloc( 1 );
1856 oMatch1[i] = Vec_IntAlloc( 1 );
1857
1858 oDep2[i] = Vec_IntAlloc( 1 );
1859 oMatch2[i] = Vec_IntAlloc( 1 );
1860 }
1861
1862 /************* Strashing ************/
1863 pNtk1 = Abc_NtkStrash( pNtk1, 0, 0, 0 );
1864 pNtk2 = Abc_NtkStrash( pNtk2, 0, 0, 0 );
1865 printf("Network strashing is done!\n");
1866 /************************************/
1867
1868 /******* Getting Dependencies *******/
1869 getDependencies(pNtk1, iDep1, oDep1);
1870 getDependencies(pNtk2, iDep2, oDep2);
1871 printf("Getting dependencies is done!\n");
1872 /************************************/
1873
1874 /***** Intializing match lists ******/
1875 initMatchList(pNtk1, iDep1, oDep1, iMatch1, &iLastItem1, oMatch1, &oLastItem1, iGroup1, oGroup1, p_equivalence);
1876 initMatchList(pNtk2, iDep2, oDep2, iMatch2, &iLastItem2, oMatch2, &oLastItem2, iGroup2, oGroup2, p_equivalence);
1877 printf("Initializing match lists is done!\n");
1878 /************************************/
1879
1880 if( !checkListConsistency(iMatch1, oMatch1, iMatch2, oMatch2, iLastItem1, oLastItem1, iLastItem2, oLastItem2) )
1881 {
1882 fprintf( stdout, "I/O dependencies of two circuits are different.\n");
1883 goto freeAndExit;
1884 }
1885
1886 printf("Refining IOs by dependencies ...");
1887 // split match lists further by checking dependencies
1888 do
1889 {
1890 int iNumOfItemsAdded = 1, oNumOfItemsAdded = 1;
1891
1892 do
1893 {
1894 if( oNumOfItemsAdded )
1895 {
1896 iSortDependencies(pNtk1, iDep1, oGroup1);
1897 iSortDependencies(pNtk2, iDep2, oGroup2);
1898 }
1899
1900 if( iNumOfItemsAdded )
1901 {
1902 oSortDependencies(pNtk1, oDep1, iGroup1);
1903 oSortDependencies(pNtk2, oDep2, iGroup2);
1904 }
1905
1906 if( iLastItem1 < Abc_NtkPiNum(pNtk1) )
1907 {
1908 iSplitByDep(pNtk1, iDep1, iMatch1, iGroup1, &iLastItem1, oGroup1);
1909 if( oLastItem1 < Abc_NtkPoNum(pNtk1) )
1910 oSplitByDep(pNtk1, oDep1, oMatch1, oGroup1, &oLastItem1, iGroup1);
1911 }
1912
1913 if( iLastItem2 < Abc_NtkPiNum(pNtk2) )
1914 iNumOfItemsAdded = iSplitByDep(pNtk2, iDep2, iMatch2, iGroup2, &iLastItem2, oGroup2);
1915 else
1916 iNumOfItemsAdded = 0;
1917
1918 if( oLastItem2 < Abc_NtkPoNum(pNtk2) )
1919 oNumOfItemsAdded = oSplitByDep(pNtk2, oDep2, oMatch2, oGroup2, &oLastItem2, iGroup2);
1920 else
1921 oNumOfItemsAdded = 0;
1922
1923 if(!checkListConsistency(iMatch1, oMatch1, iMatch2, oMatch2, iLastItem1, oLastItem1, iLastItem2, oLastItem2))
1924 {
1925 fprintf( stdout, "I/O dependencies of two circuits are different.\n");
1926 goto freeAndExit;
1927 }
1928 }while(iNumOfItemsAdded != 0 || oNumOfItemsAdded != 0);
1929
1930 }while(0);
1931
1932 printf(" done!\n");
1933
1934 initTime = ((float)(Abc_Clock() - clk)/(float)(CLOCKS_PER_SEC));
1935 clk = Abc_Clock();
1936
1937 topOrder1 = findTopologicalOrder(pNtk1);
1938 topOrder2 = findTopologicalOrder(pNtk2);
1939
1940 printf("Refining IOs by simulation ...");
1941
1942 do
1943 {
1944 int counter = 0;
1945 int ioSuccess1, ioSuccess2;
1946
1947 do
1948 {
1949 for(i = 0; i < iLastItem1; i++)
1950 {
1951 int temp = (int)(SIM_RANDOM_UNSIGNED % 2);
1952
1953 if(Vec_IntSize(iMatch1[i]) != Vec_IntSize(iMatch2[i]))
1954 {
1955 fprintf( stdout, "Input refinement by simulation finds two circuits different.\n");
1956 goto freeAndExit;
1957 }
1958
1959 for(j = 0; j < Vec_IntSize(iMatch1[i]); j++)
1960 {
1961 vPiValues1[Vec_IntEntry(iMatch1[i], j)] = temp + '0';
1962 vPiValues2[Vec_IntEntry(iMatch2[i], j)] = temp + '0';
1963 }
1964 }
1965
1966 ioSuccess1 = refineIOBySimulation(pNtk1, iMatch1, &iLastItem1, iGroup1, iDep1, oMatch1, &oLastItem1, oGroup1, oDep1, vPiValues1, observability1, topOrder1);
1967 ioSuccess2 = refineIOBySimulation(pNtk2, iMatch2, &iLastItem2, iGroup2, iDep2, oMatch2, &oLastItem2, oGroup2, oDep2, vPiValues2, observability2, topOrder2);
1968
1969 if(ioSuccess1 && ioSuccess2)
1970 counter = 0;
1971 else
1972 counter++;
1973
1974 if(ioSuccess1 != ioSuccess2 ||
1975 !checkListConsistency(iMatch1, oMatch1, iMatch2, oMatch2, iLastItem1, oLastItem1, iLastItem2, oLastItem2))
1976 {
1977 fprintf( stdout, "Input refinement by simulation finds two circuits different.\n");
1978 goto freeAndExit;
1979 }
1980 }while(counter <= 200);
1981
1982 }while(0);
1983
1984 printf(" done!\n");
1985
1986 simulTime = (float)(Abc_Clock() - clk)/(float)(CLOCKS_PER_SEC);
1987 printf("SAT-based search started ...\n");
1988
1989 satTime = refineBySAT(pNtk1, iMatch1, iGroup1, iDep1, &iLastItem1, oMatch1, oGroup1, oDep1, &oLastItem1, observability1,
1990 pNtk2, iMatch2, iGroup2, iDep2, &iLastItem2, oMatch2, oGroup2, oDep2, &oLastItem2, observability2);
1991
1992 printf( "Init Time = %4.2f\n", initTime );
1993 printf( "Simulation Time = %4.2f\n", simulTime );
1994 printf( "SAT Time = %4.2f\n", satTime );
1995 printf( "Overall Time = %4.2f\n", initTime + simulTime + satTime );
1996
1997freeAndExit:
1998
1999 for(i = 0; i < iLastItem1 ; i++)
2000 {
2001
2002 Vec_IntFree( iMatch1[i] );
2003 Vec_IntFree( iMatch2[i] );
2004 }
2005
2006 for(i = 0; i < oLastItem1 ; i++)
2007 {
2008
2009 Vec_IntFree( oMatch1[i] );
2010 Vec_IntFree( oMatch2[i] );
2011 }
2012
2013 for(i = 0; i < Abc_NtkPiNum(pNtk1); i++)
2014 {
2015 Vec_IntFree( iDep1[i] );
2016 Vec_IntFree( iDep2[i] );
2017 if(topOrder1 != NULL) {
2018 Vec_PtrFree( topOrder1[i] );
2019 Vec_PtrFree( topOrder2[i] );
2020 }
2021 }
2022
2023 for(i = 0; i < Abc_NtkPoNum(pNtk1); i++)
2024 {
2025 Vec_IntFree( oDep1[i] );
2026 Vec_IntFree( oDep2[i] );
2027 }
2028
2029 ABC_FREE( iMatch1 );
2030 ABC_FREE( iMatch2 );
2031 ABC_FREE( oMatch1 );
2032 ABC_FREE( oMatch2 );
2033 ABC_FREE( iDep1 );
2034 ABC_FREE( iDep2 );
2035 ABC_FREE( oDep1 );
2036 ABC_FREE( oDep2 );
2037 ABC_FREE( iGroup1 );
2038 ABC_FREE( iGroup2 );
2039 ABC_FREE( oGroup1 );
2040 ABC_FREE( oGroup2 );
2041 ABC_FREE( vPiValues1 );
2042 ABC_FREE( vPiValues2 );
2043 ABC_FREE( observability1 );
2044 ABC_FREE( observability2 );
2045 if(topOrder1 != NULL) {
2046 ABC_FREE( topOrder1 );
2047 ABC_FREE( topOrder2 );
2048 }
void initMatchList(Abc_Ntk_t *pNtk, Vec_Int_t **iDep, Vec_Int_t **oDep, Vec_Int_t **iMatch, int *iLastItem, Vec_Int_t **oMatch, int *oLastItem, int *iGroup, int *oGroup, int p_equivalence)
Definition abcBm.c:103
void iSortDependencies(Abc_Ntk_t *pNtk, Vec_Int_t **iDep, int *oGroup)
Definition abcBm.c:201
int refineIOBySimulation(Abc_Ntk_t *pNtk, Vec_Int_t **iMatch, int *iLastItem, int *iGroup, Vec_Int_t **iDep, Vec_Int_t **oMatch, int *oLastItem, int *oGroup, Vec_Int_t **oDep, char *vPiValues, int *observability, Vec_Ptr_t **topOrder)
Definition abcBm.c:510
void oSortDependencies(Abc_Ntk_t *pNtk, Vec_Int_t **oDep, int *iGroup)
Definition abcBm.c:243
float refineBySAT(Abc_Ntk_t *pNtk1, Vec_Int_t **iMatch1, int *iGroup1, Vec_Int_t **iDep1, int *iLastItem1, Vec_Int_t **oMatch1, int *oGroup1, Vec_Int_t **oDep1, int *oLastItem1, int *observability1, Abc_Ntk_t *pNtk2, Vec_Int_t **iMatch2, int *iGroup2, Vec_Int_t **iDep2, int *iLastItem2, Vec_Int_t **oMatch2, int *oGroup2, Vec_Int_t **oDep2, int *oLastItem2, int *observability2)
Definition abcBm.c:1576
int iSplitByDep(Abc_Ntk_t *pNtk, Vec_Int_t **iDep, Vec_Int_t **iMatch, int *iGroup, int *iLastItem, int *oGroup)
Definition abcBm.c:356
int checkListConsistency(Vec_Int_t **iMatch1, Vec_Int_t **oMatch1, Vec_Int_t **iMatch2, Vec_Int_t **oMatch2, int iLastItem1, int oLastItem1, int iLastItem2, int oLastItem2)
Definition abcBm.c:1758
void getDependencies(Abc_Ntk_t *pNtk, Vec_Int_t **iDep, Vec_Int_t **oDep)
Definition abcBm.c:46
Vec_Ptr_t ** findTopologicalOrder(Abc_Ntk_t *pNtk)
Definition abcBm.c:422
int oSplitByDep(Abc_Ntk_t *pNtk, Vec_Int_t **oDep, Vec_Int_t **oMatch, int *oGroup, int *oLastItem, int *iGroup)
Definition abcBm.c:285
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition abcStrash.c:265
#define ABC_NAMESPACE_IMPL_END
#define SIM_RANDOM_UNSIGNED
Definition sim.h:158
Definition walk.c:35
Here is the call graph for this function:

◆ checkEquivalence()

int checkEquivalence ( Abc_Ntk_t * pNtk1,
Vec_Int_t * matchedInputs1,
Vec_Int_t * matchedOutputs1,
Abc_Ntk_t * pNtk2,
Vec_Int_t * matchedInputs2,
Vec_Int_t * matchedOutputs2 )

Definition at line 1063 of file abcBm.c.

1065{
1066 Vec_Ptr_t * iMatchPairs, * oMatchPairs;
1067 int i;
1068 int result;
1069
1070 iMatchPairs = Vec_PtrAlloc( Abc_NtkPiNum( pNtk1 ) * 2);
1071 oMatchPairs = Vec_PtrAlloc( Abc_NtkPoNum( pNtk1 ) * 2);
1072
1073 for(i = 0; i < Abc_NtkPiNum(pNtk1); i++)
1074 {
1075 Vec_PtrPush(iMatchPairs, Abc_NtkPi(pNtk2, Vec_IntEntry(matchedInputs2, i)));
1076 Vec_PtrPush(iMatchPairs, Abc_NtkPi(pNtk1, Vec_IntEntry(matchedInputs1, i)));
1077 }
1078
1079
1080 for(i = 0; i < Abc_NtkPoNum(pNtk1); i++)
1081 {
1082 Vec_PtrPush(oMatchPairs, Abc_NtkPo(pNtk2, Vec_IntEntry(matchedOutputs2, i)));
1083 Vec_PtrPush(oMatchPairs, Abc_NtkPo(pNtk1, Vec_IntEntry(matchedOutputs1, i)));
1084 }
1085
1086 result = Abc_NtkBmSat(pNtk1, pNtk2, iMatchPairs, oMatchPairs, NULL, 0);
1087
1088 if( result )
1089 printf("*** Circuits are equivalent ***\n");
1090 else
1091 printf("*** Circuits are NOT equivalent ***\n");
1092
1093 Vec_PtrFree( iMatchPairs );
1094 Vec_PtrFree( oMatchPairs );
1095
1096 return result;
1097}
int Abc_NtkBmSat(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, Vec_Ptr_t *iMatchPairs, Vec_Ptr_t *oMatchPairs, Vec_Int_t *mismatch, int mode)
Definition abcBm.c:967
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkListConsistency()

int checkListConsistency ( Vec_Int_t ** iMatch1,
Vec_Int_t ** oMatch1,
Vec_Int_t ** iMatch2,
Vec_Int_t ** oMatch2,
int iLastItem1,
int oLastItem1,
int iLastItem2,
int oLastItem2 )

Definition at line 1758 of file abcBm.c.

1759{
1760 //int i;
1761
1762 if(iLastItem1 != iLastItem2 || oLastItem1 != oLastItem2)
1763 return FALSE;
1764
1765 /*for(i = 0; i < iLastItem1; i++) {
1766 if(Vec_IntSize(iMatch1[i]) != Vec_IntSize(iMatch2[i]))
1767 return FALSE;
1768 }
1769
1770 for(i = 0; i < oLastItem1; i++) {
1771 if(Vec_IntSize(oMatch1[i]) != Vec_IntSize(oMatch2[i]))
1772 return FALSE;
1773 }*/
1774
1775 return TRUE;
1776}
#define TRUE
Definition abcBm.c:38
#define FALSE
Definition abcBm.c:37
Here is the caller graph for this function:

◆ computeCofactor()

Abc_Ntk_t * computeCofactor ( Abc_Ntk_t * pNtk,
Vec_Ptr_t ** nodesInLevel,
int * bitVector,
Vec_Int_t * currInputs )

Definition at line 1099 of file abcBm.c.

1100{
1101 Abc_Ntk_t * subNtk;
1102 Abc_Obj_t * pObj, * pObjNew;
1103 int i, j, numOfLevels;
1104
1105 numOfLevels = Abc_AigLevel( pNtk ); // number of levels excludes PI/POs
1106
1107 // start a new network
1108 subNtk = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
1109 subNtk->pName = Extra_UtilStrsav("subNtk");
1110
1111 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(subNtk);
1112
1113 // clean the node copy fields and mark the nodes that need to be copied to the new network
1114 Abc_NtkCleanCopy( pNtk );
1115
1116 if(bitVector != NULL)
1117 {
1118 for(i = 0; i < Abc_NtkPiNum(pNtk); i++)
1119 if(bitVector[i])
1120 {
1121 pObj = Abc_NtkPi(pNtk, i);
1122 pObj->pCopy = (Abc_Obj_t *)(1);
1123 }
1124 }
1125
1126 for(i = 0; i < Vec_IntSize(currInputs); i++)
1127 {
1128 pObj = Abc_NtkPi(pNtk, Vec_IntEntry(currInputs, i));
1129 pObjNew = Abc_NtkDupObj( subNtk, pObj, 1 );
1130 pObj->pCopy = pObjNew;
1131 }
1132
1133
1134 // i = 0 are the inputs and the inputs are not added to the 2d array ( nodesInLevel )
1135 for( i = 0; i <= numOfLevels; i++ )
1136 for( j = 0; j < Vec_PtrSize( nodesInLevel[i] ); j++)
1137 {
1138 pObj = (Abc_Obj_t *)Vec_PtrEntry( nodesInLevel[i], j );
1139
1140 if(Abc_ObjChild0Copy(pObj) == NULL && Abc_ObjChild1Copy(pObj) == NULL)
1141 pObj->pCopy = NULL;
1142 else if(Abc_ObjChild0Copy(pObj) == NULL && Abc_ObjChild1Copy(pObj) == (void*)(1))
1143 pObj->pCopy = NULL;
1144 else if(Abc_ObjChild0Copy(pObj) == NULL && (Abc_ObjChild1Copy(pObj) != (NULL) && Abc_ObjChild1Copy(pObj) != (void*)(1)) )
1145 pObj->pCopy = NULL;
1146 else if(Abc_ObjChild0Copy(pObj) == (void*)(1) && Abc_ObjChild1Copy(pObj) == NULL)
1147 pObj->pCopy = NULL;
1148 else if(Abc_ObjChild0Copy(pObj) == (void*)(1) && Abc_ObjChild1Copy(pObj) == (void*)(1))
1149 pObj->pCopy = (Abc_Obj_t *)(1);
1150 else if(Abc_ObjChild0Copy(pObj) == (void*)(1) && (Abc_ObjChild1Copy(pObj) != (NULL) && Abc_ObjChild1Copy(pObj) != (void*)(1)) )
1151 pObj->pCopy = Abc_ObjChild1Copy(pObj);
1152 else if( (Abc_ObjChild0Copy(pObj) != (NULL) && Abc_ObjChild0Copy(pObj) != (void*)(1)) && Abc_ObjChild1Copy(pObj) == NULL )
1153 pObj->pCopy = NULL;
1154 else if( (Abc_ObjChild0Copy(pObj) != (NULL) && Abc_ObjChild0Copy(pObj) != (void*)(1)) && Abc_ObjChild1Copy(pObj) == (void*)(1) )
1155 pObj->pCopy = Abc_ObjChild0Copy(pObj);
1156 else if( (Abc_ObjChild0Copy(pObj) != (NULL) && Abc_ObjChild0Copy(pObj) != (void*)(1)) &&
1157 (Abc_ObjChild1Copy(pObj) != (NULL) && Abc_ObjChild1Copy(pObj) != (void*)(1)) )
1158 pObj->pCopy = Abc_AigAnd( (Abc_Aig_t *)subNtk->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) );
1159 }
1160
1161 for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
1162 {
1163 pObj = Abc_NtkPo(pNtk, i);
1164 pObjNew = Abc_NtkDupObj( subNtk, pObj, 1 );
1165
1166 if( Abc_ObjChild0Copy(pObj) == NULL)
1167 {
1168 Abc_ObjAddFanin( pObjNew, Abc_AigConst1(subNtk));
1169 pObjNew->fCompl0 = 1;
1170 }
1171 else if( Abc_ObjChild0Copy(pObj) == (void*)(1) )
1172 {
1173 Abc_ObjAddFanin( pObjNew, Abc_AigConst1(subNtk));
1174 pObjNew->fCompl0 = 0;
1175 }
1176 else
1177 Abc_ObjAddFanin( pObjNew, Abc_ObjChild0Copy(pObj) );
1178 }
1179
1180 return subNtk;
1181}
ABC_DLL Abc_Obj_t * Abc_NtkDupObj(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCopyName)
Definition abcObj.c:342
ABC_DLL int Abc_AigLevel(Abc_Ntk_t *pNtk)
Definition abcAig.c:292
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
unsigned fCompl0
Definition abc.h:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findTopologicalOrder()

static Vec_Ptr_t ** findTopologicalOrder ( Abc_Ntk_t * pNtk)

Definition at line 422 of file abcBm.c.

423{
424 Vec_Ptr_t ** vNodes;
425 Abc_Obj_t * pObj, * pFanout;
426 int i, k;
427
428 extern void Abc_NtkDfsReverse_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vNodes );
429
430 // start the array of nodes
431 vNodes = ABC_ALLOC(Vec_Ptr_t *, Abc_NtkPiNum(pNtk));
432 for(i = 0; i < Abc_NtkPiNum(pNtk); i++)
433 vNodes[i] = Vec_PtrAlloc(50);
434
435 Abc_NtkForEachCi( pNtk, pObj, i )
436 {
437 // set the traversal ID
438 Abc_NtkIncrementTravId( pNtk );
439 Abc_NodeSetTravIdCurrent( pObj );
440 pObj = Abc_ObjFanout0Ntk(pObj);
441 Abc_ObjForEachFanout( pObj, pFanout, k )
442 Abc_NtkDfsReverse_rec( pFanout, vNodes[i] );
443 }
444
445 return vNodes;
446}
void Abc_NtkDfsReverse_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition abcDfs.c:187
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDependencies()

static void getDependencies ( Abc_Ntk_t * pNtk,
Vec_Int_t ** iDep,
Vec_Int_t ** oDep )

Definition at line 46 of file abcBm.c.

47{
48 Vec_Ptr_t * vSuppFun;
49 int i, j;
50
51 vSuppFun = Sim_ComputeFunSupp(pNtk, 0);
52 for(i = 0; i < Abc_NtkPoNum(pNtk); i++) {
53 char * seg = (char *)vSuppFun->pArray[i];
54
55 for(j = 0; j < Abc_NtkPiNum(pNtk); j+=8) {
56 if(((*seg) & 0x01) == 0x01)
57 Vec_IntPushOrder(oDep[i], j);
58 if(((*seg) & 0x02) == 0x02)
59 Vec_IntPushOrder(oDep[i], j+1);
60 if(((*seg) & 0x04) == 0x04)
61 Vec_IntPushOrder(oDep[i], j+2);
62 if(((*seg) & 0x08) == 0x08)
63 Vec_IntPushOrder(oDep[i], j+3);
64 if(((*seg) & 0x10) == 0x10)
65 Vec_IntPushOrder(oDep[i], j+4);
66 if(((*seg) & 0x20) == 0x20)
67 Vec_IntPushOrder(oDep[i], j+5);
68 if(((*seg) & 0x40) == 0x40)
69 Vec_IntPushOrder(oDep[i], j+6);
70 if(((*seg) & 0x80) == 0x80)
71 Vec_IntPushOrder(oDep[i], j+7);
72
73 seg++;
74 }
75 }
76
77 for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
78 for(j = 0; j < Vec_IntSize(oDep[i]); j++)
79 Vec_IntPush(iDep[Vec_IntEntry(oDep[i], j)], i);
80
81
82 /*for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
83 {
84 printf("Output %d: ", i);
85 for(j = 0; j < Vec_IntSize(oDep[i]); j++)
86 printf("%d ", Vec_IntEntry(oDep[i], j));
87 printf("\n");
88 }
89
90 printf("\n");
91
92 for(i = 0; i < Abc_NtkPiNum(pNtk); i++)
93 {
94 printf("Input %d: ", i);
95 for(j = 0; j < Vec_IntSize(iDep[i]); j++)
96 printf("%d ", Vec_IntEntry(iDep[i], j));
97 printf("\n");
98 }
99
100 printf("\n"); */
101}
Vec_Ptr_t * Sim_ComputeFunSupp(Abc_Ntk_t *pNtk, int fVerbose)
Definition simSupp.c:103
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initMatchList()

void initMatchList ( Abc_Ntk_t * pNtk,
Vec_Int_t ** iDep,
Vec_Int_t ** oDep,
Vec_Int_t ** iMatch,
int * iLastItem,
Vec_Int_t ** oMatch,
int * oLastItem,
int * iGroup,
int * oGroup,
int p_equivalence )

Definition at line 103 of file abcBm.c.

104{
105 int i, j, curr;
106 Vec_Int_t** temp;
107
108 if(!p_equivalence) {
109 temp = ABC_ALLOC( Vec_Int_t*, Abc_NtkPiNum(pNtk)+1);
110
111 for(i = 0; i < Abc_NtkPiNum(pNtk)+1; i++)
112 temp[i] = Vec_IntAlloc( 0 );
113
114 for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
115 Vec_IntPush(temp[Vec_IntSize(oDep[i])], i);
116
117 curr = 0;
118 for(i = 0; i < Abc_NtkPiNum(pNtk)+1; i++)
119 {
120 if(Vec_IntSize(temp[i]) == 0)
121 Vec_IntFree( temp[i] );
122
123 else
124 {
125 oMatch[curr] = temp[i];
126
127 for(j = 0; j < Vec_IntSize(temp[i]); j++)
128 oGroup[Vec_IntEntry(oMatch[curr], j)] = curr;
129
130 curr++;
131 }
132 }
133
134 *oLastItem = curr;
135
136 ABC_FREE( temp );
137 }
138 else {
139 // the else part fixes the outputs for P-equivalence checking
140 for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
141 {
142 Vec_IntPush(oMatch[i], i);
143 oGroup[i] = i;
144 (*oLastItem) = Abc_NtkPoNum(pNtk);
145 }
146 }
147
148 /*for(j = 0; j < *oLastItem; j++)
149 {
150 printf("oMatch %d: ", j);
151 for(i = 0; i < Vec_IntSize(oMatch[j]); i++)
152 printf("%d ", Vec_IntEntry(oMatch[j], i));
153 printf("\n");
154 }
155
156 for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
157 printf("%d: %d ", i, oGroup[i]);*/
158
160
161 temp = ABC_ALLOC( Vec_Int_t*, Abc_NtkPoNum(pNtk)+1 );
162
163 for(i = 0; i < Abc_NtkPoNum(pNtk)+1; i++)
164 temp[i] = Vec_IntAlloc( 0 );
165
166 for(i = 0; i < Abc_NtkPiNum(pNtk); i++)
167 Vec_IntPush(temp[Vec_IntSize(iDep[i])], i);
168
169 curr = 0;
170 for(i = 0; i < Abc_NtkPoNum(pNtk)+1; i++)
171 {
172 if(Vec_IntSize(temp[i]) == 0)
173 Vec_IntFree( temp[i] );
174 else
175 {
176 iMatch[curr] = temp[i];
177 for(j = 0; j < Vec_IntSize(iMatch[curr]); j++)
178 iGroup[Vec_IntEntry(iMatch[curr], j)] = curr;
179 curr++;
180 }
181 }
182
183 *iLastItem = curr;
184
185 ABC_FREE( temp );
186
187 /*printf("\n");
188 for(j = 0; j < *iLastItem; j++)
189 {
190 printf("iMatch %d: ", j);
191 for(i = 0; i < Vec_IntSize(iMatch[j]); i++)
192 printf("%d ", Vec_IntEntry(iMatch[j], i));
193 printf("\n");
194 }
195
196 for(i = 0; i < Abc_NtkPiNum(pNtk); i++)
197 printf("%d: %d ", i, iGroup[i]);
198 printf("\n");*/
199}
Here is the caller graph for this function:

◆ iSortDependencies()

void iSortDependencies ( Abc_Ntk_t * pNtk,
Vec_Int_t ** iDep,
int * oGroup )

Definition at line 201 of file abcBm.c.

202{
203 int i, j, k;
204 Vec_Int_t * temp;
205 Vec_Int_t * oGroupList;
206
207 oGroupList = Vec_IntAlloc( 10 );
208
209 for(i = 0; i < Abc_NtkPiNum(pNtk); i++)
210 {
211 if(Vec_IntSize(iDep[i]) == 1)
212 continue;
213
214 temp = Vec_IntAlloc( Vec_IntSize(iDep[i]) );
215
216 for(j = 0; j < Vec_IntSize(iDep[i]); j++)
217 Vec_IntPushUniqueOrder(oGroupList, oGroup[Vec_IntEntry(iDep[i], j)]);
218
219 for(j = 0; j < Vec_IntSize(oGroupList); j++)
220 {
221 for(k = 0; k < Vec_IntSize(iDep[i]); k++)
222 if(oGroup[Vec_IntEntry(iDep[i], k)] == Vec_IntEntry(oGroupList, j))
223 {
224 Vec_IntPush( temp, Vec_IntEntry(iDep[i], k) );
225 Vec_IntRemove( iDep[i], Vec_IntEntry(iDep[i], k) );
226 k--;
227 }
228 }
229
230 Vec_IntFree( iDep[i] );
231 iDep[i] = temp;
232 Vec_IntClear( oGroupList );
233
234 /*printf("Input %d: ", i);
235 for(j = 0; j < Vec_IntSize(iDep[i]); j++)
236 printf("%d ", Vec_IntEntry(iDep[i], j));
237 printf("\n");*/
238 }
239
240 Vec_IntFree( oGroupList );
241}
Here is the caller graph for this function:

◆ iSplitByDep()

int iSplitByDep ( Abc_Ntk_t * pNtk,
Vec_Int_t ** iDep,
Vec_Int_t ** iMatch,
int * iGroup,
int * iLastItem,
int * oGroup )

Definition at line 356 of file abcBm.c.

357{
358 int i, j, k;
359 int numOfItemsAdded = 0;
360 Vec_Int_t * array, * sortedArray;
361
362 for(i = 0; i < *iLastItem; i++)
363 {
364 if(Vec_IntSize(iMatch[i]) == 1)
365 continue;
366
367 array = Vec_IntAlloc( Vec_IntSize(iMatch[i]) );
368 sortedArray = Vec_IntAlloc( Vec_IntSize(iMatch[i]) );
369
370 for(j = 0; j < Vec_IntSize(iMatch[i]); j++)
371 {
372 int factor, encode;
373
374 encode = 0;
375 factor = 1;
376
377 for(k = 0; k < Vec_IntSize(iDep[Vec_IntEntry(iMatch[i], j)]); k++)
378 encode += oGroup[Vec_IntEntry(iDep[Vec_IntEntry(iMatch[i], j)], k)] * factor;
379
380 Vec_IntPush(array, encode);
381 Vec_IntPushUniqueOrder(sortedArray, encode);
382
383 //printf("%d ", Vec_IntEntry(array, j));
384 }
385
386 while( Vec_IntSize(sortedArray) > 1 )
387 {
388 for(k = 0; k < Vec_IntSize(iMatch[i]); k++)
389 {
390 if(Vec_IntEntry(array, k) == Vec_IntEntryLast(sortedArray))
391 {
392 Vec_IntPush(iMatch[*iLastItem+numOfItemsAdded], Vec_IntEntry(iMatch[i], k));
393 iGroup[Vec_IntEntry(iMatch[i], k)] = *iLastItem+numOfItemsAdded;
394 Vec_IntRemove( iMatch[i], Vec_IntEntry(iMatch[i], k) );
395 Vec_IntRemove( array, Vec_IntEntry(array, k) );
396 k--;
397 }
398 }
399 numOfItemsAdded++;
400 Vec_IntPop(sortedArray);
401 }
402
403 Vec_IntFree( array );
404 Vec_IntFree( sortedArray );
405 //printf("\n");
406 }
407
408 *iLastItem += numOfItemsAdded;
409
410 /*printf("\n");
411 for(j = 0; j < *iLastItem ; j++)
412 {
413 printf("iMatch %d: ", j);
414 for(i = 0; i < Vec_IntSize(iMatch[j]); i++)
415 printf("%d ", Vec_IntEntry(iMatch[j], i));
416 printf("\n");
417 }*/
418
419 return numOfItemsAdded;
420}
Here is the caller graph for this function:

◆ match1by1()

int match1by1 ( Abc_Ntk_t * pNtk1,
Vec_Ptr_t ** nodesInLevel1,
Vec_Int_t ** iMatch1,
Vec_Int_t ** iDep1,
Vec_Int_t * matchedInputs1,
int * iGroup1,
Vec_Int_t ** oMatch1,
int * oGroup1,
Abc_Ntk_t * pNtk2,
Vec_Ptr_t ** nodesInLevel2,
Vec_Int_t ** iMatch2,
Vec_Int_t ** iDep2,
Vec_Int_t * matchedInputs2,
int * iGroup2,
Vec_Int_t ** oMatch2,
int * oGroup2,
Vec_Int_t * matchedOutputs1,
Vec_Int_t * matchedOutputs2,
Vec_Int_t * oMatchedGroups,
Vec_Int_t * iNonSingleton,
int ii,
int idx )

Definition at line 1331 of file abcBm.c.

1334{
1335 static int MATCH_FOUND = FALSE;
1336 Abc_Ntk_t * subNtk1, * subNtk2;
1337 Vec_Int_t * oNonSingleton;
1338 Vec_Ptr_t * oMatchPairs;
1339 int * skipList;
1340 int j, m;
1341 int i;
1342 static int counter = 0;
1343
1344 MATCH_FOUND = FALSE;
1345
1346 if( ii == Vec_IntSize(iNonSingleton) )
1347 {
1348 MATCH_FOUND = TRUE;
1349 return TRUE;
1350 }
1351
1352 i = Vec_IntEntry(iNonSingleton, ii);
1353
1354 if( idx == Vec_IntSize(iMatch1[i]) )
1355 {
1356 // call again with the next element in iNonSingleton
1357 return match1by1(pNtk1, nodesInLevel1, iMatch1, iDep1, matchedInputs1, iGroup1, oMatch1, oGroup1,
1358 pNtk2, nodesInLevel2, iMatch2, iDep2, matchedInputs2, iGroup2, oMatch2, oGroup2,
1359 matchedOutputs1, matchedOutputs2, oMatchedGroups, iNonSingleton, ii+1, 0);
1360
1361 }
1362
1363 oNonSingleton = Vec_IntAlloc(10);
1364 oMatchPairs = Vec_PtrAlloc(100);
1365 skipList = ABC_ALLOC(int, Vec_IntSize(iMatch1[i]));
1366
1367 for(j = 0; j < Vec_IntSize(iMatch1[i]); j++)
1368 skipList[j] = FALSE;
1369
1370 Vec_IntPush(matchedInputs1, Vec_IntEntry(iMatch1[i], idx));
1371 idx++;
1372
1373 if(idx == 1)
1374 {
1375 for(j = 0; j < Vec_IntSize(iDep1[Vec_IntEntryLast(iMatch1[i])]); j++)
1376 {
1377 if( Vec_IntSize(oMatch1[oGroup1[Vec_IntEntry(iDep1[Vec_IntEntryLast(iMatch1[i])], j)]]) == 1 )
1378 continue;
1379 if( Vec_IntFind( oMatchedGroups, oGroup1[Vec_IntEntry(iDep1[Vec_IntEntryLast(iMatch1[i])], j)]) != -1)
1380 continue;
1381
1382 Vec_IntPushUnique(oNonSingleton, oGroup1[Vec_IntEntry(iDep1[Vec_IntEntryLast(iMatch1[i])], j)]);
1383 Vec_IntPushUnique(oMatchedGroups, oGroup1[Vec_IntEntry(iDep1[Vec_IntEntryLast(iMatch1[i])], j)]);
1384 }
1385 }
1386
1387 subNtk1 = computeCofactor(pNtk1, nodesInLevel1, NULL, matchedInputs1);
1388
1389 for(j = idx-1; j < Vec_IntSize(iMatch2[i]) && MATCH_FOUND == FALSE; j++)
1390 {
1391 int tempJ;
1392 Vec_Int_t * mismatch;
1393
1394 if( skipList[j] )
1395 continue;
1396
1397 mismatch = Vec_IntAlloc(10);
1398
1399 Vec_IntPush(matchedInputs2, Vec_IntEntry(iMatch2[i], j));
1400
1401 subNtk2 = computeCofactor(pNtk2, nodesInLevel2, NULL, matchedInputs2);
1402
1403 for(m = 0; m < Vec_IntSize(matchedOutputs1); m++)
1404 {
1405 Vec_PtrPush(oMatchPairs, Abc_NtkPo(subNtk1, Vec_IntEntry(matchedOutputs1, m)));
1406 Vec_PtrPush(oMatchPairs, Abc_NtkPo(subNtk2, Vec_IntEntry(matchedOutputs2, m)));
1407 }
1408
1409 counter++;
1410
1411 if( Abc_NtkBmSat( subNtk2, subNtk1, NULL, oMatchPairs, mismatch, 0) )
1412 {
1413 if(idx-1 != j)
1414 {
1415 tempJ = Vec_IntEntry(iMatch2[i], idx-1);
1416 Vec_IntWriteEntry(iMatch2[i], idx-1, Vec_IntEntry(iMatch2[i], j));
1417 Vec_IntWriteEntry(iMatch2[i], j, tempJ);
1418 }
1419
1420 /*fprintf(matchFile, "%s matched to %s\n", Abc_ObjName(Abc_NtkPi(pNtk1, Vec_IntEntry(iMatch1[i], idx-1))),
1421 Abc_ObjName(Abc_NtkPi(pNtk2, Vec_IntEntry(iMatch2[i], j))));*/
1422
1423 // we look for a match for outputs in oNonSingleton
1424 matchNonSingletonOutputs(pNtk1, nodesInLevel1, iMatch1, iDep1, matchedInputs1, iGroup1, oMatch1, oGroup1,
1425 pNtk2, nodesInLevel2, iMatch2, iDep2, matchedInputs2, iGroup2, oMatch2, oGroup2,
1426 matchedOutputs1, matchedOutputs2, oMatchedGroups, iNonSingleton,
1427 subNtk1, subNtk2, oMatchPairs, oNonSingleton, 0, 0, ii, idx);
1428
1429
1430 if(idx-1 != j)
1431 {
1432 tempJ = Vec_IntEntry(iMatch2[i], idx-1);
1433 Vec_IntWriteEntry(iMatch2[i], idx-1, Vec_IntEntry(iMatch2[i], j));
1434 Vec_IntWriteEntry(iMatch2[i], j, tempJ);
1435 }
1436 }
1437 else
1438 {
1439 Abc_Ntk_t * FpNtk1, * FpNtk2;
1440 int * bitVector1, * bitVector2;
1441 Vec_Int_t * currInputs1, * currInputs2;
1442 Vec_Ptr_t * vSupp;
1443 Abc_Obj_t * pObj;
1444 int suppNum1 = 0;
1445 int * suppNum2;
1446
1447 bitVector1 = ABC_ALLOC( int, Abc_NtkPiNum(pNtk1) );
1448 bitVector2 = ABC_ALLOC( int, Abc_NtkPiNum(pNtk2) );
1449
1450 currInputs1 = Vec_IntAlloc(10);
1451 currInputs2 = Vec_IntAlloc(10);
1452
1453 suppNum2 = ABC_ALLOC(int, Vec_IntSize(iMatch2[i])-idx+1);
1454
1455 for(m = 0; m < Abc_NtkPiNum(pNtk1); m++)
1456 {
1457 bitVector1[m] = 0;
1458 bitVector2[m] = 0;
1459 }
1460
1461 for(m = 0; m < Vec_IntSize(iMatch2[i])-idx+1; m++)
1462 suppNum2[m]= 0;
1463
1464 // First of all set the value of the inputs that are already matched and are in mismatch
1465 for(m = 0; m < Vec_IntSize(mismatch); m += 2)
1466 {
1467 int n = Vec_IntEntry(mismatch, m);
1468
1469 bitVector1[Vec_IntEntry(matchedInputs1, n)] = Vec_IntEntry(mismatch, m+1);
1470 bitVector2[Vec_IntEntry(matchedInputs2, n)] = Vec_IntEntry(mismatch, m+1);
1471
1472 }
1473
1474 for(m = idx-1; m < Vec_IntSize(iMatch1[i]); m++)
1475 {
1476 Vec_IntPush(currInputs1, Vec_IntEntry(iMatch1[i], m));
1477 Vec_IntPush(currInputs2, Vec_IntEntry(iMatch2[i], m));
1478 }
1479
1480 // Then add all the inputs that are not yet matched to the currInputs
1481 for(m = 0; m < Abc_NtkPiNum(pNtk1); m++)
1482 {
1483 if(Vec_IntFind( matchedInputs1, m ) == -1)
1484 Vec_IntPushUnique(currInputs1, m);
1485
1486 if(Vec_IntFind( matchedInputs2, m ) == -1)
1487 Vec_IntPushUnique(currInputs2, m);
1488 }
1489
1490 FpNtk1 = computeCofactor(pNtk1, nodesInLevel1, bitVector1, currInputs1);
1491 FpNtk2 = computeCofactor(pNtk2, nodesInLevel2, bitVector2, currInputs2);
1492
1493 Abc_NtkForEachPo( FpNtk1, pObj, m )
1494 {
1495 int n;
1496 vSupp = Abc_NtkNodeSupport( FpNtk1, &pObj, 1 );
1497
1498 for(n = 0; n < vSupp->nSize; n++)
1499 if( Abc_ObjId((Abc_Obj_t *)vSupp->pArray[n]) == 1 )
1500 suppNum1 += Vec_IntFind( matchedOutputs1, m) + 1;
1501
1502 Vec_PtrFree( vSupp );
1503 }
1504
1505 Abc_NtkForEachPo( FpNtk2, pObj, m )
1506 {
1507 int n;
1508 vSupp = Abc_NtkNodeSupport( FpNtk2, &pObj, 1 );
1509
1510 for(n = 0; n < vSupp->nSize; n++)
1511 if( (int)Abc_ObjId((Abc_Obj_t *)vSupp->pArray[n])-1 < (Vec_IntSize(iMatch2[i]))-idx+1 &&
1512 (int)Abc_ObjId((Abc_Obj_t *)vSupp->pArray[n])-1 >= 0)
1513 suppNum2[Abc_ObjId((Abc_Obj_t *)vSupp->pArray[n])-1] += Vec_IntFind( matchedOutputs2, m) + 1;
1514
1515 Vec_PtrFree( vSupp );
1516 }
1517
1518 /*if(suppNum1 != 0)
1519 printf("Ntk1 is trigged");
1520
1521 if(suppNum2[0] != 0)
1522 printf("Ntk2 is trigged");*/
1523
1524 for(m = 0; m < Vec_IntSize(iMatch2[i])-idx+1; m++)
1525 if(suppNum2[m] != suppNum1)
1526 {
1527 skipList[m+idx-1] = TRUE;
1528 /*printf("input is skipped");*/
1529 }
1530
1531 Abc_NtkDelete( FpNtk1 );
1532 Abc_NtkDelete( FpNtk2 );
1533 ABC_FREE( bitVector1 );
1534 ABC_FREE( bitVector2 );
1535 Vec_IntFree( currInputs1 );
1536 Vec_IntFree( currInputs2 );
1537 ABC_FREE( suppNum2 );
1538 }
1539
1540 Vec_PtrClear(oMatchPairs);
1541 Abc_NtkDelete( subNtk2 );
1542 Vec_IntFree(mismatch);
1543
1544 //Vec_IntWriteEntry(iMatch2[i], j, tempJ);
1545
1546 if( MATCH_FOUND == FALSE )
1547 Vec_IntPop(matchedInputs2);
1548 }
1549
1550 if( MATCH_FOUND == FALSE )
1551 {
1552 Vec_IntPop(matchedInputs1);
1553
1554 if(idx == 1)
1555 {
1556 for(m = 0; m < Vec_IntSize(oNonSingleton); m++)
1557 Vec_IntPop( oMatchedGroups );
1558 }
1559 }
1560
1561 Vec_IntFree( oNonSingleton );
1562 Vec_PtrFree( oMatchPairs );
1563 ABC_FREE( skipList );
1564 Abc_NtkDelete( subNtk1 );
1565
1566 if(MATCH_FOUND && counter != 0)
1567 {
1568 /*printf("Number of INPUT SAT instances = %d\n", counter);*/
1569
1570 counter = 0;
1571 }
1572
1573 return MATCH_FOUND;
1574}
int match1by1(Abc_Ntk_t *pNtk1, Vec_Ptr_t **nodesInLevel1, Vec_Int_t **iMatch1, Vec_Int_t **iDep1, Vec_Int_t *matchedInputs1, int *iGroup1, Vec_Int_t **oMatch1, int *oGroup1, Abc_Ntk_t *pNtk2, Vec_Ptr_t **nodesInLevel2, Vec_Int_t **iMatch2, Vec_Int_t **iDep2, Vec_Int_t *matchedInputs2, int *iGroup2, Vec_Int_t **oMatch2, int *oGroup2, Vec_Int_t *matchedOutputs1, Vec_Int_t *matchedOutputs2, Vec_Int_t *oMatchedGroups, Vec_Int_t *iNonSingleton, int ii, int idx)
Definition abcBm.c:1331
Abc_Ntk_t * computeCofactor(Abc_Ntk_t *pNtk, Vec_Ptr_t **nodesInLevel, int *bitVector, Vec_Int_t *currInputs)
Definition abcBm.c:1099
int matchNonSingletonOutputs(Abc_Ntk_t *pNtk1, Vec_Ptr_t **nodesInLevel1, Vec_Int_t **iMatch1, Vec_Int_t **iDep1, Vec_Int_t *matchedInputs1, int *iGroup1, Vec_Int_t **oMatch1, int *oGroup1, Abc_Ntk_t *pNtk2, Vec_Ptr_t **nodesInLevel2, Vec_Int_t **iMatch2, Vec_Int_t **iDep2, Vec_Int_t *matchedInputs2, int *iGroup2, Vec_Int_t **oMatch2, int *oGroup2, Vec_Int_t *matchedOutputs1, Vec_Int_t *matchedOutputs2, Vec_Int_t *oMatchedGroups, Vec_Int_t *iNonSingleton, Abc_Ntk_t *subNtk1, Abc_Ntk_t *subNtk2, Vec_Ptr_t *oMatchPairs, Vec_Int_t *oNonSingleton, int oI, int idx, int ii, int iidx)
Definition abcBm.c:1185
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchNonSingletonOutputs()

int matchNonSingletonOutputs ( Abc_Ntk_t * pNtk1,
Vec_Ptr_t ** nodesInLevel1,
Vec_Int_t ** iMatch1,
Vec_Int_t ** iDep1,
Vec_Int_t * matchedInputs1,
int * iGroup1,
Vec_Int_t ** oMatch1,
int * oGroup1,
Abc_Ntk_t * pNtk2,
Vec_Ptr_t ** nodesInLevel2,
Vec_Int_t ** iMatch2,
Vec_Int_t ** iDep2,
Vec_Int_t * matchedInputs2,
int * iGroup2,
Vec_Int_t ** oMatch2,
int * oGroup2,
Vec_Int_t * matchedOutputs1,
Vec_Int_t * matchedOutputs2,
Vec_Int_t * oMatchedGroups,
Vec_Int_t * iNonSingleton,
Abc_Ntk_t * subNtk1,
Abc_Ntk_t * subNtk2,
Vec_Ptr_t * oMatchPairs,
Vec_Int_t * oNonSingleton,
int oI,
int idx,
int ii,
int iidx )

Definition at line 1185 of file abcBm.c.

1190{
1191 static int MATCH_FOUND;
1192 int i;
1193 int j, temp;
1194 Vec_Int_t * mismatch;
1195 int * skipList;
1196 static int counter = 0;
1197
1198 MATCH_FOUND = FALSE;
1199
1200 if( oI == Vec_IntSize( oNonSingleton ) )
1201 {
1202 if( iNonSingleton != NULL)
1203 if( match1by1(pNtk1, nodesInLevel1, iMatch1, iDep1, matchedInputs1, iGroup1, oMatch1, oGroup1,
1204 pNtk2, nodesInLevel2, iMatch2, iDep2, matchedInputs2, iGroup2, oMatch2, oGroup2,
1205 matchedOutputs1, matchedOutputs2, oMatchedGroups, iNonSingleton, ii, iidx) )
1206 MATCH_FOUND = TRUE;
1207
1208 if( iNonSingleton == NULL)
1209 MATCH_FOUND = TRUE;
1210
1211 return MATCH_FOUND;
1212 }
1213
1214 i = Vec_IntEntry(oNonSingleton, oI);
1215
1216 mismatch = Vec_IntAlloc(10);
1217
1218 skipList = ABC_ALLOC(int, Vec_IntSize(oMatch1[i]));
1219
1220 for(j = 0; j < Vec_IntSize(oMatch1[i]); j++)
1221 skipList[j] = FALSE;
1222
1223 Vec_PtrPush(oMatchPairs, Abc_NtkPo(subNtk1, Vec_IntEntry(oMatch1[i], idx)) );
1224 Vec_IntPush(matchedOutputs1, Vec_IntEntry(oMatch1[i], idx));
1225
1226 for(j = 0; j < Vec_IntSize( oMatch2[i] ) && MATCH_FOUND == FALSE; j++)
1227 {
1228 if( Vec_IntEntry(oMatch2[i], j) == -1 || skipList[j] == TRUE)
1229 continue;
1230
1231 Vec_PtrPush(oMatchPairs, Abc_NtkPo(subNtk2, Vec_IntEntry(oMatch2[i], j)));
1232 Vec_IntPush(matchedOutputs2, Vec_IntEntry(oMatch2[i], j));
1233
1234 counter++;
1235 if( Abc_NtkBmSat( subNtk1, subNtk2, NULL, oMatchPairs, mismatch, 0) )
1236 {
1237 /*fprintf(matchFile, "%s matched to %s\n", Abc_ObjName(Abc_NtkPo(pNtk1, Vec_IntEntry(oMatch1[i], idx))),
1238 Abc_ObjName(Abc_NtkPo(pNtk2, Vec_IntEntry(oMatch2[i], j)))); */
1239
1240 temp = Vec_IntEntry(oMatch2[i], j);
1241 Vec_IntWriteEntry(oMatch2[i], j, -1);
1242
1243 if(idx != Vec_IntSize( oMatch1[i] ) - 1)
1244 // call the same function with idx+1
1245 matchNonSingletonOutputs(pNtk1, nodesInLevel1, iMatch1, iDep1, matchedInputs1, iGroup1, oMatch1, oGroup1,
1246 pNtk2, nodesInLevel2, iMatch2, iDep2, matchedInputs2, iGroup2, oMatch2, oGroup2,
1247 matchedOutputs1, matchedOutputs2, oMatchedGroups, iNonSingleton,
1248 subNtk1, subNtk2, oMatchPairs,
1249 oNonSingleton, oI, idx+1, ii, iidx);
1250 else
1251 // call the same function with idx = 0 and oI++
1252 matchNonSingletonOutputs(pNtk1, nodesInLevel1, iMatch1, iDep1, matchedInputs1, iGroup1, oMatch1, oGroup1,
1253 pNtk2, nodesInLevel2, iMatch2, iDep2, matchedInputs2, iGroup2, oMatch2, oGroup2,
1254 matchedOutputs1, matchedOutputs2, oMatchedGroups, iNonSingleton,
1255 subNtk1, subNtk2, oMatchPairs,
1256 oNonSingleton, oI+1, 0, ii, iidx);
1257
1258 Vec_IntWriteEntry(oMatch2[i], j, temp);
1259 }
1260 else
1261 {
1262 int * output1, * output2;
1263 int k;
1264 Abc_Obj_t * pObj;
1265 int * pModel;
1266 char * vPiValues;
1267
1268
1269 vPiValues = ABC_ALLOC( char, Abc_NtkPiNum(subNtk1) + 1);
1270 vPiValues[Abc_NtkPiNum(subNtk1)] = '\0';
1271
1272 for(k = 0; k < Abc_NtkPiNum(subNtk1); k++)
1273 vPiValues[k] = '0';
1274
1275 for(k = 0; k < Vec_IntSize(mismatch); k += 2)
1276 vPiValues[Vec_IntEntry(mismatch, k)] = Vec_IntEntry(mismatch, k+1);
1277
1278 pModel = ABC_ALLOC( int, Abc_NtkCiNum(subNtk1) );
1279
1280 Abc_NtkForEachPi( subNtk1, pObj, k )
1281 pModel[k] = vPiValues[k] - '0';
1282 Abc_NtkForEachLatch( subNtk1, pObj, k )
1283 pModel[Abc_NtkPiNum(subNtk1)+k] = pObj->iData - 1;
1284
1285 output1 = Abc_NtkVerifySimulatePattern( subNtk1, pModel );
1286
1287 Abc_NtkForEachLatch( subNtk2, pObj, k )
1288 pModel[Abc_NtkPiNum(subNtk2)+k] = pObj->iData - 1;
1289
1290 output2 = Abc_NtkVerifySimulatePattern( subNtk2, pModel );
1291
1292
1293 for(k = 0; k < Vec_IntSize( oMatch1[i] ); k++)
1294 if(output1[Vec_IntEntry(oMatch1[i], idx)] != output2[Vec_IntEntry(oMatch2[i], k)])
1295 {
1296 skipList[k] = TRUE;
1297 /*printf("Output is SKIPPED");*/
1298 }
1299
1300 ABC_FREE( vPiValues );
1301 ABC_FREE( pModel );
1302 ABC_FREE( output1 );
1303 ABC_FREE( output2 );
1304 }
1305
1306 if(MATCH_FOUND == FALSE )
1307 {
1308 Vec_PtrPop(oMatchPairs);
1309 Vec_IntPop(matchedOutputs2);
1310 }
1311 }
1312
1313 if(MATCH_FOUND == FALSE )
1314 {
1315 Vec_PtrPop(oMatchPairs);
1316 Vec_IntPop(matchedOutputs1);
1317 }
1318
1319 if(MATCH_FOUND && counter != 0)
1320 {
1321 /*printf("Number of OUTPUT SAT instances = %d", counter);*/
1322 counter = 0;
1323 }
1324
1325 ABC_FREE( mismatch );
1326 ABC_FREE( skipList );
1327
1328 return MATCH_FOUND;
1329}
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
int iData
Definition abc.h:146
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oSortDependencies()

void oSortDependencies ( Abc_Ntk_t * pNtk,
Vec_Int_t ** oDep,
int * iGroup )

Definition at line 243 of file abcBm.c.

244{
245 int i, j, k;
246 Vec_Int_t * temp;
247 Vec_Int_t * iGroupList;
248
249 iGroupList = Vec_IntAlloc( 10 );
250
251 for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
252 {
253 if(Vec_IntSize(oDep[i]) == 1)
254 continue;
255
256 temp = Vec_IntAlloc( Vec_IntSize(oDep[i]) );
257
258 for(j = 0; j < Vec_IntSize(oDep[i]); j++)
259 Vec_IntPushUniqueOrder(iGroupList, iGroup[Vec_IntEntry(oDep[i], j)]);
260
261 for(j = 0; j < Vec_IntSize(iGroupList); j++)
262 {
263 for(k = 0; k < Vec_IntSize(oDep[i]); k++)
264 if(iGroup[Vec_IntEntry(oDep[i], k)] == Vec_IntEntry(iGroupList, j))
265 {
266 Vec_IntPush( temp, Vec_IntEntry(oDep[i], k) );
267 Vec_IntRemove( oDep[i], Vec_IntEntry(oDep[i], k) );
268 k--;
269 }
270 }
271
272 Vec_IntFree( oDep[i] );
273 oDep[i] = temp;
274 Vec_IntClear( iGroupList );
275
276 /*printf("Output %d: ", i);
277 for(j = 0; j < Vec_IntSize(oDep[i]); j++)
278 printf("%d ", Vec_IntEntry(oDep[i], j));
279 printf("\n");*/
280 }
281
282 Vec_IntFree( iGroupList );
283}
Here is the caller graph for this function:

◆ oSplitByDep()

int oSplitByDep ( Abc_Ntk_t * pNtk,
Vec_Int_t ** oDep,
Vec_Int_t ** oMatch,
int * oGroup,
int * oLastItem,
int * iGroup )

Definition at line 285 of file abcBm.c.

286{
287 int i, j, k;
288 int numOfItemsAdded;
289 Vec_Int_t * array, * sortedArray;
290
291 numOfItemsAdded = 0;
292
293 for(i = 0; i < *oLastItem; i++)
294 {
295 if(Vec_IntSize(oMatch[i]) == 1)
296 continue;
297
298 array = Vec_IntAlloc( Vec_IntSize(oMatch[i]) );
299 sortedArray = Vec_IntAlloc( Vec_IntSize(oMatch[i]) );
300
301 for(j = 0; j < Vec_IntSize(oMatch[i]); j++)
302 {
303 int factor, encode;
304
305 encode = 0;
306 factor = 1;
307
308 for(k = 0; k < Vec_IntSize(oDep[Vec_IntEntry(oMatch[i], j)]); k++)
309 encode += iGroup[Vec_IntEntry(oDep[Vec_IntEntry(oMatch[i], j)], k)] * factor;
310
311 Vec_IntPush(array, encode);
312 Vec_IntPushUniqueOrder(sortedArray, encode);
313
314 if( encode < 0)
315 printf("WARNING! Integer overflow!");
316
317 //printf("%d ", Vec_IntEntry(array, j));
318 }
319
320 while( Vec_IntSize(sortedArray) > 1 )
321 {
322 for(k = 0; k < Vec_IntSize(oMatch[i]); k++)
323 {
324 if(Vec_IntEntry(array, k) == Vec_IntEntryLast(sortedArray))
325 {
326 Vec_IntPush(oMatch[*oLastItem+numOfItemsAdded], Vec_IntEntry(oMatch[i], k));
327 oGroup[Vec_IntEntry(oMatch[i], k)] = *oLastItem+numOfItemsAdded;
328 Vec_IntRemove( oMatch[i], Vec_IntEntry(oMatch[i], k) );
329 Vec_IntRemove( array, Vec_IntEntry(array, k) );
330 k--;
331 }
332 }
333 numOfItemsAdded++;
334 Vec_IntPop(sortedArray);
335 }
336
337 Vec_IntFree( array );
338 Vec_IntFree( sortedArray );
339 //printf("\n");
340 }
341
342 *oLastItem += numOfItemsAdded;
343
344 /*printf("\n");
345 for(j = 0; j < *oLastItem ; j++)
346 {
347 printf("oMatch %d: ", j);
348 for(i = 0; i < Vec_IntSize(oMatch[j]); i++)
349 printf("%d ", Vec_IntEntry(oMatch[j], i));
350 printf("\n");
351 }*/
352
353 return numOfItemsAdded;
354}
Here is the caller graph for this function:

◆ refineBySAT()

float refineBySAT ( Abc_Ntk_t * pNtk1,
Vec_Int_t ** iMatch1,
int * iGroup1,
Vec_Int_t ** iDep1,
int * iLastItem1,
Vec_Int_t ** oMatch1,
int * oGroup1,
Vec_Int_t ** oDep1,
int * oLastItem1,
int * observability1,
Abc_Ntk_t * pNtk2,
Vec_Int_t ** iMatch2,
int * iGroup2,
Vec_Int_t ** iDep2,
int * iLastItem2,
Vec_Int_t ** oMatch2,
int * oGroup2,
Vec_Int_t ** oDep2,
int * oLastItem2,
int * observability2 )

Definition at line 1576 of file abcBm.c.

1578{
1579 int i, j;
1580 Abc_Obj_t * pObj;
1581 Vec_Int_t * iNonSingleton;
1582 Vec_Int_t * matchedInputs1, * matchedInputs2;
1583 Vec_Int_t * matchedOutputs1, * matchedOutputs2;
1584 Vec_Ptr_t ** nodesInLevel1, ** nodesInLevel2;
1585 Vec_Int_t * oMatchedGroups;
1586 FILE *result;
1587 int matchFound;
1588 abctime clk = Abc_Clock();
1589 float satTime = 0.0;
1590
1591 /*matchFile = fopen("satmatch.txt", "w");*/
1592
1593 iNonSingleton = Vec_IntAlloc(10);
1594
1595 matchedInputs1 = Vec_IntAlloc( Abc_NtkPiNum(pNtk1) );
1596 matchedInputs2 = Vec_IntAlloc( Abc_NtkPiNum(pNtk2) );
1597
1598 matchedOutputs1 = Vec_IntAlloc( Abc_NtkPoNum(pNtk1) );
1599 matchedOutputs2 = Vec_IntAlloc( Abc_NtkPoNum(pNtk2) );
1600
1601 nodesInLevel1 = ABC_ALLOC( Vec_Ptr_t *, Abc_AigLevel( pNtk1 ) + 1); // why numOfLevels+1? because the inputs are in level 0
1602 for(i = 0; i <= Abc_AigLevel( pNtk1 ); i++)
1603 nodesInLevel1[i] = Vec_PtrAlloc( 20 );
1604
1605 // bucket sort the objects based on their levels
1606 Abc_AigForEachAnd( pNtk1, pObj, i )
1607 Vec_PtrPush(nodesInLevel1[Abc_ObjLevel(pObj)], pObj);
1608
1609 nodesInLevel2 = ABC_ALLOC( Vec_Ptr_t *, Abc_AigLevel( pNtk2 ) + 1); // why numOfLevels+1? because the inputs are in level 0
1610 for(i = 0; i <= Abc_AigLevel( pNtk2 ); i++)
1611 nodesInLevel2[i] = Vec_PtrAlloc( 20 );
1612
1613 // bucket sort the objects based on their levels
1614 Abc_AigForEachAnd( pNtk2, pObj, i )
1615 Vec_PtrPush(nodesInLevel2[Abc_ObjLevel(pObj)], pObj);
1616
1617 oMatchedGroups = Vec_IntAlloc( 10 );
1618
1619 for(i = 0; i < *iLastItem1; i++)
1620 {
1621 if(Vec_IntSize(iMatch1[i]) == 1)
1622 {
1623 Vec_IntPush(matchedInputs1, Vec_IntEntryLast(iMatch1[i]));
1624 Vec_IntPush(matchedInputs2, Vec_IntEntryLast(iMatch2[i]));
1625 }
1626 else
1627 Vec_IntPush(iNonSingleton, i);
1628 }
1629
1630 for(i = 0; i < *oLastItem1; i++)
1631 {
1632 if(Vec_IntSize(oMatch1[i]) == 1)
1633 {
1634 Vec_IntPush(matchedOutputs1, Vec_IntEntryLast(oMatch1[i]));
1635 Vec_IntPush(matchedOutputs2, Vec_IntEntryLast(oMatch2[i]));
1636 }
1637 }
1638
1639 for(i = 0; i < Vec_IntSize(iNonSingleton) - 1; i++)
1640 {
1641 for(j = i + 1; j < Vec_IntSize(iNonSingleton); j++)
1642 if( observability2[Vec_IntEntry(iMatch2[Vec_IntEntry(iNonSingleton, j)], 0)] >
1643 observability2[Vec_IntEntry(iMatch2[Vec_IntEntry(iNonSingleton, i)], 0)] )
1644 {
1645 int temp = Vec_IntEntry(iNonSingleton, i);
1646 Vec_IntWriteEntry( iNonSingleton, i, Vec_IntEntry(iNonSingleton, j) );
1647 Vec_IntWriteEntry( iNonSingleton, j, temp );
1648 }
1649 else if( observability2[Vec_IntEntry(iMatch2[Vec_IntEntry(iNonSingleton, j)], 0)] ==
1650 observability2[Vec_IntEntry(iMatch2[Vec_IntEntry(iNonSingleton, i)], 0)] )
1651 {
1652 if( Vec_IntSize(iMatch2[Vec_IntEntry(iNonSingleton, j)]) < Vec_IntSize(iMatch2[Vec_IntEntry(iNonSingleton, i)]) )
1653 {
1654 int temp = Vec_IntEntry(iNonSingleton, i);
1655 Vec_IntWriteEntry( iNonSingleton, i, Vec_IntEntry(iNonSingleton, j) );
1656 Vec_IntWriteEntry( iNonSingleton, j, temp );
1657 }
1658 }
1659 }
1660
1661 /*for(i = 0; i < Vec_IntSize(iNonSingleton) - 1; i++)
1662 {
1663 for(j = i + 1; j < Vec_IntSize(iNonSingleton); j++)
1664 if( Vec_IntSize(oDep2[oGroup2[Vec_IntEntryLast(iMatch2[Vec_IntEntry(iNonSingleton, j)])]]) >
1665 Vec_IntSize(oDep2[oGroup2[Vec_IntEntryLast(iMatch2[Vec_IntEntry(iNonSingleton, i)])]]) )
1666 {
1667 int temp = Vec_IntEntry(iNonSingleton, i);
1668 Vec_IntWriteEntry( iNonSingleton, i, Vec_IntEntry(iNonSingleton, j) );
1669 Vec_IntWriteEntry( iNonSingleton, j, temp );
1670 }
1671 else if( Vec_IntSize(oDep2[oGroup2[Vec_IntEntryLast(iMatch2[Vec_IntEntry(iNonSingleton, j)])]]) ==
1672 Vec_IntSize(oDep2[oGroup2[Vec_IntEntryLast(iMatch2[Vec_IntEntry(iNonSingleton, i)])]]) )
1673 {
1674 if( observability2[Vec_IntEntry(iMatch2[Vec_IntEntry(iNonSingleton, j)], 0)] >
1675 observability2[Vec_IntEntry(iMatch2[Vec_IntEntry(iNonSingleton, i)], 0)] )
1676 {
1677 int temp = Vec_IntEntry(iNonSingleton, i);
1678 Vec_IntWriteEntry( iNonSingleton, i, Vec_IntEntry(iNonSingleton, j) );
1679 Vec_IntWriteEntry( iNonSingleton, j, temp );
1680 }
1681 }
1682 }*/
1683
1684 matchFound = match1by1(pNtk1, nodesInLevel1, iMatch1, iDep1, matchedInputs1, iGroup1, oMatch1, oGroup1,
1685 pNtk2, nodesInLevel2, iMatch2, iDep2, matchedInputs2, iGroup2, oMatch2, oGroup2,
1686 matchedOutputs1, matchedOutputs2, oMatchedGroups, iNonSingleton, 0, 0);
1687
1688 if( matchFound && Vec_IntSize(matchedOutputs1) != Abc_NtkPoNum(pNtk1) )
1689 {
1690 Vec_Int_t * oNonSingleton;
1691 Vec_Ptr_t * oMatchPairs;
1692 Abc_Ntk_t * subNtk1, * subNtk2;
1693
1694 oNonSingleton = Vec_IntAlloc( 10 );
1695
1696 oMatchPairs = Vec_PtrAlloc(Abc_NtkPoNum(pNtk1) * 2);
1697
1698 for(i = 0; i < *oLastItem1; i++)
1699 if( Vec_IntSize(oMatch1[i]) > 1 && Vec_IntFind( oMatchedGroups, i) == -1 )
1700 Vec_IntPush(oNonSingleton, i);
1701
1702 subNtk1 = computeCofactor(pNtk1, nodesInLevel1, NULL, matchedInputs1);
1703 subNtk2 = computeCofactor(pNtk2, nodesInLevel2, NULL, matchedInputs2);
1704
1705 matchFound = matchNonSingletonOutputs(pNtk1, nodesInLevel1, iMatch1, iDep1, matchedInputs1, iGroup1, oMatch1, oGroup1,
1706 pNtk2, nodesInLevel2, iMatch2, iDep2, matchedInputs2, iGroup1, oMatch2, oGroup2,
1707 matchedOutputs1, matchedOutputs2, oMatchedGroups, NULL,
1708 subNtk1, subNtk2, oMatchPairs, oNonSingleton, 0, 0, 0, 0);
1709
1710 Vec_IntFree( oNonSingleton );
1711 Vec_PtrFree( oMatchPairs );
1712
1713 Abc_NtkDelete(subNtk1);
1714 Abc_NtkDelete(subNtk2);
1715 }
1716
1717 satTime = (float)(Abc_Clock() - clk)/(float)(CLOCKS_PER_SEC);
1718
1719 if( matchFound )
1720 {
1721 checkEquivalence( pNtk1, matchedInputs1, matchedOutputs1, pNtk2, matchedInputs2, matchedOutputs2);
1722
1723 result = fopen("IOmatch.txt", "w");
1724
1725 fprintf(result, "I/O = %d / %d \n\n", Abc_NtkPiNum(pNtk1), Abc_NtkPoNum(pNtk1));
1726
1727 for(i = 0; i < Vec_IntSize(matchedInputs1) ; i++)
1728 fprintf(result, "{%s}\t{%s}\n", Abc_ObjName(Abc_NtkPi(pNtk1, Vec_IntEntry(matchedInputs1, i))), Abc_ObjName(Abc_NtkPi(pNtk2, Vec_IntEntry(matchedInputs2, i))) );
1729
1730 fprintf(result, "\n-----------------------------------------\n");
1731
1732 for(i = 0; i < Vec_IntSize(matchedOutputs1) ; i++)
1733 fprintf(result, "{%s}\t{%s}\n", Abc_ObjName(Abc_NtkPo(pNtk1, Vec_IntEntry(matchedOutputs1, i))), Abc_ObjName(Abc_NtkPo(pNtk2, Vec_IntEntry(matchedOutputs2, i))) );
1734
1735 fclose( result );
1736 }
1737
1738 Vec_IntFree( matchedInputs1 );
1739 Vec_IntFree( matchedInputs2 );
1740 Vec_IntFree( matchedOutputs1 );
1741 Vec_IntFree( matchedOutputs2 );
1742 Vec_IntFree( iNonSingleton );
1743 Vec_IntFree( oMatchedGroups );
1744
1745 for(i = 0; i <= Abc_AigLevel( pNtk1 ); i++)
1746 Vec_PtrFree( nodesInLevel1[i] );
1747 for(i = 0; i <= Abc_AigLevel( pNtk2 ); i++)
1748 Vec_PtrFree( nodesInLevel2[i] );
1749
1750
1751 ABC_FREE( nodesInLevel1 );
1752 ABC_FREE( nodesInLevel2 );
1753 /*fclose(matchFile);*/
1754
1755 return satTime;
1756}
int checkEquivalence(Abc_Ntk_t *pNtk1, Vec_Int_t *matchedInputs1, Vec_Int_t *matchedOutputs1, Abc_Ntk_t *pNtk2, Vec_Int_t *matchedInputs2, Vec_Int_t *matchedOutputs2)
Definition abcBm.c:1063
Here is the call graph for this function:
Here is the caller graph for this function:

◆ refineIOBySimulation()

int refineIOBySimulation ( Abc_Ntk_t * pNtk,
Vec_Int_t ** iMatch,
int * iLastItem,
int * iGroup,
Vec_Int_t ** iDep,
Vec_Int_t ** oMatch,
int * oLastItem,
int * oGroup,
Vec_Int_t ** oDep,
char * vPiValues,
int * observability,
Vec_Ptr_t ** topOrder )

Definition at line 510 of file abcBm.c.

511{
512 Abc_Obj_t * pObj;
513 int * pModel;//, ** pModel2;
514 int * output, * output2;
515 int lastItem;
516 int i, j, k;
517 Vec_Int_t * iComputedNum, * iComputedNumSorted;
518 Vec_Int_t * oComputedNum; // encoding the number of flips
519 int factor;
520 int isRefined = FALSE;
521
522 pModel = ABC_ALLOC( int, Abc_NtkCiNum(pNtk) );
523
524 Abc_NtkForEachPi( pNtk, pObj, i )
525 pModel[i] = vPiValues[i] - '0';
526 Abc_NtkForEachLatch( pNtk, pObj, i )
527 pModel[Abc_NtkPiNum(pNtk)+i] = pObj->iData - 1;
528
529 output = Abc_NtkVerifySimulatePattern( pNtk, pModel );
530
531 oComputedNum = Vec_IntAlloc( Abc_NtkPoNum(pNtk) );
532 for(i = 0; i < Abc_NtkPoNum(pNtk); i++)
533 Vec_IntPush(oComputedNum, 0);
534
535 /****************************************************************************************/
536 /********** group outputs that produce 1 and outputs that produce 0 together ************/
537
538 lastItem = *oLastItem;
539 for(i = 0; i < lastItem && (*oLastItem) != Abc_NtkPoNum(pNtk); i++)
540 {
541 int flag = FALSE;
542
543 if(Vec_IntSize(oMatch[i]) == 1)
544 continue;
545
546 for(j = 1; j < Vec_IntSize(oMatch[i]); j++)
547 if(output[Vec_IntEntry(oMatch[i], 0)] != output[Vec_IntEntry(oMatch[i], j)])
548 {
549 flag = TRUE;
550 break;
551 }
552
553 if(flag)
554 {
555 for(j = 0; j < Vec_IntSize(oMatch[i]); j++)
556 if(output[Vec_IntEntry(oMatch[i], j)])
557 {
558 Vec_IntPush(oMatch[*oLastItem], Vec_IntEntry(oMatch[i], j));
559 oGroup[Vec_IntEntry(oMatch[i], j)] = *oLastItem;
560 Vec_IntRemove(oMatch[i], Vec_IntEntry(oMatch[i], j));
561 j--;
562 }
563
564 (*oLastItem)++;
565 }
566 }
567
568 if( (*oLastItem) > lastItem )
569 {
570 isRefined = TRUE;
571 iSortDependencies(pNtk, iDep, oGroup);
572 }
573
574 /****************************************************************************************/
575 /************* group inputs that make the same number of flips in outpus ****************/
576
577 lastItem = *iLastItem;
578 for(i = 0; i < lastItem && (*iLastItem) != Abc_NtkPiNum(pNtk); i++)
579 {
580 int num;
581
582 if(Vec_IntSize(iMatch[i]) == 1)
583 continue;
584
585 iComputedNum = Vec_IntAlloc( Vec_IntSize(iMatch[i]) );
586 iComputedNumSorted = Vec_IntAlloc( Vec_IntSize(iMatch[i]) );
587
588 for(j = 0; j < Vec_IntSize(iMatch[i]); j++)
589 {
590 if( vPiValues[Vec_IntEntry(iMatch[i], j)] == '0' )
591 pModel[Vec_IntEntry(iMatch[i], j)] = 1;
592 else
593 pModel[Vec_IntEntry(iMatch[i], j)] = 0;
594
595 //output2 = Abc_NtkVerifySimulatePattern( pNtk, pModel );
596 output2 = Abc_NtkSimulateOneNode( pNtk, pModel, Vec_IntEntry(iMatch[i], j), topOrder );
597
598 num = 0;
599 factor = 1;
600 for(k = 0; k < Vec_IntSize(iDep[Vec_IntEntry(iMatch[i], j)]); k++)
601 {
602 int outputIndex = Vec_IntEntry(iDep[Vec_IntEntry(iMatch[i], j)], k);
603
604 if(output2[outputIndex])
605 num += (oGroup[outputIndex] + 1) * factor;
606
607 if(output[outputIndex] != output2[outputIndex])
608 {
609 int temp = Vec_IntEntry(oComputedNum, outputIndex) + i + 1;
610 Vec_IntWriteEntry(oComputedNum, outputIndex, temp);
611 observability[Vec_IntEntry(iMatch[i], j)]++;
612 }
613 }
614
615 Vec_IntPush(iComputedNum, num);
616 Vec_IntPushUniqueOrder(iComputedNumSorted, num);
617
618 pModel[Vec_IntEntry(iMatch[i], j)] = vPiValues[Vec_IntEntry(iMatch[i], j)] - '0';
619 ABC_FREE( output2 );
620 }
621
622 while( Vec_IntSize( iComputedNumSorted ) > 1 )
623 {
624 for(k = 0; k < Vec_IntSize(iMatch[i]); k++)
625 {
626 if(Vec_IntEntry(iComputedNum, k) == Vec_IntEntryLast(iComputedNumSorted) )
627 {
628 Vec_IntPush(iMatch[*iLastItem], Vec_IntEntry(iMatch[i], k));
629 iGroup[Vec_IntEntry(iMatch[i], k)] = *iLastItem;
630 Vec_IntRemove( iMatch[i], Vec_IntEntry(iMatch[i], k) );
631 Vec_IntRemove( iComputedNum, Vec_IntEntry(iComputedNum, k) );
632 k--;
633 }
634 }
635 (*iLastItem)++;
636 Vec_IntPop( iComputedNumSorted );
637 }
638
639 Vec_IntFree( iComputedNum );
640 Vec_IntFree( iComputedNumSorted );
641 }
642
643 if( (*iLastItem) > lastItem )
644 {
645 isRefined = TRUE;
646 oSortDependencies(pNtk, oDep, iGroup);
647 }
648
649 /****************************************************************************************/
650 /********** encode the number of flips in each output by flipping the outputs ***********/
651 /********** and group all the outputs that have the same encoding ***********/
652
653 lastItem = *oLastItem;
654 for(i = 0; i < lastItem && (*oLastItem) != Abc_NtkPoNum(pNtk); i++)
655 {
656 Vec_Int_t * encode, * sortedEncode; // encoding the number of flips
657
658 if(Vec_IntSize(oMatch[i]) == 1)
659 continue;
660
661 encode = Vec_IntAlloc( Vec_IntSize(oMatch[i]) );
662 sortedEncode = Vec_IntAlloc( Vec_IntSize(oMatch[i]) );
663
664 for(j = 0; j < Vec_IntSize(oMatch[i]); j++)
665 {
666 Vec_IntPush(encode, Vec_IntEntry(oComputedNum, Vec_IntEntry(oMatch[i], j)) );
667 Vec_IntPushUniqueOrder( sortedEncode, Vec_IntEntry(encode, j) );
668 }
669
670 while( Vec_IntSize(sortedEncode) > 1 )
671 {
672 for(j = 0; j < Vec_IntSize(oMatch[i]); j++)
673 if(Vec_IntEntry(encode, j) == Vec_IntEntryLast(sortedEncode))
674 {
675 Vec_IntPush(oMatch[*oLastItem], Vec_IntEntry(oMatch[i], j));
676 oGroup[Vec_IntEntry(oMatch[i], j)] = *oLastItem;
677 Vec_IntRemove( oMatch[i], Vec_IntEntry(oMatch[i], j) );
678 Vec_IntRemove( encode, Vec_IntEntry(encode, j) );
679 j --;
680 }
681
682 (*oLastItem)++;
683 Vec_IntPop( sortedEncode );
684 }
685
686 Vec_IntFree( encode );
687 Vec_IntFree( sortedEncode );
688 }
689
690 if( (*oLastItem) > lastItem )
691 isRefined = TRUE;
692
693 ABC_FREE( pModel );
694 ABC_FREE( output );
695 Vec_IntFree( oComputedNum );
696
697 return isRefined;
698}
int * Abc_NtkSimulateOneNode(Abc_Ntk_t *pNtk, int *pModel, int input, Vec_Ptr_t **topOrder)
Definition abcBm.c:449
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ matchFile

FILE* matchFile

Definition at line 1183 of file abcBm.c.

◆ pValues1__

int* pValues1__

Definition at line 808 of file abcBm.c.

◆ pValues2__

int * pValues2__

Definition at line 808 of file abcBm.c.