ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcNpnSave.c File Reference
#include "base/abc/abc.h"
#include "aig/aig/aig.h"
Include dependency graph for abcNpnSave.c:

Go to the source code of this file.

Classes

struct  Npn_Obj_t_
 
struct  Npn_Man_t_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Npn_Obj_t_ Npn_Obj_t
 DECLARATIONS ///.
 
typedef struct Npn_Man_t_ Npn_Man_t
 

Functions

void Npn_TruthPermute_rec (char *pStr, int mid, int end)
 FUNCTION DEFINITIONS ///.
 
word Npn_TruthPadWord (word uTruth, int nVars)
 
void Npn_ManResize (Npn_Man_t *p)
 
Npn_Obj_tNpn_ManAdd (Npn_Man_t *p, word uTruth)
 
void Npn_ManRead (Npn_Man_t *p, char *pFileName)
 
void Npn_ManWrite (Npn_Man_t *p, char *pFileName)
 
Npn_Man_tNpn_ManStart (char *pFileName)
 
void Npn_ManStop (Npn_Man_t *p)
 
void Npn_ManClean ()
 
void Npn_ManLoad (char *pFileName)
 
void Npn_ManSave (char *pFileName)
 
void Npn_ManSaveOne (unsigned *puTruth, int nVars)
 

Typedef Documentation

◆ Npn_Man_t

typedef struct Npn_Man_t_ Npn_Man_t

Definition at line 32 of file abcNpnSave.c.

◆ Npn_Obj_t

typedef typedefABC_NAMESPACE_IMPL_START struct Npn_Obj_t_ Npn_Obj_t

DECLARATIONS ///.

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

FileName [abcNpnSave.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Network and node package.]

Synopsis [Interface with the FPGA mapping package.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - November 21, 2006.]

Revision [

Id
abcNpnSave.c,v 1.00 2006/11/21 00:00:00 alanmi Exp

]

Definition at line 31 of file abcNpnSave.c.

Function Documentation

◆ Npn_ManAdd()

Npn_Obj_t * Npn_ManAdd ( Npn_Man_t * p,
word uTruth )

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

Synopsis [Adds one entry to the table.]

Description [Increments ref counter by 1.]

SideEffects []

SeeAlso []

Definition at line 437 of file abcNpnSave.c.

438{
439 Npn_Obj_t * pEntry;
440 int * pPlace, Key = Npn_ManHash( p, uTruth );
441 // resize the link storage if needed
442 if ( p->nEntries == p->nBufferSize )
443 {
444 p->nBufferSize *= 2;
445 p->pBuffer = ABC_REALLOC( Npn_Obj_t, p->pBuffer, p->nBufferSize );
446 }
447 // find the entry
448 for ( pEntry = Npn_ManObj(p, p->pBins[Key]),
449 pPlace = p->pBins + Key;
450 pEntry;
451 pPlace = &pEntry->iNext,
452 pEntry = Npn_ManObj(p, pEntry->iNext) )
453 if ( pEntry->uTruth == uTruth )
454 {
455 pEntry->Count++;
456 return pEntry;
457 }
458 // create new entry
459 *pPlace = p->nEntries;
460 assert( p->nEntries < p->nBufferSize );
461 pEntry = Npn_ManObj( p, p->nEntries++ );
462 pEntry->uTruth = uTruth;
463 pEntry->Count = 1;
464 pEntry->iNext = 0;
465 // resize the table if needed
466 if ( p->nEntries > 3 * p->nBins )
467 Npn_ManResize( p );
468 return pEntry;
469}
void Npn_ManResize(Npn_Man_t *p)
Definition abcNpnSave.c:391
typedefABC_NAMESPACE_IMPL_START struct Npn_Obj_t_ Npn_Obj_t
DECLARATIONS ///.
Definition abcNpnSave.c:31
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
Cube * p
Definition exorList.c:222
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Npn_ManClean()

void Npn_ManClean ( )

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

