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 #include "src/wasm/ast-decoder.h" | 6 #include "src/wasm/ast-decoder.h" |
7 #include "src/wasm/decoder.h" | 7 #include "src/wasm/decoder.h" |
8 #include "src/wasm/wasm-external-refs.h" | 8 #include "src/wasm/wasm-external-refs.h" |
9 #include "src/wasm/wasm-module.h" | 9 #include "src/wasm/wasm-module.h" |
10 | 10 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 491 |
492 static inline double ExecuteF64NearestInt(double a, TrapReason* trap) { | 492 static inline double ExecuteF64NearestInt(double a, TrapReason* trap) { |
493 return nearbyint(a); | 493 return nearbyint(a); |
494 } | 494 } |
495 | 495 |
496 static inline double ExecuteF64Sqrt(double a, TrapReason* trap) { | 496 static inline double ExecuteF64Sqrt(double a, TrapReason* trap) { |
497 return sqrt(a); | 497 return sqrt(a); |
498 } | 498 } |
499 | 499 |
500 static int32_t ExecuteI32SConvertF32(float a, TrapReason* trap) { | 500 static int32_t ExecuteI32SConvertF32(float a, TrapReason* trap) { |
501 if (a < static_cast<float>(INT32_MAX) && a >= static_cast<float>(INT32_MIN)) { | 501 // The upper bound is (INT32_MAX + 1), which is the lowest float-representable |
| 502 // number above INT32_MAX which cannot be represented as int32. |
| 503 float upper_bound = 2147483648.0f; |
| 504 // We use INT32_MIN as a lower bound because (INT32_MIN - 1) is not |
| 505 // representable as float, and no number between (INT32_MIN - 1) and INT32_MIN |
| 506 // is. |
| 507 float lower_bound = static_cast<float>(INT32_MIN); |
| 508 if (a < upper_bound && a >= lower_bound) { |
502 return static_cast<int32_t>(a); | 509 return static_cast<int32_t>(a); |
503 } | 510 } |
504 *trap = kTrapFloatUnrepresentable; | 511 *trap = kTrapFloatUnrepresentable; |
505 return 0; | 512 return 0; |
506 } | 513 } |
507 | 514 |
508 static int32_t ExecuteI32SConvertF64(double a, TrapReason* trap) { | 515 static int32_t ExecuteI32SConvertF64(double a, TrapReason* trap) { |
509 if (a < (static_cast<double>(INT32_MAX) + 1.0) && | 516 // The upper bound is (INT32_MAX + 1), which is the lowest double- |
510 a > (static_cast<double>(INT32_MIN) - 1.0)) { | 517 // representable number above INT32_MAX which cannot be represented as int32. |
| 518 double upper_bound = 2147483648.0; |
| 519 // The lower bound is (INT32_MIN - 1), which is the greatest double- |
| 520 // representable number below INT32_MIN which cannot be represented as int32. |
| 521 double lower_bound = -2147483649.0; |
| 522 if (a < upper_bound && a > lower_bound) { |
511 return static_cast<int32_t>(a); | 523 return static_cast<int32_t>(a); |
512 } | 524 } |
513 *trap = kTrapFloatUnrepresentable; | 525 *trap = kTrapFloatUnrepresentable; |
514 return 0; | 526 return 0; |
515 } | 527 } |
516 | 528 |
517 static uint32_t ExecuteI32UConvertF32(float a, TrapReason* trap) { | 529 static uint32_t ExecuteI32UConvertF32(float a, TrapReason* trap) { |
518 if (a < (static_cast<float>(UINT32_MAX) + 1.0) && a > -1) { | 530 // The upper bound is (UINT32_MAX + 1), which is the lowest |
| 531 // float-representable number above UINT32_MAX which cannot be represented as |
| 532 // uint32. |
| 533 double upper_bound = 4294967296.0f; |
| 534 double lower_bound = -1.0f; |
| 535 if (a < upper_bound && a > lower_bound) { |
519 return static_cast<uint32_t>(a); | 536 return static_cast<uint32_t>(a); |
520 } | 537 } |
521 *trap = kTrapFloatUnrepresentable; | 538 *trap = kTrapFloatUnrepresentable; |
522 return 0; | 539 return 0; |
523 } | 540 } |
524 | 541 |
525 static uint32_t ExecuteI32UConvertF64(double a, TrapReason* trap) { | 542 static uint32_t ExecuteI32UConvertF64(double a, TrapReason* trap) { |
526 if (a < (static_cast<float>(UINT32_MAX) + 1.0) && a > -1) { | 543 // The upper bound is (UINT32_MAX + 1), which is the lowest |
| 544 // double-representable number above UINT32_MAX which cannot be represented as |
| 545 // uint32. |
| 546 double upper_bound = 4294967296.0; |
| 547 double lower_bound = -1.0; |
| 548 if (a < upper_bound && a > lower_bound) { |
527 return static_cast<uint32_t>(a); | 549 return static_cast<uint32_t>(a); |
528 } | 550 } |
529 *trap = kTrapFloatUnrepresentable; | 551 *trap = kTrapFloatUnrepresentable; |
530 return 0; | 552 return 0; |
531 } | 553 } |
532 | 554 |
533 static inline uint32_t ExecuteI32ConvertI64(int64_t a, TrapReason* trap) { | 555 static inline uint32_t ExecuteI32ConvertI64(int64_t a, TrapReason* trap) { |
534 return static_cast<uint32_t>(a & 0xFFFFFFFF); | 556 return static_cast<uint32_t>(a & 0xFFFFFFFF); |
535 } | 557 } |
536 | 558 |
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 | 1843 |
1822 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1844 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1823 Zone* zone, const byte* start, const byte* end) { | 1845 Zone* zone, const byte* start, const byte* end) { |
1824 ControlTransfers targets(zone, 0, start, end); | 1846 ControlTransfers targets(zone, 0, start, end); |
1825 return targets.map_; | 1847 return targets.map_; |
1826 } | 1848 } |
1827 | 1849 |
1828 } // namespace wasm | 1850 } // namespace wasm |
1829 } // namespace internal | 1851 } // namespace internal |
1830 } // namespace v8 | 1852 } // namespace v8 |
OLD | NEW |