Skip to content

Commit 79de037

Browse files
nschimmethemactep
andcommitted
faac: use fast math to save power (#1091)
* makefile: do not pad empty extras, flash_eraseall in sysupgrade cleans entire partition * package/faac: update to edc0246 Update faac from 64fc541 to edc0246 Hash change: 64fc54142912088eecabaa159339768eca30f3d6 -> edc02462e529b23539d932681fc0f96120e4708e Changelog: 33558e6: CI: add native MSVC build and fix Windows compatibility (#66) 081d81d: remove dead code (#65) 0622a3a: optimize FFT reordering by combining real and imaginary passes (#68) a5abf5e: optimize FFT performance (#70) 07fb0b4: ci: update GitHub Actions and add Dependabot configuration (#74) 0a01417: Bump the actions group with 2 updates (#75) d3a9c22: remove redundant defines (#76) 4f74d18: make faacgui usable again (#77) c5c142d: report library version on version mismatch 407db12: maintain library SONAME version 0.0.0 ab58250: Merge branch 'master' of https://github.com/knik0/faac c79fd73: build both static and shared library by default 779a803: properly declare symbol visibility as hidden ad7e4f0: refactor quantizer for portable C and extensible SIMD dispatch (#71) edc0246: optimize memory allocation and unify MDCT implementation (#73) * faac: use fast math to save power --------- Co-authored-by: Paul Philippov <paul@themactep.com> Co-authored-by: Paul Philippov <themactep@gmail.com>
1 parent 7991f04 commit 79de037

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
libfaac/faac_real.h | 31 +++++++++++++++++++++++++++++--
2+
libfaac/quantize.c | 2 +-
3+
2 files changed, 30 insertions(+), 3 deletions(-)
4+
5+
diff --git a/libfaac/faac_real.h b/libfaac/faac_real.h
6+
index 4d004d7..a2e76fd 100644
7+
--- a/libfaac/faac_real.h
8+
+++ b/libfaac/faac_real.h
9+
@@ -25,6 +25,33 @@
10+
#endif
11+
12+
#include <math.h>
13+
+#include <stdint.h>
14+
+
15+
+static inline float fast_log2(float x)
16+
+{
17+
+ union { float f; uint32_t i; } vx = { x };
18+
+ float y = (float)vx.i;
19+
+ y *= 1.1920928955078125e-7f;
20+
+ return y - 126.94269504f;
21+
+}
22+
+
23+
+static inline float fast_log10(float x)
24+
+{
25+
+ return fast_log2(x) * 0.3010299956639812f;
26+
+}
27+
+
28+
+static inline float fast_pow2(float x)
29+
+{
30+
+ if (x < -126.0f) return 0.0f;
31+
+ if (x > 128.0f) return 3e38f;
32+
+ union { uint32_t i; float f; } v = { (uint32_t)((x + 126.94269504f) * 8388608.0f) };
33+
+ return v.f;
34+
+}
35+
+
36+
+static inline float fast_pow(float x, float y)
37+
+{
38+
+ return fast_pow2(y * fast_log2(x));
39+
+}
40+
41+
#ifdef FAAC_PRECISION_SINGLE
42+
typedef float faac_real;
43+
@@ -32,8 +59,8 @@ typedef float faac_real;
44+
#define FAAC_COS cosf
45+
#define FAAC_SQRT sqrtf
46+
#define FAAC_FABS fabsf
47+
-#define FAAC_LOG10 log10f
48+
-#define FAAC_POW powf
49+
+#define FAAC_LOG10 fast_log10
50+
+#define FAAC_POW fast_pow
51+
#define FAAC_ASIN asinf
52+
#define FAAC_LRINT lrintf
53+
#define FAAC_FLOOR floorf
54+
diff --git a/libfaac/quantize.c b/libfaac/quantize.c
55+
index 27d3a79..0f67c9e 100644
56+
--- a/libfaac/quantize.c
57+
+++ b/libfaac/quantize.c
58+
@@ -171,7 +171,7 @@ static void qlevel(CoderInfo * __restrict coderInfo,
59+
)
60+
{
61+
int sb;
62+
-#if !defined(__clang__) && defined(__GNUC__) && (GCC_VERSION >= 40600)
63+
+#if !defined(__clang__) && defined(__GNUC__) && (GCC_VERSION >= 40600) && false
64+
/* 2^0.25 (1.50515 dB) step from AAC specs */
65+
static const faac_real sfstep = 1.0 / FAAC_LOG10(FAAC_SQRT(FAAC_SQRT(2.0)));
66+
#else
67+

package/faac/faac.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ FAAC_DEPENDENCIES = host-pkgconf
1111
FAAC_INSTALL_STAGING = YES
1212
FAAC_INSTALL_TARGET = YES
1313

14+
FAAC_CONF_ENV += CFLAGS="$(TARGET_CFLAGS) -ffast-math"
15+
1416
FAAC_CONF_OPTS = \
1517
$(if $(BR2_PACKAGE_FAAC_ENABLE_DRM),-Ddrm=true,-Ddrm=false) \
1618
-Dfloating-point=single

0 commit comments

Comments
 (0)