ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ifCheck.c
Go to the documentation of this file.
1
20
21#include "if.h"
22
24
25
29
30#ifdef WIN32
31typedef unsigned __int64 word;
32#else
33typedef unsigned long long word;
34#endif
35
36// elementary truth tables
37static word Truths6[6] = {
38 0xAAAAAAAAAAAAAAAA,
39 0xCCCCCCCCCCCCCCCC,
40 0xF0F0F0F0F0F0F0F0,
41 0xFF00FF00FF00FF00,
42 0xFFFF0000FFFF0000,
43 0xFFFFFFFF00000000
44};
45
49
61int If_ManCutReach_rec( If_Obj_t * pPath, If_Obj_t * pLeaf )
62{
63 if ( pPath == pLeaf )
64 return 1;
65 if ( pPath->fMark )
66 return 0;
67 assert( If_ObjIsAnd(pPath) );
68 if ( If_ManCutReach_rec( If_ObjFanin0(pPath), pLeaf ) )
69 return 1;
70 if ( If_ManCutReach_rec( If_ObjFanin1(pPath), pLeaf ) )
71 return 1;
72 return 0;
73}
74int If_ManCutReach( If_Man_t * p, If_Cut_t * pCut, If_Obj_t * pPath, If_Obj_t * pLeaf )
75{
76 If_Obj_t * pTemp;
77 int i, RetValue;
78 If_CutForEachLeaf( p, pCut, pTemp, i )
79 pTemp->fMark = 1;
80 RetValue = If_ManCutReach_rec( pPath, pLeaf );
81 If_CutForEachLeaf( p, pCut, pTemp, i )
82 pTemp->fMark = 0;
83 return RetValue;
84}
85
97int If_ManCutTruthCheck_rec( If_Obj_t * pObj, word * pTruths )
98{
99 word T0, T1;
100 if ( pObj->fMark )
101 return pTruths[If_ObjId(pObj)];
102 assert( If_ObjIsAnd(pObj) );
103 T0 = If_ManCutTruthCheck_rec( If_ObjFanin0(pObj), pTruths );
104 T1 = If_ManCutTruthCheck_rec( If_ObjFanin1(pObj), pTruths );
105 T0 = If_ObjFaninC0(pObj) ? ~T0 : T0;
106 T1 = If_ObjFaninC1(pObj) ? ~T1 : T1;
107 return T0 & T1;
108}
109int If_ManCutTruthCheck( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut, If_Obj_t * pLeaf, int Cof, word * pTruths )
110{
111 word Truth;
112 If_Obj_t * pTemp;
113 int i, k = 0;
114 assert( Cof == 0 || Cof == 1 );
115 If_CutForEachLeaf( p, pCut, pTemp, i )
116 {
117 assert( pTemp->fMark == 0 );
118 pTemp->fMark = 1;
119 if ( pLeaf == pTemp )
120 pTruths[If_ObjId(pTemp)] = (Cof ? ~((word)0) : 0);
121 else
122 pTruths[If_ObjId(pTemp)] = Truths6[k++] ;
123 }
124 assert( k + 1 == If_CutLeaveNum(pCut) );
125 // compute truth table
126 Truth = If_ManCutTruthCheck_rec( pObj, pTruths );
127 If_CutForEachLeaf( p, pCut, pTemp, i )
128 pTemp->fMark = 0;
129 return Truth == 0 || Truth == ~((word)0);
130}
131
132
144void If_ManCutCheck( If_Man_t * p, If_Obj_t * pObj, If_Cut_t * pCut )
145{
146 static int nDecCalls = 0;
147 static int nDecStruct = 0;
148 static int nDecStruct2 = 0;
149 static int nDecFunction = 0;
150 word * pTruths;
151 If_Obj_t * pLeaf, * pPath;
152 int i;
153 if ( pCut == NULL )
154 {
155 printf( "DecStr = %9d (%6.2f %%).\n", nDecStruct, 100.0*nDecStruct/nDecCalls );
156 printf( "DecStr2 = %9d (%6.2f %%).\n", nDecStruct2, 100.0*nDecStruct2/nDecCalls );
157 printf( "DecFunc = %9d (%6.2f %%).\n", nDecFunction, 100.0*nDecFunction/nDecCalls );
158 printf( "Total = %9d (%6.2f %%).\n", nDecCalls, 100.0*nDecCalls/nDecCalls );
159 return;
160 }
161 assert( If_ObjIsAnd(pObj) );
162 assert( pCut->nLeaves <= 7 );
163 nDecCalls++;
164 // check structural decomposition
165 If_CutForEachLeaf( p, pCut, pLeaf, i )
166 if ( pLeaf == If_ObjFanin0(pObj) || pLeaf == If_ObjFanin1(pObj) )
167 break;
168 if ( i < If_CutLeaveNum(pCut) )
169 {
170 pPath = (pLeaf == If_ObjFanin0(pObj)) ? If_ObjFanin1(pObj) : If_ObjFanin0(pObj);
171 if ( !If_ManCutReach( p, pCut, pPath, pLeaf ) )
172 {
173 nDecStruct++;
174// nDecFunction++;
175// return;
176 }
177 else
178 nDecStruct2++;
179 }
180 // check functional decomposition
181 pTruths = malloc( sizeof(word) * If_ManObjNum(p) );
182 If_CutForEachLeaf( p, pCut, pLeaf, i )
183 {
184 if ( If_ManCutTruthCheck( p, pObj, pCut, pLeaf, 0, pTruths ) )
185 {
186 nDecFunction++;
187 break;
188 }
189 if ( If_ManCutTruthCheck( p, pObj, pCut, pLeaf, 1, pTruths ) )
190 {
191 nDecFunction++;
192 break;
193 }
194 }
195 free( pTruths );
196}
197
201
202
204
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
int If_ManCutReach(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pPath, If_Obj_t *pLeaf)
Definition ifCheck.c:74
void If_ManCutCheck(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut)
Definition ifCheck.c:144
int If_ManCutTruthCheck(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut, If_Obj_t *pLeaf, int Cof, word *pTruths)
Definition ifCheck.c:109
int If_ManCutReach_rec(If_Obj_t *pPath, If_Obj_t *pLeaf)
FUNCTION DEFINITIONS ///.
Definition ifCheck.c:61
int If_ManCutTruthCheck_rec(If_Obj_t *pObj, word *pTruths)
Definition ifCheck.c:97
struct If_Cut_t_ If_Cut_t
Definition if.h:80
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition if.h:503
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
struct If_Obj_t_ If_Obj_t
Definition if.h:79
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
unsigned nLeaves
Definition if.h:316
unsigned fMark
Definition if.h:338
#define assert(ex)
Definition util_old.h:213
VOID_HACK free()
char * malloc()