abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cutTruth.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cutTruth.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [K-feasible cut computation package.]
8 
9  Synopsis [Incremental truth table computation.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: cutTruth.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "cutInt.h"
22 
24 
25 
26 /*
27  Truth tables computed in this package are represented as bit-strings
28  stored in the cut data structure. Cuts of any number of inputs have
29  the truth table with 2^k bits, where k is the max number of cut inputs.
30 */
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// DECLARATIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 // used in abcCut.c
37 int nTotal = 0;
38 int nGood = 0;
39 int nEqual = 0;
40 
41 ////////////////////////////////////////////////////////////////////////
42 /// FUNCTION DEFINITIONS ///
43 ////////////////////////////////////////////////////////////////////////
44 
45 /**Function*************************************************************
46 
47  Synopsis [Computes the stretching phase of the cut w.r.t. the merged cut.]
48 
49  Description []
50 
51  SideEffects []
52 
53  SeeAlso []
54 
55 ***********************************************************************/
56 static inline unsigned Cut_TruthPhase( Cut_Cut_t * pCut, Cut_Cut_t * pCut1 )
57 {
58  unsigned uPhase = 0;
59  int i, k;
60  for ( i = k = 0; i < (int)pCut->nLeaves; i++ )
61  {
62  if ( k == (int)pCut1->nLeaves )
63  break;
64  if ( pCut->pLeaves[i] < pCut1->pLeaves[k] )
65  continue;
66  assert( pCut->pLeaves[i] == pCut1->pLeaves[k] );
67  uPhase |= (1 << i);
68  k++;
69  }
70  return uPhase;
71 }
72 
73 /**Function*************************************************************
74 
75  Synopsis [Performs truth table computation.]
76 
77  Description [This procedure cannot be used while recording oracle
78  because it will overwrite Num0 and Num1.]
79 
80  SideEffects []
81 
82  SeeAlso []
83 
84 ***********************************************************************/
86 {
87  unsigned uTruth;
88  unsigned * uCanon2;
89  char * pPhases2;
90  assert( pCut->nVarsMax < 6 );
91 
92  // get the direct truth table
93  uTruth = *Cut_CutReadTruth(pCut);
94 
95  // compute the direct truth table
96  Extra_TruthCanonFastN( pCut->nVarsMax, pCut->nLeaves, &uTruth, &uCanon2, &pPhases2 );
97 // uCanon[0] = uCanon2[0];
98 // uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
99 // uPhases[0] = pPhases2[0];
100  pCut->uCanon0 = uCanon2[0];
101  pCut->Num0 = pPhases2[0];
102 
103  // get the complemented truth table
104  uTruth = ~*Cut_CutReadTruth(pCut);
105 
106  // compute the direct truth table
107  Extra_TruthCanonFastN( pCut->nVarsMax, pCut->nLeaves, &uTruth, &uCanon2, &pPhases2 );
108 // uCanon[0] = uCanon2[0];
109 // uCanon[1] = (p->nVarsMax == 6)? uCanon2[1] : uCanon2[0];
110 // uPhases[0] = pPhases2[0];
111  pCut->uCanon1 = uCanon2[0];
112  pCut->Num1 = pPhases2[0];
113 }
114 
115 /**Function*************************************************************
116 
117  Synopsis [Performs truth table computation.]
118 
119  Description []
120 
121  SideEffects []
122 
123  SeeAlso []
124 
125 ***********************************************************************/
126 void Cut_TruthComputeOld( Cut_Cut_t * pCut, Cut_Cut_t * pCut0, Cut_Cut_t * pCut1, int fCompl0, int fCompl1 )
127 {
128  static unsigned uTruth0[8], uTruth1[8];
129  int nTruthWords = Cut_TruthWords( pCut->nVarsMax );
130  unsigned * pTruthRes;
131  int i, uPhase;
132 
133  // permute the first table
134  uPhase = Cut_TruthPhase( pCut, pCut0 );
135  Extra_TruthExpand( pCut->nVarsMax, nTruthWords, Cut_CutReadTruth(pCut0), uPhase, uTruth0 );
136  if ( fCompl0 )
137  {
138  for ( i = 0; i < nTruthWords; i++ )
139  uTruth0[i] = ~uTruth0[i];
140  }
141 
142  // permute the second table
143  uPhase = Cut_TruthPhase( pCut, pCut1 );
144  Extra_TruthExpand( pCut->nVarsMax, nTruthWords, Cut_CutReadTruth(pCut1), uPhase, uTruth1 );
145  if ( fCompl1 )
146  {
147  for ( i = 0; i < nTruthWords; i++ )
148  uTruth1[i] = ~uTruth1[i];
149  }
150 
151  // write the resulting table
152  pTruthRes = Cut_CutReadTruth(pCut);
153 
154  if ( pCut->fCompl )
155  {
156  for ( i = 0; i < nTruthWords; i++ )
157  pTruthRes[i] = ~(uTruth0[i] & uTruth1[i]);
158  }
159  else
160  {
161  for ( i = 0; i < nTruthWords; i++ )
162  pTruthRes[i] = uTruth0[i] & uTruth1[i];
163  }
164 }
165 
166 /**Function*************************************************************
167 
168  Synopsis [Performs truth table computation.]
169 
170  Description []
171 
172  SideEffects []
173 
174  SeeAlso []
175 
176 ***********************************************************************/
177 void Cut_TruthCompute( Cut_Man_t * p, Cut_Cut_t * pCut, Cut_Cut_t * pCut0, Cut_Cut_t * pCut1, int fCompl0, int fCompl1 )
178 {
179  // permute the first table
180  if ( fCompl0 )
181  Extra_TruthNot( p->puTemp[0], Cut_CutReadTruth(pCut0), pCut->nVarsMax );
182  else
183  Extra_TruthCopy( p->puTemp[0], Cut_CutReadTruth(pCut0), pCut->nVarsMax );
184  Extra_TruthStretch( p->puTemp[2], p->puTemp[0], pCut0->nLeaves, pCut->nVarsMax, Cut_TruthPhase(pCut, pCut0) );
185  // permute the second table
186  if ( fCompl1 )
187  Extra_TruthNot( p->puTemp[1], Cut_CutReadTruth(pCut1), pCut->nVarsMax );
188  else
189  Extra_TruthCopy( p->puTemp[1], Cut_CutReadTruth(pCut1), pCut->nVarsMax );
190  Extra_TruthStretch( p->puTemp[3], p->puTemp[1], pCut1->nLeaves, pCut->nVarsMax, Cut_TruthPhase(pCut, pCut1) );
191  // produce the resulting table
192  if ( pCut->fCompl )
193  Extra_TruthNand( Cut_CutReadTruth(pCut), p->puTemp[2], p->puTemp[3], pCut->nVarsMax );
194  else
195  Extra_TruthAnd( Cut_CutReadTruth(pCut), p->puTemp[2], p->puTemp[3], pCut->nVarsMax );
196 
197 // Ivy_TruthTestOne( *Cut_CutReadTruth(pCut) );
198 
199  // quit if no fancy computation is needed
200  if ( !p->pParams->fFancy )
201  return;
202 
203  if ( pCut->nLeaves != 7 )
204  return;
205 
206  // count the total number of truth tables computed
207  nTotal++;
208 
209  // MAPPING INTO ALTERA 6-2 LOGIC BLOCKS
210  // call this procedure to find the minimum number of common variables in the cofactors
211  // if this number is less or equal than 3, the cut can be implemented using the 6-2 logic block
212  if ( Extra_TruthMinCofSuppOverlap( Cut_CutReadTruth(pCut), pCut->nVarsMax, NULL ) <= 4 )
213  nGood++;
214 
215  // MAPPING INTO ACTEL 2x2 CELLS
216  // call this procedure to see if a semi-canonical form can be found in the lookup table
217  // (if it exists, then a two-level 3-input LUT implementation of the cut exists)
218  // Before this procedure is called, cell manager should be defined by calling
219  // Cut_CellLoad (make sure file "cells22_daomap_iwls.txt" is available in the working dir)
220 // if ( Cut_CellIsRunning() && pCut->nVarsMax <= 9 )
221 // nGood += Cut_CellTruthLookup( Cut_CutReadTruth(pCut), pCut->nVarsMax );
222 }
223 
224 
225 
226 ////////////////////////////////////////////////////////////////////////
227 /// END OF FILE ///
228 ////////////////////////////////////////////////////////////////////////
229 
230 
232 
int Extra_TruthCanonFastN(int nVarsMax, int nVarsReal, unsigned *pt, unsigned **pptRes, char **ppfRes)
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Cut_TruthWords(int nVarsMax)
Definition: cutInt.h:125
static unsigned * Cut_CutReadTruth(Cut_Cut_t *p)
Definition: cut.h:94
void Cut_TruthNCanonicize(Cut_Cut_t *pCut)
Definition: cutTruth.c:85
unsigned uCanon1
Definition: cut.h:87
static unsigned Cut_TruthPhase(Cut_Cut_t *pCut, Cut_Cut_t *pCut1)
FUNCTION DEFINITIONS ///.
Definition: cutTruth.c:56
ABC_NAMESPACE_IMPL_START int nTotal
DECLARATIONS ///.
Definition: cutTruth.c:37
int pLeaves[0]
Definition: cut.h:89
unsigned nLeaves
Definition: cut.h:84
unsigned Num0
Definition: cut.h:79
void Extra_TruthExpand(int nVars, int nWords, unsigned *puTruth, unsigned uPhase, unsigned *puTruthR)
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
unsigned uCanon0
Definition: cut.h:86
static void Extra_TruthAnd(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:326
void Extra_TruthStretch(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase)
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int nEqual
Definition: cutTruth.c:39
int Extra_TruthMinCofSuppOverlap(unsigned *pTruth, int nVars, int *pVarMin)
int nGood
Definition: cutTruth.c:38
unsigned fCompl
Definition: cut.h:82
void Cut_TruthComputeOld(Cut_Cut_t *pCut, Cut_Cut_t *pCut0, Cut_Cut_t *pCut1, int fCompl0, int fCompl1)
Definition: cutTruth.c:126
void Cut_TruthCompute(Cut_Man_t *p, Cut_Cut_t *pCut, Cut_Cut_t *pCut0, Cut_Cut_t *pCut1, int fCompl0, int fCompl1)
Definition: cutTruth.c:177
Cut_Params_t * pParams
Definition: cutInt.h:51
#define assert(ex)
Definition: util_old.h:213
unsigned * puTemp[4]
Definition: cutInt.h:73
unsigned Num1
Definition: cut.h:80
static void Extra_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:320
unsigned nVarsMax
Definition: cut.h:83
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
static void Extra_TruthNand(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: extra.h:344