src/map/mapper/mapperSuper.c File Reference

#include "mapperInt.h"
Include dependency graph for mapperSuper.c:

Go to the source code of this file.

Functions

static int Map_LibraryReadFile (Map_SuperLib_t *pLib, FILE *pFile)
static Map_Super_tMap_LibraryReadGate (Map_SuperLib_t *pLib, char *pBuffer, int nVars)
static int Map_LibraryTruthVerify (Map_SuperLib_t *pLib, Map_Super_t *pGate)
static void Map_LibraryComputeTruth (Map_SuperLib_t *pLib, char *pFormula, unsigned uTruthRes[])
static void Map_LibraryComputeTruth_rec (Map_SuperLib_t *pLib, char *pFormula, unsigned uTruthsIn[][2], unsigned uTruthRes[])
static void Map_LibraryPrintClasses (Map_SuperLib_t *p)
int Map_LibraryRead (Map_SuperLib_t *pLib, char *pFileName)
char * Map_LibraryReadFormulaStep (char *pFormula, char *pStrings[], int *pnStrings)
void Map_LibraryPrintSupergate (Map_Super_t *pGate)

Function Documentation

void Map_LibraryComputeTruth ( Map_SuperLib_t pLib,
char *  pFormula,
unsigned  uTruthRes[] 
) [static]

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

Synopsis [Derives the functionality of the supergate.]

Description [This procedure is useful for verification the supergate library. The truth table derived by this procedure should be the same as the one contained in the original supergate file.]

SideEffects []

SeeAlso []

Definition at line 339 of file mapperSuper.c.

00340 {
00341     char Buffer[1000];
00342     strcpy( Buffer, pFormula );
00343     Map_LibraryComputeTruth_rec( pLib, Buffer, pLib->uTruths, uTruthRes );
00344 }

void Map_LibraryComputeTruth_rec ( Map_SuperLib_t pLib,
char *  pFormula,
unsigned  uTruthsIn[][2],
unsigned  uTruthRes[] 
) [static]

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

Synopsis [Derives the functionality of the supergate.]

Description [This procedure is useful for verification the supergate library. The truth table derived by this procedure should be the same as the one contained in the original supergate file.]

SideEffects []

SeeAlso []

Definition at line 359 of file mapperSuper.c.

00360 {
00361     Mio_Gate_t * pMioGate;
00362     char * pGateName, * pStrings[6];
00363     unsigned uTruthsFanins[6][2];
00364     int nStrings, i;
00365 
00366     // perform one step parsing of the formula
00367     // detect the root gate name, the next-step strings, and their number
00368     pGateName = Map_LibraryReadFormulaStep( pFormula, pStrings, &nStrings );
00369     if ( nStrings == 0 ) // elementary variable
00370     {
00371         assert( pGateName[0] - 'a' < pLib->nVarsMax );
00372         uTruthRes[0] = uTruthsIn[pGateName[0] - 'a'][0];
00373         uTruthRes[1] = uTruthsIn[pGateName[0] - 'a'][1];
00374         return;
00375     }
00376     // derive the functionality of the fanins
00377     for ( i = 0; i < nStrings; i++ )
00378         Map_LibraryComputeTruth_rec( pLib, pStrings[i], uTruthsIn, uTruthsFanins[i] );
00379     // get the root supergate
00380     pMioGate = Mio_LibraryReadGateByName( pLib->pGenlib, pGateName );
00381     if ( pMioGate == NULL )
00382         printf( "A supergate contains gate \"%s\" that is not in \"%s\".\n", pGateName, Mio_LibraryReadName(pLib->pGenlib) ); 
00383     // derive the functionality of the output of the supergate
00384     Mio_DeriveTruthTable( pMioGate, uTruthsFanins, nStrings, pLib->nVarsMax, uTruthRes );
00385 }

void Map_LibraryPrintClasses ( Map_SuperLib_t p  )  [static]

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

