AGX Dynamics  2.37.3.2
byteswap.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_BYTESWAP_H
18 #define AGX_BYTESWAP_H
19 
20 #include <agx/agx.h>
21 
22 #ifdef _MSC_VER
23 #else
24 #ifdef __APPLE__
25 #include <CoreFoundation/CoreFoundation.h>
26 #else //LINUX
27 // The byteswap_.* family of macros inject code containing the deprecated 'register' keyword.
29 #include <byteswap.h>
30 #endif
31 #endif
32 
33 namespace agx
34 {
35 #ifdef _MSC_VER
36  static inline uint16_t ByteSwap16 ( uint16_t x )
37  {
38  return ( x >> 8 ) | ( x << 8 );
39  }
40 
41  static inline uint32_t ByteSwap32 ( uint32_t x )
42  {
43  return ( ByteSwap16 ( x & 0xffff ) << 16 ) | ( ByteSwap16 ( x >> 16 ) );
44  }
45 
46  static inline uint64_t ByteSwap64 ( uint64_t x )
47  {
48  return ( ( ( uint64_t ) ByteSwap32 ( uint32_t( x & 0xffffffffull ) ) << 32 ) ) |
49  ( ByteSwap32 ( uint32_t( x >> 32 ) ) );
50  }
51 
52 #else
53 #ifdef __APPLE__
54  static inline uint16_t ByteSwap16 ( uint16_t x )
55  {
56  return CFSwapInt16(x);
57  }
58 
59  static inline uint32_t ByteSwap32 ( uint32_t x )
60  {
61  return CFSwapInt32(x);
62  }
63 
64  static inline uint64_t ByteSwap64 ( uint64_t x )
65  {
66  return CFSwapInt64(x);
67  }
68 
69 #else //LINUX
70 
71  static inline uint16_t ByteSwap16 ( uint16_t x )
72  {
73  return bswap_16(x);
74  }
75 
76  static inline uint32_t ByteSwap32 ( uint32_t x )
77  {
78  return bswap_32(x);
79  }
80 
81  static inline uint64_t ByteSwap64 ( uint64_t x )
82  {
83  return bswap_64(x);
84  }
85 
86 #endif
87 #endif
88 }
89 
90 #ifdef __linux__
91 #include <agx/PopDisableWarnings.h>
92 #endif
93 
94 
95 #endif /* _AGX_BYTESWAP_H_ */
static uint32_t ByteSwap32(uint32_t x)
Definition: byteswap.h:76
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
static uint16_t ByteSwap16(uint16_t x)
Definition: byteswap.h:71
static uint64_t ByteSwap64(uint64_t x)
Definition: byteswap.h:81