From 3a0b012ee016e2fe40f49c72da119cb89d2ba312 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 12 Aug 2009 17:08:41 +0200 Subject: volume: add first mmx optimized function Add code for an mmx optimized version of s16ne volume scaling. Install the custom function. --- src/pulsecore/svolume_mmx.c | 424 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 424 insertions(+) create mode 100644 src/pulsecore/svolume_mmx.c (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c new file mode 100644 index 00000000..9f49a624 --- /dev/null +++ b/src/pulsecore/svolume_mmx.c @@ -0,0 +1,424 @@ +/*** + This file is part of PulseAudio. + + Copyright 2004-2006 Lennart Poettering + Copyright 2009 Wim Taymans + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include +#include + +#include "sample-util.h" +#include "endianmacros.h" + +#if 0 +static void +pa_volume_u8_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + for (channel = 0; length; length--) { + int32_t t, hi, lo; + + hi = volumes[channel] >> 16; + lo = volumes[channel] & 0xFFFF; + + t = (int32_t) *samples - 0x80; + t = ((t * lo) >> 16) + (t * hi); + t = PA_CLAMP_UNLIKELY(t, -0x80, 0x7F); + *samples++ = (uint8_t) (t + 0x80); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_alaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + for (channel = 0; length; length--) { + int32_t t, hi, lo; + + hi = volumes[channel] >> 16; + lo = volumes[channel] & 0xFFFF; + + t = (int32_t) st_alaw2linear16(*samples); + t = ((t * lo) >> 16) + (t * hi); + t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF); + *samples++ = (uint8_t) st_13linear2alaw((int16_t) t >> 3); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_ulaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + for (channel = 0; length; length--) { + int32_t t, hi, lo; + + hi = volumes[channel] >> 16; + lo = volumes[channel] & 0xFFFF; + + t = (int32_t) st_ulaw2linear16(*samples); + t = ((t * lo) >> 16) + (t * hi); + t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF); + *samples++ = (uint8_t) st_14linear2ulaw((int16_t) t >> 2); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} +#endif + +static void +pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + int64_t channel, temp; + + /* the max number of samples we process at a time */ + channels = MAX (4, channels); + +#define VOLUME_32x16(s,v) /* v1_h | v1_l | v0_h | v0_l */ \ + " pxor %%mm4, %%mm4 \n\t" \ + " punpcklwd %%mm4, "#s" \n\t" /* 0 | p1 | 0 | p0 */ \ + " pcmpgtw "#s", %%mm4 \n\t" /* select sign from sample */ \ + " pand "#v", %%mm4 \n\t" /* extract correction factors */ \ + " movq "#s", %%mm5 \n\t" \ + " pmulhuw "#v", "#s" \n\t" /* 0 | p1*v1lh | 0 | p0*v0lh */ \ + " psubd %%mm4, "#s" \n\t" /* sign correction */ \ + " psrld $16, "#v" \n\t" /* 0 | v1h | 0 | v0h */ \ + " pmaddwd %%mm5, "#v" \n\t" /* p1 * v1h | p0 * v0h */ \ + " paddd "#s", "#v" \n\t" /* p1 * v1 | p0 * v0 */ \ + " packssdw "#v", "#v" \n\t" /* p0*v0 | p1*v1 | p0*v0 | p1*v1 */ + +#define MOD_ADD(a,b) \ + " add "#a", %3 \n\t" \ + " mov %3, %4 \n\t" \ + " sub %5, %4 \n\t" \ + " cmp %3, "#b" \n\t" \ + " cmovae %4, %3 \n\t" + + __asm__ __volatile__ ( + " xor %3, %3 \n\t" + " sar $1, %2 \n\t" /* length /= sizeof (int16_t) */ + + " test $1, %2 \n\t" /* check for odd samples */ + " je 2f \n\t" + + " movd (%1, %3, 4), %%mm0 \n\t" /* do odd samples */ + " movw (%0), %%ax \n\t" + " movd %%eax, %%mm1 \n\t" + VOLUME_32x16 (%%mm1, %%mm0) + " movd %%mm0, %%eax \n\t" + " movw %%ax, (%0) \n\t" + " add $2, %0 \n\t" + MOD_ADD ($1, %5) + " dec %2 \n\t" + + "2: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 2 samples at a time */ + " test $1, %2 \n\t" /* check for odd samples */ + " je 4f \n\t" + + "3: \n\t" /* do samples in pairs of 2 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* v1_h | v1_l | v0_h | v0_l */ + " movd (%0), %%mm1 \n\t" /* X | X | p1 | p0 */ + VOLUME_32x16 (%%mm1, %%mm0) + " movd %%mm0, (%0) \n\t" + " add $4, %0 \n\t" + MOD_ADD ($2, %5) + " dec %2 \n\t" + + "4: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 4 samples at a time */ + " cmp $0, %2 \n\t" + " je 6f \n\t" + + "5: \n\t" /* do samples in pairs of 4 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* v1_h | v1_l | v0_h | v0_l */ + " movq 8(%1, %3, 4), %%mm2 \n\t" /* v3_h | v3_l | v2_h | v2_l */ + " movd (%0), %%mm1 \n\t" /* X | X | p1 | p0 */ + " movd 4(%0), %%mm3 \n\t" /* X | X | p3 | p2 */ + VOLUME_32x16 (%%mm1, %%mm0) + VOLUME_32x16 (%%mm3, %%mm2) + " movd %%mm0, (%0) \n\t" + " movd %%mm2, 4(%0) \n\t" + " add $8, %0 \n\t" + MOD_ADD ($4, %5) + " dec %2 \n\t" + " jne 5b \n\t" + + "6: \n\t" + " emms \n\t" + + : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((int64_t)channel), "=r" (temp) + : "r" ((int64_t)channels) + : "rax", "cc" + ); +} + +#if 0 +static void +pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + length /= sizeof (int16_t); + + for (channel = 0; length; length--) { + int32_t t, hi, lo; + + hi = volumes[channel] >> 16; + lo = volumes[channel] & 0xFFFF; + + t = (int32_t) PA_INT16_SWAP(*samples); + t = ((t * lo) >> 16) + (t * hi); + t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF); + *samples++ = PA_INT16_SWAP((int16_t) t); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_float32ne_mmx (float *samples, float *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + length /= sizeof (float); + + for (channel = 0; length; length--) { + *samples++ *= volumes[channel]; + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_float32re_mmx (float *samples, float *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + length /= sizeof (float); + + for (channel = 0; length; length--) { + float t; + + t = PA_FLOAT32_SWAP(*samples); + t *= volumes[channel]; + *samples++ = PA_FLOAT32_SWAP(t); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_s32ne_mmx (int32_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + length /= sizeof (int32_t); + + for (channel = 0; length; length--) { + int64_t t; + + t = (int64_t)(*samples); + t = (t * volumes[channel]) >> 16; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + *samples++ = (int32_t) t; + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_s32re_mmx (int32_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + length /= sizeof (int32_t); + + for (channel = 0; length; length--) { + int64_t t; + + t = (int64_t) PA_INT32_SWAP(*samples); + t = (t * volumes[channel]) >> 16; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + *samples++ = PA_INT32_SWAP((int32_t) t); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_s24ne_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + uint8_t *e; + + e = samples + length; + + for (channel = 0; samples < e; samples += 3) { + int64_t t; + + t = (int64_t)((int32_t) (PA_READ24NE(samples) << 8)); + t = (t * volumes[channel]) >> 16; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + PA_WRITE24NE(samples, ((uint32_t) (int32_t) t) >> 8); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_s24re_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + uint8_t *e; + + e = samples + length; + + for (channel = 0; samples < e; samples += 3) { + int64_t t; + + t = (int64_t)((int32_t) (PA_READ24RE(samples) << 8)); + t = (t * volumes[channel]) >> 16; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + PA_WRITE24RE(samples, ((uint32_t) (int32_t) t) >> 8); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_s24_32ne_mmx (uint32_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + length /= sizeof (uint32_t); + + for (channel = 0; length; length--) { + int64_t t; + + t = (int64_t) ((int32_t) (*samples << 8)); + t = (t * volumes[channel]) >> 16; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + *samples++ = ((uint32_t) ((int32_t) t)) >> 8; + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} + +static void +pa_volume_s24_32re_mmx (uint32_t *samples, int32_t *volumes, unsigned channels, unsigned length) +{ + unsigned channel; + + length /= sizeof (uint32_t); + + for (channel = 0; length; length--) { + int64_t t; + + t = (int64_t) ((int32_t) (PA_UINT32_SWAP(*samples) << 8)); + t = (t * volumes[channel]) >> 16; + t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); + *samples++ = PA_UINT32_SWAP(((uint32_t) ((int32_t) t)) >> 8); + + if (PA_UNLIKELY(++channel >= channels)) + channel = 0; + } +} +#endif + +#undef RUN_TEST + +#ifdef RUN_TEST +#define CHANNELS 1 +#define SAMPLES 1021 +#define TIMES 1000 + +static void run_test (void) { + int16_t samples[SAMPLES]; + int16_t samples_ref[SAMPLES]; + int16_t samples_orig[SAMPLES]; + int32_t volumes[CHANNELS]; + int i, j; + pa_do_volume_func_t func; + + func = pa_get_volume_func (PA_SAMPLE_S16NE); + + printf ("checking\n"); + + for (j = 0; j < TIMES; j++) { + pa_random (samples, sizeof (samples)); + memcpy (samples_ref, samples, sizeof (samples)); + memcpy (samples_orig, samples, sizeof (samples)); + + for (i = 0; i < CHANNELS; i++) { + volumes[i] = rand() >> 15; + } + + pa_volume_s16ne_mmx (samples, volumes, CHANNELS, SAMPLES * sizeof (int16_t)); + func (samples_ref, volumes, CHANNELS, SAMPLES * sizeof (int16_t)); + + for (i = 0; i < SAMPLES; i++) { + if (samples[i] != samples_ref[i]) { + printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], + samples_orig[i], volumes[i % CHANNELS]); + } +#if 0 + else + printf ("%d: %04x == %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], + samples_orig[i], volumes[i % CHANNELS]); +#endif + } + } +} +#endif + +void pa_volume_func_init_mmx (void) { + pa_log_info("Initialising MMX optimized functions."); + +#ifdef RUN_TEST + run_test (); +#endif + + pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_mmx); +} -- cgit From 08f3e16c84fabca9c6789440f98ff8dca62eb81a Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 12 Aug 2009 20:43:37 +0200 Subject: volume_mmx: fix mmx code a bit --- src/pulsecore/svolume_mmx.c | 46 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 9f49a624..6dcc26c2 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -104,14 +104,15 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi { int64_t channel, temp; - /* the max number of samples we process at a time */ + /* the max number of samples we process at a time, this is also the max amount + * we overread the volume array, which should have enough padding. */ channels = MAX (4, channels); #define VOLUME_32x16(s,v) /* v1_h | v1_l | v0_h | v0_l */ \ " pxor %%mm4, %%mm4 \n\t" \ " punpcklwd %%mm4, "#s" \n\t" /* 0 | p1 | 0 | p0 */ \ " pcmpgtw "#s", %%mm4 \n\t" /* select sign from sample */ \ - " pand "#v", %%mm4 \n\t" /* extract correction factors */ \ + " pand "#v", %%mm4 \n\t" /* extract sign correction factors */ \ " movq "#s", %%mm5 \n\t" \ " pmulhuw "#v", "#s" \n\t" /* 0 | p1*v1lh | 0 | p0*v0lh */ \ " psubd %%mm4, "#s" \n\t" /* sign correction */ \ @@ -123,8 +124,8 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi #define MOD_ADD(a,b) \ " add "#a", %3 \n\t" \ " mov %3, %4 \n\t" \ - " sub %5, %4 \n\t" \ - " cmp %3, "#b" \n\t" \ + " sub "#b", %4 \n\t" \ + " cmp "#b", %3 \n\t" \ " cmovae %4, %3 \n\t" __asm__ __volatile__ ( @@ -135,14 +136,13 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " je 2f \n\t" " movd (%1, %3, 4), %%mm0 \n\t" /* do odd samples */ - " movw (%0), %%ax \n\t" - " movd %%eax, %%mm1 \n\t" + " movw (%0), %4 \n\t" + " movd %4, %%mm1 \n\t" VOLUME_32x16 (%%mm1, %%mm0) - " movd %%mm0, %%eax \n\t" - " movw %%ax, (%0) \n\t" + " movd %%mm0, %4 \n\t" + " movw %4, (%0) \n\t" " add $2, %0 \n\t" MOD_ADD ($1, %5) - " dec %2 \n\t" "2: \n\t" " sar $1, %2 \n\t" /* prepare for processing 2 samples at a time */ @@ -156,7 +156,6 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " movd %%mm0, (%0) \n\t" " add $4, %0 \n\t" MOD_ADD ($2, %5) - " dec %2 \n\t" "4: \n\t" " sar $1, %2 \n\t" /* prepare for processing 4 samples at a time */ @@ -180,9 +179,9 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi "6: \n\t" " emms \n\t" - : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((int64_t)channel), "=r" (temp) + : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((int64_t)channel), "=&r" (temp) : "r" ((int64_t)channels) - : "rax", "cc" + : "cc" ); } @@ -370,7 +369,7 @@ pa_volume_s24_32re_mmx (uint32_t *samples, int32_t *volumes, unsigned channels, #undef RUN_TEST #ifdef RUN_TEST -#define CHANNELS 1 +#define CHANNELS 2 #define SAMPLES 1021 #define TIMES 1000 @@ -378,25 +377,32 @@ static void run_test (void) { int16_t samples[SAMPLES]; int16_t samples_ref[SAMPLES]; int16_t samples_orig[SAMPLES]; - int32_t volumes[CHANNELS]; - int i, j; + int32_t volumes[CHANNELS + 16]; + int i, j, padding; pa_do_volume_func_t func; func = pa_get_volume_func (PA_SAMPLE_S16NE); - printf ("checking\n"); + printf ("checking %d\n", sizeof (samples)); for (j = 0; j < TIMES; j++) { + /* + for (i = 0; i < SAMPLES; i++) { + samples[i] samples_ref[i] = samples_orig[i] = rand() >> 16; + } + */ + pa_random (samples, sizeof (samples)); memcpy (samples_ref, samples, sizeof (samples)); memcpy (samples_orig, samples, sizeof (samples)); - for (i = 0; i < CHANNELS; i++) { + for (i = 0; i < CHANNELS; i++) volumes[i] = rand() >> 15; - } + for (padding = 0; padding < 16; padding++, i++) + volumes[i] = volumes[padding]; - pa_volume_s16ne_mmx (samples, volumes, CHANNELS, SAMPLES * sizeof (int16_t)); - func (samples_ref, volumes, CHANNELS, SAMPLES * sizeof (int16_t)); + pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); + func (samples_ref, volumes, CHANNELS, sizeof (samples)); for (i = 0; i < SAMPLES; i++) { if (samples[i] != samples_ref[i]) { -- cgit From 5998cf99b08d448dd5158ed6229262aa67ea4a66 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 13 Aug 2009 13:45:01 +0200 Subject: svolume: improve SSE and MMX code --- src/pulsecore/svolume_mmx.c | 200 +++++++++++++++++++++++++++++--------------- 1 file changed, 134 insertions(+), 66 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 6dcc26c2..3c229456 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -99,6 +99,46 @@ pa_volume_ulaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsig } #endif +#define VOLUME_32x16(s,v) /* .. | vh | vl | */ \ + " pxor %%mm4, %%mm4 \n\t" /* .. | 0 | 0 | */ \ + " punpcklwd %%mm4, "#s" \n\t" /* .. | 0 | p0 | */ \ + " pcmpgtw "#v", %%mm4 \n\t" /* .. | 0 | s(vl) | */ \ + " pand "#s", %%mm4 \n\t" /* .. | 0 | (p0) | (vl >> 15) & p */ \ + " movq %%mm6, %%mm5 \n\t" /* .. | ffff | 0 | */ \ + " pand "#v", %%mm5 \n\t" /* .. | vh | 0 | */ \ + " por %%mm5, %%mm4 \n\t" /* .. | vh | (p0) | */ \ + " pmulhw "#s", "#v" \n\t" /* .. | 0 | vl*p0 | */ \ + " paddw %%mm4, "#v" \n\t" /* .. | vh | vl*p0 | vh + sign correct */ \ + " pslld $16, "#s" \n\t" /* .. | p0 | 0 | */ \ + " por %%mm7, "#s" \n\t" /* .. | p0 | 1 | */ \ + " pmaddwd "#s", "#v" \n\t" /* .. | p0 * v0 | */ \ + " packssdw "#v", "#v" \n\t" /* .. | p1*v1 | p0*v0 | */ + +#define MOD_ADD(a,b) \ + " add "#a", %3 \n\t" \ + " mov %3, %4 \n\t" \ + " sub "#b", %4 \n\t" \ + " cmp "#b", %3 \n\t" \ + " cmovae %4, %3 \n\t" + +/* swap 16 bits */ +#define SWAP_16(s) \ + " movq "#s", %%mm4 \n\t" /* .. | h l | */ \ + " psrlw $8, %%mm4 \n\t" /* .. | 0 h | */ \ + " psllw $8, "#s" \n\t" /* .. | l 0 | */ \ + " por %%mm4, "#s" \n\t" /* .. | l h | */ + +/* swap 2 registers 16 bits for better pairing */ +#define SWAP_16_2(s1,s2) \ + " movq "#s1", %%mm4 \n\t" /* .. | h l | */ \ + " movq "#s2", %%mm5 \n\t" \ + " psrlw $8, %%mm4 \n\t" /* .. | 0 h | */ \ + " psrlw $8, %%mm5 \n\t" \ + " psllw $8, "#s1" \n\t" /* .. | l 0 | */ \ + " psllw $8, "#s2" \n\t" \ + " por %%mm4, "#s1" \n\t" /* .. | l h | */ \ + " por %%mm5, "#s2" \n\t" + static void pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { @@ -108,38 +148,22 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi * we overread the volume array, which should have enough padding. */ channels = MAX (4, channels); -#define VOLUME_32x16(s,v) /* v1_h | v1_l | v0_h | v0_l */ \ - " pxor %%mm4, %%mm4 \n\t" \ - " punpcklwd %%mm4, "#s" \n\t" /* 0 | p1 | 0 | p0 */ \ - " pcmpgtw "#s", %%mm4 \n\t" /* select sign from sample */ \ - " pand "#v", %%mm4 \n\t" /* extract sign correction factors */ \ - " movq "#s", %%mm5 \n\t" \ - " pmulhuw "#v", "#s" \n\t" /* 0 | p1*v1lh | 0 | p0*v0lh */ \ - " psubd %%mm4, "#s" \n\t" /* sign correction */ \ - " psrld $16, "#v" \n\t" /* 0 | v1h | 0 | v0h */ \ - " pmaddwd %%mm5, "#v" \n\t" /* p1 * v1h | p0 * v0h */ \ - " paddd "#s", "#v" \n\t" /* p1 * v1 | p0 * v0 */ \ - " packssdw "#v", "#v" \n\t" /* p0*v0 | p1*v1 | p0*v0 | p1*v1 */ - -#define MOD_ADD(a,b) \ - " add "#a", %3 \n\t" \ - " mov %3, %4 \n\t" \ - " sub "#b", %4 \n\t" \ - " cmp "#b", %3 \n\t" \ - " cmovae %4, %3 \n\t" - __asm__ __volatile__ ( " xor %3, %3 \n\t" " sar $1, %2 \n\t" /* length /= sizeof (int16_t) */ + " pcmpeqw %%mm6, %%mm6 \n\t" /* .. | ffff | ffff | */ + " pcmpeqw %%mm7, %%mm7 \n\t" /* .. | ffff | ffff | */ + " pslld $16, %%mm6 \n\t" /* .. | ffff | 0 | */ + " psrld $31, %%mm7 \n\t" /* .. | 0 | 1 | */ " test $1, %2 \n\t" /* check for odd samples */ " je 2f \n\t" - " movd (%1, %3, 4), %%mm0 \n\t" /* do odd samples */ - " movw (%0), %4 \n\t" + " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ + " movw (%0), %4 \n\t" /* .. | p0 | */ " movd %4, %%mm1 \n\t" VOLUME_32x16 (%%mm1, %%mm0) - " movd %%mm0, %4 \n\t" + " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ " movw %4, (%0) \n\t" " add $2, %0 \n\t" MOD_ADD ($1, %5) @@ -149,11 +173,11 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " test $1, %2 \n\t" /* check for odd samples */ " je 4f \n\t" - "3: \n\t" /* do samples in pairs of 2 */ - " movq (%1, %3, 4), %%mm0 \n\t" /* v1_h | v1_l | v0_h | v0_l */ - " movd (%0), %%mm1 \n\t" /* X | X | p1 | p0 */ + "3: \n\t" /* do samples in groups of 2 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ VOLUME_32x16 (%%mm1, %%mm0) - " movd %%mm0, (%0) \n\t" + " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ " add $4, %0 \n\t" MOD_ADD ($2, %5) @@ -162,15 +186,15 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " cmp $0, %2 \n\t" " je 6f \n\t" - "5: \n\t" /* do samples in pairs of 4 */ - " movq (%1, %3, 4), %%mm0 \n\t" /* v1_h | v1_l | v0_h | v0_l */ - " movq 8(%1, %3, 4), %%mm2 \n\t" /* v3_h | v3_l | v2_h | v2_l */ - " movd (%0), %%mm1 \n\t" /* X | X | p1 | p0 */ - " movd 4(%0), %%mm3 \n\t" /* X | X | p3 | p2 */ + "5: \n\t" /* do samples in groups of 4 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movq 8(%1, %3, 4), %%mm2 \n\t" /* | v3h | v3l | v2h | v2l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ + " movd 4(%0), %%mm3 \n\t" /* .. | p3 | p2 | */ VOLUME_32x16 (%%mm1, %%mm0) VOLUME_32x16 (%%mm3, %%mm2) - " movd %%mm0, (%0) \n\t" - " movd %%mm2, 4(%0) \n\t" + " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ + " movd %%mm2, 4(%0) \n\t" /* | p3*v3 | p2*v2 | */ " add $8, %0 \n\t" MOD_ADD ($4, %5) " dec %2 \n\t" @@ -185,30 +209,83 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi ); } -#if 0 static void pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { - unsigned channel; + int64_t channel, temp; - length /= sizeof (int16_t); + /* the max number of samples we process at a time, this is also the max amount + * we overread the volume array, which should have enough padding. */ + channels = MAX (4, channels); - for (channel = 0; length; length--) { - int32_t t, hi, lo; + __asm__ __volatile__ ( + " xor %3, %3 \n\t" + " sar $1, %2 \n\t" /* length /= sizeof (int16_t) */ + " pcmpeqw %%mm6, %%mm6 \n\t" /* .. | ffff | ffff | */ + " pcmpeqw %%mm7, %%mm7 \n\t" /* .. | ffff | ffff | */ + " pslld $16, %%mm6 \n\t" /* .. | ffff | 0 | */ + " psrld $31, %%mm7 \n\t" /* .. | 0 | 1 | */ - hi = volumes[channel] >> 16; - lo = volumes[channel] & 0xFFFF; + " test $1, %2 \n\t" /* check for odd samples */ + " je 2f \n\t" - t = (int32_t) PA_INT16_SWAP(*samples); - t = ((t * lo) >> 16) + (t * hi); - t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF); - *samples++ = PA_INT16_SWAP((int16_t) t); + " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ + " movw (%0), %4 \n\t" /* .. | p0 | */ + " rorw $8, %4 \n\t" + " movd %4, %%mm1 \n\t" + VOLUME_32x16 (%%mm1, %%mm0) + " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ + " rorw $8, %4 \n\t" + " movw %4, (%0) \n\t" + " add $2, %0 \n\t" + MOD_ADD ($1, %5) - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } + "2: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 2 samples at a time */ + " test $1, %2 \n\t" /* check for odd samples */ + " je 4f \n\t" + + "3: \n\t" /* do samples in groups of 2 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ + SWAP_16 (%%mm1) + VOLUME_32x16 (%%mm1, %%mm0) + SWAP_16 (%%mm0) + " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ + " add $4, %0 \n\t" + MOD_ADD ($2, %5) + + "4: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 4 samples at a time */ + " cmp $0, %2 \n\t" + " je 6f \n\t" + + "5: \n\t" /* do samples in groups of 4 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movq 8(%1, %3, 4), %%mm2 \n\t" /* | v3h | v3l | v2h | v2l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ + " movd 4(%0), %%mm3 \n\t" /* .. | p3 | p2 | */ + SWAP_16_2 (%%mm1, %%mm3) + VOLUME_32x16 (%%mm1, %%mm0) + VOLUME_32x16 (%%mm3, %%mm2) + SWAP_16_2 (%%mm0, %%mm2) + " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ + " movd %%mm2, 4(%0) \n\t" /* | p3*v3 | p2*v2 | */ + " add $8, %0 \n\t" + MOD_ADD ($4, %5) + " dec %2 \n\t" + " jne 5b \n\t" + + "6: \n\t" + " emms \n\t" + + : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((int64_t)channel), "=&r" (temp) + : "r" ((int64_t)channels) + : "cc" + ); } +#if 0 static void pa_volume_float32ne_mmx (float *samples, float *volumes, unsigned channels, unsigned length) { @@ -366,42 +443,37 @@ pa_volume_s24_32re_mmx (uint32_t *samples, int32_t *volumes, unsigned channels, } #endif -#undef RUN_TEST +#define RUN_TEST #ifdef RUN_TEST #define CHANNELS 2 #define SAMPLES 1021 #define TIMES 1000 +#define PADDING 16 static void run_test (void) { int16_t samples[SAMPLES]; int16_t samples_ref[SAMPLES]; int16_t samples_orig[SAMPLES]; - int32_t volumes[CHANNELS + 16]; + int32_t volumes[CHANNELS + PADDING]; int i, j, padding; pa_do_volume_func_t func; - func = pa_get_volume_func (PA_SAMPLE_S16NE); + func = pa_get_volume_func (PA_SAMPLE_S16RE); - printf ("checking %d\n", sizeof (samples)); + printf ("checking MMX %d\n", sizeof (samples)); for (j = 0; j < TIMES; j++) { - /* - for (i = 0; i < SAMPLES; i++) { - samples[i] samples_ref[i] = samples_orig[i] = rand() >> 16; - } - */ - pa_random (samples, sizeof (samples)); memcpy (samples_ref, samples, sizeof (samples)); memcpy (samples_orig, samples, sizeof (samples)); for (i = 0; i < CHANNELS; i++) - volumes[i] = rand() >> 15; - for (padding = 0; padding < 16; padding++, i++) + volumes[i] = rand() >> 1; + for (padding = 0; padding < PADDING; padding++, i++) volumes[i] = volumes[padding]; - pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); + pa_volume_s16re_mmx (samples, volumes, CHANNELS, sizeof (samples)); func (samples_ref, volumes, CHANNELS, sizeof (samples)); for (i = 0; i < SAMPLES; i++) { @@ -409,11 +481,6 @@ static void run_test (void) { printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], samples_orig[i], volumes[i % CHANNELS]); } -#if 0 - else - printf ("%d: %04x == %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], - samples_orig[i], volumes[i % CHANNELS]); -#endif } } } @@ -427,4 +494,5 @@ void pa_volume_func_init_mmx (void) { #endif pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_mmx); + pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_mmx); } -- cgit From 563cb2dea9f7f73180e2b8cc8d45b0df9358c936 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 13 Aug 2009 17:12:44 +0200 Subject: main: hook up cpu detection code Add CPU detection code to activate the various optimisations. Move some method definitions around. Use compatibility macros when we can. --- src/pulsecore/svolume_mmx.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 3c229456..e56f7c31 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -31,6 +31,8 @@ #include #include +#include "cpu-x86.h" + #include "sample-util.h" #include "endianmacros.h" @@ -142,7 +144,7 @@ pa_volume_ulaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsig static void pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { - int64_t channel, temp; + pa_reg_x86 channel, temp; /* the max number of samples we process at a time, this is also the max amount * we overread the volume array, which should have enough padding. */ @@ -203,8 +205,8 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi "6: \n\t" " emms \n\t" - : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((int64_t)channel), "=&r" (temp) - : "r" ((int64_t)channels) + : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((pa_reg_x86)channel), "=&r" (temp) + : "r" ((pa_reg_x86)channels) : "cc" ); } @@ -212,7 +214,7 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi static void pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { - int64_t channel, temp; + pa_reg_x86 channel, temp; /* the max number of samples we process at a time, this is also the max amount * we overread the volume array, which should have enough padding. */ @@ -279,8 +281,8 @@ pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi "6: \n\t" " emms \n\t" - : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((int64_t)channel), "=&r" (temp) - : "r" ((int64_t)channels) + : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((pa_reg_x86)channel), "=&r" (temp) + : "r" ((pa_reg_x86)channels) : "cc" ); } @@ -443,7 +445,7 @@ pa_volume_s24_32re_mmx (uint32_t *samples, int32_t *volumes, unsigned channels, } #endif -#define RUN_TEST +#undef RUN_TEST #ifdef RUN_TEST #define CHANNELS 2 @@ -486,7 +488,7 @@ static void run_test (void) { } #endif -void pa_volume_func_init_mmx (void) { +void pa_volume_func_init_mmx (pa_cpu_x86_flag_t flags) { pa_log_info("Initialising MMX optimized functions."); #ifdef RUN_TEST -- cgit From dcae9a3113d1ce30e330c97dd5a81fec4e272bed Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 14 Aug 2009 13:12:30 +0200 Subject: svolume: add some comments --- src/pulsecore/svolume_mmx.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index e56f7c31..b36fe946 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -101,6 +101,22 @@ pa_volume_ulaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsig } #endif +/* in s: 2 int16_t samples + * in v: 2 int32_t volumes, fixed point 16:16 + * out s: contains scaled and clamped int16_t samples. + * + * We calculate the high 32 bits of a 32x16 multiply which we then + * clamp to 16 bits. The calulcation is: + * + * vl = (v & 0xffff) + * vh = (v >> 16) + * s = ((s * vl) >> 16) + (s * vh); + * + * For the first multiply we have to do a sign correction as we need to + * multiply a signed int with an unsigned int. Hacker's delight 8-3 gives a + * simple formula to correct the sign of the high word after the signed + * multiply. + */ #define VOLUME_32x16(s,v) /* .. | vh | vl | */ \ " pxor %%mm4, %%mm4 \n\t" /* .. | 0 | 0 | */ \ " punpcklwd %%mm4, "#s" \n\t" /* .. | 0 | p0 | */ \ @@ -116,6 +132,8 @@ pa_volume_ulaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsig " pmaddwd "#s", "#v" \n\t" /* .. | p0 * v0 | */ \ " packssdw "#v", "#v" \n\t" /* .. | p1*v1 | p0*v0 | */ +/* approximately advances %3 = (%3 + a) % b. This function requires that + * a <= b. */ #define MOD_ADD(a,b) \ " add "#a", %3 \n\t" \ " mov %3, %4 \n\t" \ -- cgit From a1235446a733164f00a96688784913172456a34e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 14 Aug 2009 15:19:26 +0200 Subject: volume: make the benchmark more meaningfull MMX is about 6x faster, SSE around 15x on my machine. --- src/pulsecore/svolume_mmx.c | 53 ++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index b36fe946..9ad7dea1 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -24,8 +24,7 @@ #include #endif -#include - +#include #include #include #include @@ -478,31 +477,45 @@ static void run_test (void) { int32_t volumes[CHANNELS + PADDING]; int i, j, padding; pa_do_volume_func_t func; + struct timeval start, stop; - func = pa_get_volume_func (PA_SAMPLE_S16RE); - - printf ("checking MMX %d\n", sizeof (samples)); + func = pa_get_volume_func (PA_SAMPLE_S16NE); - for (j = 0; j < TIMES; j++) { - pa_random (samples, sizeof (samples)); - memcpy (samples_ref, samples, sizeof (samples)); - memcpy (samples_orig, samples, sizeof (samples)); + printf ("checking MMX %zd\n", sizeof (samples)); - for (i = 0; i < CHANNELS; i++) - volumes[i] = rand() >> 1; - for (padding = 0; padding < PADDING; padding++, i++) - volumes[i] = volumes[padding]; + pa_random (samples, sizeof (samples)); + memcpy (samples_ref, samples, sizeof (samples)); + memcpy (samples_orig, samples, sizeof (samples)); - pa_volume_s16re_mmx (samples, volumes, CHANNELS, sizeof (samples)); - func (samples_ref, volumes, CHANNELS, sizeof (samples)); + for (i = 0; i < CHANNELS; i++) + volumes[i] = rand() >> 1; + for (padding = 0; padding < PADDING; padding++, i++) + volumes[i] = volumes[padding]; - for (i = 0; i < SAMPLES; i++) { - if (samples[i] != samples_ref[i]) { - printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], - samples_orig[i], volumes[i % CHANNELS]); - } + func (samples_ref, volumes, CHANNELS, sizeof (samples)); + pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); + for (i = 0; i < SAMPLES; i++) { + if (samples[i] != samples_ref[i]) { + printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], + samples_orig[i], volumes[i % CHANNELS]); } } + + pa_gettimeofday(&start); + for (j = 0; j < TIMES; j++) { + memcpy (samples, samples_orig, sizeof (samples)); + pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); + } + pa_gettimeofday(&stop); + pa_log_info("MMX: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); + + pa_gettimeofday(&start); + for (j = 0; j < TIMES; j++) { + memcpy (samples_ref, samples_orig, sizeof (samples)); + func (samples_ref, volumes, CHANNELS, sizeof (samples)); + } + pa_gettimeofday(&stop); + pa_log_info("ref: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); } #endif -- cgit From f24c24c14b6614cf19ee916886c8b02384bac435 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 14 Aug 2009 15:41:32 +0200 Subject: volume: improved comments --- src/pulsecore/svolume_mmx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 9ad7dea1..d4fcedf5 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -196,7 +196,7 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ VOLUME_32x16 (%%mm1, %%mm0) - " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ " add $4, %0 \n\t" MOD_ADD ($2, %5) @@ -212,8 +212,8 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " movd 4(%0), %%mm3 \n\t" /* .. | p3 | p2 | */ VOLUME_32x16 (%%mm1, %%mm0) VOLUME_32x16 (%%mm3, %%mm2) - " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ - " movd %%mm2, 4(%0) \n\t" /* | p3*v3 | p2*v2 | */ + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ + " movd %%mm2, 4(%0) \n\t" /* .. | p3*v3 | p2*v2 | */ " add $8, %0 \n\t" MOD_ADD ($4, %5) " dec %2 \n\t" @@ -270,7 +270,7 @@ pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi SWAP_16 (%%mm1) VOLUME_32x16 (%%mm1, %%mm0) SWAP_16 (%%mm0) - " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ " add $4, %0 \n\t" MOD_ADD ($2, %5) @@ -288,8 +288,8 @@ pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi VOLUME_32x16 (%%mm1, %%mm0) VOLUME_32x16 (%%mm3, %%mm2) SWAP_16_2 (%%mm0, %%mm2) - " movd %%mm0, (%0) \n\t" /* | p1*v1 | p0*v0 | */ - " movd %%mm2, 4(%0) \n\t" /* | p3*v3 | p2*v2 | */ + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ + " movd %%mm2, 4(%0) \n\t" /* .. | p3*v3 | p2*v2 | */ " add $8, %0 \n\t" MOD_ADD ($4, %5) " dec %2 \n\t" -- cgit From 591baacba5913de32e6556a71a8300d25addbec4 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 14 Aug 2009 15:48:10 +0200 Subject: volume: remove ref functions --- src/pulsecore/svolume_mmx.c | 223 -------------------------------------------- 1 file changed, 223 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index d4fcedf5..ad539278 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -35,71 +35,6 @@ #include "sample-util.h" #include "endianmacros.h" -#if 0 -static void -pa_volume_u8_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - for (channel = 0; length; length--) { - int32_t t, hi, lo; - - hi = volumes[channel] >> 16; - lo = volumes[channel] & 0xFFFF; - - t = (int32_t) *samples - 0x80; - t = ((t * lo) >> 16) + (t * hi); - t = PA_CLAMP_UNLIKELY(t, -0x80, 0x7F); - *samples++ = (uint8_t) (t + 0x80); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_alaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - for (channel = 0; length; length--) { - int32_t t, hi, lo; - - hi = volumes[channel] >> 16; - lo = volumes[channel] & 0xFFFF; - - t = (int32_t) st_alaw2linear16(*samples); - t = ((t * lo) >> 16) + (t * hi); - t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF); - *samples++ = (uint8_t) st_13linear2alaw((int16_t) t >> 3); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_ulaw_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - for (channel = 0; length; length--) { - int32_t t, hi, lo; - - hi = volumes[channel] >> 16; - lo = volumes[channel] & 0xFFFF; - - t = (int32_t) st_ulaw2linear16(*samples); - t = ((t * lo) >> 16) + (t * hi); - t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF); - *samples++ = (uint8_t) st_14linear2ulaw((int16_t) t >> 2); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} -#endif - /* in s: 2 int16_t samples * in v: 2 int32_t volumes, fixed point 16:16 * out s: contains scaled and clamped int16_t samples. @@ -304,164 +239,6 @@ pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi ); } -#if 0 -static void -pa_volume_float32ne_mmx (float *samples, float *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - length /= sizeof (float); - - for (channel = 0; length; length--) { - *samples++ *= volumes[channel]; - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_float32re_mmx (float *samples, float *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - length /= sizeof (float); - - for (channel = 0; length; length--) { - float t; - - t = PA_FLOAT32_SWAP(*samples); - t *= volumes[channel]; - *samples++ = PA_FLOAT32_SWAP(t); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_s32ne_mmx (int32_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - length /= sizeof (int32_t); - - for (channel = 0; length; length--) { - int64_t t; - - t = (int64_t)(*samples); - t = (t * volumes[channel]) >> 16; - t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); - *samples++ = (int32_t) t; - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_s32re_mmx (int32_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - length /= sizeof (int32_t); - - for (channel = 0; length; length--) { - int64_t t; - - t = (int64_t) PA_INT32_SWAP(*samples); - t = (t * volumes[channel]) >> 16; - t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); - *samples++ = PA_INT32_SWAP((int32_t) t); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_s24ne_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - uint8_t *e; - - e = samples + length; - - for (channel = 0; samples < e; samples += 3) { - int64_t t; - - t = (int64_t)((int32_t) (PA_READ24NE(samples) << 8)); - t = (t * volumes[channel]) >> 16; - t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); - PA_WRITE24NE(samples, ((uint32_t) (int32_t) t) >> 8); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_s24re_mmx (uint8_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - uint8_t *e; - - e = samples + length; - - for (channel = 0; samples < e; samples += 3) { - int64_t t; - - t = (int64_t)((int32_t) (PA_READ24RE(samples) << 8)); - t = (t * volumes[channel]) >> 16; - t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); - PA_WRITE24RE(samples, ((uint32_t) (int32_t) t) >> 8); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_s24_32ne_mmx (uint32_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - length /= sizeof (uint32_t); - - for (channel = 0; length; length--) { - int64_t t; - - t = (int64_t) ((int32_t) (*samples << 8)); - t = (t * volumes[channel]) >> 16; - t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); - *samples++ = ((uint32_t) ((int32_t) t)) >> 8; - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} - -static void -pa_volume_s24_32re_mmx (uint32_t *samples, int32_t *volumes, unsigned channels, unsigned length) -{ - unsigned channel; - - length /= sizeof (uint32_t); - - for (channel = 0; length; length--) { - int64_t t; - - t = (int64_t) ((int32_t) (PA_UINT32_SWAP(*samples) << 8)); - t = (t * volumes[channel]) >> 16; - t = PA_CLAMP_UNLIKELY(t, -0x80000000LL, 0x7FFFFFFFLL); - *samples++ = PA_UINT32_SWAP(((uint32_t) ((int32_t) t)) >> 8); - - if (PA_UNLIKELY(++channel >= channels)) - channel = 0; - } -} -#endif - #undef RUN_TEST #ifdef RUN_TEST -- cgit From a98fa950d2f04e2ba4d4a470296a081e1050f76d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 19 Aug 2009 15:56:44 +0200 Subject: svolume: remove unneeded compare We don't need the compare because the sub operation already set the right flags for us. --- src/pulsecore/svolume_mmx.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index ad539278..5243b447 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -72,7 +72,6 @@ " add "#a", %3 \n\t" \ " mov %3, %4 \n\t" \ " sub "#b", %4 \n\t" \ - " cmp "#b", %3 \n\t" \ " cmovae %4, %3 \n\t" /* swap 16 bits */ -- cgit From bd49d43bd387758f151c56b7ed1643ecb72c0258 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 19 Aug 2009 16:09:48 +0200 Subject: svolume: add CPU guards around code Mark code that should only be compiled on x86 CPUs with proper defines. --- src/pulsecore/svolume_mmx.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 5243b447..fb4c82c6 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -35,6 +35,7 @@ #include "sample-util.h" #include "endianmacros.h" +#if defined (__i386__) || defined (__amd64__) /* in s: 2 int16_t samples * in v: 2 int32_t volumes, fixed point 16:16 * out s: contains scaled and clamped int16_t samples. @@ -295,7 +296,11 @@ static void run_test (void) { } #endif +#endif /* defined (__i386__) || defined (__amd64__) */ + + void pa_volume_func_init_mmx (pa_cpu_x86_flag_t flags) { +#if defined (__i386__) || defined (__amd64__) pa_log_info("Initialising MMX optimized functions."); #ifdef RUN_TEST @@ -304,4 +309,5 @@ void pa_volume_func_init_mmx (pa_cpu_x86_flag_t flags) { pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_mmx); pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_mmx); +#endif /* defined (__i386__) || defined (__amd64__) */ } -- cgit From 370016c0e73236830513a9ea9c16366c15bd30a2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 19 Aug 2009 18:52:28 +0200 Subject: svolume: fix compilation in 32bits --- src/pulsecore/svolume_mmx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index fb4c82c6..86af76d3 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -114,11 +114,11 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " je 2f \n\t" " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ - " movw (%0), %4 \n\t" /* .. | p0 | */ + " movw (%0), %w4 \n\t" /* .. | p0 | */ " movd %4, %%mm1 \n\t" VOLUME_32x16 (%%mm1, %%mm0) " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ - " movw %4, (%0) \n\t" + " movw %w4, (%0) \n\t" " add $2, %0 \n\t" MOD_ADD ($1, %5) @@ -184,13 +184,13 @@ pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi " je 2f \n\t" " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ - " movw (%0), %4 \n\t" /* .. | p0 | */ - " rorw $8, %4 \n\t" + " movw (%0), %w4 \n\t" /* .. | p0 | */ + " rorw $8, %w4 \n\t" " movd %4, %%mm1 \n\t" VOLUME_32x16 (%%mm1, %%mm0) " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ - " rorw $8, %4 \n\t" - " movw %4, (%0) \n\t" + " rorw $8, %w4 \n\t" + " movw %w4, (%0) \n\t" " add $2, %0 \n\t" MOD_ADD ($1, %5) -- cgit From f09b51198f43d79b22cb92b5223d01a7ab339d9f Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 20 Aug 2009 10:56:20 +0200 Subject: whitespace fixes --- src/pulsecore/svolume_mmx.c | 366 ++++++++++++++++++++++---------------------- 1 file changed, 183 insertions(+), 183 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 86af76d3..7e242684 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -73,7 +73,7 @@ " add "#a", %3 \n\t" \ " mov %3, %4 \n\t" \ " sub "#b", %4 \n\t" \ - " cmovae %4, %3 \n\t" + " cmovae %4, %3 \n\t" /* swap 16 bits */ #define SWAP_16(s) \ @@ -96,147 +96,147 @@ static void pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { - pa_reg_x86 channel, temp; - - /* the max number of samples we process at a time, this is also the max amount - * we overread the volume array, which should have enough padding. */ - channels = MAX (4, channels); - - __asm__ __volatile__ ( - " xor %3, %3 \n\t" - " sar $1, %2 \n\t" /* length /= sizeof (int16_t) */ - " pcmpeqw %%mm6, %%mm6 \n\t" /* .. | ffff | ffff | */ - " pcmpeqw %%mm7, %%mm7 \n\t" /* .. | ffff | ffff | */ - " pslld $16, %%mm6 \n\t" /* .. | ffff | 0 | */ - " psrld $31, %%mm7 \n\t" /* .. | 0 | 1 | */ - - " test $1, %2 \n\t" /* check for odd samples */ - " je 2f \n\t" - - " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ - " movw (%0), %w4 \n\t" /* .. | p0 | */ - " movd %4, %%mm1 \n\t" - VOLUME_32x16 (%%mm1, %%mm0) - " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ - " movw %w4, (%0) \n\t" - " add $2, %0 \n\t" - MOD_ADD ($1, %5) - - "2: \n\t" - " sar $1, %2 \n\t" /* prepare for processing 2 samples at a time */ - " test $1, %2 \n\t" /* check for odd samples */ - " je 4f \n\t" - - "3: \n\t" /* do samples in groups of 2 */ - " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ - " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ - VOLUME_32x16 (%%mm1, %%mm0) - " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ - " add $4, %0 \n\t" - MOD_ADD ($2, %5) - - "4: \n\t" - " sar $1, %2 \n\t" /* prepare for processing 4 samples at a time */ - " cmp $0, %2 \n\t" - " je 6f \n\t" - - "5: \n\t" /* do samples in groups of 4 */ - " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ - " movq 8(%1, %3, 4), %%mm2 \n\t" /* | v3h | v3l | v2h | v2l | */ - " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ - " movd 4(%0), %%mm3 \n\t" /* .. | p3 | p2 | */ - VOLUME_32x16 (%%mm1, %%mm0) - VOLUME_32x16 (%%mm3, %%mm2) - " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ - " movd %%mm2, 4(%0) \n\t" /* .. | p3*v3 | p2*v2 | */ - " add $8, %0 \n\t" - MOD_ADD ($4, %5) - " dec %2 \n\t" - " jne 5b \n\t" - - "6: \n\t" - " emms \n\t" - - : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((pa_reg_x86)channel), "=&r" (temp) - : "r" ((pa_reg_x86)channels) - : "cc" - ); + pa_reg_x86 channel, temp; + + /* the max number of samples we process at a time, this is also the max amount + * we overread the volume array, which should have enough padding. */ + channels = MAX (4, channels); + + __asm__ __volatile__ ( + " xor %3, %3 \n\t" + " sar $1, %2 \n\t" /* length /= sizeof (int16_t) */ + " pcmpeqw %%mm6, %%mm6 \n\t" /* .. | ffff | ffff | */ + " pcmpeqw %%mm7, %%mm7 \n\t" /* .. | ffff | ffff | */ + " pslld $16, %%mm6 \n\t" /* .. | ffff | 0 | */ + " psrld $31, %%mm7 \n\t" /* .. | 0 | 1 | */ + + " test $1, %2 \n\t" /* check for odd samples */ + " je 2f \n\t" + + " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ + " movw (%0), %w4 \n\t" /* .. | p0 | */ + " movd %4, %%mm1 \n\t" + VOLUME_32x16 (%%mm1, %%mm0) + " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ + " movw %w4, (%0) \n\t" + " add $2, %0 \n\t" + MOD_ADD ($1, %5) + + "2: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 2 samples at a time */ + " test $1, %2 \n\t" /* check for odd samples */ + " je 4f \n\t" + + "3: \n\t" /* do samples in groups of 2 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ + VOLUME_32x16 (%%mm1, %%mm0) + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ + " add $4, %0 \n\t" + MOD_ADD ($2, %5) + + "4: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 4 samples at a time */ + " cmp $0, %2 \n\t" + " je 6f \n\t" + + "5: \n\t" /* do samples in groups of 4 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movq 8(%1, %3, 4), %%mm2 \n\t" /* | v3h | v3l | v2h | v2l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ + " movd 4(%0), %%mm3 \n\t" /* .. | p3 | p2 | */ + VOLUME_32x16 (%%mm1, %%mm0) + VOLUME_32x16 (%%mm3, %%mm2) + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ + " movd %%mm2, 4(%0) \n\t" /* .. | p3*v3 | p2*v2 | */ + " add $8, %0 \n\t" + MOD_ADD ($4, %5) + " dec %2 \n\t" + " jne 5b \n\t" + + "6: \n\t" + " emms \n\t" + + : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((pa_reg_x86)channel), "=&r" (temp) + : "r" ((pa_reg_x86)channels) + : "cc" + ); } static void pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsigned length) { - pa_reg_x86 channel, temp; - - /* the max number of samples we process at a time, this is also the max amount - * we overread the volume array, which should have enough padding. */ - channels = MAX (4, channels); - - __asm__ __volatile__ ( - " xor %3, %3 \n\t" - " sar $1, %2 \n\t" /* length /= sizeof (int16_t) */ - " pcmpeqw %%mm6, %%mm6 \n\t" /* .. | ffff | ffff | */ - " pcmpeqw %%mm7, %%mm7 \n\t" /* .. | ffff | ffff | */ - " pslld $16, %%mm6 \n\t" /* .. | ffff | 0 | */ - " psrld $31, %%mm7 \n\t" /* .. | 0 | 1 | */ - - " test $1, %2 \n\t" /* check for odd samples */ - " je 2f \n\t" - - " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ - " movw (%0), %w4 \n\t" /* .. | p0 | */ - " rorw $8, %w4 \n\t" - " movd %4, %%mm1 \n\t" - VOLUME_32x16 (%%mm1, %%mm0) - " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ - " rorw $8, %w4 \n\t" - " movw %w4, (%0) \n\t" - " add $2, %0 \n\t" - MOD_ADD ($1, %5) - - "2: \n\t" - " sar $1, %2 \n\t" /* prepare for processing 2 samples at a time */ - " test $1, %2 \n\t" /* check for odd samples */ - " je 4f \n\t" - - "3: \n\t" /* do samples in groups of 2 */ - " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ - " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ - SWAP_16 (%%mm1) - VOLUME_32x16 (%%mm1, %%mm0) - SWAP_16 (%%mm0) - " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ - " add $4, %0 \n\t" - MOD_ADD ($2, %5) - - "4: \n\t" - " sar $1, %2 \n\t" /* prepare for processing 4 samples at a time */ - " cmp $0, %2 \n\t" - " je 6f \n\t" - - "5: \n\t" /* do samples in groups of 4 */ - " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ - " movq 8(%1, %3, 4), %%mm2 \n\t" /* | v3h | v3l | v2h | v2l | */ - " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ - " movd 4(%0), %%mm3 \n\t" /* .. | p3 | p2 | */ - SWAP_16_2 (%%mm1, %%mm3) - VOLUME_32x16 (%%mm1, %%mm0) - VOLUME_32x16 (%%mm3, %%mm2) - SWAP_16_2 (%%mm0, %%mm2) - " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ - " movd %%mm2, 4(%0) \n\t" /* .. | p3*v3 | p2*v2 | */ - " add $8, %0 \n\t" - MOD_ADD ($4, %5) - " dec %2 \n\t" - " jne 5b \n\t" - - "6: \n\t" - " emms \n\t" - - : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((pa_reg_x86)channel), "=&r" (temp) - : "r" ((pa_reg_x86)channels) - : "cc" - ); + pa_reg_x86 channel, temp; + + /* the max number of samples we process at a time, this is also the max amount + * we overread the volume array, which should have enough padding. */ + channels = MAX (4, channels); + + __asm__ __volatile__ ( + " xor %3, %3 \n\t" + " sar $1, %2 \n\t" /* length /= sizeof (int16_t) */ + " pcmpeqw %%mm6, %%mm6 \n\t" /* .. | ffff | ffff | */ + " pcmpeqw %%mm7, %%mm7 \n\t" /* .. | ffff | ffff | */ + " pslld $16, %%mm6 \n\t" /* .. | ffff | 0 | */ + " psrld $31, %%mm7 \n\t" /* .. | 0 | 1 | */ + + " test $1, %2 \n\t" /* check for odd samples */ + " je 2f \n\t" + + " movd (%1, %3, 4), %%mm0 \n\t" /* | v0h | v0l | */ + " movw (%0), %w4 \n\t" /* .. | p0 | */ + " rorw $8, %w4 \n\t" + " movd %4, %%mm1 \n\t" + VOLUME_32x16 (%%mm1, %%mm0) + " movd %%mm0, %4 \n\t" /* .. | p0*v0 | */ + " rorw $8, %w4 \n\t" + " movw %w4, (%0) \n\t" + " add $2, %0 \n\t" + MOD_ADD ($1, %5) + + "2: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 2 samples at a time */ + " test $1, %2 \n\t" /* check for odd samples */ + " je 4f \n\t" + + "3: \n\t" /* do samples in groups of 2 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ + SWAP_16 (%%mm1) + VOLUME_32x16 (%%mm1, %%mm0) + SWAP_16 (%%mm0) + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ + " add $4, %0 \n\t" + MOD_ADD ($2, %5) + + "4: \n\t" + " sar $1, %2 \n\t" /* prepare for processing 4 samples at a time */ + " cmp $0, %2 \n\t" + " je 6f \n\t" + + "5: \n\t" /* do samples in groups of 4 */ + " movq (%1, %3, 4), %%mm0 \n\t" /* | v1h | v1l | v0h | v0l | */ + " movq 8(%1, %3, 4), %%mm2 \n\t" /* | v3h | v3l | v2h | v2l | */ + " movd (%0), %%mm1 \n\t" /* .. | p1 | p0 | */ + " movd 4(%0), %%mm3 \n\t" /* .. | p3 | p2 | */ + SWAP_16_2 (%%mm1, %%mm3) + VOLUME_32x16 (%%mm1, %%mm0) + VOLUME_32x16 (%%mm3, %%mm2) + SWAP_16_2 (%%mm0, %%mm2) + " movd %%mm0, (%0) \n\t" /* .. | p1*v1 | p0*v0 | */ + " movd %%mm2, 4(%0) \n\t" /* .. | p3*v3 | p2*v2 | */ + " add $8, %0 \n\t" + MOD_ADD ($4, %5) + " dec %2 \n\t" + " jne 5b \n\t" + + "6: \n\t" + " emms \n\t" + + : "+r" (samples), "+r" (volumes), "+r" (length), "=D" ((pa_reg_x86)channel), "=&r" (temp) + : "r" ((pa_reg_x86)channels) + : "cc" + ); } #undef RUN_TEST @@ -248,51 +248,51 @@ pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi #define PADDING 16 static void run_test (void) { - int16_t samples[SAMPLES]; - int16_t samples_ref[SAMPLES]; - int16_t samples_orig[SAMPLES]; - int32_t volumes[CHANNELS + PADDING]; - int i, j, padding; - pa_do_volume_func_t func; - struct timeval start, stop; - - func = pa_get_volume_func (PA_SAMPLE_S16NE); - - printf ("checking MMX %zd\n", sizeof (samples)); - - pa_random (samples, sizeof (samples)); - memcpy (samples_ref, samples, sizeof (samples)); - memcpy (samples_orig, samples, sizeof (samples)); - - for (i = 0; i < CHANNELS; i++) - volumes[i] = rand() >> 1; - for (padding = 0; padding < PADDING; padding++, i++) - volumes[i] = volumes[padding]; - - func (samples_ref, volumes, CHANNELS, sizeof (samples)); - pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); - for (i = 0; i < SAMPLES; i++) { - if (samples[i] != samples_ref[i]) { - printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], - samples_orig[i], volumes[i % CHANNELS]); - } - } + int16_t samples[SAMPLES]; + int16_t samples_ref[SAMPLES]; + int16_t samples_orig[SAMPLES]; + int32_t volumes[CHANNELS + PADDING]; + int i, j, padding; + pa_do_volume_func_t func; + struct timeval start, stop; - pa_gettimeofday(&start); - for (j = 0; j < TIMES; j++) { - memcpy (samples, samples_orig, sizeof (samples)); - pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); - } - pa_gettimeofday(&stop); - pa_log_info("MMX: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); + func = pa_get_volume_func (PA_SAMPLE_S16NE); + + printf ("checking MMX %zd\n", sizeof (samples)); + + pa_random (samples, sizeof (samples)); + memcpy (samples_ref, samples, sizeof (samples)); + memcpy (samples_orig, samples, sizeof (samples)); + + for (i = 0; i < CHANNELS; i++) + volumes[i] = rand() >> 1; + for (padding = 0; padding < PADDING; padding++, i++) + volumes[i] = volumes[padding]; - pa_gettimeofday(&start); - for (j = 0; j < TIMES; j++) { - memcpy (samples_ref, samples_orig, sizeof (samples)); func (samples_ref, volumes, CHANNELS, sizeof (samples)); - } - pa_gettimeofday(&stop); - pa_log_info("ref: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); + pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); + for (i = 0; i < SAMPLES; i++) { + if (samples[i] != samples_ref[i]) { + printf ("%d: %04x != %04x (%04x * %04x)\n", i, samples[i], samples_ref[i], + samples_orig[i], volumes[i % CHANNELS]); + } + } + + pa_gettimeofday(&start); + for (j = 0; j < TIMES; j++) { + memcpy (samples, samples_orig, sizeof (samples)); + pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); + } + pa_gettimeofday(&stop); + pa_log_info("MMX: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); + + pa_gettimeofday(&start); + for (j = 0; j < TIMES; j++) { + memcpy (samples_ref, samples_orig, sizeof (samples)); + func (samples_ref, volumes, CHANNELS, sizeof (samples)); + } + pa_gettimeofday(&stop); + pa_log_info("ref: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); } #endif @@ -301,13 +301,13 @@ static void run_test (void) { void pa_volume_func_init_mmx (pa_cpu_x86_flag_t flags) { #if defined (__i386__) || defined (__amd64__) - pa_log_info("Initialising MMX optimized functions."); + pa_log_info("Initialising MMX optimized functions."); #ifdef RUN_TEST - run_test (); + run_test (); #endif - pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_mmx); - pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_mmx); + pa_set_volume_func (PA_SAMPLE_S16NE, (pa_do_volume_func_t) pa_volume_s16ne_mmx); + pa_set_volume_func (PA_SAMPLE_S16RE, (pa_do_volume_func_t) pa_volume_s16re_mmx); #endif /* defined (__i386__) || defined (__amd64__) */ } -- cgit From f8ffe0dabcedf56437c00feb895d7d7229971ba0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 20 Aug 2009 12:30:48 +0200 Subject: svolume: cleanups Use PA_MAX Use pa_rtclock_now() for benchmarks --- src/pulsecore/svolume_mmx.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/pulsecore/svolume_mmx.c') diff --git a/src/pulsecore/svolume_mmx.c b/src/pulsecore/svolume_mmx.c index 7e242684..8510b0c4 100644 --- a/src/pulsecore/svolume_mmx.c +++ b/src/pulsecore/svolume_mmx.c @@ -100,7 +100,7 @@ pa_volume_s16ne_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi /* the max number of samples we process at a time, this is also the max amount * we overread the volume array, which should have enough padding. */ - channels = MAX (4, channels); + channels = PA_MAX (4U, channels); __asm__ __volatile__ ( " xor %3, %3 \n\t" @@ -170,7 +170,7 @@ pa_volume_s16re_mmx (int16_t *samples, int32_t *volumes, unsigned channels, unsi /* the max number of samples we process at a time, this is also the max amount * we overread the volume array, which should have enough padding. */ - channels = MAX (4, channels); + channels = PA_MAX (4U, channels); __asm__ __volatile__ ( " xor %3, %3 \n\t" @@ -254,7 +254,7 @@ static void run_test (void) { int32_t volumes[CHANNELS + PADDING]; int i, j, padding; pa_do_volume_func_t func; - struct timeval start, stop; + pa_usec_t start, stop; func = pa_get_volume_func (PA_SAMPLE_S16NE); @@ -278,21 +278,21 @@ static void run_test (void) { } } - pa_gettimeofday(&start); + start = pa_rtclock_now(); for (j = 0; j < TIMES; j++) { memcpy (samples, samples_orig, sizeof (samples)); pa_volume_s16ne_mmx (samples, volumes, CHANNELS, sizeof (samples)); } - pa_gettimeofday(&stop); - pa_log_info("MMX: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); + stop = pa_rtclock_now(); + pa_log_info("MMX: %llu usec.", (long long unsigned int)(stop - start)); - pa_gettimeofday(&start); + start = pa_rtclock_now(); for (j = 0; j < TIMES; j++) { memcpy (samples_ref, samples_orig, sizeof (samples)); func (samples_ref, volumes, CHANNELS, sizeof (samples)); } - pa_gettimeofday(&stop); - pa_log_info("ref: %llu usec.", (long long unsigned int)pa_timeval_diff (&stop, &start)); + stop = pa_rtclock_now(); + pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start)); } #endif -- cgit