Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
endianness.h
Go to the documentation of this file.
1
#ifndef _ENDIANNESS_H
2
#define _ENDIANNESS_H
3
double
DONTUSE__NXSwapBigDoubleToLittleEndian
(
double
x
);
4
5
#include "config.h"
6
7
#if defined (__HAIKU__) //For unknow reasons, Haiku don't fit into any case below
8
#include <endian.h>
9
#elif defined (__APPLE__) || defined (MACOSX) || defined (BSD) || defined (__FreeBSD__)
10
#include <machine/endian.h>
11
#else
12
13
#if defined (IRIX)
14
# include <sys/endian.h>
15
16
#elif !defined (_WIN32) && !defined (__CYGWIN__) && !defined (SOLARIS)
17
# include <endian.h>
18
#else
19
# define __BIG_ENDIAN 1
20
# define __LITTLE_ENDIAN 0
21
# define __BYTE_ORDER 0
22
#endif
23
#endif
24
#if defined (__APPLE__) || defined (MACOSX)
25
#include <machine/endian.h>
26
#if __BYTE_ORDER == __BIG_ENDIAN
27
# include <machine/byte_order.h>
28
# define le32_to_cpu( x ) ( NXSwapHostLongToLittle( x ) )
29
# define le16_to_cpu( x ) ( NXSwapHostShortToLittle( x ) )
30
# define le64_to_cpu( x ) ( DONTUSE__NXSwapBigDoubleToLittleEndian( x ) )
31
#else
32
# define le32_to_cpu( x ) (x)
33
# define le16_to_cpu( x ) (x)
34
# define le64_to_cpu( x ) (x)
35
#endif
36
#else
37
#if defined (IRIX) || (defined (__SVR4) && defined (__sun ) )
38
#include <sys/types.h>
39
# if BYTE_ORDER == BIG_ENDIAN
/* depends on MIPSEB or MIPSEL and SGIAPI */
40
# define le32_to_cpu( x ) \
41
( ( (x)<<24 ) \
42
|( ( (x)<<8 )&0x00FF0000 ) \
43
|( ( (uint32_t) (x)>>8 )&0x0000FF00 ) \
44
|( (uint32_t) (x)>>24 ) )
45
# define le16_to_cpu( x ) ( ( (x&0xFF)<<8 )|( (unsigned short) (x)>>8 ) )
46
# define le64_to_cpu( x ) ( DONTUSE__NXSwapBigDoubleToLittleEndian( x ) )
47
# else
48
# define le32_to_cpu( x ) (x)
49
# define le16_to_cpu( x ) (x)
50
# define le64_to_cpu( x ) (x)
51
# endif
52
53
#elif __BYTE_ORDER == __BIG_ENDIAN && !defined (BSD) && !defined (__FreeBSD__)
54
# include <byteswap.h>
55
# define le32_to_cpu( x ) ( bswap_32( x ) )
56
# define le16_to_cpu( x ) ( bswap_16( x ) )
57
# define le64_to_cpu( x ) ( DONTUSE__NXSwapBigDoubleToLittleEndian( x ) )
58
#else
59
# define le32_to_cpu( x ) (x)
60
# define le16_to_cpu( x ) (x)
61
# define le64_to_cpu( x ) (x)
62
#endif
63
#endif
64
65
inline
float
VSSwapHostFloatToLittle
(
float
x
)
66
{
67
union
LILfloat
68
{
69
float
f
;
70
unsigned
int
i
;
71
}
72
l;
73
l.f =
x
;
74
l.i =
le32_to_cpu
( l.i );
75
return
l.f;
76
}
77
78
inline
double
VSSwapHostDoubleToLittle
(
double
x
)
79
{
80
return
le64_to_cpu
( x );
81
}
82
83
inline
unsigned
int
VSSwapHostIntToLittle
(
unsigned
int
x
)
84
{
85
return
le32_to_cpu
( x );
86
}
87
88
inline
unsigned
short
VSSwapHostShortToLittle
(
unsigned
short
x
)
89
{
90
return
le16_to_cpu
( x );
91
}
92
93
inline
double
DONTUSE__NXSwapBigDoubleToLittleEndian
(
double
x
)
94
{
95
union
LILdubl
96
{
97
double
d
;
98
unsigned
int
i
[2];
99
}
100
l;
101
l.d =
x
;
102
unsigned
int
tmp =
le32_to_cpu
( l.i[0] );
103
l.i[0] =
le32_to_cpu
( l.i[1] );
104
l.i[1] = tmp;
105
return
l.d;
106
}
107
108
#endif //_ENDIANNESS_H
109
src
endianness.h
Generated on Fri May 29 2015 23:07:20 for Vegastrike 0.5.1 rc1 by
1.8.4