From e3c265fe0a10555e12cdd26d0a1513b8fd9416d7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 7 Jul 2001 20:20:17 +0000 Subject: [PATCH] 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 | 4 +-- src/video/SDL_blit_0.c | 24 ++++++++-------- src/video/SDL_blit_1.c | 6 ++-- src/video/SDL_blit_N.c | 50 ++++++++++++++++++---------------- src/video/dga/SDL_dgavideo.c | 4 +-- src/video/fbcon/SDL_fbevents.c | 6 ++-- src/video/fbcon/SDL_fbvideo.c | 4 +-- src/video/x11/SDL_x11modes.c | 4 +-- 8 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h index e3eff5328..a8a75f5b5 100644 --- a/src/video/SDL_blit.h +++ b/src/video/SDL_blit.h @@ -384,7 +384,7 @@ do { \ /* 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 @@ do { \ /* 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; \ diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c index bb3afaa14..3faa898ba 100644 --- a/src/video/SDL_blit_0.c +++ b/src/video/SDL_blit_0.c @@ -55,7 +55,7 @@ static void BlitBto1(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -72,7 +72,7 @@ static void BlitBto1(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -108,7 +108,7 @@ static void BlitBto2(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -142,7 +142,7 @@ static void BlitBto3(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -180,7 +180,7 @@ static void BlitBto4(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -214,7 +214,7 @@ static void BlitBto1Key(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -231,7 +231,7 @@ static void BlitBto1Key(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -266,7 +266,7 @@ static void BlitBto2Key(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -299,7 +299,7 @@ static void BlitBto3Key(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -333,7 +333,7 @@ static void BlitBto4Key(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -369,7 +369,7 @@ static void BlitBtoNAlpha(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; @@ -416,7 +416,7 @@ static void BlitBtoNAlphaKey(SDL_BlitInfo *info) while ( height-- ) { Uint8 byte = 0, bit; for ( c=0; c>7; diff --git a/src/video/SDL_blit_1.c b/src/video/SDL_blit_1.c index 0c0dda264..ace7db804 100644 --- a/src/video/SDL_blit_1.c +++ b/src/video/SDL_blit_1.c @@ -137,7 +137,7 @@ static void Blit1to2(SDL_BlitInfo *info) dst += 4; } /* Get any leftovers */ - switch (width % 4) { + switch (width & 3) { case 3: *(Uint16 *)dst = map[*src++]; dst += 2; @@ -169,7 +169,7 @@ static void Blit1to2(SDL_BlitInfo *info) dst += 4; } /* Get any leftovers */ - switch (width % 4) { + switch (width & 3) { case 3: *(Uint16 *)dst = map[*src++]; dst += 2; @@ -266,7 +266,7 @@ static void Blit1to4(SDL_BlitInfo *info) *dst++ = map[*src++]; *dst++ = map[*src++]; } - switch ( width % 4 ) { + switch ( width & 3 ) { case 3: *dst++ = map[*src++]; case 2: diff --git a/src/video/SDL_blit_N.c b/src/video/SDL_blit_N.c index 6cd466462..57acaceff 100644 --- a/src/video/SDL_blit_N.c +++ b/src/video/SDL_blit_N.c @@ -78,7 +78,8 @@ static void Blit_RGB888_index8(SDL_BlitInfo *info) #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 @@ static void Blit_RGB888_index8(SDL_BlitInfo *info) RGB888_RGB332(*dst++, *src); ++src; } - switch ( width % 4 ) { + switch ( width & 3 ) { case 3: RGB888_RGB332(*dst++, *src); ++src; @@ -148,7 +149,7 @@ static void Blit_RGB888_index8(SDL_BlitInfo *info) *dst++ = map[pixel]; ++src; } - switch ( width % 4 ) { + switch ( width & 3 ) { case 3: RGB888_RGB332(pixel, *src); *dst++ = map[pixel]; @@ -235,7 +236,7 @@ static void Blit_RGB888_RGB555(SDL_BlitInfo *info) dst += 2; } /* Get any leftovers */ - switch (width % 4) { + switch (width & 3) { case 3: RGB888_RGB555(dst, src); ++src; @@ -266,7 +267,7 @@ static void Blit_RGB888_RGB555(SDL_BlitInfo *info) dst += 2; } /* Get any leftovers */ - switch (width % 4) { + switch (width & 3) { case 3: RGB888_RGB555(dst, src); ++src; @@ -355,7 +356,7 @@ static void Blit_RGB888_RGB565(SDL_BlitInfo *info) dst += 2; } /* Get any leftovers */ - switch (width % 4) { + switch (width & 3) { case 3: RGB888_RGB565(dst, src); ++src; @@ -386,7 +387,7 @@ static void Blit_RGB888_RGB565(SDL_BlitInfo *info) dst += 2; } /* Get any leftovers */ - switch (width % 4) { + switch (width & 3) { case 3: RGB888_RGB565(dst, src); ++src; @@ -418,7 +419,7 @@ static void Blit_RGB888_RGB565(SDL_BlitInfo *info) #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 @@ static void Blit_RGB565_32(SDL_BlitInfo *info, Uint32 *map) 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 @@ static void Blit_RGB565_32(SDL_BlitInfo *info, Uint32 *map) } /* 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 @@ static void Blit_RGB565_ARGB8888(SDL_BlitInfo *info) } /* 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 @@ static void Blit_RGB565_ABGR8888(SDL_BlitInfo *info) } /* 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 @@ static void Blit_RGB565_RGBA8888(SDL_BlitInfo *info) } /* 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 @@ static void Blit_RGB888_index8_map(SDL_BlitInfo *info) 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 @@ static void Blit_RGB888_index8_map(SDL_BlitInfo *info) *dst++ = map[pixel]; ++src; } - switch ( width % 4 ) { + switch ( width & 3 ) { case 3: RGB888_RGB332(pixel, *src); *dst++ = map[pixel]; @@ -1103,7 +1105,9 @@ static void BlitNto1(SDL_BlitInfo *info) 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 @@ static void BlitNto1Key(SDL_BlitInfo *info) 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 @@ struct blit_table { 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 @@ static struct blit_table normal_blit_2[] = { /* 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 @@ static struct blit_table normal_blit_4[] = { /* 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 @@ SDL_loblit SDL_CalculateBlitN(SDL_Surface *surface, int blit_index) struct private_swaccel *sdata; SDL_PixelFormat *srcfmt; SDL_PixelFormat *dstfmt; - struct blit_table *table; + const struct blit_table *table; int which; SDL_loblit blitfun; diff --git a/src/video/dga/SDL_dgavideo.c b/src/video/dga/SDL_dgavideo.c index a99d24373..ab64bd44c 100644 --- a/src/video/dga/SDL_dgavideo.c +++ b/src/video/dga/SDL_dgavideo.c @@ -278,8 +278,8 @@ static void PrintMode(XDGAMode *mode) 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) && diff --git a/src/video/fbcon/SDL_fbevents.c b/src/video/fbcon/SDL_fbevents.c index 54995a2fb..2a4d8eafa 100644 --- a/src/video/fbcon/SDL_fbevents.c +++ b/src/video/fbcon/SDL_fbevents.c @@ -247,8 +247,8 @@ int FB_OpenKeyboard(_THIS) { /* 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 @@ fprintf(stderr, "Using ELO touchscreen\n"); 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 */ diff --git a/src/video/fbcon/SDL_fbvideo.c b/src/video/fbcon/SDL_fbvideo.c index 23760dd9a..04a8ed1a5 100644 --- a/src/video/fbcon/SDL_fbvideo.c +++ b/src/video/fbcon/SDL_fbvideo.c @@ -62,7 +62,7 @@ static inline void outb (unsigned char value, unsigned short port) #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 @@ static SDL_Rect checkres[] = { { 0, 0, 320, 240 }, { 0, 0, 320, 200 } }; -static struct { +static const struct { int xres; int yres; int pixclock; diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index 3199d4806..ea2074eb3 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -78,8 +78,8 @@ static void restore_mode(_THIS) #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;