diff options
author | Andrew Scheidecker <andrew@scheidecker.net> | 2015-12-23 09:09:49 -0800 |
---|---|---|
committer | Andrew Scheidecker <andrew@scheidecker.net> | 2015-12-23 09:29:24 -0800 |
commit | 32490684ab0fa568d4e539c24f7c560295da57de (patch) | |
tree | 4e4a91591ea75ba52cc9c0d37698f8aac743896e /src/wasm-interpreter.h | |
parent | a79329fbe135bab9a319fd3afc911620b12f0124 (diff) | |
download | binaryen-32490684ab0fa568d4e539c24f7c560295da57de.tar.gz binaryen-32490684ab0fa568d4e539c24f7c560295da57de.tar.bz2 binaryen-32490684ab0fa568d4e539c24f7c560295da57de.zip |
Fix a few Windows/VS2013 compile errors
Diffstat (limited to 'src/wasm-interpreter.h')
-rw-r--r-- | src/wasm-interpreter.h | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 97958b041..3db818787 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -35,6 +35,25 @@ using namespace cashew; IString WASM("wasm"); + +#ifdef WIN32 +#include <intrin.h> + +int32_t safe_clz(int32_t v) { + unsigned long result; + return _BitScanReverse(&result,v) ? result : 32; +} + +int32_t safe_ctz(int32_t v) { + unsigned long result; + return _BitScanForward(&result,v) ? result : 32; +} + +int32_t platform_popcount(int32_t v) +{ + return __popcnt(v); +} +#else int32_t safe_clz(int32_t v) { if (v == 0) return 32; return __builtin_clz(v); @@ -45,6 +64,12 @@ int32_t safe_ctz(int32_t v) { return __builtin_ctz(v); } +int32_t platform_popcount(int32_t v) +{ + return __buildin_popcount(v); +} +#endif + enum { pageSize = 64*1024, maxCallDepth = 250 @@ -374,7 +399,7 @@ private: if (v == 0) return Literal(32); return Literal((int32_t)safe_ctz(v)); } - case Popcnt: return Literal((int32_t)__builtin_popcount(v)); + case Popcnt: return Literal((int32_t)platform_popcount(v)); case ReinterpretInt: { float v = value.reinterpretf32(); if (isnan(v)) { @@ -403,7 +428,7 @@ private: if (low == 0) return Literal(32+(int64_t)safe_ctz(high)); return Literal((int64_t)safe_ctz(low)); } - case Popcnt: return Literal(int64_t(__builtin_popcount(low) + __builtin_popcount(high))); + case Popcnt: return Literal(int64_t(platform_popcount(low) + platform_popcount(high))); case WrapInt64: return Literal(int32_t(value.geti64())); case ReinterpretInt: { return Literal(value.reinterpretf64()); |