You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

670 lines
17 KiB

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