ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
extraUtilMult.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "misc/vec/vec.h"
#include "aig/gia/gia.h"
Include dependency graph for extraUtilMult.c:

Go to the source code of this file.

Classes

struct  Abc_BddMan_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Abc_BddMan_ Abc_BddMan
 DECLARATIONS ///.
 

Functions

Abc_BddManAbc_BddManAlloc (int nVars, int nObjs)
 
void Abc_BddManFree (Abc_BddMan *p)
 
int Abc_BddAnd (Abc_BddMan *p, int a, int b)
 
int Abc_BddOr (Abc_BddMan *p, int a, int b)
 
int Abc_BddCount_rec (Abc_BddMan *p, int i)
 
void Abc_BddUnmark_rec (Abc_BddMan *p, int i)
 
int Abc_BddCountNodes (Abc_BddMan *p, int i)
 
int Abc_BddCountNodesArray (Abc_BddMan *p, Vec_Int_t *vNodes)
 
int Abc_BddCountNodesArray2 (Abc_BddMan *p, Vec_Int_t *vNodes)
 
void Abc_BddPrint_rec (Abc_BddMan *p, int a, int *pPath)
 
void Abc_BddPrint (Abc_BddMan *p, int a)
 
void Abc_BddPrintTest (Abc_BddMan *p)
 
void Abc_BddGiaTest2 (Gia_Man_t *pGia, int fVerbose)
 
void Abc_BddGiaTest (Gia_Man_t *pGia, int fVerbose)
 

Typedef Documentation

◆ Abc_BddMan

typedef typedefABC_NAMESPACE_IMPL_START struct Abc_BddMan_ Abc_BddMan

DECLARATIONS ///.

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

