diff options
Diffstat (limited to 'apps/codecs/lib/codeclib.h')
-rw-r--r-- | apps/codecs/lib/codeclib.h | 101 |
1 files changed, 68 insertions, 33 deletions
diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h index 9c3624b422..aeae5d6369 100644 --- a/apps/codecs/lib/codeclib.h +++ b/apps/codecs/lib/codeclib.h | |||
@@ -74,45 +74,80 @@ unsigned udiv32_arm(unsigned a, unsigned b); | |||
74 | #define UDIV32(a, b) (a / b) | 74 | #define UDIV32(a, b) (a / b) |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | /* TODO figure out if we really need to care about calculating | 77 | #if !defined(CPU_ARM) || ARM_ARCH < 5 |
78 | av_log2(0) */ | ||
79 | #if defined(CPU_ARM) && ARM_ARCH >= 6 | ||
80 | static inline unsigned int av_log2(uint32_t v) | ||
81 | { | ||
82 | unsigned int r; | ||
83 | asm volatile("clz %[r], %[v]\n\t" /* count leading zeroes */ | ||
84 | "rsb %[r], %[r], #31\n\t" /* r = 31 - leading zeroes */ | ||
85 | "usat %[r], #5, %[r]\n\t" /* unsigned saturate r so -1 -> 0 */ | ||
86 | :[r] "=r" (r) : [v] "r" (v)); | ||
87 | return(r); | ||
88 | } | ||
89 | #elif defined(CPU_ARM) && ARM_ARCH >= 5 | ||
90 | static inline unsigned int av_log2(uint32_t v) | ||
91 | { | ||
92 | return v ? 31 - __builtin_clz(v) : 0; | ||
93 | } | ||
94 | #else /* CPU_ARM */ | ||
95 | /* From libavutil/common.h */ | 78 | /* From libavutil/common.h */ |
96 | extern const uint8_t ff_log2_tab[256] ICONST_ATTR; | 79 | extern const uint8_t bs_log2_tab[256] ICONST_ATTR; |
80 | extern const uint8_t bs_clz_tab[256] ICONST_ATTR; | ||
81 | #endif | ||
97 | 82 | ||
98 | static inline unsigned int av_log2(unsigned int v) | 83 | #define BS_LOG2 0 /* default personality, equivalent floor(log2(x)) */ |
99 | { | 84 | #define BS_CLZ 1 /* alternate personality, Count Leading Zeros */ |
100 | int n; | 85 | #define BS_SHORT 2 /* input guaranteed not to exceed 16 bits */ |
86 | #define BS_0_0 4 /* guarantee mapping of 0 input to 0 output */ | ||
101 | 87 | ||
102 | n = 0; | 88 | /* Generic bit-scanning function, used to wrap platform CLZ instruction or |
103 | if (v & 0xffff0000) { | 89 | scan-and-lookup code, and to provide control over output for 0 inputs. */ |
104 | v >>= 16; | 90 | static inline unsigned int bs_generic(unsigned int v, int mode) |
105 | n += 16; | 91 | { |
92 | #if defined(CPU_ARM) && ARM_ARCH >= 5 | ||
93 | unsigned int r = __builtin_clz(v); | ||
94 | if (mode & BS_CLZ) | ||
95 | { | ||
96 | if (mode & BS_0_0) | ||
97 | r &= 31; | ||
98 | } else { | ||
99 | r = 31 - r; | ||
100 | /* If mode is constant, this is a single conditional instruction */ | ||
101 | if (mode & BS_0_0 && (signed)r < 0) | ||
102 | r += 1; | ||
103 | } | ||
104 | #else | ||
105 | const uint8_t *bs_tab; | ||
106 | unsigned int r; | ||
107 | unsigned int n = v; | ||
108 | int inc; | ||
109 | /* Set up table, increment, and initial result value based on | ||
110 | personality. */ | ||
111 | if (mode & BS_CLZ) | ||
112 | { | ||
113 | bs_tab = bs_clz_tab; | ||
114 | r = 24; | ||
115 | inc = -16; | ||
116 | } else { | ||
117 | bs_tab = bs_log2_tab; | ||
118 | r = 0; | ||
119 | inc = 16; | ||
106 | } | 120 | } |
107 | if (v & 0xff00) { | 121 | if (!(mode & BS_SHORT) && n >= 0x10000) { |
108 | v >>= 8; | 122 | n >>= 16; |
109 | n += 8; | 123 | r += inc; |
110 | } | 124 | } |
111 | n += ff_log2_tab[v]; | 125 | if (n > 0xff) { |
112 | 126 | n >>= 8; | |
113 | return n; | 127 | r += inc / 2; |
114 | } | 128 | } |
129 | #ifdef CPU_COLDFIRE | ||
130 | /* The high 24 bits of n are guaranteed empty after the above, so a | ||
131 | superfluous ext.b instruction can be saved by loading the LUT value over | ||
132 | n with asm */ | ||
133 | asm volatile ( | ||
134 | "move.b (%1,%0.l),%0" | ||
135 | : "+d" (n) | ||
136 | : "a" (bs_tab) | ||
137 | ); | ||
138 | #else | ||
139 | n = bs_tab[n]; | ||
115 | #endif | 140 | #endif |
141 | r += n; | ||
142 | if (mode & BS_CLZ && mode & BS_0_0 && v == 0) | ||
143 | r = 0; | ||
144 | #endif | ||
145 | return r; | ||
146 | } | ||
147 | |||
148 | /* TODO figure out if we really need to care about calculating | ||
149 | av_log2(0) */ | ||
150 | #define av_log2(v) bs_generic(v, BS_0_0) | ||
116 | 151 | ||
117 | /* Various codec helper functions */ | 152 | /* Various codec helper functions */ |
118 | 153 | ||