From 884fd4d2590c30c7787fc05b86b050125fd53f33 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Tue, 15 Jan 2013 16:08:58 -0500 Subject: [PATCH 1/4] tableprint: Fix use of a size_t print with MSVC %zu was introduced in C99, so MSVC has its own way to handle it, namely %Iu. Signed-off-by: Derek Buitenhuis --- libavcodec/tableprint.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libavcodec/tableprint.h b/libavcodec/tableprint.h index 81bb9afdcb..daa89fe99b 100644 --- a/libavcodec/tableprint.h +++ b/libavcodec/tableprint.h @@ -71,10 +71,20 @@ void write_uint32_t_2d_array(const void *, int, int); void write_float_2d_array (const void *, int, int); /** @} */ // end of printfuncs group +/* + * MSVC doesn't have %zu, since it was introduced in C99, + * but has its own %Iu for printing size_t values. + */ +#if defined(_MSC_VER) +#define FMT "Iu" +#else +#define FMT "zu" +#endif + #define WRITE_ARRAY(prefix, type, name) \ do { \ const size_t array_size = FF_ARRAY_ELEMS(name); \ - printf(prefix" "#type" "#name"[%zu] = {\n", \ + printf(prefix" "#type" "#name"[%"FMT"] = {\n", \ array_size); \ write_##type##_array(name, array_size); \ printf("};\n"); \ @@ -84,7 +94,7 @@ void write_float_2d_array (const void *, int, int); do { \ const size_t array_size1 = FF_ARRAY_ELEMS(name); \ const size_t array_size2 = FF_ARRAY_ELEMS(name[0]); \ - printf(prefix" "#type" "#name"[%zu][%zu] = {\n", \ + printf(prefix" "#type" "#name"[%"FMT"][%"FMT"] = {\n", \ array_size1, array_size2 ); \ write_##type##_2d_array(name, array_size1, array_size2); \ printf("};\n"); \ From bc31a7a3b6bcd7409e4440d7d8124006813fe15a Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Tue, 15 Jan 2013 16:08:59 -0500 Subject: [PATCH 2/4] tablegen: Don't use cbrtf in host tools 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 --- 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 01963a3f9d..60d900a94f 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 a222f2c423..a6c203ff3b 100644 --- a/libavcodec/mpegaudio_tablegen.h +++ b/libavcodec/mpegaudio_tablegen.h @@ -47,7 +47,8 @@ static void mpegaudio_tableinit(void) double value = i / 4; double f, fm; int e, m; - f = value * cbrtf(value) * pow(2, (i & 3) * 0.25); + /* cbrtf() isn't available on all systems, so we use powf(). */ + f = value * 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; @@ -58,7 +59,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); + /* 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); expval_table_fixed[exponent][value] = llrint(f); expval_table_float[exponent][value] = f; } From 479a52795526a5ad6628e37d9614dee5e32dc773 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Tue, 15 Jan 2013 16:09:00 -0500 Subject: [PATCH 3/4] cos_tablegen: Don't use lrint You cannot count on it being present on all systems, and you cannot include libm.h in a host tool, so just hard code a baseline implementation. Signed-off-by: Derek Buitenhuis --- libavcodec/cos_tablegen.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libavcodec/cos_tablegen.c b/libavcodec/cos_tablegen.c index 8a9085704e..9cf9cef6aa 100644 --- a/libavcodec/cos_tablegen.c +++ b/libavcodec/cos_tablegen.c @@ -37,11 +37,16 @@ static int clip_f15(int v) static void printval(double val, int fixed) { - if (fixed) - printf(" "FIXEDFMT",", clip_f15(lrint(val * (double)(1<<15)))); - else - printf(" "FLOATFMT",", val); + if (fixed) { + /* lrint() isn't always available, so round and cast manually. */ + double new_val = val * (double) (1 << 15); + new_val = new_val >= 0 ? floor(new_val + 0.5) : ceil(new_val - 0.5); + + printf(" "FIXEDFMT",", clip_f15((long int) new_val)); + } else { + printf(" "FLOATFMT",", val); + } } int main(int argc, char *argv[]) From c0085f94fea89b180e5727b193484a83586d3490 Mon Sep 17 00:00:00 2001 From: Derek Buitenhuis Date: Tue, 15 Jan 2013 16:09:01 -0500 Subject: [PATCH 4/4] mpegaudio_tablegen: Don't use llrint You cannot count on it being present on all systems, and you cannot include libm.h in a host tool, so just hard code a baseline implementation. Signed-off-by: Derek Buitenhuis --- libavcodec/mpegaudio_tablegen.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/mpegaudio_tablegen.h b/libavcodec/mpegaudio_tablegen.h index a6c203ff3b..8a3e51ae60 100644 --- a/libavcodec/mpegaudio_tablegen.h +++ b/libavcodec/mpegaudio_tablegen.h @@ -61,7 +61,8 @@ static void mpegaudio_tableinit(void) for (value = 0; value < 16; value++) { /* 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); - expval_table_fixed[exponent][value] = llrint(f); + /* llrint() isn't always available, so round and cast manually. */ + expval_table_fixed[exponent][value] = (long long int) (f >= 0 ? floor(f + 0.5) : ceil(f - 0.5)); expval_table_float[exponent][value] = f; } exp_table_fixed[exponent] = expval_table_fixed[exponent][1];