Fix a typo in xas.1 (thanks to Marcell)
[amule.git] / src / ArchSpecific.h
blob019d645e891e695c937232513d34870db87e586b
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 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
34 #define ENDIAN_SWAP_16(x) (wxUINT16_SWAP_ON_BE(x))
35 #define ENDIAN_SWAP_I_16(x) x = wxUINT16_SWAP_ON_BE(x)
36 #define ENDIAN_SWAP_32(x) (wxUINT32_SWAP_ON_BE(x))
37 #define ENDIAN_SWAP_I_32(x) x = wxUINT32_SWAP_ON_BE(x)
39 #if ((defined __GNUC__) && __GNUC__ >= 2) || defined (_MSC_VER) || (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550))
40 #define ENDIAN_SWAP_64(x) (wxUINT64_SWAP_ON_BE(x))
41 #define ENDIAN_SWAP_I_64(x) x = wxUINT64_SWAP_ON_BE(x)
42 #endif
44 // ntohs
45 #define ENDIAN_NTOHS(x) ( wxUINT16_SWAP_ON_LE(x) )
46 // ntohl
47 #define ENDIAN_NTOHL(x) ( wxUINT32_SWAP_ON_LE(x) )
48 // new
49 #define ENDIAN_NTOHLL(x) ( wxUINT64_SWAP_ON_LE(x) )
50 // htons
51 #define ENDIAN_HTONS(x) ( wxUINT16_SWAP_ON_LE(x) )
52 // htonl
53 #define ENDIAN_HTONL(x) ( wxUINT32_SWAP_ON_LE(x) )
54 // new
55 #define ENDIAN_HTONLL(x) ( wxUINT64_SWAP_ON_LE(x) )
58 /**
59 * Returns the value in the given bytestream.
61 * The value is returned exactly as it is found.
63 // \{
64 inline uint16 RawPeekUInt16(const void* p);
65 inline uint32 RawPeekUInt32(const void* p);
66 inline uint64 RawPeekUInt64(const void* p);
67 // \}
71 /**
72 * Writes the specified value into the bytestream.
74 * The value is written exactly as it is.
76 // \{
77 inline void RawPokeUInt16(void* p, uint16 nVal);
78 inline void RawPokeUInt32(void* p, uint32 nVal);
79 inline void RawPokeUInt64(void* p, uint64 nVal);
80 // \}
83 /**
84 * Returns the value in the given bytestream.
86 * The value is returned as little-endian.
88 // \{
89 inline uint8 PeekUInt8(const void* p);
90 inline uint16 PeekUInt16(const void* p);
91 inline uint32 PeekUInt32(const void* p);
92 inline uint64 PeekUInt64(const void* p);
93 // \}
96 /**
97 * Writes the specified value into the bytestream.
99 * The value is written as little-endian.
101 // \{
102 inline void PokeUInt8(void* p, uint8 nVal);
103 inline void PokeUInt16(void* p, uint16 nVal);
104 inline void PokeUInt32(void* p, uint32 nVal);
105 inline void PokeUInt64(void* p, uint64 nVal);
106 // \}
109 #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(GCC_USES_STRICT_ALIASING)
110 #define ARCHSPECIFIC_USE_MEMCPY
111 #endif
114 ///////////////////////////////////////////////////////////////////////////////
115 // Peek - helper functions for read-accessing memory without modifying the memory pointer
117 inline uint16 RawPeekUInt16(const void* p)
119 #ifndef ARCHSPECIFIC_USE_MEMCPY
120 return *((uint16*)p);
121 #else
122 uint16 value;
123 memcpy( &value, p, sizeof( uint16 ) );
124 return value;
125 #endif
129 inline uint32 RawPeekUInt32(const void* p)
131 #ifndef ARCHSPECIFIC_USE_MEMCPY
132 return *((uint32*)p);
133 #else
134 uint32 value;
135 memcpy( &value, p, sizeof( uint32 ) );
136 return value;
137 #endif
141 inline uint64 RawPeekUInt64(const void* p)
143 #ifndef ARCHSPECIFIC_USE_MEMCPY
144 return *((uint64*)p);
145 #else
146 uint64 value;
147 memcpy( &value, p, sizeof( uint64 ) );
148 return value;
149 #endif
153 inline uint8 PeekUInt8(const void* p)
155 return *((uint8*)p);
159 inline uint16 PeekUInt16(const void* p)
161 return ENDIAN_SWAP_16( RawPeekUInt16( p ) );
165 inline uint32 PeekUInt32(const void* p)
167 return ENDIAN_SWAP_32( RawPeekUInt32( p ) );
170 inline uint64 PeekUInt64(const void* p)
172 return ENDIAN_SWAP_64( RawPeekUInt64( p ) );
177 ///////////////////////////////////////////////////////////////////////////////
178 // Poke - helper functions for write-accessing memory without modifying the memory pointer
181 inline void RawPokeUInt16(void* p, uint16 nVal)
183 #ifndef ARCHSPECIFIC_USE_MEMCPY
184 *((uint16*)p) = nVal;
185 #else
186 memcpy( p, &nVal, sizeof(uint16) );
187 #endif
191 inline void RawPokeUInt32(void* p, uint32 nVal)
193 #ifndef ARCHSPECIFIC_USE_MEMCPY
194 *((uint32*)p) = nVal;
195 #else
196 memcpy( p, &nVal, sizeof(uint32) );
197 #endif
201 inline void RawPokeUInt64(void* p, uint64 nVal)
203 #ifndef ARCHSPECIFIC_USE_MEMCPY
204 *((uint64*)p) = nVal;
205 #else
206 memcpy( p, &nVal, sizeof(uint64) );
207 #endif
211 inline void PokeUInt8(void* p, uint8 nVal)
213 *((uint8*)p) = nVal;
217 inline void PokeUInt16(void* p, uint16 nVal)
219 RawPokeUInt16( p, ENDIAN_SWAP_16( nVal ) );
223 inline void PokeUInt32(void* p, uint32 nVal)
225 RawPokeUInt32( p, ENDIAN_SWAP_32( nVal ) );
228 inline void PokeUInt64(void* p, uint64 nVal)
230 RawPokeUInt64( p, ENDIAN_SWAP_64( nVal ) );
233 // Don't pollute the preprocessor namespace
234 #undef ARCHSPECIFIC_USE_MEMCPY
236 #endif
237 // File_checked_for_headers