OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
6 | 6 |
7 #include "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
8 | 8 |
9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
10 | 10 |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 op = m->Float32RoundUp().op(); | 749 op = m->Float32RoundUp().op(); |
750 break; | 750 break; |
751 } else { | 751 } else { |
752 op = UnsupportedOpcode(opcode); | 752 op = UnsupportedOpcode(opcode); |
753 break; | 753 break; |
754 } | 754 } |
755 } | 755 } |
756 case wasm::kExprF32Trunc: { | 756 case wasm::kExprF32Trunc: { |
757 if (m->Float32RoundTruncate().IsSupported()) { | 757 if (m->Float32RoundTruncate().IsSupported()) { |
758 op = m->Float32RoundTruncate().op(); | 758 op = m->Float32RoundTruncate().op(); |
759 break; | |
760 } else { | 759 } else { |
761 op = UnsupportedOpcode(opcode); | 760 return BuildF32Trunc(input); |
762 break; | |
763 } | 761 } |
| 762 break; |
764 } | 763 } |
765 case wasm::kExprF32NearestInt: { | 764 case wasm::kExprF32NearestInt: { |
766 if (m->Float32RoundTiesEven().IsSupported()) { | 765 if (m->Float32RoundTiesEven().IsSupported()) { |
767 op = m->Float32RoundTiesEven().op(); | 766 op = m->Float32RoundTiesEven().op(); |
768 break; | 767 break; |
769 } else { | 768 } else { |
770 op = UnsupportedOpcode(opcode); | 769 op = UnsupportedOpcode(opcode); |
771 break; | 770 break; |
772 } | 771 } |
773 } | 772 } |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 Binop(wasm::kExprI64And, Binop(wasm::kExprI64ShrU, result, | 1357 Binop(wasm::kExprI64And, Binop(wasm::kExprI64ShrU, result, |
1359 jsgraph()->Int64Constant(32)), | 1358 jsgraph()->Int64Constant(32)), |
1360 jsgraph()->Int64Constant(0x00000000ffffffff)), | 1359 jsgraph()->Int64Constant(0x00000000ffffffff)), |
1361 Binop(wasm::kExprI64And, result, | 1360 Binop(wasm::kExprI64And, result, |
1362 jsgraph()->Int64Constant(0x00000000ffffffff))); | 1361 jsgraph()->Int64Constant(0x00000000ffffffff))); |
1363 | 1362 |
1364 return result; | 1363 return result; |
1365 } | 1364 } |
1366 | 1365 |
1367 | 1366 |
| 1367 Node* WasmGraphBuilder::BuildF32Trunc(Node* input) { |
| 1368 // int32_t int_input = bitftoi(input); |
| 1369 // int32_t exponent = int_input & 0x7f800000; |
| 1370 // if (exponent >= ((23 + 127) << 23)) { |
| 1371 // if (input != input) { |
| 1372 // return bititof(int_input | (1 << 22)); |
| 1373 // } |
| 1374 // return input; |
| 1375 // } |
| 1376 // int32_t sign = int_input & 0x80000000; |
| 1377 // if (exponent < (127 << 23)) { |
| 1378 // return bititof(sign); |
| 1379 // } |
| 1380 // int32_t mantissa = int_input & 0x007fffff; |
| 1381 // int32_t shift = (127 + 23) - (exponent >> 23); |
| 1382 // int32_t new_mantissa = (mantissa >> shift) << shift; |
| 1383 // int32_t result = new_mantissa | exponent | sign; |
| 1384 // return bititof(result); |
| 1385 |
| 1386 Node* int_input = Unop(wasm::kExprI32ReinterpretF32, input); |
| 1387 Node* exponent = |
| 1388 Binop(wasm::kExprI32And, int_input, jsgraph()->Int32Constant(0x7f800000)); |
| 1389 |
| 1390 Node* sign = |
| 1391 Binop(wasm::kExprI32And, int_input, jsgraph()->Int32Constant(0x80000000)); |
| 1392 |
| 1393 Node* result_out_of_range = int_input; |
| 1394 |
| 1395 Node* result_nan = |
| 1396 Binop(wasm::kExprI32Ior, int_input, jsgraph()->Int32Constant(1 << 22)); |
| 1397 |
| 1398 Node* result_zero = sign; |
| 1399 |
| 1400 Node* mantissa = |
| 1401 Binop(wasm::kExprI32And, int_input, jsgraph()->Int32Constant(0x007fffff)); |
| 1402 Node* shift = |
| 1403 Binop(wasm::kExprI32Sub, jsgraph()->Int32Constant(23 + 127), |
| 1404 Binop(wasm::kExprI32ShrU, exponent, jsgraph()->Int32Constant(23))); |
| 1405 Node* new_mantissa = Binop(wasm::kExprI32Shl, |
| 1406 Binop(wasm::kExprI32ShrU, mantissa, shift), shift); |
| 1407 Node* result_truncate = |
| 1408 Binop(wasm::kExprI32Ior, Binop(wasm::kExprI32Ior, new_mantissa, exponent), |
| 1409 sign); |
| 1410 |
| 1411 Diamond is_zero( |
| 1412 graph(), jsgraph()->common(), |
| 1413 Binop(wasm::kExprI32LtU, exponent, jsgraph()->Int32Constant(127 << 23))); |
| 1414 |
| 1415 Node* result_within_range = |
| 1416 is_zero.Phi(wasm::kAstI32, result_zero, result_truncate); |
| 1417 |
| 1418 Diamond input_nan(graph(), jsgraph()->common(), |
| 1419 Binop(wasm::kExprF32Ne, input, input)); |
| 1420 Node* result_exponent_geq_23 = |
| 1421 input_nan.Phi(wasm::kAstI32, result_nan, result_out_of_range); |
| 1422 |
| 1423 Diamond exponent_geq_23(graph(), jsgraph()->common(), |
| 1424 Binop(wasm::kExprI32GeU, exponent, |
| 1425 jsgraph()->Int32Constant((23 + 127) << 23))); |
| 1426 |
| 1427 Node* result = exponent_geq_23.Phi(wasm::kAstI32, result_exponent_geq_23, |
| 1428 result_within_range); |
| 1429 |
| 1430 return Unop(wasm::kExprF32ReinterpretI32, result); |
| 1431 } |
| 1432 |
| 1433 |
1368 Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args) { | 1434 Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args) { |
1369 const size_t params = sig->parameter_count(); | 1435 const size_t params = sig->parameter_count(); |
1370 const size_t extra = 2; // effect and control inputs. | 1436 const size_t extra = 2; // effect and control inputs. |
1371 const size_t count = 1 + params + extra; | 1437 const size_t count = 1 + params + extra; |
1372 | 1438 |
1373 // Reallocate the buffer to make space for extra inputs. | 1439 // Reallocate the buffer to make space for extra inputs. |
1374 args = Realloc(args, count); | 1440 args = Realloc(args, count); |
1375 | 1441 |
1376 // Add effect and control inputs. | 1442 // Add effect and control inputs. |
1377 args[params + 1] = *effect_; | 1443 args[params + 1] = *effect_; |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 code->Disassemble(buffer.start(), os); | 2092 code->Disassemble(buffer.start(), os); |
2027 } | 2093 } |
2028 #endif | 2094 #endif |
2029 return code; | 2095 return code; |
2030 } | 2096 } |
2031 | 2097 |
2032 | 2098 |
2033 } // namespace compiler | 2099 } // namespace compiler |
2034 } // namespace internal | 2100 } // namespace internal |
2035 } // namespace v8 | 2101 } // namespace v8 |
OLD | NEW |