| 1 |
/** @file host.h |
| 2 |
** @brief Host |
| 3 |
** @author Andrea Vedaldi |
| 4 |
** @sa @ref portability |
| 5 |
**/ |
| 6 |
|
| 7 |
/* |
| 8 |
Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. |
| 9 |
All rights reserved. |
| 10 |
|
| 11 |
This file is part of the VLFeat library and is made available under |
| 12 |
the terms of the BSD license (see the COPYING file). |
| 13 |
*/ |
| 14 |
|
| 15 |
#ifndef VL_HOST_H |
| 16 |
#define VL_HOST_H |
| 17 |
|
| 18 |
/** ------------------------------------------------------------------ |
| 19 |
** @name Configuration options |
| 20 |
** @{ */ |
| 21 |
|
| 22 |
#if defined(__DOXYGEN__) |
| 23 |
#define VL_DISABLE_THREADS |
| 24 |
#define VL_DISABLE_SSE2 |
| 25 |
#define VL_DISABLE_OPENMP |
| 26 |
#endif |
| 27 |
|
| 28 |
/** @} */ |
| 29 |
|
| 30 |
/** ------------------------------------------------------------------ |
| 31 |
** @name Defining functions |
| 32 |
** @{ */ |
| 33 |
|
| 34 |
#if defined(__DOXYGEN__) |
| 35 |
#define VL_EXPORT |
| 36 |
#define VL_INLINE |
| 37 |
#endif |
| 38 |
|
| 39 |
/** @} */ |
| 40 |
|
| 41 |
/** ------------------------------------------------------------------ |
| 42 |
** @name C preprocessor helper macros |
| 43 |
** @{ */ |
| 44 |
|
| 45 |
/** @brief Convert the argument to a string |
| 46 |
** @param x value to be stringified. |
| 47 |
** |
| 48 |
** This macro stringifies the argument @a x by means of the |
| 49 |
** <code>#</code> prerpocessor operator. |
| 50 |
** |
| 51 |
** The standard C preprocessor does not prescan arguments which are |
| 52 |
** stringified, so |
| 53 |
** |
| 54 |
** @code |
| 55 |
** #define A B |
| 56 |
** char const * str = VL_STRINGIFY(A) ; |
| 57 |
** @endcode |
| 58 |
** |
| 59 |
** initializes <code>str</code> with a pointer to the string |
| 60 |
** <code>"A"</code>, which mihgt be unexpected. To fix this issue, |
| 61 |
** you can use ::VL_XSTRINGIFY. |
| 62 |
** |
| 63 |
** @sa ::VL_XSTRINGIFY |
| 64 |
**/ |
| 65 |
|
| 66 |
#define VL_STRINGIFY(x) # x |
| 67 |
|
| 68 |
/** @brief Expand and then convert the argument to a string |
| 69 |
** @param x value to be macro-expanded and converted. |
| 70 |
** |
| 71 |
** This macro macro-expands the argument @a x and stringifies the |
| 72 |
** result of the expansion. For instance |
| 73 |
** |
| 74 |
** @code |
| 75 |
** #define A B |
| 76 |
** char const * str = VL_STRINGIFY(A) ; |
| 77 |
** @endcode |
| 78 |
** |
| 79 |
** initializes <code>str</code> with a pointer to the string |
| 80 |
** <code>"B"</code>. |
| 81 |
** |
| 82 |
** @sa ::VL_STRINGIFY |
| 83 |
**/ |
| 84 |
|
| 85 |
#define VL_XSTRINGIFY(x) VL_STRINGIFY(x) |
| 86 |
|
| 87 |
/** @brief Concatenate two arguments into a lexical unit |
| 88 |
** @param x first argument to be concatenated. |
| 89 |
** @param y second argument to be concatenated. |
| 90 |
** |
| 91 |
** This macro concatenates its arguments into a single lexical unit |
| 92 |
** by means of the <code>##</code> preprocessor operator. Notice that |
| 93 |
** arguments concatenated by <code>##</code> are not pre-expanded by |
| 94 |
** the C preprocessor. To macro-expand the arguments and then |
| 95 |
** concatenate them,use ::VL_XCAT. |
| 96 |
** |
| 97 |
** @see ::VL_XCAT |
| 98 |
**/ |
| 99 |
|
| 100 |
#define VL_CAT(x,y) x ## y |
| 101 |
|
| 102 |
/** @brief Expand and then concatenate two arguments into a lexical unit |
| 103 |
** @param x first argument to be concatenated. |
| 104 |
** @param y second argument to be concatenated. |
| 105 |
** |
| 106 |
** This macro is the same as ::VL_CAT, except that the arguments are |
| 107 |
** macro expanded before being concatenated. |
| 108 |
** |
| 109 |
** @see ::VL_CAT |
| 110 |
**/ |
| 111 |
|
| 112 |
#define VL_XCAT(x,y) VL_CAT(x,y) |
| 113 |
|
| 114 |
/** @brief Expand and then concatenate three arguments into a lexical unit |
| 115 |
** @param x first argument to be concatenated. |
| 116 |
** @param y second argument to be concatenated. |
| 117 |
** @param z third argument to be concatenated. |
| 118 |
** |
| 119 |
** This macro is the same as ::VL_XCAT, except that it has three arguments. |
| 120 |
** |
| 121 |
** @see ::VL_XCAT |
| 122 |
**/ |
| 123 |
|
| 124 |
#define VL_XCAT3(x,y,z) VL_XCAT(VL_XCAT(x,y),z) |
| 125 |
|
| 126 |
/** @brief Expand and then concatenate four arguments into a lexical unit |
| 127 |
** @param x first argument to be concatenated. |
| 128 |
** @param y second argument to be concatenated. |
| 129 |
** @param z third argument to be concatenated. |
| 130 |
** @param u fourth argument to be concatenated. |
| 131 |
** |
| 132 |
** This macro is the same as ::VL_XCAT, except that it has four arguments. |
| 133 |
** |
| 134 |
** @see ::VL_XCAT |
| 135 |
**/ |
| 136 |
|
| 137 |
#define VL_XCAT4(x,y,z,u) VL_XCAT(VL_XCAT3(x,y,z),u) |
| 138 |
|
| 139 |
/** @brief Expand and then concatenate five arguments into a lexical unit |
| 140 |
** @param x first argument to be concatenated. |
| 141 |
** @param y second argument to be concatenated. |
| 142 |
** @param z third argument to be concatenated. |
| 143 |
** @param u fourth argument to be concatenated. |
| 144 |
** @param v fifth argument to be concatenated. |
| 145 |
** |
| 146 |
** This macro is the same as ::VL_XCAT, except that it has five arguments. |
| 147 |
** |
| 148 |
** @see ::VL_XCAT |
| 149 |
**/ |
| 150 |
|
| 151 |
#define VL_XCAT5(x,y,z,u,v) VL_XCAT(VL_XCAT4(x,y,z,u),v) |
| 152 |
|
| 153 |
/** @brief Convert a boolean to "yes" or "no" strings |
| 154 |
** @param x boolean to convert. |
| 155 |
** |
| 156 |
** A pointer to either the string "yes" (if @a x is true) |
| 157 |
** or the string "no". |
| 158 |
** |
| 159 |
** @par Example |
| 160 |
** @code |
| 161 |
** VL_PRINTF("Is x true? %s.", VL_YESNO(x)) |
| 162 |
** @endcode |
| 163 |
**/ |
| 164 |
|
| 165 |
#define VL_YESNO(x) ((x)?"yes":"no") |
| 166 |
|
| 167 |
/** @} */ |
| 168 |
|
| 169 |
/* |
| 170 |
The following macros identify the host OS, architecture and compiler. |
| 171 |
They are derived from http://predef.sourceforge.net/ |
| 172 |
*/ |
| 173 |
|
| 174 |
/** @name Identifying the host operating system |
| 175 |
** @{ */ |
| 176 |
#if defined(linux) || \ |
| 177 |
defined(__linux) || \ |
| 178 |
defined(__linux__) || \ |
| 179 |
defined(__DOXYGEN__) |
| 180 |
#define VL_OS_LINUX 1 |
| 181 |
#endif |
| 182 |
|
| 183 |
#if (defined(__APPLE__) & defined(__MACH__)) || \ |
| 184 |
defined(__DOXYGEN__) |
| 185 |
#define VL_OS_MACOSX 1 |
| 186 |
#endif |
| 187 |
|
| 188 |
#if defined(__WIN32__) || \ |
| 189 |
defined(_WIN32) || \ |
| 190 |
defined(__DOXYGEN__) |
| 191 |
#define VL_OS_WIN 1 |
| 192 |
#endif |
| 193 |
|
| 194 |
#if defined(_WIN64) || \ |
| 195 |
defined(__DOXYGEN__) |
| 196 |
#define VL_OS_WIN64 1 |
| 197 |
#endif |
| 198 |
/** @} */ |
| 199 |
|
| 200 |
/** @name Identifying the host threading library |
| 201 |
** @{ */ |
| 202 |
#if !defined(VL_OS_WIN) && !defined(VL_OS_WIN64) || \ |
| 203 |
defined(__DOXYGEN__) |
| 204 |
#define VL_THREADS_POSIX 1 |
| 205 |
#endif |
| 206 |
|
| 207 |
#if defined(VL_OS_WIN) || defined(VL_OS_WIN64) || \ |
| 208 |
defined(__DOXYGEN__) |
| 209 |
#define VL_THREADS_WIN 1 |
| 210 |
#endif |
| 211 |
/** @} */ |
| 212 |
|
| 213 |
/** @name Identifying the host compiler |
| 214 |
** @{ */ |
| 215 |
#if defined(__GNUC__) || defined(__DOXYGEN__) |
| 216 |
# if defined(__GNUC_PATCHLEVEL__) |
| 217 |
# define VL_COMPILER_GNUC (__GNUC__ * 10000 \ |
| 218 |
+ __GNUC_MINOR__ * 100 \ |
| 219 |
+ __GNUC_PATCHLEVEL__) |
| 220 |
# else |
| 221 |
# define VL_COMPILER_GNUC (__GNUC__ * 10000 \ |
| 222 |
+ __GNUC_MINOR__ * 100) |
| 223 |
# endif |
| 224 |
#endif |
| 225 |
|
| 226 |
#if defined(_MSC_VER) || defined(__DOXYGEN__) |
| 227 |
#define VL_COMPILER_MSC _MSC_VER |
| 228 |
#endif |
| 229 |
|
| 230 |
#if defined(__LCC__) || defined(__DOXYGEN__) |
| 231 |
#warning "LCC support is experimental!" |
| 232 |
#define VL_COMPILER_LCC 1 |
| 233 |
#endif |
| 234 |
|
| 235 |
/** @} */ |
| 236 |
|
| 237 |
/** @name Identifying the host CPU architecture |
| 238 |
** @{ */ |
| 239 |
#if defined(i386) || \ |
| 240 |
defined(__i386__) || \ |
| 241 |
defined(__DOXYGEN__) |
| 242 |
#define VL_ARCH_IX86 300 |
| 243 |
#elif defined(__i486__) |
| 244 |
#define VL_ARCH_IX86 400 |
| 245 |
#elif defined(__i586__) |
| 246 |
#define VL_ARCH_IX86 500 |
| 247 |
#elif defined(__i686__) |
| 248 |
#define VL_ARCH_IX86 600 |
| 249 |
#elif defined(_M_IX86) |
| 250 |
#define VL_ARCH_IX86 _M_IX86 |
| 251 |
#endif |
| 252 |
|
| 253 |
#if defined(_M_X64) || \ |
| 254 |
defined(__amd64__) || \ |
| 255 |
defined(__amd64) || \ |
| 256 |
defined(__x86_64) || \ |
| 257 |
defined(__x86_64) |
| 258 |
#define VL_ARCH_X64 |
| 259 |
#endif |
| 260 |
|
| 261 |
#if defined(__ia64__) || \ |
| 262 |
defined(_IA64) || \ |
| 263 |
defined(__IA64) || \ |
| 264 |
defined(__ia64) || \ |
| 265 |
defined(_M_IA64) || \ |
| 266 |
defined(__DOXYGEN__) |
| 267 |
#define VL_ARCH_IA64 |
| 268 |
#endif |
| 269 |
/** @} */ |
| 270 |
|
| 271 |
/** @name Identifying the host data model |
| 272 |
** @{ */ |
| 273 |
#if defined(__LLP64__) || \ |
| 274 |
defined(__LLP64) || \ |
| 275 |
defined(__LLP64) || \ |
| 276 |
(defined(VL_COMPILER_MSC) & defined(VL_OS_WIN64)) || \ |
| 277 |
(defined(VL_COMPILER_LCC) & defined(VL_OS_WIN64)) || \ |
| 278 |
defined(__DOXYGEN__) |
| 279 |
#define VL_COMPILER_LLP64 |
| 280 |
#endif |
| 281 |
|
| 282 |
#if defined(__LP64__) || \ |
| 283 |
defined(__LP64) || \ |
| 284 |
defined(__LP64) || \ |
| 285 |
(defined(VL_OS_MACOSX) & defined(VL_ARCH_IA64)) || \ |
| 286 |
defined(__DOXYGEN__) |
| 287 |
#define VL_COMPILER_LP64 |
| 288 |
#endif |
| 289 |
|
| 290 |
#if (!defined(VL_COMPILER_LLP64) & !defined(VL_COMPILER_LP64)) || \ |
| 291 |
defined(__DOXYGEN__) |
| 292 |
#define VL_COMPILER_ILP32 |
| 293 |
#endif |
| 294 |
/** @} */ |
| 295 |
|
| 296 |
/** @name Identifying the host endianness |
| 297 |
** @{ */ |
| 298 |
#if defined(__LITTLE_ENDIAN__) || \ |
| 299 |
defined(VL_ARCH_IX86) || \ |
| 300 |
defined(VL_ARCH_IA64) || \ |
| 301 |
defined(VL_ARCH_X64) || \ |
| 302 |
defined(__DOXYGEN__) |
| 303 |
#define VL_ARCH_LITTLE_ENDIAN |
| 304 |
#endif |
| 305 |
|
| 306 |
#if defined(__DOXYGEN__) || \ |
| 307 |
!defined(VL_ARCH_LITTLE_ENDIAN) |
| 308 |
#define VL_ARCH_BIG_ENDIAN |
| 309 |
#endif |
| 310 |
/** @} */ |
| 311 |
|
| 312 |
#if defined(VL_COMPILER_MSC) & ! defined(__DOXYGEN__) |
| 313 |
# define VL_UNUSED |
| 314 |
# define VL_INLINE static __inline |
| 315 |
#if defined _MSC_VER && _MSC_VER < 1900 |
| 316 |
# define snprintf _snprintf |
| 317 |
# define isnan _isnan |
| 318 |
#endif |
| 319 |
# ifdef VL_BUILD_DLL |
| 320 |
# ifdef __cplusplus |
| 321 |
# define VL_EXPORT extern "C" __declspec(dllexport) |
| 322 |
# else |
| 323 |
# define VL_EXPORT extern __declspec(dllexport) |
| 324 |
# endif |
| 325 |
# else |
| 326 |
# ifdef __cplusplus |
| 327 |
# define VL_EXPORT extern "C" |
| 328 |
# else |
| 329 |
# define VL_EXPORT extern |
| 330 |
# endif |
| 331 |
# endif |
| 332 |
#endif |
| 333 |
|
| 334 |
#if defined(VL_COMPILER_LCC) & ! defined(__DOXYGEN__) |
| 335 |
# define VL_UNUSED |
| 336 |
# define VL_INLINE static __inline |
| 337 |
# define snprintf _snprintf |
| 338 |
# define isnan _isnan |
| 339 |
VL_INLINE float fabsf(float x) { return (float) fabs((double) x) ; } |
| 340 |
# ifdef VL_BUILD_DLL |
| 341 |
# define VL_EXPORT extern __declspec(dllexport) |
| 342 |
# else |
| 343 |
# define VL_EXPORT extern |
| 344 |
# endif |
| 345 |
#endif |
| 346 |
|
| 347 |
#if defined(VL_COMPILER_GNUC) & ! defined(__DOXYGEN__) |
| 348 |
# define VL_UNUSED __attribute__((unused)) |
| 349 |
# define VL_INLINE static __inline__ |
| 350 |
# ifdef VL_BUILD_DLL |
| 351 |
# ifdef __cplusplus |
| 352 |
# define VL_EXPORT __attribute__((visibility ("default"))) extern "C" |
| 353 |
# else |
| 354 |
# define VL_EXPORT __attribute__((visibility ("default"))) extern |
| 355 |
# endif |
| 356 |
# else |
| 357 |
# ifdef __cplusplus |
| 358 |
# define VL_EXPORT extern "C" |
| 359 |
# else |
| 360 |
# define VL_EXPORT extern |
| 361 |
# endif |
| 362 |
# endif |
| 363 |
#endif |
| 364 |
|
| 365 |
VL_EXPORT char * vl_static_configuration_to_string_copy () ; |
| 366 |
|
| 367 |
/** ------------------------------------------------------------------ |
| 368 |
** @name Atomic data types |
| 369 |
** @{ |
| 370 |
**/ |
| 371 |
|
| 372 |
#define VL_TRUE 1 /**< @brief @c true (1) constant */ |
| 373 |
#define VL_FALSE 0 /**< @brief @c false (0) constant */ |
| 374 |
|
| 375 |
#if defined(VL_COMPILER_LP64) || defined(VL_COMPILER_LLP64) |
| 376 |
typedef long long vl_int64 ; /**< @brief Signed 64-bit integer. */ |
| 377 |
typedef int vl_int32 ; /**< @brief Signed 32-bit integer. */ |
| 378 |
typedef short vl_int16 ; /**< @brief Signed 16-bit integer. */ |
| 379 |
typedef char vl_int8 ; /**< @brief Signed 8-bit integer. */ |
| 380 |
|
| 381 |
typedef long long unsigned vl_uint64 ; /**< @brief Unsigned 64-bit integer. */ |
| 382 |
typedef int unsigned vl_uint32 ; /**< @brief Unsigned 32-bit integer. */ |
| 383 |
typedef short unsigned vl_uint16 ; /**< @brief Unsigned 16-bit integer. */ |
| 384 |
typedef char unsigned vl_uint8 ; /**< @brief Unsigned 8-bit integer. */ |
| 385 |
|
| 386 |
typedef int vl_int ; /**< @brief Same as @c int. */ |
| 387 |
typedef unsigned int vl_uint ; /**< @brief Same as <code>unsigned int</code>. */ |
| 388 |
|
| 389 |
typedef int vl_bool ; /**< @brief Boolean. */ |
| 390 |
typedef vl_int64 vl_intptr ; /**< @brief Integer holding a pointer. */ |
| 391 |
typedef vl_uint64 vl_uintptr ; /**< @brief Unsigned integer holding a pointer. */ |
| 392 |
typedef vl_uint64 vl_size ; /**< @brief Unsigned integer holding the size of a memory block. */ |
| 393 |
typedef vl_int64 vl_index ; /**< @brief Signed version of ::vl_size and ::vl_uindex */ |
| 394 |
typedef vl_uint64 vl_uindex ; /**< @brief Same as ::vl_size */ |
| 395 |
#endif |
| 396 |
|
| 397 |
#if defined(VL_COMPILER_ILP32) |
| 398 |
|
| 399 |
#ifdef VL_COMPILER_MSC |
| 400 |
typedef __int64 vl_int64 ; |
| 401 |
#else |
| 402 |
typedef long long vl_int64 ; |
| 403 |
#endif |
| 404 |
|
| 405 |
typedef int vl_int32 ; |
| 406 |
typedef short vl_int16 ; |
| 407 |
typedef char vl_int8 ; |
| 408 |
|
| 409 |
#ifdef VL_COMPILER_MSC |
| 410 |
typedef __int64 unsigned vl_uint64 ; |
| 411 |
#else |
| 412 |
typedef long long unsigned vl_uint64 ; |
| 413 |
#endif |
| 414 |
typedef int unsigned vl_uint32 ; |
| 415 |
typedef short unsigned vl_uint16 ; |
| 416 |
typedef char unsigned vl_uint8 ; |
| 417 |
|
| 418 |
typedef int vl_int ; |
| 419 |
typedef unsigned int vl_uint ; |
| 420 |
|
| 421 |
typedef int vl_bool ; |
| 422 |
typedef vl_int32 vl_intptr ; |
| 423 |
typedef vl_uint32 vl_uintptr ; |
| 424 |
typedef vl_uint32 vl_size ; |
| 425 |
typedef vl_int32 vl_index ; |
| 426 |
typedef vl_uint32 vl_uindex ; |
| 427 |
#endif |
| 428 |
/** @} */ |
| 429 |
|
| 430 |
/** @name Creating integer constants |
| 431 |
** @{ */ |
| 432 |
#if defined(VL_COMPILER_LP64) || defined(__DOXYGEN__) |
| 433 |
#define VL_INT8_C(x) x |
| 434 |
#define VL_INT16_C(x) x |
| 435 |
#define VL_INT32_C(x) x |
| 436 |
#define VL_INT64_C(x) x ## L |
| 437 |
|
| 438 |
#define VL_UINT8_C(x) x |
| 439 |
#define VL_UINT16_C(x) x |
| 440 |
#define VL_UINT32_C(x) x ## U |
| 441 |
#define VL_UINT64_C(x) x ## UL |
| 442 |
#endif |
| 443 |
|
| 444 |
#if (defined(VL_COMPILER_LLP64) || defined(VL_COMPILER_ILP32)) \ |
| 445 |
& !defined(__DOXYGEN__) |
| 446 |
#define VL_INT8_C(x) x |
| 447 |
#define VL_INT16_C(x) x |
| 448 |
#define VL_INT32_C(x) x |
| 449 |
#define VL_INT64_C(x) x ## LL |
| 450 |
|
| 451 |
#define VL_UINT8_C(x) x |
| 452 |
#define VL_UINT16_C(x) x |
| 453 |
#define VL_UINT32_C(x) x ## U |
| 454 |
#define VL_UINT64_C(x) x ## ULL |
| 455 |
#endif |
| 456 |
/** @} */ |
| 457 |
|
| 458 |
/** ------------------------------------------------------------------ |
| 459 |
** @name Printing the atomic data types |
| 460 |
** @{ */ |
| 461 |
|
| 462 |
/* Lengths only: */ |
| 463 |
|
| 464 |
/** @def VL_FL_INT64 |
| 465 |
** @brief @c printf length flag for ::vl_int64 and ::vl_uint64. |
| 466 |
**/ |
| 467 |
|
| 468 |
/** @def VL_FL_INT32 |
| 469 |
** @brief @c printf length flag for ::vl_int32 and ::vl_uint32. |
| 470 |
**/ |
| 471 |
|
| 472 |
/** @def VL_FL_INT16 |
| 473 |
** @brief @c printf length flag for ::vl_int16 and ::vl_uint16. |
| 474 |
**/ |
| 475 |
|
| 476 |
/** @def VL_FL_INT8 |
| 477 |
** @brief @c printf length flag for ::vl_int8 and ::vl_uint8. |
| 478 |
**/ |
| 479 |
|
| 480 |
/** @def VL_FL_INDEX |
| 481 |
** @brief @c printf length flag for ::vl_index and ::vl_uindex |
| 482 |
**/ |
| 483 |
|
| 484 |
#ifdef VL_COMPILER_MSC |
| 485 |
#define VL_FL_INT64 "I64" |
| 486 |
#else |
| 487 |
#define VL_FL_INT64 "ll" |
| 488 |
#endif |
| 489 |
#define VL_FL_INT32 "" |
| 490 |
#define VL_FL_INT16 "h" |
| 491 |
#define VL_FL_INT8 "hh" |
| 492 |
|
| 493 |
#if defined(VL_COMPILER_LP64) || defined(VL_COMPILER_LLP64) |
| 494 |
#define VL_FL_INDEX VL_FL_INT64 |
| 495 |
#endif |
| 496 |
|
| 497 |
#if defined(VL_COMPILER_ILP32) |
| 498 |
#define VL_FL_INDEX VL_FL_INT32 |
| 499 |
#endif |
| 500 |
|
| 501 |
/* Formats (but not conversions!): */ |
| 502 |
|
| 503 |
/** @def VL_FMT_SIZE |
| 504 |
** @brief @c printf flag for ::vl_size |
| 505 |
**/ |
| 506 |
|
| 507 |
/** @def VL_FMT_INDEX |
| 508 |
** @brief @c printf flag for ::vl_index |
| 509 |
**/ |
| 510 |
|
| 511 |
/** @def VL_FMT_UINDEX |
| 512 |
** @brief @c printf flag for ::vl_uindex |
| 513 |
**/ |
| 514 |
|
| 515 |
/** @def VL_FMT_INTPTR |
| 516 |
** @brief @c printf flag for ::vl_intptr |
| 517 |
**/ |
| 518 |
|
| 519 |
/** @def VL_FMT_UINTPTR |
| 520 |
** @brief @c printf flag for ::vl_uintptr |
| 521 |
**/ |
| 522 |
|
| 523 |
#define VL_FMT_INDEX VL_FL_INDEX "d" |
| 524 |
#define VL_FMT_INTPTR VL_FMT_INDEX |
| 525 |
#define VL_FMT_UINDEX VL_FL_INDEX "u" |
| 526 |
#define VL_FMT_SIZE VL_FMT_UINDEX |
| 527 |
#define VL_FMT_UINTPTR VL_FMT_UINDEX |
| 528 |
|
| 529 |
/** @} */ |
| 530 |
|
| 531 |
/** ------------------------------------------------------------------ |
| 532 |
** @name Atomic data types limits |
| 533 |
** @{ */ |
| 534 |
|
| 535 |
/** @brief Largest integer (math constant) */ |
| 536 |
#define VL_BIG_INT 0x7FFFFFFFL |
| 537 |
|
| 538 |
/** @brief Smallest integer (math constant) */ |
| 539 |
#define VL_SMALL_INT (- VL_BIG_INT - 1) |
| 540 |
|
| 541 |
/** @brief Largest unsigned integer (math constant) */ |
| 542 |
#define VL_BIG_UINT 0xFFFFFFFFUL |
| 543 |
|
| 544 |
/** @} */ |
| 545 |
|
| 546 |
/** ------------------------------------------------------------------ |
| 547 |
** @name Endianness detection and conversion |
| 548 |
** @{ |
| 549 |
**/ |
| 550 |
VL_INLINE void vl_swap_host_big_endianness_8 (void *dst, void* src) ; |
| 551 |
VL_INLINE void vl_swap_host_big_endianness_4 (void *dst, void* src) ; |
| 552 |
VL_INLINE void vl_swap_host_big_endianness_2 (void *dst, void* src) ; |
| 553 |
/** @} */ |
| 554 |
|
| 555 |
/** ------------------------------------------------------------------ |
| 556 |
** @name Obtaining host info at run time |
| 557 |
** @{ */ |
| 558 |
|
| 559 |
typedef struct _VlX86CpuInfo |
| 560 |
{ |
| 561 |
union { |
| 562 |
char string [0x20] ; |
| 563 |
vl_uint32 words [0x20 / 4] ; |
| 564 |
} vendor ; |
| 565 |
vl_bool hasAVX ; |
| 566 |
vl_bool hasSSE42 ; |
| 567 |
vl_bool hasSSE41 ; |
| 568 |
vl_bool hasSSE3 ; |
| 569 |
vl_bool hasSSE2 ; |
| 570 |
vl_bool hasSSE ; |
| 571 |
vl_bool hasMMX ; |
| 572 |
} VlX86CpuInfo ; |
| 573 |
|
| 574 |
void _vl_x86cpu_info_init (VlX86CpuInfo *self) ; |
| 575 |
char * _vl_x86cpu_info_to_string_copy (VlX86CpuInfo const *self) ; |
| 576 |
|
| 577 |
/** @} */ |
| 578 |
|
| 579 |
/** ------------------------------------------------------------------ |
| 580 |
** @brief Host <-> big endian transformation for 8-bytes value |
| 581 |
** |
| 582 |
** @param dst destination 8-byte buffer. |
| 583 |
** @param src source 8-byte bufffer. |
| 584 |
** @see @ref host-arch-endianness. |
| 585 |
**/ |
| 586 |
|
| 587 |
VL_INLINE void |
| 588 |
vl_swap_host_big_endianness_8 (void *dst, void* src) |
| 589 |
{ |
| 590 |
char *dst_ = (char*) dst ; |
| 591 |
char *src_ = (char*) src ; |
| 592 |
#if defined(VL_ARCH_BIG_ENDIAN) |
| 593 |
dst_ [0] = src_ [0] ; |
| 594 |
dst_ [1] = src_ [1] ; |
| 595 |
dst_ [2] = src_ [2] ; |
| 596 |
dst_ [3] = src_ [3] ; |
| 597 |
dst_ [4] = src_ [4] ; |
| 598 |
dst_ [5] = src_ [5] ; |
| 599 |
dst_ [6] = src_ [6] ; |
| 600 |
dst_ [7] = src_ [7] ; |
| 601 |
#else |
| 602 |
dst_ [0] = src_ [7] ; |
| 603 |
dst_ [1] = src_ [6] ; |
| 604 |
dst_ [2] = src_ [5] ; |
| 605 |
dst_ [3] = src_ [4] ; |
| 606 |
dst_ [4] = src_ [3] ; |
| 607 |
dst_ [5] = src_ [2] ; |
| 608 |
dst_ [6] = src_ [1] ; |
| 609 |
dst_ [7] = src_ [0] ; |
| 610 |
#endif |
| 611 |
} |
| 612 |
|
| 613 |
/** ------------------------------------------------------------------ |
| 614 |
** @brief Host <-> big endian transformation for 4-bytes value |
| 615 |
** |
| 616 |
** @param dst destination 4-byte buffer. |
| 617 |
** @param src source 4-byte bufffer. |
| 618 |
** @sa @ref host-arch-endianness. |
| 619 |
**/ |
| 620 |
|
| 621 |
VL_INLINE void |
| 622 |
vl_swap_host_big_endianness_4 (void *dst, void* src) |
| 623 |
{ |
| 624 |
char *dst_ = (char*) dst ; |
| 625 |
char *src_ = (char*) src ; |
| 626 |
#if defined(VL_ARCH_BIG_ENDIAN) |
| 627 |
dst_ [0] = src_ [0] ; |
| 628 |
dst_ [1] = src_ [1] ; |
| 629 |
dst_ [2] = src_ [2] ; |
| 630 |
dst_ [3] = src_ [3] ; |
| 631 |
#else |
| 632 |
dst_ [0] = src_ [3] ; |
| 633 |
dst_ [1] = src_ [2] ; |
| 634 |
dst_ [2] = src_ [1] ; |
| 635 |
dst_ [3] = src_ [0] ; |
| 636 |
#endif |
| 637 |
} |
| 638 |
|
| 639 |
/** ------------------------------------------------------------------ |
| 640 |
** @brief Host <-> big endian transformation for 2-bytes value |
| 641 |
** |
| 642 |
** @param dst destination 2-byte buffer. |
| 643 |
** @param src source 2-byte bufffer. |
| 644 |
** @see @ref host-arch-endianness. |
| 645 |
**/ |
| 646 |
|
| 647 |
VL_INLINE void |
| 648 |
vl_swap_host_big_endianness_2 (void *dst, void* src) |
| 649 |
{ |
| 650 |
char *dst_ = (char*) dst ; |
| 651 |
char *src_ = (char*) src ; |
| 652 |
#if defined(VL_ARCH_BIG_ENDIAN) |
| 653 |
dst_ [0] = src_ [0] ; |
| 654 |
dst_ [1] = src_ [1] ; |
| 655 |
#else |
| 656 |
dst_ [0] = src_ [1] ; |
| 657 |
dst_ [1] = src_ [0] ; |
| 658 |
#endif |
| 659 |
} |
| 660 |
|
| 661 |
/* VL_HOST_H */ |
| 662 |
#endif |