Synopsis [Prints N-classes of supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 420 of file mapperSuper.c.

00421 {
00422 /*
00423     st_generator * gen;
00424     Map_Super_t * pSuper, * pSuper2;
00425     unsigned Key, uTruth;
00426     int Counter = 0;
00427     // copy all the supergates into one array
00428     st_foreach_item( p->tSuplib, gen, (char **)&Key, (char **)&pSuper )
00429     {
00430         for ( pSuper2 = pSuper; pSuper2; pSuper2 = pSuper2->pNext )
00431         {
00432             uTruth = pSuper2->Phase;
00433             Extra_PrintBinary( stdout, &uTruth, 5 );
00434             printf( "  %5d   ",  pSuper2->Num );
00435             printf( "%s",    pSuper2->pFormula );
00436             printf( "\n" );
00437         }
00438         printf( "\n" );
00439         if ( ++ Counter == 100 )
00440             break;
00441     }
00442 */
00443 }

void Map_LibraryPrintSupergate ( Map_Super_t pGate  ) 

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 398 of file mapperSuper.c.

00399 {
00400     printf( "%5d : ",  pGate->nUsed );
00401     printf( "%5d   ",  pGate->Num );
00402     printf( "A = %5.2f   ",  pGate->Area );
00403     printf( "D = %5.2f   ",  pGate->tDelayMax );
00404     printf( "%s",    pGate->pFormula );
00405     printf( "\n" );
00406 }

int Map_LibraryRead ( Map_SuperLib_t pLib,
char *  pFileName 
)

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

Synopsis [Reads the supergate library from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file mapperSuper.c.

00048 {
00049     FILE * pFile;
00050     int Status;
00051     // read the beginning of the file
00052     assert( pLib->pGenlib == NULL );
00053     pFile = fopen( pFileName, "r" );
00054     if ( pFile == NULL )
00055     {
00056         printf( "Cannot open input file \"%s\".\n", pFileName );
00057         return 0;
00058     }
00059     Status = Map_LibraryReadFile( pLib, pFile );
00060     fclose( pFile );
00061 //    Map_LibraryPrintClasses( pLib );
00062     return Status;
00063 }

int Map_LibraryReadFile ( Map_SuperLib_t pLib,
FILE *  pFile 
) [static]

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

FileName [mapperSuper.c]

PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]

Synopsis [Generic technology mapping engine.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - June 1, 2004.]

Revision [

Id
mapperSuper.c,v 1.6 2005/01/23 06:59:44 alanmi Exp

] DECLARATIONS ///

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

Synopsis [Reads the library file.]

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file mapperSuper.c.

00078 {
00079     ProgressBar * pProgress;
00080     char pBuffer[2000];
00081     FILE * pFileGen;
00082     Map_Super_t * pGate;
00083     char * pTemp, * pLibName;
00084     int nCounter, nGatesTotal;
00085     unsigned uCanon[2];
00086 
00087     // skip empty and comment lines
00088     while ( fgets( pBuffer, 5000, pFile ) != NULL )
00089     {
00090         // skip leading spaces
00091         for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
00092         // skip comment lines and empty lines
00093         if ( *pTemp != 0 && *pTemp != '#' )
00094             break;
00095     }
00096 
00097     // get the genlib file name
00098     pLibName = strtok( pTemp, " \t\r\n" );
00099     if ( strcmp( pLibName, "GATE" ) == 0 )
00100     {
00101         printf( "The input file \"%s\" looks like a GENLIB file and not a supergate library file.\n", pLib->pName );
00102         return 0;
00103     }
00104     pFileGen = fopen( pLibName, "r" );
00105     if ( pFileGen == NULL )
00106     {
00107         printf( "Cannot open the GENLIB file \"%s\".\n", pLibName );
00108         return 0;
00109     }
00110     fclose( pFileGen );
00111 
00112     // read the genlib library
00113     pLib->pGenlib = Mio_LibraryRead( Abc_FrameGetGlobalFrame(), pLibName, 0, 0 );
00114     if ( pLib->pGenlib == NULL )
00115     {
00116         printf( "Cannot read GENLIB file \"%s\".\n", pLibName );
00117         return 0;
00118     }
00119 
00120     // read the number of variables
00121     fscanf( pFile, "%d\n", &pLib->nVarsMax );
00122     if ( pLib->nVarsMax < 2 || pLib->nVarsMax > 10 )
00123     {
00124         printf( "Suspicious number of variables (%d).\n", pLib->nVarsMax );
00125         return 0;
00126     }
00127 
00128     // read the number of gates
00129     fscanf( pFile, "%d\n", &nGatesTotal );
00130     if ( nGatesTotal < 1 || nGatesTotal > 10000000 )
00131     {
00132         printf( "Suspicious number of gates (%d).\n", nGatesTotal );
00133         return 0;
00134     }
00135 
00136     // read the lines
00137     nCounter = 0;
00138     pProgress = Extra_ProgressBarStart( stdout, nGatesTotal );
00139     while ( fgets( pBuffer, 5000, pFile ) != NULL )
00140     {
00141         for ( pTemp = pBuffer; *pTemp == ' ' || *pTemp == '\r' || *pTemp == '\n'; pTemp++ );
00142         if ( pTemp[0] == '\0' )
00143             continue;
00144         // get the gate
00145         pGate = Map_LibraryReadGate( pLib, pTemp, pLib->nVarsMax );
00146         assert( pGate->Num == nCounter + 1 );
00147         // count the number of parantheses in the formula - this is the number of gates
00148         for ( pTemp = pGate->pFormula; *pTemp; pTemp++ )
00149             pGate->nGates += (*pTemp == '(');
00150         // verify the truth table
00151         assert( Map_LibraryTruthVerify(pLib, pGate) );
00152 
00153         // find the N-canonical form of this supergate
00154         pGate->nPhases = Map_CanonComputeSlow( pLib->uTruths, pLib->nVarsMax, pLib->nVarsMax, pGate->uTruth, pGate->uPhases, uCanon );
00155         // add the supergate into the table by its N-canonical table
00156         Map_SuperTableInsertC( pLib->tTableC, uCanon, pGate );
00157         // update the progress bar
00158         Extra_ProgressBarUpdate( pProgress, ++nCounter, NULL );
00159     }
00160     Extra_ProgressBarStop( pProgress );
00161     pLib->nSupersAll = nCounter;
00162     if ( nCounter != nGatesTotal )
00163         printf( "The number of gates read (%d) is different what the file says (%d).\n", nGatesTotal, nCounter );
00164     return 1;
00165 }

char* Map_LibraryReadFormulaStep ( char *  pFormula,
char *  pStrings[],
int *  pnStrings 
)

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

Synopsis [Performs one step of parsing the formula into parts.]

Description [This function will eventually be replaced when the tree-supergate library representation will become standard.]

SideEffects []

SeeAlso []

Definition at line 251 of file mapperSuper.c.

00252 {
00253     char * pName, * pPar1, * pPar2, * pCur;
00254     int nStrings, CountPars;
00255 
00256     // skip leading spaces
00257     for ( pName = pFormula; *pName && *pName == ' '; pName++ );
00258     assert( *pName );
00259     // find the first opening paranthesis
00260     for ( pPar1 = pName; *pPar1 && *pPar1 != '('; pPar1++ );
00261     if ( *pPar1 == 0 )
00262     {
00263         *pnStrings = 0;
00264         return pName;
00265     }
00266     // overwrite it with space
00267     assert( *pPar1 == '(' );
00268     *pPar1 = 0;
00269     // find the corresponding closing paranthesis
00270     for ( CountPars = 1, pPar2 = pPar1 + 1; *pPar2 && CountPars; pPar2++ )
00271         if ( *pPar2 == '(' )
00272             CountPars++;
00273         else if ( *pPar2 == ')' )
00274             CountPars--;
00275     pPar2--;
00276     assert( CountPars == 0 );
00277     // overwrite it with space
00278     assert( *pPar2 == ')' );
00279     *pPar2 = 0;
00280     // save the intervals between the commas
00281     nStrings = 0;
00282     pCur = pPar1 + 1;
00283     while ( 1 )
00284     {
00285         // save the current string
00286         pStrings[ nStrings++ ] = pCur;
00287         // find the beginning of the next string
00288         for ( CountPars = 0; *pCur && (CountPars || *pCur != ','); pCur++ )
00289             if ( *pCur == '(' )
00290                 CountPars++;
00291             else if ( *pCur == ')' )
00292                 CountPars--;
00293         if ( *pCur == 0 )
00294             break;
00295         assert( *pCur == ',' );
00296         *pCur = 0;
00297         pCur++;
00298     }
00299     // save the results and return
00300     *pnStrings = nStrings;
00301     return pName;
00302 }

Map_Super_t * Map_LibraryReadGate ( Map_SuperLib_t pLib,
char *  pBuffer,
int  nVars 
) [static]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 178 of file mapperSuper.c.

00179 {
00180     Map_Super_t * pGate;
00181     char * pTemp;
00182     int i;
00183 
00184     // start and clean the gate
00185     pGate = (Map_Super_t *)Extra_MmFixedEntryFetch( pLib->mmSupers );
00186     memset( pGate, 0, sizeof(Map_Super_t) );
00187 
00188     // read the number
00189     pTemp = strtok( pBuffer, " " );
00190     pGate->Num = atoi(pTemp);
00191 
00192     // read the signature
00193     pTemp = strtok( NULL, " " );
00194     if ( pLib->nVarsMax < 6 )
00195     {
00196         pGate->uTruth[0] = Extra_ReadBinary(pTemp);
00197         pGate->uTruth[1] = 0;
00198     }
00199     else
00200     {
00201         pGate->uTruth[0] = Extra_ReadBinary(pTemp+32);
00202         pTemp[32] = 0;
00203         pGate->uTruth[1] = Extra_ReadBinary(pTemp);
00204     }
00205 
00206     // read the max delay
00207     pTemp = strtok( NULL, " " );
00208     pGate->tDelayMax.Rise = (float)atof(pTemp);
00209     pGate->tDelayMax.Fall = pGate->tDelayMax.Rise;
00210 
00211     // read the pin-to-pin delay
00212     for ( i = 0; i < nVars; i++ )
00213     {
00214         pTemp = strtok( NULL, " " );
00215         pGate->tDelaysR[i].Rise = (float)atof(pTemp);
00216         pGate->tDelaysF[i].Fall = pGate->tDelaysR[i].Rise;
00217     }
00218 
00219     // read the area
00220     pTemp = strtok( NULL, " " );
00221     pGate->Area = (float)atof(pTemp);
00222 
00223     // the rest is the gate name
00224     pTemp = strtok( NULL, " \r\n" );
00225     if ( strlen(pTemp) == 0 )
00226         printf( "A gate name is empty.\n" );
00227 
00228     // save the gate name
00229     pGate->pFormula = Extra_MmFlexEntryFetch( pLib->mmForms, strlen(pTemp) + 1 );
00230     strcpy( pGate->pFormula, pTemp );
00231 
00232     // the rest is the gate name
00233     pTemp = strtok( NULL, " \n\0" );
00234     if ( pTemp != NULL )
00235         printf( "The following trailing symbols found \"%s\".\n", pTemp );
00236     return pGate;
00237 }

int Map_LibraryTruthVerify ( Map_SuperLib_t pLib,
Map_Super_t pGate 
) [static]

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

Synopsis [Verifies the truth table of the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 316 of file mapperSuper.c.

00317 {
00318     unsigned uTruthRes[2];
00319     Map_LibraryComputeTruth( pLib, pGate->pFormula, uTruthRes );
00320     if ( uTruthRes[0] != pGate->uTruth[0] || uTruthRes[1] != pGate->uTruth[1] )
00321         return 0;
00322     return 1;
00323 }


Generated on Tue Jan 5 12:19:06 2010 for abc70930 by  doxygen 1.6.1