ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
superGate.c File Reference
#include <math.h>
#include "superInt.h"
Include dependency graph for superGate.c:

Go to the source code of this file.

Classes

struct  Super_ManStruct_t_
 
struct  Super_GateStruct_t_
 

Macros

#define SUPER_MASK(n)
 DECLARATIONS ///.
 
#define SUPER_FULL   (~((unsigned)0))
 
#define SUPER_NO_VAR   (-9999.0)
 
#define SUPER_EPSILON   (0.001)
 
#define Super_ManForEachGate(GateArray, Limit, Index, Gate)
 

Typedefs

typedef struct Super_ManStruct_t_ Super_Man_t
 
typedef struct Super_GateStruct_t_ Super_Gate_t
 

Functions

void Super_Precompute (Mio_Library_t *pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose, char *pFileName)
 FUNCTION DEFINITIONS ///.
 
Vec_Str_tSuper_PrecomputeStr (Mio_Library_t *pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose)
 
void Super_WriteFileHeaderStr (Super_Man_t *pMan, Vec_Str_t *vStr)
 
void Super_WriteLibraryGateName_rec (Super_Gate_t *pGate, char *pBuffer)
 
char * Super_WriteLibraryGateName (Super_Gate_t *pGate)
 
void Super_WriteLibraryGate (FILE *pFile, Super_Man_t *pMan, Super_Gate_t *pGate, int Num)
 
void Super_WriteLibraryTreeFile_rec (FILE *pFile, Super_Man_t *pMan, Super_Gate_t *pSuper, int *pCounter)
 
void Super_WriteLibraryTreeStr_rec (Vec_Str_t *vStr, Super_Man_t *pMan, Super_Gate_t *pSuper, int *pCounter)
 
void Super_WriteLibraryTree (Super_Man_t *pMan)
 

Macro Definition Documentation

◆ SUPER_EPSILON

#define SUPER_EPSILON   (0.001)

Definition at line 33 of file superGate.c.

◆ SUPER_FULL

#define SUPER_FULL   (~((unsigned)0))

Definition at line 31 of file superGate.c.

◆ Super_ManForEachGate

#define Super_ManForEachGate ( GateArray,
Limit,
Index,
Gate )
Value:
for ( Index = 0; \
Index < Limit && (Gate = GateArray[Index]); \
Index++ )

Definition at line 97 of file superGate.c.

97#define Super_ManForEachGate( GateArray, Limit, Index, Gate ) \
98 for ( Index = 0; \
99 Index < Limit && (Gate = GateArray[Index]); \
100 Index++ )

◆ SUPER_MASK

#define SUPER_MASK ( n)
Value:
((~((unsigned)0)) >> (32-(n)))

DECLARATIONS ///.

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

FileName [superGate.c]

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

Synopsis [Pre-computation of supergates.]

Author [MVSIS Group]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - September 8, 2003.]

Revision [

Id
superGate.c,v 1.7 2004/08/03 00:11:40 satrajit Exp

]

Definition at line 30 of file superGate.c.

◆ SUPER_NO_VAR

#define SUPER_NO_VAR   (-9999.0)

Definition at line 32 of file superGate.c.

Typedef Documentation

◆ Super_Gate_t

Definition at line 37 of file superGate.c.

◆ Super_Man_t

Definition at line 36 of file superGate.c.

Function Documentation

◆ Super_Precompute()

void Super_Precompute ( Mio_Library_t * pLibGen,
int nVarsMax,
int nLevels,
int nGatesMax,
float tDelayMax,
float tAreaMax,
int TimeLimit,
int fSkipInv,
int fVerbose,
char * pFileName )

FUNCTION DEFINITIONS ///.

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

