[Scummvm-cvs-logs] scummvm master -> ff98725172cd1b57251fb9ead4ef1aaf4081e730

lordhoto lordhoto at gmail.com
Fri Aug 19 01:09:47 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ff98725172 COMMON: intLog2 uses _BitScanReverse on MSVC


Commit: ff98725172cd1b57251fb9ead4ef1aaf4081e730
    https://github.com/scummvm/scummvm/commit/ff98725172cd1b57251fb9ead4ef1aaf4081e730
Author: Bertrand Augereau (bertrand_augereau at yahoo.fr)
Date: 2011-08-18T16:05:37-07:00

Commit Message:
COMMON: intLog2 uses _BitScanReverse on MSVC

Changed paths:
    base/main.cpp
    common/math.h



diff --git a/base/main.cpp b/base/main.cpp
index a0792a9..435eeb1 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -48,6 +48,7 @@
 #include "common/textconsole.h"
 #include "common/tokenizer.h"
 #include "common/translation.h"
+#include "common/math.h"
 
 #include "gui/gui-manager.h"
 #include "gui/error.h"
diff --git a/common/math.h b/common/math.h
index 56ab171..f787b84 100644
--- a/common/math.h
+++ b/common/math.h
@@ -26,6 +26,31 @@
 #define COMMON_MATH_H
 
 #include "common/scummsys.h"
+#ifdef _MSC_VER
+// HACK:
+// intrin.h on MSVC includes setjmp.h, which will fail compiling due to our
+// forbidden symbol colde. Since we also can not assure that defining
+// FORBIDDEN_SYMBOL_EXCEPTION_setjmp and FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+// will actually allow the symbols, since forbidden.h might be included
+// earlier already we need to undefine them here...
+#undef setjmp
+#undef longjmp
+#include <intrin.h>
+// ...and redefine them here so no code can actually use it.
+// This could be resolved by including intrin.h on MSVC in scummsys.h before
+// the forbidden.h include. This might make sense, in case we use MSVC
+// extensions like _BitScanReverse in more places. But for now this hack should
+// be ok...
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp
+#undef setjmp
+#define setjmp(a)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+#undef longjmp
+#define longjmp(a,b)	FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+#endif
 
 #ifndef M_SQRT1_2
 	#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
@@ -63,6 +88,14 @@ inline int intLog2(uint32 v) {
 		// limits.h
 		return (sizeof(unsigned int) * 8 - 1) - __builtin_clz(v);
 }
+#elif defined(_MSC_VER)
+inline int intLog2(uint32 v) {
+	unsigned long result = 0;
+	unsigned char nonZero = _BitScanReverse(&result, v);
+	// _BitScanReverse stores the position of the MSB set in case its result
+	// is non zero, thus we can just return it as is.
+	return nonZero ? result : -1;
+}
 #else
 // See http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
 static const char LogTable256[256] = {






More information about the Scummvm-git-logs mailing list