diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2015-02-10 22:19:51 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-02-17 00:42:04 +0000 |
commit | b584648df169bb9c8b67b24b4504b0fea82b093d (patch) | |
tree | 8506080a4bb82de5b9a82c6a33a932f8daef8bf2 | |
parent | 738e9b185c72b6814bc3e4ea2a7a23adce326a73 (diff) |
Use Clang 3.6's __builtin_assume in Q_ASSUME
It's more efficient than the current implementation. Example:
int f(int i)
{
Q_ASSUME(i < 8);
return i < 8;
}
Before:
cmpl $8, %edi
setl %al
movzbl %al, %eax
retq
After:
movl $1, %eax
retq
Change-Id: I1a800c709d3543699131ffff13c1c50713a8da2c
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r-- | src/corelib/global/qcompilerdetection.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 8ef8b79902..ba87bb5cc9 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -173,7 +173,11 @@ # else # define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__) # endif -# define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable() +# if __has_builtin(__builtin_assume) +# define Q_ASSUME_IMPL(expr) __builtin_assume(expr) +# else +# define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable() +# endif # define Q_UNREACHABLE_IMPL() __builtin_unreachable() # if !defined(__has_extension) # /* Compatibility with older Clang versions */ |