1 /**CFile****************************************************************
2 
3   FileName    [abc_global.h]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Global declarations.]
8 
9   Synopsis    [Global declarations.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - Jan 30, 2009.]
16 
17   Revision    [$Id: abc_global.h,v 1.00 2009/01/30 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #ifndef ABC__misc__util__abc_global_h
22 #define ABC__misc__util__abc_global_h
23 
24 ////////////////////////////////////////////////////////////////////////
25 ///                          INCLUDES                                ///
26 ////////////////////////////////////////////////////////////////////////
27 
28 #ifndef ABC_USE_BRIDGE
29 #define ABC_USE_BRIDGE
30 #endif
31 
32 #ifdef _WIN32
33 #ifndef __MINGW32__
34 #define inline __inline // compatible with MS VS 6.0
35 #pragma warning(disable : 4152) // warning C4152: nonstandard extension, function/data pointer conversion in expression
36 #pragma warning(disable : 4200) // warning C4200: nonstandard extension used : zero-sized array in struct/union
37 #pragma warning(disable : 4244) // warning C4244: '+=' : conversion from 'int ' to 'unsigned short ', possible loss of data
38 #pragma warning(disable : 4514) // warning C4514: 'Vec_StrPop' : unreferenced inline function has been removed
39 #pragma warning(disable : 4710) // warning C4710: function 'Vec_PtrGrow' not inlined
40 //#pragma warning( disable : 4273 )
41 #endif
42 #endif
43 
44 #ifdef WIN32
45   #ifdef WIN32_NO_DLL
46     #define ABC_DLLEXPORT
47     #define ABC_DLLIMPORT
48   #else
49     #define ABC_DLLEXPORT __declspec(dllexport)
50     #define ABC_DLLIMPORT __declspec(dllimport)
51   #endif
52 #else  /* defined(WIN32) */
53 #define ABC_DLLIMPORT
54 #endif /* defined(WIN32) */
55 
56 #ifndef ABC_DLL
57 #define ABC_DLL ABC_DLLIMPORT
58 #endif
59 
60 #if !defined(___unused)
61 #if defined(__GNUC__)
62 #define ___unused __attribute__ ((__unused__))
63 #else
64 #define ___unused
65 #endif
66 #endif
67 
68 /*
69 #ifdef __cplusplus
70 #error "C++ code"
71 #else
72 #error "C code"
73 #endif
74 */
75 
76 #include <time.h>
77 #include <stdarg.h>
78 #include <stdlib.h>
79 #include <assert.h>
80 #include <stdio.h>
81 #include <string.h>
82 
83 // catch memory leaks in Visual Studio
84 #ifdef WIN32
85   #ifdef _DEBUG
86     #define _CRTDBG_MAP_ALLOC
87     #include <crtdbg.h>
88   #endif
89 #endif
90 
91 #include "abc_namespaces.h"
92 
93 ////////////////////////////////////////////////////////////////////////
94 ///                         PARAMETERS                               ///
95 ////////////////////////////////////////////////////////////////////////
96 
97 ABC_NAMESPACE_HEADER_START
98 
99 ////////////////////////////////////////////////////////////////////////
100 ///                         BASIC TYPES                              ///
101 ////////////////////////////////////////////////////////////////////////
102 
103 #ifdef ABC_USE_STDINT_H
104 
105 #ifndef __STDC_LIMIT_MACROS
106   #define __STDC_LIMIT_MACROS
107 #endif
108 
109 #ifndef __STDC_CONSTANT_MACROS
110   #define __STDC_CONSTANT_MACROS
111 #endif
112 
113 // If there is stdint.h, assume this is a reasonably-modern platform that
114 // would also have stddef.h and limits.h
115 #include <limits.h>
116 #include <stddef.h>
117 #include <stdint.h>
118 
119 #if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF
120 #define SIZEOF_VOID_P 8
121 #ifdef _WIN32
122 #define NT64
123 #else
124 #define LIN64
125 #endif
126 #elif UINTPTR_MAX == 0xFFFFFFFF
127 #define SIZEOF_VOID_P 4
128 #ifdef _WIN32
129 #define NT
130 #else
131 #define LIN
132 #endif
133 #else
134    #error unsupported platform
135 #endif
136 
137 #if ULONG_MAX == 0xFFFFFFFFFFFFFFFF
138 #define SIZEOF_LONG 8
139 #elif ULONG_MAX == 0xFFFFFFFF
140 #define SIZEOF_LONG 4
141 #else
142    #error unsupported platform
143 #endif
144 
145 #if UINT_MAX == 0xFFFFFFFFFFFFFFFF
146 #define SIZEOF_INT 8
147 #elif UINT_MAX == 0xFFFFFFFF
148 #define SIZEOF_INT 4
149 #else
150    #error unsupported platform
151 #endif
152 
153 #endif
154 
155 /**
156  * Pointer difference type; replacement for ptrdiff_t.
157  * This is a signed integral type that is the same size as a pointer.
158  * NOTE: This type may be different sizes on different platforms.
159  */
160 #if       defined(__ccdoc__)
161 typedef platform_dependent_type ABC_PTRDIFF_T;
162 #elif     defined(ABC_USE_STDINT_H)
163 typedef ptrdiff_t ABC_PTRDIFF_T;
164 #elif     defined(LIN64)
165 typedef long ABC_PTRDIFF_T;
166 #elif     defined(NT64)
167 typedef long long ABC_PTRDIFF_T;
168 #elif     defined(NT) || defined(LIN) || defined(WIN32)
169 typedef int ABC_PTRDIFF_T;
170 #else
171    #error unknown platform
172 #endif /* defined(PLATFORM) */
173 
174 /**
175  * Unsigned integral type that can contain a pointer.
176  * This is an unsigned integral type that is the same size as a pointer.
177  * NOTE: This type may be different sizes on different platforms.
178  */
179 #if       defined(__ccdoc__)
180 typedef platform_dependent_type ABC_PTRUINT_T;
181 #elif     defined(ABC_USE_STDINT_H)
182 typedef uintptr_t ABC_PTRUINT_T;
183 #elif     defined(LIN64)
184 typedef unsigned long ABC_PTRUINT_T;
185 #elif     defined(NT64)
186 typedef unsigned long long ABC_PTRUINT_T;
187 #elif     defined(NT) || defined(LIN) || defined(WIN32)
188 typedef unsigned int ABC_PTRUINT_T;
189 #else
190    #error unknown platform
191 #endif /* defined(PLATFORM) */
192 
193 /**
194  * Signed integral type that can contain a pointer.
195  * This is a signed integral type that is the same size as a pointer.
196  * NOTE: This type may be different sizes on different platforms.
197  */
198 #if       defined(__ccdoc__)
199 typedef platform_dependent_type ABC_PTRINT_T;
200 #elif     defined(ABC_USE_STDINT_H)
201 typedef intptr_t ABC_PTRINT_T;
202 #elif     defined(LIN64)
203 typedef long ABC_PTRINT_T;
204 #elif     defined(NT64)
205 typedef long long ABC_PTRINT_T;
206 #elif     defined(NT) || defined(LIN) || defined(WIN32)
207 typedef int ABC_PTRINT_T;
208 #else
209    #error unknown platform
210 #endif /* defined(PLATFORM) */
211 
212 /**
213  * 64-bit signed integral type.
214  */
215 #if       defined(__ccdoc__)
216 typedef platform_dependent_type ABC_INT64_T;
217 #elif     defined(ABC_USE_STDINT_H)
218 typedef int64_t ABC_INT64_T;
219 #elif     defined(LIN64)
220 typedef long ABC_INT64_T;
221 #elif     defined(NT64) || defined(LIN)
222 typedef long long ABC_INT64_T;
223 #elif     defined(WIN32) || defined(NT)
224 typedef signed __int64 ABC_INT64_T;
225 #else
226    #error unknown platform
227 #endif /* defined(PLATFORM) */
228 
229 /**
230  * 64-bit unsigned integral type.
231  */
232 #if       defined(__ccdoc__)
233 typedef platform_dependent_type ABC_UINT64_T;
234 #elif     defined(ABC_USE_STDINT_H)
235 typedef uint64_t ABC_UINT64_T;
236 #elif     defined(LIN64)
237 typedef unsigned long ABC_UINT64_T;
238 #elif     defined(NT64) || defined(LIN)
239 typedef unsigned long long ABC_UINT64_T;
240 #elif     defined(WIN32) || defined(NT)
241 typedef unsigned __int64 ABC_UINT64_T;
242 #else
243    #error unknown platform
244 #endif /* defined(PLATFORM) */
245 
246 #ifdef LIN
247   #define ABC_CONST(number) number ## ULL
248 #else // LIN64 and windows
249   #define ABC_CONST(number) number
250 #endif
251 
252 typedef ABC_UINT64_T word;
253 typedef ABC_INT64_T iword;
254 
255 ////////////////////////////////////////////////////////////////////////
256 ///                      MACRO DEFINITIONS                           ///
257 ////////////////////////////////////////////////////////////////////////
258 
259 #define ABC_INFINITY    (1000000000)
260 
261 #define ABC_SWAP(Type, a, b)  { Type t = a; a = b; b = t; }
262 
263 #define ABC_PRT(a,t)    (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec\n", 1.0*((double)(t))/((double)CLOCKS_PER_SEC)))
264 #define ABC_PRTr(a,t)   (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec\r", 1.0*((double)(t))/((double)CLOCKS_PER_SEC)))
265 #define ABC_PRTn(a,t)   (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec  ", 1.0*((double)(t))/((double)CLOCKS_PER_SEC)))
266 #define ABC_PRTP(a,t,T) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec (%6.2f %%)\n", 1.0*((double)(t))/((double)CLOCKS_PER_SEC), ((double)(T))? 100.0*((double)(t))/((double)(T)) : 0.0))
267 #define ABC_PRM(a,f)    (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB\n",    1.0*((double)(f))/(1<<20)))
268 #define ABC_PRMr(a,f)   (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB\r",    1.0*((double)(f))/(1<<20)))
269 #define ABC_PRMn(a,f)   (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB  ",    1.0*((double)(f))/(1<<20)))
270 #define ABC_PRMP(a,f,F) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB (%6.2f %%)\n",  (1.0*((double)(f))/(1<<20)), (((double)(F))? 100.0*((double)(f))/((double)(F)) : 0.0) ) )
271 
272 #define ABC_ALLOC(type, num)     ((type *) malloc(sizeof(type) * (size_t)(num)))
273 #define ABC_CALLOC(type, num)    ((type *) calloc((size_t)(num), sizeof(type)))
274 #define ABC_FALLOC(type, num)    ((type *) memset(malloc(sizeof(type) * (size_t)(num)), 0xff, sizeof(type) * (size_t)(num)))
275 #define ABC_FREE(obj)            ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
276 #define ABC_REALLOC(type, obj, num) \
277         ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (size_t)(num))) : \
278          ((type *) malloc(sizeof(type) * (size_t)(num))))
279 
Abc_AbsInt(int a)280 static inline int      Abc_AbsInt( int a        )             { return a < 0 ? -a : a; }
Abc_MaxInt(int a,int b)281 static inline int      Abc_MaxInt( int a, int b )             { return a > b ?  a : b; }
Abc_MinInt(int a,int b)282 static inline int      Abc_MinInt( int a, int b )             { return a < b ?  a : b; }
Abc_MaxWord(word a,word b)283 static inline word     Abc_MaxWord( word a, word b )          { return a > b ?  a : b; }
Abc_MinWord(word a,word b)284 static inline word     Abc_MinWord( word a, word b )          { return a < b ?  a : b; }
Abc_AbsFloat(float a)285 static inline float    Abc_AbsFloat( float a          )       { return a < 0 ? -a : a; }
Abc_MaxFloat(float a,float b)286 static inline float    Abc_MaxFloat( float a, float b )       { return a > b ?  a : b; }
Abc_MinFloat(float a,float b)287 static inline float    Abc_MinFloat( float a, float b )       { return a < b ?  a : b; }
Abc_AbsDouble(double a)288 static inline double   Abc_AbsDouble( double a           )    { return a < 0 ? -a : a; }
Abc_MaxDouble(double a,double b)289 static inline double   Abc_MaxDouble( double a, double b )    { return a > b ?  a : b; }
Abc_MinDouble(double a,double b)290 static inline double   Abc_MinDouble( double a, double b )    { return a < b ?  a : b; }
291 
Abc_Float2Int(float Val)292 static inline int      Abc_Float2Int( float Val )             { union { int x; float y; } v; v.y = Val; return v.x;         }
Abc_Int2Float(int Num)293 static inline float    Abc_Int2Float( int Num )               { union { int x; float y; } v; v.x = Num; return v.y;         }
Abc_Dbl2Word(double Dbl)294 static inline word     Abc_Dbl2Word( double Dbl )             { union { word x; double y; } v; v.y = Dbl; return v.x;       }
Abc_Word2Dbl(word Num)295 static inline double   Abc_Word2Dbl( word Num )               { union { word x; double y; } v; v.x = Num; return v.y;       }
Abc_Base2Log(unsigned n)296 static inline int      Abc_Base2Log( unsigned n )             { int r; if ( n < 2 ) return (int)n; for ( r = 0, n--; n; n >>= 1, r++ ) {}; return r; }
Abc_Base10Log(unsigned n)297 static inline int      Abc_Base10Log( unsigned n )            { int r; if ( n < 2 ) return (int)n; for ( r = 0, n--; n; n /= 10, r++ ) {}; return r; }
Abc_Base16Log(unsigned n)298 static inline int      Abc_Base16Log( unsigned n )            { int r; if ( n < 2 ) return (int)n; for ( r = 0, n--; n; n /= 16, r++ ) {}; return r; }
Abc_UtilStrsav(char * s)299 static inline char *   Abc_UtilStrsav( char * s )             { return s ? strcpy(ABC_ALLOC(char, strlen(s)+1), s) : NULL;  }
Abc_BitByteNum(int nBits)300 static inline int      Abc_BitByteNum( int nBits )            { return (nBits>>3) + ((nBits&7)  > 0);                       }
Abc_BitWordNum(int nBits)301 static inline int      Abc_BitWordNum( int nBits )            { return (nBits>>5) + ((nBits&31) > 0);                       }
Abc_Bit6WordNum(int nBits)302 static inline int      Abc_Bit6WordNum( int nBits )           { return (nBits>>6) + ((nBits&63) > 0);                       }
Abc_TruthByteNum(int nVars)303 static inline int      Abc_TruthByteNum( int nVars )          { return nVars <= 3 ? 1 : (1 << (nVars - 3));                 }
Abc_TruthWordNum(int nVars)304 static inline int      Abc_TruthWordNum( int nVars )          { return nVars <= 5 ? 1 : (1 << (nVars - 5));                 }
Abc_Truth6WordNum(int nVars)305 static inline int      Abc_Truth6WordNum( int nVars )         { return nVars <= 6 ? 1 : (1 << (nVars - 6));                 }
Abc_InfoHasBit(unsigned * p,int i)306 static inline int      Abc_InfoHasBit( unsigned * p, int i )  { return (p[(i)>>5] & (unsigned)(1<<((i) & 31))) > 0;         }
Abc_InfoSetBit(unsigned * p,int i)307 static inline void     Abc_InfoSetBit( unsigned * p, int i )  { p[(i)>>5] |= (unsigned)(1<<((i) & 31));                     }
Abc_InfoXorBit(unsigned * p,int i)308 static inline void     Abc_InfoXorBit( unsigned * p, int i )  { p[(i)>>5] ^= (unsigned)(1<<((i) & 31));                     }
Abc_InfoMask(int nVar)309 static inline unsigned Abc_InfoMask( int nVar )               { return (~(unsigned)0) >> (32-nVar);                         }
310 
Abc_Var2Lit(int Var,int c)311 static inline int      Abc_Var2Lit( int Var, int c )          { assert(Var >= 0 && !(c >> 1)); return Var + Var + c;        }
Abc_Lit2Var(int Lit)312 static inline int      Abc_Lit2Var( int Lit )                 { assert(Lit >= 0); return Lit >> 1;                          }
Abc_LitIsCompl(int Lit)313 static inline int      Abc_LitIsCompl( int Lit )              { assert(Lit >= 0); return Lit & 1;                           }
Abc_LitNot(int Lit)314 static inline int      Abc_LitNot( int Lit )                  { assert(Lit >= 0); return Lit ^ 1;                           }
Abc_LitNotCond(int Lit,int c)315 static inline int      Abc_LitNotCond( int Lit, int c )       { assert(Lit >= 0); return Lit ^ (int)(c > 0);                }
Abc_LitRegular(int Lit)316 static inline int      Abc_LitRegular( int Lit )              { assert(Lit >= 0); return Lit & ~01;                         }
Abc_Lit2LitV(int * pMap,int Lit)317 static inline int      Abc_Lit2LitV( int * pMap, int Lit )    { assert(Lit >= 0); return Abc_Var2Lit( pMap[Abc_Lit2Var(Lit)], Abc_LitIsCompl(Lit) );      }
Abc_Lit2LitL(int * pMap,int Lit)318 static inline int      Abc_Lit2LitL( int * pMap, int Lit )    { assert(Lit >= 0); return Abc_LitNotCond( pMap[Abc_Lit2Var(Lit)], Abc_LitIsCompl(Lit) );   }
319 
Abc_Ptr2Int(void * p)320 static inline int      Abc_Ptr2Int( void * p )                { return (int)(ABC_PTRINT_T)p;      }
Abc_Int2Ptr(int i)321 static inline void *   Abc_Int2Ptr( int i )                   { return (void *)(ABC_PTRINT_T)i;   }
Abc_Ptr2Wrd(void * p)322 static inline word     Abc_Ptr2Wrd( void * p )                { return (word)(ABC_PTRUINT_T)p;    }
Abc_Wrd2Ptr(word i)323 static inline void *   Abc_Wrd2Ptr( word i )                  { return (void *)(ABC_PTRUINT_T)i;  }
324 
Abc_Var2Lit2(int Var,int Att)325 static inline int      Abc_Var2Lit2( int Var, int Att )       { assert(!(Att >> 2)); return (Var << 2) + Att; }
Abc_Lit2Var2(int Lit)326 static inline int      Abc_Lit2Var2( int Lit )                { assert(Lit >= 0);    return Lit >> 2;         }
Abc_Lit2Att2(int Lit)327 static inline int      Abc_Lit2Att2( int Lit )                { assert(Lit >= 0);    return Lit & 3;          }
Abc_Var2Lit3(int Var,int Att)328 static inline int      Abc_Var2Lit3( int Var, int Att )       { assert(!(Att >> 3)); return (Var << 3) + Att; }
Abc_Lit2Var3(int Lit)329 static inline int      Abc_Lit2Var3( int Lit )                { assert(Lit >= 0);    return Lit >> 3;         }
Abc_Lit2Att3(int Lit)330 static inline int      Abc_Lit2Att3( int Lit )                { assert(Lit >= 0);    return Lit & 7;          }
Abc_Var2Lit4(int Var,int Att)331 static inline int      Abc_Var2Lit4( int Var, int Att )       { assert(!(Att >> 4)); return (Var << 4) + Att; }
Abc_Lit2Var4(int Lit)332 static inline int      Abc_Lit2Var4( int Lit )                { assert(Lit >= 0);    return Lit >> 4;         }
Abc_Lit2Att4(int Lit)333 static inline int      Abc_Lit2Att4( int Lit )                { assert(Lit >= 0);    return Lit & 15;         }
334 
335 // time counting
336 typedef ABC_INT64_T abctime;
Abc_Clock()337 static inline abctime Abc_Clock()
338 {
339 #if (defined(LIN) || defined(LIN64)) && !(__APPLE__ & __MACH__) && !defined(__MINGW32__)
340     struct timespec ts;
341     if ( clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) < 0 )
342         return (abctime)-1;
343     abctime res = ((abctime) ts.tv_sec) * CLOCKS_PER_SEC;
344     res += (((abctime) ts.tv_nsec) * CLOCKS_PER_SEC) / 1000000000;
345     return res;
346 #else
347     return (abctime) clock();
348 #endif
349 }
350 
351 
352 // misc printing procedures
353 enum Abc_VerbLevel
354 {
355     ABC_PROMPT   = -2,
356     ABC_ERROR    = -1,
357     ABC_WARNING  =  0,
358     ABC_STANDARD =  1,
359     ABC_VERBOSE  =  2
360 };
361 
362 
363 #ifdef ABC_USE_BRIDGE
364 
365 // bridge communication
366 #define BRIDGE_NETLIST           106
367 #define BRIDGE_ABS_NETLIST       107
368 extern int Gia_ManToBridgeText( FILE * pFile, int Size, unsigned char * pBuffer );
369 extern int Gia_ManToBridgeAbsNetlist( FILE * pFile, void * p, int pkg_type );
370 
371 // string printing
372 extern char * vnsprintf(const char* format, va_list args);
373 extern char * nsprintf(const char* format, ...);
374 
Abc_Print(int level,const char * format,...)375 static inline void Abc_Print( int level, const char * format, ... )
376 {
377     extern ABC_DLL int Abc_FrameIsBridgeMode();
378     va_list args;
379     extern unsigned enable_dbg_outs;
380     if ( !enable_dbg_outs )
381         return;
382 
383     if ( ! Abc_FrameIsBridgeMode() ){
384         if ( level == ABC_ERROR )
385             printf( "Error: " );
386         else if ( level == ABC_WARNING )
387             printf( "Warning: " );
388     }else{
389         if ( level == ABC_ERROR )
390             Gia_ManToBridgeText( stdout, (int)strlen("Error: "), (unsigned char*)"Error: " );
391         else if ( level == ABC_WARNING )
392             Gia_ManToBridgeText( stdout, (int)strlen("Warning: "), (unsigned char*)"Warning: " );
393     }
394 
395     va_start( args, format );
396     if ( Abc_FrameIsBridgeMode() )
397     {
398         char * tmp = vnsprintf( format, args );
399         Gia_ManToBridgeText( stdout, (int)strlen(tmp), (unsigned char*)tmp );
400         free( tmp );
401     }
402     else
403         vprintf( format, args );
404     va_end( args );
405 }
406 
407 #else
408 
Abc_Print(int level,const char * format,...)409 static inline void Abc_Print( int level, const char * format, ... )
410 {
411     va_list args;
412     va_start( args, format );
413     if ( level == ABC_ERROR )
414         printf( "Error: " );
415     else if ( level == ABC_WARNING )
416         printf( "Warning: " );
417     vprintf( format, args );
418     va_end( args );
419 }
420 
421 #endif
422 
423 
Abc_PrintInt(int i)424 static inline void Abc_PrintInt( int i )
425 {
426     double v3 = (double)i/1000;
427     double v6 = (double)i/1000000;
428 
429     Abc_Print( 1,  "  " );
430 
431     if ( i > -1000 && i < 1000 )
432         Abc_Print( 1, " %4d", i );
433 
434     else if ( v3 > -9.995 && v3 < 9.995 )
435         Abc_Print( 1, "%4.2fk", v3 );
436     else if ( v3 > -99.95 && v3 < 99.95 )
437         Abc_Print( 1, "%4.1fk", v3 );
438     else if ( v3 > -999.5 && v3 < 999.5 )
439         Abc_Print( 1, "%4.0fk", v3 );
440 
441     else if ( v6 > -9.995 && v6 < 9.995 )
442         Abc_Print( 1, "%4.2fm", v6 );
443     else if ( v6 > -99.95 && v6 < 99.95 )
444         Abc_Print( 1, "%4.1fm", v6 );
445     else if ( v6 > -999.5 && v6 < 999.5 )
446         Abc_Print( 1, "%4.0fm", v6 );
447 }
448 
449 
Abc_PrintTime(int level,const char * pStr,abctime time)450 static inline void Abc_PrintTime( int level, const char * pStr, abctime time )
451 {
452     ABC_PRT( pStr, time );
453 }
454 
Abc_PrintTimeP(int level,const char * pStr,abctime time,abctime Time)455 static inline void Abc_PrintTimeP( int level, const char * pStr, abctime time, abctime Time )
456 {
457     ABC_PRTP( pStr, time, Time );
458 }
459 
Abc_PrintMemoryP(int level,const char * pStr,int mem,int Mem)460 static inline void Abc_PrintMemoryP( int level, const char * pStr, int mem, int Mem )
461 {
462     ABC_PRMP( pStr, mem, Mem );
463 }
464 
465 // Returns the next prime >= p
Abc_PrimeCudd(unsigned int p)466 static inline int Abc_PrimeCudd( unsigned int p )
467 {
468     int i,pn;
469     p--;
470     do {
471         p++;
472         if (p&1)
473         {
474             pn = 1;
475             i = 3;
476             while ((unsigned) (i * i) <= p)
477             {
478                 if (p % (unsigned)i == 0) {
479                     pn = 0;
480                     break;
481                 }
482                 i += 2;
483             }
484         }
485         else
486             pn = 0;
487     } while (!pn);
488     return (int)(p);
489 
490 } // end of Cudd_Prime
491 
492 // the returned buffer has 32 unused bytes at the end, filled with zeros
Abc_FileReadContents(char * pFileName,int * pnFileSize)493 static inline void * Abc_FileReadContents( char * pFileName, int * pnFileSize )
494 {
495     int RetValue, nFileSize;
496     char * pBuffer;
497     FILE * pFile = fopen( pFileName, "rb" );
498     if ( pFile == NULL )
499         return NULL;
500     // get the file size, in bytes
501     fseek( pFile, 0, SEEK_END );
502     nFileSize = ftell( pFile );
503     if ( pnFileSize )
504         *pnFileSize = nFileSize;
505     rewind( pFile );
506     // load the contents of the file into memory
507     pBuffer = ABC_ALLOC( char, nFileSize + 32 );
508     RetValue = fread( pBuffer, 1, nFileSize, pFile );
509     memset( pBuffer + nFileSize, 0, 32 );
510     assert( RetValue == nFileSize );
511     fclose( pFile );
512     return (void *)pBuffer;
513 }
514 
515 
516 // sorting
517 extern void   Abc_MergeSort( int * pInput, int nSize );
518 extern int *  Abc_MergeSortCost( int * pCosts, int nSize );
519 extern void   Abc_QuickSort1( word * pData, int nSize, int fDecrease );
520 extern void   Abc_QuickSort2( word * pData, int nSize, int fDecrease );
521 extern void   Abc_QuickSort3( word * pData, int nSize, int fDecrease );
522 extern void   Abc_QuickSortCostData( int * pCosts, int nSize, int fDecrease, word * pData, int * pResult );
523 extern int *  Abc_QuickSortCost( int * pCosts, int nSize, int fDecrease );
524 
525 extern unsigned Abc_Random( int fReset );
526 extern word     Abc_RandomW( int fReset );
527 
528 ABC_NAMESPACE_HEADER_END
529 
530 #endif
531 
532 ////////////////////////////////////////////////////////////////////////
533 ///                       END OF FILE                                ///
534 ////////////////////////////////////////////////////////////////////////
535