From: "Markus F.X.J. Oberhumer"
authorSam Lantinga <slouken@lokigames.com>
Sat, 07 Jul 2001 20:20:17 +0000
changeset 91e85e03f195b4
parent 90 ee1f71c10889
child 92 dab667b72ccc
From: "Markus F.X.J. Oberhumer"
Subject: SDL CVS patches

below you will find some small patches against the
current SDL CVS.

It adresses these things:

1) Use "&" instead of "%" in some cases. For negative
signed integers (x % 8) is not always (x & 7),
and the compiler can produce slightly faster
code when using "&" here.

2) Some const issues.
src/video/SDL_blit.h
src/video/SDL_blit_0.c
src/video/SDL_blit_1.c
src/video/SDL_blit_N.c
src/video/dga/SDL_dgavideo.c
src/video/fbcon/SDL_fbevents.c
src/video/fbcon/SDL_fbvideo.c
src/video/x11/SDL_x11modes.c
     1.1 --- a/src/video/SDL_blit.h	Sat Jul 07 08:08:42 2001 +0000
     1.2 +++ b/src/video/SDL_blit.h	Sat Jul 07 20:20:17 2001 +0000
     1.3 @@ -384,7 +384,7 @@
     1.4  /* 8-times unrolled loop */
     1.5  #define DUFFS_LOOP8(pixel_copy_increment, width)			\
     1.6  { int n = (width+7)/8;							\
     1.7 -	switch (width % 8) {						\
     1.8 +	switch (width & 7) {						\
     1.9  	case 0: do {	pixel_copy_increment;				\
    1.10  	case 7:		pixel_copy_increment;				\
    1.11  	case 6:		pixel_copy_increment;				\
    1.12 @@ -400,7 +400,7 @@
    1.13  /* 4-times unrolled loop */
    1.14  #define DUFFS_LOOP4(pixel_copy_increment, width)			\
    1.15  { int n = (width+3)/4;							\
    1.16 -	switch (width % 4) {						\
    1.17 +	switch (width & 3) {						\
    1.18  	case 0: do {	pixel_copy_increment;				\
    1.19  	case 3:		pixel_copy_increment;				\
    1.20  	case 2:		pixel_copy_increment;				\
     2.1 --- a/src/video/SDL_blit_0.c	Sat Jul 07 08:08:42 2001 +0000
     2.2 +++ b/src/video/SDL_blit_0.c	Sat Jul 07 20:20:17 2001 +0000
     2.3 @@ -55,7 +55,7 @@
     2.4  		while ( height-- ) {
     2.5  		        Uint8 byte = 0, bit;
     2.6  	    		for ( c=0; c<width; ++c ) {
     2.7 -				if ( (c%8) == 0 ) {
     2.8 +				if ( (c&7) == 0 ) {
     2.9  					byte = *src++;
    2.10  				}
    2.11  				bit = (byte&0x80)>>7;
    2.12 @@ -72,7 +72,7 @@
    2.13  		while ( height-- ) {
    2.14  		        Uint8 byte = 0, bit;
    2.15  	    		for ( c=0; c<width; ++c ) {
    2.16 -				if ( (c%8) == 0 ) {
    2.17 +				if ( (c&7) == 0 ) {
    2.18  					byte = *src++;
    2.19  				}
    2.20  				bit = (byte&0x80)>>7;
    2.21 @@ -108,7 +108,7 @@
    2.22  	while ( height-- ) {
    2.23  	        Uint8 byte = 0, bit;
    2.24  	    	for ( c=0; c<width; ++c ) {
    2.25 -			if ( (c%8) == 0 ) {
    2.26 +			if ( (c&7) == 0 ) {
    2.27  				byte = *src++;
    2.28  			}
    2.29  			bit = (byte&0x80)>>7;
    2.30 @@ -142,7 +142,7 @@
    2.31  	while ( height-- ) {
    2.32  	        Uint8 byte = 0, bit;
    2.33  	    	for ( c=0; c<width; ++c ) {
    2.34 -			if ( (c%8) == 0 ) {
    2.35 +			if ( (c&7) == 0 ) {
    2.36  				byte = *src++;
    2.37  			}
    2.38  			bit = (byte&0x80)>>7;
    2.39 @@ -180,7 +180,7 @@
    2.40  	while ( height-- ) {
    2.41  	        Uint8 byte = 0, bit;
    2.42  	    	for ( c=0; c<width; ++c ) {
    2.43 -			if ( (c%8) == 0 ) {
    2.44 +			if ( (c&7) == 0 ) {
    2.45  				byte = *src++;
    2.46  			}
    2.47  			bit = (byte&0x80)>>7;
    2.48 @@ -214,7 +214,7 @@
    2.49  		while ( height-- ) {
    2.50  		        Uint8  byte = 0, bit;
    2.51  	    		for ( c=0; c<width; ++c ) {
    2.52 -				if ( (c%8) == 0 ) {
    2.53 +				if ( (c&7) == 0 ) {
    2.54  					byte = *src++;
    2.55  				}
    2.56  				bit = (byte&0x80)>>7;
    2.57 @@ -231,7 +231,7 @@
    2.58  		while ( height-- ) {
    2.59  		        Uint8  byte = 0, bit;
    2.60  	    		for ( c=0; c<width; ++c ) {
    2.61 -				if ( (c%8) == 0 ) {
    2.62 +				if ( (c&7) == 0 ) {
    2.63  					byte = *src++;
    2.64  				}
    2.65  				bit = (byte&0x80)>>7;
    2.66 @@ -266,7 +266,7 @@
    2.67  	while ( height-- ) {
    2.68  	        Uint8 byte = 0, bit;
    2.69  	    	for ( c=0; c<width; ++c ) {
    2.70 -			if ( (c%8) == 0 ) {
    2.71 +			if ( (c&7) == 0 ) {
    2.72  				byte = *src++;
    2.73  			}
    2.74  			bit = (byte&0x80)>>7;
    2.75 @@ -299,7 +299,7 @@
    2.76  	while ( height-- ) {
    2.77  	        Uint8  byte = 0, bit;
    2.78  	    	for ( c=0; c<width; ++c ) {
    2.79 -			if ( (c%8) == 0 ) {
    2.80 +			if ( (c&7) == 0 ) {
    2.81  				byte = *src++;
    2.82  			}
    2.83  			bit = (byte&0x80)>>7;
    2.84 @@ -333,7 +333,7 @@
    2.85  	while ( height-- ) {
    2.86  	        Uint8 byte = 0, bit;
    2.87  	    	for ( c=0; c<width; ++c ) {
    2.88 -			if ( (c%8) == 0 ) {
    2.89 +			if ( (c&7) == 0 ) {
    2.90  				byte = *src++;
    2.91  			}
    2.92  			bit = (byte&0x80)>>7;
    2.93 @@ -369,7 +369,7 @@
    2.94  	while ( height-- ) {
    2.95  	        Uint8 byte = 0, bit;
    2.96  	    	for ( c=0; c<width; ++c ) {
    2.97 -			if ( (c%8) == 0 ) {
    2.98 +			if ( (c&7) == 0 ) {
    2.99  				byte = *src++;
   2.100  			}
   2.101  			bit = (byte&0x80)>>7;
   2.102 @@ -416,7 +416,7 @@
   2.103  	while ( height-- ) {
   2.104  	        Uint8  byte = 0, bit;
   2.105  	    	for ( c=0; c<width; ++c ) {
   2.106 -			if ( (c%8) == 0 ) {
   2.107 +			if ( (c&7) == 0 ) {
   2.108  				byte = *src++;
   2.109  			}
   2.110  			bit = (byte&0x80)>>7;
     3.1 --- a/src/video/SDL_blit_1.c	Sat Jul 07 08:08:42 2001 +0000
     3.2 +++ b/src/video/SDL_blit_1.c	Sat Jul 07 20:20:17 2001 +0000
     3.3 @@ -137,7 +137,7 @@
     3.4  				dst += 4;
     3.5  			}
     3.6  			/* Get any leftovers */
     3.7 -			switch (width % 4) {
     3.8 +			switch (width & 3) {
     3.9  				case 3:
    3.10  					*(Uint16 *)dst = map[*src++];
    3.11  					dst += 2;
    3.12 @@ -169,7 +169,7 @@
    3.13  				dst += 4;
    3.14  			}
    3.15  			/* Get any leftovers */
    3.16 -			switch (width % 4) {
    3.17 +			switch (width & 3) {
    3.18  				case 3:
    3.19  					*(Uint16 *)dst = map[*src++];
    3.20  					dst += 2;
    3.21 @@ -266,7 +266,7 @@
    3.22  			*dst++ = map[*src++];
    3.23  			*dst++ = map[*src++];
    3.24  		}
    3.25 -		switch ( width % 4 ) {
    3.26 +		switch ( width & 3 ) {
    3.27  			case 3:
    3.28  				*dst++ = map[*src++];
    3.29  			case 2:
     4.1 --- a/src/video/SDL_blit_N.c	Sat Jul 07 08:08:42 2001 +0000
     4.2 +++ b/src/video/SDL_blit_N.c	Sat Jul 07 20:20:17 2001 +0000
     4.3 @@ -78,7 +78,8 @@
     4.4  #endif
     4.5  	int width, height;
     4.6  	Uint32 *src;
     4.7 -	Uint8 *map, *dst;
     4.8 +	const Uint8 *map;
     4.9 +	Uint8 *dst;
    4.10  	int srcskip, dstskip;
    4.11  
    4.12  	/* Set up some basic variables */
    4.13 @@ -107,7 +108,7 @@
    4.14  				RGB888_RGB332(*dst++, *src);
    4.15  				++src;
    4.16  			}
    4.17 -			switch ( width % 4 ) {
    4.18 +			switch ( width & 3 ) {
    4.19  				case 3:
    4.20  					RGB888_RGB332(*dst++, *src);
    4.21  					++src;
    4.22 @@ -148,7 +149,7 @@
    4.23  				*dst++ = map[pixel];
    4.24  				++src;
    4.25  			}
    4.26 -			switch ( width % 4 ) {
    4.27 +			switch ( width & 3 ) {
    4.28  				case 3:
    4.29  					RGB888_RGB332(pixel, *src);
    4.30  					*dst++ = map[pixel];
    4.31 @@ -235,7 +236,7 @@
    4.32  				dst += 2;
    4.33  			}
    4.34  			/* Get any leftovers */
    4.35 -			switch (width % 4) {
    4.36 +			switch (width & 3) {
    4.37  				case 3:
    4.38  					RGB888_RGB555(dst, src);
    4.39  					++src;
    4.40 @@ -266,7 +267,7 @@
    4.41  				dst += 2;
    4.42  			}
    4.43  			/* Get any leftovers */
    4.44 -			switch (width % 4) {
    4.45 +			switch (width & 3) {
    4.46  				case 3:
    4.47  					RGB888_RGB555(dst, src);
    4.48  					++src;
    4.49 @@ -355,7 +356,7 @@
    4.50  				dst += 2;
    4.51  			}
    4.52  			/* Get any leftovers */
    4.53 -			switch (width % 4) {
    4.54 +			switch (width & 3) {
    4.55  				case 3:
    4.56  					RGB888_RGB565(dst, src);
    4.57  					++src;
    4.58 @@ -386,7 +387,7 @@
    4.59  				dst += 2;
    4.60  			}
    4.61  			/* Get any leftovers */
    4.62 -			switch (width % 4) {
    4.63 +			switch (width & 3) {
    4.64  				case 3:
    4.65  					RGB888_RGB565(dst, src);
    4.66  					++src;
    4.67 @@ -418,7 +419,7 @@
    4.68  #else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
    4.69  #define RGB565_32(dst, src, map) (map[src[1]*2] + map[src[0]*2+1])
    4.70  #endif
    4.71 -static void Blit_RGB565_32(SDL_BlitInfo *info, Uint32 *map)
    4.72 +static void Blit_RGB565_32(SDL_BlitInfo *info, const Uint32 *map)
    4.73  {
    4.74  #ifndef USE_DUFFS_LOOP
    4.75  	int c;
    4.76 @@ -461,7 +462,7 @@
    4.77  			src += 2;
    4.78  		}
    4.79  		/* Get any leftovers */
    4.80 -		switch (width % 4) {
    4.81 +		switch (width & 3) {
    4.82  			case 3:
    4.83  				*dst++ = RGB565_32(dst, src, map);
    4.84  				src += 2;
    4.85 @@ -480,7 +481,7 @@
    4.86  }
    4.87  
    4.88  /* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */
    4.89 -static Uint32 RGB565_ARGB8888_LUT[512] = {
    4.90 +static const Uint32 RGB565_ARGB8888_LUT[512] = {
    4.91  		0x00000000, 0xff000000, 0x00000008, 0xff002000,
    4.92  		0x00000010, 0xff004000, 0x00000018, 0xff006100,
    4.93  		0x00000020, 0xff008100, 0x00000029, 0xff00a100,
    4.94 @@ -616,7 +617,7 @@
    4.95  }
    4.96  
    4.97  /* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */
    4.98 -static Uint32 RGB565_ABGR8888_LUT[512] = {
    4.99 +static const Uint32 RGB565_ABGR8888_LUT[512] = {
   4.100  		0xff000000, 0x00000000, 0xff080000, 0x00002000,
   4.101  		0xff100000, 0x00004000, 0xff180000, 0x00006100,
   4.102  		0xff200000, 0x00008100, 0xff290000, 0x0000a100,
   4.103 @@ -752,7 +753,7 @@
   4.104  }
   4.105  
   4.106  /* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
   4.107 -static Uint32 RGB565_RGBA8888_LUT[512] = {
   4.108 +static const Uint32 RGB565_RGBA8888_LUT[512] = {
   4.109  		0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
   4.110  		0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
   4.111  		0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
   4.112 @@ -888,7 +889,7 @@
   4.113  }
   4.114  
   4.115  /* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */
   4.116 -static Uint32 RGB565_BGRA8888_LUT[512] = {
   4.117 +static const Uint32 RGB565_BGRA8888_LUT[512] = {
   4.118  		0x00000000, 0x000000ff, 0x08000000, 0x002000ff,
   4.119  		0x10000000, 0x004000ff, 0x18000000, 0x006100ff,
   4.120  		0x20000000, 0x008100ff, 0x29000000, 0x00a100ff,
   4.121 @@ -1039,7 +1040,8 @@
   4.122  	int pixel;
   4.123  	int width, height;
   4.124  	Uint32 *src;
   4.125 -	Uint8 *map, *dst;
   4.126 +	const Uint8 *map;
   4.127 +	Uint8 *dst;
   4.128  	int srcskip, dstskip;
   4.129  
   4.130  	/* Set up some basic variables */
   4.131 @@ -1078,7 +1080,7 @@
   4.132  			*dst++ = map[pixel];
   4.133  			++src;
   4.134  		}
   4.135 -		switch ( width % 4 ) {
   4.136 +		switch ( width & 3 ) {
   4.137  			case 3:
   4.138  				RGB888_RGB332(pixel, *src);
   4.139  				*dst++ = map[pixel];
   4.140 @@ -1103,7 +1105,9 @@
   4.141  	int c;
   4.142  #endif
   4.143  	int width, height;
   4.144 -	Uint8 *src, *map, *dst;
   4.145 +	Uint8 *src;
   4.146 +	const Uint8 *map;
   4.147 +	Uint8 *dst;
   4.148  	int srcskip, dstskip;
   4.149  	int srcbpp;
   4.150  	Uint32 pixel;
   4.151 @@ -1259,7 +1263,7 @@
   4.152  	Uint8 *dst = info->d_pixels;
   4.153  	int dstskip = info->d_skip;
   4.154  	SDL_PixelFormat *srcfmt = info->src;
   4.155 -	Uint8 *palmap = info->table;
   4.156 +	const Uint8 *palmap = info->table;
   4.157  	Uint32 ckey = srcfmt->colorkey;
   4.158  	Uint32 rgbmask = ~srcfmt->Amask;
   4.159  	int srcbpp;
   4.160 @@ -1431,11 +1435,11 @@
   4.161  	SDL_loblit blitfunc;
   4.162          enum { NO_ALPHA, SET_ALPHA, COPY_ALPHA } alpha;
   4.163  };
   4.164 -static struct blit_table normal_blit_1[] = {
   4.165 +static const struct blit_table normal_blit_1[] = {
   4.166  	/* Default for 8-bit RGB source, an invalid combination */
   4.167  	{ 0,0,0, 0, 0,0,0, 0, NULL, NULL },
   4.168  };
   4.169 -static struct blit_table normal_blit_2[] = {
   4.170 +static const struct blit_table normal_blit_2[] = {
   4.171  #ifdef USE_ASMBLIT
   4.172      { 0x0000F800,0x000007E0,0x0000001F, 2, 0x0000001F,0x000007E0,0x0000F800,
   4.173        0, ConvertX86p16_16BGR565, ConvertX86, NO_ALPHA },
   4.174 @@ -1456,11 +1460,11 @@
   4.175      /* Default for 16-bit RGB source, used if no other blitter matches */
   4.176      { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
   4.177  };
   4.178 -static struct blit_table normal_blit_3[] = {
   4.179 +static const struct blit_table normal_blit_3[] = {
   4.180  	/* Default for 24-bit RGB source, never optimized */
   4.181      { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
   4.182  };
   4.183 -static struct blit_table normal_blit_4[] = {
   4.184 +static const struct blit_table normal_blit_4[] = {
   4.185  #ifdef USE_ASMBLIT
   4.186      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F,
   4.187        MMX_CPU, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA },
   4.188 @@ -1497,7 +1501,7 @@
   4.189  	/* Default for 32-bit RGB source, used if no other blitter matches */
   4.190  	{ 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
   4.191  };
   4.192 -static struct blit_table *normal_blit[] = {
   4.193 +static const struct blit_table *normal_blit[] = {
   4.194  	normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
   4.195  };
   4.196  
   4.197 @@ -1506,7 +1510,7 @@
   4.198  	struct private_swaccel *sdata;
   4.199  	SDL_PixelFormat *srcfmt;
   4.200  	SDL_PixelFormat *dstfmt;
   4.201 -	struct blit_table *table;
   4.202 +	const struct blit_table *table;
   4.203  	int which;
   4.204  	SDL_loblit blitfun;
   4.205  
     5.1 --- a/src/video/dga/SDL_dgavideo.c	Sat Jul 07 08:08:42 2001 +0000
     5.2 +++ b/src/video/dga/SDL_dgavideo.c	Sat Jul 07 20:20:17 2001 +0000
     5.3 @@ -278,8 +278,8 @@
     5.4  
     5.5  static int cmpmodes(const void *va, const void *vb)
     5.6  {
     5.7 -    XDGAMode *a = (XDGAMode *)va;
     5.8 -    XDGAMode *b = (XDGAMode *)vb;
     5.9 +    const XDGAMode *a = (const XDGAMode *)va;
    5.10 +    const XDGAMode *b = (const XDGAMode *)vb;
    5.11  
    5.12      /* Prefer DirectColor visuals for otherwise equal modes */
    5.13      if ( (a->viewportWidth == b->viewportWidth) &&
     6.1 --- a/src/video/fbcon/SDL_fbevents.c	Sat Jul 07 08:08:42 2001 +0000
     6.2 +++ b/src/video/fbcon/SDL_fbevents.c	Sat Jul 07 20:20:17 2001 +0000
     6.3 @@ -247,8 +247,8 @@
     6.4  {
     6.5  	/* Open only if not already opened */
     6.6   	if ( keyboard_fd < 0 ) {
     6.7 -		char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
     6.8 -		char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
     6.9 +		static const char * const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
    6.10 +		static const char * const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
    6.11  		int i, tty0_fd;
    6.12  
    6.13  		/* Try to query for a free virtual terminal */
    6.14 @@ -524,7 +524,7 @@
    6.15  
    6.16  	if ( mousedev == NULL ) {
    6.17  		/* FIXME someday... allow multiple mice in this driver */
    6.18 -		char *ps2mice[] = {
    6.19 +		static const char * const ps2mice[] = {
    6.20  		    "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL
    6.21  		};
    6.22  		/* First try to use GPM in repeater mode */
     7.1 --- a/src/video/fbcon/SDL_fbvideo.c	Sat Jul 07 08:08:42 2001 +0000
     7.2 +++ b/src/video/fbcon/SDL_fbvideo.c	Sat Jul 07 20:20:17 2001 +0000
     7.3 @@ -62,7 +62,7 @@
     7.4  #endif /* FB_TYPE_VGA_PLANES */
     7.5  
     7.6  /* A list of video resolutions that we query for (sorted largest to smallest) */
     7.7 -static SDL_Rect checkres[] = {
     7.8 +static const SDL_Rect checkres[] = {
     7.9  	{  0, 0, 1600, 1200 },		/* 16 bpp: 0x11E, or 286 */
    7.10  	{  0, 0, 1408, 1056 },		/* 16 bpp: 0x19A, or 410 */
    7.11  	{  0, 0, 1280, 1024 },		/* 16 bpp: 0x11A, or 282 */
    7.12 @@ -77,7 +77,7 @@
    7.13  	{  0, 0,  320,  240 },
    7.14  	{  0, 0,  320,  200 }
    7.15  };
    7.16 -static struct {
    7.17 +static const struct {
    7.18  	int xres;
    7.19  	int yres;
    7.20  	int pixclock;
     8.1 --- a/src/video/x11/SDL_x11modes.c	Sat Jul 07 08:08:42 2001 +0000
     8.2 +++ b/src/video/x11/SDL_x11modes.c	Sat Jul 07 20:20:17 2001 +0000
     8.3 @@ -78,8 +78,8 @@
     8.4  #ifdef XFREE86_VM
     8.5  static int cmpmodes(const void *va, const void *vb)
     8.6  {
     8.7 -    XF86VidModeModeInfo *a = *(XF86VidModeModeInfo**)va;
     8.8 -    XF86VidModeModeInfo *b = *(XF86VidModeModeInfo**)vb;
     8.9 +    const XF86VidModeModeInfo *a = *(const XF86VidModeModeInfo**)va;
    8.10 +    const XF86VidModeModeInfo *b = *(const XF86VidModeModeInfo**)vb;
    8.11      if(a->hdisplay > b->hdisplay)
    8.12          return -1;
    8.13      return b->vdisplay - a->vdisplay;