00001
00019 #include "fpgaInt.h"
00020
00024
00028
00040 int Fpga_LutLibReadVarMax( Fpga_LutLib_t * p ) { return p->LutMax; }
00041 float * Fpga_LutLibReadLutAreas( Fpga_LutLib_t * p ) { return p->pLutAreas; }
00042 float Fpga_LutLibReadLutArea( Fpga_LutLib_t * p, int Size ) { assert( Size <= p->LutMax ); return p->pLutAreas[Size]; }
00043
00055 Fpga_LutLib_t * Fpga_LutLibCreate( char * FileName, int fVerbose )
00056 {
00057 char pBuffer[1000], * pToken;
00058 Fpga_LutLib_t * p;
00059 FILE * pFile;
00060 int i, k;
00061
00062 pFile = fopen( FileName, "r" );
00063 if ( pFile == NULL )
00064 {
00065 printf( "Cannot open LUT library file \"%s\".\n", FileName );
00066 return NULL;
00067 }
00068
00069 p = ALLOC( Fpga_LutLib_t, 1 );
00070 memset( p, 0, sizeof(Fpga_LutLib_t) );
00071 p->pName = Extra_UtilStrsav( FileName );
00072
00073 i = 1;
00074 while ( fgets( pBuffer, 1000, pFile ) != NULL )
00075 {
00076 pToken = strtok( pBuffer, " \t\n" );
00077 if ( pToken == NULL )
00078 continue;
00079 if ( pToken[0] == '#' )
00080 continue;
00081 if ( i != atoi(pToken) )
00082 {
00083 printf( "Error in the LUT library file \"%s\".\n", FileName );
00084 free( p );
00085 return NULL;
00086 }
00087
00088
00089 pToken = strtok( NULL, " \t\n" );
00090 p->pLutAreas[i] = (float)atof(pToken);
00091
00092
00093 k = 0;
00094 while ( pToken = strtok( NULL, " \t\n" ) )
00095 p->pLutDelays[i][k++] = (float)atof(pToken);
00096
00097
00098 if ( k > i )
00099 {
00100 printf( "LUT %d has too many pins (%d). Max allowed is %d.\n", i, k, i );
00101 return NULL;
00102 }
00103
00104
00105 if ( k > 1 )
00106 p->fVarPinDelays = 1;
00107
00108 if ( i == FPGA_MAX_LUTSIZE )
00109 {
00110 printf( "Skipping LUTs of size more than %d.\n", i );
00111 return NULL;
00112 }
00113 i++;
00114 }
00115 p->LutMax = i-1;
00116 if ( p->LutMax > FPGA_MAX_LEAVES )
00117 {
00118 p->LutMax = FPGA_MAX_LEAVES;
00119 printf( "Warning: LUTs with more than %d input will not be used.\n", FPGA_MAX_LEAVES );
00120 }
00121
00122
00123 if ( p->fVarPinDelays )
00124 {
00125 for ( i = 1; i <= p->LutMax; i++ )
00126 for ( k = 0; k < i; k++ )
00127 {
00128 if ( p->pLutDelays[i][k] <= 0.0 )
00129 printf( "Warning: Pin %d of LUT %d has delay %f. Pin delays should be non-negative numbers. Technology mapping may not work correctly.\n",
00130 k, i, p->pLutDelays[i][k] );
00131 if ( k && p->pLutDelays[i][k-1] > p->pLutDelays[i][k] )
00132 printf( "Warning: Pin %d of LUT %d has delay %f. Pin %d of LUT %d has delay %f. Pin delays should be in non-decreasing order. Technology mapping may not work correctly.\n",
00133 k-1, i, p->pLutDelays[i][k-1],
00134 k, i, p->pLutDelays[i][k] );
00135 }
00136 }
00137 else
00138 {
00139 for ( i = 1; i <= p->LutMax; i++ )
00140 {
00141 if ( p->pLutDelays[i][0] <= 0.0 )
00142 printf( "Warning: LUT %d has delay %f. Pin delays should be non-negative numbers. Technology mapping may not work correctly.\n",
00143 k, i, p->pLutDelays[i][0] );
00144 }
00145 }
00146
00147 return p;
00148 }
00149
00161 Fpga_LutLib_t * Fpga_LutLibDup( Fpga_LutLib_t * p )
00162 {
00163 Fpga_LutLib_t * pNew;
00164 pNew = ALLOC( Fpga_LutLib_t, 1 );
00165 *pNew = *p;
00166 pNew->pName = Extra_UtilStrsav( pNew->pName );
00167 return pNew;
00168 }
00169
00181 void Fpga_LutLibFree( Fpga_LutLib_t * pLutLib )
00182 {
00183 if ( pLutLib == NULL )
00184 return;
00185 FREE( pLutLib->pName );
00186 FREE( pLutLib );
00187 }
00188
00189
00201 void Fpga_LutLibPrint( Fpga_LutLib_t * pLutLib )
00202 {
00203 int i, k;
00204 printf( "# The area/delay of k-variable LUTs:\n" );
00205 printf( "# k area delay\n" );
00206 if ( pLutLib->fVarPinDelays )
00207 {
00208 for ( i = 1; i <= pLutLib->LutMax; i++ )
00209 {
00210 printf( "%d %7.2f ", i, pLutLib->pLutAreas[i] );
00211 for ( k = 0; k < i; k++ )
00212 printf( " %7.2f", pLutLib->pLutDelays[i][k] );
00213 printf( "\n" );
00214 }
00215 }
00216 else
00217 for ( i = 1; i <= pLutLib->LutMax; i++ )
00218 printf( "%d %7.2f %7.2f\n", i, pLutLib->pLutAreas[i], pLutLib->pLutDelays[i][0] );
00219 }
00220
00232 int Fpga_LutLibDelaysAreDiscrete( Fpga_LutLib_t * pLutLib )
00233 {
00234 float Delay;
00235 int i;
00236 for ( i = 1; i <= pLutLib->LutMax; i++ )
00237 {
00238 Delay = pLutLib->pLutDelays[i][0];
00239 if ( ((float)((int)Delay)) != Delay )
00240 return 0;
00241 }
00242 return 1;
00243 }
00244
00248
00249