Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 77300
Collapse All | Expand All

(-)SDL_endian.h (-29 / +92 lines)
Lines 22-28 Link Here
22
22
23
#ifdef SAVE_RCSID
23
#ifdef SAVE_RCSID
24
static char rcsid =
24
static char rcsid =
25
 "@(#) $Id: SDL_endian.h,v 1.6 2004/01/04 16:49:07 slouken Exp $";
25
 "@(#) $Id: SDL_endian.h,v 1.11 2004/11/27 23:11:20 pmandin Exp $";
26
#endif
26
#endif
27
27
28
/* Functions for reading and writing endian-specific values */
28
/* Functions for reading and writing endian-specific values */
Lines 54-108 Link Here
54
extern "C" {
54
extern "C" {
55
#endif
55
#endif
56
56
57
/* The macros used to swap values */
58
/* Try to use superfast macros on systems that support them */
59
#ifdef linux
60
#include <asm/byteorder.h>
61
#ifdef __arch__swab16
62
#define SDL_Swap16  __arch__swab16
63
#endif
64
#ifdef __arch__swab32
65
#define SDL_Swap32  __arch__swab32
66
#endif
67
#endif /* linux */
68
/* Use inline functions for compilers that support them, and static
57
/* Use inline functions for compilers that support them, and static
69
   functions for those that do not.  Because these functions become
58
   functions for those that do not.  Because these functions become
70
   static for compilers that do not support inline functions, this
59
   static for compilers that do not support inline functions, this
71
   header should only be included in files that actually use them.
60
   header should only be included in files that actually use them.
72
*/
61
*/
73
#ifndef SDL_Swap16
62
#if defined(__GNUC__) && defined(__i386__)
74
static __inline__ Uint16 SDL_Swap16(Uint16 D) {
63
static __inline__ Uint16 SDL_Swap16(Uint16 x)
75
	return((D<<8)|(D>>8));
64
{
65
	__asm__("xchgb %b0,%h0" : "=q" (x) :  "0" (x));
66
	return x;
67
}
68
#elif defined(__GNUC__) && defined(__x86_64__)
69
static __inline__ Uint16 SDL_Swap16(Uint16 x)
70
{
71
	__asm__("xchgb %b0,%h0" : "=q" (x) :  "0" (x));
72
	return x;
73
}
74
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
75
static __inline__ Uint16 SDL_Swap16(Uint16 x)
76
{
77
	Uint16 result;
78
79
	__asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x));
80
	return result;
81
}
82
#elif defined(__GNUC__) && defined(__M68000__)
83
static __inline__ Uint16 SDL_Swap16(Uint16 x)
84
{
85
	__asm__("rorw #8,%0" : "=d" (x) :  "0" (x) : "cc");
86
	return x;
87
}
88
#else
89
static __inline__ Uint16 SDL_Swap16(Uint16 x) {
90
	return((x<<8)|(x>>8));
76
}
91
}
77
#endif
92
#endif
78
#ifndef SDL_Swap32
93
79
static __inline__ Uint32 SDL_Swap32(Uint32 D) {
94
#if defined(__GNUC__) && defined(__i386__)
80
	return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));
95
static __inline__ Uint32 SDL_Swap32(Uint32 x)
96
{
97
	__asm__("bswap %0" : "=r" (x) : "0" (x));
98
	return x;
99
}
100
#elif defined(__GNUC__) && defined(__x86_64__)
101
static __inline__ Uint32 SDL_Swap32(Uint32 x)
102
{
103
	__asm__("bswapl %0" : "=r" (x) : "0" (x));
104
	return x;
105
}
106
#elif defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))
107
static __inline__ Uint32 SDL_Swap32(Uint32 x)
108
{
109
	Uint32 result;
110
111
	__asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x));
112
	__asm__("rlwimi %0,%2,8,8,15"   : "=&r" (result) : "0" (result),    "r" (x));
113
	__asm__("rlwimi %0,%2,24,0,7"   : "=&r" (result) : "0" (result),    "r" (x));
114
	return result;
115
}
116
#elif defined(__GNUC__) && defined(__M68000__)
117
static __inline__ Uint32 SDL_Swap32(Uint32 x)
118
{
119
	__asm__("rorw	#8,%0\n\tswap	%0\n\tror	#8,%0" : "=d" (x) :  "0" (x) : "cc");
120
	return x;
121
}
122
#else
123
static __inline__ Uint32 SDL_Swap32(Uint32 x) {
124
	return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24));
81
}
125
}
82
#endif
126
#endif
127
83
#ifdef SDL_HAS_64BIT_TYPE
128
#ifdef SDL_HAS_64BIT_TYPE
84
#ifndef SDL_Swap64
129
#if defined(__GNUC__) && defined(__i386__)
85
static __inline__ Uint64 SDL_Swap64(Uint64 val) {
130
static __inline__ Uint64 SDL_Swap64(Uint64 x)
131
{
132
	union { 
133
		struct { Uint32 a,b; } s;
134
		Uint64 u;
135
	} v;
136
	v.u = x;
137
	__asm__("bswapl %0 ; bswapl %1 ; xchgl %0,%1" 
138
	        : "=r" (v.s.a), "=r" (v.s.b) 
139
	        : "0" (v.s.a), "1" (v.s.b)); 
140
	return v.u;
141
}
142
#elif defined(__GNUC__) && defined(__x86_64__)
143
static __inline__ Uint64 SDL_Swap64(Uint64 x)
144
{
145
	__asm__("bswapq %0" : "=r" (x) : "0" (x));
146
	return x;
147
}
148
#else
149
static __inline__ Uint64 SDL_Swap64(Uint64 x)
150
{
86
	Uint32 hi, lo;
151
	Uint32 hi, lo;
87
152
88
	/* Separate into high and low 32-bit values and swap them */
153
	/* Separate into high and low 32-bit values and swap them */
89
	lo = (Uint32)(val&0xFFFFFFFF);
154
	lo = (Uint32)(x&0xFFFFFFFF);
90
	val >>= 32;
155
	x >>= 32;
91
	hi = (Uint32)(val&0xFFFFFFFF);
156
	hi = (Uint32)(x&0xFFFFFFFF);
92
	val = SDL_Swap32(lo);
157
	x = SDL_Swap32(lo);
93
	val <<= 32;
158
	x <<= 32;
94
	val |= SDL_Swap32(hi);
159
	x |= SDL_Swap32(hi);
95
	return(val);
160
	return(x);
96
}
161
}
97
#endif
162
#endif
98
#else
163
#else
99
#ifndef SDL_Swap64
100
/* This is mainly to keep compilers from complaining in SDL code.
164
/* This is mainly to keep compilers from complaining in SDL code.
101
   If there is no real 64-bit datatype, then compilers will complain about
165
   If there is no real 64-bit datatype, then compilers will complain about
102
   the fake 64-bit datatype that SDL provides when it compiles user code.
166
   the fake 64-bit datatype that SDL provides when it compiles user code.
103
*/
167
*/
104
#define SDL_Swap64(X)	(X)
168
#define SDL_Swap64(X)	(X)
105
#endif
106
#endif /* SDL_HAS_64BIT_TYPE */
169
#endif /* SDL_HAS_64BIT_TYPE */
107
170
108
171

Return to bug 77300