21#ifndef ABC__misc__util__abc_global_h
22#define ABC__misc__util__abc_global_h
34#define inline __inline
35#pragma warning(disable : 4152)
36#pragma warning(disable : 4200)
37#pragma warning(disable : 4244)
38#pragma warning(disable : 4514)
39#pragma warning(disable : 4710)
49 #define ABC_DLLEXPORT __declspec(dllexport)
50 #define ABC_DLLIMPORT __declspec(dllimport)
57#define ABC_DLL ABC_DLLIMPORT
60#if !defined(___unused)
62#define ___unused __attribute__ ((__unused__))
86 #define _CRTDBG_MAP_ALLOC
101#ifdef ABC_USE_STDINT_H
108#if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF
109#define SIZEOF_VOID_P 8
115#elif UINTPTR_MAX == 0xFFFFFFFF
116#define SIZEOF_VOID_P 4
123 #error unsupported platform
126#if ULONG_MAX == 0xFFFFFFFFFFFFFFFF
128#elif ULONG_MAX == 0xFFFFFFFF
131 #error unsupported platform
134#if UINT_MAX == 0xFFFFFFFFFFFFFFFF
136#elif UINT_MAX == 0xFFFFFFFF
139 #error unsupported platform
151#if defined(__ccdoc__)
152typedef platform_dependent_type ABC_PTRDIFF_T;
153#elif defined(ABC_USE_STDINT_H)
154typedef ptrdiff_t ABC_PTRDIFF_T;
156typedef long ABC_PTRDIFF_T;
158typedef long long ABC_PTRDIFF_T;
159#elif defined(NT) || defined(LIN) || defined(WIN32)
160typedef int ABC_PTRDIFF_T;
162 #error unknown platform
170#if defined(__ccdoc__)
171typedef platform_dependent_type ABC_PTRUINT_T;
172#elif defined(ABC_USE_STDINT_H)
173typedef uintptr_t ABC_PTRUINT_T;
175typedef unsigned long ABC_PTRUINT_T;
177typedef unsigned long long ABC_PTRUINT_T;
178#elif defined(NT) || defined(LIN) || defined(WIN32)
179typedef unsigned int ABC_PTRUINT_T;
181 #error unknown platform
189#if defined(__ccdoc__)
190typedef platform_dependent_type ABC_PTRINT_T;
191#elif defined(ABC_USE_STDINT_H)
194typedef long ABC_PTRINT_T;
196typedef long long ABC_PTRINT_T;
197#elif defined(NT) || defined(LIN) || defined(WIN32)
198typedef int ABC_PTRINT_T;
200 #error unknown platform
206#if defined(__ccdoc__)
207typedef platform_dependent_type ABC_INT64_T;
208#elif defined(ABC_USE_STDINT_H)
209typedef int64_t ABC_INT64_T;
211typedef long ABC_INT64_T;
212#elif defined(NT64) || defined(LIN)
213typedef long long ABC_INT64_T;
214#elif defined(WIN32) || defined(NT)
215typedef signed __int64 ABC_INT64_T;
217 #error unknown platform
223#if defined(__ccdoc__)
224typedef platform_dependent_type ABC_UINT64_T;
225#elif defined(ABC_USE_STDINT_H)
226typedef uint64_t ABC_UINT64_T;
228typedef unsigned long ABC_UINT64_T;
229#elif defined(NT64) || defined(LIN)
230typedef unsigned long long ABC_UINT64_T;
231#elif defined(WIN32) || defined(NT)
232typedef unsigned __int64 ABC_UINT64_T;
234 #error unknown platform
238 #define ABC_CONST(number) number ## ULL
240 #define ABC_CONST(number) number
250#define ABC_INFINITY (1000000000)
251#define ABC_INT_MAX (2147483647)
253#define ABC_SWAP(Type, a, b) { Type t = a; a = b; b = t; }
255#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)))
256#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)))
257#define ABC_PRTn(a,t) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%9.2f sec ", 1.0*((double)(t))/((double)CLOCKS_PER_SEC)))
258#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))
259#define ABC_PRM(a,f) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB\n", 1.0*((double)(f))/(1<<20)))
260#define ABC_PRMr(a,f) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB\r", 1.0*((double)(f))/(1<<20)))
261#define ABC_PRMn(a,f) (Abc_Print(1, "%s =", (a)), Abc_Print(1, "%10.3f MB ", 1.0*((double)(f))/(1<<20)))
262#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) ) )
264#define ABC_ALLOC(type, num) ((type *) malloc(sizeof(type) * (size_t)(num)))
265#define ABC_CALLOC(type, num) ((type *) calloc((size_t)(num), sizeof(type)))
266#define ABC_FALLOC(type, num) ((type *) memset(malloc(sizeof(type) * (size_t)(num)), 0xff, sizeof(type) * (size_t)(num)))
267#define ABC_FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
268#define ABC_REALLOC(type, obj, num) \
269 ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (size_t)(num))) : \
270 ((type *) malloc(sizeof(type) * (size_t)(num))))
272static inline int Abc_AbsInt(
int a ) {
return a < 0 ? -a : a; }
273static inline int Abc_MaxInt(
int a,
int b ) {
return a > b ? a : b; }
274static inline int Abc_MinInt(
int a,
int b ) {
return a < b ? a : b; }
275static inline word Abc_MaxWord(
word a,
word b ) {
return a > b ? a : b; }
276static inline word Abc_MinWord(
word a,
word b ) {
return a < b ? a : b; }
277static inline float Abc_AbsFloat(
float a ) {
return a < 0 ? -a : a; }
278static inline float Abc_MaxFloat(
float a,
float b ) {
return a > b ? a : b; }
279static inline float Abc_MinFloat(
float a,
float b ) {
return a < b ? a : b; }
280static inline double Abc_AbsDouble(
double a ) {
return a < 0 ? -a : a; }
281static inline double Abc_MaxDouble(
double a,
double b ) {
return a > b ? a : b; }
282static inline double Abc_MinDouble(
double a,
double b ) {
return a < b ? a : b; }
284static inline int Abc_Float2Int(
float Val ) {
union {
int x;
float y; } v; v.y = Val;
return v.x; }
285static inline float Abc_Int2Float(
int Num ) {
union {
int x;
float y; } v; v.x = Num;
return v.y; }
286static inline word Abc_Dbl2Word(
double Dbl ) {
union {
word x;
double y; } v; v.y = Dbl;
return v.x; }
287static inline double Abc_Word2Dbl(
word Num ) {
union {
word x;
double y; } v; v.x = Num;
return v.y; }
288static inline int Abc_Base2Log(
unsigned n ) {
int r;
if ( n < 2 )
return (
int)n;
for ( r = 0, n--; n; n >>= 1, r++ ) {};
return r; }
289static inline int Abc_Base10Log(
unsigned n ) {
int r;
if ( n < 2 )
return (
int)n;
for ( r = 0, n--; n; n /= 10, r++ ) {};
return r; }
290static inline int Abc_Base16Log(
unsigned n ) {
int r;
if ( n < 2 )
return (
int)n;
for ( r = 0, n--; n; n /= 16, r++ ) {};
return r; }
291static inline int Abc_Base2LogW(
word n ) {
int r;
if ( n < 2 )
return (
int)n;
for ( r = 0, n--; n; n >>= 1, r++ ) {};
return r; }
292static inline int Abc_Base10LogW(
word n ) {
int r;
if ( n < 2 )
return (
int)n;
for ( r = 0, n--; n; n /= 10, r++ ) {};
return r; }
293static inline int Abc_Base16LogW(
word n ) {
int r;
if ( n < 2 )
return (
int)n;
for ( r = 0, n--; n; n /= 16, r++ ) {};
return r; }
294static inline char * Abc_UtilStrsav(
char * s ) {
return s ?
strcpy(
ABC_ALLOC(
char,
strlen(s)+1), s) : NULL; }
295static inline char * Abc_UtilStrsavTwo(
char * s,
char * a ){
char * r;
if (!a)
return Abc_UtilStrsav(s); r =
ABC_ALLOC(
char,
strlen(s)+
strlen(a)+1);
sprintf(r,
"%s%s", s, a );
return r; }
296static inline char * Abc_UtilStrsavNum(
char * s,
int n ) {
char * r;
if (!s)
return NULL; r =
ABC_ALLOC(
char,
strlen(s)+12+1);
sprintf(r,
"%s%d", s, n );
return r; }
297static inline int Abc_BitByteNum(
int nBits ) {
return (nBits>>3) + ((nBits&7) > 0); }
298static inline int Abc_BitWordNum(
int nBits ) {
return (nBits>>5) + ((nBits&31) > 0); }
299static inline int Abc_Bit6WordNum(
int nBits ) {
return (nBits>>6) + ((nBits&63) > 0); }
300static inline int Abc_TruthByteNum(
int nVars ) {
return nVars <= 3 ? 1 : (1 << (nVars - 3)); }
301static inline int Abc_TruthWordNum(
int nVars ) {
return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
302static inline int Abc_Truth6WordNum(
int nVars ) {
return nVars <= 6 ? 1 : (1 << (nVars - 6)); }
303static inline int Abc_InfoHasBit(
unsigned *
p,
int i ) {
return (
p[(i)>>5] & (
unsigned)(1<<((i) & 31))) > 0; }
304static inline void Abc_InfoSetBit(
unsigned *
p,
int i ) {
p[(i)>>5] |= (
unsigned)(1<<((i) & 31)); }
305static inline void Abc_InfoXorBit(
unsigned *
p,
int i ) {
p[(i)>>5] ^= (
unsigned)(1<<((i) & 31)); }
306static inline unsigned Abc_InfoMask(
int nVar ) {
return (~(
unsigned)0) >> (32-nVar); }
308static inline int Abc_Var2Lit(
int Var,
int c ) {
assert(
Var >= 0 && !(c >> 1));
return Var +
Var + c; }
309static inline int Abc_Lit2Var(
int Lit ) {
assert(Lit >= 0);
return Lit >> 1; }
310static inline int Abc_LitIsCompl(
int Lit ) {
assert(Lit >= 0);
return Lit & 1; }
311static inline int Abc_LitNot(
int Lit ) {
assert(Lit >= 0);
return Lit ^ 1; }
312static inline int Abc_LitNotCond(
int Lit,
int c ) {
assert(Lit >= 0);
return Lit ^ (int)(c > 0); }
313static inline int Abc_LitRegular(
int Lit ) {
assert(Lit >= 0);
return Lit & ~01; }
314static inline int Abc_Lit2LitV(
int * pMap,
int Lit ) {
assert(Lit >= 0);
return Abc_Var2Lit( pMap[Abc_Lit2Var(Lit)], Abc_LitIsCompl(Lit) ); }
315static inline int Abc_Lit2LitL(
int * pMap,
int Lit ) {
assert(Lit >= 0);
return Abc_LitNotCond( pMap[Abc_Lit2Var(Lit)], Abc_LitIsCompl(Lit) ); }
317static inline int Abc_Ptr2Int(
void *
p ) {
return (
int)(ABC_PTRINT_T)
p; }
318static inline void * Abc_Int2Ptr(
int i ) {
return (
void *)(ABC_PTRINT_T)i; }
319static inline word Abc_Ptr2Wrd(
void *
p ) {
return (
word)(ABC_PTRUINT_T)
p; }
320static inline void * Abc_Wrd2Ptr(
word i ) {
return (
void *)(ABC_PTRUINT_T)i; }
322static inline int Abc_Var2Lit2(
int Var,
int Att ) {
assert(!(Att >> 2));
return (
Var << 2) + Att; }
323static inline int Abc_Lit2Var2(
int Lit ) {
assert(Lit >= 0);
return Lit >> 2; }
324static inline int Abc_Lit2Att2(
int Lit ) {
assert(Lit >= 0);
return Lit & 3; }
325static inline int Abc_Var2Lit3(
int Var,
int Att ) {
assert(!(Att >> 3));
return (
Var << 3) + Att; }
326static inline int Abc_Lit2Var3(
int Lit ) {
assert(Lit >= 0);
return Lit >> 3; }
327static inline int Abc_Lit2Att3(
int Lit ) {
assert(Lit >= 0);
return Lit & 7; }
328static inline int Abc_Var2Lit4(
int Var,
int Att ) {
assert(!(Att >> 4));
return (
Var << 4) + Att; }
329static inline int Abc_Lit2Var4(
int Lit ) {
assert(Lit >= 0);
return Lit >> 4; }
330static inline int Abc_Lit2Att4(
int Lit ) {
assert(Lit >= 0);
return Lit & 15; }
334static inline abctime Abc_Clock()
336#if defined(__APPLE__) && defined(__MACH__)
337 #define APPLE_MACH (__APPLE__ & __MACH__)
341#if (defined(LIN) || defined(LIN64)) && !APPLE_MACH && !defined(__MINGW32__) && !defined(__wasm)
343 if ( clock_gettime(CLOCK_MONOTONIC, &ts) < 0 )
346 res += (((
abctime) ts.tv_nsec) * CLOCKS_PER_SEC) / 1000000000;
353static inline abctime Abc_ThreadClock()
355#if defined(__APPLE__) && defined(__MACH__)
356 #define APPLE_MACH (__APPLE__ & __MACH__)
360#if (defined(LIN) || defined(LIN64)) && !APPLE_MACH && !defined(__MINGW32__) && !defined(__wasm)
362 if ( clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) < 0 )
365 res += (((
abctime) ts.tv_nsec) * CLOCKS_PER_SEC) / 1000000000;
386#define BRIDGE_NETLIST 106
387#define BRIDGE_ABS_NETLIST 107
392extern char *
vnsprintf(
const char* format, va_list args);
393extern char *
nsprintf(
const char* format, ...);
395static inline void Abc_Print(
int level,
const char * format, ... )
407 printf(
"Warning: " );
415 va_start( args, format );
429static inline void Abc_Print(
int level,
const char * format, ... )
432 va_start( args, format );
436 printf(
"Warning: " );
444static inline void Abc_PrintInt(
int i )
446 double v3 = (double)i/1000;
447 double v6 = (double)i/1000000;
451 if ( i > -1000 && i < 1000 )
452 Abc_Print( 1,
" %4d", i );
454 else if ( v3 > -9.995 && v3 < 9.995 )
455 Abc_Print( 1,
"%4.2fk", v3 );
456 else if ( v3 > -99.95 && v3 < 99.95 )
457 Abc_Print( 1,
"%4.1fk", v3 );
458 else if ( v3 > -999.5 && v3 < 999.5 )
459 Abc_Print( 1,
"%4.0fk", v3 );
461 else if ( v6 > -9.995 && v6 < 9.995 )
462 Abc_Print( 1,
"%4.2fm", v6 );
463 else if ( v6 > -99.95 && v6 < 99.95 )
464 Abc_Print( 1,
"%4.1fm", v6 );
465 else if ( v6 > -999.5 && v6 < 999.5 )
466 Abc_Print( 1,
"%4.0fm", v6 );
470static inline void Abc_PrintTime(
int level,
const char * pStr,
abctime time )
475static inline void Abc_PrintTimeP(
int level,
const char * pStr,
abctime time,
abctime Time )
480static inline void Abc_PrintMemoryP(
int level,
const char * pStr,
int mem,
int Mem )
486static inline int Abc_PrimeCudd(
unsigned int p )
496 while ((
unsigned) (i * i) <=
p)
498 if (
p % (
unsigned)i == 0) {
513static inline void * Abc_FileReadContents(
char * pFileName,
int * pnFileSize )
515 int RetValue, nFileSize;
517 FILE * pFile = fopen( pFileName,
"rb" );
522 nFileSize = ftell( pFile );
524 *pnFileSize = nFileSize;
527 pBuffer =
ABC_ALLOC(
char, nFileSize + 32 );
528 RetValue = fread( pBuffer, 1, nFileSize, pFile );
529 memset( pBuffer + nFileSize, 0, 32 );
530 assert( RetValue == nFileSize );
532 return (
void *)pBuffer;
534static inline void Abc_ReverseOrder(
int * pA,
int nA )
537 for ( i = 0; i < nA/2; i++ )
557extern void Util_ProcessThreads(
int (*pUserFunc)(
void *),
void * vData,
int nProcs,
int TimeOut,
int fVerbose );
word Abc_RandomW(int fReset)
#define ABC_SWAP(Type, a, b)
void Abc_QuickSortCostData(int *pCosts, int nSize, int fDecrease, word *pData, int *pResult)
void Abc_MergeSort(int *pInput, int nSize)
void Abc_MergeSortCost2(int *pInput, int nSize, int *pCost)
void Abc_QuickSort1(word *pData, int nSize, int fDecrease)
int * Abc_MergeSortCost(int *pCosts, int nSize)
char * vnsprintf(const char *format, va_list args)
void Abc_QuickSort2(word *pData, int nSize, int fDecrease)
int * Abc_QuickSortCost(int *pCosts, int nSize, int fDecrease)
#define ABC_ALLOC(type, num)
#define ABC_PRTP(a, t, T)
int Gia_ManToBridgeAbsNetlist(FILE *pFile, void *p, int pkg_type)
#define ABC_PRMP(a, f, F)
unsigned Abc_Random(int fReset)
int Gia_ManToBridgeText(FILE *pFile, int Size, unsigned char *pBuffer)
void Abc_QuickSort3(word *pData, int nSize, int fDecrease)
char * nsprintf(const char *format,...)
void Util_ProcessThreads(int(*pUserFunc)(void *), void *vData, int nProcs, int TimeOut, int fVerbose)
DECLARATIONS ///.
void Abc_MergeSortCost2Reverse(int *pInput, int nSize, int *pCost)
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
ABC_DLL int Abc_FrameIsBridgeMode()
unsigned __int64 word
DECLARATIONS ///.
unsigned enable_dbg_outs
FUNCTION DEFINITIONS ///.