Synopsis [Precomputes the library of supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 140 of file superGate.c.

141{
142 Vec_Str_t * vStr;
143 FILE * pFile = fopen( pFileName, "wb" );
144 if ( pFile == NULL )
145 {
146 printf( "Cannot open output file \"%s\".\n", pFileName );
147 return;
148 }
149 vStr = Super_PrecomputeStr( pLibGen, nVarsMax, nLevels, nGatesMax, tDelayMax, tAreaMax, TimeLimit, fSkipInv, fVerbose );
150 if ( vStr )
151 {
152 fwrite( Vec_StrArray(vStr), 1, Vec_StrSize(vStr), pFile );
153 Vec_StrFree( vStr );
154 }
155 fclose( pFile );
156 // report the result of writing
157 if ( fVerbose )
158 {
159 printf( "The supergates are written using new format \"%s\" ", pFileName );
160 printf( "(%0.3f MB).\n", ((double)Extra_FileSize(pFileName))/(1<<20) );
161 }
162}
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
int Extra_FileSize(char *pFileName)
Vec_Str_t * Super_PrecomputeStr(Mio_Library_t *pLibGen, int nVarsMax, int nLevels, int nGatesMax, float tDelayMax, float tAreaMax, int TimeLimit, int fSkipInv, int fVerbose)
Definition superGate.c:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Super_PrecomputeStr()

Vec_Str_t * Super_PrecomputeStr ( Mio_Library_t * pLibGen,
int nVarsMax,
int nLevels,
int nGatesMax,
float tDelayMax,
float tAreaMax,
int TimeLimit,
int fSkipInv,
int fVerbose )

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

Synopsis [Precomputes the library of supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 175 of file superGate.c.

176{
177 Vec_Str_t * vStr;
178 Super_Man_t * pMan;
179 Mio_Gate_t ** ppGates;
180 int nGates, Level;
181 abctime clk, clockStart;
182
183 assert( nVarsMax < 7 );
184 if ( nGatesMax && nGatesMax < nVarsMax )
185 {
186 fprintf( stderr, "Erro! The number of supergates requested (%d) in less than the number of variables (%d).\n", nGatesMax, nVarsMax );
187 fprintf( stderr, "The library cannot be computed.\n" );
188 return NULL;
189 }
190
191 // get the root gates
192 ppGates = Mio_CollectRoots( pLibGen, nVarsMax, tDelayMax, 0, &nGates, fVerbose );
193 if ( nGatesMax && nGates >= nGatesMax )
194 {
195 fprintf( stdout, "Warning! Genlib library contains more gates than can be computed.\n");
196 fprintf( stdout, "Only one-gate supergates are included in the supergate library.\n" );
197 }
198
199 // start the manager
200 pMan = Super_ManStart();
201 pMan->pName = Mio_LibraryReadName(pLibGen);
202 pMan->nGatesMax = nGatesMax;
203 pMan->fSkipInv = fSkipInv;
204 pMan->tDelayMax = tDelayMax;
205 pMan->tAreaMax = tAreaMax;
206 pMan->TimeLimit = TimeLimit; // in seconds
207 pMan->TimeStop = TimeLimit ? TimeLimit * CLOCKS_PER_SEC + Abc_Clock() : 0; // in CPU ticks
208 pMan->fVerbose = fVerbose;
209
210 if ( nGates == 0 )
211 {
212 fprintf( stderr, "Error: No genlib gates satisfy the limits criteria. Stop.\n");
213 fprintf( stderr, "Limits: max delay = %.2f, max area = %.2f, time limit = %d sec.\n",
214 pMan->tDelayMax, pMan->tAreaMax, pMan->TimeLimit );
215
216 // stop the manager
217 Super_ManStop( pMan );
218 ABC_FREE( ppGates );
219
220 return NULL;
221 }
222
223 // get the starting supergates
224 Super_First( pMan, nVarsMax );
225
226 // perform the computation of supergates
227 clockStart = Abc_Clock();
228if ( fVerbose )
229{
230 printf( "Computing supergates with %d inputs, %d levels, and %d max gates.\n",
231 pMan->nVarsMax, nLevels, nGatesMax );
232 printf( "Limits: max delay = %.2f, max area = %.2f, time limit = %d sec.\n",
233 pMan->tDelayMax, pMan->tAreaMax, pMan->TimeLimit );
234}
235
236 for ( Level = 1; Level <= nLevels; Level++ )
237 {
238 if ( pMan->TimeStop && Abc_Clock() > pMan->TimeStop )
239 break;
240clk = Abc_Clock();
241 Super_Compute( pMan, ppGates, nGates, nGatesMax, fSkipInv );
242 pMan->nLevels = Level;
243if ( fVerbose )
244{
245 printf( "Lev %d: Try =%12d. Add =%6d. Rem =%5d. Save =%6d. Lookups =%12d. Aliases =%12d. ",
246 Level, pMan->nTried, pMan->nAdded, pMan->nRemoved, pMan->nAdded - pMan->nRemoved, pMan->nLookups, pMan->nAliases );
247ABC_PRT( "Time", Abc_Clock() - clk );
248fflush( stdout );
249}
250 }
251 pMan->Time = Abc_Clock() - clockStart;
252
253if ( fVerbose )
254{
255printf( "Writing the output file...\n" );
256fflush( stdout );
257}
258 // write them into a file
259 vStr = Super_Write( pMan );
260
261 // stop the manager
262 Super_ManStop( pMan );
263 ABC_FREE( ppGates );
264 return vStr;
265}
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_FREE(obj)
Definition abc_global.h:267
Mio_Gate_t ** Mio_CollectRoots(Mio_Library_t *pLib, int nInputs, float tDelay, int fSkipInv, int *pnGates, int fVerbose)
Definition mioUtils.c:515
char * Mio_LibraryReadName(Mio_Library_t *pLib)
DECLARATIONS ///.
Definition mioApi.c:43
struct Mio_GateStruct_t_ Mio_Gate_t
Definition mio.h:43
struct Super_ManStruct_t_ Super_Man_t
Definition superGate.c:36
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Super_WriteFileHeaderStr()

void Super_WriteFileHeaderStr ( Super_Man_t * pMan,
Vec_Str_t * vStr )

Definition at line 1092 of file superGate.c.

1093{
1094 char pBuffer[1000];
1095 sprintf( pBuffer, "#\n" );
1096 Vec_StrPrintStr( vStr, pBuffer );
1097 sprintf( pBuffer, "# Supergate library derived for \"%s\" on %s.\n", pMan->pName, Extra_TimeStamp() );
1098 Vec_StrPrintStr( vStr, pBuffer );
1099 sprintf( pBuffer, "#\n" );
1100 Vec_StrPrintStr( vStr, pBuffer );
1101 sprintf( pBuffer, "# Command line: \"super -I %d -L %d -N %d -T %d -D %.2f -A %.2f %s %s\".\n",
1102 pMan->nVarsMax, pMan->nLevels, pMan->nGatesMax, pMan->TimeLimit, pMan->tDelayMax, pMan->tAreaMax, (pMan->fSkipInv? "" : "-s"), pMan->pName );
1103 Vec_StrPrintStr( vStr, pBuffer );
1104 sprintf( pBuffer, "#\n" );
1105 Vec_StrPrintStr( vStr, pBuffer );
1106 sprintf( pBuffer, "# The number of inputs = %10d.\n", pMan->nVarsMax );
1107 Vec_StrPrintStr( vStr, pBuffer );
1108 sprintf( pBuffer, "# The number of levels = %10d.\n", pMan->nLevels );
1109 Vec_StrPrintStr( vStr, pBuffer );
1110 sprintf( pBuffer, "# The maximum delay = %10.2f.\n", pMan->tDelayMax );
1111 Vec_StrPrintStr( vStr, pBuffer );
1112 sprintf( pBuffer, "# The maximum area = %10.2f.\n", pMan->tAreaMax );
1113 Vec_StrPrintStr( vStr, pBuffer );
1114 sprintf( pBuffer, "# The maximum runtime (sec) = %10d.\n", pMan->TimeLimit );
1115 Vec_StrPrintStr( vStr, pBuffer );
1116 sprintf( pBuffer, "#\n" );
1117 Vec_StrPrintStr( vStr, pBuffer );
1118 sprintf( pBuffer, "# The number of attempts = %10d.\n", pMan->nTried );
1119 Vec_StrPrintStr( vStr, pBuffer );
1120 sprintf( pBuffer, "# The number of supergates = %10d.\n", pMan->nGates );
1121 Vec_StrPrintStr( vStr, pBuffer );
1122 sprintf( pBuffer, "# The number of functions = %10d.\n", pMan->nUnique );
1123 Vec_StrPrintStr( vStr, pBuffer );
1124 sprintf( pBuffer, "# The total functions = %.0f (2^%d).\n", pow((double)2,pMan->nMints), pMan->nMints );
1125 Vec_StrPrintStr( vStr, pBuffer );
1126 sprintf( pBuffer, "#\n" );
1127 Vec_StrPrintStr( vStr, pBuffer );
1128 sprintf( pBuffer, "# Generation time = %10.2f sec.\n", (float)(pMan->Time)/(float)(CLOCKS_PER_SEC) );
1129 Vec_StrPrintStr( vStr, pBuffer );
1130 sprintf( pBuffer, "#\n" );
1131 Vec_StrPrintStr( vStr, pBuffer );
1132 sprintf( pBuffer, "%s\n", pMan->pName );
1133 Vec_StrPrintStr( vStr, pBuffer );
1134 sprintf( pBuffer, "%d\n", pMan->nVarsMax );
1135 Vec_StrPrintStr( vStr, pBuffer );
1136 sprintf( pBuffer, "%d\n", pMan->nGates );
1137 Vec_StrPrintStr( vStr, pBuffer );
1138}
char * Extra_TimeStamp()
char * sprintf()
Here is the call graph for this function:

◆ Super_WriteLibraryGate()

void Super_WriteLibraryGate ( FILE * pFile,
Super_Man_t * pMan,
Super_Gate_t * pGate,
int Num )

Definition at line 1226 of file superGate.c.

1227{
1228 int i;
1229 fprintf( pFile, "%04d ", Num ); // the number
1230 Extra_PrintBinary( pFile, pGate->uTruth, pMan->nMints ); // the truth table
1231 fprintf( pFile, " %5.2f", pGate->tDelayMax ); // the max delay
1232 fprintf( pFile, " " );
1233 for ( i = 0; i < pMan->nVarsMax; i++ ) // the pin-to-pin delays
1234 fprintf( pFile, " %5.2f", pGate->ptDelays[i]==SUPER_NO_VAR? 0.0 : pGate->ptDelays[i] );
1235 fprintf( pFile, " %5.2f", pGate->Area ); // the area
1236 fprintf( pFile, " " );
1237 fprintf( pFile, "%s", Super_WriteLibraryGateName(pGate) ); // the symbolic expression
1238 fprintf( pFile, "\n" );
1239}
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
unsigned uTruth[2]
Definition superGate.c:87
char * Super_WriteLibraryGateName(Super_Gate_t *pGate)
Definition superGate.c:1219
#define SUPER_NO_VAR
Definition superGate.c:32
Here is the call graph for this function:

◆ Super_WriteLibraryGateName()

char * Super_WriteLibraryGateName ( Super_Gate_t * pGate)

Definition at line 1219 of file superGate.c.

1220{
1221 static char Buffer[2000];
1222 Buffer[0] = 0;
1223 Super_WriteLibraryGateName_rec( pGate, Buffer );
1224 return Buffer;
1225}
void Super_WriteLibraryGateName_rec(Super_Gate_t *pGate, char *pBuffer)
Definition superGate.c:1198
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Super_WriteLibraryGateName_rec()

void Super_WriteLibraryGateName_rec ( Super_Gate_t * pGate,
char * pBuffer )

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

Synopsis [Writes the gates into the file.]

Description []

SideEffects []

SeeAlso []

Definition at line 1198 of file superGate.c.

1199{
1200 char Buffer[10];
1201 int i;
1202
1203 if ( pGate->pRoot == NULL )
1204 {
1205 sprintf( Buffer, "%c", 'a' + pGate->Number );
1206 strcat( pBuffer, Buffer );
1207 return;
1208 }
1209 strcat( pBuffer, Mio_GateReadName(pGate->pRoot) );
1210 strcat( pBuffer, "(" );
1211 for ( i = 0; i < (int)pGate->nFanins; i++ )
1212 {
1213 if ( i )
1214 strcat( pBuffer, "," );
1215 Super_WriteLibraryGateName_rec( pGate->pFanins[i], pBuffer );
1216 }
1217 strcat( pBuffer, ")" );
1218}
char * Mio_GateReadName(Mio_Gate_t *pGate)
Definition mioApi.c:169
Super_Gate_t * pFanins[6]
Definition superGate.c:88
Mio_Gate_t * pRoot
Definition superGate.c:82
char * strcat()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Super_WriteLibraryTree()

void Super_WriteLibraryTree ( Super_Man_t * pMan)

Definition at line 1449 of file superGate.c.

1450{
1451 Vec_Str_t * vStr;
1452 char * pFileName = Extra_FileNameGenericAppend( pMan->pName, ".super" );
1453 FILE * pFile = fopen( pFileName, "wb" );
1454 if ( pFile == NULL )
1455 {
1456 printf( "Cannot open output file \"%s\".\n", pFileName );
1457 return;
1458 }
1459 vStr = Super_WriteLibraryTreeStr( pMan );
1460 fwrite( Vec_StrArray(vStr), 1, Vec_StrSize(vStr), pFile );
1461 fclose( pFile );
1462 Vec_StrFree( vStr );
1463 // report the result of writing
1464 if ( pMan->fVerbose )
1465 {
1466 printf( "The supergates are written using new format \"%s\" ", pFileName );
1467 printf( "(%0.3f MB).\n", ((double)Extra_FileSize(pFileName))/(1<<20) );
1468 }
1469}
char * Extra_FileNameGenericAppend(char *pBase, char *pSuffix)
Here is the call graph for this function:

◆ Super_WriteLibraryTreeFile_rec()

void Super_WriteLibraryTreeFile_rec ( FILE * pFile,
Super_Man_t * pMan,
Super_Gate_t * pSuper,
int * pCounter )

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

Synopsis [Recursively writes the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 1309 of file superGate.c.

1310{
1311 int nFanins, i;
1312 // skip an elementary variable and a gate that was already written
1313 if ( pSuper->fVar || pSuper->Number > 0 )
1314 return;
1315 // write the fanins
1316 nFanins = Mio_GateReadPinNum(pSuper->pRoot);
1317 for ( i = 0; i < nFanins; i++ )
1318 Super_WriteLibraryTreeFile_rec( pFile, pMan, pSuper->pFanins[i], pCounter );
1319 // finally write the gate
1320 pSuper->Number = (*pCounter)++;
1321 fprintf( pFile, "%s", pSuper->fSuper? "* " : "" );
1322 fprintf( pFile, "%s", Mio_GateReadName(pSuper->pRoot) );
1323 for ( i = 0; i < nFanins; i++ )
1324 fprintf( pFile, " %d", pSuper->pFanins[i]->Number );
1325 // write the formula
1326 // this step is optional, the resulting library will work in any case
1327 // however, it may be helpful to for debugging to compare the same library
1328 // written in the old format and written in the new format with formulas
1329// fprintf( pFile, " # %s", Super_WriteLibraryGateName( pSuper ) );
1330 fprintf( pFile, "\n" );
1331}
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Definition mioApi.c:177
void Super_WriteLibraryTreeFile_rec(FILE *pFile, Super_Man_t *pMan, Super_Gate_t *pSuper, int *pCounter)
Definition superGate.c:1309
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Super_WriteLibraryTreeStr_rec()

void Super_WriteLibraryTreeStr_rec ( Vec_Str_t * vStr,
Super_Man_t * pMan,
Super_Gate_t * pSuper,
int * pCounter )

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

Synopsis [Recursively writes the gates.]

Description []

SideEffects []

SeeAlso []

Definition at line 1389 of file superGate.c.

1390{
1391 int nFanins, i;
1392 // skip an elementary variable and a gate that was already written
1393 if ( pSuper->fVar || pSuper->Number > 0 )
1394 return;
1395 // write the fanins
1396 nFanins = Mio_GateReadPinNum(pSuper->pRoot);
1397 for ( i = 0; i < nFanins; i++ )
1398 Super_WriteLibraryTreeStr_rec( vStr, pMan, pSuper->pFanins[i], pCounter );
1399 // finally write the gate
1400 pSuper->Number = (*pCounter)++;
1401// fprintf( pFile, "%s", pSuper->fSuper? "* " : "" );
1402// fprintf( pFile, "%s", Mio_GateReadName(pSuper->pRoot) );
1403// for ( i = 0; i < nFanins; i++ )
1404// fprintf( pFile, " %d", pSuper->pFanins[i]->Number );
1405 Vec_StrPrintStr( vStr, pSuper->fSuper? "* " : "" );
1406 Vec_StrPrintStr( vStr, Mio_GateReadName(pSuper->pRoot) );
1407 for ( i = 0; i < nFanins; i++ )
1408 {
1409 Vec_StrPrintStr( vStr, " " );
1410 Vec_StrPrintNum( vStr, pSuper->pFanins[i]->Number );
1411 }
1412 // write the formula
1413 // this step is optional, the resulting library will work in any case
1414 // however, it may be helpful to for debugging to compare the same library
1415 // written in the old format and written in the new format with formulas
1416// fprintf( pFile, " # %s", Super_WriteLibraryGateName( pSuper ) );
1417// fprintf( pFile, "\n" );
1418 Vec_StrPrintStr( vStr, "\n" );
1419}
void Super_WriteLibraryTreeStr_rec(Vec_Str_t *vStr, Super_Man_t *pMan, Super_Gate_t *pSuper, int *pCounter)
Definition superGate.c:1389
Here is the call graph for this function:
Here is the caller graph for this function: