Skip to content

Instantly share code, notes, and snippets.

@mgk
Created October 14, 2015 19:17
Show Gist options
  • Save mgk/be1ea65e0a38bad4d418 to your computer and use it in GitHub Desktop.
Save mgk/be1ea65e0a38bad4d418 to your computer and use it in GitHub Desktop.
second patch for libvpx 1082
From 3a4d4c6b23c1d604f18437835a700182758717e9 Mon Sep 17 00:00:00 2001
From: Johann <[email protected]>
Date: Wed, 14 Oct 2015 10:42:41 -0700
Subject: [PATCH] Check for bswap* builtins before using
Canonical builtin checks for clang are to use
__has_builtin. Much less fragile than version checks.
https://code.google.com/p/webm/issues/detail?id=1082
Change-Id: I8151fb75899acdf1a935c23aad9441da99a9abcd
---
diff --git a/vpx_util/endian_inl.h b/vpx_util/endian_inl.h
index 6b177f1..1c759a3 100644
--- a/vpx_util/endian_inl.h
+++ b/vpx_util/endian_inl.h
@@ -25,14 +25,10 @@
# define LOCAL_GCC_PREREQ(maj, min) 0
#endif
-#ifdef __clang__
-# define LOCAL_CLANG_VERSION ((__clang_major__ << 8) | __clang_minor__)
-# define LOCAL_CLANG_PREREQ(maj, min) \
- (LOCAL_CLANG_VERSION >= (((maj) << 8) | (min)))
-#else
-# define LOCAL_CLANG_VERSION 0
-# define LOCAL_CLANG_PREREQ(maj, min) 0
-#endif // __clang__
+// handle clang compatibility
+#ifndef __has_builtin
+# define __has_builtin(x) 0
+#endif
// some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__)
#if !defined(WORDS_BIGENDIAN) && \
@@ -53,13 +49,14 @@
#define HToBE32(X) BSwap32(X)
#endif
-// clang-3.3 and gcc-4.3 have builtin functions for swap32/swap64
-#if LOCAL_GCC_PREREQ(4, 3) || LOCAL_CLANG_PREREQ(3, 3)
+// compilers which support bswap32 generally support bswap64
+#if LOCAL_GCC_PREREQ(4, 3) || \
+ (__has_builtin(__builtin_bswap32) && __has_builtin(bswap64))
#define HAVE_BUILTIN_BSWAP32
#define HAVE_BUILTIN_BSWAP64
#endif
-// clang-3.3 and gcc-4.8 have a builtin function for swap16
-#if LOCAL_GCC_PREREQ(4, 8) || LOCAL_CLANG_PREREQ(3, 3)
+// bswap16 support came much later
+#if LOCAL_GCC_PREREQ(4, 8) || __has_builtin(__builtin_bswap16)
#define HAVE_BUILTIN_BSWAP16
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment