summaryrefslogtreecommitdiffstats
path: root/src/VBox/GuestHost/OpenGL/include/cr_endian.h
blob: 29366e8457ffeb3bfdaf50817a88b4332e4cde54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef CR_ENDIAN_H
#define CR_ENDIAN_H

#define CR_LITTLE_ENDIAN 0
#define CR_BIG_ENDIAN 1

#include <iprt/cdefs.h>

#ifdef __cplusplus 
extern "C" {
#endif

extern DECLEXPORT(char) crDetermineEndianness( void );

#ifdef WINDOWS
typedef __int64 CR64BitType;
#else
#ifndef __STDC__
typedef long long CR64BitType;
#else
typedef struct  _CR64BitType
{
    unsigned int  lo;
    unsigned int  hi;

} CR64BitType;
#endif
#endif

#define SWAP8(x) x
#define SWAP16(x) (short) ((((x) & 0x00FF) << 8) | (((x) & 0xFF00) >> 8))
#define SWAP32(x) ((((x) & 0x000000FF) << 24) | \
		   (((x) & 0x0000FF00) << 8)  | \
		   (((x) & 0x00FF0000) >> 8)  | \
		   (((x) & 0xFF000000) >> 24))
#ifdef WINDOWS
#define SWAP64(x) \
	 ((((x) & 0xFF00000000000000L) >> 56) | \
		(((x) & 0x00FF000000000000L) >> 40) | \
		(((x) & 0x0000FF0000000000L) >> 24) | \
		(((x) & 0x000000FF00000000L) >> 8)  | \
		(((x) & 0x00000000FF000000L) << 8)  | \
		(((x) & 0x0000000000FF0000L) << 24) | \
		(((x) & 0x000000000000FF00L) << 40) | \
		(((x) & 0x00000000000000FFL) << 56))
#else
#ifndef __STDC__
#define SWAP64(x) \
	  x = ((((x) & 0xFF00000000000000LL) >> 56) | \
		(((x) & 0x00FF000000000000LL) >> 40) | \
		(((x) & 0x0000FF0000000000LL) >> 24) | \
		(((x) & 0x000000FF00000000LL) >> 8)  | \
		(((x) & 0x00000000FF000000LL) << 8)  | \
		(((x) & 0x0000000000FF0000LL) << 24) | \
		(((x) & 0x000000000000FF00LL) << 40) | \
		(((x) & 0x00000000000000FFLL) << 56))
#else
#define SWAP64(x) \
   {                                            \
      GLubyte *bytes = (GLubyte *) &(x);    \
      GLubyte tmp = bytes[0];                   \
      bytes[0] = bytes[7];                      \
      bytes[7] = tmp;                           \
      tmp = bytes[1];                           \
      bytes[1] = bytes[6];                      \
      bytes[6] = tmp;                           \
      tmp = bytes[2];                           \
      bytes[2] = bytes[5];                      \
      bytes[5] = tmp;                           \
      tmp = bytes[4];                           \
      bytes[4] = bytes[3];                      \
      bytes[3] = tmp;                           \
   }
#endif
#endif

DECLEXPORT(double) SWAPDOUBLE( double d );

#define SWAPFLOAT(x) ( ((*((int *) &(x)) & 0x000000FF) << 24) | \
                       ((*((int *) &(x)) & 0x0000FF00) << 8) | \
                       ((*((int *) &(x)) & 0x00FF0000) >> 8) | \
                       ((*((int *) &(x)) & 0xFF000000) >> 24))


#ifdef __cplusplus
} /* extern "C" */
#endif
 

#endif /* CR_ENDIAN_H */