diff options
author | Ben Smith <binjimin@gmail.com> | 2017-04-04 17:09:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-04 17:09:16 -0700 |
commit | f0045ae5f5e8f842a44af179c0575388adf570e7 (patch) | |
tree | 2667ab98c098e3e53a84157e93f0a213c31ba1c7 /src | |
parent | fa6a4e0c6cbf253fa6dab9b8da59312d7e7e6b3f (diff) | |
download | wabt-f0045ae5f5e8f842a44af179c0575388adf570e7.tar.gz wabt-f0045ae5f5e8f842a44af179c0575388adf570e7.tar.bz2 wabt-f0045ae5f5e8f842a44af179c0575388adf570e7.zip |
Run tests on AppVeyor (#385)
Fixes issue #326.
* Install target installs all executables; this is required because we don't
actually know where MSVC builds its targets to
* Use absolute paths when running all executables
* Set `PYTHONPATH` to test directory; for some reason the Windows `sys.path`
doesn't include the current script's directory
* In `wasmdump`, strip the directory up to the last slash or backslash
* In `wasm-interp`, Use round-to-nearest-ties-to-even when converting from
uint64 to float or double
* Check for backslash or slash in `get_dirname` in `wasm-interp`, when looking
for modules alongside the JSON file
* print floats in `wasm-interp` using `%f` not `%g`, since MSVC prints using 3
digits for exponent instead of 2
* In `run-wasm-link.py`, remove file before renaming on top of it
Diffstat (limited to 'src')
-rw-r--r-- | src/binary-reader-objdump.cc | 16 | ||||
-rw-r--r-- | src/config.h.in | 31 | ||||
-rw-r--r-- | src/interpreter.cc | 4 | ||||
-rw-r--r-- | src/tools/wasm-interp.cc | 15 |
4 files changed, 55 insertions, 11 deletions
diff --git a/src/binary-reader-objdump.cc b/src/binary-reader-objdump.cc index c6698289..3e117728 100644 --- a/src/binary-reader-objdump.cc +++ b/src/binary-reader-objdump.cc @@ -21,6 +21,7 @@ #include <string.h> #include <stdio.h> +#include <algorithm> #include <vector> #include "binary-reader-nop.h" @@ -327,11 +328,18 @@ Result BinaryReaderObjdump::OnCount(uint32_t count) { Result BinaryReaderObjdump::BeginModule(uint32_t version) { if (options->print_header) { - const char* basename = strrchr(options->infile, '/'); - if (basename) - basename++; - else + const char* last_slash = strrchr(options->infile, '/'); + const char* last_backslash = strrchr(options->infile, '\\'); + const char* basename; + if (last_slash && last_backslash) { + basename = std::max(last_slash, last_backslash) + 1; + } else if (last_slash) { + basename = last_slash + 1; + } else if (last_backslash) { + basename = last_backslash + 1; + } else { basename = options->infile; + } printf("%s:\tfile format wasm %#08x\n", basename, version); header_printed = true; } diff --git a/src/config.h.in b/src/config.h.in index 453e7985..052aae88 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -265,4 +265,35 @@ typedef int ssize_t; #endif #endif +#if COMPILER_IS_MSVC && defined(_M_X64) +// MSVC on x64 generates uint64 -> float conversions but doesn't do +// round-to-nearest-ties-to-even, which is required by WebAssembly. +#include <emmintrin.h> +__inline double wabt_convert_uint64_to_double(unsigned __int64 x) { + __m128d result = _mm_setzero_pd(); + if (x & 0x8000000000000000ULL) { + result = _mm_cvtsi64_sd(result, (x >> 1) | (x & 1)); + result = _mm_add_sd(result, result); + } else { + result = _mm_cvtsi64_sd(result, x); + } + return _mm_cvtsd_f64(result); +} + +__inline float wabt_convert_uint64_to_float(unsigned __int64 x) { + __m128 result = _mm_setzero_ps(); + if (x & 0x8000000000000000ULL) { + result = _mm_cvtsi64_ss(result, (x >> 1) | (x & 1)); + result = _mm_add_ss(result, result); + } else { + result = _mm_cvtsi64_ss(result, x); + } + return _mm_cvtss_f32(result); +} + +#else +#define wabt_convert_uint64_to_double(x) static_cast<double>(x) +#define wabt_convert_uint64_to_float(x) static_cast<float>(x) +#endif + #endif /* WABT_CONFIG_H_ */ diff --git a/src/interpreter.cc b/src/interpreter.cc index bb1e6a9c..1e12d4a8 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -1558,7 +1558,7 @@ InterpreterResult run_interpreter(InterpreterThread* thread, case InterpreterOpcode::F32ConvertUI64: { VALUE_TYPE_I64 value = POP_I64(); - PUSH_F32(BITCAST_FROM_F32(static_cast<float>(value))); + PUSH_F32(BITCAST_FROM_F32(wabt_convert_uint64_to_float(value))); break; } @@ -1610,7 +1610,7 @@ InterpreterResult run_interpreter(InterpreterThread* thread, case InterpreterOpcode::F64ConvertUI64: { VALUE_TYPE_I64 value = POP_I64(); - PUSH_F64(BITCAST_FROM_F64(static_cast<double>(value))); + PUSH_F64(BITCAST_FROM_F64(wabt_convert_uint64_to_double(value))); break; } diff --git a/src/tools/wasm-interp.cc b/src/tools/wasm-interp.cc index 924c6b20..643fc3fa 100644 --- a/src/tools/wasm-interp.cc +++ b/src/tools/wasm-interp.cc @@ -19,6 +19,7 @@ #include <stdio.h> #include <stdlib.h> +#include <algorithm> #include <vector> #include "binary-reader.h" @@ -179,19 +180,23 @@ static void parse_options(int argc, char** argv) { } static StringSlice get_dirname(const char* s) { - /* strip everything after and including the last slash, e.g.: + /* strip everything after and including the last slash (or backslash), e.g.: * * s = "foo/bar/baz", => "foo/bar" * s = "/usr/local/include/stdio.h", => "/usr/local/include" * s = "foo.bar", => "" + * s = "some\windows\directory", => "some\windows" */ const char* last_slash = strrchr(s, '/'); - if (last_slash == nullptr) + const char* last_backslash = strrchr(s, '\\'); + if (!last_slash) last_slash = s; + if (!last_backslash) + last_backslash = s; StringSlice result; result.start = s; - result.length = last_slash - s; + result.length = std::max(last_slash, last_backslash) - s; return result; } @@ -213,14 +218,14 @@ static void sprint_typed_value(char* buffer, case Type::F32: { float value; memcpy(&value, &tv->value.f32_bits, sizeof(float)); - snprintf(buffer, size, "f32:%g", value); + snprintf(buffer, size, "f32:%f", value); break; } case Type::F64: { double value; memcpy(&value, &tv->value.f64_bits, sizeof(double)); - snprintf(buffer, size, "f64:%g", value); + snprintf(buffer, size, "f64:%f", value); break; } |