include/SDL_stdinc.h
changeset 3067 bcd41b269091
parent 3032 77c3e67f0740
child 3234 f8c02d0560d5
equal deleted inserted replaced
3066:8cbf68bdf81b 3067:bcd41b269091
    80 #endif
    80 #endif
    81 
    81 
    82 /* The number of elements in an array */
    82 /* The number of elements in an array */
    83 #define SDL_arraysize(array)	(sizeof(array)/sizeof(array[0]))
    83 #define SDL_arraysize(array)	(sizeof(array)/sizeof(array[0]))
    84 #define SDL_TABLESIZE(table)	SDL_arraysize(table)
    84 #define SDL_TABLESIZE(table)	SDL_arraysize(table)
       
    85 
       
    86 /* Use proper C++ casts when compiled as C++ to be compatible with the option
       
    87  -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above. */
       
    88 #ifdef __cplusplus
       
    89 #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
       
    90 #define SDL_static_cast(type, expression) static_cast<type>(expression)
       
    91 #else
       
    92 #define SDL_reinterpret_cast(type, expression) ((type)(expression))
       
    93 #define SDL_static_cast(type, expression) ((type)(expression))
       
    94 #endif
    85 
    95 
    86 /* Basic data types */
    96 /* Basic data types */
    87 typedef enum SDL_bool
    97 typedef enum SDL_bool
    88 {
    98 {
    89     SDL_FALSE = 0,
    99     SDL_FALSE = 0,
   296 	int u0, u1, u2;						\
   306 	int u0, u1, u2;						\
   297 	__asm__ __volatile__ (					\
   307 	__asm__ __volatile__ (					\
   298 		"cld\n\t"					\
   308 		"cld\n\t"					\
   299 		"rep ; stosl\n\t"				\
   309 		"rep ; stosl\n\t"				\
   300 		: "=&D" (u0), "=&a" (u1), "=&c" (u2)		\
   310 		: "=&D" (u0), "=&a" (u1), "=&c" (u2)		\
   301 		: "0" (dst), "1" (val), "2" ((Uint32)(len))	\
   311 		: "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, len))	\
   302 		: "memory" );					\
   312 		: "memory" );					\
   303 } while(0)
   313 } while(0)
   304 #endif
   314 #endif
   305 #ifndef SDL_memset4
   315 #ifndef SDL_memset4
   306 #define SDL_memset4(dst, val, len)		\
   316 #define SDL_memset4(dst, val, len)		\
   307 do {						\
   317 do {						\
   308 	unsigned _count = (len);		\
   318 	unsigned _count = (len);		\
   309 	unsigned _n = (_count + 3) / 4;		\
   319 	unsigned _n = (_count + 3) / 4;		\
   310 	Uint32 *_p = (Uint32 *)(dst);		\
   320 	Uint32 *_p = SDL_static_cast(Uint32 *, dst);		\
   311 	Uint32 _val = (val);			\
   321 	Uint32 _val = (val);			\
   312         switch (_count % 4) {			\
   322         switch (_count % 4) {			\
   313         case 0: do {    *_p++ = _val;		\
   323         case 0: do {    *_p++ = _val;		\
   314         case 3:         *_p++ = _val;		\
   324         case 3:         *_p++ = _val;		\
   315         case 2:         *_p++ = _val;		\
   325         case 2:         *_p++ = _val;		\
   335 		"1:\ttestb $1,%b4\n\t"					  \
   345 		"1:\ttestb $1,%b4\n\t"					  \
   336 		"je 2f\n\t"						  \
   346 		"je 2f\n\t"						  \
   337 		"movsb\n"						  \
   347 		"movsb\n"						  \
   338 		"2:"							  \
   348 		"2:"							  \
   339 		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
   349 		: "=&c" (u0), "=&D" (u1), "=&S" (u2)			  \
   340 		: "0" ((unsigned)(len)/4), "q" (len), "1" (dst),"2" (src) \
   350 		: "0" (SDL_static_cast(unsigned, len)/4), "q" (len), "1" (dst),"2" (src) \
   341 		: "memory" );						  \
   351 		: "memory" );						  \
   342 } while(0)
   352 } while(0)
   343 #endif
   353 #endif
   344 #ifndef SDL_memcpy
   354 #ifndef SDL_memcpy
   345 #ifdef HAVE_MEMCPY
   355 #ifdef HAVE_MEMCPY
   361 	int ecx, edi, esi;					\
   371 	int ecx, edi, esi;					\
   362 	__asm__ __volatile__ (					\
   372 	__asm__ __volatile__ (					\
   363 		"cld\n\t"					\
   373 		"cld\n\t"					\
   364 		"rep ; movsl"					\
   374 		"rep ; movsl"					\
   365 		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
   375 		: "=&c" (ecx), "=&D" (edi), "=&S" (esi)		\
   366 		: "0" ((unsigned)(len)), "1" (dst), "2" (src)	\
   376 		: "0" (SDL_static_cast(unsigned, len)), "1" (dst), "2" (src)	\
   367 		: "memory" );					\
   377 		: "memory" );					\
   368 } while(0)
   378 } while(0)
   369 #endif
   379 #endif
   370 #ifndef SDL_memcpy4
   380 #ifndef SDL_memcpy4
   371 #define SDL_memcpy4(dst, src, len)	SDL_memcpy(dst, src, (len) << 2)
   381 #define SDL_memcpy4(dst, src, len)	SDL_memcpy(dst, src, (len) << 2)
   373 
   383 
   374 #if defined(__GNUC__) && defined(i386)
   384 #if defined(__GNUC__) && defined(i386)
   375 #define SDL_revcpy(dst, src, len)			\
   385 #define SDL_revcpy(dst, src, len)			\
   376 do {							\
   386 do {							\
   377 	int u0, u1, u2;					\
   387 	int u0, u1, u2;					\
   378 	char *dstp = (char *)(dst);			\
   388 	char *dstp = SDL_static_cast(char *, dst);			\
   379 	char *srcp = (char *)(src);			\
   389 	char *srcp = SDL_static_cast(char *, src);			\
   380 	int n = (len);					\
   390 	int n = (len);					\
   381 	if ( n >= 4 ) {					\
   391 	if ( n >= 4 ) {					\
   382 	__asm__ __volatile__ (				\
   392 	__asm__ __volatile__ (				\
   383 		"std\n\t"				\
   393 		"std\n\t"				\
   384 		"rep ; movsl\n\t"			\
   394 		"rep ; movsl\n\t"			\