On 01/24/16 12:29 PM, Erik de Castro Lopo wrote:> Dave Yeo wrote:
> 
>> After this the build dies with,
>> util.c: In function 'benchmark_function':
>> util.c:124:17: error: 'CLOCK_PROCESS_CPUTIME_ID' undeclared (first use
>> in this function)
>>     clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &start) ;
>>
>> Would using gettimeofday() be accurate enough?
> 
> AS a fall back yes, but not as replacement on platforms with clock_gettime().
> 
>> Perhaps simpler just to
>> disable the microbench test on OS/2 as gettimeofday() would require a
>> configure test and OS/2 is a minor platform?
> 
> 
> I would accept a patch that disables the microsbenchmark on OS/2 I would
> also accept one that uses gettimeofday() when clock_gettime() is not
> available.

Here's one attempt, added configure options to disable AVX and clock_gettime, 
only tested on OS/2.
With this compilation succeeds on OS/2. Make check does eventually fail with,
...
WAVE fixup test... prepare... encode... decode... compare... OK
AIFF fixup test... prepare... encode... decode... compare... OK
Generating multiple input files from noise...
ERROR: creating files with dd
...
which I don't understand. Perhaps buggy dd. I take it this succeeds on Windows. 
Since $COMSPEC is set here we take the if_win path.
Dave
From 7e7e97eedd6df9ceb49d701cd68bc0133aebb4c0 Mon Sep 17 00:00:00 2001
From: Dave Yeo <dave.r.yeo@gmail.com>
Date: Sun, 24 Jan 2016 22:09:50 -0800
Subject: [PATCH 1/2] Enable disabling AVX and AVX2 instructions through a
 configure option

Handy for toolchains or operating systems that don't support AVX or AVX2

Signed-off-by: Dave Yeo <dave.r.yeo@gmail.com>
---
 configure.ac                      | 13 +++++++++++++
 src/libFLAC/include/private/cpu.h |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/configure.ac b/configure.ac
index d6bb2d0..915869b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -238,6 +238,19 @@ AC_DEFINE(FLAC__USE_ALTIVEC)
 AH_TEMPLATE(FLAC__USE_ALTIVEC, [define to enable use of Altivec instructions])
 fi
 
+AC_ARG_ENABLE(avx,
+AC_HELP_STRING([--disable-avx], [Disable AVX, AVX2 optimizations]),
+[case "${enableval}" in
+	yes) use_avx=true ;;
+	no)  use_avx=false ;;
+	*) AC_MSG_ERROR(bad value ${enableval} for --enable-avx) ;;
+esac],[use_avx=true])
+AM_CONDITIONAL(FLaC__USE_AVX, test "x$use_avx" = xtrue)
+if test "x$use_avx" = xtrue ; then
+AC_DEFINE(FLAC__USE_AVX)
+AH_TEMPLATE(FLAC__USE_AVX, [define to enable use of AVX instructions])
+fi
+
 AC_ARG_ENABLE(thorough-tests,
 AC_HELP_STRING([--disable-thorough-tests], [Disable thorough (long) testing, do only basic tests]),
 [case "${enableval}" in
diff --git a/src/libFLAC/include/private/cpu.h b/src/libFLAC/include/private/cpu.h
index 380f4f0..46d01e3 100644
--- a/src/libFLAC/include/private/cpu.h
+++ b/src/libFLAC/include/private/cpu.h
@@ -78,9 +78,11 @@
     #define FLAC__SSE2_SUPPORTED 1
     #define FLAC__SSSE3_SUPPORTED 1
     #define FLAC__SSE4_1_SUPPORTED 1
+#ifdef FLAC__USE_AVX
     #define FLAC__AVX_SUPPORTED 1
     #define FLAC__AVX2_SUPPORTED 1
     #define FLAC__FMA_SUPPORTED 1
+#endif
   #else /* for GCC older than 4.9 */
     #define FLAC__SSE_TARGET(x)
     #ifdef __SSE__
-- 
2.0.0

From 75ce4c6c622f0882012f0e04f20004d1c3f136bc Mon Sep 17 00:00:00 2001
From: Dave Yeo <dave.r.yeo@gmail.com>
Date: Tue, 2 Feb 2016 20:19:59 -0800
Subject: [PATCH 2/2] Use gettimeofday() for benchmarking

Some operating systems such as OS/2 don't have any of the CLOCK* API implemented

Signed-off-by: Dave Yeo <dave.r.yeo@gmail.com>
---
 configure.ac      | 14 ++++++++++++++
 microbench/util.c | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 915869b..ec5466d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -371,6 +371,20 @@ AC_DEFINE(FLAC__HAS_DOCBOOK_TO_MAN)
 AH_TEMPLATE(FLAC__HAS_DOCBOOK_TO_MAN, [define if you have docbook-to-man or docbook2man])
 fi
 
+# Check for clock_gettime()
+CheckClockGettime()
+{
+    AC_ARG_ENABLE(clock_gettime,
+AC_HELP_STRING([--enable-clock_gettime], [use clock_gettime() instead of gettimeofday() on UNIX [[default=yes]]]),
+                  , enable_clock_gettime=yes)
+    if test x$enable_clock_gettime = xyes; then
+        AC_CHECK_LIB(rt, clock_gettime, have_clock_gettime=yes)
+        if test x$have_clock_gettime = xyes; then
+            AC_DEFINE(HAVE_CLOCK_GETTIME)
+        fi
+    fi
+}
+
 # only matters for x86
 AC_CHECK_PROGS(NASM, nasm)
 AM_CONDITIONAL(FLaC__HAS_NASM, test -n "$NASM")
diff --git a/microbench/util.c b/microbench/util.c
index ff1c3fb..dbd4bc1 100644
--- a/microbench/util.c
+++ b/microbench/util.c
@@ -95,7 +95,7 @@ benchmark_function (void (*testfunc) (void), unsigned count)
 	return counter_diff (&start, &end) / count ;
 } /* benchmark_function */
 
-#else
+#elif defined HAVE_CLOCK_GETTIME
 
 #include <time.h>
 #include <sys/time.h>
@@ -131,6 +131,42 @@ benchmark_function (void (*testfunc) (void), unsigned count)
 	return timespec_diff (&start, &end) / count ;
 } /* benchmark_function */
 
+#else
+
+#include <time.h>
+#include <sys/time.h>
+
+static double
+timeval_diff (const struct timeval * start, const struct timeval * end)
+{       struct timeval diff;
+
+        if (end->tv_usec - start->tv_usec < 0)
+        {       diff.tv_sec = end->tv_sec - start->tv_sec - 1 ;
+                diff.tv_usec = 1000000 + end->tv_usec - start->tv_usec ;
+                }
+        else
+        {       diff.tv_sec = end->tv_sec - start->tv_sec ;
+                diff.tv_usec = end->tv_usec-start->tv_usec ;
+                } ;
+
+        return diff.tv_sec + 1e-6 * diff.tv_usec ;
+}
+
+double
+benchmark_function (void (*testfunc) (void), unsigned count)
+{	struct timeval start, end;
+	unsigned k ;
+
+	gettimeofday(&start, NULL);
+
+	for (k = 0 ; k < count ; k++)
+		testfunc () ;
+
+	gettimeofday(&end, NULL);
+
+	return timeval_diff (&start, &end) / count ;
+} /* benchmark_function */
+
 #endif
 
 static int
-- 
2.0.0

_______________________________________________
flac-dev mailing list
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev

Reply via email to