abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ifCheck.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ifCheck.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [FPGA mapping based on priority cuts.]
8 
9  Synopsis [Sequential mapping.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 21, 2006.]
16 
17  Revision [$Id: ifCheck.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "if.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 #ifdef WIN32
31 typedef unsigned __int64 word;
32 #else
33 typedef unsigned long long word;
34 #endif
35 
36 // elementary truth tables
37 static word Truths6[6] = {
38  0xAAAAAAAAAAAAAAAA,
39  0xCCCCCCCCCCCCCCCC,
40  0xF0F0F0F0F0F0F0F0,
41  0xFF00FF00FF00FF00,
42  0xFFFF0000FFFF0000,
43  0xFFFFFFFF00000000
44 };
45 
46 ////////////////////////////////////////////////////////////////////////
47 /// FUNCTION DEFINITIONS ///
48 ////////////////////////////////////////////////////////////////////////
49 
50 /**Function*************************************************************
51 
52  Synopsis [Returns 1 if the node Leaf is reachable on the path.]
53 
54  Description []
55 
56  SideEffects []
57 
58  SeeAlso []
59 
60 ***********************************************************************/
61 int 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 }
74 int 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 
86 /**Function*************************************************************
87 
88  Synopsis [Derive truth table for each cofactor.]
89 
90  Description []
91 
92  SideEffects []
93 
94  SeeAlso []
95 
96 ***********************************************************************/
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 }
109 int 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 
133 /**Function*************************************************************
134 
135  Synopsis [Checks if cut can be structurally/functionally decomposed.]
136 
137  Description [The decomposition is Fn(a,b,c,...) = F2(a, Fn-1(b,c,...)).]
138 
139  SideEffects []
140 
141  SeeAlso []
142 
143 ***********************************************************************/
144 void 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 
198 ////////////////////////////////////////////////////////////////////////
199 /// END OF FILE ///
200 ////////////////////////////////////////////////////////////////////////
201 
202 
204 
static ABC_NAMESPACE_IMPL_START int pTruths[13719]
DECLARATIONS ///.
Definition: rwrTemp.c:30
char * malloc()
unsigned nLeaves
Definition: if.h:289
VOID_HACK free()
static int If_ObjId(If_Obj_t *pObj)
Definition: if.h:379
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Definition: if.h:303
static int If_ObjIsAnd(If_Obj_t *pObj)
Definition: if.h:377
Definition: if.h:275
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: if.h:474
static int If_CutLeaveNum(If_Cut_t *pCut)
Definition: if.h:390
static int If_ObjFaninC0(If_Obj_t *pObj)
Definition: if.h:382
static If_Obj_t * If_ObjFanin0(If_Obj_t *pObj)
Definition: if.h:380
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
static int If_ObjFaninC1(If_Obj_t *pObj)
Definition: if.h:383
void If_ManCutCheck(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut)
Definition: ifCheck.c:144
int If_ManCutTruthCheck_rec(If_Obj_t *pObj, word *pTruths)
Definition: ifCheck.c:97
int If_ManCutReach_rec(If_Obj_t *pPath, If_Obj_t *pLeaf)
FUNCTION DEFINITIONS ///.
Definition: ifCheck.c:61
Definition: if.h:180
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static If_Obj_t * If_ObjFanin1(If_Obj_t *pObj)
Definition: if.h:381
static word Truths6[6]
Definition: ifCheck.c:37
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int If_ManObjNum(If_Man_t *p)
Definition: if.h:363
static ABC_NAMESPACE_IMPL_START word Truth[8]
DECLARATIONS ///.
Definition: giaShrink6.c:32
#define assert(ex)
Definition: util_old.h:213
int If_ManCutReach(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pPath, If_Obj_t *pLeaf)
Definition: ifCheck.c:74
ABC_NAMESPACE_IMPL_START typedef unsigned long long word
DECLARATIONS ///.
Definition: ifCheck.c:33
unsigned fMark
Definition: if.h:310