aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/main.cpp1
-rw-r--r--common/math.h33
2 files changed, 34 insertions, 0 deletions
diff --git a/base/main.cpp b/base/main.cpp
index a0792a9ad2..435eeb1571 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 56ab171bd3..f787b84fa6 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] = {