summaryrefslogtreecommitdiffstats
path: root/apps/codecs/demac/libdemac/filter.c
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2008-11-24 18:40:49 +0000
committerJens Arnold <amiconn@rockbox.org>2008-11-24 18:40:49 +0000
commit3761c0108cbfc6f88c4bf43fc13a38a2f7db0d6f (patch)
treea064992dc69635d60e7bc1cb106fc43c6a4e3a40 /apps/codecs/demac/libdemac/filter.c
parent66c0cf2eb17158eec9d0cd2553481a2caf86e611 (diff)
downloadrockbox-3761c0108cbfc6f88c4bf43fc13a38a2f7db0d6f.tar.gz
rockbox-3761c0108cbfc6f88c4bf43fc13a38a2f7db0d6f.zip
Branch optimisation in both C (giving hints to gcc - verified using -fprofile-arcs and gcov) and asm files. Biggest effect on coldfire (-c1000: +8%, -c2000: +5%), but ARM also profits a bit (less than 1% on ARM7TDMI, around 1% on ARM1136).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19199 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/demac/libdemac/filter.c')
-rw-r--r--apps/codecs/demac/libdemac/filter.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/apps/codecs/demac/libdemac/filter.c b/apps/codecs/demac/libdemac/filter.c
index 5601fffcd4..d66bdc69b0 100644
--- a/apps/codecs/demac/libdemac/filter.c
+++ b/apps/codecs/demac/libdemac/filter.c
@@ -100,7 +100,7 @@ struct filter_t {
#if defined(CPU_ARM) && (ARM_ARCH >= 6)
#define SATURATE(x) ({int __res; asm("ssat %0, #16, %1" : "=r"(__res) : "r"(x)); __res; })
#else
-#define SATURATE(x) (((x) == (int16_t)(x)) ? (x) : ((x) >> 31) ^ 0x7FFF);
+#define SATURATE(x) (LIKELY((x) == (int16_t)(x)) ? (x) : ((x) >> 31) ^ 0x7FFF);
#endif
/* Apply the filter with state f to count entries in data[] */
@@ -109,20 +109,22 @@ static void ICODE_ATTR_DEMAC do_apply_filter_3980(struct filter_t* f,
int32_t* data, int count)
{
int res;
- int absres;
+ int absres;
#ifdef PREPARE_SCALARPRODUCT
PREPARE_SCALARPRODUCT
#endif
- while(count--)
+ while(LIKELY(count--))
{
res = FP_TO_INT(scalarproduct(f->coeffs, f->delay - ORDER));
- if (*data < 0)
- vector_add(f->coeffs, f->adaptcoeffs - ORDER);
- else if (*data > 0)
- vector_sub(f->coeffs, f->adaptcoeffs - ORDER);
+ if (LIKELY(*data != 0)) {
+ if (*data < 0)
+ vector_add(f->coeffs, f->adaptcoeffs - ORDER);
+ else
+ vector_sub(f->coeffs, f->adaptcoeffs - ORDER);
+ }
res += *data;
@@ -136,11 +138,11 @@ static void ICODE_ATTR_DEMAC do_apply_filter_3980(struct filter_t* f,
/* Update the adaption coefficients */
absres = (res < 0 ? -res : res);
- if (absres > (f->avg * 3))
+ if (UNLIKELY(absres > (f->avg * 3)))
*f->adaptcoeffs = ((res >> 25) & 64) - 32;
else if (absres > (f->avg * 4) / 3)
*f->adaptcoeffs = ((res >> 26) & 32) - 16;
- else if (absres > 0)
+ else if (LIKELY(absres > 0))
*f->adaptcoeffs = ((res >> 27) & 16) - 8;
else
*f->adaptcoeffs = 0;
@@ -154,7 +156,7 @@ static void ICODE_ATTR_DEMAC do_apply_filter_3980(struct filter_t* f,
f->adaptcoeffs++;
/* Have we filled the history buffer? */
- if (f->delay == f->history_end) {
+ if (UNLIKELY(f->delay == f->history_end)) {
memmove(f->coeffs + ORDER, f->delay - (ORDER*2),
(ORDER*2) * sizeof(filter_int));
f->adaptcoeffs = f->coeffs + ORDER*2;
@@ -172,14 +174,16 @@ static void ICODE_ATTR_DEMAC do_apply_filter_3970(struct filter_t* f,
PREPARE_SCALARPRODUCT
#endif
- while(count--)
+ while(LIKELY(count--))
{
res = FP_TO_INT(scalarproduct(f->coeffs, f->delay - ORDER));
- if (*data < 0)
- vector_add(f->coeffs, f->adaptcoeffs - ORDER);
- else if (*data > 0)
- vector_sub(f->coeffs, f->adaptcoeffs - ORDER);
+ if (LIKELY(*data != 0)) {
+ if (*data < 0)
+ vector_add(f->coeffs, f->adaptcoeffs - ORDER);
+ else
+ vector_sub(f->coeffs, f->adaptcoeffs - ORDER);
+ }
/* Convert res from (32-FRACBITS).FRACBITS fixed-point format to an
integer (rounding to nearest) and add the input value to
@@ -199,7 +203,7 @@ static void ICODE_ATTR_DEMAC do_apply_filter_3970(struct filter_t* f,
f->adaptcoeffs++;
/* Have we filled the history buffer? */
- if (f->delay == f->history_end) {
+ if (UNLIKELY(f->delay == f->history_end)) {
memmove(f->coeffs + ORDER, f->delay - (ORDER*2),
(ORDER*2) * sizeof(filter_int));
f->adaptcoeffs = f->coeffs + ORDER*2;