abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
lpkAbcUtil.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [lpkAbcUtil.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Fast Boolean matching for LUT structures.]
8 
9  Synopsis [Procedures working on decomposed functions.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: lpkAbcUtil.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "lpkInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Allocates the function.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 Lpk_Fun_t * Lpk_FunAlloc( int nVars )
46 {
47  Lpk_Fun_t * p;
48  p = (Lpk_Fun_t *)ABC_ALLOC( char, sizeof(Lpk_Fun_t) + sizeof(unsigned) * Kit_TruthWordNum(nVars) * 3 );
49  memset( p, 0, sizeof(Lpk_Fun_t) );
50  return p;
51 }
52 
53 /**Function*************************************************************
54 
55  Synopsis [Deletes the function]
56 
57  Description []
58 
59  SideEffects []
60 
61  SeeAlso []
62 
63 ***********************************************************************/
65 {
66  ABC_FREE( p );
67 }
68 
69 /**Function*************************************************************
70 
71  Synopsis [Creates the starting function.]
72 
73  Description []
74 
75  SideEffects []
76 
77  SeeAlso []
78 
79 ***********************************************************************/
80 Lpk_Fun_t * Lpk_FunCreate( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, int nLutK, int AreaLim, int DelayLim )
81 {
82  Lpk_Fun_t * p;
83  Abc_Obj_t * pNode;
84  int i;
85  p = Lpk_FunAlloc( Vec_PtrSize(vLeaves) );
86  p->Id = Vec_PtrSize(vLeaves);
87  p->vNodes = vLeaves;
88  p->nVars = Vec_PtrSize(vLeaves);
89  p->nLutK = nLutK;
90  p->nAreaLim = AreaLim;
91  p->nDelayLim = DelayLim;
92  p->uSupp = Kit_TruthSupport( pTruth, p->nVars );
93  Kit_TruthCopy( Lpk_FunTruth(p,0), pTruth, p->nVars );
94  Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pNode, i )
95  {
96  p->pFanins[i] = i;
97  p->pDelays[i] = pNode->Level;
98  }
99  Vec_PtrPush( p->vNodes, p );
100  return p;
101 }
102 
103 /**Function*************************************************************
104 
105  Synopsis [Creates the new function with the given truth table.]
106 
107  Description []
108 
109  SideEffects []
110 
111  SeeAlso []
112 
113 ***********************************************************************/
114 Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth )
115 {
116  Lpk_Fun_t * pNew;
117  pNew = Lpk_FunAlloc( p->nVars );
118  pNew->Id = Vec_PtrSize(p->vNodes);
119  pNew->vNodes = p->vNodes;
120  pNew->nVars = p->nVars;
121  pNew->nLutK = p->nLutK;
122  pNew->nAreaLim = p->nAreaLim;
123  pNew->nDelayLim = p->nDelayLim;
124  pNew->uSupp = Kit_TruthSupport( pTruth, p->nVars );
125  Kit_TruthCopy( Lpk_FunTruth(pNew,0), pTruth, p->nVars );
126  memcpy( pNew->pFanins, p->pFanins, 16 );
127  memcpy( pNew->pDelays, p->pDelays, 16 );
128  Vec_PtrPush( p->vNodes, pNew );
129  return pNew;
130 }
131 
132 /**Function*************************************************************
133 
134  Synopsis [Minimizes support of the function.]
135 
136  Description []
137 
138  SideEffects []
139 
140  SeeAlso []
141 
142 ***********************************************************************/
144 {
145  int i, k, nVarsNew;
146  // compress the truth table
147  if ( p->uSupp == Kit_BitMask(p->nVars) )
148  return 0;
149  // invalidate support info
150  p->fSupports = 0;
151 //Extra_PrintBinary( stdout, &p->uSupp, p->nVars ); printf( "\n" );
152  // minimize support
153  nVarsNew = Kit_WordCountOnes(p->uSupp);
154  Kit_TruthShrink( Lpk_FunTruth(p, 1), Lpk_FunTruth(p, 0), nVarsNew, p->nVars, p->uSupp, 1 );
155  k = 0;
156  Lpk_SuppForEachVar( p->uSupp, i )
157  {
158  p->pFanins[k] = p->pFanins[i];
159  p->pDelays[k] = p->pDelays[i];
160 /*
161  if ( p->fSupports )
162  {
163  p->puSupps[2*k+0] = p->puSupps[2*i+0];
164  p->puSupps[2*k+1] = p->puSupps[2*i+1];
165  }
166 */
167  k++;
168  }
169  assert( k == nVarsNew );
170  p->nVars = k;
171  p->uSupp = Kit_BitMask(p->nVars);
172  return 1;
173 }
174 
175 /**Function*************************************************************
176 
177  Synopsis [Computes cofactors w.r.t. each variable.]
178 
179  Description []
180 
181  SideEffects []
182 
183  SeeAlso []
184 
185 ***********************************************************************/
187 {
188  unsigned * pTruth = Lpk_FunTruth( p, 0 );
189  unsigned * pTruth0 = Lpk_FunTruth( p, 1 );
190  unsigned * pTruth1 = Lpk_FunTruth( p, 2 );
191  int Var;
192  assert( p->fSupports == 0 );
193 // Lpk_SuppForEachVar( p->uSupp, Var )
194  for ( Var = 0; Var < (int)p->nVars; Var++ )
195  {
196  Kit_TruthCofactor0New( pTruth0, pTruth, p->nVars, Var );
197  Kit_TruthCofactor1New( pTruth1, pTruth, p->nVars, Var );
198  p->puSupps[2*Var+0] = Kit_TruthSupport( pTruth0, p->nVars );
199  p->puSupps[2*Var+1] = Kit_TruthSupport( pTruth1, p->nVars );
200  }
201  p->fSupports = 1;
202 }
203 
204 /**Function*************************************************************
205 
206  Synopsis [Get the delay of the bound set.]
207 
208  Description []
209 
210  SideEffects []
211 
212  SeeAlso []
213 
214 ***********************************************************************/
215 int Lpk_SuppDelay( unsigned uSupp, char * pDelays )
216 {
217  int Delay, Var;
218  Delay = 0;
219  Lpk_SuppForEachVar( uSupp, Var )
220  Delay = Abc_MaxInt( Delay, pDelays[Var] );
221  return Delay + 1;
222 }
223 
224 /**Function*************************************************************
225 
226  Synopsis [Converts support into variables.]
227 
228  Description []
229 
230  SideEffects []
231 
232  SeeAlso []
233 
234 ***********************************************************************/
235 int Lpk_SuppToVars( unsigned uBoundSet, char * pVars )
236 {
237  int i, nVars = 0;
238  Lpk_SuppForEachVar( uBoundSet, i )
239  pVars[nVars++] = i;
240  return nVars;
241 }
242 
243 ////////////////////////////////////////////////////////////////////////
244 /// END OF FILE ///
245 ////////////////////////////////////////////////////////////////////////
246 
247 
249 
char * memset()
unsigned nAreaLim
Definition: lpkInt.h:150
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Kit_TruthWordNum(int nVars)
Definition: kit.h:224
void Lpk_FunComputeCofSupps(Lpk_Fun_t *p)
Definition: lpkAbcUtil.c:186
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned nVars
Definition: lpkInt.h:148
int Lpk_SuppDelay(unsigned uSupp, char *pDelays)
Definition: lpkAbcUtil.c:215
unsigned nLutK
Definition: lpkInt.h:149
Vec_Ptr_t * vNodes
Definition: lpkInt.h:146
unsigned uSupp
Definition: lpkInt.h:154
unsigned fSupports
Definition: lpkInt.h:152
char * memcpy()
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
void Lpk_FunFree(Lpk_Fun_t *p)
Definition: lpkAbcUtil.c:64
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
unsigned Level
Definition: abc.h:142
unsigned Id
Definition: lpkInt.h:147
static unsigned * Lpk_FunTruth(Lpk_Fun_t *p, int Num)
Definition: lpkInt.h:179
void Kit_TruthCofactor0New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition: kitTruth.c:521
ABC_NAMESPACE_IMPL_START Lpk_Fun_t * Lpk_FunAlloc(int nVars)
DECLARATIONS ///.
Definition: lpkAbcUtil.c:45
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Kit_TruthCofactor1New(unsigned *pOut, unsigned *pIn, int nVars, int iVar)
Definition: kitTruth.c:573
int Lpk_FunSuppMinimize(Lpk_Fun_t *p)
Definition: lpkAbcUtil.c:143
int Lpk_SuppToVars(unsigned uBoundSet, char *pVars)
Definition: lpkAbcUtil.c:235
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Kit_TruthShrink(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn)
Definition: kitTruth.c:200
#define ABC_FREE(obj)
Definition: abc_global.h:232
char pDelays[16]
Definition: lpkInt.h:156
Lpk_Fun_t * Lpk_FunDup(Lpk_Fun_t *p, unsigned *pTruth)
Definition: lpkAbcUtil.c:114
unsigned Kit_TruthSupport(unsigned *pTruth, int nVars)
Definition: kitTruth.c:346
static void Kit_TruthCopy(unsigned *pOut, unsigned *pIn, int nVars)
Definition: kit.h:355
int Var
Definition: SolverTypes.h:42
char pFanins[16]
Definition: lpkInt.h:157
#define assert(ex)
Definition: util_old.h:213
static int Kit_WordCountOnes(unsigned uWord)
Definition: kit.h:243
#define Lpk_SuppForEachVar(Supp, Var)
Definition: lpkInt.h:195
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
unsigned puSupps[32]
Definition: lpkInt.h:155
static unsigned Kit_BitMask(int nBits)
Definition: kit.h:225
Lpk_Fun_t * Lpk_FunCreate(Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, unsigned *pTruth, int nLutK, int AreaLim, int DelayLim)
Definition: lpkAbcUtil.c:80
unsigned nDelayLim
Definition: lpkInt.h:151