[FFmpeg-devel] [PATCH 2/4] tablegen: Don't use cbrtf in host tools

Derek Buitenhuis derek.buitenhuis at gmail.com
Tue Jan 15 22:28:03 CET 2013


You cannot count on them being present on all systems, and you
cannot include libm.h in a host tool, so just hard code baseline
implementations.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
 libavcodec/cbrt_tablegen.h      |    3 ++-
 libavcodec/mpegaudio_tablegen.h |    6 ++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavcodec/cbrt_tablegen.h b/libavcodec/cbrt_tablegen.h
index a9d34dc..5ef97c8 100644
--- a/libavcodec/cbrt_tablegen.h
+++ b/libavcodec/cbrt_tablegen.h
@@ -36,12 +36,13 @@ static void 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 = cbrtf(i) * i;
+            f.f = powf(i, 1.0 / 3.0) * i;
             cbrt_tab[i] = f.i;
         }
     }
diff --git a/libavcodec/mpegaudio_tablegen.h b/libavcodec/mpegaudio_tablegen.h
index 6c15d3c..1090ea5 100644
--- a/libavcodec/mpegaudio_tablegen.h
+++ b/libavcodec/mpegaudio_tablegen.h
@@ -48,7 +48,8 @@ static void mpegaudio_tableinit(void)
         double value = i / 4;
         double f, fm;
         int e, m;
-        f  = value / IMDCT_SCALAR * cbrtf(value) * pow(2, (i & 3) * 0.25);
+        /* cbrtf() isn't available on all systems, so we use powf(). */
+        f  = value / IMDCT_SCALAR * powf(value, 1.0 / 3.0) * pow(2, (i & 3) * 0.25);
         fm = frexp(f, &e);
         m  = (uint32_t)(fm * (1LL << 31) + 0.5);
         e += FRAC_BITS - 31 + 5 - 100;
@@ -59,7 +60,8 @@ static void mpegaudio_tableinit(void)
     }
     for (exponent = 0; exponent < 512; exponent++) {
         for (value = 0; value < 16; value++) {
-            double f = (double)value * cbrtf(value) * pow(2, (exponent - 400) * 0.25 + FRAC_BITS + 5) / IMDCT_SCALAR;
+            /* cbrtf() isn't available on all systems, so we use powf(). */
+            double f = (double)value * powf(value, 1.0 / 3.0) * pow(2, (exponent - 400) * 0.25 + FRAC_BITS + 5) / IMDCT_SCALAR;
             expval_table_fixed[exponent][value] = llrint(f);
             expval_table_float[exponent][value] = f;
         }
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list