[FFmpeg-devel] [PATCHv3 3/3] avcodec/cbrt_tablegen: avoid pow and speed up cbrt_tableinit

Ganesh Ajjanagadde gajjanagadde at gmail.com
Thu Nov 26 16:23:04 CET 2015


On systems having cbrt, there is no reason to use the slow pow function.

Sample benchmark (x86-64, Haswell, GNU/Linux):
new:
5124920 decicycles in cbrt_tableinit,       1 runs,      0 skips

old:
12321680 decicycles in cbrt_tableinit,       1 runs,      0 skips

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 libavcodec/cbrt_tablegen.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavcodec/cbrt_tablegen.h b/libavcodec/cbrt_tablegen.h
index 27a3e3a..4e90ac1 100644
--- a/libavcodec/cbrt_tablegen.h
+++ b/libavcodec/cbrt_tablegen.h
@@ -26,15 +26,17 @@
 #include <stdint.h>
 #include <math.h>
 #include "libavutil/attributes.h"
+#include "libavutil/tablegen.h"
 #include "libavcodec/aac_defines.h"
 
 #if USE_FIXED
-#define CBRT(x) (int)floor((x).f * 8192 + 0.5)
+#define CBRT(x) lrint((x).f * 8192)
 #else
 #define CBRT(x) x.i
 #endif
 
 #if CONFIG_HARDCODED_TABLES
+#include "libavutil/tablegen.h"
 #if USE_FIXED
 #define cbrt_tableinit_fixed()
 #include "libavcodec/cbrt_fixed_tables.h"
@@ -43,19 +45,19 @@
 #include "libavcodec/cbrt_tables.h"
 #endif
 #else
+#include "libavutil/libm.h"
 static uint32_t cbrt_tab[1 << 13];
 
 static av_cold void AAC_RENAME(cbrt_tableinit)(void)
 {
     if (!cbrt_tab[(1<<13) - 1]) {
         int i;
-        /* cbrtf() isn't available on all systems, so we use powf(). */
         for (i = 0; i < 1<<13; i++) {
             union {
                 float f;
                 uint32_t i;
             } f;
-            f.f = pow(i, 1.0 / 3.0) * i;
+            f.f = cbrt(i) * i;
             cbrt_tab[i] = CBRT(f);
         }
     }
-- 
2.6.2



More information about the ffmpeg-devel mailing list