summaryrefslogtreecommitdiff
path: root/lib/fixedpoint
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-09-18 06:00:05 -0400
committerMichael Sevakis <jethead71@rockbox.org>2017-11-21 05:01:14 -0500
commitaced667f48c29a160aa4e5c0a8df037092b28189 (patch)
tree66e48e4a27daaf36f01d7ff1ed6876a7de38b0c0 /lib/fixedpoint
parent5c9688961ef9166cec5225db50d5f73691d8292d (diff)
downloadrockbox-aced667f48c29a160aa4e5c0a8df037092b28189.zip
rockbox-aced667f48c29a160aa4e5c0a8df037092b28189.tar.gz
rockbox-aced667f48c29a160aa4e5c0a8df037092b28189.tar.bz2
rockbox-aced667f48c29a160aa4e5c0a8df037092b28189.tar.xz
Undo hacks to meant to get around string formatting limitations
The new vuprintf makes unnecessary workarounds due to formatting limitations. I checked grep output for whatever appeared to fit but it's possible I missed some instances because they weren't so obvious. Also, this means sound settings can dynamically work with any number of decimals rather than the current assumption of one or two. Add an ipow() function to help and take advantage of dynamic field width and precision. Consolidate string formatting of sound settings. Change-Id: I46caf534859dfd1916cd440cd25e5206b192fcd8
Diffstat (limited to 'lib/fixedpoint')
-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 645419d..d1307bb 100644
--- a/lib/fixedpoint/fixedpoint.c
+++ b/lib/fixedpoint/fixedpoint.c
@@ -211,6 +211,35 @@ long fp_sqrt(long x, unsigned int fracbits)
return g;
}
+/* raise an integer to an integer power */
+long ipow(long x, long y)
+{
+ /* y[k] = bit k of y, 0 or 1; k=0...n; n=|_ lg(y) _|
+ *
+ * x^y = x^(y[0]*2^0 + y[1]*2^1 + ... + y[n]*2^n)
+ * = x^(y[0]*2^0) * x^(y[1]*2^1) * ... * x^(y[n]*2^n)
+ */
+ long a = 1;
+
+ if (y < 0 && x != -1)
+ {
+ a = 0; /* would be < 1 or +inf if x == 0 */
+ }
+ else
+ {
+ while (y)
+ {
+ if (y & 1)
+ a *= x;
+
+ y /= 2;
+ x *= x;
+ }
+ }
+
+ return a;
+}
+
/**
* Fixed point sinus using a lookup table
* 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 bc50ff6..dcd7c82 100644
--- a/lib/fixedpoint/fixedpoint.h
+++ b/lib/fixedpoint/fixedpoint.h
@@ -85,6 +85,8 @@ long fp14_sin(int val);
long fp16_log(int x);
long fp16_exp(int x);
+long ipow(long x, long y);
+
/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit,
* whichever is faster for the architecture) */
#ifdef CPU_ARM
diff --git a/lib/fixedpoint/fixedpoint.make b/lib/fixedpoint/fixedpoint.make
index 0233e94..5be0e38 100644
--- a/lib/fixedpoint/fixedpoint.make
+++ b/lib/fixedpoint/fixedpoint.make
@@ -13,11 +13,8 @@ FIXEDPOINTLIB_OBJ := $(call c2obj, $(FIXEDPOINTLIB_SRC))
INCLUDES += -I$(FIXEDPOINTLIB_DIR)
OTHER_SRC += $(FIXEDPOINTLIB_SRC)
-# If not SOFTWARECODECS, then only plugins depend upon us
-ifdef SOFTWARECODECS
CORE_LIBS += $(FIXEDPOINTLIB)
CORE_GCSECTIONS := yes
-endif
FIXEDPOINTLIB_FLAGS := $(CFLAGS) $(SHARED_CFLAGS)