abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cswTable.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cswTable.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Cut sweeping.]
8 
9  Synopsis []
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - July 11, 2007.]
16 
17  Revision [$Id: cswTable.c,v 1.00 2007/07/11 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "cswInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Computes hash value of the cut.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 unsigned Csw_CutHash( Csw_Cut_t * pCut )
46 {
47  static int s_FPrimes[128] = {
48  1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459,
49  1499, 1559, 1607, 1657, 1709, 1759, 1823, 1877, 1933, 1997,
50  2039, 2089, 2141, 2213, 2269, 2311, 2371, 2411, 2467, 2543,
51  2609, 2663, 2699, 2741, 2797, 2851, 2909, 2969, 3037, 3089,
52  3169, 3221, 3299, 3331, 3389, 3461, 3517, 3557, 3613, 3671,
53  3719, 3779, 3847, 3907, 3943, 4013, 4073, 4129, 4201, 4243,
54  4289, 4363, 4441, 4493, 4549, 4621, 4663, 4729, 4793, 4871,
55  4933, 4973, 5021, 5087, 5153, 5227, 5281, 5351, 5417, 5471,
56  5519, 5573, 5651, 5693, 5749, 5821, 5861, 5923, 6011, 6073,
57  6131, 6199, 6257, 6301, 6353, 6397, 6481, 6563, 6619, 6689,
58  6737, 6803, 6863, 6917, 6977, 7027, 7109, 7187, 7237, 7309,
59  7393, 7477, 7523, 7561, 7607, 7681, 7727, 7817, 7877, 7933,
60  8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147
61  };
62  unsigned uHash;
63  int i;
64  assert( pCut->nFanins <= 16 );
65  uHash = 0;
66  for ( i = 0; i < pCut->nFanins; i++ )
67  uHash ^= pCut->pFanins[i] * s_FPrimes[i];
68  return uHash;
69 }
70 
71 /**Function*************************************************************
72 
73  Synopsis [Returns the total number of cuts in the table.]
74 
75  Description []
76 
77  SideEffects []
78 
79  SeeAlso []
80 
81 ***********************************************************************/
83 {
84  Csw_Cut_t * pEnt;
85  int i, Counter = 0;
86  for ( i = 0; i < p->nTableSize; i++ )
87  for ( pEnt = p->pTable[i]; pEnt; pEnt = pEnt->pNext )
88  Counter++;
89  return Counter;
90 }
91 
92 /**Function*************************************************************
93 
94  Synopsis [Adds the cut to the hash table.]
95 
96  Description []
97 
98  SideEffects []
99 
100  SeeAlso []
101 
102 ***********************************************************************/
104 {
105  int iEntry = Csw_CutHash(pCut) % p->nTableSize;
106  pCut->pNext = p->pTable[iEntry];
107  p->pTable[iEntry] = pCut;
108 }
109 
110 /**Function*************************************************************
111 
112  Synopsis [Returns an equivalent node if it exists.]
113 
114  Description []
115 
116  SideEffects []
117 
118  SeeAlso []
119 
120 ***********************************************************************/
122 {
123  Aig_Obj_t * pRes = NULL;
124  Csw_Cut_t * pEnt;
125  unsigned * pTruthNew, * pTruthOld;
126  int iEntry = Csw_CutHash(pCut) % p->nTableSize;
127  for ( pEnt = p->pTable[iEntry]; pEnt; pEnt = pEnt->pNext )
128  {
129  if ( pEnt->nFanins != pCut->nFanins )
130  continue;
131  if ( pEnt->uSign != pCut->uSign )
132  continue;
133  if ( memcmp( pEnt->pFanins, pCut->pFanins, sizeof(int) * pCut->nFanins ) )
134  continue;
135  pTruthOld = Csw_CutTruth(pEnt);
136  pTruthNew = Csw_CutTruth(pCut);
137  if ( (pTruthOld[0] & 1) == (pTruthNew[0] & 1) )
138  {
139  if ( Kit_TruthIsEqual( pTruthOld, pTruthNew, pCut->nFanins ) )
140  {
141  pRes = Aig_ManObj( p->pManRes, pEnt->iNode );
142  assert( pRes->fPhase == Aig_ManObj( p->pManRes, pCut->iNode )->fPhase );
143  break;
144  }
145  }
146  else
147  {
148  if ( Kit_TruthIsOpposite( pTruthOld, pTruthNew, pCut->nFanins ) )
149  {
150  pRes = Aig_Not( Aig_ManObj( p->pManRes, pEnt->iNode ) );
151  assert( Aig_Regular(pRes)->fPhase != Aig_ManObj( p->pManRes, pCut->iNode )->fPhase );
152  break;
153  }
154  }
155  }
156  return pRes;
157 }
158 
159 
160 ////////////////////////////////////////////////////////////////////////
161 /// END OF FILE ///
162 ////////////////////////////////////////////////////////////////////////
163 
164 
166 
int iNode
Definition: cswInt.h:62
typedefABC_NAMESPACE_HEADER_START struct Csw_Man_t_ Csw_Man_t
INCLUDES ///.
Definition: cswInt.h:52
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
static Aig_Obj_t * Aig_ManObj(Aig_Man_t *p, int i)
Definition: aig.h:270
static int Kit_TruthIsEqual(unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: kit.h:274
static Aig_Obj_t * Aig_Not(Aig_Obj_t *p)
Definition: aig.h:247
Aig_Obj_t * Csw_TableCutLookup(Csw_Man_t *p, Csw_Cut_t *pCut)
Definition: cswTable.c:121
static unsigned * Csw_CutTruth(Csw_Cut_t *pCut)
Definition: cswInt.h:104
ABC_NAMESPACE_IMPL_START unsigned Csw_CutHash(Csw_Cut_t *pCut)
DECLARATIONS ///.
Definition: cswTable.c:45
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int memcmp()
Definition: aig.h:69
static int Counter
int pFanins[0]
Definition: cswInt.h:66
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Csw_TableCutInsert(Csw_Man_t *p, Csw_Cut_t *pCut)
Definition: cswTable.c:103
unsigned int fPhase
Definition: aig.h:78
int Csw_TableCountCuts(Csw_Man_t *p)
Definition: cswTable.c:82
static int Kit_TruthIsOpposite(unsigned *pIn0, unsigned *pIn1, int nVars)
Definition: kit.h:290
unsigned uSign
Definition: cswInt.h:61
#define assert(ex)
Definition: util_old.h:213
Csw_Cut_t * pNext
Definition: cswInt.h:58
char nFanins
Definition: cswInt.h:65