[go: up one dir, main page]

Menu

[9c90d7]: / util / uttypes.h  Maximize  Restore  History

Download this file

171 lines (154 with data), 5.6 kB

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