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/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 op = m->Word32And(); | 405 op = m->Word32And(); |
406 break; | 406 break; |
407 case wasm::kExprI32Ior: | 407 case wasm::kExprI32Ior: |
408 op = m->Word32Or(); | 408 op = m->Word32Or(); |
409 break; | 409 break; |
410 case wasm::kExprI32Xor: | 410 case wasm::kExprI32Xor: |
411 op = m->Word32Xor(); | 411 op = m->Word32Xor(); |
412 break; | 412 break; |
413 case wasm::kExprI32Shl: | 413 case wasm::kExprI32Shl: |
414 op = m->Word32Shl(); | 414 op = m->Word32Shl(); |
| 415 right = MaskShiftCount32(right); |
415 break; | 416 break; |
416 case wasm::kExprI32ShrU: | 417 case wasm::kExprI32ShrU: |
417 op = m->Word32Shr(); | 418 op = m->Word32Shr(); |
| 419 right = MaskShiftCount32(right); |
418 break; | 420 break; |
419 case wasm::kExprI32ShrS: | 421 case wasm::kExprI32ShrS: |
420 op = m->Word32Sar(); | 422 op = m->Word32Sar(); |
| 423 right = MaskShiftCount32(right); |
421 break; | 424 break; |
422 case wasm::kExprI32Ror: | 425 case wasm::kExprI32Ror: |
423 op = m->Word32Ror(); | 426 op = m->Word32Ror(); |
| 427 right = MaskShiftCount32(right); |
424 break; | 428 break; |
425 case wasm::kExprI32Rol: | 429 case wasm::kExprI32Rol: |
| 430 right = MaskShiftCount32(right); |
426 return BuildI32Rol(left, right); | 431 return BuildI32Rol(left, right); |
427 case wasm::kExprI32Eq: | 432 case wasm::kExprI32Eq: |
428 op = m->Word32Equal(); | 433 op = m->Word32Equal(); |
429 break; | 434 break; |
430 case wasm::kExprI32Ne: | 435 case wasm::kExprI32Ne: |
431 return Invert(Binop(wasm::kExprI32Eq, left, right)); | 436 return Invert(Binop(wasm::kExprI32Eq, left, right)); |
432 case wasm::kExprI32LtS: | 437 case wasm::kExprI32LtS: |
433 op = m->Int32LessThan(); | 438 op = m->Int32LessThan(); |
434 break; | 439 break; |
435 case wasm::kExprI32LeS: | 440 case wasm::kExprI32LeS: |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 case wasm::kExprI64Ior: | 494 case wasm::kExprI64Ior: |
490 op = m->Word64Or(); | 495 op = m->Word64Or(); |
491 break; | 496 break; |
492 // kExprI64Xor: | 497 // kExprI64Xor: |
493 case wasm::kExprI64Xor: | 498 case wasm::kExprI64Xor: |
494 op = m->Word64Xor(); | 499 op = m->Word64Xor(); |
495 break; | 500 break; |
496 // kExprI64Shl: | 501 // kExprI64Shl: |
497 case wasm::kExprI64Shl: | 502 case wasm::kExprI64Shl: |
498 op = m->Word64Shl(); | 503 op = m->Word64Shl(); |
| 504 right = MaskShiftCount64(right); |
499 break; | 505 break; |
500 // kExprI64ShrU: | 506 // kExprI64ShrU: |
501 case wasm::kExprI64ShrU: | 507 case wasm::kExprI64ShrU: |
502 op = m->Word64Shr(); | 508 op = m->Word64Shr(); |
| 509 right = MaskShiftCount64(right); |
503 break; | 510 break; |
504 // kExprI64ShrS: | 511 // kExprI64ShrS: |
505 case wasm::kExprI64ShrS: | 512 case wasm::kExprI64ShrS: |
506 op = m->Word64Sar(); | 513 op = m->Word64Sar(); |
| 514 right = MaskShiftCount64(right); |
507 break; | 515 break; |
508 // kExprI64Eq: | 516 // kExprI64Eq: |
509 case wasm::kExprI64Eq: | 517 case wasm::kExprI64Eq: |
510 op = m->Word64Equal(); | 518 op = m->Word64Equal(); |
511 break; | 519 break; |
512 // kExprI64Ne: | 520 // kExprI64Ne: |
513 case wasm::kExprI64Ne: | 521 case wasm::kExprI64Ne: |
514 return Invert(Binop(wasm::kExprI64Eq, left, right)); | 522 return Invert(Binop(wasm::kExprI64Eq, left, right)); |
515 // kExprI64LtS: | 523 // kExprI64LtS: |
516 case wasm::kExprI64LtS: | 524 case wasm::kExprI64LtS: |
(...skipping 23 matching lines...) Expand all Loading... |
540 case wasm::kExprI64GeU: | 548 case wasm::kExprI64GeU: |
541 op = m->Uint64LessThanOrEqual(); | 549 op = m->Uint64LessThanOrEqual(); |
542 std::swap(left, right); | 550 std::swap(left, right); |
543 break; | 551 break; |
544 | 552 |
545 #if WASM_64 | 553 #if WASM_64 |
546 // Opcodes only supported on 64-bit platforms. | 554 // Opcodes only supported on 64-bit platforms. |
547 // TODO(titzer): query the machine operator builder here instead of #ifdef. | 555 // TODO(titzer): query the machine operator builder here instead of #ifdef. |
548 case wasm::kExprI64Ror: | 556 case wasm::kExprI64Ror: |
549 op = m->Word64Ror(); | 557 op = m->Word64Ror(); |
| 558 right = MaskShiftCount64(right); |
550 break; | 559 break; |
551 case wasm::kExprI64Rol: | 560 case wasm::kExprI64Rol: |
| 561 right = MaskShiftCount64(right); |
552 return BuildI64Rol(left, right); | 562 return BuildI64Rol(left, right); |
553 #endif | 563 #endif |
554 | 564 |
555 case wasm::kExprF32CopySign: | 565 case wasm::kExprF32CopySign: |
556 return BuildF32CopySign(left, right); | 566 return BuildF32CopySign(left, right); |
557 case wasm::kExprF64CopySign: | 567 case wasm::kExprF64CopySign: |
558 return BuildF64CopySign(left, right); | 568 return BuildF64CopySign(left, right); |
559 case wasm::kExprF32Add: | 569 case wasm::kExprF32Add: |
560 op = m->Float32Add(); | 570 op = m->Float32Add(); |
561 break; | 571 break; |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 | 966 |
957 | 967 |
958 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } | 968 Node* WasmGraphBuilder::ReturnVoid() { return Return(0, Buffer(0)); } |
959 | 969 |
960 | 970 |
961 Node* WasmGraphBuilder::Unreachable() { | 971 Node* WasmGraphBuilder::Unreachable() { |
962 trap_->Unreachable(); | 972 trap_->Unreachable(); |
963 return nullptr; | 973 return nullptr; |
964 } | 974 } |
965 | 975 |
| 976 Node* WasmGraphBuilder::MaskShiftCount32(Node* node) { |
| 977 static const int32_t kMask32 = 0x1f; |
| 978 if (!jsgraph()->machine()->Word32ShiftIsSafe()) { |
| 979 // Shifts by constants are so common we pattern-match them here. |
| 980 Int32Matcher match(node); |
| 981 if (match.HasValue()) { |
| 982 int32_t masked = (match.Value() & kMask32); |
| 983 if (match.Value() != masked) node = jsgraph()->Int32Constant(masked); |
| 984 } else { |
| 985 node = graph()->NewNode(jsgraph()->machine()->Word32And(), node, |
| 986 jsgraph()->Int32Constant(kMask32)); |
| 987 } |
| 988 } |
| 989 return node; |
| 990 } |
| 991 |
| 992 Node* WasmGraphBuilder::MaskShiftCount64(Node* node) { |
| 993 static const int64_t kMask64 = 0x3f; |
| 994 if (!jsgraph()->machine()->Word32ShiftIsSafe()) { |
| 995 // Shifts by constants are so common we pattern-match them here. |
| 996 Int64Matcher match(node); |
| 997 if (match.HasValue()) { |
| 998 int64_t masked = (match.Value() & kMask64); |
| 999 if (match.Value() != masked) node = jsgraph()->Int64Constant(masked); |
| 1000 } else { |
| 1001 node = graph()->NewNode(jsgraph()->machine()->Word64And(), node, |
| 1002 jsgraph()->Int64Constant(kMask64)); |
| 1003 } |
| 1004 } |
| 1005 return node; |
| 1006 } |
966 | 1007 |
967 Node* WasmGraphBuilder::BuildF32Neg(Node* input) { | 1008 Node* WasmGraphBuilder::BuildF32Neg(Node* input) { |
968 Node* result = | 1009 Node* result = |
969 Unop(wasm::kExprF32ReinterpretI32, | 1010 Unop(wasm::kExprF32ReinterpretI32, |
970 Binop(wasm::kExprI32Xor, Unop(wasm::kExprI32ReinterpretF32, input), | 1011 Binop(wasm::kExprI32Xor, Unop(wasm::kExprI32ReinterpretF32, input), |
971 jsgraph()->Int32Constant(0x80000000))); | 1012 jsgraph()->Int32Constant(0x80000000))); |
972 | 1013 |
973 return result; | 1014 return result; |
974 } | 1015 } |
975 | 1016 |
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2763 static_cast<int>(function.code_end_offset - function.code_start_offset), | 2804 static_cast<int>(function.code_end_offset - function.code_start_offset), |
2764 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); | 2805 decode_ms, static_cast<int>(graph.NodeCount()), compile_ms); |
2765 } | 2806 } |
2766 return code; | 2807 return code; |
2767 } | 2808 } |
2768 | 2809 |
2769 | 2810 |
2770 } // namespace compiler | 2811 } // namespace compiler |
2771 } // namespace internal | 2812 } // namespace internal |
2772 } // namespace v8 | 2813 } // namespace v8 |
OLD | NEW |