avcodec/cbrt_tablegen: speed up dynamic table creation

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

Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
This commit is contained in:
Ganesh Ajjanagadde 2015-11-25 16:59:07 -05:00
parent 1d0c94ddae
commit 2f5075f551
2 changed files with 3 additions and 3 deletions

View File

@ -29,7 +29,7 @@
#include "libavcodec/aac_defines.h" #include "libavcodec/aac_defines.h"
#if USE_FIXED #if USE_FIXED
#define CBRT(x) (int)floor((x).f * 8192 + 0.5) #define CBRT(x) lrint((x).f * 8192)
#else #else
#define CBRT(x) x.i #define CBRT(x) x.i
#endif #endif
@ -49,13 +49,12 @@ static av_cold void AAC_RENAME(cbrt_tableinit)(void)
{ {
if (!cbrt_tab[(1<<13) - 1]) { if (!cbrt_tab[(1<<13) - 1]) {
int i; int i;
/* cbrtf() isn't available on all systems, so we use powf(). */
for (i = 0; i < 1<<13; i++) { for (i = 0; i < 1<<13; i++) {
union { union {
float f; float f;
uint32_t i; uint32_t i;
} f; } f;
f.f = pow(i, 1.0 / 3.0) * i; f.f = cbrt(i) * i;
cbrt_tab[i] = CBRT(f); cbrt_tab[i] = CBRT(f);
} }
} }

View File

@ -23,6 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#define CONFIG_HARDCODED_TABLES 0 #define CONFIG_HARDCODED_TABLES 0
#include "cbrt_tablegen.h" #include "cbrt_tablegen.h"
#include "libavutil/tablegen.h"
#include "tableprint.h" #include "tableprint.h"
int main(void) int main(void)