abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fpgaLib.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [fpgaLib.c]
4 
5  PackageName [MVSIS 1.3: Multi-valued logic synthesis system.]
6 
7  Synopsis [Technology mapping for variable-size-LUT FPGAs.]
8 
9  Author [MVSIS Group]
10 
11  Affiliation [UC Berkeley]
12 
13  Date [Ver. 2.0. Started - August 18, 2004.]
14 
15  Revision [$Id: fpgaLib.c,v 1.4 2005/01/23 06:59:41 alanmi Exp $]
16 
17 ***********************************************************************/
18 
19 #include "fpgaInt.h"
20 
22 
23 
24 ////////////////////////////////////////////////////////////////////////
25 /// DECLARATIONS ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// FUNCTION DEFINITIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 /**Function*************************************************************
33 
34  Synopsis [APIs to access LUT library.]
35 
36  Description []
37 
38  SideEffects []
39 
40  SeeAlso []
41 
42 ***********************************************************************/
44 float * Fpga_LutLibReadLutAreas( Fpga_LutLib_t * p ) { return p->pLutAreas; }
45 float Fpga_LutLibReadLutArea( Fpga_LutLib_t * p, int Size ) { assert( Size <= p->LutMax ); return p->pLutAreas[Size]; }
46 
47 /**Function*************************************************************
48 
49  Synopsis [Reads the description of LUTs from the LUT library file.]
50 
51  Description []
52 
53  SideEffects []
54 
55  SeeAlso []
56 
57 ***********************************************************************/
58 Fpga_LutLib_t * Fpga_LutLibRead( char * FileName, int fVerbose )
59 {
60  char pBuffer[1000], * pToken;
61  Fpga_LutLib_t * p;
62  FILE * pFile;
63  int i, k;
64 
65  pFile = fopen( FileName, "r" );
66  if ( pFile == NULL )
67  {
68  printf( "Cannot open LUT library file \"%s\".\n", FileName );
69  return NULL;
70  }
71 
72  p = ABC_ALLOC( Fpga_LutLib_t, 1 );
73  memset( p, 0, sizeof(Fpga_LutLib_t) );
74  p->pName = Extra_UtilStrsav( FileName );
75 
76  i = 1;
77  while ( fgets( pBuffer, 1000, pFile ) != NULL )
78  {
79  pToken = strtok( pBuffer, " \t\n" );
80  if ( pToken == NULL )
81  continue;
82  if ( pToken[0] == '#' )
83  continue;
84  if ( i != atoi(pToken) )
85  {
86  printf( "Error in the LUT library file \"%s\".\n", FileName );
87  ABC_FREE( p );
88  return NULL;
89  }
90 
91  // read area
92  pToken = strtok( NULL, " \t\n" );
93  p->pLutAreas[i] = (float)atof(pToken);
94 
95  // read delays
96  k = 0;
97  while ( (pToken = strtok( NULL, " \t\n" )) )
98  p->pLutDelays[i][k++] = (float)atof(pToken);
99 
100  // check for out-of-bound
101  if ( k > i )
102  {
103  printf( "LUT %d has too many pins (%d). Max allowed is %d.\n", i, k, i );
104  return NULL;
105  }
106 
107  // check if var delays are specifies
108  if ( k > 1 )
109  p->fVarPinDelays = 1;
110 
111  if ( i == FPGA_MAX_LUTSIZE )
112  {
113  printf( "Skipping LUTs of size more than %d.\n", i );
114  return NULL;
115  }
116  i++;
117  }
118  p->LutMax = i-1;
119 /*
120  if ( p->LutMax > FPGA_MAX_LEAVES )
121  {
122  p->LutMax = FPGA_MAX_LEAVES;
123  printf( "Warning: LUTs with more than %d inputs will not be used.\n", FPGA_MAX_LEAVES );
124  }
125 */
126  // check the library
127  if ( p->fVarPinDelays )
128  {
129  for ( i = 1; i <= p->LutMax; i++ )
130  for ( k = 0; k < i; k++ )
131  {
132  if ( p->pLutDelays[i][k] <= 0.0 )
133  printf( "Warning: Pin %d of LUT %d has delay %f. Pin delays should be non-negative numbers. Technology mapping may not work correctly.\n",
134  k, i, p->pLutDelays[i][k] );
135  if ( k && p->pLutDelays[i][k-1] > p->pLutDelays[i][k] )
136  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",
137  k-1, i, p->pLutDelays[i][k-1],
138  k, i, p->pLutDelays[i][k] );
139  }
140  }
141  else
142  {
143  for ( i = 1; i <= p->LutMax; i++ )
144  {
145  if ( p->pLutDelays[i][0] <= 0.0 )
146  printf( "Warning: LUT %d has delay %f. Pin delays should be non-negative numbers. Technology mapping may not work correctly.\n",
147  i, p->pLutDelays[i][0] );
148  }
149  }
150 
151  return p;
152 }
153 
154 /**Function*************************************************************
155 
156  Synopsis [Duplicates the LUT library.]
157 
158  Description []
159 
160  SideEffects []
161 
162  SeeAlso []
163 
164 ***********************************************************************/
166 {
167  Fpga_LutLib_t * pNew;
168  pNew = ABC_ALLOC( Fpga_LutLib_t, 1 );
169  *pNew = *p;
170  pNew->pName = Extra_UtilStrsav( pNew->pName );
171  return pNew;
172 }
173 
174 /**Function*************************************************************
175 
176  Synopsis [Frees the LUT library.]
177 
178  Description []
179 
180  SideEffects []
181 
182  SeeAlso []
183 
184 ***********************************************************************/
186 {
187  if ( pLutLib == NULL )
188  return;
189  ABC_FREE( pLutLib->pName );
190  ABC_FREE( pLutLib );
191 }
192 
193 
194 /**Function*************************************************************
195 
196  Synopsis [Prints the LUT library.]
197 
198  Description []
199 
200  SideEffects []
201 
202  SeeAlso []
203 
204 ***********************************************************************/
206 {
207  int i, k;
208  printf( "# The area/delay of k-variable LUTs:\n" );
209  printf( "# k area delay\n" );
210  if ( pLutLib->fVarPinDelays )
211  {
212  for ( i = 1; i <= pLutLib->LutMax; i++ )
213  {
214  printf( "%d %7.2f ", i, pLutLib->pLutAreas[i] );
215  for ( k = 0; k < i; k++ )
216  printf( " %7.2f", pLutLib->pLutDelays[i][k] );
217  printf( "\n" );
218  }
219  }
220  else
221  for ( i = 1; i <= pLutLib->LutMax; i++ )
222  printf( "%d %7.2f %7.2f\n", i, pLutLib->pLutAreas[i], pLutLib->pLutDelays[i][0] );
223 }
224 
225 /**Function*************************************************************
226 
227  Synopsis [Returns 1 if the delays are discrete.]
228 
229  Description []
230 
231  SideEffects []
232 
233  SeeAlso []
234 
235 ***********************************************************************/
237 {
238  float Delay;
239  int i;
240  for ( i = 1; i <= pLutLib->LutMax; i++ )
241  {
242  Delay = pLutLib->pLutDelays[i][0];
243  if ( ((float)((int)Delay)) != Delay )
244  return 0;
245  }
246  return 1;
247 }
248 
249 ////////////////////////////////////////////////////////////////////////
250 /// END OF FILE ///
251 ////////////////////////////////////////////////////////////////////////
252 
253 
255 
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
float pLutDelays[FPGA_MAX_LUTSIZE+1][FPGA_MAX_LUTSIZE+1]
Definition: fpgaInt.h:176
float Fpga_LutLibReadLutArea(Fpga_LutLib_t *p, int Size)
Definition: fpgaLib.c:45
char * strtok()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
float pLutAreas[FPGA_MAX_LUTSIZE+1]
Definition: fpgaInt.h:175
void Fpga_LutLibPrint(Fpga_LutLib_t *pLutLib)
Definition: fpgaLib.c:205
char * Extra_UtilStrsav(const char *s)
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Fpga_LutLib_t * Fpga_LutLibRead(char *FileName, int fVerbose)
Definition: fpgaLib.c:58
ABC_NAMESPACE_IMPL_START int Fpga_LutLibReadVarMax(Fpga_LutLib_t *p)
DECLARATIONS ///.
Definition: fpgaLib.c:43
#define FPGA_MAX_LUTSIZE
INCLUDES ///.
Definition: fpga.h:37
double atof()
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
float * Fpga_LutLibReadLutAreas(Fpga_LutLib_t *p)
Definition: fpgaLib.c:44
#define ABC_FREE(obj)
Definition: abc_global.h:232
Fpga_LutLib_t * Fpga_LutLibDup(Fpga_LutLib_t *p)
Definition: fpgaLib.c:165
#define assert(ex)
Definition: util_old.h:213
int Fpga_LutLibDelaysAreDiscrete(Fpga_LutLib_t *pLutLib)
Definition: fpgaLib.c:236
void Fpga_LutLibFree(Fpga_LutLib_t *pLutLib)
Definition: fpgaLib.c:185