summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/fixedpoint/fixedpoint.c29
-rw-r--r--lib/fixedpoint/fixedpoint.h2
-rw-r--r--lib/fixedpoint/fixedpoint.make3
3 files changed, 31 insertions, 3 deletions
diff --git a/lib/fixedpoint/fixedpoint.c b/lib/fixedpoint/fixedpoint.c
index 645419d102..d1307bb248 100644
--- a/lib/fixedpoint/fixedpoint.c
+++ b/lib/fixedpoint/fixedpoint.c
@@ -211,6 +211,35 @@ long fp_sqrt(long x, unsigned int fracbits)
211 return g; 211 return g;
212} 212}
213 213
214/* raise an integer to an integer power */
215long ipow(long x, long y)
216{
217 /* y[k] = bit k of y, 0 or 1; k=0...n; n=|_ lg(y) _|
218 *
219 * x^y = x^(y[0]*2^0 + y[1]*2^1 + ... + y[n]*2^n)
220 * = x^(y[0]*2^0) * x^(y[1]*2^1) * ... * x^(y[n]*2^n)
221 */
222 long a = 1;
223
224 if (y < 0 && x != -1)
225 {
226 a = 0; /* would be < 1 or +inf if x == 0 */
227 }
228 else
229 {
230 while (y)
231 {
232 if (y & 1)
233 a *= x;
234
235 y /= 2;
236 x *= x;
237 }
238 }
239
240 return a;
241}
242
214/** 243/**
215 * Fixed point sinus using a lookup table 244 * Fixed point sinus using a lookup table
216 * don't forget to divide the result by 16384 to get the actual sinus value 245 * don't forget to divide the result by 16384 to get the actual sinus value
diff --git a/lib/fixedpoint/fixedpoint.h b/lib/fixedpoint/fixedpoint.h
index bc50ff687d..dcd7c8298c 100644
--- a/lib/fixedpoint/fixedpoint.h
+++ b/lib/fixedpoint/fixedpoint.h
@@ -85,6 +85,8 @@ long fp14_sin(int val);
85long fp16_log(int x); 85long fp16_log(int x);
86long fp16_exp(int x); 86long fp16_exp(int x);
87 87
88long ipow(long x, long y);
89
88/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit, 90/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
89 * whichever is faster for the architecture) */ 91 * whichever is faster for the architecture) */
90#ifdef CPU_ARM 92#ifdef CPU_ARM
diff --git a/lib/fixedpoint/fixedpoint.make b/lib/fixedpoint/fixedpoint.make
index 0233e9499b..5be0e38ea7 100644
--- a/lib/fixedpoint/fixedpoint.make
+++ b/lib/fixedpoint/fixedpoint.make
@@ -13,11 +13,8 @@ FIXEDPOINTLIB_OBJ := $(call c2obj, $(FIXEDPOINTLIB_SRC))
13INCLUDES += -I$(FIXEDPOINTLIB_DIR) 13INCLUDES += -I$(FIXEDPOINTLIB_DIR)
14OTHER_SRC += $(FIXEDPOINTLIB_SRC) 14OTHER_SRC += $(FIXEDPOINTLIB_SRC)
15 15
16# If not SOFTWARECODECS, then only plugins depend upon us
17ifdef SOFTWARECODECS
18CORE_LIBS += $(FIXEDPOINTLIB) 16CORE_LIBS += $(FIXEDPOINTLIB)
19CORE_GCSECTIONS := yes 17CORE_GCSECTIONS := yes
20endif
21 18
22FIXEDPOINTLIB_FLAGS := $(CFLAGS) $(SHARED_CFLAGS) 19FIXEDPOINTLIB_FLAGS := $(CFLAGS) $(SHARED_CFLAGS)
23 20