VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_endian.h@ 71880

Last change on this file since 71880 was 69474, checked in by vboxsync, 7 years ago

*: scm updates - header files should have 'svn:keywords=Id Revision' too (doesn't mean they have to use them).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 2.5 KB
Line 
1#ifndef CR_ENDIAN_H
2#define CR_ENDIAN_H
3
4#define CR_LITTLE_ENDIAN 0
5#define CR_BIG_ENDIAN 1
6
7#include <iprt/cdefs.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13extern DECLEXPORT(char) crDetermineEndianness( void );
14
15#ifdef WINDOWS
16typedef __int64 CR64BitType;
17#else
18#ifndef __STDC__
19typedef long long CR64BitType;
20#else
21typedef struct _CR64BitType
22{
23 unsigned int lo;
24 unsigned int hi;
25
26} CR64BitType;
27#endif
28#endif
29
30#define SWAP8(x) x
31#define SWAP16(x) (short) ((((x) & 0x00FF) << 8) | (((x) & 0xFF00) >> 8))
32#define SWAP32(x) ((((x) & 0x000000FF) << 24) | \
33 (((x) & 0x0000FF00) << 8) | \
34 (((x) & 0x00FF0000) >> 8) | \
35 (((x) & 0xFF000000) >> 24))
36#ifdef WINDOWS
37#define SWAP64(x) \
38 ((((x) & 0xFF00000000000000L) >> 56) | \
39 (((x) & 0x00FF000000000000L) >> 40) | \
40 (((x) & 0x0000FF0000000000L) >> 24) | \
41 (((x) & 0x000000FF00000000L) >> 8) | \
42 (((x) & 0x00000000FF000000L) << 8) | \
43 (((x) & 0x0000000000FF0000L) << 24) | \
44 (((x) & 0x000000000000FF00L) << 40) | \
45 (((x) & 0x00000000000000FFL) << 56))
46#else
47#ifndef __STDC__
48#define SWAP64(x) \
49 x = ((((x) & 0xFF00000000000000LL) >> 56) | \
50 (((x) & 0x00FF000000000000LL) >> 40) | \
51 (((x) & 0x0000FF0000000000LL) >> 24) | \
52 (((x) & 0x000000FF00000000LL) >> 8) | \
53 (((x) & 0x00000000FF000000LL) << 8) | \
54 (((x) & 0x0000000000FF0000LL) << 24) | \
55 (((x) & 0x000000000000FF00LL) << 40) | \
56 (((x) & 0x00000000000000FFLL) << 56))
57#else
58#define SWAP64(x) \
59 { \
60 GLubyte *bytes = (GLubyte *) &(x); \
61 GLubyte tmp = bytes[0]; \
62 bytes[0] = bytes[7]; \
63 bytes[7] = tmp; \
64 tmp = bytes[1]; \
65 bytes[1] = bytes[6]; \
66 bytes[6] = tmp; \
67 tmp = bytes[2]; \
68 bytes[2] = bytes[5]; \
69 bytes[5] = tmp; \
70 tmp = bytes[4]; \
71 bytes[4] = bytes[3]; \
72 bytes[3] = tmp; \
73 }
74#endif
75#endif
76
77DECLEXPORT(double) SWAPDOUBLE( double d );
78
79#define SWAPFLOAT(x) ( ((*((int *) &(x)) & 0x000000FF) << 24) | \
80 ((*((int *) &(x)) & 0x0000FF00) << 8) | \
81 ((*((int *) &(x)) & 0x00FF0000) >> 8) | \
82 ((*((int *) &(x)) & 0xFF000000) >> 24))
83
84
85#ifdef __cplusplus
86} /* extern "C" */
87#endif
88
89
90#endif /* CR_ENDIAN_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette