author | rubidium |
Wed, 09 Jul 2008 13:32:13 +0000 | |
branch | noai |
changeset 11126 | 72d4c9314c72 |
parent 11044 | 097ea3e7ec56 |
permissions | -rw-r--r-- |
9723 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9723
diff
changeset
|
3 |
/** @file endian_func.hpp Function to handling different endian machines. */ |
9723 | 4 |
|
5 |
#ifndef ENDIAN_FUNC_H |
|
6 |
#define ENDIAN_FUNC_H |
|
7 |
||
11044
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
8 |
#include "endian_type.hpp" |
9723 | 9 |
#include "bitmath_func.hpp" |
10 |
||
11 |
/* Setup alignment and conversion macros */ |
|
11044
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
12 |
#if TTD_ENDIAN == TTD_BIG_ENDIAN |
9723 | 13 |
#define FROM_BE16(x) (x) |
14 |
#define FROM_BE32(x) (x) |
|
15 |
#define TO_BE16(x) (x) |
|
16 |
#define TO_BE32(x) (x) |
|
17 |
#define TO_BE32X(x) (x) |
|
18 |
#define FROM_LE16(x) BSWAP16(x) |
|
19 |
#define FROM_LE32(x) BSWAP32(x) |
|
20 |
#define TO_LE16(x) BSWAP16(x) |
|
21 |
#define TO_LE32(x) BSWAP32(x) |
|
22 |
#define TO_LE32X(x) BSWAP32(x) |
|
23 |
#else |
|
24 |
#define FROM_BE16(x) BSWAP16(x) |
|
25 |
#define FROM_BE32(x) BSWAP32(x) |
|
26 |
#define TO_BE16(x) BSWAP16(x) |
|
27 |
#define TO_BE32(x) BSWAP32(x) |
|
28 |
#define TO_BE32X(x) BSWAP32(x) |
|
29 |
#define FROM_LE16(x) (x) |
|
30 |
#define FROM_LE32(x) (x) |
|
31 |
#define TO_LE16(x) (x) |
|
32 |
#define TO_LE32(x) (x) |
|
33 |
#define TO_LE32X(x) (x) |
|
11044
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
34 |
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */ |
9723 | 35 |
|
11126
72d4c9314c72
(svn r13684) [NoAI] -Sync: with trunk r13599:13683.
rubidium
parents:
11044
diff
changeset
|
36 |
static FORCEINLINE uint16 ReadLE16Aligned(const void *x) |
9723 | 37 |
{ |
38 |
return FROM_LE16(*(const uint16*)x); |
|
39 |
} |
|
40 |
||
11126
72d4c9314c72
(svn r13684) [NoAI] -Sync: with trunk r13599:13683.
rubidium
parents:
11044
diff
changeset
|
41 |
static FORCEINLINE uint16 ReadLE16Unaligned(const void *x) |
9723 | 42 |
{ |
11044
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
43 |
#if OTTD_ALIGNMENT == 1 |
9723 | 44 |
return ((const byte*)x)[0] | ((const byte*)x)[1] << 8; |
45 |
#else |
|
46 |
return FROM_LE16(*(const uint16*)x); |
|
11044
097ea3e7ec56
(svn r13600) [NoAI] -Sync: with trunk r13508:13599.
rubidium
parents:
10455
diff
changeset
|
47 |
#endif /* OTTD_ALIGNMENT == 1 */ |
9723 | 48 |
} |
49 |
||
50 |
#endif /* ENDIAN_FUNC_HPP */ |