Synopsis [Cleans the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 649 of file abcNpnSave.c.

650{
651 if ( pNpnMan != NULL )
652 {
653 Npn_ManStop( pNpnMan );
654 pNpnMan = NULL;
655 }
656}
void Npn_ManStop(Npn_Man_t *p)
Definition abcNpnSave.c:631
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Npn_ManLoad()

void Npn_ManLoad ( char * pFileName)

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

Synopsis [Loads functions from a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 669 of file abcNpnSave.c.

670{
671// Npn_TruthPermute_rec( "012345", 0, 5 );
672 if ( pNpnMan != NULL )
673 {
674 Abc_Print( 1, "Removing old table with %d entries.\n", pNpnMan->nEntries );
675 Npn_ManStop( pNpnMan );
676 }
677 pNpnMan = Npn_ManStart( pFileName );
678 Abc_Print( 1, "Created new table with %d entries from file \"%s\".\n", pNpnMan->nEntries, pFileName );
679}
Npn_Man_t * Npn_ManStart(char *pFileName)
Definition abcNpnSave.c:588
Here is the call graph for this function:

◆ Npn_ManRead()

void Npn_ManRead ( Npn_Man_t * p,
char * pFileName )

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

Synopsis [Fills table from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 482 of file abcNpnSave.c.

483{
484 char pBuffer[1000];
485 char * pToken;
486 Npn_Obj_t * pEntry;
487 unsigned Truth[2];
488 word uTruth;
489 FILE * pFile = fopen( pFileName, "r" );
490 if ( pFile == NULL )
491 {
492 Abc_Print( -1, "Cannot open NPN function file \"%s\".\n", pFileName );
493 return;
494 }
495 // read lines from the file
496 while ( fgets( pBuffer, 1000, pFile ) != NULL )
497 {
498 pToken = strtok( pBuffer, " \t\n" );
499 if ( pToken == NULL )
500 continue;
501 if ( pToken[0] == '#' )
502 continue;
503 if ( strlen(pToken) != 16 )
504 {
505 Abc_Print( 0, "Skipping token %s that does not look like a 16-digit hex number.\n" );
506 continue;
507 }
508 // extract truth table
509 Extra_ReadHexadecimal( Truth, pToken, 6 );
510 uTruth = (((word)Truth[1]) << 32) | (word)Truth[0];
511 // add truth table
512 pEntry = Npn_ManAdd( p, uTruth );
513 assert( pEntry->Count == 1 );
514 // read area
515 pToken = strtok( NULL, " \t\n" );
516 pEntry->Count = atoi(pToken);
517 }
518 fclose( pFile );
519}
Npn_Obj_t * Npn_ManAdd(Npn_Man_t *p, word uTruth)
Definition abcNpnSave.c:437
int Extra_ReadHexadecimal(unsigned Sign[], char *pString, int nVars)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int strlen()
char * strtok()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Npn_ManResize()

void Npn_ManResize ( Npn_Man_t * p)

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

Synopsis [Resizes the table.]

Description []

SideEffects []

SeeAlso []

Definition at line 391 of file abcNpnSave.c.

392{
393 Npn_Obj_t * pEntry, * pNext;
394 int * pBinsOld, * ppPlace;
395 int nBinsOld, Counter, i;
396 abctime clk;
397 assert( p->pBins != NULL );
398clk = Abc_Clock();
399 // save the old Bins
400 pBinsOld = p->pBins;
401 nBinsOld = p->nBins;
402 // get the new Bins
403 p->nBins = Abc_PrimeCudd( 3 * nBinsOld );
404 p->pBins = ABC_CALLOC( int, p->nBins );
405 // rehash the entries from the old table
406 Counter = 1;
407 for ( i = 0; i < nBinsOld; i++ )
408 for ( pEntry = Npn_ManObj(p, pBinsOld[i]),
409 pNext = pEntry ? Npn_ManObj(p, pEntry->iNext) : NULL;
410 pEntry;
411 pEntry = pNext,
412 pNext = pEntry ? Npn_ManObj(p, pEntry->iNext) : NULL )
413 {
414 // get the place where this entry goes
415 ppPlace = p->pBins + Npn_ManHash( p, pEntry->uTruth );
416 // add the entry to the list
417 pEntry->iNext = *ppPlace;
418 *ppPlace = Npn_ManObjNum( p, pEntry );
419 Counter++;
420 }
421 assert( Counter == p->nEntries );
422 ABC_FREE( pBinsOld );
423//ABC_PRT( "Hash table resizing time", Abc_Clock() - clk );
424}
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
Here is the caller graph for this function:

◆ Npn_ManSave()

void Npn_ManSave ( char * pFileName)

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

Synopsis [Saves functions into a file.]

Description []

SideEffects []

SeeAlso []

Definition at line 692 of file abcNpnSave.c.

693{
694 if ( pNpnMan == NULL )
695 {
696 Abc_Print( 1, "There is no table with entries.\n" );
697 return;
698 }
699 Npn_ManWrite( pNpnMan, pFileName );
700 Abc_Print( 1, "Dumped table with %d entries from file \"%s\".\n", pNpnMan->nEntries, pFileName );
701}
void Npn_ManWrite(Npn_Man_t *p, char *pFileName)
Definition abcNpnSave.c:552
Here is the call graph for this function:

◆ Npn_ManSaveOne()

void Npn_ManSaveOne ( unsigned * puTruth,
int nVars )

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

Synopsis [Saves one function into storage.]

Description []

SideEffects []

SeeAlso []

Definition at line 714 of file abcNpnSave.c.

715{
716 word uTruth = (((word)puTruth[1]) << 32) | (word)puTruth[0];
717 assert( nVars >= 0 && nVars <= 6 );
718 if ( pNpnMan == NULL )
719 {
720 Abc_Print( 1, "Creating new table with 0 entries.\n" );
721 pNpnMan = Npn_ManStart( NULL );
722 }
723 // skip truth tables that do not depend on some vars
724 if ( !Npn_TruthIsMinBase( uTruth ) )
725 return;
726 // extend truth table to look like 6-input
727 uTruth = Npn_TruthPadWord( uTruth, nVars );
728 // semi(!)-NPN-canonize the truth table
729 uTruth = Npn_TruthCanon( uTruth, 6, NULL );
730 // add to storage
731 Npn_ManAdd( pNpnMan, uTruth );
732}
word Npn_TruthPadWord(word uTruth, int nVars)
Definition abcNpnSave.c:191
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Npn_ManStart()

Npn_Man_t * Npn_ManStart ( char * pFileName)

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

Synopsis [Creates the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 588 of file abcNpnSave.c.

589{
590 Npn_Man_t * p;
591 p = ABC_CALLOC( Npn_Man_t, 1 );
592 if ( pFileName == NULL )
593 {
594 p->nBufferSize = 1000000;
595 p->nBufferSize = 100;
596 p->pBuffer = ABC_ALLOC( Npn_Obj_t, p->nBufferSize );
597 p->nBins = Abc_PrimeCudd( p->nBufferSize / 2 );
598 p->pBins = ABC_CALLOC( int, p->nBins );
599 p->nEntries = 1;
600 }
601 else
602 {
603 FILE * pFile = fopen( pFileName, "r" );
604 if ( pFile == NULL )
605 {
606 Abc_Print( -1, "Cannot open NPN function file \"%s\".\n", pFileName );
607 return NULL;
608 }
609 fclose( pFile );
610 p->nBufferSize = 4 * ( Extra_FileSize(pFileName) / 20 );
611 p->pBuffer = ABC_ALLOC( Npn_Obj_t, p->nBufferSize );
612 p->nBins = Abc_PrimeCudd( p->nBufferSize / 2 );
613 p->pBins = ABC_CALLOC( int, p->nBins );
614 p->nEntries = 1;
615 Npn_ManRead( p, pFileName );
616 }
617 return p;
618}
void Npn_ManRead(Npn_Man_t *p, char *pFileName)
Definition abcNpnSave.c:482
struct Npn_Man_t_ Npn_Man_t
Definition abcNpnSave.c:32
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
int Extra_FileSize(char *pFileName)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Npn_ManStop()

void Npn_ManStop ( Npn_Man_t * p)

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

Synopsis [Deletes the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 631 of file abcNpnSave.c.

632{
633 ABC_FREE( p->pBuffer );
634 ABC_FREE( p->pBins );
635 ABC_FREE( p );
636}
Here is the caller graph for this function:

◆ Npn_ManWrite()

void Npn_ManWrite ( Npn_Man_t * p,
char * pFileName )

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

Synopsis [Adds one entry to the table.]

Description []

SideEffects []

SeeAlso []

Definition at line 552 of file abcNpnSave.c.

553{
554 Vec_Ptr_t * vEntries;
555 Npn_Obj_t * pEntry;
556 FILE * pFile = fopen( pFileName, "w" );
557 int i;
558 if ( pFile == NULL )
559 {
560 Abc_Print( -1, "Cannot open NPN function file \"%s\".\n", pFileName );
561 return;
562 }
563 vEntries = Vec_PtrAlloc( p->nEntries );
564 for ( i = 0; i < p->nBins; i++ )
565 for ( pEntry = Npn_ManObj(p, p->pBins[i]); pEntry; pEntry = Npn_ManObj(p, pEntry->iNext) )
566 Vec_PtrPush( vEntries, pEntry );
567 Vec_PtrSort( vEntries, (int (*)(const void *, const void *))Npn_ManCompareEntries );
568 Vec_PtrForEachEntry( Npn_Obj_t *, vEntries, pEntry, i )
569 {
570 Extra_PrintHexadecimal( pFile, (unsigned *)&pEntry->uTruth, 6 );
571 fprintf( pFile, " %d %d\n", pEntry->Count, Npn_TruthSuppSize(pEntry->uTruth, 6) );
572 }
573 fclose( pFile );
574 Vec_PtrFree( vEntries );
575}
void Extra_PrintHexadecimal(FILE *pFile, unsigned Sign[], int nVars)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Npn_TruthPadWord()

word Npn_TruthPadWord ( word uTruth,
int nVars )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 191 of file abcNpnSave.c.

192{
193 if ( nVars == 6 )
194 return uTruth;
195 if ( nVars <= 5 )
196 uTruth = ((uTruth & ABC_CONST(0x00000000FFFFFFFF)) << 32) | (uTruth & ABC_CONST(0x00000000FFFFFFFF));
197 if ( nVars <= 4 )
198 uTruth = ((uTruth & ABC_CONST(0x0000FFFF0000FFFF)) << 16) | (uTruth & ABC_CONST(0x0000FFFF0000FFFF));
199 if ( nVars <= 3 )
200 uTruth = ((uTruth & ABC_CONST(0x00FF00FF00FF00FF)) << 8) | (uTruth & ABC_CONST(0x00FF00FF00FF00FF));
201 if ( nVars <= 2 )
202 uTruth = ((uTruth & ABC_CONST(0x0F0F0F0F0F0F0F0F)) << 4) | (uTruth & ABC_CONST(0x0F0F0F0F0F0F0F0F));
203 if ( nVars <= 1 )
204 uTruth = ((uTruth & ABC_CONST(0x3333333333333333)) << 2) | (uTruth & ABC_CONST(0x3333333333333333));
205 if ( nVars == 0 )
206 uTruth = ((uTruth & ABC_CONST(0x5555555555555555)) << 1) | (uTruth & ABC_CONST(0x5555555555555555));
207 return uTruth;
208}
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
Here is the caller graph for this function:

◆ Npn_TruthPermute_rec()

void Npn_TruthPermute_rec ( char * pStr,
int mid,
int end )

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file abcNpnSave.c.

81{
82 static int count = 0;
83 char * pTemp = Abc_UtilStrsav(pStr);
84 char e;
85 int i;
86 if ( mid == end )
87 {
88 printf( "%03d: %s\n", count++, pTemp );
89 return ;
90 }
91 for ( i = mid; i <= end; i++ )
92 {
93 e = pTemp[mid];
94 pTemp[mid] = pTemp[i];
95 pTemp[i] = e;
96
97 Npn_TruthPermute_rec( pTemp, mid + 1, end );
98
99 e = pTemp[mid];
100 pTemp[mid] = pTemp[i];
101 pTemp[i] = e;
102 }
103 ABC_FREE( pTemp );
104}
void Npn_TruthPermute_rec(char *pStr, int mid, int end)
FUNCTION DEFINITIONS ///.
Definition abcNpnSave.c:80
Here is the call graph for this function:
Here is the caller graph for this function: