abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcMeasure.c File Reference
#include "base/abc/abc.h"
#include "bool/kit/kit.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Abc_NtkPrintMeasures (unsigned *pTruth, int nVars)
 DECLARATIONS ///. More...
 
void Abc_Ntk4VarObjPrint_rec (Abc_Obj_t *pObj)
 
unsigned Abc_Ntk4VarObj (Vec_Ptr_t *vNodes)
 
void Abc_Ntk4VarTable (Abc_Ntk_t *pNtk)
 
int Abc_NtkPrintOneDecompCheckCofList (unsigned *uCofs, int nCofs)
 
int Abc_NtkPrintOneDecompCheck (unsigned *uCofs, int nCofs, unsigned uMask)
 
void Abc_NtkPrintOneDecomp_rec (unsigned *uCofs, int nCofs, int nVars, unsigned uMask, int *pBestSize, unsigned *puBestMask)
 
void Abc_NtkPrintOneDecomp (unsigned *pTruth, int nVars)
 
void Abc_NtkPrintOneDec (unsigned *pTruth, int nVars)
 

Function Documentation

unsigned Abc_Ntk4VarObj ( Vec_Ptr_t vNodes)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 144 of file abcMeasure.c.

145 {
146  Abc_Obj_t * pObj;
147  unsigned uTruth0, uTruth1;
148  int i;
149  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
150  {
151  uTruth0 = (unsigned)(Abc_ObjFanin0(pObj)->pCopy);
152  uTruth1 = (unsigned)(Abc_ObjFanin1(pObj)->pCopy);
153  if ( Abc_ObjFaninC0(pObj) )
154  uTruth0 = ~uTruth0;
155  if ( Abc_ObjFaninC1(pObj) )
156  uTruth1 = ~uTruth1;
157  pObj->pCopy = (Abc_Obj_t *)(uTruth0 & uTruth1);
158  }
159  return uTruth0 & uTruth1;
160 }
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
Abc_Obj_t * pCopy
Definition: abc.h:148
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Abc_Ntk4VarObjPrint_rec ( Abc_Obj_t pObj)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 110 of file abcMeasure.c.

111 {
112  if ( pObj == Abc_AigConst1(pObj->pNtk) )
113  {
114  printf( "1" );
115  return;
116  }
117  if ( Abc_ObjIsPi(pObj) )
118  {
119  printf( "%c", pObj->Id - 1 + 'a' );
120  return;
121  }
122 
123  printf( "(" );
125  if ( Abc_ObjFaninC0(pObj) )
126  printf( "\'" );
128  if ( Abc_ObjFaninC1(pObj) )
129  printf( "\'" );
130  printf( ")" );
131 }
static Abc_Obj_t * Abc_ObjFanin1(Abc_Obj_t *pObj)
Definition: abc.h:374
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
static int Abc_ObjFaninC1(Abc_Obj_t *pObj)
Definition: abc.h:378
void Abc_Ntk4VarObjPrint_rec(Abc_Obj_t *pObj)
Definition: abcMeasure.c:110
static int Abc_ObjFaninC0(Abc_Obj_t *pObj)
Definition: abc.h:377
static int Abc_ObjIsPi(Abc_Obj_t *pObj)
Definition: abc.h:347
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
Abc_Ntk_t * pNtk
Definition: abc.h:130
int Id
Definition: abc.h:132
void Abc_Ntk4VarTable ( Abc_Ntk_t pNtk)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 173 of file abcMeasure.c.

