summaryrefslogtreecommitdiffstats
path: root/apps/codecs
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2009-12-05 16:47:43 +0000
committerNils Wallménius <nils@rockbox.org>2009-12-05 16:47:43 +0000
commitb9d7f98f8c5653c9b5d945655cc64934da596142 (patch)
tree0a25d85df5377aa053287cdc53af6957ab140adf /apps/codecs
parent0651fe572b8fe1eb5457325f81a8c9986e479ef6 (diff)
downloadrockbox-b9d7f98f8c5653c9b5d945655cc64934da596142.tar.gz
rockbox-b9d7f98f8c5653c9b5d945655cc64934da596142.zip
Move av_log2 function and asociated table to the codec lib, remove 3 identical implementations, always have LUT in iram (gives a *tiny* speedup on coldfire), make the clz based function return the same value as the non clz based function for 0 input to be safe (slows down flac ~2% on the gigabeat S)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23858 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/lib/codeclib.c12
-rw-r--r--apps/codecs/lib/codeclib.h36
-rw-r--r--apps/codecs/libcook/cook_fixpoint.h31
-rw-r--r--apps/codecs/libffmpegFLAC/SOURCES3
-rw-r--r--apps/codecs/libffmpegFLAC/golomb.h30
-rw-r--r--apps/codecs/libffmpegFLAC/tables.c18
-rw-r--r--apps/codecs/libwma/wmadeci.c29
7 files changed, 50 insertions, 109 deletions
diff --git a/apps/codecs/lib/codeclib.c b/apps/codecs/lib/codeclib.c
index 8cc40894e3..1c624e0f8c 100644
--- a/apps/codecs/lib/codeclib.c
+++ b/apps/codecs/lib/codeclib.c
@@ -138,6 +138,18 @@ void qsort(void *base, size_t nmemb, size_t size,
ci->qsort(base,nmemb,size,compar);
}
+/* From ffmpeg - libavutil/common.h */
+const uint8_t ff_log2_tab[256] ICONST_ATTR = {
+ 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
+ 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
+};
+
#ifdef RB_PROFILE
void __cyg_profile_func_enter(void *this_fn, void *call_site) {
#ifdef CPU_COLDFIRE
diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h
index e7f45d3572..bf7b41775a 100644
--- a/apps/codecs/lib/codeclib.h
+++ b/apps/codecs/lib/codeclib.h
@@ -19,6 +19,9 @@
*
****************************************************************************/
+#ifndef __CODECLIB_H__
+#define __CODECLIB_H__
+
#include "config.h"
#include "codecs.h"
#include <sys/types.h>
@@ -71,6 +74,37 @@ unsigned udiv32_arm(unsigned a, unsigned b);
#define UDIV32(a, b) (a / b)
#endif
+/* TODO figure out if we really need to care about calculating
+ av_log2(0) */
+#if (defined(CPU_ARM) && (ARM_ARCH > 4))
+static inline unsigned int av_log2(uint32_t v)
+{
+ unsigned int lz = __builtin_clz(v);
+ return 31 - lz + (lz >> 5); /* make sure av_log2(0) returns 0 */
+}
+#else
+/* From libavutil/common.h */
+extern const uint8_t ff_log2_tab[256] ICONST_ATTR;
+
+static inline unsigned int av_log2(unsigned int v)
+{
+ int n;
+
+ n = 0;
+ if (v & 0xffff0000) {
+ v >>= 16;
+ n += 16;
+ }
+ if (v & 0xff00) {
+ v >>= 8;
+ n += 8;
+ }
+ n += ff_log2_tab[v];
+
+ return n;
+}
+#endif
+
/* Various codec helper functions */
int codec_init(void);
@@ -82,3 +116,5 @@ void __cyg_profile_func_enter(void *this_fn, void *call_site)
void __cyg_profile_func_exit(void *this_fn, void *call_site)
NO_PROF_ATTR ICODE_ATTR;
#endif
+
+#endif /* __CODECLIB_H__ */
diff --git a/apps/codecs/libcook/cook_fixpoint.h b/apps/codecs/libcook/cook_fixpoint.h
index 33646125dd..b17d99eeeb 100644
--- a/apps/codecs/libcook/cook_fixpoint.h
+++ b/apps/codecs/libcook/cook_fixpoint.h
@@ -40,20 +40,9 @@
#include "asm_arm.h"
#include "asm_mcf5249.h"
#include "codeclib_misc.h"
+#include "codeclib.h"
#endif
-/* The following table is taken from libavutil/mathematics.c */
-const uint8_t ff_log2_tab[256] ={
- 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-
/* cplscales was moved from cookdata_fixpoint.h since only *
* cook_fixpoint.h should see/use it. */
static const FIXPU* cplscales[5] = {
@@ -114,24 +103,6 @@ static inline int32_t fixmul31(int32_t x, int32_t y)
}
#endif
-/* math functions taken from libavutil/common.h */
-
-static inline int av_log2(unsigned int v)
-{
- int n = 0;
- if (v & 0xffff0000) {
- v >>= 16;
- n += 16;
- }
- if (v & 0xff00) {
- v >>= 8;
- n += 8;
- }
- n += ff_log2_tab[v];
-
- return n;
-}
-
/**
* Clips a signed integer value into the amin-amax range.
* @param a value to clip
diff --git a/apps/codecs/libffmpegFLAC/SOURCES b/apps/codecs/libffmpegFLAC/SOURCES
index 823a2b7744..deed19bcec 100644
--- a/apps/codecs/libffmpegFLAC/SOURCES
+++ b/apps/codecs/libffmpegFLAC/SOURCES
@@ -1,9 +1,6 @@
bitstream.c
decoder.c
shndec.c
-#if !(defined(CPU_ARM) && (ARM_ARCH > 4))
-tables.c
-#endif
#if defined(CPU_COLDFIRE)
coldfire.S
#elif defined(CPU_ARM)
diff --git a/apps/codecs/libffmpegFLAC/golomb.h b/apps/codecs/libffmpegFLAC/golomb.h
index 11753fc4bb..4f99671338 100644
--- a/apps/codecs/libffmpegFLAC/golomb.h
+++ b/apps/codecs/libffmpegFLAC/golomb.h
@@ -20,35 +20,7 @@
*/
#include <limits.h>
-
-#if (defined(CPU_ARM) && (ARM_ARCH > 4))
-static inline int av_log2(uint32_t v)
-{
- return 31 - __builtin_clz(v);
-}
-#else
-
-/* From libavutil/common.h */
-extern const uint8_t ff_log2_tab[256];
-
-static inline int av_log2(unsigned int v)
-{
- int n;
-
- n = 0;
- if (v & 0xffff0000) {
- v >>= 16;
- n += 16;
- }
- if (v & 0xff00) {
- v >>= 8;
- n += 8;
- }
- n += ff_log2_tab[v];
-
- return n;
-}
-#endif
+#include "codeclib.h"
/**
* @file golomb.h
diff --git a/apps/codecs/libffmpegFLAC/tables.c b/apps/codecs/libffmpegFLAC/tables.c
deleted file mode 100644
index 58b1bb68d7..0000000000
--- a/apps/codecs/libffmpegFLAC/tables.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifdef BUILD_STANDALONE
-#define ICONST_ATTR
-#else
-#include "codeclib.h"
-#endif
-#include <inttypes.h>
-
-/* From ffmpeg - libavutil/common.h */
-const uint8_t ff_log2_tab[256] ICONST_ATTR = {
- 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
diff --git a/apps/codecs/libwma/wmadeci.c b/apps/codecs/libwma/wmadeci.c
index 87af30b518..ae1a93ecf2 100644
--- a/apps/codecs/libwma/wmadeci.c
+++ b/apps/codecs/libwma/wmadeci.c
@@ -29,35 +29,6 @@
#include "wmafixed.h"
#include "wmadata.h"
-static const uint8_t ff_log2_tab[256]={
- 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-
-static inline int av_log2(unsigned int v)
-{
- int n;
-
- n = 0;
- if (v & 0xffff0000) {
- v >>= 16;
- n += 16;
- }
- if (v & 0xff00) {
- v >>= 8;
- n += 8;
- }
- n += ff_log2_tab[v];
-
- return n;
-}
-
static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len);
inline void vector_fmul_add_add(fixed32 *dst, const fixed32 *data,
const fixed32 *window, int n);