From 32490684ab0fa568d4e539c24f7c560295da57de Mon Sep 17 00:00:00 2001 From: Andrew Scheidecker Date: Wed, 23 Dec 2015 09:09:49 -0800 Subject: Fix a few Windows/VS2013 compile errors --- src/wasm-interpreter.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/wasm-interpreter.h') 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 + +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()); -- cgit v1.2.3 From 65f8f24c7bb1da884eb74d5fd742fcf35526483c Mon Sep 17 00:00:00 2001 From: Andrew Scheidecker Date: Wed, 23 Dec 2015 10:17:50 -0800 Subject: Implement feedback --- src/wasm-interpreter.h | 6 ++---- src/wasm-validator.h | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 3db818787..76c3f66ba 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -49,8 +49,7 @@ int32_t safe_ctz(int32_t v) { return _BitScanForward(&result,v) ? result : 32; } -int32_t platform_popcount(int32_t v) -{ +int32_t platform_popcount(int32_t v) { return __popcnt(v); } #else @@ -64,8 +63,7 @@ int32_t safe_ctz(int32_t v) { return __builtin_ctz(v); } -int32_t platform_popcount(int32_t v) -{ +int32_t platform_popcount(int32_t v) { return __buildin_popcount(v); } #endif diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 46bcf7a2e..f0e73fb85 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -39,7 +39,7 @@ public: void visitLoop(Loop *curr) override { if (curr->in.is()) { - ChildChecker childChecker(curr->in); + LoopChildChecker childChecker(curr->in); childChecker.walk(curr->body); shouldBeTrue(childChecker.valid); } @@ -98,11 +98,11 @@ public: private: // the "in" label has a none type, since no one can receive its value. make sure no one breaks to it with a value. - struct ChildChecker : public WasmWalker { + struct LoopChildChecker : public WasmWalker { Name in; bool valid = true; - ChildChecker(Name in) : in(in) {} + LoopChildChecker(Name in) : in(in) {} void visitBreak(Break *curr) override { if (curr->name == in && curr->value) { -- cgit v1.2.3