174 {
175  static unsigned u4VarTruths[4] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00 };
176  static unsigned u4VarTts[222] = {
177  0x0000, 0x0001, 0x0003, 0x0006, 0x0007, 0x000f, 0x0016, 0x0017, 0x0018, 0x0019,
178  0x001b, 0x001e, 0x001f, 0x003c, 0x003d, 0x003f, 0x0069, 0x006b, 0x006f, 0x007e,
179  0x007f, 0x00ff, 0x0116, 0x0117, 0x0118, 0x0119, 0x011a, 0x011b, 0x011e, 0x011f,
180  0x012c, 0x012d, 0x012f, 0x013c, 0x013d, 0x013e, 0x013f, 0x0168, 0x0169, 0x016a,
181  0x016b, 0x016e, 0x016f, 0x017e, 0x017f, 0x0180, 0x0181, 0x0182, 0x0183, 0x0186,
182  0x0187, 0x0189, 0x018b, 0x018f, 0x0196, 0x0197, 0x0198, 0x0199, 0x019a, 0x019b,
183  0x019e, 0x019f, 0x01a8, 0x01a9, 0x01aa, 0x01ab, 0x01ac, 0x01ad, 0x01ae, 0x01af,
184  0x01bc, 0x01bd, 0x01be, 0x01bf, 0x01e8, 0x01e9, 0x01ea, 0x01eb, 0x01ee, 0x01ef,
185  0x01fe, 0x033c, 0x033d, 0x033f, 0x0356, 0x0357, 0x0358, 0x0359, 0x035a, 0x035b,
186  0x035e, 0x035f, 0x0368, 0x0369, 0x036a, 0x036b, 0x036c, 0x036d, 0x036e, 0x036f,
187  0x037c, 0x037d, 0x037e, 0x03c0, 0x03c1, 0x03c3, 0x03c5, 0x03c6, 0x03c7, 0x03cf,
188  0x03d4, 0x03d5, 0x03d6, 0x03d7, 0x03d8, 0x03d9, 0x03db, 0x03dc, 0x03dd, 0x03de,
189  0x03fc, 0x0660, 0x0661, 0x0662, 0x0663, 0x0666, 0x0667, 0x0669, 0x066b, 0x066f,
190  0x0672, 0x0673, 0x0676, 0x0678, 0x0679, 0x067a, 0x067b, 0x067e, 0x0690, 0x0691,
191  0x0693, 0x0696, 0x0697, 0x069f, 0x06b0, 0x06b1, 0x06b2, 0x06b3, 0x06b4, 0x06b5,
192  0x06b6, 0x06b7, 0x06b9, 0x06bd, 0x06f0, 0x06f1, 0x06f2, 0x06f6, 0x06f9, 0x0776,
193  0x0778, 0x0779, 0x077a, 0x077e, 0x07b0, 0x07b1, 0x07b4, 0x07b5, 0x07b6, 0x07bc,
194  0x07e0, 0x07e1, 0x07e2, 0x07e3, 0x07e6, 0x07e9, 0x07f0, 0x07f1, 0x07f2, 0x07f8,
195  0x0ff0, 0x1668, 0x1669, 0x166a, 0x166b, 0x166e, 0x167e, 0x1681, 0x1683, 0x1686,
196  0x1687, 0x1689, 0x168b, 0x168e, 0x1696, 0x1697, 0x1698, 0x1699, 0x169a, 0x169b,
197  0x169e, 0x16a9, 0x16ac, 0x16ad, 0x16bc, 0x16e9, 0x177e, 0x178e, 0x1796, 0x1798,
198  0x179a, 0x17ac, 0x17e8, 0x18e7, 0x19e1, 0x19e3, 0x19e6, 0x1bd8, 0x1be4, 0x1ee1,
199  0x3cc3, 0x6996
200  };
201  int Counters[222] = {0};
202  Vec_Ptr_t * vNodes;
203  Abc_Obj_t * pObj;
204  unsigned uTruth;
205  int i, k, Count = 0;
206 
207  unsigned short * puCanons = NULL;
208  unsigned char * puMap = NULL;
209  Extra_Truth4VarNPN( &puCanons, NULL, NULL, &puMap );
210 
211  // set elementary truth tables
212  assert( Abc_NtkPiNum(pNtk) == 4 );
213  Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)0xFFFFFFFF;
214  Abc_NtkForEachPi( pNtk, pObj, i )
215  pObj->pCopy = (Abc_Obj_t *)u4VarTruths[i];
216 
217  // create truth tables
218  Abc_NtkForEachPo( pNtk, pObj, i )
219  {
220  vNodes = Abc_NtkDfsNodes( pNtk, &pObj, 1 );
221  if ( Vec_PtrSize(vNodes) == 0 )
222  uTruth = (unsigned)Abc_ObjFanin0(pObj)->pCopy;
223  else
224  uTruth = Abc_Ntk4VarObj( vNodes );
225 
226  if ( (uTruth & 0xFFFF) < (~uTruth & 0xFFFF) )
227  uTruth = uTruth & 0xFFFF;
228  else
229  uTruth = ~uTruth & 0xFFFF;
230 
231  for ( k = 0; k < 222; k++ )
232  if ( u4VarTts[k] == uTruth )
233  break;
234  if ( k == 222 )
235  continue;
236 /*
237 // if ( uTruth == 1725 )
238  if ( k == 96 )
239  {
240  printf( "%d : ", Vec_PtrSize(vNodes) );
241  Abc_Ntk4VarObjPrint_rec( Abc_ObjFanin0(pObj) );
242  printf( "\n" );
243  }
244 */
245  Counters[k]++;
246 
247 // Counters[ puMap[uTruth & 0xFFFF] ]++;
248  Vec_PtrFree( vNodes );
249  }
250  ABC_FREE( puCanons );
251  ABC_FREE( puMap );
252 
253  Count = 0;
254  for ( k = 0; k < 222; k++ )
255  {
256  printf( "%d/%x/%d ", k, u4VarTts[k], Counters[k] );
257  Count += Counters[k];
258  }
259  printf( " Total = %d\n", Count );
260 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition: abcAig.c:683
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
Abc_Obj_t * pCopy
Definition: abc.h:148
unsigned Abc_Ntk4VarObj(Vec_Ptr_t *vNodes)
Definition: abcMeasure.c:144
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Abc_NtkPiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:285
void Extra_Truth4VarNPN(unsigned short **puCanons, char **puPhases, char **puPerms, unsigned char **puMap)
#define assert(ex)
Definition: util_old.h:213
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition: abcDfs.c:120
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
ABC_NAMESPACE_IMPL_START void Abc_NtkPrintMeasures ( unsigned *  pTruth,
int  nVars 
)

