summaryrefslogtreecommitdiff
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
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
-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,
138 ci->qsort(base,nmemb,size,compar); 138 ci->qsort(base,nmemb,size,compar);
139} 139}
140 140
141/* From ffmpeg - libavutil/common.h */
142const uint8_t ff_log2_tab[256] ICONST_ATTR = {
143 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,
144 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,
145 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,
146 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,
147 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
148 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
149 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
150 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
151};
152
141#ifdef RB_PROFILE 153#ifdef RB_PROFILE
142void __cyg_profile_func_enter(void *this_fn, void *call_site) { 154void __cyg_profile_func_enter(void *this_fn, void *call_site) {
143#ifdef CPU_COLDFIRE 155#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 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#ifndef __CODECLIB_H__
23#define __CODECLIB_H__
24
22#include "config.h" 25#include "config.h"
23#include "codecs.h" 26#include "codecs.h"
24#include <sys/types.h> 27#include <sys/types.h>
@@ -71,6 +74,37 @@ unsigned udiv32_arm(unsigned a, unsigned b);
71#define UDIV32(a, b) (a / b) 74#define UDIV32(a, b) (a / b)
72#endif 75#endif
73 76
77/* TODO figure out if we really need to care about calculating
78 av_log2(0) */
79#if (defined(CPU_ARM) && (ARM_ARCH > 4))
80static inline unsigned int av_log2(uint32_t v)
81{
82 unsigned int lz = __builtin_clz(v);
83 return 31 - lz + (lz >> 5); /* make sure av_log2(0) returns 0 */
84}
85#else
86/* From libavutil/common.h */
87extern const uint8_t ff_log2_tab[256] ICONST_ATTR;
88
89static inline unsigned int av_log2(unsigned int v)
90{
91 int n;
92
93 n = 0;
94 if (v & 0xffff0000) {
95 v >>= 16;
96 n += 16;
97 }
98 if (v & 0xff00) {
99 v >>= 8;
100 n += 8;
101 }
102 n += ff_log2_tab[v];
103
104 return n;
105}
106#endif
107
74/* Various codec helper functions */ 108/* Various codec helper functions */
75 109
76int codec_init(void); 110int codec_init(void);
@@ -82,3 +116,5 @@ void __cyg_profile_func_enter(void *this_fn, void *call_site)
82void __cyg_profile_func_exit(void *this_fn, void *call_site) 116void __cyg_profile_func_exit(void *this_fn, void *call_site)
83 NO_PROF_ATTR ICODE_ATTR; 117 NO_PROF_ATTR ICODE_ATTR;
84#endif 118#endif
119
120#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 @@
40#include "asm_arm.h" 40#include "asm_arm.h"
41#include "asm_mcf5249.h" 41#include "asm_mcf5249.h"
42#include "codeclib_misc.h" 42#include "codeclib_misc.h"
43#include "codeclib.h"
43#endif 44#endif
44 45
45/* The following table is taken from libavutil/mathematics.c */
46const uint8_t ff_log2_tab[256] ={
47 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,
48 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,
49 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,
50 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,
51 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
52 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
53 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
54 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
55};
56
57/* cplscales was moved from cookdata_fixpoint.h since only * 46/* cplscales was moved from cookdata_fixpoint.h since only *
58 * cook_fixpoint.h should see/use it. */ 47 * cook_fixpoint.h should see/use it. */
59static const FIXPU* cplscales[5] = { 48static const FIXPU* cplscales[5] = {
@@ -114,24 +103,6 @@ static inline int32_t fixmul31(int32_t x, int32_t y)
114} 103}
115#endif 104#endif
116 105
117/* math functions taken from libavutil/common.h */
118
119static inline int av_log2(unsigned int v)
120{
121 int n = 0;
122 if (v & 0xffff0000) {
123 v >>= 16;
124 n += 16;
125 }
126 if (v & 0xff00) {
127 v >>= 8;
128 n += 8;
129 }
130 n += ff_log2_tab[v];
131
132 return n;
133}
134
135/** 106/**
136 * Clips a signed integer value into the amin-amax range. 107 * Clips a signed integer value into the amin-amax range.
137 * @param a value to clip 108 * @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 @@
1bitstream.c 1bitstream.c
2decoder.c 2decoder.c
3shndec.c 3shndec.c
4#if !(defined(CPU_ARM) && (ARM_ARCH > 4))
5tables.c
6#endif
7#if defined(CPU_COLDFIRE) 4#if defined(CPU_COLDFIRE)
8coldfire.S 5coldfire.S
9#elif defined(CPU_ARM) 6#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 @@
20 */ 20 */
21 21
22#include <limits.h> 22#include <limits.h>
23 23#include "codeclib.h"
24#if (defined(CPU_ARM) && (ARM_ARCH > 4))
25static inline int av_log2(uint32_t v)
26{
27 return 31 - __builtin_clz(v);
28}
29#else
30
31/* From libavutil/common.h */
32extern const uint8_t ff_log2_tab[256];
33
34static inline int av_log2(unsigned int v)
35{
36 int n;
37
38 n = 0;
39 if (v & 0xffff0000) {
40 v >>= 16;
41 n += 16;
42 }
43 if (v & 0xff00) {
44 v >>= 8;
45 n += 8;
46 }
47 n += ff_log2_tab[v];
48
49 return n;
50}
51#endif
52 24
53/** 25/**
54 * @file golomb.h 26 * @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 @@
1#ifdef BUILD_STANDALONE
2#define ICONST_ATTR
3#else
4#include "codeclib.h"
5#endif
6#include <inttypes.h>
7
8/* From ffmpeg - libavutil/common.h */
9const uint8_t ff_log2_tab[256] ICONST_ATTR = {
10 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,
11 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,
12 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,
13 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,
14 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
15 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
16 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
17 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
18};
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 @@
29#include "wmafixed.h" 29#include "wmafixed.h"
30#include "wmadata.h" 30#include "wmadata.h"
31 31
32static const uint8_t ff_log2_tab[256]={
33 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,
34 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,
35 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,
36 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,
37 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
38 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
39 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
40 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
41};
42
43static inline int av_log2(unsigned int v)
44{
45 int n;
46
47 n = 0;
48 if (v & 0xffff0000) {
49 v >>= 16;
50 n += 16;
51 }
52 if (v & 0xff00) {
53 v >>= 8;
54 n += 8;
55 }
56 n += ff_log2_tab[v];
57
58 return n;
59}
60
61static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len); 32static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len);
62inline void vector_fmul_add_add(fixed32 *dst, const fixed32 *data, 33inline void vector_fmul_add_add(fixed32 *dst, const fixed32 *data,
63 const fixed32 *window, int n); 34 const fixed32 *window, int n);