diff options
| author | Jens Arnold <amiconn@rockbox.org> | 2009-06-07 21:27:05 +0000 |
|---|---|---|
| committer | Jens Arnold <amiconn@rockbox.org> | 2009-06-07 21:27:05 +0000 |
| commit | 1d6df54df27cb41c02226678a2c8f9feddd1a1e0 (patch) | |
| tree | 5fdc6dd98ac0208f5c3351b062063af6914cbefb /apps/plugins | |
| parent | c3182ec333982e961d3babfbdb1125fd5bac7fb8 (diff) | |
| download | rockbox-1d6df54df27cb41c02226678a2c8f9feddd1a1e0.zip rockbox-1d6df54df27cb41c02226678a2c8f9feddd1a1e0.tar.gz rockbox-1d6df54df27cb41c02226678a2c8f9feddd1a1e0.tar.bz2 rockbox-1d6df54df27cb41c02226678a2c8f9feddd1a1e0.tar.xz | |
Convert a number of places in core and plugins to use the BIT_N() macro instead of 1<<n. Speeds up things on SH1, and also reduces core binsize. Most notable speedups: 1 bit lcd driver: drawpixel +20%, drawline + 27%, hline +5%; jpeg viewer: +8% for 1/8 scaling. Other targets are unaffected.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21205 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
| -rw-r--r-- | apps/plugins/alpine_cdc.c | 6 | ||||
| -rw-r--r-- | apps/plugins/jpeg/jpeg_decoder.c | 4 | ||||
| -rw-r--r-- | apps/plugins/lib/fixedpoint.c | 3 | ||||
| -rw-r--r-- | apps/plugins/lib/grey_core.c | 2 | ||||
| -rw-r--r-- | apps/plugins/lib/helper.c | 14 | ||||
| -rw-r--r-- | apps/plugins/rockboy/cpu.c | 10 | ||||
| -rw-r--r-- | apps/plugins/rockboy/lcd.c | 4 | ||||
| -rw-r--r-- | apps/plugins/rockboy/sound.c | 2 | ||||
| -rw-r--r-- | apps/plugins/sudoku/generator.c | 4 | ||||
| -rw-r--r-- | apps/plugins/sudoku/sudoku.c | 12 | ||||
| -rw-r--r-- | apps/plugins/zxbox/sp_def.h | 4 | ||||
| -rw-r--r-- | apps/plugins/zxbox/spkey.c | 4 | ||||
| -rw-r--r-- | apps/plugins/zxbox/spscr.c | 4 |
13 files changed, 44 insertions, 29 deletions
diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c index a7aeec3..494fa17 100644 --- a/apps/plugins/alpine_cdc.c +++ b/apps/plugins/alpine_cdc.c @@ -669,16 +669,16 @@ void dump_packet(char* dest, int dst_size, char* src, int n) bool bit_test(unsigned char* buf, unsigned bit) { - return (buf[bit/4] & (0x01 << bit%4)) != 0; + return (buf[bit>>2] & BIT_N(bit&3)) != 0; } void bit_set(unsigned char* buf, unsigned bit, bool val) { if (val) - buf[bit/4] |= (0x01 << bit%4); + buf[bit>>2] |= BIT_N(bit&3); else - buf[bit/4] &= ~(0x01 << bit%4); + buf[bit>>2] &= ~BIT_N(bit&3); } diff --git a/apps/plugins/jpeg/jpeg_decoder.c b/apps/plugins/jpeg/jpeg_decoder.c index 71d5088..c90bff8 100644 --- a/apps/plugins/jpeg/jpeg_decoder.c +++ b/apps/plugins/jpeg/jpeg_decoder.c @@ -1067,12 +1067,12 @@ INLINE void check_bit_buffer(struct bitstream* pb, int nbits) INLINE int get_bits(struct bitstream* pb, int nbits) { - return ((int) (pb->get_buffer >> (pb->bits_left -= nbits))) & ((1<<nbits)-1); + return ((int) (pb->get_buffer >> (pb->bits_left -= nbits))) & (BIT_N(nbits)-1); } INLINE int peek_bits(struct bitstream* pb, int nbits) { - return ((int) (pb->get_buffer >> (pb->bits_left - nbits))) & ((1<<nbits)-1); + return ((int) (pb->get_buffer >> (pb->bits_left - nbits))) & (BIT_N(nbits)-1); } INLINE void drop_bits(struct bitstream* pb, int nbits) diff --git a/apps/plugins/lib/fixedpoint.c b/apps/plugins/lib/fixedpoint.c index 7b9b68a..0ae2cde 100644 --- a/apps/plugins/lib/fixedpoint.c +++ b/apps/plugins/lib/fixedpoint.c @@ -22,6 +22,7 @@ ****************************************************************************/ #include <inttypes.h> +#include "plugin.h" #include "fixedpoint.h" /* Inverse gain of circular cordic rotation in s0.31 format. */ @@ -144,7 +145,7 @@ long fsincos(unsigned long phase, long *cos) */ long fsqrt(long a, unsigned int fracbits) { - long b = a/2 + (1 << fracbits); /* initial approximation */ + long b = a/2 + BIT_N(fracbits); /* initial approximation */ unsigned n; const unsigned iterations = 4; diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c index 18b2716..ea70ae9 100644 --- a/apps/plugins/lib/grey_core.c +++ b/apps/plugins/lib/grey_core.c @@ -860,7 +860,7 @@ static void grey_screendump_hook(int fd) + _GREY_MULUQ(_grey_info.width, gy & ~_GREY_BMASK); #if LCD_DEPTH == 1 - mask = 1 << (y & 7); + mask = BIT_N(y & 7); src = rb->lcd_framebuffer + _GREY_MULUQ(LCD_WIDTH, y >> 3); do diff --git a/apps/plugins/lib/helper.c b/apps/plugins/lib/helper.c index e35e43a..b95ee7a 100644 --- a/apps/plugins/lib/helper.c +++ b/apps/plugins/lib/helper.c @@ -22,6 +22,20 @@ #include "plugin.h" #include "helper.h" +#ifdef CPU_SH +/* Lookup table for using the BIT_N() macro in plugins */ +const unsigned bit_n_table[32] = { + 1LU<< 0, 1LU<< 1, 1LU<< 2, 1LU<< 3, + 1LU<< 4, 1LU<< 5, 1LU<< 6, 1LU<< 7, + 1LU<< 8, 1LU<< 9, 1LU<<10, 1LU<<11, + 1LU<<12, 1LU<<13, 1LU<<14, 1LU<<15, + 1LU<<16, 1LU<<17, 1LU<<18, 1LU<<19, + 1LU<<20, 1LU<<21, 1LU<<22, 1LU<<23, + 1LU<<24, 1LU<<25, 1LU<<26, 1LU<<27, + 1LU<<28, 1LU<<29, 1LU<<30, 1LU<<31 +}; +#endif + /* Force the backlight on */ void backlight_force_on(void) { diff --git a/apps/plugins/rockboy/cpu.c b/apps/plugins/rockboy/cpu.c index 1aca06f..2fc7411 100644 --- a/apps/plugins/rockboy/cpu.c +++ b/apps/plugins/rockboy/cpu.c @@ -147,9 +147,9 @@ F = (F & (FN)) | ZFLAG(A) | daa_carry_table[LB(acc)>>2]; } (r) = swap_table[(r)]; \ F = ZFLAG((r)); } -#define BIT(n,r) { F = (F & FC) | ZFLAG(((r) & (1 << (n)))) | FH; } -#define RES(n,r) { (r) &= ~(1 << (n)); } -#define SET(n,r) { (r) |= (1 << (n)); } +#define BIT(n,r) { F = (F & FC) | ZFLAG(((r) & BIT_N(n))) | FH; } +#define RES(n,r) { (r) &= ~BIT_N(n); } +#define SET(n,r) { (r) |= BIT_N(n); } #define CB_REG_CASES(r, n) \ case 0x00|(n): RLC(r); break; \ @@ -225,7 +225,7 @@ label: op(b); break; #define PRE_INT ( DI, PUSH(PC) ) -#define THROW_INT(n) ( (IF &= ~(1<<(n))), (PC = 0x40+((n)<<3)) ) +#define THROW_INT(n) ( (IF &= ~BIT_N(n)), (PC = 0x40+((n)<<3)) ) #ifdef DYNAREC un32 reg_backup[16]; @@ -355,7 +355,7 @@ static int cpu_idle(int max) /* Figure out when the next timer interrupt will happen */ unit = ((-R_TAC) & 3) << 1; - cnt = (511 - cpu.tim + (1<<unit)) >> unit; + cnt = (511 - cpu.tim + BIT_N(unit)) >> unit; cnt += (255 - R_TIMA) << (9 - unit); if (max < cnt) diff --git a/apps/plugins/rockboy/lcd.c b/apps/plugins/rockboy/lcd.c index da3b138..372e9e0 100644 --- a/apps/plugins/rockboy/lcd.c +++ b/apps/plugins/rockboy/lcd.c @@ -216,8 +216,8 @@ static void updatepatpix(void) a = ((i<<4) | (j<<1)); for (k = 0; k < 8; k++) { - c = vram[a] & (1<<k) ? 1 : 0; - c |= vram[a+1] & (1<<k) ? 2 : 0; + c = vram[a] & BIT_N(k) ? 1 : 0; + c |= vram[a+1] & BIT_N(k) ? 2 : 0; patpix[i+1024][j][k] = c; } for (k = 0; k < 8; k++) diff --git a/apps/plugins/rockboy/sound.c b/apps/plugins/rockboy/sound.c index 041b783..6efc01b 100644 --- a/apps/plugins/rockboy/sound.c +++ b/apps/plugins/rockboy/sound.c @@ -182,7 +182,7 @@ static void gbSoundChannel1(int *r, int *l) int newfreq = 0; if(S1.swsteps) { - newfreq = freq + updown * freq / (1 << S1.swsteps); + newfreq = freq + updown * freq / BIT_N(S1.swsteps); if(newfreq == freq) newfreq = 0; } diff --git a/apps/plugins/sudoku/generator.c b/apps/plugins/sudoku/generator.c index 3d37bde..59bb906 100644 --- a/apps/plugins/sudoku/generator.c +++ b/apps/plugins/sudoku/generator.c @@ -54,7 +54,7 @@ #define STATE_MASK 0x0000ff80 #define STATE_SHIFT (7-1) /* digits 1..9 */ -#define DIGIT_STATE(digit) (1<<(STATE_SHIFT+(digit))) +#define DIGIT_STATE(digit) BIT_N(STATE_SHIFT+(digit)) #define DIGIT_MASK 0x000f0000 #define DIGIT_SHIFT 16 @@ -266,7 +266,7 @@ numset( int mask ) { int i, n = 0; for( i = STATE_SHIFT + 1 ; i <= STATE_SHIFT + 9 ; ++i ) - if( mask & (1<<i) ) + if( mask & BIT_N(i) ) ++n; else ++counts[ i - STATE_SHIFT - 1 ]; diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c index 69c41f4..413be29 100644 --- a/apps/plugins/sudoku/sudoku.c +++ b/apps/plugins/sudoku/sudoku.c @@ -337,7 +337,7 @@ void sudoku_init(Sudoku* sud); void sudoku_set(Sudoku* sud, int x, int y, int num, bool original); int sudoku_get(Sudoku* sud, int x, int y, bool* original); -#define BIT(n) ((Bitset)(1<<(n))) +#define BIT(n) ((Bitset)BIT_N(n)) #define BIT_TEST(v,n) ((((Bitset)v) & BIT(n)) != 0) #define BIT_CLEAR(v,n) (v) &= ~BIT(n) #define MARK_BIT BIT(0) @@ -965,7 +965,7 @@ void display_board(struct sudoku_state_t* state) rb->lcd_vline(XOFS+cellxpos[r]-2,YOFSSCRATCHPAD, YOFSSCRATCHPAD+CELL_HEIGHT+1); #endif - if ((r>0) && state->possiblevals[state->y][state->x]&(1<<(r))) + if ((r>0) && state->possiblevals[state->y][state->x]&BIT_N(r)) rb->lcd_bitmap_part(sudoku_normal,NUMBER_TYPE,BITMAP_HEIGHT*r, BITMAP_STRIDE,XOFS+cellxpos[r-1], YOFSSCRATCHPAD+1,CELL_WIDTH,CELL_HEIGHT); @@ -976,7 +976,7 @@ void display_board(struct sudoku_state_t* state) rb->lcd_vline(XOFS+cellxpos[8]+CELL_WIDTH+1,YOFSSCRATCHPAD, YOFSSCRATCHPAD+CELL_HEIGHT+1); #endif - if (state->possiblevals[state->y][state->x]&(1<<(r))) + if (state->possiblevals[state->y][state->x]&BIT_N(r)) rb->lcd_bitmap_part(sudoku_normal,NUMBER_TYPE,BITMAP_HEIGHT*r, BITMAP_STRIDE,XOFS+cellxpos[8],YOFSSCRATCHPAD+1, CELL_WIDTH,CELL_HEIGHT); @@ -1004,7 +1004,7 @@ void display_board(struct sudoku_state_t* state) rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, YOFS+cellypos[r]-2); #endif - if ((r>0) && state->possiblevals[state->y][state->x]&(1<<(r))) + if ((r>0) && state->possiblevals[state->y][state->x]&BIT_N(r)) rb->lcd_bitmap_part(sudoku_normal,NUMBER_TYPE,BITMAP_HEIGHT*r, BITMAP_STRIDE,XOFSSCRATCHPAD+1, YOFS+cellypos[r-1],CELL_WIDTH,CELL_HEIGHT); @@ -1015,7 +1015,7 @@ void display_board(struct sudoku_state_t* state) rb->lcd_hline(XOFSSCRATCHPAD,XOFSSCRATCHPAD+CELL_WIDTH+1, YOFS+cellypos[8]+CELL_HEIGHT+1); #endif - if (state->possiblevals[state->y][state->x]&(1<<(r))) + if (state->possiblevals[state->y][state->x]&BIT_N(r)) rb->lcd_bitmap_part(sudoku_normal,NUMBER_TYPE,BITMAP_HEIGHT*r, BITMAP_STRIDE,XOFSSCRATCHPAD+1,YOFS+cellypos[8], CELL_WIDTH,CELL_HEIGHT); @@ -1552,7 +1552,7 @@ enum plugin_status plugin_start(const void* parameter) /* Toggle current number in the possiblevals structure */ if (state.currentboard[state.y][state.x]!='0') { state.possiblevals[state.y][state.x]^= - (1 << (state.currentboard[state.y][state.x] - '0')); + BIT_N(state.currentboard[state.y][state.x] - '0'); } break; #endif diff --git a/apps/plugins/zxbox/sp_def.h b/apps/plugins/zxbox/sp_def.h index 1030be1..931804f 100644 --- a/apps/plugins/zxbox/sp_def.h +++ b/apps/plugins/zxbox/sp_def.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 1996-1998 Szeredi Miklos * Email: mszeredi@inf.bme.hu * @@ -20,7 +20,7 @@ #include "spperif.h" -#define MARK_SCR(addr) SPNM(scr_mark)[(addr) >> 5] |= 1 << ((addr) & 0x1F) +#define MARK_SCR(addr) SPNM(scr_mark)[(addr) >> 5] |= BIT_N((addr) & 0x1F) #define PUTMEM(addr, ptr, val) \ { \ diff --git a/apps/plugins/zxbox/spkey.c b/apps/plugins/zxbox/spkey.c index a21aed6..77427e8 100644 --- a/apps/plugins/zxbox/spkey.c +++ b/apps/plugins/zxbox/spkey.c @@ -85,7 +85,7 @@ int spkb_state_changed; #define SKE {0, 0, 0, 0, 0, 0, 0, 0} -#define SKP(x) (1 << x) +#define SKP(x) BIT_N(x) #define SKN0(x) {SKP(x), 0, 0, 0, 0, 0, 0, 0} #define SKN1(x) {0, SKP(x), 0, 0, 0, 0, 0, 0} @@ -617,7 +617,7 @@ static void copy_basekeys(struct spbasekey *addk) static unsigned transform_shift(int modif) { if(!modif) return 0; - else return (1 << (modif - 1)); + else return BIT_N(modif - 1); } diff --git a/apps/plugins/zxbox/spscr.c b/apps/plugins/zxbox/spscr.c index 2c24fb3..d419ff0 100644 --- a/apps/plugins/zxbox/spscr.c +++ b/apps/plugins/zxbox/spscr.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 1996-1998 Szeredi Miklos * Email: mszeredi@inf.bme.hu * @@ -82,7 +82,7 @@ byte *update_screen_line(byte *scrp, int coli, int scri, int border, SPNM(imag_mark)[coli] |= mark; SPNM(imag_horiz) |= mark; coli >>= 3; - SPNM(imag_vert) |= (1 << coli); + SPNM(imag_vert) |= BIT_N(coli); spmp = PRNM(proc).mem + (scri << 5); spcp = PRNM(proc).mem + 0x5800 + (coli << 5); |