156
158
#define __builtin_expect(x, expected_value) (x)
159
#define likely(x) __builtin_expect((x),1)
160
#define unlikely(x) __builtin_expect((x),0)
162
The semantics of builtin_expect() are that
163
1) its two arguments are long
164
2) it's likely that they are ==
165
Those of our likely(x) are that x can be bool/int/longlong/pointer.
167
#define likely(x) __builtin_expect(((x) != 0),1)
168
#define unlikely(x) __builtin_expect(((x) != 0),0)
164
171
The macros below are useful in optimising places where it has been
538
549
#define DONT_REMEMBER_SIGNAL
541
/* Define void to stop lint from generating "null effekt" comments */
542
#ifndef DONT_DEFINE_VOID
545
#define VOID(X) (__void__ = (int) (X))
550
#endif /* DONT_DEFINE_VOID */
552
552
#if defined(_lint) || defined(FORCE_INIT_OF_VARS)
553
553
#define LINT_INIT(var) var=0 /* No uninitialize-warning */
571
571
#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
572
572
#define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
573
#define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
573
#define swap_variables(t, a, b) { t swap_dummy; swap_dummy= a; a= b; b= swap_dummy; }
574
574
#define test(a) ((a) ? 1 : 0)
575
575
#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
576
576
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
577
577
#define test_all_bits(a,b) (((a) & (b)) == (b))
578
578
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
579
579
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
580
581
#ifndef HAVE_RINT
581
#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
583
All integers up to this number can be represented exactly as double precision
584
values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
586
#define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
589
rint(3) implementation for platforms that do not have it.
590
Always rounds to the nearest integer with ties being rounded to the nearest
591
even integer to mimic glibc's rint() behavior in the "round-to-nearest"
592
FPU mode. Hardware-specific optimizations are possible (frndint on x86).
593
Unlike this implementation, hardware will also honor the FPU rounding mode.
596
static inline double rint(double x)
602
All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
606
i += (double) ((f > 0.5) || (f == 0.5 &&
607
i <= (double) MAX_EXACT_INTEGER &&
610
i -= (double) ((f < -0.5) || (f == -0.5 &&
611
i >= (double) -MAX_EXACT_INTEGER &&
615
#endif /* HAVE_RINT */
584
617
/* Define some general constants */
924
958
#define my_offsetof(TYPE, MEMBER) \
925
959
((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
927
#define NullS (char *) 0
961
#define NullS STATIC_CAST(char *)(0)
928
962
/* Nowdays we do not support MessyDos */
930
964
#define NEAR /* Who needs segments ? */
1069
1104
typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */
1070
1105
typedef short int15; /* Most effective integer 0 <= x <= 32767 */
1071
1106
typedef int myf; /* Type of MyFlags in my_funcs */
1072
typedef char my_bool; /* Small bool */
1073
1107
#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
1074
1108
typedef char bool; /* Ordinary boolean values 0 1 */
1133
1167
#define SCALE_SEC 100
1134
1168
#define SCALE_USEC 10000
1135
1169
#define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
1136
#define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
1170
#define MY_HOW_OFTEN_TO_WRITE 10000 /* How often we want info on screen */
1141
1173
Define-funktions for reading and storing in machine independent format
1145
1177
/* Optimized store functions for Intel x86 */
1146
1178
#if defined(__i386__) || defined(_WIN32)
1147
#define sint2korr(A) (*((int16 *) (A)))
1179
#define sint2korr(A) (*((const int16 *) (A)))
1148
1180
#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
1149
1181
(((uint32) 255L << 24) | \
1150
1182
(((uint32) (uchar) (A)[2]) << 16) |\
1153
1185
(((uint32) (uchar) (A)[2]) << 16) |\
1154
1186
(((uint32) (uchar) (A)[1]) << 8) | \
1155
1187
((uint32) (uchar) (A)[0])))
1156
#define sint4korr(A) (*((long *) (A)))
1157
#define uint2korr(A) (*((uint16 *) (A)))
1188
#define sint4korr(A) (*((const long *) (A)))
1189
#define uint2korr(A) (*((const uint16 *) (A)))
1158
1190
#if defined(HAVE_purify) && !defined(_WIN32)
1159
1191
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
1160
1192
(((uint32) ((uchar) (A)[1])) << 8) +\
1166
1198
Please, note, uint3korr reads 4 bytes (not 3) !
1167
1199
It means, that you have to provide enough allocated space !
1169
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
1201
#define uint3korr(A) (long) (*((const unsigned int *) (A)) & 0xFFFFFF)
1170
1202
#endif /* HAVE_purify && !_WIN32 */
1171
#define uint4korr(A) (*((uint32 *) (A)))
1203
#define uint4korr(A) (*((const uint32 *) (A)))
1172
1204
#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
1173
1205
(((uint32) ((uchar) (A)[1])) << 8) +\
1174
1206
(((uint32) ((uchar) (A)[2])) << 16) +\
1180
1212
(((uint32) ((uchar) (A)[3])) << 24)) + \
1181
1213
(((ulonglong) ((uchar) (A)[4])) << 32) + \
1182
1214
(((ulonglong) ((uchar) (A)[5])) << 40))
1183
#define uint8korr(A) (*((ulonglong *) (A)))
1184
#define sint8korr(A) (*((longlong *) (A)))
1215
#define uint8korr(A) (*((const ulonglong *) (A)))
1216
#define sint8korr(A) (*((const longlong *) (A)))
1185
1217
#define int2store(T,A) *((uint16*) (T))= (uint16) (A)
1186
1218
#define int3store(T,A) do { *(T)= (uchar) ((A));\
1187
1219
*(T+1)=(uchar) (((uint) (A) >> 8));\
1206
1238
} doubleget_union;
1207
1239
#define doubleget(V,M) \
1208
1240
do { doubleget_union _tmp; \
1209
_tmp.m[0] = *((long*)(M)); \
1210
_tmp.m[1] = *(((long*) (M))+1); \
1241
_tmp.m[0] = *((const long*)(M)); \
1242
_tmp.m[1] = *(((const long*) (M))+1); \
1211
1243
(V) = _tmp.v; } while(0)
1212
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
1213
*(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
1244
#define doublestore(T,V) do { *((long *) T) = ((const doubleget_union *)&V)->m[0]; \
1245
*(((long *) T)+1) = ((const doubleget_union *)&V)->m[1]; \
1215
#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
1247
#define float4get(V,M) do { *((float *) &(V)) = *((const float*) (M)); } while(0)
1216
1248
#define float8get(V,M) doubleget((V),(M))
1217
#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
1218
#define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V),sizeof(float))
1219
#define floatget(V,M) memcpy((uchar*) &V,(uchar*) (M),sizeof(float))
1249
#define float4store(V,M) memcpy((uchar*) V,(const uchar*) (&M),sizeof(float))
1250
#define floatstore(T,V) memcpy((uchar*)(T), (const uchar*)(&V),sizeof(float))
1251
#define floatget(V,M) memcpy((uchar*) &V,(const uchar*) (M),sizeof(float))
1220
1252
#define float8store(V,M) doublestore((V),(M))
1509
1542
#if !defined(max)
1510
1543
#define max(a, b) ((a) > (b) ? (a) : (b))
1511
1544
#define min(a, b) ((a) < (b) ? (a) : (b))
1547
Only Linux is known to need an explicit sync of the directory to make sure a
1548
file creation/deletion/renaming in(from,to) this directory durable.
1550
#ifdef TARGET_OS_LINUX
1551
#define NEED_EXPLICIT_SYNC_DIR 1
1514
1554
#if !defined(__cplusplus) && !defined(bool)
1515
1555
#define bool In_C_you_should_use_my_bool_instead()
1558
/* Provide __func__ macro definition for platforms that miss it. */
1559
#if __STDC_VERSION__ < 199901L
1561
# define __func__ __FUNCTION__
1563
# define __func__ "<unknown>"
1565
#elif defined(_MSC_VER)
1566
# if _MSC_VER < 1300
1567
# define __func__ "<unknown>"
1569
# define __func__ __FUNCTION__
1571
#elif defined(__BORLANDC__)
1572
# define __func__ __FUNC__
1574
# define __func__ "<unknown>"
1518
1577
#endif /* my_global_h */