DECLARATIONS ///.

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

FileName [abc_.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis []

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
abc_.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file abcMeasure.c.

47 {
48  unsigned uCofs[10][32];
49  int i, k, nOnes;
50 
51  // total pairs
52  nOnes = Kit_TruthCountOnes( uCofs[0], nVars );
53  printf( "Total = %d.\n", nOnes * ((1 << nVars) - nOnes) );
54 
55  // print measures for individual variables
56  for ( i = 0; i < nVars; i++ )
57  {
58  Kit_TruthUniqueNew( uCofs[0], pTruth, nVars, i );
59  nOnes = Kit_TruthCountOnes( uCofs[0], nVars );
60  printf( "%7d ", nOnes );
61  }
62  printf( "\n" );
63 
64  // consider pairs
65  for ( i = 0; i < nVars; i++ )
66  for ( k = 0; k < nVars; k++ )
67  {
68  if ( i == k )
69  {
70  printf( " " );
71  continue;
72  }
73  Kit_TruthCofactor0New( uCofs[0], pTruth, nVars, i );
74  Kit_TruthCofactor1New( uCofs[1], pTruth, nVars, i );
75 
76  Kit_TruthCofactor0New( uCofs[2], uCofs[0], nVars, k ); // 00
77  Kit_TruthCofactor1New( uCofs[3], uCofs[0], nVars, k ); // 01
78  Kit_TruthCofactor0New( uCofs[4], uCofs[1], nVars, k ); // 10
79  Kit_TruthCofactor1New( uCofs[5], uCofs[1], nVars, k ); // 11
80 
81  Kit_TruthAndPhase( uCofs[6], uCofs[2], uCofs[5], nVars, 0, 1 ); // 00 & 11'
82  Kit_TruthAndPhase( uCofs[7], uCofs[2], uCofs[5], nVars, 1, 0 ); // 00' & 11
83  Kit_TruthAndPhase( uCofs[8], uCofs[3], uCofs[4], nVars, 0, 1 ); // 01 & 10'
84  Kit_TruthAndPhase( uCofs[9], uCofs[3], uCofs[4], nVars, 1, 0 ); // 01' & 10
85 
86  nOnes = Kit_TruthCountOnes( uCofs[6], nVars ) +
87  Kit_TruthCountOnes( uCofs[7], nVars ) +
88  Kit_TruthCountOnes( uCofs[8], nVars ) +
89  Kit_TruthCountOnes( uCofs[9], nVars );
90 
91  printf( "%7d ", nOnes );
92  if ( k == nVars - 1 )
93  printf( "\n" );
94  }
95  printf( "\n" );
96 }
static void Kit_TruthAndPhase(unsigned *pOut, unsigned *pIn0, unsigned *pIn1, int nVars, int fCompl0, int fCompl1)
Definition: kit.h:409
void Kit_TruthCofactor0New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition: kitTruth.c:521
static int Kit_TruthCountOnes(unsigned *pIn, int nVars)
Definition: kit.h:251
void Kit_TruthCofactor1New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition: kitTruth.c:573
void Kit_TruthUniqueNew(unsigned *pRes, unsigned *pTruth, int nVars, int iVar)
Definition: kitTruth.c:922
void Abc_NtkPrintOneDec ( unsigned *  pTruth,
int  nVars 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 430 of file abcMeasure.c.

431 {
432  unsigned uCof[(1<<11)], * pOut = uCof, * pIn = pTruth, * pTemp;
433  int nDiffs[16];
434  int Order[16];
435  int i, fChange, Temp, Counter;
436 
437  // find the ordering
438  for ( i = 0; i < nVars; i++ )
439  {
440  Kit_TruthUniqueNew( uCof, pTruth, nVars, i );
441  nDiffs[i] = Kit_TruthCountOnes( uCof, nVars );
442  Order[i] = i;
443  }
444 
445  // permute truth table to least active variable first
446  Counter = 0;
447  do {
448  fChange = 0;
449  for ( i = 0; i < nVars-1; i++ )
450  {
451  if ( nDiffs[i] <= nDiffs[i+1] )
452  continue;
453  fChange = 1;
454  Counter++;
455 
456  Temp = nDiffs[i];
457  nDiffs[i] = nDiffs[i+1];
458  nDiffs[i+1] = Temp;
459 
460  Temp = Order[i];
461  Order[i] = Order[i+1];
462  Order[i+1] = Temp;
463 
464  Extra_TruthSwapAdjacentVars( pOut, pIn, nVars, i );
465  pTemp = pIn; pIn = pOut; pOut = pTemp;
466  }
467  } while ( fChange );
468 
469  // swap if it was moved an even number of times
470  if ( Counter & 1 )
471  Extra_TruthCopy( pOut, pIn, nVars );
472 
473  // call the decomposition
474  Abc_NtkPrintOneDecomp( pTruth, nVars );
475 }
static int Kit_TruthCountOnes(unsigned *pIn, int nVars)
Definition: kit.h:251
static int Counter
void Kit_TruthUniqueNew(unsigned *pRes, unsigned *pTruth, int nVars, int iVar)
Definition: kitTruth.c:922
void Extra_TruthSwapAdjacentVars(unsigned *pOut, unsigned *pIn, int nVars, int Start)
void Abc_NtkPrintOneDecomp(unsigned *pTruth, int nVars)
Definition: abcMeasure.c:388
static void Extra_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: extra.h:302
void Abc_NtkPrintOneDecomp ( unsigned *  pTruth,
int  nVars 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 388 of file abcMeasure.c.

389 {
390  int BoundSet = 6;
391  unsigned uCofs[64], uMask, uBestMask = 0;
392  int i, nCofs, nMints, nMintShift, BestSize = 1;
393 
394  assert( nVars > BoundSet );
395  assert( nVars <= BoundSet + 5 ); // at most 5 variable cofactors
396 
397  // collect the cofactors
398  nCofs = (1 << BoundSet);
399  nMints = (1 << (nVars-BoundSet));
400  nMintShift = 0;
401  uMask = Kit_CubeMask( nMints );
402  for ( i = 0; i < nCofs; i++ )
403  {
404  uCofs[i] = (pTruth[nMintShift/32] >> (nMintShift % 32)) & uMask;
405  nMintShift += nMints;
406  }
407 
408  // try removing variables
409  for ( i = 0; i < BoundSet; i++ )
410  Abc_NtkPrintOneDecomp_rec( uCofs, nCofs, nVars, (1 << i), &BestSize, &uBestMask );
411 
412  printf( "Best size = %d ", BestSize );
413  printf( "Best mask = " );
414  Extra_PrintBinary( stdout, &uBestMask, nVars );
415  printf( "\n" );
416 }
static unsigned Kit_CubeMask(int nVar)
Definition: kit.h:182
void Abc_NtkPrintOneDecomp_rec(unsigned *uCofs, int nCofs, int nVars, unsigned uMask, int *pBestSize, unsigned *puBestMask)
Definition: abcMeasure.c:348
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
#define assert(ex)
Definition: util_old.h:213
void Abc_NtkPrintOneDecomp_rec ( unsigned *  uCofs,
int  nCofs,
int  nVars,
unsigned  uMask,
int *  pBestSize,
unsigned *  puBestMask 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 348 of file abcMeasure.c.

349 {
350  unsigned uMaskNew;
351  int v, last, Counter = 0;
352  // find the last variable in the mask
353  for ( v = 0; v < nVars; v++ )
354  if ( uMask & (1<<v) )
355  {
356  last = v;
357  Counter++;
358  }
359  if ( Counter > 3 )
360  return;
361  // try adding one variable after the last
362  for ( v = last + 1; v < nVars; v++ )
363  {
364  uMaskNew = uMask | (1 << v);
365  if ( !Abc_NtkPrintOneDecompCheck( uCofs, nCofs, uMaskNew ) )
366  continue;
367  if ( *pBestSize < Counter + 1 )
368  {
369  *pBestSize = Counter + 1;
370  *puBestMask = uMaskNew;
371  }
372  // try other masks
373  Abc_NtkPrintOneDecomp_rec( uCofs, nCofs, nVars, uMaskNew, pBestSize, puBestMask );
374  }
375 }
int Abc_NtkPrintOneDecompCheck(unsigned *uCofs, int nCofs, unsigned uMask)
Definition: abcMeasure.c:307
void Abc_NtkPrintOneDecomp_rec(unsigned *uCofs, int nCofs, int nVars, unsigned uMask, int *pBestSize, unsigned *puBestMask)
Definition: abcMeasure.c:348
static int Counter
int Abc_NtkPrintOneDecompCheck ( unsigned *  uCofs,
int  nCofs,
unsigned  uMask 
)

Function*************************************************************

Synopsis [Checks all cofactors with the given mask.]

Description []

SideEffects []

SeeAlso []

Definition at line 307 of file abcMeasure.c.

308 {
309  unsigned pCofs[32][32];
310  int nCofNums[32] = {0};
311  int uMasks[32];
312  int nGroups = 0;
313  int i, k;
314  for ( i = 0; i < nCofs; i++ )
315  {
316  // find group of this cof
317  for ( k = 0; k < nGroups; k++ )
318  if ( (int)(i & uMask) == uMasks[k] )
319  break;
320  if ( k == nGroups )
321  {
322  uMasks[k] = (i & uMask);
323  nGroups++;
324  }
325  // save cof in the group
326  pCofs[k][ nCofNums[k]++ ] = uCofs[i];
327  assert( nCofNums[k] <= 32 );
328  assert( nGroups <= 32 );
329  }
330  // check the groups
331  for ( i = 0; i < nGroups; i++ )
332  if ( !Abc_NtkPrintOneDecompCheckCofList(pCofs[i], nCofNums[i]) )
333  return 0;
334  return 1;
335 }
int Abc_NtkPrintOneDecompCheckCofList(unsigned *uCofs, int nCofs)
Definition: abcMeasure.c:276
#define assert(ex)
Definition: util_old.h:213
int Abc_NtkPrintOneDecompCheckCofList ( unsigned *  uCofs,
int  nCofs 
)

Function*************************************************************

Synopsis [Returns 1 if there are no more than 2 unique cofactors.]

Description []

SideEffects []

SeeAlso []

Definition at line 276 of file abcMeasure.c.

277 {
278  int i, Ind = -1;
279  assert( nCofs > 2 );
280  for ( i = 1; i < nCofs; i++ )
281  {
282  if ( uCofs[i] == uCofs[0] )
283  continue;
284  if ( Ind == -1 )
285  {
286  Ind = i;
287  continue;
288  }
289  if ( uCofs[i] == uCofs[Ind] )
290  continue;
291  return 0;
292  }
293  return 1;
294 }
#define assert(ex)
Definition: util_old.h:213