From 96e5e9eef81a3758fd7bca3b21a5874c4e9f760e Mon Sep 17 00:00:00 2001 From: Thom Johansen Date: Thu, 15 Feb 2007 22:51:45 +0000 Subject: [PATCH] Optimise/touchup some asm macros in dsp.h, and also remove some now unneeded ones. Add config.h to dsp.c so that these macros actually get used, and also do some minor nitpicks to the resampler while I'm at it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12322 a1c6a512-1295-4272-9138-f99709370657 --- apps/dsp.c | 9 ++-- apps/dsp.h | 119 +++++++++++++++++++++++------------------------------ 2 files changed, 56 insertions(+), 72 deletions(-) diff --git a/apps/dsp.c b/apps/dsp.c index 533342ecf1..e0fb4475da 100644 --- a/apps/dsp.c +++ b/apps/dsp.c @@ -19,6 +19,7 @@ #include #include #include +#include "config.h" #include "dsp.h" #include "eq.h" #include "kernel.h" @@ -268,7 +269,6 @@ static int downsample(int32_t **dst, int32_t **src, int count, /* Wrap phase accumulator back to start of next frame. */ r->phase = phase - (count << 16); - r->delta = delta; r->last_sample[0] = src[0][count - 1]; r->last_sample[1] = src[1][count - 1]; return i; @@ -282,12 +282,12 @@ static long upsample(int32_t **dst, int32_t **src, int count, struct resample_da int i = 0, j; int pos; int num_channels = dsp->stereo_mode == STEREO_MONO ? 1 : 2; - - while ((pos = phase >> 16) == 0) + + while ((phase >> 16) == 0) { for (j = 0; j < num_channels; j++) *d[j]++ = r->last_sample[j] + FRACMUL((phase & 0xffff) << 15, - src[j][pos] - r->last_sample[j]); + src[j][0] - r->last_sample[j]); phase += delta; i++; } @@ -303,7 +303,6 @@ static long upsample(int32_t **dst, int32_t **src, int count, struct resample_da /* Wrap phase accumulator back to start of next frame. */ r->phase = phase - (count << 16); - r->delta = delta; r->last_sample[0] = src[0][count - 1]; r->last_sample[1] = src[1][count - 1]; return i; diff --git a/apps/dsp.h b/apps/dsp.h index 2f676d22bc..8e82b6118d 100644 --- a/apps/dsp.h +++ b/apps/dsp.h @@ -49,6 +49,9 @@ enum { /* A bunch of fixed point assembler helper macros */ #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) +/* These macros use the Coldfire EMAC extension and need the MACSR flags set + * to fractional mode with no rounding. + */ /* Multiply two S.31 fractional integers and return the sign bit and the * 31 most significant bits of the result. @@ -56,9 +59,9 @@ enum { #define FRACMUL(x, y) \ ({ \ long t; \ - asm volatile ("mac.l %[a], %[b], %%acc0\n\t" \ - "movclr.l %%acc0, %[t]\n\t" \ - : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \ + asm ("mac.l %[a], %[b], %%acc0\n\t" \ + "movclr.l %%acc0, %[t]\n\t" \ + : [t] "=r" (t) : [a] "r" (x), [b] "r" (y)); \ t; \ }) @@ -69,70 +72,50 @@ enum { #define FRACMUL_SHL(x, y, z) \ ({ \ long t, t2; \ - asm volatile ("mac.l %[a], %[b], %%acc0\n\t" \ - "moveq.l %[d], %[t]\n\t" \ - "move.l %%accext01, %[t2]\n\t" \ - "and.l %[mask], %[t2]\n\t" \ - "lsr.l %[t], %[t2]\n\t" \ - "movclr.l %%acc0, %[t]\n\t" \ - "asl.l %[c], %[t]\n\t" \ - "or.l %[t2], %[t]\n\t" \ - : [t] "=d" (t), [t2] "=d" (t2) \ - : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \ - [c] "i" ((z)), [d] "i" (8 - (z))); \ + asm ("mac.l %[a], %[b], %%acc0\n\t" \ + "moveq.l %[d], %[t]\n\t" \ + "move.l %%accext01, %[t2]\n\t" \ + "and.l %[mask], %[t2]\n\t" \ + "lsr.l %[t], %[t2]\n\t" \ + "movclr.l %%acc0, %[t]\n\t" \ + "asl.l %[c], %[t]\n\t" \ + "or.l %[t2], %[t]\n\t" \ + : [t] "=&d" (t), [t2] "=&d" (t2) \ + : [a] "r" (x), [b] "r" (y), [mask] "d" (0xff), \ + [c] "i" ((z)), [d] "i" (8 - (z))); \ t; \ }) -/* Multiply one S.31-bit and one S8.23 fractional integer and return the - * sign bit and the 31 most significant bits of the result. - */ -#define FRACMUL_8(x, y) \ -({ \ - long t; \ - long u; \ - asm volatile ("mac.l %[a], %[b], %%acc0\n\t" \ - "move.l %%accext01, %[u]\n\t" \ - "movclr.l %%acc0, %[t]\n\t" \ - : [t] "=r" (t), [u] "=r" (u) : [a] "r" (x), [b] "r" (y)); \ - (t << 8) | (u & 0xff); \ -}) - /* Multiply one S.31-bit and one S8.23 fractional integer and return the * sign bit and the 31 most significant bits of the result. Load next value * to multiply with into x from s (and increase s); x must contain the * initial value. */ -#define FRACMUL_8_LOOP_PART(x, s, d, y) \ -{ \ - long u; \ - asm volatile ("mac.l %[a], %[b], (%[c])+, %[a], %%acc0\n\t" \ - "move.l %%accext01, %[u]\n\t" \ - "movclr.l %%acc0, %[t]" \ - : [a] "+r" (x), [c] "+a" (s), [t] "=r" (d), [u] "=r" (u) \ - : [b] "r" (y)); \ - d = (d << 8) | (u & 0xff); \ -} - #define FRACMUL_8_LOOP(x, y, s, d) \ { \ - long t; \ - FRACMUL_8_LOOP_PART(x, s, t, y); \ - asm volatile ("move.l %[t],(%[d])+" \ - : [d] "+a" (d)\ - : [t] "r" (t)); \ + long t, t2; \ + asm volatile ("mac.l %[a], %[b], (%[src])+, %[a], %%acc0\n\t" \ + "move.l %%accext01, %[t2]\n\t" \ + "movclr.l %%acc0, %[t]\n\t" \ + "asl.l #8, %[t]\n\t" \ + "move.b %[t2], %[t]\n\t" \ + "move.l %[t], (%[dst])+\n\t" \ + : [a] "+r" (x), [src] "+a" (s), [dst] "+a" (d), \ + [t] "=r" (t), [t2] "=r" (t2) \ + : [b] "r" (y)); \ } #define ACC(acc, x, y) \ (void)acc; \ - asm volatile ("mac.l %[a], %[b], %%acc0" \ - : : [a] "i,r" (x), [b] "i,r" (y)); + asm ("mac.l %[a], %[b], %%acc0" \ + : : [a] "i,r" (x), [b] "i,r" (y)); #define GET_ACC(acc) \ ({ \ long t; \ (void)acc; \ - asm volatile ("movclr.l %%acc0, %[t]" \ - : [t] "=r" (t)); \ + asm ("movclr.l %%acc0, %[t]" \ + : [t] "=r" (t)); \ t; \ }) @@ -145,11 +128,12 @@ enum { */ #define FRACMUL(x, y) \ ({ \ - long t; \ - asm volatile ("smull r0, r1, %[a], %[b]\n\t" \ - "mov %[t], r1, asl #1\n\t" \ - "orr %[t], %[t], r0, lsr #31\n\t" \ - : [t] "=r" (t) : [a] "r" (x), [b] "r" (y) : "r0", "r1"); \ + long t, t2; \ + asm ("smull %[t], %[t2], %[a], %[b]\n\t" \ + "mov %[t2], %[t2], asl #1\n\t" \ + "orr %[t], %[t2], %[t], lsr #31\n\t" \ + : [t] "=&r" (t), [t2] "=&r" (t2) \ + : [a] "r" (x), [b] "r" (y)); \ t; \ }) @@ -158,14 +142,13 @@ enum { */ #define FRACMUL_SHL(x, y, z) \ ({ \ - long t; \ - asm volatile ("smull r0, r1, %[a], %[b]\n\t" \ - "mov %[t], r1, asl %[c]\n\t" \ - "orr %[t], %[t], r0, lsr %[d]\n\t" \ - : [t] "=r" (t) \ - : [a] "r" (x), [b] "r" (y), \ - [c] "M" ((z) + 1), [d] "M" (31 - (z)) \ - : "r0", "r1"); \ + long t, t2; \ + asm ("smull %[t], %[t2], %[a], %[b]\n\t" \ + "mov %[t2], %[t2], asl %[c]\n\t" \ + "orr %[t], %[t2], %[t], lsr %[d]\n\t" \ + : [t] "=&r" (t), [t2] "=&r" (t2) \ + : [a] "r" (x), [b] "r" (y), \ + [c] "M" ((z) + 1), [d] "M" (31 - (z))); \ t; \ }) @@ -180,10 +163,12 @@ enum { */ #define FRACMUL_8_LOOP(x, y, s, d) \ ({ \ - asm volatile ("smull r0, r1, %[a], %[b]\n\t" \ - "mov %[t], r1, asl #9\n\t" \ - "orr %[t], %[t], r0, lsr #23\n\t" \ - : [t] "=r" (*(d)++) : [a] "r" (x), [b] "r" (y) : "r0", "r1"); \ + long t, t2; \ + asm volatile ("smull %[t], %[t2], %[a], %[b]\n\t" \ + "mov %[t2], %[t2], asl #9\n\t" \ + "orr %[d], %[t2], %[t], lsr #23\n\t" \ + : [d] "=&r" (*(d)++), [t] "=&r" (t), [t2] "=&r" (t2) \ + : [a] "r" (x), [b] "r" (y)); \ x = *(s)++; \ }) @@ -193,8 +178,8 @@ enum { #define ACC(acc, x, y) acc += FRACMUL(x, y) #define GET_ACC(acc) acc #define FRACMUL(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 31)) -#define FRACMUL_SHL(x, y, z) ((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z))))) -#define FRACMUL_8(x, y) (long) (((((long long) (x)) * ((long long) (y))) >> 23)) +#define FRACMUL_SHL(x, y, z) \ +((long)(((((long long) (x)) * ((long long) (y))) >> (31 - (z))))) #define FRACMUL_8_LOOP(x, y, s, d) \ ({ \ long t = x; \