From: "Markus F.X.J. Oberhumer"
authorSam Lantinga <slouken@lokigames.com>
Sat, 07 Jul 2001 20:20:17 +0000
changeset 91 e85e03f195b4
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
--- a/src/video/SDL_blit.h	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/SDL_blit.h	Sat Jul 07 20:20:17 2001 +0000
@@ -384,7 +384,7 @@
 /* 8-times unrolled loop */
 #define DUFFS_LOOP8(pixel_copy_increment, width)			\
 { int n = (width+7)/8;							\
-	switch (width % 8) {						\
+	switch (width & 7) {						\
 	case 0: do {	pixel_copy_increment;				\
 	case 7:		pixel_copy_increment;				\
 	case 6:		pixel_copy_increment;				\
@@ -400,7 +400,7 @@
 /* 4-times unrolled loop */
 #define DUFFS_LOOP4(pixel_copy_increment, width)			\
 { int n = (width+3)/4;							\
-	switch (width % 4) {						\
+	switch (width & 3) {						\
 	case 0: do {	pixel_copy_increment;				\
 	case 3:		pixel_copy_increment;				\
 	case 2:		pixel_copy_increment;				\
--- a/src/video/SDL_blit_0.c	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/SDL_blit_0.c	Sat Jul 07 20:20:17 2001 +0000
@@ -55,7 +55,7 @@
 		while ( height-- ) {
 		        Uint8 byte = 0, bit;
 	    		for ( c=0; c<width; ++c ) {
-				if ( (c%8) == 0 ) {
+				if ( (c&7) == 0 ) {
 					byte = *src++;
 				}
 				bit = (byte&0x80)>>7;
@@ -72,7 +72,7 @@
 		while ( height-- ) {
 		        Uint8 byte = 0, bit;
 	    		for ( c=0; c<width; ++c ) {
-				if ( (c%8) == 0 ) {
+				if ( (c&7) == 0 ) {
 					byte = *src++;
 				}
 				bit = (byte&0x80)>>7;
@@ -108,7 +108,7 @@
 	while ( height-- ) {
 	        Uint8 byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
@@ -142,7 +142,7 @@
 	while ( height-- ) {
 	        Uint8 byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
@@ -180,7 +180,7 @@
 	while ( height-- ) {
 	        Uint8 byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
@@ -214,7 +214,7 @@
 		while ( height-- ) {
 		        Uint8  byte = 0, bit;
 	    		for ( c=0; c<width; ++c ) {
-				if ( (c%8) == 0 ) {
+				if ( (c&7) == 0 ) {
 					byte = *src++;
 				}
 				bit = (byte&0x80)>>7;
@@ -231,7 +231,7 @@
 		while ( height-- ) {
 		        Uint8  byte = 0, bit;
 	    		for ( c=0; c<width; ++c ) {
-				if ( (c%8) == 0 ) {
+				if ( (c&7) == 0 ) {
 					byte = *src++;
 				}
 				bit = (byte&0x80)>>7;
@@ -266,7 +266,7 @@
 	while ( height-- ) {
 	        Uint8 byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
@@ -299,7 +299,7 @@
 	while ( height-- ) {
 	        Uint8  byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
@@ -333,7 +333,7 @@
 	while ( height-- ) {
 	        Uint8 byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
@@ -369,7 +369,7 @@
 	while ( height-- ) {
 	        Uint8 byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
@@ -416,7 +416,7 @@
 	while ( height-- ) {
 	        Uint8  byte = 0, bit;
 	    	for ( c=0; c<width; ++c ) {
-			if ( (c%8) == 0 ) {
+			if ( (c&7) == 0 ) {
 				byte = *src++;
 			}
 			bit = (byte&0x80)>>7;
--- a/src/video/SDL_blit_1.c	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/SDL_blit_1.c	Sat Jul 07 20:20:17 2001 +0000
@@ -137,7 +137,7 @@
 				dst += 4;
 			}
 			/* Get any leftovers */
-			switch (width % 4) {
+			switch (width & 3) {
 				case 3:
 					*(Uint16 *)dst = map[*src++];
 					dst += 2;
@@ -169,7 +169,7 @@
 				dst += 4;
 			}
 			/* Get any leftovers */
-			switch (width % 4) {
+			switch (width & 3) {
 				case 3:
 					*(Uint16 *)dst = map[*src++];
 					dst += 2;
@@ -266,7 +266,7 @@
 			*dst++ = map[*src++];
 			*dst++ = map[*src++];
 		}
-		switch ( width % 4 ) {
+		switch ( width & 3 ) {
 			case 3:
 				*dst++ = map[*src++];
 			case 2:
--- a/src/video/SDL_blit_N.c	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/SDL_blit_N.c	Sat Jul 07 20:20:17 2001 +0000
@@ -78,7 +78,8 @@
 #endif
 	int width, height;
 	Uint32 *src;
-	Uint8 *map, *dst;
+	const Uint8 *map;
+	Uint8 *dst;
 	int srcskip, dstskip;
 
 	/* Set up some basic variables */
@@ -107,7 +108,7 @@
 				RGB888_RGB332(*dst++, *src);
 				++src;
 			}
-			switch ( width % 4 ) {
+			switch ( width & 3 ) {
 				case 3:
 					RGB888_RGB332(*dst++, *src);
 					++src;
@@ -148,7 +149,7 @@
 				*dst++ = map[pixel];
 				++src;
 			}
-			switch ( width % 4 ) {
+			switch ( width & 3 ) {
 				case 3:
 					RGB888_RGB332(pixel, *src);
 					*dst++ = map[pixel];
@@ -235,7 +236,7 @@
 				dst += 2;
 			}
 			/* Get any leftovers */
-			switch (width % 4) {
+			switch (width & 3) {
 				case 3:
 					RGB888_RGB555(dst, src);
 					++src;
@@ -266,7 +267,7 @@
 				dst += 2;
 			}
 			/* Get any leftovers */
-			switch (width % 4) {
+			switch (width & 3) {
 				case 3:
 					RGB888_RGB555(dst, src);
 					++src;
@@ -355,7 +356,7 @@
 				dst += 2;
 			}
 			/* Get any leftovers */
-			switch (width % 4) {
+			switch (width & 3) {
 				case 3:
 					RGB888_RGB565(dst, src);
 					++src;
@@ -386,7 +387,7 @@
 				dst += 2;
 			}
 			/* Get any leftovers */
-			switch (width % 4) {
+			switch (width & 3) {
 				case 3:
 					RGB888_RGB565(dst, src);
 					++src;
@@ -418,7 +419,7 @@
 #else /* ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) */
 #define RGB565_32(dst, src, map) (map[src[1]*2] + map[src[0]*2+1])
 #endif
-static void Blit_RGB565_32(SDL_BlitInfo *info, Uint32 *map)
+static void Blit_RGB565_32(SDL_BlitInfo *info, const Uint32 *map)
 {
 #ifndef USE_DUFFS_LOOP
 	int c;
@@ -461,7 +462,7 @@
 			src += 2;
 		}
 		/* Get any leftovers */
-		switch (width % 4) {
+		switch (width & 3) {
 			case 3:
 				*dst++ = RGB565_32(dst, src, map);
 				src += 2;
@@ -480,7 +481,7 @@
 }
 
 /* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */
-static Uint32 RGB565_ARGB8888_LUT[512] = {
+static const Uint32 RGB565_ARGB8888_LUT[512] = {
 		0x00000000, 0xff000000, 0x00000008, 0xff002000,
 		0x00000010, 0xff004000, 0x00000018, 0xff006100,
 		0x00000020, 0xff008100, 0x00000029, 0xff00a100,
@@ -616,7 +617,7 @@
 }
 
 /* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */
-static Uint32 RGB565_ABGR8888_LUT[512] = {
+static const Uint32 RGB565_ABGR8888_LUT[512] = {
 		0xff000000, 0x00000000, 0xff080000, 0x00002000,
 		0xff100000, 0x00004000, 0xff180000, 0x00006100,
 		0xff200000, 0x00008100, 0xff290000, 0x0000a100,
@@ -752,7 +753,7 @@
 }
 
 /* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
-static Uint32 RGB565_RGBA8888_LUT[512] = {
+static const Uint32 RGB565_RGBA8888_LUT[512] = {
 		0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
 		0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
 		0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
@@ -888,7 +889,7 @@
 }
 
 /* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */
-static Uint32 RGB565_BGRA8888_LUT[512] = {
+static const Uint32 RGB565_BGRA8888_LUT[512] = {
 		0x00000000, 0x000000ff, 0x08000000, 0x002000ff,
 		0x10000000, 0x004000ff, 0x18000000, 0x006100ff,
 		0x20000000, 0x008100ff, 0x29000000, 0x00a100ff,
@@ -1039,7 +1040,8 @@
 	int pixel;
 	int width, height;
 	Uint32 *src;
-	Uint8 *map, *dst;
+	const Uint8 *map;
+	Uint8 *dst;
 	int srcskip, dstskip;
 
 	/* Set up some basic variables */
@@ -1078,7 +1080,7 @@
 			*dst++ = map[pixel];
 			++src;
 		}
-		switch ( width % 4 ) {
+		switch ( width & 3 ) {
 			case 3:
 				RGB888_RGB332(pixel, *src);
 				*dst++ = map[pixel];
@@ -1103,7 +1105,9 @@
 	int c;
 #endif
 	int width, height;
-	Uint8 *src, *map, *dst;
+	Uint8 *src;
+	const Uint8 *map;
+	Uint8 *dst;
 	int srcskip, dstskip;
 	int srcbpp;
 	Uint32 pixel;
@@ -1259,7 +1263,7 @@
 	Uint8 *dst = info->d_pixels;
 	int dstskip = info->d_skip;
 	SDL_PixelFormat *srcfmt = info->src;
-	Uint8 *palmap = info->table;
+	const Uint8 *palmap = info->table;
 	Uint32 ckey = srcfmt->colorkey;
 	Uint32 rgbmask = ~srcfmt->Amask;
 	int srcbpp;
@@ -1431,11 +1435,11 @@
 	SDL_loblit blitfunc;
         enum { NO_ALPHA, SET_ALPHA, COPY_ALPHA } alpha;
 };
-static struct blit_table normal_blit_1[] = {
+static const struct blit_table normal_blit_1[] = {
 	/* Default for 8-bit RGB source, an invalid combination */
 	{ 0,0,0, 0, 0,0,0, 0, NULL, NULL },
 };
-static struct blit_table normal_blit_2[] = {
+static const struct blit_table normal_blit_2[] = {
 #ifdef USE_ASMBLIT
     { 0x0000F800,0x000007E0,0x0000001F, 2, 0x0000001F,0x000007E0,0x0000F800,
       0, ConvertX86p16_16BGR565, ConvertX86, NO_ALPHA },
@@ -1456,11 +1460,11 @@
     /* Default for 16-bit RGB source, used if no other blitter matches */
     { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
 };
-static struct blit_table normal_blit_3[] = {
+static const struct blit_table normal_blit_3[] = {
 	/* Default for 24-bit RGB source, never optimized */
     { 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
 };
-static struct blit_table normal_blit_4[] = {
+static const struct blit_table normal_blit_4[] = {
 #ifdef USE_ASMBLIT
     { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F,
       MMX_CPU, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA },
@@ -1497,7 +1501,7 @@
 	/* Default for 32-bit RGB source, used if no other blitter matches */
 	{ 0,0,0, 0, 0,0,0, 0, NULL, BlitNtoN, 0 }
 };
-static struct blit_table *normal_blit[] = {
+static const struct blit_table *normal_blit[] = {
 	normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
 };
 
@@ -1506,7 +1510,7 @@
 	struct private_swaccel *sdata;
 	SDL_PixelFormat *srcfmt;
 	SDL_PixelFormat *dstfmt;
-	struct blit_table *table;
+	const struct blit_table *table;
 	int which;
 	SDL_loblit blitfun;
 
--- a/src/video/dga/SDL_dgavideo.c	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/dga/SDL_dgavideo.c	Sat Jul 07 20:20:17 2001 +0000
@@ -278,8 +278,8 @@
 
 static int cmpmodes(const void *va, const void *vb)
 {
-    XDGAMode *a = (XDGAMode *)va;
-    XDGAMode *b = (XDGAMode *)vb;
+    const XDGAMode *a = (const XDGAMode *)va;
+    const XDGAMode *b = (const XDGAMode *)vb;
 
     /* Prefer DirectColor visuals for otherwise equal modes */
     if ( (a->viewportWidth == b->viewportWidth) &&
--- a/src/video/fbcon/SDL_fbevents.c	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/fbcon/SDL_fbevents.c	Sat Jul 07 20:20:17 2001 +0000
@@ -247,8 +247,8 @@
 {
 	/* Open only if not already opened */
  	if ( keyboard_fd < 0 ) {
-		char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
-		char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
+		static const char * const tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
+		static const char * const vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
 		int i, tty0_fd;
 
 		/* Try to query for a free virtual terminal */
@@ -524,7 +524,7 @@
 
 	if ( mousedev == NULL ) {
 		/* FIXME someday... allow multiple mice in this driver */
-		char *ps2mice[] = {
+		static const char * const ps2mice[] = {
 		    "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL
 		};
 		/* First try to use GPM in repeater mode */
--- a/src/video/fbcon/SDL_fbvideo.c	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/fbcon/SDL_fbvideo.c	Sat Jul 07 20:20:17 2001 +0000
@@ -62,7 +62,7 @@
 #endif /* FB_TYPE_VGA_PLANES */
 
 /* A list of video resolutions that we query for (sorted largest to smallest) */
-static SDL_Rect checkres[] = {
+static const SDL_Rect checkres[] = {
 	{  0, 0, 1600, 1200 },		/* 16 bpp: 0x11E, or 286 */
 	{  0, 0, 1408, 1056 },		/* 16 bpp: 0x19A, or 410 */
 	{  0, 0, 1280, 1024 },		/* 16 bpp: 0x11A, or 282 */
@@ -77,7 +77,7 @@
 	{  0, 0,  320,  240 },
 	{  0, 0,  320,  200 }
 };
-static struct {
+static const struct {
 	int xres;
 	int yres;
 	int pixclock;
--- a/src/video/x11/SDL_x11modes.c	Sat Jul 07 08:08:42 2001 +0000
+++ b/src/video/x11/SDL_x11modes.c	Sat Jul 07 20:20:17 2001 +0000
@@ -78,8 +78,8 @@
 #ifdef XFREE86_VM
 static int cmpmodes(const void *va, const void *vb)
 {
-    XF86VidModeModeInfo *a = *(XF86VidModeModeInfo**)va;
-    XF86VidModeModeInfo *b = *(XF86VidModeModeInfo**)vb;
+    const XF86VidModeModeInfo *a = *(const XF86VidModeModeInfo**)va;
+    const XF86VidModeModeInfo *b = *(const XF86VidModeModeInfo**)vb;
     if(a->hdisplay > b->hdisplay)
         return -1;
     return b->vdisplay - a->vdisplay;