[FFmpeg-devel] [PATCH 1/3] lavc/cbrt_tablegen: convert cbrt_tab to a union

Ganesh Ajjanagadde gajjanagadde at gmail.com
Thu Dec 31 17:39:20 CET 2015


This is used to prepare for optimizations of the table generation, which
is inherently done as floating point computation of i * cbrt[i].

Tested with FATE.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 libavcodec/aacdec_fixed.c    |  4 ++--
 libavcodec/aacdec_template.c |  2 +-
 libavcodec/cbrt_tablegen.h   | 23 +++++++++--------------
 3 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c
index 923fbe0..ebc585e 100644
--- a/libavcodec/aacdec_fixed.c
+++ b/libavcodec/aacdec_fixed.c
@@ -154,9 +154,9 @@ static void vector_pow43(int *coefs, int len)
     for (i=0; i<len; i++) {
         coef = coefs[i];
         if (coef < 0)
-            coef = -(int)cbrt_tab[-coef];
+            coef = -(int)cbrt_tab[-coef].i;
         else
-            coef = (int)cbrt_tab[coef];
+            coef = (int)cbrt_tab[coef].i;
         coefs[i] = coef;
     }
 }
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 620600c..b3ec9e6 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1791,7 +1791,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, INTFLOAT coef[1024],
                                         v = -v;
                                     *icf++ = v;
 #else
-                                    *icf++ = cbrt_tab[n] | (bits & 1U<<31);
+                                    *icf++ = cbrt_tab[n].i | (bits & 1U<<31);
 #endif /* USE_FIXED */
                                     bits <<= 1;
                                 } else {
diff --git a/libavcodec/cbrt_tablegen.h b/libavcodec/cbrt_tablegen.h
index 59b5a1d..ef4c099 100644
--- a/libavcodec/cbrt_tablegen.h
+++ b/libavcodec/cbrt_tablegen.h
@@ -26,14 +26,9 @@
 #include <stdint.h>
 #include <math.h>
 #include "libavutil/attributes.h"
+#include "libavutil/intfloat.h"
 #include "libavcodec/aac_defines.h"
 
-#if USE_FIXED
-#define CBRT(x) lrint((x).f * 8192)
-#else
-#define CBRT(x) x.i
-#endif
-
 #if CONFIG_HARDCODED_TABLES
 #if USE_FIXED
 #define cbrt_tableinit_fixed()
@@ -43,20 +38,20 @@
 #include "libavcodec/cbrt_tables.h"
 #endif
 #else
-static uint32_t cbrt_tab[1 << 13];
+static union av_intfloat32 cbrt_tab[1 << 13];
 
 static av_cold void AAC_RENAME(cbrt_tableinit)(void)
 {
-    if (!cbrt_tab[(1<<13) - 1]) {
+    if (!cbrt_tab[(1<<13) - 1].i) {
         int i;
         for (i = 0; i < 1<<13; i++) {
-            union {
-                float f;
-                uint32_t i;
-            } f;
-            f.f = cbrt(i) * i;
-            cbrt_tab[i] = CBRT(f);
+            cbrt_tab[i].f = i * cbrt(i);
         }
+#if USE_FIXED
+        for (i = 0; i < 1<<13; i++) {
+            cbrt_tab[i].i = lrint(cbrt_tab[i].f * 8192);
+        }
+#endif
     }
 }
 #endif /* CONFIG_HARDCODED_TABLES */
-- 
2.6.4



More information about the ffmpeg-devel mailing list