[FFmpeg-devel] [PATCH] configure: add host libm capability detection

Ganesh Ajjanagadde gajjanagadde at gmail.com
Thu Nov 26 06:04:38 CET 2015


This is needed in order to obtain what is available for hardcoded
table generation.

A minimal avutil/host_libm.h is also created.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
 configure             | 41 +++++++++++++++++++++++++++++++++++++++++
 libavutil/host_libm.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)
 create mode 100644 libavutil/host_libm.h

diff --git a/configure b/configure
index 0198b75..af411a3 100755
--- a/configure
+++ b/configure
@@ -926,6 +926,10 @@ ld_o(){
     eval printf '%s\\n' $LD_O
 }
 
+host_ld_o(){
+    eval printf '%s\\n' $HOSTLD_O
+}
+
 check_ld(){
     log check_ld "$@"
     type=$1
@@ -938,6 +942,18 @@ check_ld(){
     check_cmd $ld $LDFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs
 }
 
+check_host_ld(){
+    log check_host_ld "$@"
+    type=$1
+    shift 1
+    flags=$(filter_out '-l*|*.so' $@)
+    libs=$(filter '-l*|*.so' $@)
+    check_$type $($host_cflags_filter $flags) || return
+    flags=$($host_ldflags_filter $flags)
+    libs=$($host_ldflags_filter $libs)
+    check_cmd $host_ld $host_ldflags $flags $(host_ld_o $TMPE) $TMPO $host_libs $extralibs
+}
+
 print_include(){
     hdr=$1
     test "${hdr%.h}" = "${hdr}" &&
@@ -1061,6 +1077,20 @@ int main(void){ return (int) foo; }
 EOF
 }
 
+check_host_mathfunc(){
+    log check_host_mathfunc "$@"
+    func=$1
+    narg=$2
+    shift 2
+    test $narg = 2 && args="f, g" || args="f"
+    disable $(add_suffix _host $func)
+    check_host_ld "host_cc" "$@" <<EOF && enable $(add_suffix _host $func)
+#include <math.h>
+float foo(float f, float g) { return $func($args); }
+int main(void){ return (int) foo; }
+EOF
+}
+
 check_func_headers(){
     log check_func_headers "$@"
     headers=$1
@@ -1762,6 +1792,12 @@ INTRINSICS_LIST="
     intrinsics_neon
 "
 
+HOST_MATH_FUNCS="
+    cbrt
+    llrint
+    rint
+"
+
 MATH_FUNCS="
     atanf
     atan2f
@@ -1902,6 +1938,7 @@ HAVE_LIST="
     $HAVE_LIST_PUB
     $HEADERS_LIST
     $INTRINSICS_LIST
+    $(add_suffix _host $HOST_MATH_FUNCS)
     $MATH_FUNCS
     $SYSTEM_FUNCS
     $THREADS_LIST
@@ -5317,6 +5354,10 @@ for func in $MATH_FUNCS; do
     eval check_mathfunc $func \${${func}_args:-1}
 done
 
+for func in $HOST_MATH_FUNCS; do
+    eval check_host_mathfunc $func \${${func}_args:-1}
+done
+
 # these are off by default, so fail if requested and not available
 enabled avfoundation_indev && { check_header_oc AVFoundation/AVFoundation.h || disable avfoundation_indev; }
 enabled avfoundation_indev && { check_lib2 CoreGraphics/CoreGraphics.h CGGetActiveDisplayList -framework CoreGraphics ||
diff --git a/libavutil/host_libm.h b/libavutil/host_libm.h
new file mode 100644
index 0000000..927b93e
--- /dev/null
+++ b/libavutil/host_libm.h
@@ -0,0 +1,51 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * Replacements for frequently missing host libm functions
+ */
+
+#ifndef AVUTIL_HOST_LIBM_H
+#define AVUTIL_HOST_LIBM_H
+
+#include <math.h>
+#include "config.h"
+#include "attributes.h"
+#include "intfloat.h"
+
+#if !HAVE_CBRT_HOST
+static av_always_inline double cbrt(double x)
+{
+    return x < 0 ? -pow(-x, 1.0 / 3.0) : pow(x, 1.0 / 3.0);
+}
+#endif
+
+#if !HAVE_LLRINT_HOST
+#undef llrint
+#define llrint(x) ((long long)rint(x))
+#endif /* HAVE_LLRINT_HOST */
+
+#if !HAVE_RINT_HOST
+static inline double rint(double x)
+{
+    return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
+}
+#endif /* HAVE_RINT_HOST */
+
+#endif /* AVUTIL_LIBM_H */
-- 
2.6.2



More information about the ffmpeg-devel mailing list