comparison src/mendian.h @ 36:bef14a3387a1

Add missing files.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Aug 2013 20:53:49 +0300
parents
children
comparison
equal deleted inserted replaced
35:06ab31de6d14 36:bef14a3387a1
1 #ifndef MENDIAN_H
2 #define MENDIAN_H 1
3
4 #include "mtypes.h"
5
6 /* Endianess swapping macros
7 */
8 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \
9 (Uint16) ((Uint16) (value) >> 8) | \
10 (Uint16) ((Uint16) (value) << 8)) )
11
12
13 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \
14 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \
15 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \
16 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \
17 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24)))
18
19
20 /* Macros that swap only when needed ...
21 */
22 #if (BYTEORDER == BIG_ENDIAN)
23 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
24 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
25 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value)
26 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value)
27
28 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value))
29 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value))
30 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value))
31 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value))
32
33 #elif (BYTEORDER == LIL_ENDIAN)
34
35 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value))
36 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value))
37 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value))
38 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value))
39
40 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
41 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
42 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value)
43 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value)
44
45 #endif
46
47
48 #endif