[babl/sse-conversions-2013] Use clock_gettime for babl_ticks if available
- From: Daniel Sabo <daniels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl/sse-conversions-2013] Use clock_gettime for babl_ticks if available
- Date: Sat, 6 Apr 2013 03:58:52 +0000 (UTC)
commit e4d0837384bcf39eea8b099aec222e2b30d0578c
Author: Daniel Sabo <DanielSabo gmail com>
Date: Fri Apr 5 20:14:04 2013 -0700
Use clock_gettime for babl_ticks if available
babl/Makefile.am | 1 +
babl/babl-util.c | 30 ++++++++++++++++++++++++
configure.ac | 66 ++++++++++++++++++++++++++++++++++++++++++++---------
3 files changed, 85 insertions(+), 12 deletions(-)
---
diff --git a/babl/Makefile.am b/babl/Makefile.am
index 976b1e0..89636c0 100644
--- a/babl/Makefile.am
+++ b/babl/Makefile.am
@@ -85,6 +85,7 @@ libbabl_ BABL_API_VERSION@_la_LIBADD=\
libbabl_ BABL_API_VERSION@_la_LDFLAGS= \
${no_undefined} $(MATH_LIB) \
+ $(CLOCK_GETTIME_LIBS) \
-version-info $(BABL_LIBRARY_VERSION)
# GObject Introspection
diff --git a/babl/babl-util.c b/babl/babl-util.c
index 40ddfa2..504977c 100644
--- a/babl/babl-util.c
+++ b/babl/babl-util.c
@@ -23,6 +23,34 @@
#include <sys/time.h>
#include <time.h>
+#ifdef HAVE_CLOCK_GETTIME
+struct timespec start_time;
+
+static void
+init_ticks (void)
+{
+ static int done = 0;
+
+ if (done)
+ return;
+ done = 1;
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
+}
+
+long
+babl_ticks (void)
+{
+ struct timespec measure_time;
+ init_ticks ();
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &measure_time);
+
+ long long delta_t = (measure_time.tv_sec - start_time.tv_sec) * 1000000000 + (measure_time.tv_nsec -
start_time.tv_nsec);
+
+ return (delta_t + 999) / 1000;
+}
+
+#else
+
static struct timeval start_time;
#define usecs(time) ((time.tv_sec - start_time.tv_sec) * 1000000 + time.tv_usec)
@@ -47,6 +75,8 @@ babl_ticks (void)
return usecs (measure_time) - usecs (start_time);
}
+#endif HAVE_CLOCK_GETTIME
+
long
babl_process_cost (long ticks_start,
long ticks_end)
diff --git a/configure.ac b/configure.ac
index 4954e38..28abf22 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,30 @@ AC_SUBST(MATH_LIB)
AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
AM_CONDITIONAL(OS_UNIX, test "$os_win32" != "yes")
+############################
+# Check for clock_gettime
+############################
+
+if test "x$os_win32" != xyes; then
+ have_clock_gettime_save_LIBS="$LIBS"
+ LIBS="$LIBS -lrt"
+ AC_MSG_CHECKING([for clock_gettime])
+ AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <time.h>]],
+ [[struct timespec t; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);]])],
+ [have_clock_gettime=yes],
+ [have_clock_gettime=no])
+ AC_MSG_RESULT($have_clock_gettime)
+ if test "x$have_clock_gettime" = xyes; then
+ CLOCK_GETTIME_LIBS="-lrt"
+ AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define to 1 if clock_gettime is available.])
+ fi
+ LIBS="$have_clock_gettime_save_LIBS"
+fi
+
+AC_SUBST(CLOCK_GETTIME_LIBS)
+#AM_CONDITIONAL(HAVE_CLOCK_GETTIME, test "x$have_clock_gettime" = "xyes")
dnl ===========================================================================
@@ -294,6 +318,10 @@ AC_ARG_ENABLE(sse,
[ --enable-sse enable SSE support (default=auto)],,
enable_sse=$enable_mmx)
+AC_ARG_ENABLE(sse2,
+ [ --enable-sse2 enable SSE2 support (default=auto)],,
+ enable_sse2=$enable_sse)
+
if test "x$enable_mmx" = xyes; then
BABL_DETECT_CFLAGS(MMX_EXTRA_CFLAGS, '-mmmx')
SSE_EXTRA_CFLAGS=
@@ -329,21 +357,24 @@ if test "x$enable_mmx" = xyes; then
AC_MSG_WARN([The assembler does not support the SSE command set.])
)
- BABL_DETECT_CFLAGS(sse2_flag, '-msse2')
- SSE2_EXTRA_CFLAGS="$SSE_EXTRA_CFLAGS $sse2_flag"
+
+ if test "x$enable_sse2" = xyes; then
+ BABL_DETECT_CFLAGS(sse2_flag, '-msse2')
+ SSE2_EXTRA_CFLAGS="$SSE_EXTRA_CFLAGS $sse2_flag"
- AC_MSG_CHECKING(whether we can compile SSE2 code)
+ AC_MSG_CHECKING(whether we can compile SSE2 code)
- CFLAGS="$CFLAGS $sse2_flag"
+ CFLAGS="$CFLAGS $sse2_flag"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("punpckhwd %xmm0,%xmm1");])],
- AC_DEFINE(USE_SSE2, 1, [Define to 1 if SSE2 assembly is available.])
- AC_MSG_RESULT(yes)
- ,
- enable_sse2=no
- AC_MSG_RESULT(no)
- AC_MSG_WARN([The assembler does not support the SSE2 command set.])
- )
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[asm ("punpckhwd %xmm0,%xmm1");])],
+ AC_DEFINE(USE_SSE2, 1, [Define to 1 if SSE2 assembly is available.])
+ AC_MSG_RESULT(yes)
+ ,
+ enable_sse2=no
+ AC_MSG_RESULT(no)
+ AC_MSG_WARN([The assembler does not support the SSE2 command set.])
+ )
+ fi
fi
,
@@ -454,3 +485,14 @@ INSTALL
)
AC_OUTPUT
+
+dnl Print a summary of features enabled/disabled:
+AC_MSG_RESULT([
+Building Babl with prefix=$prefix
+
+Optional features:
+ SIMD: mmx: $enable_mmx
+ sse: $enable_sse
+ sse2:$enable_sse2
+ RTC: $have_clock_gettime
+]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]