Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef VL_HOST_H
00016 #define VL_HOST_H
00017
00022 #if defined(__DOXYGEN__)
00023 #define VL_DISABLE_THREADS
00024 #define VL_DISABLE_SSE2
00025 #define VL_DISABLE_OPENMP
00026 #endif
00027
00034 #if defined(__DOXYGEN__)
00035 #define VL_EXPORT
00036 #define VL_INLINE
00037 #endif
00038
00066 #define VL_STRINGIFY(x) # x
00067
00085 #define VL_XSTRINGIFY(x) VL_STRINGIFY(x)
00086
00100 #define VL_CAT(x,y) x ## y
00101
00112 #define VL_XCAT(x,y) VL_CAT(x,y)
00113
00124 #define VL_XCAT3(x,y,z) VL_XCAT(VL_XCAT(x,y),z)
00125
00137 #define VL_XCAT4(x,y,z,u) VL_XCAT(VL_XCAT3(x,y,z),u)
00138
00151 #define VL_XCAT5(x,y,z,u,v) VL_XCAT(VL_XCAT4(x,y,z,u),v)
00152
00165 #define VL_YESNO(x) ((x)?"yes":"no")
00166
00169
00170
00171
00172
00173
00176 #if defined(linux) || \
00177 defined(__linux) || \
00178 defined(__linux__) || \
00179 defined(__DOXYGEN__)
00180 #define VL_OS_LINUX 1
00181 #endif
00182
00183 #if (defined(__APPLE__) & defined(__MACH__)) || \
00184 defined(__DOXYGEN__)
00185 #define VL_OS_MACOSX 1
00186 #endif
00187
00188 #if defined(__WIN32__) || \
00189 defined(_WIN32) || \
00190 defined(__DOXYGEN__)
00191 #define VL_OS_WIN 1
00192 #endif
00193
00194 #if defined(_WIN64) || \
00195 defined(__DOXYGEN__)
00196 #define VL_OS_WIN64 1
00197 #endif
00198
00202 #if defined(VL_OS_MACOSX) || defined(VL_OS_LINUX) || \
00203 defined(__DOXYGEN__)
00204 #define VL_THREADS_POSIX 1
00205 #endif
00206
00207 #if defined(VL_OS_WIN) || defined(VL_OS_WIN64) || \
00208 defined(__DOXYGEN__)
00209 #define VL_THREADS_WIN 1
00210 #endif
00211
00215 #if defined(__GNUC__) || defined(__DOXYGEN__)
00216 # if defined(__GNUC_PATCHLEVEL__)
00217 # define VL_COMPILER_GNUC (__GNUC__ * 10000 \
00218 + __GNUC_MINOR__ * 100 \
00219 + __GNUC_PATCHLEVEL__)
00220 # else
00221 # define VL_COMPILER_GNUC (__GNUC__ * 10000 \
00222 + __GNUC_MINOR__ * 100)
00223 # endif
00224 #endif
00225
00226 #if defined(_MSC_VER) || defined(__DOXYGEN__)
00227 #define VL_COMPILER_MSC _MSC_VER
00228 #endif
00229
00230 #if defined(__LCC__) || defined(__DOXYGEN__)
00231 #warning "LCC support is experimental!"
00232 #define VL_COMPILER_LCC 1
00233 #endif
00234
00239 #if defined(i386) || \
00240 defined(__i386__) || \
00241 defined(__DOXYGEN__)
00242 #define VL_ARCH_IX86 300
00243 #elif defined(__i486__)
00244 #define VL_ARCH_IX86 400
00245 #elif defined(__i586__)
00246 #define VL_ARCH_IX86 500
00247 #elif defined(__i686__)
00248 #define VL_ARCH_IX86 600
00249 #elif defined(_M_IX86)
00250 #define VL_ARCH_IX86 _M_IX86
00251 #endif
00252
00253 #if defined(_M_X64) || \
00254 defined(__amd64__) || \
00255 defined(__amd64) || \
00256 defined(__x86_64) || \
00257 defined(__x86_64)
00258 #define VL_ARCH_X64
00259 #endif
00260
00261 #if defined(__ia64__) || \
00262 defined(_IA64) || \
00263 defined(__IA64) || \
00264 defined(__ia64) || \
00265 defined(_M_IA64) || \
00266 defined(__DOXYGEN__)
00267 #define VL_ARCH_IA64
00268 #endif
00269
00273 #if defined(__LLP64__) || \
00274 defined(__LLP64) || \
00275 defined(__LLP64) || \
00276 (defined(VL_COMPILER_MSC) & defined(VL_OS_WIN64)) || \
00277 (defined(VL_COMPILER_LCC) & defined(VL_OS_WIN64)) || \
00278 defined(__DOXYGEN__)
00279 #define VL_COMPILER_LLP64
00280 #endif
00281
00282 #if defined(__LP64__) || \
00283 defined(__LP64) || \
00284 defined(__LP64) || \
00285 (defined(VL_OS_MACOSX) & defined(VL_ARCH_IA64)) || \
00286 defined(__DOXYGEN__)
00287 #define VL_COMPILER_LP64
00288 #endif
00289
00290 #if (!defined(VL_COMPILER_LLP64) & !defined(VL_COMPILER_LP64)) || \
00291 defined(__DOXYGEN__)
00292 #define VL_COMPILER_ILP32
00293 #endif
00294
00298 #if defined(__LITTLE_ENDIAN__) || \
00299 defined(VL_ARCH_IX86) || \
00300 defined(VL_ARCH_IA64) || \
00301 defined(VL_ARCH_X64) || \
00302 defined(__DOXYGEN__)
00303 #define VL_ARCH_LITTLE_ENDIAN
00304 #endif
00305
00306 #if defined(__DOXYGEN__) || \
00307 !defined(VL_ARCH_LITTLE_ENDIAN)
00308 #define VL_ARCH_BIG_ENDIAN
00309 #endif
00310
00312 #if defined(VL_COMPILER_MSC) & ! defined(__DOXYGEN__)
00313 # define VL_UNUSED
00314 # define VL_INLINE static __inline
00315 # define snprintf _snprintf
00316 # define isnan _isnan
00317 # ifdef VL_BUILD_DLL
00318 # ifdef __cplusplus
00319 # define VL_EXPORT extern "C" __declspec(dllexport)
00320 # else
00321 # define VL_EXPORT extern __declspec(dllexport)
00322 # endif
00323 # else
00324 # ifdef __cplusplus
00325 # define VL_EXPORT extern "C" __declspec(dllimport)
00326 # else
00327 # define VL_EXPORT extern __declspec(dllimport)
00328 # endif
00329 # endif
00330 #endif
00331
00332 #if defined(VL_COMPILER_LCC) & ! defined(__DOXYGEN__)
00333 # define VL_UNUSED
00334 # define VL_INLINE static __inline
00335 # define snprintf _snprintf
00336 # define isnan _isnan
00337 VL_INLINE float fabsf(float x) { return (float) fabs((double) x) ; }
00338 # ifdef VL_BUILD_DLL
00339 # define VL_EXPORT extern __declspec(dllexport)
00340 # else
00341 # define VL_EXPORT extern
00342 # endif
00343 #endif
00344
00345 #if defined(VL_COMPILER_GNUC) & ! defined(__DOXYGEN__)
00346 # define VL_UNUSED __attribute__((unused))
00347 # define VL_INLINE static __inline__
00348 # ifdef VL_BUILD_DLL
00349 # ifdef __cplusplus
00350 # define VL_EXPORT __attribute__((visibility ("default"))) extern "C"
00351 # else
00352 # define VL_EXPORT __attribute__((visibility ("default"))) extern
00353 # endif
00354 # else
00355 # ifdef __cplusplus
00356 # define VL_EXPORT extern "C"
00357 # else
00358 # define VL_EXPORT extern
00359 # endif
00360 # endif
00361 #endif
00362
00363 VL_EXPORT char * vl_static_configuration_to_string_copy () ;
00364
00370 #define VL_TRUE 1
00371 #define VL_FALSE 0
00373 #if defined(VL_COMPILER_LP64) || defined(VL_COMPILER_LLP64)
00374 typedef long long vl_int64 ;
00375 typedef int vl_int32 ;
00376 typedef short vl_int16 ;
00377 typedef char vl_int8 ;
00379 typedef long long unsigned vl_uint64 ;
00380 typedef int unsigned vl_uint32 ;
00381 typedef short unsigned vl_uint16 ;
00382 typedef char unsigned vl_uint8 ;
00384 typedef int vl_int ;
00385 typedef unsigned int vl_uint ;
00387 typedef int vl_bool ;
00388 typedef vl_int64 vl_intptr ;
00389 typedef vl_uint64 vl_uintptr ;
00390 typedef vl_uint64 vl_size ;
00391 typedef vl_int64 vl_index ;
00392 typedef vl_uint64 vl_uindex ;
00393 #endif
00394
00395 #if defined(VL_COMPILER_ILP32)
00396
00397 #ifdef VL_COMPILER_MSC
00398 typedef __int64 vl_int64 ;
00399 #else
00400 typedef long long vl_int64 ;
00401 #endif
00402
00403 typedef int vl_int32 ;
00404 typedef short vl_int16 ;
00405 typedef char vl_int8 ;
00406
00407 #ifdef VL_COMPILER_MSC
00408 typedef __int64 unsigned vl_uint64 ;
00409 #else
00410 typedef long long unsigned vl_uint64 ;
00411 #endif
00412 typedef int unsigned vl_uint32 ;
00413 typedef short unsigned vl_uint16 ;
00414 typedef char unsigned vl_uint8 ;
00415
00416 typedef int vl_int ;
00417 typedef unsigned int vl_uint ;
00418
00419 typedef int vl_bool ;
00420 typedef vl_int32 vl_intptr ;
00421 typedef vl_uint32 vl_uintptr ;
00422 typedef vl_uint32 vl_size ;
00423 typedef vl_int32 vl_index ;
00424 typedef vl_uint32 vl_uindex ;
00425 #endif
00426
00430 #if defined(VL_COMPILER_LP64) || defined(__DOXYGEN__)
00431 #define VL_INT8_C(x) x
00432 #define VL_INT16_C(x) x
00433 #define VL_INT32_C(x) x
00434 #define VL_INT64_C(x) x ## L
00435
00436 #define VL_UINT8_C(x) x
00437 #define VL_UINT16_C(x) x
00438 #define VL_UINT32_C(x) x ## U
00439 #define VL_UINT64_C(x) x ## UL
00440 #endif
00441
00442 #if (defined(VL_COMPILER_LLP64) || defined(VL_COMPILER_ILP32)) \
00443 & !defined(__DOXYGEN__)
00444 #define VL_INT8_C(x) x
00445 #define VL_INT16_C(x) x
00446 #define VL_INT32_C(x) x
00447 #define VL_INT64_C(x) x ## LL
00448
00449 #define VL_UINT8_C(x) x
00450 #define VL_UINT16_C(x) x
00451 #define VL_UINT32_C(x) x ## U
00452 #define VL_UINT64_C(x) x ## ULL
00453 #endif
00454
00460
00461
00482 #ifdef VL_COMPILER_MSC
00483 #define VL_FL_INT64 "I64"
00484 #else
00485 #define VL_FL_INT64 "ll"
00486 #endif
00487 #define VL_FL_INT32 ""
00488 #define VL_FL_INT16 "h"
00489 #define VL_FL_INT8 "hh"
00490
00491 #if defined(VL_COMPILER_LP64) || defined(VL_COMPILER_LLP64)
00492 #define VL_FL_INDEX VL_FL_INT64
00493 #endif
00494
00495 #if defined(VL_COMPILER_ILP32)
00496 #define VL_FL_INDEX VL_FL_INT32
00497 #endif
00498
00499
00500
00521 #define VL_FMT_INDEX VL_FL_INDEX "d"
00522 #define VL_FMT_INTPTR VL_FMT_INDEX
00523 #define VL_FMT_UINDEX VL_FL_INDEX "u"
00524 #define VL_FMT_SIZE VL_FMT_UINDEX
00525 #define VL_FMT_UINTPTR VL_FMT_UINDEX
00526
00534 #define VL_BIG_INT 0x7FFFFFFFL
00535
00537 #define VL_SMALL_INT (- VL_BIG_INT - 1)
00538
00540 #define VL_BIG_UINT 0xFFFFFFFFUL
00541
00548 VL_INLINE void vl_swap_host_big_endianness_8 (void *dst, void* src) ;
00549 VL_INLINE void vl_swap_host_big_endianness_4 (void *dst, void* src) ;
00550 VL_INLINE void vl_swap_host_big_endianness_2 (void *dst, void* src) ;
00557 typedef struct _VlX86CpuInfo
00558 {
00559 union {
00560 char string [0x20] ;
00561 vl_uint32 words [0x20 / 4] ;
00562 } vendor ;
00563 vl_bool hasAVX ;
00564 vl_bool hasSSE42 ;
00565 vl_bool hasSSE41 ;
00566 vl_bool hasSSE3 ;
00567 vl_bool hasSSE2 ;
00568 vl_bool hasSSE ;
00569 vl_bool hasMMX ;
00570 } VlX86CpuInfo ;
00571
00572 void _vl_x86cpu_info_init (VlX86CpuInfo *self) ;
00573 char * _vl_x86cpu_info_to_string_copy (VlX86CpuInfo const *self) ;
00574
00585 VL_INLINE void
00586 vl_swap_host_big_endianness_8 (void *dst, void* src)
00587 {
00588 char *dst_ = (char*) dst ;
00589 char *src_ = (char*) src ;
00590 #if defined(VL_ARCH_BIG_ENDIAN)
00591 dst_ [0] = src_ [0] ;
00592 dst_ [1] = src_ [1] ;
00593 dst_ [2] = src_ [2] ;
00594 dst_ [3] = src_ [3] ;
00595 dst_ [4] = src_ [4] ;
00596 dst_ [5] = src_ [5] ;
00597 dst_ [6] = src_ [6] ;
00598 dst_ [7] = src_ [7] ;
00599 #else
00600 dst_ [0] = src_ [7] ;
00601 dst_ [1] = src_ [6] ;
00602 dst_ [2] = src_ [5] ;
00603 dst_ [3] = src_ [4] ;
00604 dst_ [4] = src_ [3] ;
00605 dst_ [5] = src_ [2] ;
00606 dst_ [6] = src_ [1] ;
00607 dst_ [7] = src_ [0] ;
00608 #endif
00609 }
00610
00619 VL_INLINE void
00620 vl_swap_host_big_endianness_4 (void *dst, void* src)
00621 {
00622 char *dst_ = (char*) dst ;
00623 char *src_ = (char*) src ;
00624 #if defined(VL_ARCH_BIG_ENDIAN)
00625 dst_ [0] = src_ [0] ;
00626 dst_ [1] = src_ [1] ;
00627 dst_ [2] = src_ [2] ;
00628 dst_ [3] = src_ [3] ;
00629 #else
00630 dst_ [0] = src_ [3] ;
00631 dst_ [1] = src_ [2] ;
00632 dst_ [2] = src_ [1] ;
00633 dst_ [3] = src_ [0] ;
00634 #endif
00635 }
00636
00645 VL_INLINE void
00646 vl_swap_host_big_endianness_2 (void *dst, void* src)
00647 {
00648 char *dst_ = (char*) dst ;
00649 char *src_ = (char*) src ;
00650 #if defined(VL_ARCH_BIG_ENDIAN)
00651 dst_ [0] = src_ [0] ;
00652 dst_ [1] = src_ [1] ;
00653 #else
00654 dst_ [0] = src_ [1] ;
00655 dst_ [1] = src_ [0] ;
00656 #endif
00657 }
00658
00659
00660 #endif