debian: fix build-deps for focal
[amule.git] / src / ArchSpecific.h
blob35f983af57ee176d52e06738137c3292bf8c5ca6
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef ARCHSPECIFIC_H
27 #define ARCHSPECIFIC_H
29 #include "Types.h"
30 #include "config.h"
32 #define ENDIAN_SWAP_16(x) (wxUINT16_SWAP_ON_BE(x))
33 #define ENDIAN_SWAP_I_16(x) x = wxUINT16_SWAP_ON_BE(x)
34 #define ENDIAN_SWAP_32(x) (wxUINT32_SWAP_ON_BE(x))
35 #define ENDIAN_SWAP_I_32(x) x = wxUINT32_SWAP_ON_BE(x)
37 #if ((defined __GNUC__) && __GNUC__ >= 2) || defined (_MSC_VER) || (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550))
38 #define ENDIAN_SWAP_64(x) (wxUINT64_SWAP_ON_BE(x))
39 #define ENDIAN_SWAP_I_64(x) x = wxUINT64_SWAP_ON_BE(x)
40 #endif
42 // ntohs
43 #define ENDIAN_NTOHS(x) ( wxUINT16_SWAP_ON_LE(x) )
44 // ntohl
45 #define ENDIAN_NTOHL(x) ( wxUINT32_SWAP_ON_LE(x) )
46 // new
47 #define ENDIAN_NTOHLL(x) ( wxUINT64_SWAP_ON_LE(x) )
48 // htons
49 #define ENDIAN_HTONS(x) ( wxUINT16_SWAP_ON_LE(x) )
50 // htonl
51 #define ENDIAN_HTONL(x) ( wxUINT32_SWAP_ON_LE(x) )
52 // new
53 #define ENDIAN_HTONLL(x) ( wxUINT64_SWAP_ON_LE(x) )
56 /**
57 * Returns the value in the given bytestream.
59 * The value is returned exactly as it is found.
61 // \{
62 inline uint16 RawPeekUInt16(const void* p);
63 inline uint32 RawPeekUInt32(const void* p);
64 inline uint64 RawPeekUInt64(const void* p);
65 // \}
69 /**
70 * Writes the specified value into the bytestream.
72 * The value is written exactly as it is.
74 // \{
75 inline void RawPokeUInt16(void* p, uint16 nVal);
76 inline void RawPokeUInt32(void* p, uint32 nVal);
77 inline void RawPokeUInt64(void* p, uint64 nVal);
78 // \}
81 /**
82 * Returns the value in the given bytestream.
84 * The value is returned as little-endian.
86 // \{
87 inline uint8 PeekUInt8(const void* p);
88 inline uint16 PeekUInt16(const void* p);
89 inline uint32 PeekUInt32(const void* p);
90 inline uint64 PeekUInt64(const void* p);
91 // \}
94 /**
95 * Writes the specified value into the bytestream.
97 * The value is written as little-endian.
99 // \{
100 inline void PokeUInt8(void* p, uint8 nVal);
101 inline void PokeUInt16(void* p, uint16 nVal);
102 inline void PokeUInt32(void* p, uint32 nVal);
103 inline void PokeUInt64(void* p, uint64 nVal);
104 // \}
107 #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(GCC_USES_STRICT_ALIASING)
108 #define ARCHSPECIFIC_USE_MEMCPY
109 #endif
112 ///////////////////////////////////////////////////////////////////////////////
113 // Peek - helper functions for read-accessing memory without modifying the memory pointer
115 inline uint16 RawPeekUInt16(const void* p)
117 #ifndef ARCHSPECIFIC_USE_MEMCPY
118 return *((uint16*)p);
119 #else
120 uint16 value;
121 memcpy( &value, p, sizeof( uint16 ) );
122 return value;
123 #endif
127 inline uint32 RawPeekUInt32(const void* p)
129 #ifndef ARCHSPECIFIC_USE_MEMCPY
130 return *((uint32*)p);
131 #else
132 uint32 value;
133 memcpy( &value, p, sizeof( uint32 ) );
134 return value;
135 #endif
139 inline uint64 RawPeekUInt64(const void* p)
141 #ifndef ARCHSPECIFIC_USE_MEMCPY
142 return *((uint64*)p);
143 #else
144 uint64 value;
145 memcpy( &value, p, sizeof( uint64 ) );
146 return value;
147 #endif
151 inline uint8 PeekUInt8(const void* p)
153 return *((uint8*)p);
157 inline uint16 PeekUInt16(const void* p)
159 return ENDIAN_SWAP_16( RawPeekUInt16( p ) );
163 inline uint32 PeekUInt32(const void* p)
165 return ENDIAN_SWAP_32( RawPeekUInt32( p ) );
168 inline uint64 PeekUInt64(const void* p)
170 return ENDIAN_SWAP_64( RawPeekUInt64( p ) );
175 ///////////////////////////////////////////////////////////////////////////////
176 // Poke - helper functions for write-accessing memory without modifying the memory pointer
179 inline void RawPokeUInt16(void* p, uint16 nVal)
181 #ifndef ARCHSPECIFIC_USE_MEMCPY
182 *((uint16*)p) = nVal;
183 #else
184 memcpy( p, &nVal, sizeof(uint16) );
185 #endif
189 inline void RawPokeUInt32(void* p, uint32 nVal)
191 #ifndef ARCHSPECIFIC_USE_MEMCPY
192 *((uint32*)p) = nVal;
193 #else
194 memcpy( p, &nVal, sizeof(uint32) );
195 #endif
199 inline void RawPokeUInt64(void* p, uint64 nVal)
201 #ifndef ARCHSPECIFIC_USE_MEMCPY
202 *((uint64*)p) = nVal;
203 #else
204 memcpy( p, &nVal, sizeof(uint64) );
205 #endif
209 inline void PokeUInt8(void* p, uint8 nVal)
211 *((uint8*)p) = nVal;
215 inline void PokeUInt16(void* p, uint16 nVal)
217 RawPokeUInt16( p, ENDIAN_SWAP_16( nVal ) );
221 inline void PokeUInt32(void* p, uint32 nVal)
223 RawPokeUInt32( p, ENDIAN_SWAP_32( nVal ) );
226 inline void PokeUInt64(void* p, uint64 nVal)
228 RawPokeUInt64( p, ENDIAN_SWAP_64( nVal ) );
231 // Don't pollute the preprocessor namespace
232 #undef ARCHSPECIFIC_USE_MEMCPY
234 #endif
235 // File_checked_for_headers