From 13f08d70fd5ba237ae53aad1de8bb3d613010246 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Sun, 29 Nov 2009 18:11:49 +0000 Subject: Enable strict aliasing optimizations for codecs on gcc versions >= 4.0, fix alising violations that this uncovered, gives small speedups for most codecs, FS#10801 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23784 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/codecs.make | 4 ++-- apps/codecs/libspc/spc_codec.h | 20 +++++++++++--------- apps/codecs/libspc/spc_dsp.c | 21 +++++++++++---------- apps/codecs/mod.c | 8 ++++---- apps/codecs/mp3_enc.c | 18 ++++++++++-------- 5 files changed, 38 insertions(+), 33 deletions(-) (limited to 'apps') diff --git a/apps/codecs/codecs.make b/apps/codecs/codecs.make index 87ed5f2b40..f169ade798 100644 --- a/apps/codecs/codecs.make +++ b/apps/codecs/codecs.make @@ -41,8 +41,8 @@ include $(APPSDIR)/codecs/librm/librm.make include $(APPSDIR)/codecs/libatrac/libatrac.make # compile flags for codecs -CODECFLAGS = $(CFLAGS) -I$(APPSDIR)/codecs -I$(APPSDIR)/codecs/lib \ - -DCODEC +CODECFLAGS = $(filter-out -fno-strict-aliasing,$(CFLAGS)) -fstrict-aliasing \ + -I$(APPSDIR)/codecs -I$(APPSDIR)/codecs/lib -DCODEC ifndef SIMVER CODEC_LDS := $(APPSDIR)/plugins/plugin.lds # codecs and plugins use same file diff --git a/apps/codecs/libspc/spc_codec.h b/apps/codecs/libspc/spc_codec.h index 923645b4aa..cf72f90af4 100644 --- a/apps/codecs/libspc/spc_codec.h +++ b/apps/codecs/libspc/spc_codec.h @@ -137,16 +137,15 @@ static inline void set_le16( void* p, unsigned n ) } #define GET_LE16( addr ) get_le16( addr ) +#define GET_LE16A( addr ) get_le16( addr ) #define SET_LE16( addr, data ) set_le16( addr, data ) #define INT16A( addr ) (*(uint16_t*) (addr)) #define INT16SA( addr ) (*(int16_t*) (addr)) #ifdef ROCKBOX_LITTLE_ENDIAN - #define GET_LE16A( addr ) (*(uint16_t*) (addr)) #define GET_LE16SA( addr ) (*( int16_t*) (addr)) #define SET_LE16A( addr, data ) (void) (*(uint16_t*) (addr) = (data)) #else - #define GET_LE16A( addr ) get_le16 ( addr ) #define GET_LE16SA( addr ) get_le16s( addr ) #define SET_LE16A( addr, data ) set_le16 ( addr, data ) #endif @@ -166,13 +165,22 @@ struct cpu_regs_t uint8_t sp; }; +struct src_dir +{ + uint16_t start; + uint16_t loop; +}; + struct cpu_ram_t { union { uint8_t padding1 [0x100]; uint16_t align; } padding1 [1]; - uint8_t ram [0x10000]; + union { + uint8_t ram [0x10000]; + struct src_dir sd [0x10000/sizeof(struct src_dir)]; + }; uint8_t padding2 [0x100]; }; @@ -339,12 +347,6 @@ struct Spc_Dsp #endif }; -struct src_dir -{ - char start [2]; - char loop [2]; -}; - void DSP_run_( struct Spc_Dsp* this, long count, int32_t* out_buf ) ICODE_ATTR; void DSP_reset( struct Spc_Dsp* this ); diff --git a/apps/codecs/libspc/spc_dsp.c b/apps/codecs/libspc/spc_dsp.c index d1facf89a2..9ebd3e6353 100644 --- a/apps/codecs/libspc/spc_dsp.c +++ b/apps/codecs/libspc/spc_dsp.c @@ -77,12 +77,13 @@ static void decode_brr( struct Spc_Dsp* this, unsigned start_addr, /* setup same variables as where decode_brr() is called from */ #undef RAM #define RAM ram.ram + struct src_dir const* const sd = - (struct src_dir*) &RAM [this->r.g.wave_page * 0x100]; + &ram.sd[this->r.g.wave_page * 0x100/sizeof(struct src_dir)]; struct cache_entry_t* const wave_entry = &this->wave_entry [raw_voice->waveform]; - - /* the following block can be put in place of the call to + + /* the following block can be put in place of the call to decode_brr() below */ { @@ -106,7 +107,7 @@ static void decode_brr( struct Spc_Dsp* this, unsigned start_addr, wave_entry->start_addr = start_addr; uint8_t const* const loop_ptr = - RAM + GET_LE16A( sd [raw_voice->waveform].loop ); + RAM + letoh16(sd[raw_voice->waveform].loop); short* loop_start = 0; short* out = BRRcache + start_addr * 2; @@ -251,7 +252,7 @@ static void key_on(struct Spc_Dsp* const this, struct voice_t* const voice, voice->envx = 0; voice->env_mode = state_attack; voice->env_timer = env_rate_init; /* TODO: inaccurate? */ - unsigned start_addr = GET_LE16A(sd [raw_voice->waveform].start); + unsigned start_addr = letoh16(sd[raw_voice->waveform].start); #if !SPC_BRRCACHE { voice->addr = RAM + start_addr; @@ -331,9 +332,9 @@ void DSP_run_( struct Spc_Dsp* this, long count, int32_t* out_buf ) } while ( (vbit >>= 1) != 0 ); } - - struct src_dir const* const sd = - (struct src_dir*) &RAM [this->r.g.wave_page * 0x100]; + + struct src_dir const* const sd = + &ram.sd[this->r.g.wave_page * 0x100/sizeof(struct src_dir)]; #ifdef ROCKBOX_BIG_ENDIAN /* Convert endiannesses before entering loops - these @@ -358,7 +359,7 @@ void DSP_run_( struct Spc_Dsp* this, long count, int32_t* out_buf ) const int echo_start = this->r.g.echo_page * 0x100; #endif /* CPU_COLDFIRE */ #else - #define VOICE_RATE(x) (INT16A(raw_voice->rate) & 0x3FFF) + #define VOICE_RATE(x) (GET_LE16(raw_voice->rate) & 0x3FFF) #define IF_RBE(...) #endif /* ROCKBOX_BIG_ENDIAN */ @@ -590,7 +591,7 @@ void DSP_run_( struct Spc_Dsp* this, long count, int32_t* out_buf ) /* action based on previous block's header */ if ( voice->block_header & 1 ) { - addr = RAM + GET_LE16A( sd [raw_voice->waveform].loop ); + addr = RAM + letoh16(sd[raw_voice->waveform].loop); this->r.g.wave_ended |= vbit; if ( !(voice->block_header & 2) ) /* 1% of the time */ { diff --git a/apps/codecs/mod.c b/apps/codecs/mod.c index 523e1c7d0b..cbeaf0837f 100644 --- a/apps/codecs/mod.c +++ b/apps/codecs/mod.c @@ -1097,16 +1097,16 @@ static inline int clip(int i) else return(i); } -STATICIRAM void synthrender(void *renderbuffer, int samplecount) ICODE_ATTR; -void synthrender(void *renderbuffer, int samplecount) +STATICIRAM void synthrender(int32_t *renderbuffer, int samplecount) ICODE_ATTR; +void synthrender(int32_t *renderbuffer, int samplecount) { /* 125bpm equals to 50Hz (= 0.02s) * => one tick = mixingrate/50, * samples passing in one tick: * mixingrate/(bpm/2.5) = 2.5*mixingrate/bpm */ - int *p_left = (int *) renderbuffer; /* int in rockbox */ - int *p_right = p_left+1; + int32_t *p_left = renderbuffer; /* int in rockbox */ + int32_t *p_right = p_left+1; signed short s; int qf_distance, qf_distance2; diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c index 82a8620027..18774ef456 100644 --- a/apps/codecs/mp3_enc.c +++ b/apps/codecs/mp3_enc.c @@ -2090,33 +2090,35 @@ STATICIRAM void to_mono_mm(void) /* |llllllllllllllll|rrrrrrrrrrrrrrrr| => * |mmmmmmmmmmmmmmmm|mmmmmmmmmmmmmmmm| */ - uint32_t *samp = (uint32_t *)&mfbuf[2*512]; - uint32_t *samp_end = samp + samp_per_frame; + uint16_t *samp = &mfbuf[2*512]; + uint16_t *samp_end = samp + 2*samp_per_frame; - inline void to_mono(uint32_t **samp) + inline void to_mono(uint16_t **samp) { - int32_t lr = **samp; + int16_t l = **samp; + int16_t r = **(samp+1); int32_t m; switch(cfg.rec_mono_mode) { case 1: /* mono = L */ - m = lr >> 16; + m = l; break; case 2: /* mono = R */ - m = (int16_t)lr; + m = r; break; case 0: default: /* mono = (L+R)/2 */ - m = (int16_t)lr + (lr >> 16) + err; + m = r + r + err; err = m & 1; m >>= 1; break; } - *(*samp)++ = (m << 16) | (uint16_t)m; + *(*samp)++ = (uint16_t)m; + *(*samp)++ = (uint16_t)m; } /* to_mono */ do -- cgit v1.2.3