From: Josh Coalson Date: Wed, 24 Jan 2007 04:23:53 +0000 (+0000) Subject: minor optimizations X-Git-Tag: 1.2.0~206 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5dd47832d34bdf688d53e17e87c4a174e9474aa;p=platform%2Fupstream%2Fflac.git minor optimizations --- diff --git a/src/libFLAC/fixed.c b/src/libFLAC/fixed.c index d432962..a87e6c6 100644 --- a/src/libFLAC/fixed.c +++ b/src/libFLAC/fixed.c @@ -34,6 +34,7 @@ #endif #include +#include #include "private/bitmath.h" #include "private/fixed.h" #include "FLAC/assert.h" @@ -355,32 +356,36 @@ void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, u switch(order) { case 0: - for(i = 0; i < idata_len; i++) { - residual[i] = data[i]; - } + FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); + memcpy(residual, data, sizeof(residual[0])*data_len); break; case 1: - for(i = 0; i < idata_len; i++) { + for(i = 0; i < idata_len; i++) residual[i] = data[i] - data[i-1]; - } break; case 2: - for(i = 0; i < idata_len; i++) { - /* == data[i] - 2*data[i-1] + data[i-2] */ + for(i = 0; i < idata_len; i++) +#if 1 /* OPT: may be faster with some compilers on some systems */ residual[i] = data[i] - (data[i-1] << 1) + data[i-2]; - } +#else + residual[i] = data[i] - 2*data[i-1] + data[i-2]; +#endif break; case 3: - for(i = 0; i < idata_len; i++) { - /* == data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3] */ + for(i = 0; i < idata_len; i++) +#if 1 /* OPT: may be faster with some compilers on some systems */ residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3]; - } +#else + residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3]; +#endif break; case 4: - for(i = 0; i < idata_len; i++) { - /* == data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4] */ + for(i = 0; i < idata_len; i++) +#if 1 /* OPT: may be faster with some compilers on some systems */ residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4]; - } +#else + residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4]; +#endif break; default: FLAC__ASSERT(0); @@ -393,32 +398,36 @@ void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, switch(order) { case 0: - for(i = 0; i < idata_len; i++) { - data[i] = residual[i]; - } + FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0])); + memcpy(data, residual, sizeof(residual[0])*data_len); break; case 1: - for(i = 0; i < idata_len; i++) { + for(i = 0; i < idata_len; i++) data[i] = residual[i] + data[i-1]; - } break; case 2: - for(i = 0; i < idata_len; i++) { - /* == residual[i] + 2*data[i-1] - data[i-2] */ + for(i = 0; i < idata_len; i++) +#if 1 /* OPT: may be faster with some compilers on some systems */ data[i] = residual[i] + (data[i-1]<<1) - data[i-2]; - } +#else + data[i] = residual[i] + 2*data[i-1] - data[i-2]; +#endif break; case 3: - for(i = 0; i < idata_len; i++) { - /* residual[i] + 3*data[i-1] - 3*data[i-2]) + data[i-3] */ + for(i = 0; i < idata_len; i++) +#if 1 /* OPT: may be faster with some compilers on some systems */ data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3]; - } +#else + data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3]; +#endif break; case 4: - for(i = 0; i < idata_len; i++) { - /* == residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4] */ + for(i = 0; i < idata_len; i++) +#if 1 /* OPT: may be faster with some compilers on some systems */ data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4]; - } +#else + data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4]; +#endif break; default: FLAC__ASSERT(0);