CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

lo_endian-msvc.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2004 Steve Harris
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2.1
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * $Id$
15 */
16
17 #ifndef LO_ENDIAN_H
18 #define LO_ENDIAN_H
19
20 #include <sys/types.h>
21
22 #ifdef _MSC_VER
23 #define inline __inline
24 #define uint64_t unsigned __int64
25 #define uint32_t unsigned __int32
26 #else
27 #include <stdint.h>
28 #endif
29
30 #ifdef WIN32
31 #include <winsock2.h>
32 #include <ws2tcpip.h>
33 #else
34 #include <netinet/in.h>
35 #endif
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #define lo_swap16(x) htons(x)
42
43 #define lo_swap32(x) htonl(x)
44
45 /* These macros come from the Linux kernel */
46
47 #ifndef lo_swap16
48 #define lo_swap16(x) \
49 ({ \
50 uint16_t __x = (x); \
51 ((uint16_t)( \
52 (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
53 (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
54 })
55 #warning USING UNOPTIMISED ENDIAN STUFF
56 #endif
57
58 #ifndef lo_swap32
59 #define lo_swap32(x) \
60 ({ \
61 uint32_t __x = (x); \
62 ((uint32_t)( \
63 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
64 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
65 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
66 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
67 })
68 #endif
69
70 #if 0
71 #ifndef lo_swap64
72 #define lo_swap64(x) \
73 ({ \
74 uint64_t __x = (x); \
75 ((uint64_t)( \
76 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
77 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
78 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
79 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
80 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
81 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
82 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
83 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
84 })
85 #endif
86 #else
87
88 typedef union {
89 uint64_t all;
90 struct {
91 uint32_t a;
92 uint32_t b;
93 } part;
94 } lo_split64;
95
96 static inline uint64_t lo_swap64(uint64_t x)
97 {
98 lo_split64 in, out;
99
100 in.all = x;
101 out.part.a = lo_swap32(in.part.b);
102 out.part.b = lo_swap32(in.part.a);
103
104 return out.all;
105 }
106 #endif
107
108 /* Host to OSC and OSC to Host conversion macros */
109
110 #if 0
111 #define lo_htoo16(x) (x)
112 #define lo_htoo32(x) (x)
113 #define lo_htoo64(x) (x)
114 #define lo_otoh16(x) (x)
115 #define lo_otoh32(x) (x)
116 #define lo_otoh64(x) (x)
117 #else
118 #define lo_htoo16 lo_swap16
119 #define lo_htoo32 lo_swap32
120 #define lo_htoo64 lo_swap64
121 #define lo_otoh16 lo_swap16
122 #define lo_otoh32 lo_swap32
123 #define lo_otoh64 lo_swap64
124 #endif
125
126 #ifdef __cplusplus
127 }
128 #endif
129
130 #ifdef _MSC_VER
131 #undef inline
132 #undef uint64_t
133 #undef uint32_t
134 #endif
135
136 #endif
137
138 /* vi:set ts=8 sts=4 sw=4: */