slightly faster asm av_log2 for armv6 (currently only Gigabeat S)
[kugel-rb.git] / apps / codecs / lib / codeclib.h
blob4f30b306e315b47dabc7abf50337d4625bc1be34
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef __CODECLIB_H__
23 #define __CODECLIB_H__
25 #include "config.h"
26 #include "codecs.h"
27 #include <sys/types.h>
29 extern struct codec_api *ci;
30 extern size_t mem_ptr;
31 extern size_t bufsize;
32 extern unsigned char* mp3buf; /* The actual MP3 buffer from Rockbox */
33 extern unsigned char* mallocbuf; /* The free space after the codec in the codec buffer */
34 extern unsigned char* filebuf; /* The rest of the MP3 buffer */
36 /* Standard library functions that are used by the codecs follow here */
38 /* Get these functions 'out of the way' of the standard functions. Not doing
39 * so confuses the cygwin linker, and maybe others. These functions need to
40 * be implemented elsewhere */
41 #define malloc(x) codec_malloc(x)
42 #define calloc(x,y) codec_calloc(x,y)
43 #define realloc(x,y) codec_realloc(x,y)
44 #define free(x) codec_free(x)
45 #define alloca(x) __builtin_alloca(x)
47 void* codec_malloc(size_t size);
48 void* codec_calloc(size_t nmemb, size_t size);
49 void* codec_realloc(void* ptr, size_t size);
50 void codec_free(void* ptr);
52 void *memcpy(void *dest, const void *src, size_t n);
53 void *memset(void *s, int c, size_t n);
54 int memcmp(const void *s1, const void *s2, size_t n);
55 void *memmove(void *s1, const void *s2, size_t n);
57 size_t strlen(const char *s);
58 char *strcpy(char *dest, const char *src);
59 char *strcat(char *dest, const char *src);
60 int strcmp(const char *, const char *);
62 void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
64 /*MDCT library functions*/
66 extern void mdct_backward(int n, int32_t *in, int32_t *out);
68 #if defined(CPU_ARM) && (ARM_ARCH == 4)
69 /* optimised unsigned integer division for ARMv4, in IRAM */
70 unsigned udiv32_arm(unsigned a, unsigned b);
71 #define UDIV32(a, b) udiv32_arm(a, b)
72 #else
73 /* default */
74 #define UDIV32(a, b) (a / b)
75 #endif
77 /* TODO figure out if we really need to care about calculating
78 av_log2(0) */
79 #ifdef CPU_ARM
80 #if ARM_ARCH > 5
81 static inline unsigned int av_log2(uint32_t v)
83 unsigned int r;
84 asm volatile("clz %[r], %[v]\n\t" /* count leading zeroes */
85 "rsb %[r], %[r], #31\n\t" /* r = 31 - leading zeroes */
86 "usat %[r], #5, %[r]\n\t" /* unsigned saturate r so -1 -> 0 */
87 :[r] "=r" (r) : [v] "r" (v));
88 return(r);
90 #elif ARM_ARCH > 4
91 static inline unsigned int av_log2(uint32_t v)
93 return v ? 31 - __builtin_clz(v) : 0;
95 #endif
96 #else /* CPU_ARM */
97 /* From libavutil/common.h */
98 extern const uint8_t ff_log2_tab[256] ICONST_ATTR;
100 static inline unsigned int av_log2(unsigned int v)
102 int n;
104 n = 0;
105 if (v & 0xffff0000) {
106 v >>= 16;
107 n += 16;
109 if (v & 0xff00) {
110 v >>= 8;
111 n += 8;
113 n += ff_log2_tab[v];
115 return n;
117 #endif
119 /* Various codec helper functions */
121 int codec_init(void);
122 void codec_set_replaygain(struct mp3entry* id3);
124 #ifdef RB_PROFILE
125 void __cyg_profile_func_enter(void *this_fn, void *call_site)
126 NO_PROF_ATTR ICODE_ATTR;
127 void __cyg_profile_func_exit(void *this_fn, void *call_site)
128 NO_PROF_ATTR ICODE_ATTR;
129 #endif
131 #endif /* __CODECLIB_H__ */