OLD | NEW |
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 Loading... |
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) \ |
162 V(I32AsmjsSConvertF32, float) \ | 164 V(I32AsmjsSConvertF32, float) \ |
163 V(I32AsmjsUConvertF32, float) \ | 165 V(I32AsmjsUConvertF32, float) \ |
164 V(I32AsmjsSConvertF64, double) \ | 166 V(I32AsmjsSConvertF64, double) \ |
165 V(I32AsmjsUConvertF64, double) | 167 V(I32AsmjsUConvertF64, double) |
166 | 168 |
167 #define FOREACH_OTHER_UNOP_NAN(V) \ | 169 #define FOREACH_OTHER_UNOP_NAN(V) \ |
168 V(F32Sqrt, float) \ | 170 V(F32Sqrt, float) \ |
169 V(F64Sqrt, double) | 171 V(F64Sqrt, double) |
170 | 172 |
171 static inline int32_t ExecuteI32DivS(int32_t a, int32_t b, TrapReason* trap) { | 173 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 Loading... |
597 } | 599 } |
598 | 600 |
599 static inline double ExecuteF64ConvertF32(float a, TrapReason* trap) { | 601 static inline double ExecuteF64ConvertF32(float a, TrapReason* trap) { |
600 return static_cast<double>(a); | 602 return static_cast<double>(a); |
601 } | 603 } |
602 | 604 |
603 static inline double ExecuteF64ReinterpretI64(int64_t a, TrapReason* trap) { | 605 static inline double ExecuteF64ReinterpretI64(int64_t a, TrapReason* trap) { |
604 return bit_cast<double>(a); | 606 return bit_cast<double>(a); |
605 } | 607 } |
606 | 608 |
607 static inline int32_t ExecuteI32ReinterpretF32(WasmVal a) { | 609 static inline int32_t ExecuteI32ReinterpretF32(float a, TrapReason* trap) { |
608 return a.to_unchecked<int32_t>(); | 610 return bit_cast<int32_t>(a); |
609 } | 611 } |
610 | 612 |
611 static inline int64_t ExecuteI64ReinterpretF64(WasmVal a) { | 613 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) { |
612 return a.to_unchecked<int64_t>(); | 614 return bit_cast<int64_t>(a); |
613 } | 615 } |
614 | 616 |
615 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages, | 617 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages, |
616 WasmInstance* instance) { | 618 WasmInstance* instance) { |
617 // TODO(ahaas): Move memory allocation to wasm-module.cc for better | 619 // TODO(ahaas): Move memory allocation to wasm-module.cc for better |
618 // encapsulation. | 620 // encapsulation. |
619 if (delta_pages > wasm::kV8MaxWasmMemoryPages || | 621 if (delta_pages > wasm::kV8MaxWasmMemoryPages || |
620 delta_pages > instance->module->max_mem_pages) { | 622 delta_pages > instance->module->max_mem_pages) { |
621 return -1; | 623 return -1; |
622 } | 624 } |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 len = 1 + operand.length; | 1541 len = 1 + operand.length; |
1540 break; | 1542 break; |
1541 } | 1543 } |
1542 case kExprMemorySize: { | 1544 case kExprMemorySize: { |
1543 MemoryIndexOperand operand(&decoder, code->at(pc)); | 1545 MemoryIndexOperand operand(&decoder, code->at(pc)); |
1544 Push(pc, WasmVal(static_cast<uint32_t>(instance()->mem_size / | 1546 Push(pc, WasmVal(static_cast<uint32_t>(instance()->mem_size / |
1545 WasmModule::kPageSize))); | 1547 WasmModule::kPageSize))); |
1546 len = 1 + operand.length; | 1548 len = 1 + operand.length; |
1547 break; | 1549 break; |
1548 } | 1550 } |
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 } | |
1562 #define EXECUTE_SIMPLE_BINOP(name, ctype, op) \ | 1551 #define EXECUTE_SIMPLE_BINOP(name, ctype, op) \ |
1563 case kExpr##name: { \ | 1552 case kExpr##name: { \ |
1564 WasmVal rval = Pop(); \ | 1553 WasmVal rval = Pop(); \ |
1565 WasmVal lval = Pop(); \ | 1554 WasmVal lval = Pop(); \ |
1566 WasmVal result(lval.to<ctype>() op rval.to<ctype>()); \ | 1555 WasmVal result(lval.to<ctype>() op rval.to<ctype>()); \ |
1567 Push(pc, result); \ | 1556 Push(pc, result); \ |
1568 break; \ | 1557 break; \ |
1569 } | 1558 } |
1570 FOREACH_SIMPLE_BINOP(EXECUTE_SIMPLE_BINOP) | 1559 FOREACH_SIMPLE_BINOP(EXECUTE_SIMPLE_BINOP) |
1571 #undef EXECUTE_SIMPLE_BINOP | 1560 #undef EXECUTE_SIMPLE_BINOP |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 | 1881 |
1893 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1882 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1894 Zone* zone, const byte* start, const byte* end) { | 1883 Zone* zone, const byte* start, const byte* end) { |
1895 ControlTransfers targets(zone, nullptr, start, end); | 1884 ControlTransfers targets(zone, nullptr, start, end); |
1896 return targets.map_; | 1885 return targets.map_; |
1897 } | 1886 } |
1898 | 1887 |
1899 } // namespace wasm | 1888 } // namespace wasm |
1900 } // namespace internal | 1889 } // namespace internal |
1901 } // namespace v8 | 1890 } // namespace v8 |
OLD | NEW |