FileName [extraUtilMult.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [extra]

Synopsis [Simple BDD package.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 23, 2018.]

Revision [

Id
extraUtilMult.c,v 1.0 2018/05/23 00:00:00 alanmi Exp

]

Definition at line 34 of file extraUtilMult.c.

Function Documentation

◆ Abc_BddAnd()

int Abc_BddAnd ( Abc_BddMan * p,
int a,
int b )

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

Synopsis [Boolean AND.]

Description []

SideEffects []

SeeAlso []

Definition at line 194 of file extraUtilMult.c.

195{
196 int r0, r1, r;
197 if ( a == 0 ) return 0;
198 if ( b == 0 ) return 0;
199 if ( a == 1 ) return b;
200 if ( b == 1 ) return a;
201 if ( a == b ) return a;
202 if ( a > b ) return Abc_BddAnd( p, b, a );
203 if ( (r = Abc_BddCacheLookup(p, a, b)) >= 0 )
204 return r;
205 if ( Abc_BddVar(p, a) < Abc_BddVar(p, b) )
206 r0 = Abc_BddAnd( p, Abc_BddElse(p, a), b ),
207 r1 = Abc_BddAnd( p, Abc_BddThen(p, a), b );
208 else if ( Abc_BddVar(p, a) > Abc_BddVar(p, b) )
209 r0 = Abc_BddAnd( p, a, Abc_BddElse(p, b) ),
210 r1 = Abc_BddAnd( p, a, Abc_BddThen(p, b) );
211 else // if ( Abc_BddVar(p, a) == Abc_BddVar(p, b) )
212 r0 = Abc_BddAnd( p, Abc_BddElse(p, a), Abc_BddElse(p, b) ),
213 r1 = Abc_BddAnd( p, Abc_BddThen(p, a), Abc_BddThen(p, b) );
214 r = Abc_BddUniqueCreate( p, Abc_MinInt(Abc_BddVar(p, a), Abc_BddVar(p, b)), r1, r0 );
215 return Abc_BddCacheInsert( p, a, b, r );
216}
Cube * p
Definition exorList.c:222
int Abc_BddAnd(Abc_BddMan *p, int a, int b)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddCount_rec()

int Abc_BddCount_rec ( Abc_BddMan * p,
int i )

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

Synopsis [Counting nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 233 of file extraUtilMult.c.

234{
235 if ( i < 2 )
236 return 0;
237 if ( Abc_BddMark(p, i) )
238 return 0;
239 Abc_BddSetMark( p, i, 1 );
240 return 1 + Abc_BddCount_rec(p, Abc_BddElse(p, i)) + Abc_BddCount_rec(p, Abc_BddThen(p, i));
241}
int Abc_BddCount_rec(Abc_BddMan *p, int i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddCountNodes()

int Abc_BddCountNodes ( Abc_BddMan * p,
int i )

Definition at line 252 of file extraUtilMult.c.

253{
254 int Count = Abc_BddCount_rec( p, i );
255 Abc_BddUnmark_rec( p, i );
256 return Count;
257}
void Abc_BddUnmark_rec(Abc_BddMan *p, int i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddCountNodesArray()

int Abc_BddCountNodesArray ( Abc_BddMan * p,
Vec_Int_t * vNodes )

Definition at line 258 of file extraUtilMult.c.

259{
260 int i, a, Count = 0;
261 Vec_IntForEachEntry( vNodes, a, i )
262 Count += Abc_BddCount_rec( p, a );
263 Vec_IntForEachEntry( vNodes, a, i )
264 Abc_BddUnmark_rec( p, a );
265 return Count;
266}
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:

◆ Abc_BddCountNodesArray2()

int Abc_BddCountNodesArray2 ( Abc_BddMan * p,
Vec_Int_t * vNodes )

Definition at line 267 of file extraUtilMult.c.

268{
269 int i, a, Count = 0;
270 Vec_IntForEachEntry( vNodes, a, i )
271 {
272 Count += Abc_BddCount_rec( p, a );
273 Abc_BddUnmark_rec( p, a );
274 }
275 return Count;
276}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddGiaTest()

void Abc_BddGiaTest ( Gia_Man_t * pGia,
int fVerbose )

Definition at line 350 of file extraUtilMult.c.

351{
352 Abc_BddMan * p;
353 Vec_Int_t * vNodes;
354 Gia_Obj_t * pObj; int i;
355 p = Abc_BddManAlloc( Gia_ManCiNum(pGia), 1 << 20 ); // 30 B/node
356 Gia_ManFillValue( pGia );
357 Gia_ManConst0(pGia)->Value = 0;
358 Gia_ManForEachCi( pGia, pObj, i )
359 pObj->Value = Abc_BddIthVar( i );
360 vNodes = Vec_IntAlloc( Gia_ManAndNum(pGia) );
361 Gia_ManForEachAnd( pGia, pObj, i )
362 {
363 int Cof0 = Abc_LitNotCond(Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj));
364 int Cof1 = Abc_LitNotCond(Gia_ObjFanin1(pObj)->Value, Gia_ObjFaninC1(pObj));
365 pObj->Value = Abc_BddAnd( p, Cof0, Cof1 );
366 }
367 Gia_ManForEachCo( pGia, pObj, i )
368 pObj->Value = Abc_LitNotCond(Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj));
369 Gia_ManForEachCo( pGia, pObj, i )
370 {
371 if ( fVerbose )
372 Abc_BddPrint( p, pObj->Value );
373 Vec_IntPush( vNodes, pObj->Value );
374 }
375 printf( "Shared nodes = %d.\n", Abc_BddCountNodesArray2(p, vNodes) );
376 Vec_IntFree( vNodes );
377 Abc_BddManFree( p );
378}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
typedefABC_NAMESPACE_IMPL_START struct Abc_BddMan_ Abc_BddMan
DECLARATIONS ///.
void Abc_BddPrint(Abc_BddMan *p, int a)
int Abc_BddCountNodesArray2(Abc_BddMan *p, Vec_Int_t *vNodes)
void Abc_BddManFree(Abc_BddMan *p)
Abc_BddMan * Abc_BddManAlloc(int nVars, int nObjs)
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
unsigned Value
Definition gia.h:89
Here is the call graph for this function:

◆ Abc_BddGiaTest2()

void Abc_BddGiaTest2 ( Gia_Man_t * pGia,
int fVerbose )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 343 of file extraUtilMult.c.

344{
345 Abc_BddMan * p = Abc_BddManAlloc( 10, 100 );
347 Abc_BddManFree( p );
348}
void Abc_BddPrintTest(Abc_BddMan *p)
Here is the call graph for this function:

◆ Abc_BddManAlloc()

Abc_BddMan * Abc_BddManAlloc ( int nVars,
int nObjs )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 145 of file extraUtilMult.c.

146{
147 Abc_BddMan * p; int i;
148 p = ABC_CALLOC( Abc_BddMan, 1 );
149 p->nVars = nVars;
150 p->nObjsAlloc = nObjs;
151 p->nUniqueMask = (1 << Abc_Base2Log(nObjs)) - 1;
152 p->nCacheMask = (1 << Abc_Base2Log(nObjs)) - 1;
153 p->pUnique = ABC_CALLOC( int, p->nUniqueMask + 1 );
154 p->pNexts = ABC_CALLOC( int, p->nObjsAlloc );
155 p->pCache = ABC_CALLOC( int, 3*(p->nCacheMask + 1) );
156 p->pObjs = ABC_CALLOC( int, 2*p->nObjsAlloc );
157 p->pMark = ABC_CALLOC( unsigned char, p->nObjsAlloc );
158 p->pVars = ABC_CALLOC( unsigned char, p->nObjsAlloc );
159 p->pVars[0] = 0xff;
160 p->nObjs = 1;
161 for ( i = 0; i < nVars; i++ )
162 Abc_BddUniqueCreate( p, i, 1, 0 );
163 assert( p->nObjs == nVars + 1 );
164 p->nMemory = sizeof(Abc_BddMan)/4 +
165 p->nUniqueMask + 1 + p->nObjsAlloc +
166 (p->nCacheMask + 1) * 3 * sizeof(int)/4 +
167 p->nObjsAlloc * 2 * sizeof(int)/4;
168 return p;
169}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Abc_BddManFree()

void Abc_BddManFree ( Abc_BddMan * p)

Definition at line 170 of file extraUtilMult.c.

171{
172 printf( "BDD stats: Var = %d Obj = %d Alloc = %d Hit = %d Miss = %d ",
173 p->nVars, p->nObjs, p->nObjsAlloc, p->nCacheLookups-p->nCacheMisses, p->nCacheMisses );
174 printf( "Mem = %.2f MB\n", 4.0*(int)(p->nMemory/(1<<20)) );
175 ABC_FREE( p->pUnique );
176 ABC_FREE( p->pNexts );
177 ABC_FREE( p->pCache );
178 ABC_FREE( p->pObjs );
179 ABC_FREE( p->pVars );
180 ABC_FREE( p );
181}
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the caller graph for this function:

◆ Abc_BddOr()

int Abc_BddOr ( Abc_BddMan * p,
int a,
int b )

Definition at line 217 of file extraUtilMult.c.

218{
219 return Abc_LitNot( Abc_BddAnd(p, Abc_LitNot(a), Abc_LitNot(b)) );
220}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddPrint()

void Abc_BddPrint ( Abc_BddMan * p,
int a )

Definition at line 310 of file extraUtilMult.c.

311{
312 int * pPath = ABC_FALLOC( int, p->nVars );
313 printf( "BDD %d = ", a );
314 Abc_BddPrint_rec( p, a, pPath );
315 ABC_FREE( pPath );
316 printf( "\n" );
317}
#define ABC_FALLOC(type, num)
Definition abc_global.h:266
void Abc_BddPrint_rec(Abc_BddMan *p, int a, int *pPath)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddPrint_rec()

void Abc_BddPrint_rec ( Abc_BddMan * p,
int a,
int * pPath )

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

Synopsis [Printing BDD.]

Description []

SideEffects []

SeeAlso []

Definition at line 291 of file extraUtilMult.c.

292{
293 if ( a == 0 )
294 return;
295 if ( a == 1 )
296 {
297 int i;
298 for ( i = 0; i < p->nVars; i++ )
299 if ( pPath[i] == 0 || pPath[i] == 1 )
300 printf( "%c%d", pPath[i] ? '+' : '-', i );
301 printf( " " );
302 return;
303 }
304 pPath[Abc_BddVar(p, a)] = 0;
305 Abc_BddPrint_rec( p, Abc_BddElse(p, a), pPath );
306 pPath[Abc_BddVar(p, a)] = 1;
307 Abc_BddPrint_rec( p, Abc_BddThen(p, a), pPath );
308 pPath[Abc_BddVar(p, a)] = -1;
309}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddPrintTest()

void Abc_BddPrintTest ( Abc_BddMan * p)

Definition at line 318 of file extraUtilMult.c.

319{
320 int bVarA = Abc_BddIthVar(0);
321 int bVarB = Abc_BddIthVar(1);
322 int bVarC = Abc_BddIthVar(2);
323 int bVarD = Abc_BddIthVar(3);
324 int bAndAB = Abc_BddAnd( p, bVarA, bVarB );
325 int bAndCD = Abc_BddAnd( p, bVarC, bVarD );
326 int bFunc = Abc_BddOr( p, bAndAB, bAndCD );
327 Abc_BddPrint( p, bFunc );
328 printf( "Nodes = %d\n", Abc_BddCountNodes(p, bFunc) );
329}
int Abc_BddOr(Abc_BddMan *p, int a, int b)
int Abc_BddCountNodes(Abc_BddMan *p, int i)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_BddUnmark_rec()

void Abc_BddUnmark_rec ( Abc_BddMan * p,
int i )

Definition at line 242 of file extraUtilMult.c.

243{
244 if ( i < 2 )
245 return;
246 if ( !Abc_BddMark(p, i) )
247 return;
248 Abc_BddSetMark( p, i, 0 );
249 Abc_BddUnmark_rec( p, Abc_BddElse(p, i) );
250 Abc_BddUnmark_rec( p, Abc_BddThen(p, i) );
251}
Here is the call graph for this function:
Here is the caller graph for this function: