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 #ifndef WASM_EXTERNAL_REFS_H | 5 #ifndef WASM_EXTERNAL_REFS_H |
6 #define WASM_EXTERNAL_REFS_H | 6 #define WASM_EXTERNAL_REFS_H |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace wasm { | 10 namespace wasm { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 double result = static_cast<double>(high_word); | 85 double result = static_cast<double>(high_word); |
86 result *= shift; | 86 result *= shift; |
87 result += static_cast<double>(low_word); | 87 result += static_cast<double>(low_word); |
88 *output = result; | 88 *output = result; |
89 | 89 |
90 #else | 90 #else |
91 *output = static_cast<double>(*input); | 91 *output = static_cast<double>(*input); |
92 #endif | 92 #endif |
93 } | 93 } |
94 | 94 |
| 95 static int32_t float32_to_int64_wrapper(float* input, int64_t* output) { |
| 96 // We use "<" here to check the upper bound because of rounding problems: With |
| 97 // "<=" some inputs would be considered within int64 range which are actually |
| 98 // not within int64 range. |
| 99 if (*input >= static_cast<float>(std::numeric_limits<int64_t>::min()) && |
| 100 *input < static_cast<float>(std::numeric_limits<int64_t>::max())) { |
| 101 *output = static_cast<int64_t>(*input); |
| 102 return 1; |
| 103 } |
| 104 return 0; |
| 105 } |
| 106 |
| 107 static int32_t float32_to_uint64_wrapper(float* input, uint64_t* output) { |
| 108 // We use "<" here to check the upper bound because of rounding problems: With |
| 109 // "<=" some inputs would be considered within uint64 range which are actually |
| 110 // not within uint64 range. |
| 111 if (*input > -1.0 && |
| 112 *input < static_cast<float>(std::numeric_limits<uint64_t>::max())) { |
| 113 *output = static_cast<uint64_t>(*input); |
| 114 return 1; |
| 115 } |
| 116 return 0; |
| 117 } |
| 118 |
| 119 static int32_t float64_to_int64_wrapper(double* input, int64_t* output) { |
| 120 // We use "<" here to check the upper bound because of rounding problems: With |
| 121 // "<=" some inputs would be considered within int64 range which are actually |
| 122 // not within int64 range. |
| 123 if (*input >= static_cast<double>(std::numeric_limits<int64_t>::min()) && |
| 124 *input < static_cast<double>(std::numeric_limits<int64_t>::max())) { |
| 125 *output = static_cast<int64_t>(*input); |
| 126 return 1; |
| 127 } |
| 128 return 0; |
| 129 } |
| 130 |
| 131 static int32_t float64_to_uint64_wrapper(double* input, uint64_t* output) { |
| 132 // We use "<" here to check the upper bound because of rounding problems: With |
| 133 // "<=" some inputs would be considered within uint64 range which are actually |
| 134 // not within uint64 range. |
| 135 if (*input > -1.0 && |
| 136 *input < static_cast<double>(std::numeric_limits<uint64_t>::max())) { |
| 137 *output = static_cast<uint64_t>(*input); |
| 138 return 1; |
| 139 } |
| 140 return 0; |
| 141 } |
95 } // namespace wasm | 142 } // namespace wasm |
96 } // namespace internal | 143 } // namespace internal |
97 } // namespace v8 | 144 } // namespace v8 |
98 | 145 |
99 #endif | 146 #endif |
OLD | NEW |