Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: src/wasm/wasm-interpreter.cc

Issue 2639353002: [wasm] Fix I32ReinterpretF32 and I64ReinterpretF64 on ia32. (Closed)
Patch Set: use memcpy instead of reinterpret_cast Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-interpreter.h ('k') | test/cctest/wasm/test-run-wasm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/wasm-interpreter.h" 5 #include "src/wasm/wasm-interpreter.h"
6 6
7 #include "src/utils.h" 7 #include "src/utils.h"
8 #include "src/wasm/decoder.h" 8 #include "src/wasm/decoder.h"
9 #include "src/wasm/function-body-decoder.h" 9 #include "src/wasm/function-body-decoder.h"
10 #include "src/wasm/wasm-external-refs.h" 10 #include "src/wasm/wasm-external-refs.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 V(F32SConvertI64, int64_t) \ 152 V(F32SConvertI64, int64_t) \
153 V(F32UConvertI64, uint64_t) \ 153 V(F32UConvertI64, uint64_t) \
154 V(F32ConvertF64, double) \ 154 V(F32ConvertF64, double) \
155 V(F32ReinterpretI32, int32_t) \ 155 V(F32ReinterpretI32, int32_t) \
156 V(F64SConvertI32, int32_t) \ 156 V(F64SConvertI32, int32_t) \
157 V(F64UConvertI32, uint32_t) \ 157 V(F64UConvertI32, uint32_t) \
158 V(F64SConvertI64, int64_t) \ 158 V(F64SConvertI64, int64_t) \
159 V(F64UConvertI64, uint64_t) \ 159 V(F64UConvertI64, uint64_t) \
160 V(F64ConvertF32, float) \ 160 V(F64ConvertF32, float) \
161 V(F64ReinterpretI64, int64_t) \ 161 V(F64ReinterpretI64, int64_t) \
162 V(I32ReinterpretF32, float) \
163 V(I64ReinterpretF64, double) \
164 V(I32AsmjsSConvertF32, float) \ 162 V(I32AsmjsSConvertF32, float) \
165 V(I32AsmjsUConvertF32, float) \ 163 V(I32AsmjsUConvertF32, float) \
166 V(I32AsmjsSConvertF64, double) \ 164 V(I32AsmjsSConvertF64, double) \
167 V(I32AsmjsUConvertF64, double) 165 V(I32AsmjsUConvertF64, double)
168 166
169 #define FOREACH_OTHER_UNOP_NAN(V) \ 167 #define FOREACH_OTHER_UNOP_NAN(V) \
170 V(F32Sqrt, float) \ 168 V(F32Sqrt, float) \
171 V(F64Sqrt, double) 169 V(F64Sqrt, double)
172 170
173 static inline int32_t ExecuteI32DivS(int32_t a, int32_t b, TrapReason* trap) { 171 static inline int32_t ExecuteI32DivS(int32_t a, int32_t b, TrapReason* trap) {
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 597 }
600 598
601 static inline double ExecuteF64ConvertF32(float a, TrapReason* trap) { 599 static inline double ExecuteF64ConvertF32(float a, TrapReason* trap) {
602 return static_cast<double>(a); 600 return static_cast<double>(a);
603 } 601 }
604 602
605 static inline double ExecuteF64ReinterpretI64(int64_t a, TrapReason* trap) { 603 static inline double ExecuteF64ReinterpretI64(int64_t a, TrapReason* trap) {
606 return bit_cast<double>(a); 604 return bit_cast<double>(a);
607 } 605 }
608 606
609 static inline int32_t ExecuteI32ReinterpretF32(float a, TrapReason* trap) { 607 static inline int32_t ExecuteI32ReinterpretF32(WasmVal a) {
610 return bit_cast<int32_t>(a); 608 return a.to_unchecked<int32_t>();
611 } 609 }
612 610
613 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) { 611 static inline int64_t ExecuteI64ReinterpretF64(WasmVal a) {
614 return bit_cast<int64_t>(a); 612 return a.to_unchecked<int64_t>();
615 } 613 }
616 614
617 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages, 615 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages,
618 WasmInstance* instance) { 616 WasmInstance* instance) {
619 // TODO(ahaas): Move memory allocation to wasm-module.cc for better 617 // TODO(ahaas): Move memory allocation to wasm-module.cc for better
620 // encapsulation. 618 // encapsulation.
621 if (delta_pages > wasm::kV8MaxWasmMemoryPages || 619 if (delta_pages > wasm::kV8MaxWasmMemoryPages ||
622 delta_pages > instance->module->max_mem_pages) { 620 delta_pages > instance->module->max_mem_pages) {
623 return -1; 621 return -1;
624 } 622 }
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 len = 1 + operand.length; 1539 len = 1 + operand.length;
1542 break; 1540 break;
1543 } 1541 }
1544 case kExprMemorySize: { 1542 case kExprMemorySize: {
1545 MemoryIndexOperand operand(&decoder, code->at(pc)); 1543 MemoryIndexOperand operand(&decoder, code->at(pc));
1546 Push(pc, WasmVal(static_cast<uint32_t>(instance()->mem_size / 1544 Push(pc, WasmVal(static_cast<uint32_t>(instance()->mem_size /
1547 WasmModule::kPageSize))); 1545 WasmModule::kPageSize)));
1548 len = 1 + operand.length; 1546 len = 1 + operand.length;
1549 break; 1547 break;
1550 } 1548 }
1549 // We need to treat kExprI32ReinterpretF32 and kExprI64ReinterpretF64
1550 // specially to guarantee that the quiet bit of a NaN is preserved on
1551 // ia32 by the reinterpret casts.
1552 case kExprI32ReinterpretF32: {
1553 WasmVal result(ExecuteI32ReinterpretF32(Pop()));
1554 Push(pc, result);
1555 break;
1556 }
1557 case kExprI64ReinterpretF64: {
1558 WasmVal result(ExecuteI64ReinterpretF64(Pop()));
1559 Push(pc, result);
1560 break;
1561 }
1551 #define EXECUTE_SIMPLE_BINOP(name, ctype, op) \ 1562 #define EXECUTE_SIMPLE_BINOP(name, ctype, op) \
1552 case kExpr##name: { \ 1563 case kExpr##name: { \
1553 WasmVal rval = Pop(); \ 1564 WasmVal rval = Pop(); \
1554 WasmVal lval = Pop(); \ 1565 WasmVal lval = Pop(); \
1555 WasmVal result(lval.to<ctype>() op rval.to<ctype>()); \ 1566 WasmVal result(lval.to<ctype>() op rval.to<ctype>()); \
1556 Push(pc, result); \ 1567 Push(pc, result); \
1557 break; \ 1568 break; \
1558 } 1569 }
1559 FOREACH_SIMPLE_BINOP(EXECUTE_SIMPLE_BINOP) 1570 FOREACH_SIMPLE_BINOP(EXECUTE_SIMPLE_BINOP)
1560 #undef EXECUTE_SIMPLE_BINOP 1571 #undef EXECUTE_SIMPLE_BINOP
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 1892
1882 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( 1893 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
1883 Zone* zone, const byte* start, const byte* end) { 1894 Zone* zone, const byte* start, const byte* end) {
1884 ControlTransfers targets(zone, nullptr, start, end); 1895 ControlTransfers targets(zone, nullptr, start, end);
1885 return targets.map_; 1896 return targets.map_;
1886 } 1897 }
1887 1898
1888 } // namespace wasm 1899 } // namespace wasm
1889 } // namespace internal 1900 } // namespace internal
1890 } // namespace v8 1901 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-interpreter.h ('k') | test/cctest/wasm/test-run-wasm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698