abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fraigChoice.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fraigTrans.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Adds the additive and distributive choices to the AIG.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 1.0. Started - February 1, 2003.]
14 
15  Revision [$Id: fraigTrans.c,v 1.1 2005/02/28 05:34:34 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fraigInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis [Adds choice nodes based on associativity.]
35 
36  Description [Make nLimit big AND gates and add all decompositions
37  to the Fraig.]
38 
39  SideEffects []
40 
41  SeeAlso []
42 
43 ***********************************************************************/
44 void Fraig_ManAddChoices( Fraig_Man_t * pMan, int fVerbose, int nLimit )
45 {
46 // ProgressBar * pProgress;
47  char Buffer[100];
48  abctime clkTotal = Abc_Clock();
49  int i, nNodesBefore, nNodesAfter, nInputs, nMaxNodes;
50  int /*nMaxLevel,*/ nDistributive;
51  Fraig_Node_t *pNode, *pRepr;
52  Fraig_Node_t *pX, *pA, *pB, *pC, /* *pD,*/ *pN, /* *pQ, *pR,*/ *pT;
53  int fShortCut = 0;
54 
55  nDistributive = 0;
56 
57 // Fraig_ManSetApprox( pMan, 1 );
58 
59  // NO functional reduction
60  if (fShortCut) Fraig_ManSetFuncRed( pMan, 0 );
61 
62  // First we mark critical functions i.e. compute those
63  // nodes which lie on the critical path. Note that this
64  // doesn't update the required times on any choice nodes
65  // which are not the representatives
66 /*
67  nMaxLevel = Fraig_GetMaxLevel( pMan );
68  for ( i = 0; i < pMan->nOutputs; i++ )
69  {
70  Fraig_SetNodeRequired( pMan, pMan->pOutputs[i], nMaxLevel );
71  }
72 */
73  nNodesBefore = Fraig_ManReadNodeNum( pMan );
74  nInputs = Fraig_ManReadInputNum( pMan );
75  nMaxNodes = nInputs + nLimit * ( nNodesBefore - nInputs );
76 
77  printf ("Limit = %d, Before = %d\n", nMaxNodes, nNodesBefore );
78 
79  if (0)
80  {
81  char buffer[128];
82  sprintf (buffer, "test" );
83 // Fraig_MappingShow( pMan, buffer );
84  }
85 
86 // pProgress = Extra_ProgressBarStart( stdout, nMaxNodes );
88 
89  for ( i = nInputs+1; (i < Fraig_ManReadNodeNum( pMan ))
90  && (nMaxNodes > Fraig_ManReadNodeNum( pMan )); ++i )
91  {
92 // if ( i == nNodesBefore )
93 // break;
94 
95  pNode = Fraig_ManReadIthNode( pMan, i );
96  assert ( pNode );
97 
98  pRepr = pNode->pRepr ? pNode->pRepr : pNode;
99  //printf ("Slack: %d\n", Fraig_NodeReadSlack( pRepr ));
100 
101  // All the new associative choices we add will have huge slack
102  // since we do not redo timing, and timing doesnt handle choices
103  // well anyway. However every newly added node is a choice of an
104  // existing critical node, so they are considered critical.
105 // if ( (Fraig_NodeReadSlack( pRepr ) > 3) && (i < nNodesBefore) )
106 // continue;
107 
108 // if ( pNode->pRepr )
109 // continue;
110 
111  // Try ((ab)c), x = ab -> (a(bc)) and (b(ac))
112  pX = Fraig_NodeReadOne(pNode);
113  pC = Fraig_NodeReadTwo(pNode);
114  if (Fraig_NodeIsAnd(pX) && !Fraig_IsComplement(pX))
115  {
118 
119 // pA = Fraig_NodeGetRepr( pA );
120 // pB = Fraig_NodeGetRepr( pB );
121 // pC = Fraig_NodeGetRepr( pC );
122 
123  if (fShortCut)
124  {
125  pT = Fraig_NodeAnd(pMan, pB, pC);
126  if ( !pT->pRepr )
127  {
128  pN = Fraig_NodeAnd(pMan, pA, pT);
129 // Fraig_NodeAddChoice( pMan, pNode, pN );
130  }
131  }
132  else
133  pN = Fraig_NodeAnd(pMan, pA, Fraig_NodeAnd(pMan, pB, pC));
134  // assert ( Fraig_NodesEqual(pN, pNode) );
135 
136 
137  if (fShortCut)
138  {
139  pT = Fraig_NodeAnd(pMan, pA, pC);
140  if ( !pT->pRepr )
141  {
142  pN = Fraig_NodeAnd(pMan, pB, pT);
143 // Fraig_NodeAddChoice( pMan, pNode, pN );
144  }
145  }
146  else
147  pN = Fraig_NodeAnd(pMan, pB, Fraig_NodeAnd(pMan, pA, pC));
148  // assert ( Fraig_NodesEqual(pN, pNode) );
149  }
150 
151 
152  // Try (a(bc)), x = bc -> ((ab)c) and ((ac)b)
153  pA = Fraig_NodeReadOne(pNode);
154  pX = Fraig_NodeReadTwo(pNode);
155  if (Fraig_NodeIsAnd(pX) && !Fraig_IsComplement(pX))
156  {
159 
160 // pA = Fraig_NodeGetRepr( pA );
161 // pB = Fraig_NodeGetRepr( pB );
162 // pC = Fraig_NodeGetRepr( pC );
163 
164  if (fShortCut)
165  {
166  pT = Fraig_NodeAnd(pMan, pA, pB);
167  if ( !pT->pRepr )
168  {
169  pN = Fraig_NodeAnd(pMan, pC, pT);
170 // Fraig_NodeAddChoice( pMan, pNode, pN );
171  }
172  }
173  else
174  pN = Fraig_NodeAnd(pMan, Fraig_NodeAnd(pMan, pA, pB), pC);
175  // assert ( Fraig_NodesEqual(pN, pNode) );
176 
177  if (fShortCut)
178  {
179  pT = Fraig_NodeAnd(pMan, pA, pC);
180  if ( !pT->pRepr )
181  {
182  pN = Fraig_NodeAnd(pMan, pB, pT);
183 // Fraig_NodeAddChoice( pMan, pNode, pN );
184  }
185  }
186  else
187  pN = Fraig_NodeAnd(pMan, Fraig_NodeAnd(pMan, pA, pC), pB);
188  // assert ( Fraig_NodesEqual(pN, pNode) );
189  }
190 
191 
192 /*
193  // Try distributive transform
194  pQ = Fraig_NodeReadOne(pNode);
195  pR = Fraig_NodeReadTwo(pNode);
196  if ( (Fraig_IsComplement(pQ) && Fraig_NodeIsAnd(pQ))
197  && (Fraig_IsComplement(pR) && Fraig_NodeIsAnd(pR)) )
198  {
199  pA = Fraig_NodeReadOne(Fraig_Regular(pQ));
200  pB = Fraig_NodeReadTwo(Fraig_Regular(pQ));
201  pC = Fraig_NodeReadOne(Fraig_Regular(pR));
202  pD = Fraig_NodeReadTwo(Fraig_Regular(pR));
203 
204  // Now detect the !(xy + xz) pattern, store
205  // x in pA, y in pB and z in pC and set pD = 0 to indicate
206  // pattern was found
207  assert (pD != 0);
208  if (pA == pC) { pC = pD; pD = 0; }
209  if (pA == pD) { pD = 0; }
210  if (pB == pC) { pB = pA; pA = pC; pC = pD; pD = 0; }
211  if (pB == pD) { pB = pA; pA = pD; pD = 0; }
212  if (pD == 0)
213  {
214  nDistributive++;
215  pN = Fraig_Not(Fraig_NodeAnd(pMan, pA,
216  Fraig_NodeOr(pMan, pB, pC)));
217  if (fShortCut) Fraig_NodeAddChoice( pMan, pNode, pN );
218  // assert ( Fraig_NodesEqual(pN, pNode) );
219  }
220  }
221 */
222  if ( i % 1000 == 0 )
223  {
224  sprintf( Buffer, "Adding choice %6d...", i - nNodesBefore );
225 // Extra_ProgressBarUpdate( pProgress, i, Buffer );
226  }
227  }
228 
229 // Extra_ProgressBarStop( pProgress );
230 
232 
233  nNodesAfter = Fraig_ManReadNodeNum( pMan );
234  printf ( "Nodes before = %6d. Nodes with associative choices = %6d. Increase = %4.2f %%.\n",
235  nNodesBefore, nNodesAfter, ((float)(nNodesAfter - nNodesBefore)) * 100.0/(nNodesBefore - nInputs) );
236  printf ( "Distributive = %d\n", nDistributive );
237 
238 }
239 
240 ////////////////////////////////////////////////////////////////////////
241 /// END OF FILE ///
242 ////////////////////////////////////////////////////////////////////////
243 
244 
246 
typedefABC_NAMESPACE_HEADER_START struct Fraig_ManStruct_t_ Fraig_Man_t
INCLUDES ///.
Definition: fraig.h:40
ABC_NAMESPACE_IMPL_START void Fraig_ManAddChoices(Fraig_Man_t *pMan, int fVerbose, int nLimit)
DECLARATIONS ///.
Definition: fraigChoice.c:44
static abctime Abc_Clock()
Definition: abc_global.h:279
Fraig_Node_t * Fraig_ManReadIthNode(Fraig_Man_t *p, int i)
Definition: fraigApi.c:53
Fraig_Node_t * Fraig_NodeReadTwo(Fraig_Node_t *p)
Definition: fraigApi.c:112
Fraig_Node_t * Fraig_NodeAnd(Fraig_Man_t *p, Fraig_Node_t *p1, Fraig_Node_t *p2)
Definition: fraigApi.c:212
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int Fraig_NodeIsAnd(Fraig_Node_t *p)
Definition: fraigApi.c:153
char * sprintf()
void Fraig_ManSetFuncRed(Fraig_Man_t *p, int fFuncRed)
Definition: fraigApi.c:88
#define Fraig_IsComplement(p)
GLOBAL VARIABLES ///.
Definition: fraig.h:107
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Fraig_Node_t * Fraig_NodeReadOne(Fraig_Node_t *p)
Definition: fraigApi.c:111
Fraig_Node_t * pRepr
Definition: fraigInt.h:242
#define Fraig_Regular(p)
Definition: fraig.h:108
#define assert(ex)
Definition: util_old.h:213
int Fraig_ManCheckConsistency(Fraig_Man_t *p)
Definition: fraigUtil.c:312
int Fraig_ManReadNodeNum(Fraig_Man_t *p)
Definition: fraigApi.c:51
ABC_INT64_T abctime
Definition: abc_global.h:278
int Fraig_ManReadInputNum(Fraig_Man_t *p)
Definition: fraigApi.c:49