diff options
author | Andreas Holzammer <andreas.holzammer@kdab.com> | 2013-02-26 14:22:17 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-12 16:57:53 +0200 |
commit | c0e187a1bd38d41cffc3471854de88d679971209 (patch) | |
tree | 0063ff8538ce8fad2fe8be57f42a07962b2fe66f | |
parent | bb28a89a869b3e0c2a1aaebeec1fb153b3aa553c (diff) |
[V8] Implement some compiler intrinsic functions
Implement CountTrailingZeros and CountLeadingZeros
Change-Id: I3383861df2b1f4e2d410216ca0a22583a84bcb32
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r-- | src/3rdparty/v8/src/compiler-intrinsics.h | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/3rdparty/v8/src/compiler-intrinsics.h b/src/3rdparty/v8/src/compiler-intrinsics.h index b73e8ac..c1693b0 100644 --- a/src/3rdparty/v8/src/compiler-intrinsics.h +++ b/src/3rdparty/v8/src/compiler-intrinsics.h @@ -28,6 +28,10 @@ #ifndef V8_COMPILER_INTRINSICS_H_ #define V8_COMPILER_INTRINSICS_H_ +#if defined(_WIN32_WCE) +#include <cmnintrin.h> +#endif + namespace v8 { namespace internal { @@ -58,7 +62,7 @@ int CompilerIntrinsics::CountSetBits(uint32_t value) { return __builtin_popcount(value); } -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) && !defined(_WIN32_WCE) #pragma intrinsic(_BitScanForward) #pragma intrinsic(_BitScanReverse) @@ -75,6 +79,21 @@ int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { return 31 - static_cast<int>(result); } +#elif defined(_WIN32_WCE) +int CompilerIntrinsics::CountTrailingZeros(uint32_t value) { + // taken from http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightFloatCast + float f = (float)(value & -value); // cast the least significant bit in v to a float + return (*(uint32_t *)&f >> 23) - 0x7f; +} + +int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { + return _CountLeadingZeros(value); +} +#else +#error Unsupported compiler +#endif + +#if defined(_MSC_VER) int CompilerIntrinsics::CountSetBits(uint32_t value) { // Manually count set bits. value = ((value >> 1) & 0x55555555) + (value & 0x55555555); @@ -84,9 +103,6 @@ int CompilerIntrinsics::CountSetBits(uint32_t value) { value = ((value >> 16) & 0x0000ffff) + (value & 0x0000ffff); return value; } - -#else -#error Unsupported compiler #endif } } // namespace v8::internal |