summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-objdump.cc16
-rw-r--r--src/config.h.in31
-rw-r--r--src/interpreter.cc4
-rw-r--r--src/tools/wasm-interp.cc15
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;
}