1 /*
2  * This file was written by Bill Cox, originally in 1991, and maintained since.  It is hereby
3  * placed into the public domain.
4  */
5 
6 /*============================================================================
7    Module : Type Definitions
8    Purpose: Provide basic types used to build all objects.  These typedefs
9             clarify what we mean when we use an integer type, and make the
10             code more portable.
11 ============================================================================*/
12 
13 #ifndef UTTYPES_H
14 #define UTTYPES_H
15 
16 #if defined(_WIN32)
17 #define true 1
18 #define false 0
19 typedef unsigned char bool;
20 #else
21 /* Standard boolean type */
22 #include <stdbool.h>
23 #endif
24 
25 #if !defined(__GNUC__) && defined(_WIN32)
26 #if (_MSC_VER < 1310)
27 typedef unsigned __int64 uint64; /* VC6: Unsigned 64 bits */
28 #else
29 typedef unsigned long long uint64; /* Unsigned 64 bits */
30 #endif
31 typedef unsigned long uint32;    /* Unsigned >= 32 bits */
32 typedef unsigned long uint;      /* Unsigned >= 32 bits */
33 typedef unsigned short uint16;   /* Unsigned >= 16 bits */
34 typedef unsigned char uint8;     /* Unsigned >= 8 bits */
35 #if (_MSC_VER < 1310)
36 typedef signed __int64 int64;    /* VC6: Signed 64 bits */
37 #else
38 typedef signed long long int64;  /* Signed 64 bits */
39 #endif
40 typedef signed long int32;       /* Signed >= 32 bits */
41 typedef signed short int16;      /* Signed >= 16 bits */
42 typedef signed char int8;        /* Signed >= 8 bits */
43 #define UINT64_MAX 0xffffffff
44 #define INT64_MAX ((int32)0x7fffffff)
45 
46 /* Some compatibility wrappers */
47 #define strcasecmp stricmp
48 
49 #else
50 /* These cause -Wall to report warnings with %llu/%lld parameters - Bill
51 #include <sys/types.h>
52 typedef __uint8_t  uint8;
53 typedef __uint16_t uint16;
54 typedef __uint32_t uint32;
55 typedef __uint64_t uint64;
56 typedef  __int8_t   int8;
57 typedef  __int16_t  int16;
58 typedef  __int32_t  int32;
59 typedef  __int64_t  int64;
60 */
61 /* long long is C99... hopefully M$ will support it */
62 typedef unsigned long long uint64; /* Unsigned >= 64 bits */
63 typedef unsigned int uint32;       /* Unsigned >= 32 bits */
64 typedef unsigned short uint16;     /* Unsigned >= 16 bits */
65 typedef unsigned char uint8;       /* Unsigned >= 8 bits */
66 typedef signed long long int64;    /* Signed >= 64 bits */
67 typedef signed int int32;          /* Signed >= 32 bits */
68 typedef signed short int16;        /* Signed >= 16 bits */
69 typedef signed char int8;        /* Signed >= 8 bits */
70 
71 #endif
72 
73 #ifndef UINT64_MAX
74 #define UINT64_MAX ((uint64)0xffffffffffffffffLL)
75 #endif
76 #ifndef UINT32_MAX
77 #define UINT32_MAX ((uint32)0xffffffff)
78 #endif
79 #ifndef UINT16_MAX
80 #define UINT16_MAX ((uint16)0xffff)
81 #endif
82 #ifndef UINT8_MAX
83 #define UINT8_MAX ((uint8)0xff)
84 #endif
85 #ifndef INT64_MAX
86 #define INT64_MAX ((int64)0x7fffffffffffffffLL)
87 #endif
88 #ifndef INT32_MAX
89 #define INT32_MAX ((int32)0x7fffffff)
90 #endif
91 #ifndef INT16_MAX
92 #define INT16_MAX ((int16)0x7fff)
93 #endif
94 #ifndef INT8_MAX
95 #define INT8_MAX ((int8)0x7f)
96 #endif
97 #ifndef INT64_MIN
98 #define INT64_MIN ((int64)(-1 - INT64_MAX))
99 #endif
100 #ifndef INT32_MIN
101 #define INT32_MIN ((int32)(-1 - INT32_MAX))
102 #endif
103 #ifndef INT16_MIN
104 #define INT16_MIN ((int16)(-1 - INT16_MAX))
105 #endif
106 #ifndef INT8_MIN
107 #define INT8_MIN ((int8)(-1 - INT8_MAX))
108 #endif
109 #ifndef DOUBLE_MAX
110 #define DOUBLE_MAX ((double)1.7e308)
111 #endif
112 
113 #if (defined(_WINDOWS) || defined(_WIN32)) && !defined(__GNUC__)
114 #define UTDIRSEP '\\'
115 #define UTDIRSEP_STRING "\\"
116 #define UTPATHSEP ';'
117 #else
118 #define UTDIRSEP '/'
119 #define UTDIRSEP_STRING "/"
120 #define UTPATHSEP ':'
121 #endif
122 
123 /*--------------------------------------------------------------------------------------------------
124   Compiler optimization hints          example: if(utUnlikely(error)) {utExit("err");}
125 --------------------------------------------------------------------------------------------------*/
126 
127 #if defined(__GNUC__) && __GNUC__ > 3
128 #define utLikely(x)          __builtin_expect((x),1)    /* assumes gcc version >= 3.0 */
129 #define utUnlikely(x)        __builtin_expect((x),0)
130 #define utExpected(x,y)      __builtin_expect((x),(y))
131 /* Prefetch doesn't fault if addr is invalid. We don't use temporal locality parameter */
132 #define utPrefetchRead(x)    __builtin_prefetch((x), 0)
133 #define utPrefetchWrite(x)   __builtin_prefetch((x), 1)
134 /* also add markers for functions that never return (exit, error) using __attribute__ */
135 #else
136 #define utLikely(x)          (x)               /* unknown if ms c compiler supports this */
137 #define utUnlikely(x)        (x)
138 #define utExpected(x,y)      (x)
139 #define utPrefetchRead(x)    (x)
140 #define utPrefetchWrite(x)   (x)
141 #endif
142 #define utPrefetch(x)        utPrefetchRead(x)
143 
144 /*--------------------------------------------------------------------------------------------------
145   handy macros
146 --------------------------------------------------------------------------------------------------*/
147 #define utMin(x, y) ((x) <= (y)? (x) : (y))
148 #define utMax(x, y) ((x) >= (y)? (x) : (y))
149 #define utAbs(x) ((x) >= 0? (x) : -(x))
150 #define utUint32ToVoidp(x) ((void *)((uint32)(x) + (char *)NULL))
151 #define utVoidpToUint32(x) (uint32)((char *)x - (char *)NULL)
152 
153 /* This loop structure allows loop initialization code to be written
154    once (between utDo and utWhile), rather than having to be duplicated */
155 #define utDo do {
156 #define utWhile(cond) if(utUnlikely(!(cond))) break;
157 #define utRepeat } while(true);
158 
159 #endif
160 
161