[Mesa-dev] [PATCH] gallium/util: Define ffsll on OpenBSD.
Jon TURNEY
jon.turney at dronecode.org.uk
Mon Feb 9 08:59:06 PST 2015
On 06/02/2015 19:58, Matt Turner wrote:
> On Fri, Feb 6, 2015 at 3:38 AM, Jonathan Gray <jsg at jsg.id.au> wrote:
>> OpenBSD has ffs in libc but does not have ffsll so use the compiler
>> builtin. PIPE_OS_BSD isn't suitable here as FreeBSD has ffsll in libc.
>>
>> Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
>> ---
>> src/gallium/auxiliary/util/u_math.h | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
>> index 5db5b66..ec282f3 100644
>> --- a/src/gallium/auxiliary/util/u_math.h
>> +++ b/src/gallium/auxiliary/util/u_math.h
>> @@ -531,6 +531,8 @@ unsigned ffs( unsigned u )
>> #elif defined(__MINGW32__) || defined(PIPE_OS_ANDROID)
>> #define ffs __builtin_ffs
>> #define ffsll __builtin_ffsll
>> +#elif defined(__OpenBSD__)
>> +#define ffsll __builtin_ffsll
>> #endif
>
> Autoconf checks for presence of a bunch of builtins. Please use those
> instead (in this case, HAVE___BUILTIN_FFSLL).
Yes, please.
This has just been 'fixed' for MinGW, now for OpenBSD, and also needs
fixing for Cygwin.
Attached is a patch which attempts to do this using autoconf checks.
-------------- next part --------------
From 580eb16295a94012c488db7ac44d09cb3ca8ff55 Mon Sep 17 00:00:00 2001
From: Jon TURNEY <jon.turney at dronecode.org.uk>
Date: Sat, 7 Feb 2015 14:17:35 +0000
Subject: [PATCH] gallium/util: Use autoconf check for ffs() and ffsll()
u_math.h should probably explicitly include config.h, but it didn't before and
already relies on some HAVE_ defines, so I haven't added it.
This makes a subtle change on non-linux platforms: previously we were explicitly
using __builtin_ffs(), whereas now we are using ffs(), and the compiler might
decide to convert that to a builtin. If we wanted to ensure the builtin was
used for some reason, this isn't quite right.
Since ffs() is used, we need to include <strings.h> for the prototype, which I
think we expect to find on all POSIX systems, but not on MSVC. Add an autoconf
check for that header and use that to conditionalize it's use.
Define _GNU_SOURCE on Cygwin so that the GNU extension ffsll() is prototyped.
I think I've put the right defines in the right place for the Android build
system, but I haven't build tested that.
Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
---
Android.common.mk | 3 +++
configure.ac | 6 +++++-
src/gallium/auxiliary/util/u_math.h | 12 ++++++++++--
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/Android.common.mk b/Android.common.mk
index 3e6d4c3..7719096 100644
--- a/Android.common.mk
+++ b/Android.common.mk
@@ -42,6 +42,9 @@ LOCAL_CFLAGS += \
LOCAL_CFLAGS += \
-DHAVE_PTHREAD=1 \
+ -DHAVE_STRINGS_H \
+ -DHAVE___BUILTIN_FFS \
+ -DHAVE___BUILTIN_FFSLL \
-fvisibility=hidden \
-Wno-sign-compare
diff --git a/configure.ac b/configure.ac
index 7c2692e..cd4d7ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -172,6 +172,10 @@ if test "x$GCC" = xyes -a "x$acv_mesa_CLANG" = xno; then
fi
fi
+dnl Check for ffs and ffsll
+AC_CHECK_HEADER([strings.h])
+AC_CHECK_FUNCS([ffs ffsll])
+
dnl Check for compiler builtins
AX_GCC_BUILTIN([__builtin_bswap32])
AX_GCC_BUILTIN([__builtin_bswap64])
@@ -219,7 +223,7 @@ solaris*)
DEFINES="$DEFINES -DSVR4"
;;
cygwin*)
- DEFINES="$DEFINES -D_XOPEN_SOURCE=700"
+ DEFINES="$DEFINES -D_GNU_SOURCE"
;;
esac
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 5db5b66..45587fb 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -52,7 +52,7 @@ extern "C" {
#include <float.h>
#include <stdarg.h>
-#ifdef PIPE_OS_UNIX
+#ifdef HAVE_STRINGS_H
#include <strings.h> /* for ffs */
#endif
@@ -528,10 +528,18 @@ unsigned ffs( unsigned u )
return i;
}
-#elif defined(__MINGW32__) || defined(PIPE_OS_ANDROID)
+#else
+#ifndef HAVE_FFS
+#ifdef HAVE___BUILTIN_FFS
#define ffs __builtin_ffs
+#endif
+#endif
+#ifndef HAVE_FFSLL
+#ifdef HAVE___BUILTIN_FFSLL
#define ffsll __builtin_ffsll
#endif
+#endif
+#endif
#endif /* FFS_DEFINED */
--
2.1.4
More information about the mesa-dev
mailing list