sbc: powerpc altivec optimizations for 4 subbands encoding
PATCH 1/1 sbc: powerpc altivec optimizations for 4 subbands encoding
Hello,
On the last weekend I tried to get familiar with powerpc altivec assembly and added some optimization for sbc encoder. Experimental patch is attached. It handles 4 subbands case only, so is not that much useful in practice. There are no problems supporting 8 subbands too, but I was just running out of time. The patch merges processing of 4 blocks into the single block of code. It's something that is also in my todo list for ARM NEON. But while this merge is mostly "nice to have" optimization for ARM, it is much more important for PowerPC because of a huge multiply-accumulate latency.
And bluez a2dp seems to work fine on ppc64 linux (playstation3).
In order to activate altivec code, -maltivec option needs to be added to gcc compilation flags.
Benchmark result:
time ./sbcenc -s4 somefile.au > /dev/null
before:
real 0m13.999s
user 0m13.468s
sys 0m0.523s
after:
real 0m5.714s
user 0m5.199s
sys 0m0.519s
3.2GHz CPU in playstation3 uses roughly 1.5% of cpu resources on sbc encoding without any optimizations. cpu usage is down to something like 0.6% after this optimization is applied.
Signature · 2 lines
Best regards, Siarhei Siamashka
From a995acc428e2c02306ca69efa85d7f6e15529245 Mon Sep 17 00:00:00 2001
From: Siarhei Siamashka <[email protected]>
Date: Mon, 16 Mar 2009 03:38:52 +0200
Subject: [PATCH] sbc: powerpc altivec optimizations for 4 subbands encoding
--- sbc/Makefile.am | 3 +- sbc/sbc_primitives.c | 6 + sbc/sbc_primitives_altivec.c | 207 ++++++++++++++++++++++++++++++++++++++++++ sbc/sbc_primitives_altivec.h | 40 ++++++++ 4 files changed, 255 insertions(+), 1 deletions(-) create mode 100644 sbc/sbc_primitives_altivec.c create mode 100644 sbc/sbc_primitives_altivec.h
sbc/Makefile.am +2 -1
@@ -10,7 +10,8 @@ noinst_LTLIBRARIES = libsbc.la libsbc_la_SOURCES = sbc.h sbc.c sbc_math.h sbc_tables.h \ sbc_primitives.h sbc_primitives_mmx.h sbc_primitives_neon.h \ - sbc_primitives.c sbc_primitives_mmx.c sbc_primitives_neon.c + sbc_primitives.c sbc_primitives_mmx.c sbc_primitives_neon.c \ + sbc_primitives_altivec.h sbc_primitives_altivec.c libsbc_la_CFLAGS = -finline-functions -fgcse-after-reload \ -funswitch-loops -funroll-loops
sbc/sbc_primitives.c +6 -0
@@ -33,6 +33,7 @@#include "sbc_primitives.h" #include "sbc_primitives_mmx.h" #include "sbc_primitives_neon.h" +#include "sbc_primitives_altivec.h" /* * A reference C code of analysis filter with SIMD-friendly tables
@@ -467,4 +468,9 @@ void sbc_init_primitives(struct sbc_encoder_state *state)#ifdef SBC_BUILD_WITH_NEON_SUPPORT sbc_init_primitives_neon (state);#endif + +/* PPC Altivec optimizations */ +#ifdef SBC_BUILD_WITH_ALTIVEC_SUPPORT +sbc_init_primitives_altivec (state); +#endif }
sbc/sbc_primitives_altivec.c new file +207 -0
207 lines not on this page · raw message
sbc/sbc_primitives_altivec.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* +* Bluetooth low-complexity, subband codec (SBC) library +* +* Copyright (C) 2004-2009 Marcel Holtmann <[email protected]> +* Copyright (C) 2004-2005 Henryk Ploetz <[email protected]> +* Copyright (C) 2005-2006 Brad Midgley <[email protected]> +* +* +* This library 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. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +#ifndef __SBC_PRIMITIVES_ALTIVEC_H +#define __SBC_PRIMITIVES_ALTIVEC_H + +#include "sbc_primitives.h" + +#if defined(__GNUC__) && defined(__ALTIVEC__) && \ + !defined(SBC_HIGH_PRECISION ) && (SCALE_OUT_BITS ==15 ) + +#define SBC_BUILD_WITH_ALTIVEC_SUPPORT + +void sbc_init_primitives_altivec (struct sbc_encoder_state *encoder_state); + +#endif + +#endif
Signature · 1 line
1.5.6.5
Marcel Holtmann
maintainerHi Siarhei,
Quoted 23 lines
On the last weekend I tried to get familiar with powerpc altivec assembly and added some optimization for sbc encoder. Experimental patch is attached. It handles 4 subbands case only, so is not that much useful in practice. There are no problems supporting 8 subbands too, but I was just running out of time. The patch merges processing of 4 blocks into the single block of code. It's something that is also in my todo list for ARM NEON. But while this merge is mostly "nice to have" optimization for ARM, it is much more important for PowerPC because of a huge multiply-accumulate latency.
And bluez a2dp seems to work fine on ppc64 linux (playstation3).
In order to activate altivec code, -maltivec option needs to be added to gcc compilation flags.
Benchmark result:
time ./sbcenc -s4 somefile.au >
/dev/nullbefore:
real 0m13.999s
user 0m13.468s
sys 0m0.523s
Quoted 8 lines
after:
real 0m5.714s
user 0m5.199s
sys 0m0.519s3.2GHz CPU in playstation3 uses roughly 1.5% of cpu resources on sbc encoding without any optimizations. cpu usage is down to something like 0.6% after this optimization is applied.
please redo the patch and include a proper commit message. For example the details from the email would be perfect for a commit message. It doesn't need to be that verbose, but a little bit more would be nice.
Regards
Marcel
Quoted 31 lines · On Saturday 14 March 2009 08:17:13 ext Marcel Holtmann wrote:
Hi Siarhei,
Quoted 29 lines
On the last weekend I tried to get familiar with powerpc altivec assembly
and added some optimization for sbc encoder. Experimental patch is
attached. It handles 4 subbands case only, so is not that much useful in practice. There are no problems supporting 8 subbands too, but I was just running out of time. The patch merges processing of 4 blocks into the single block of code. It's something that is also in my todo list for ARM NEON. But while this merge is mostly "nice to have" optimization for ARM, it is much more important for PowerPC because of a huge multiply-accumulate latency.And bluez a2dp seems to work fine on ppc64 linux (playstation3).
In order to activate altivec code, -maltivec option needs to be added to gcc compilation flags.
Benchmark result:
time ./sbcenc -s4 somefile.au >
/dev/nullbefore:
real 0m13.999s
user 0m13.468s
sys 0m0.523safter:
real 0m5.714s
user 0m5.199s
sys 0m0.519s
Quoted 7 lines
Quoted 3 lines
3.2GHz CPU in playstation3 uses roughly 1.5% of cpu resources on sbc encoding without any optimizations. cpu usage is down to something like 0.6% after this optimization is applied.
please redo the patch and include a proper commit message. For example the details from the email would be perfect for a commit message. It doesn't need to be that verbose, but a little bit more would be nice.
That patch was more like a preview targeted at the people interested in powerpc optimizations (by the way, are there any low end or embedded powerpc systems which could benefit the most from these in practice?). For me it was more like a test if the code works correctly on more exotic platform like big endian 64-bit system :) And also an exercise in powerpc assembly and a check if the bluez sbc code can be easily accommodated to different SIMD architectures.
For it to be ready to be appied, the following still needs to be done in my opinion:
1. Add '/proc/self/auxv' based altivec instructions support detection at runtime, this should work for all linux systems.
way the same binary will be usable on which are conservative about the debian
2. Add 8 subbands support, this is what is actually used for A2DP most of the time
Additionally, I wonder about the copy of the table with coefficients. For powerpc, some zero padding needs to be added. For ARM NEON, the second part of the coefficients table can be reordered to make better use of "vertical" simd instructions that it supports. For ARMv6, the second part of the table can be also tweaked to exploit the fact that some coefficients are the same and reduce the number of operations (it only can do 2 multiplicate&accumulate operations at once, so the straight "brute force" which works fine for the other SIMD extensions is not the fastest here). As an alternative to having copy-pasted and slightly modified tables in the sources, reordering of coefficients can be done at runtime (and this reordering code would also make it easier to see what kind of transformation was applied).
Signature · 2 lines
Best regards, Siarhei Siamashka
On Monday 23 March 2009 08:51:53 Siamashka Siarhei (Nokia-D/Helsinki) wrote:
[...]
Quoted 6 lines
For it to be ready to be appied, the following still needs to be done in my opinion:
1. Add '/proc/self/auxv' based altivec instructions support detection at runtime, this should work for all linux systems.
way the same binary will be usable on which are conservative about the debian
Sorry for this unfinished gibberish typing that slipped in. Translating into a "human" language: most distributions like debian use the lowest common denominator target cpu options for binary packages, runtime altivec detection will make sbc altivec optimizations work fine there without any extra hassle :)
Signature · 2 lines
Best regards, Siarhei Siamashka
Marcel Holtmann
maintainerHi Siarhei,
Quoted 37 lines
Quoted 29 lines
Quoted 29 lines
On the last weekend I tried to get familiar with powerpc altivec assembly
and added some optimization for sbc encoder. Experimental patch is
attached. It handles 4 subbands case only, so is not that much useful in practice. There are no problems supporting 8 subbands too, but I was just running out of time. The patch merges processing of 4 blocks into the single block of code. It's something that is also in my todo list for ARM NEON. But while this merge is mostly "nice to have" optimization for ARM, it is much more important for PowerPC because of a huge multiply-accumulate latency.And bluez a2dp seems to work fine on ppc64 linux (playstation3).
In order to activate altivec code, -maltivec option needs to be added to gcc compilation flags.
Benchmark result:
time ./sbcenc -s4 somefile.au >
/dev/nullbefore:
real 0m13.999s
user 0m13.468s
sys 0m0.523safter:
real 0m5.714s
user 0m5.199s
sys 0m0.519sQuoted 7 lines
Quoted 3 lines
3.2GHz CPU in playstation3 uses roughly 1.5% of cpu resources on sbc encoding without any optimizations. cpu usage is down to something like 0.6% after this optimization is applied.
please redo the patch and include a proper commit message. For example the details from the email would be perfect for a commit message. It doesn't need to be that verbose, but a little bit more would be nice.
Quoted 7 lines
That patch was more like a preview targeted at the people interested in powerpc optimizations (by the way, are there any low end or embedded powerpc systems which could benefit the most from these in practice?). For me it was more like a test if the code works correctly on more exotic platform like big endian 64-bit system :) And also an exercise in powerpc assembly and a check if the bluez sbc code can be easily accommodated to different SIMD architectures.
yes PowerPC is important for embedded devices. At some point there where even talks to use PowerPC for OLPC machines.
Quoted 7 lines
For it to be ready to be appied, the following still needs to be done in my opinion:
1. Add '/proc/self/auxv' based altivec instructions support detection at runtime, this should work for all linux systems.
way the same binary will be usable on which are conservative about the debian
2. Add 8 subbands support, this is what is actually used for A2DP most of the time
I think that having runtime would be nice. However it is not the most important part. The only thing to keep in mind is that we do the runtime check only once on program load and not always we are initiating a new SBC encoder.
Quoted 4 lines
Additionally, I wonder about the copy of the table with coefficients. For powerpc, some zero padding needs to be added. For ARM NEON, the second part of the coefficients table can be reordered to make better use of "vertical" simd instructions that it supports. For ARMv6, the second part
Quoted 8 lines
of the table can be also tweaked to exploit the fact that some coefficients are the same and reduce the number of operations (it only can do 2 multiplicate&accumulate operations at once, so the straight "brute force" which works fine for the other SIMD extensions is not the fastest here). As an alternative to having copy-pasted and slightly modified tables in the sources, reordering of coefficients can be done at runtime (and this reordering code would also make it easier to see what kind of transformation was applied).
You are the expert here. I leave this up to you.
Regards
Marcel