abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ifLibLut.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ifLibLut.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [FPGA mapping based on priority cuts.]
8 
9  Synopsis [LUT library.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 21, 2006.]
16 
17  Revision [$Id: ifLibLut.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "if.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static inline char * If_UtilStrsav( char *s ) { return !s ? s : strcpy(ABC_ALLOC(char, strlen(s)+1), s); }
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Reads the description of LUTs from the LUT library file.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 If_LibLut_t * If_LibLutRead( char * FileName )
48 {
49  char pBuffer[1000], * pToken;
50  If_LibLut_t * p;
51  FILE * pFile;
52  int i, k;
53 
54  pFile = fopen( FileName, "r" );
55  if ( pFile == NULL )
56  {
57  Abc_Print( -1, "Cannot open LUT library file \"%s\".\n", FileName );
58  return NULL;
59  }
60 
61  p = ABC_ALLOC( If_LibLut_t, 1 );
62  memset( p, 0, sizeof(If_LibLut_t) );
63  p->pName = If_UtilStrsav( FileName );
64 
65  i = 1;
66  while ( fgets( pBuffer, 1000, pFile ) != NULL )
67  {
68  pToken = strtok( pBuffer, " \t\n" );
69  if ( pToken == NULL )
70  continue;
71  if ( pToken[0] == '#' )
72  continue;
73  if ( i != atoi(pToken) )
74  {
75  Abc_Print( 1, "Error in the LUT library file \"%s\".\n", FileName );
76  ABC_FREE( p->pName );
77  ABC_FREE( p );
78  return NULL;
79  }
80 
81  // read area
82  pToken = strtok( NULL, " \t\n" );
83  p->pLutAreas[i] = (float)atof(pToken);
84 
85  // read delays
86  k = 0;
87  while ( (pToken = strtok( NULL, " \t\n" )) )
88  p->pLutDelays[i][k++] = (float)atof(pToken);
89 
90  // check for out-of-bound
91  if ( k > i )
92  {
93  ABC_FREE( p->pName );
94  ABC_FREE( p );
95  Abc_Print( 1, "LUT %d has too many pins (%d). Max allowed is %d.\n", i, k, i );
96  return NULL;
97  }
98 
99  // check if var delays are specified
100  if ( k > 1 )
101  p->fVarPinDelays = 1;
102 
103  if ( i == IF_MAX_LUTSIZE )
104  {
105  ABC_FREE( p->pName );
106  ABC_FREE( p );
107  Abc_Print( 1, "Skipping LUTs of size more than %d.\n", i );
108  return NULL;
109  }
110  i++;
111  }
112  p->LutMax = i-1;
113 
114  // check the library
115  if ( p->fVarPinDelays )
116  {
117  for ( i = 1; i <= p->LutMax; i++ )
118  for ( k = 0; k < i; k++ )
119  {
120  if ( p->pLutDelays[i][k] <= 0.0 )
121  Abc_Print( 0, "Pin %d of LUT %d has delay %f. Pin delays should be non-negative numbers. Technology mapping may not work correctly.\n",
122  k, i, p->pLutDelays[i][k] );
123  if ( k && p->pLutDelays[i][k-1] > p->pLutDelays[i][k] )
124  Abc_Print( 0, "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",
125  k-1, i, p->pLutDelays[i][k-1],
126  k, i, p->pLutDelays[i][k] );
127  }
128  }
129  else
130  {
131  for ( i = 1; i <= p->LutMax; i++ )
132  {
133  if ( p->pLutDelays[i][0] <= 0.0 )
134  Abc_Print( 0, "LUT %d has delay %f. Pin delays should be non-negative numbers. Technology mapping may not work correctly.\n",
135  i, p->pLutDelays[i][0] );
136  }
137  }
138 
139  return p;
140 }
141 
142 /**Function*************************************************************
143 
144  Synopsis [Duplicates the LUT library.]
145 
146  Description []
147 
148  SideEffects []
149 
150  SeeAlso []
151 
152 ***********************************************************************/
154 {
155  If_LibLut_t * pNew;
156  pNew = ABC_ALLOC( If_LibLut_t, 1 );
157  *pNew = *p;
158  pNew->pName = If_UtilStrsav( pNew->pName );
159  return pNew;
160 }
161 
162 /**Function*************************************************************
163 
164  Synopsis [Frees the LUT library.]
165 
166  Description []
167 
168  SideEffects []
169 
170  SeeAlso []
171 
172 ***********************************************************************/
173 void If_LibLutFree( If_LibLut_t * pLutLib )
174 {
175  if ( pLutLib == NULL )
176  return;
177  ABC_FREE( pLutLib->pName );
178  ABC_FREE( pLutLib );
179 }
180 
181 
182 /**Function*************************************************************
183 
184  Synopsis [Prints the LUT library.]
185 
186  Description []
187 
188  SideEffects []
189 
190  SeeAlso []
191 
192 ***********************************************************************/
193 void If_LibLutPrint( If_LibLut_t * pLutLib )
194 {
195  int i, k;
196  Abc_Print( 1, "# The area/delay of k-variable LUTs:\n" );
197  Abc_Print( 1, "# k area delay\n" );
198  if ( pLutLib->fVarPinDelays )
199  {
200  for ( i = 1; i <= pLutLib->LutMax; i++ )
201  {
202  Abc_Print( 1, "%d %7.2f ", i, pLutLib->pLutAreas[i] );
203  for ( k = 0; k < i; k++ )
204  Abc_Print( 1, " %7.2f", pLutLib->pLutDelays[i][k] );
205  Abc_Print( 1, "\n" );
206  }
207  }
208  else
209  for ( i = 1; i <= pLutLib->LutMax; i++ )
210  Abc_Print( 1, "%d %7.2f %7.2f\n", i, pLutLib->pLutAreas[i], pLutLib->pLutDelays[i][0] );
211 }
212 
213 /**Function*************************************************************
214 
215  Synopsis [Returns 1 if the delays are discrete.]
216 
217  Description []
218 
219  SideEffects []
220 
221  SeeAlso []
222 
223 ***********************************************************************/
225 {
226  float Delay;
227  int i;
228  for ( i = 1; i <= pLutLib->LutMax; i++ )
229  {
230  Delay = pLutLib->pLutDelays[i][0];
231  if ( ((float)((int)Delay)) != Delay )
232  return 0;
233  }
234  return 1;
235 }
236 
237 /**Function*************************************************************
238 
239  Synopsis [Returns 1 if the delays are discrete.]
240 
241  Description []
242 
243  SideEffects []
244 
245  SeeAlso []
246 
247 ***********************************************************************/
249 {
250  int i, k;
251  float Delay = pLutLib->pLutDelays[1][0];
252  if ( pLutLib->fVarPinDelays )
253  {
254  for ( i = 2; i <= pLutLib->LutMax; i++ )
255  for ( k = 0; k < i; k++ )
256  if ( pLutLib->pLutDelays[i][k] != Delay )
257  return 1;
258  }
259  else
260  {
261  for ( i = 2; i <= pLutLib->LutMax; i++ )
262  if ( pLutLib->pLutDelays[i][0] != Delay )
263  return 1;
264  }
265  return 0;
266 }
267 
268 /**Function*************************************************************
269 
270  Synopsis [Sets simple LUT library.]
271 
272  Description []
273 
274  SideEffects []
275 
276  SeeAlso []
277 
278 ***********************************************************************/
280 {
281  If_LibLut_t s_LutLib10= { "lutlib",10, 0, {0,1,1,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1},{1},{1}} };
282  If_LibLut_t s_LutLib9 = { "lutlib", 9, 0, {0,1,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1},{1}} };
283  If_LibLut_t s_LutLib8 = { "lutlib", 8, 0, {0,1,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1},{1}} };
284  If_LibLut_t s_LutLib7 = { "lutlib", 7, 0, {0,1,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1},{1}} };
285  If_LibLut_t s_LutLib6 = { "lutlib", 6, 0, {0,1,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1},{1}} };
286  If_LibLut_t s_LutLib5 = { "lutlib", 5, 0, {0,1,1,1,1,1}, {{0},{1},{1},{1},{1},{1}} };
287  If_LibLut_t s_LutLib4 = { "lutlib", 4, 0, {0,1,1,1,1}, {{0},{1},{1},{1},{1}} };
288  If_LibLut_t s_LutLib3 = { "lutlib", 3, 0, {0,1,1,1}, {{0},{1},{1},{1}} };
289  If_LibLut_t * pLutLib;
290  assert( nLutSize >= 3 && nLutSize <= 10 );
291  switch ( nLutSize )
292  {
293  case 3: pLutLib = &s_LutLib3; break;
294  case 4: pLutLib = &s_LutLib4; break;
295  case 5: pLutLib = &s_LutLib5; break;
296  case 6: pLutLib = &s_LutLib6; break;
297  case 7: pLutLib = &s_LutLib7; break;
298  case 8: pLutLib = &s_LutLib8; break;
299  case 9: pLutLib = &s_LutLib9; break;
300  case 10: pLutLib = &s_LutLib10; break;
301  default: pLutLib = NULL; break;
302  }
303  if ( pLutLib == NULL )
304  return NULL;
305  return If_LibLutDup(pLutLib);
306 }
307 
308 /**Function*************************************************************
309 
310  Synopsis [Gets the delay of the fastest pin.]
311 
312  Description []
313 
314  SideEffects []
315 
316  SeeAlso []
317 
318 ***********************************************************************/
320 {
321  return !p? 1.0 : p->pLutDelays[p->LutMax][0];
322 }
323 
324 /**Function*************************************************************
325 
326  Synopsis [Gets the delay of the slowest pin.]
327 
328  Description []
329 
330  SideEffects []
331 
332  SeeAlso []
333 
334 ***********************************************************************/
336 {
337  return !p? 1.0 : (p->fVarPinDelays? p->pLutDelays[p->LutMax][p->LutMax-1]: p->pLutDelays[p->LutMax][0]);
338 }
339 
340 ////////////////////////////////////////////////////////////////////////
341 /// END OF FILE ///
342 ////////////////////////////////////////////////////////////////////////
343 
344 
346 
char * memset()
float If_LibLutFastestPinDelay(If_LibLut_t *p)
Definition: ifLibLut.c:319
float If_LibLutSlowestPinDelay(If_LibLut_t *p)
Definition: ifLibLut.c:335
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void If_LibLutFree(If_LibLut_t *pLutLib)
Definition: ifLibLut.c:173
int LutMax
Definition: if.h:173
char * strtok()
float pLutDelays[IF_MAX_LUTSIZE+1][IF_MAX_LUTSIZE+1]
Definition: if.h:176
int If_LibLutDelaysAreDifferent(If_LibLut_t *pLutLib)
Definition: ifLibLut.c:248
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
If_LibLut_t * If_LibLutDup(If_LibLut_t *p)
Definition: ifLibLut.c:153
If_LibLut_t * If_LibLutRead(char *FileName)
FUNCTION DEFINITIONS ///.
Definition: ifLibLut.c:47
int fVarPinDelays
Definition: if.h:174
#define IF_MAX_LUTSIZE
INCLUDES ///.
Definition: if.h:52
If_LibLut_t * If_LibLutSetSimple(int nLutSize)
Definition: ifLibLut.c:279
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static void Abc_Print(int level, const char *format,...)
Definition: abc_global.h:313
char * strcpy()
double atof()
int If_LibLutDelaysAreDiscrete(If_LibLut_t *pLutLib)
Definition: ifLibLut.c:224
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define ABC_FREE(obj)
Definition: abc_global.h:232
float pLutAreas[IF_MAX_LUTSIZE+1]
Definition: if.h:175
char * pName
Definition: if.h:172
#define assert(ex)
Definition: util_old.h:213
int strlen()
static ABC_NAMESPACE_IMPL_START char * If_UtilStrsav(char *s)
DECLARATIONS ///.
Definition: ifLibLut.c:30
void If_LibLutPrint(If_LibLut_t *pLutLib)
Definition: ifLibLut.c:193