OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/base/bits.h" | 5 #include "src/base/bits.h" |
6 #include "src/compiler/instruction-selector-impl.h" | 6 #include "src/compiler/instruction-selector-impl.h" |
7 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 VisitRRO(this, kMipsSar, node); | 258 VisitRRO(this, kMipsSar, node); |
259 } | 259 } |
260 | 260 |
261 | 261 |
262 void InstructionSelector::VisitWord32Ror(Node* node) { | 262 void InstructionSelector::VisitWord32Ror(Node* node) { |
263 VisitRRO(this, kMipsRor, node); | 263 VisitRRO(this, kMipsRor, node); |
264 } | 264 } |
265 | 265 |
266 | 266 |
267 void InstructionSelector::VisitWord32Clz(Node* node) { | 267 void InstructionSelector::VisitWord32Clz(Node* node) { |
268 MipsOperandGenerator g(this); | 268 VisitRR(this, kMipsClz, node); |
269 Emit(kMipsClz, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0))); | |
270 } | 269 } |
271 | 270 |
272 | 271 |
273 void InstructionSelector::VisitInt32Add(Node* node) { | 272 void InstructionSelector::VisitInt32Add(Node* node) { |
274 MipsOperandGenerator g(this); | 273 MipsOperandGenerator g(this); |
275 | 274 |
276 // TODO(plind): Consider multiply & add optimization from arm port. | 275 // TODO(plind): Consider multiply & add optimization from arm port. |
277 VisitBinop(this, node, kMipsAdd); | 276 VisitBinop(this, node, kMipsAdd); |
278 } | 277 } |
279 | 278 |
(...skipping 26 matching lines...) Expand all Loading... |
306 if (base::bits::IsPowerOfTwo32(value + 1)) { | 305 if (base::bits::IsPowerOfTwo32(value + 1)) { |
307 InstructionOperand temp = g.TempRegister(); | 306 InstructionOperand temp = g.TempRegister(); |
308 Emit(kMipsShl | AddressingModeField::encode(kMode_None), temp, | 307 Emit(kMipsShl | AddressingModeField::encode(kMode_None), temp, |
309 g.UseRegister(m.left().node()), | 308 g.UseRegister(m.left().node()), |
310 g.TempImmediate(WhichPowerOf2(value + 1))); | 309 g.TempImmediate(WhichPowerOf2(value + 1))); |
311 Emit(kMipsSub | AddressingModeField::encode(kMode_None), | 310 Emit(kMipsSub | AddressingModeField::encode(kMode_None), |
312 g.DefineAsRegister(node), temp, g.UseRegister(m.left().node())); | 311 g.DefineAsRegister(node), temp, g.UseRegister(m.left().node())); |
313 return; | 312 return; |
314 } | 313 } |
315 } | 314 } |
316 Emit(kMipsMul, g.DefineAsRegister(node), g.UseRegister(m.left().node()), | 315 VisitRRR(this, kMipsMul, node); |
317 g.UseRegister(m.right().node())); | |
318 } | 316 } |
319 | 317 |
320 | 318 |
321 void InstructionSelector::VisitInt32MulHigh(Node* node) { | 319 void InstructionSelector::VisitInt32MulHigh(Node* node) { |
322 MipsOperandGenerator g(this); | 320 VisitRRR(this, kMipsMulHigh, node); |
323 Emit(kMipsMulHigh, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)), | |
324 g.UseRegister(node->InputAt(1))); | |
325 } | 321 } |
326 | 322 |
327 | 323 |
328 void InstructionSelector::VisitUint32MulHigh(Node* node) { | 324 void InstructionSelector::VisitUint32MulHigh(Node* node) { |
329 MipsOperandGenerator g(this); | 325 MipsOperandGenerator g(this); |
330 Emit(kMipsMulHighU, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)), | 326 Emit(kMipsMulHighU, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0)), |
331 g.UseRegister(node->InputAt(1))); | 327 g.UseRegister(node->InputAt(1))); |
332 } | 328 } |
333 | 329 |
334 | 330 |
(...skipping 23 matching lines...) Expand all Loading... |
358 | 354 |
359 void InstructionSelector::VisitUint32Mod(Node* node) { | 355 void InstructionSelector::VisitUint32Mod(Node* node) { |
360 MipsOperandGenerator g(this); | 356 MipsOperandGenerator g(this); |
361 Int32BinopMatcher m(node); | 357 Int32BinopMatcher m(node); |
362 Emit(kMipsModU, g.DefineAsRegister(node), g.UseRegister(m.left().node()), | 358 Emit(kMipsModU, g.DefineAsRegister(node), g.UseRegister(m.left().node()), |
363 g.UseRegister(m.right().node())); | 359 g.UseRegister(m.right().node())); |
364 } | 360 } |
365 | 361 |
366 | 362 |
367 void InstructionSelector::VisitChangeFloat32ToFloat64(Node* node) { | 363 void InstructionSelector::VisitChangeFloat32ToFloat64(Node* node) { |
368 MipsOperandGenerator g(this); | 364 VisitRR(this, kMipsCvtDS, node); |
369 Emit(kMipsCvtDS, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0))); | |
370 } | 365 } |
371 | 366 |
372 | 367 |
373 void InstructionSelector::VisitChangeInt32ToFloat64(Node* node) { | 368 void InstructionSelector::VisitChangeInt32ToFloat64(Node* node) { |
374 MipsOperandGenerator g(this); | 369 VisitRR(this, kMipsCvtDW, node); |
375 Emit(kMipsCvtDW, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0))); | |
376 } | 370 } |
377 | 371 |
378 | 372 |
379 void InstructionSelector::VisitChangeUint32ToFloat64(Node* node) { | 373 void InstructionSelector::VisitChangeUint32ToFloat64(Node* node) { |
380 MipsOperandGenerator g(this); | 374 VisitRR(this, kMipsCvtDUw, node); |
381 Emit(kMipsCvtDUw, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0))); | |
382 } | 375 } |
383 | 376 |
384 | 377 |
385 void InstructionSelector::VisitChangeFloat64ToInt32(Node* node) { | 378 void InstructionSelector::VisitChangeFloat64ToInt32(Node* node) { |
386 MipsOperandGenerator g(this); | 379 VisitRR(this, kMipsTruncWD, node); |
387 Emit(kMipsTruncWD, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0))); | |
388 } | 380 } |
389 | 381 |
390 | 382 |
391 void InstructionSelector::VisitChangeFloat64ToUint32(Node* node) { | 383 void InstructionSelector::VisitChangeFloat64ToUint32(Node* node) { |
392 MipsOperandGenerator g(this); | 384 VisitRR(this, kMipsTruncUwD, node); |
393 Emit(kMipsTruncUwD, g.DefineAsRegister(node), | |
394 g.UseRegister(node->InputAt(0))); | |
395 } | 385 } |
396 | 386 |
397 | 387 |
398 void InstructionSelector::VisitTruncateFloat64ToFloat32(Node* node) { | 388 void InstructionSelector::VisitTruncateFloat64ToFloat32(Node* node) { |
399 MipsOperandGenerator g(this); | 389 VisitRR(this, kMipsCvtSD, node); |
400 Emit(kMipsCvtSD, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0))); | |
401 } | 390 } |
402 | 391 |
403 | 392 |
| 393 void InstructionSelector::VisitFloat32Add(Node* node) { |
| 394 VisitRRR(this, kMipsAddS, node); |
| 395 } |
| 396 |
| 397 |
404 void InstructionSelector::VisitFloat64Add(Node* node) { | 398 void InstructionSelector::VisitFloat64Add(Node* node) { |
405 VisitRRR(this, kMipsAddD, node); | 399 VisitRRR(this, kMipsAddD, node); |
406 } | 400 } |
407 | 401 |
408 | 402 |
| 403 void InstructionSelector::VisitFloat32Sub(Node* node) { |
| 404 VisitRRR(this, kMipsSubS, node); |
| 405 } |
| 406 |
| 407 |
409 void InstructionSelector::VisitFloat64Sub(Node* node) { | 408 void InstructionSelector::VisitFloat64Sub(Node* node) { |
410 MipsOperandGenerator g(this); | 409 MipsOperandGenerator g(this); |
411 Float64BinopMatcher m(node); | 410 Float64BinopMatcher m(node); |
412 if (m.left().IsMinusZero() && m.right().IsFloat64RoundDown() && | 411 if (m.left().IsMinusZero() && m.right().IsFloat64RoundDown() && |
413 CanCover(m.node(), m.right().node())) { | 412 CanCover(m.node(), m.right().node())) { |
414 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub && | 413 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub && |
415 CanCover(m.right().node(), m.right().InputAt(0))) { | 414 CanCover(m.right().node(), m.right().InputAt(0))) { |
416 Float64BinopMatcher mright0(m.right().InputAt(0)); | 415 Float64BinopMatcher mright0(m.right().InputAt(0)); |
417 if (mright0.left().IsMinusZero()) { | 416 if (mright0.left().IsMinusZero()) { |
418 Emit(kMipsFloat64RoundUp, g.DefineAsRegister(node), | 417 Emit(kMipsFloat64RoundUp, g.DefineAsRegister(node), |
419 g.UseRegister(mright0.right().node())); | 418 g.UseRegister(mright0.right().node())); |
420 return; | 419 return; |
421 } | 420 } |
422 } | 421 } |
423 } | 422 } |
424 VisitRRR(this, kMipsSubD, node); | 423 VisitRRR(this, kMipsSubD, node); |
425 } | 424 } |
426 | 425 |
427 | 426 |
| 427 void InstructionSelector::VisitFloat32Mul(Node* node) { |
| 428 VisitRRR(this, kMipsMulS, node); |
| 429 } |
| 430 |
| 431 |
428 void InstructionSelector::VisitFloat64Mul(Node* node) { | 432 void InstructionSelector::VisitFloat64Mul(Node* node) { |
429 VisitRRR(this, kMipsMulD, node); | 433 VisitRRR(this, kMipsMulD, node); |
430 } | 434 } |
431 | 435 |
432 | 436 |
| 437 void InstructionSelector::VisitFloat32Div(Node* node) { |
| 438 VisitRRR(this, kMipsDivS, node); |
| 439 } |
| 440 |
| 441 |
433 void InstructionSelector::VisitFloat64Div(Node* node) { | 442 void InstructionSelector::VisitFloat64Div(Node* node) { |
434 VisitRRR(this, kMipsDivD, node); | 443 VisitRRR(this, kMipsDivD, node); |
435 } | 444 } |
436 | 445 |
437 | 446 |
438 void InstructionSelector::VisitFloat64Mod(Node* node) { | 447 void InstructionSelector::VisitFloat64Mod(Node* node) { |
439 MipsOperandGenerator g(this); | 448 MipsOperandGenerator g(this); |
440 Emit(kMipsModD, g.DefineAsFixed(node, f0), g.UseFixed(node->InputAt(0), f12), | 449 Emit(kMipsModD, g.DefineAsFixed(node, f0), g.UseFixed(node->InputAt(0), f12), |
441 g.UseFixed(node->InputAt(1), f14))->MarkAsCall(); | 450 g.UseFixed(node->InputAt(1), f14))->MarkAsCall(); |
442 } | 451 } |
443 | 452 |
444 | 453 |
| 454 void InstructionSelector::VisitFloat32Max(Node* node) { UNREACHABLE(); } |
| 455 |
| 456 |
445 void InstructionSelector::VisitFloat64Max(Node* node) { UNREACHABLE(); } | 457 void InstructionSelector::VisitFloat64Max(Node* node) { UNREACHABLE(); } |
446 | 458 |
447 | 459 |
| 460 void InstructionSelector::VisitFloat32Min(Node* node) { UNREACHABLE(); } |
| 461 |
| 462 |
448 void InstructionSelector::VisitFloat64Min(Node* node) { UNREACHABLE(); } | 463 void InstructionSelector::VisitFloat64Min(Node* node) { UNREACHABLE(); } |
449 | 464 |
450 | 465 |
451 void InstructionSelector::VisitFloat64Sqrt(Node* node) { | 466 void InstructionSelector::VisitFloat32Sqrt(Node* node) { |
452 MipsOperandGenerator g(this); | 467 VisitRR(this, kMipsSqrtS, node); |
453 Emit(kMipsSqrtD, g.DefineAsRegister(node), g.UseRegister(node->InputAt(0))); | |
454 } | 468 } |
455 | 469 |
456 | 470 |
| 471 void InstructionSelector::VisitFloat64Sqrt(Node* node) { |
| 472 VisitRR(this, kMipsSqrtD, node); |
| 473 } |
| 474 |
| 475 |
457 void InstructionSelector::VisitFloat64RoundDown(Node* node) { | 476 void InstructionSelector::VisitFloat64RoundDown(Node* node) { |
458 VisitRR(this, kMipsFloat64RoundDown, node); | 477 VisitRR(this, kMipsFloat64RoundDown, node); |
459 } | 478 } |
460 | 479 |
461 | 480 |
462 void InstructionSelector::VisitFloat64RoundTruncate(Node* node) { | 481 void InstructionSelector::VisitFloat64RoundTruncate(Node* node) { |
463 VisitRR(this, kMipsFloat64RoundTruncate, node); | 482 VisitRR(this, kMipsFloat64RoundTruncate, node); |
464 } | 483 } |
465 | 484 |
466 | 485 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 selector->Emit(opcode, g.NoOutput(), left, right, | 648 selector->Emit(opcode, g.NoOutput(), left, right, |
630 g.Label(cont->true_block()), g.Label(cont->false_block())); | 649 g.Label(cont->true_block()), g.Label(cont->false_block())); |
631 } else { | 650 } else { |
632 DCHECK(cont->IsSet()); | 651 DCHECK(cont->IsSet()); |
633 // TODO(plind): Revisit and test this path. | 652 // TODO(plind): Revisit and test this path. |
634 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); | 653 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); |
635 } | 654 } |
636 } | 655 } |
637 | 656 |
638 | 657 |
639 // Shared routine for multiple float compare operations. | 658 // Shared routine for multiple float32 compare operations. |
| 659 void VisitFloat32Compare(InstructionSelector* selector, Node* node, |
| 660 FlagsContinuation* cont) { |
| 661 MipsOperandGenerator g(selector); |
| 662 Node* left = node->InputAt(0); |
| 663 Node* right = node->InputAt(1); |
| 664 VisitCompare(selector, kMipsCmpS, g.UseRegister(left), g.UseRegister(right), |
| 665 cont); |
| 666 } |
| 667 |
| 668 |
| 669 // Shared routine for multiple float64 compare operations. |
640 void VisitFloat64Compare(InstructionSelector* selector, Node* node, | 670 void VisitFloat64Compare(InstructionSelector* selector, Node* node, |
641 FlagsContinuation* cont) { | 671 FlagsContinuation* cont) { |
642 MipsOperandGenerator g(selector); | 672 MipsOperandGenerator g(selector); |
643 Node* left = node->InputAt(0); | 673 Node* left = node->InputAt(0); |
644 Node* right = node->InputAt(1); | 674 Node* right = node->InputAt(1); |
645 VisitCompare(selector, kMipsCmpD, g.UseRegister(left), g.UseRegister(right), | 675 VisitCompare(selector, kMipsCmpD, g.UseRegister(left), g.UseRegister(right), |
646 cont); | 676 cont); |
647 } | 677 } |
648 | 678 |
649 | 679 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 return VisitWordCompare(selector, value, cont); | 731 return VisitWordCompare(selector, value, cont); |
702 case IrOpcode::kInt32LessThanOrEqual: | 732 case IrOpcode::kInt32LessThanOrEqual: |
703 cont->OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); | 733 cont->OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); |
704 return VisitWordCompare(selector, value, cont); | 734 return VisitWordCompare(selector, value, cont); |
705 case IrOpcode::kUint32LessThan: | 735 case IrOpcode::kUint32LessThan: |
706 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan); | 736 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan); |
707 return VisitWordCompare(selector, value, cont); | 737 return VisitWordCompare(selector, value, cont); |
708 case IrOpcode::kUint32LessThanOrEqual: | 738 case IrOpcode::kUint32LessThanOrEqual: |
709 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); | 739 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); |
710 return VisitWordCompare(selector, value, cont); | 740 return VisitWordCompare(selector, value, cont); |
| 741 case IrOpcode::kFloat32Equal: |
| 742 cont->OverwriteAndNegateIfEqual(kEqual); |
| 743 return VisitFloat32Compare(selector, value, cont); |
| 744 case IrOpcode::kFloat32LessThan: |
| 745 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan); |
| 746 return VisitFloat32Compare(selector, value, cont); |
| 747 case IrOpcode::kFloat32LessThanOrEqual: |
| 748 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); |
| 749 return VisitFloat32Compare(selector, value, cont); |
711 case IrOpcode::kFloat64Equal: | 750 case IrOpcode::kFloat64Equal: |
712 cont->OverwriteAndNegateIfEqual(kEqual); | 751 cont->OverwriteAndNegateIfEqual(kEqual); |
713 return VisitFloat64Compare(selector, value, cont); | 752 return VisitFloat64Compare(selector, value, cont); |
714 case IrOpcode::kFloat64LessThan: | 753 case IrOpcode::kFloat64LessThan: |
715 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan); | 754 cont->OverwriteAndNegateIfEqual(kUnsignedLessThan); |
716 return VisitFloat64Compare(selector, value, cont); | 755 return VisitFloat64Compare(selector, value, cont); |
717 case IrOpcode::kFloat64LessThanOrEqual: | 756 case IrOpcode::kFloat64LessThanOrEqual: |
718 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); | 757 cont->OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); |
719 return VisitFloat64Compare(selector, value, cont); | 758 return VisitFloat64Compare(selector, value, cont); |
720 case IrOpcode::kProjection: | 759 case IrOpcode::kProjection: |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 void InstructionSelector::VisitInt32SubWithOverflow(Node* node) { | 885 void InstructionSelector::VisitInt32SubWithOverflow(Node* node) { |
847 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { | 886 if (Node* ovf = NodeProperties::FindProjection(node, 1)) { |
848 FlagsContinuation cont(kOverflow, ovf); | 887 FlagsContinuation cont(kOverflow, ovf); |
849 return VisitBinop(this, node, kMipsSubOvf, &cont); | 888 return VisitBinop(this, node, kMipsSubOvf, &cont); |
850 } | 889 } |
851 FlagsContinuation cont; | 890 FlagsContinuation cont; |
852 VisitBinop(this, node, kMipsSubOvf, &cont); | 891 VisitBinop(this, node, kMipsSubOvf, &cont); |
853 } | 892 } |
854 | 893 |
855 | 894 |
| 895 void InstructionSelector::VisitFloat32Equal(Node* node) { |
| 896 FlagsContinuation cont(kEqual, node); |
| 897 VisitFloat32Compare(this, node, &cont); |
| 898 } |
| 899 |
| 900 |
| 901 void InstructionSelector::VisitFloat32LessThan(Node* node) { |
| 902 FlagsContinuation cont(kUnsignedLessThan, node); |
| 903 VisitFloat32Compare(this, node, &cont); |
| 904 } |
| 905 |
| 906 |
| 907 void InstructionSelector::VisitFloat32LessThanOrEqual(Node* node) { |
| 908 FlagsContinuation cont(kUnsignedLessThanOrEqual, node); |
| 909 VisitFloat32Compare(this, node, &cont); |
| 910 } |
| 911 |
| 912 |
856 void InstructionSelector::VisitFloat64Equal(Node* node) { | 913 void InstructionSelector::VisitFloat64Equal(Node* node) { |
857 FlagsContinuation cont(kEqual, node); | 914 FlagsContinuation cont(kEqual, node); |
858 VisitFloat64Compare(this, node, &cont); | 915 VisitFloat64Compare(this, node, &cont); |
859 } | 916 } |
860 | 917 |
861 | 918 |
862 void InstructionSelector::VisitFloat64LessThan(Node* node) { | 919 void InstructionSelector::VisitFloat64LessThan(Node* node) { |
863 FlagsContinuation cont(kUnsignedLessThan, node); | 920 FlagsContinuation cont(kUnsignedLessThan, node); |
864 VisitFloat64Compare(this, node, &cont); | 921 VisitFloat64Compare(this, node, &cont); |
865 } | 922 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) { | 966 if (IsMipsArchVariant(kMips32r2) || IsMipsArchVariant(kMips32r6)) { |
910 return MachineOperatorBuilder::kFloat64RoundDown | | 967 return MachineOperatorBuilder::kFloat64RoundDown | |
911 MachineOperatorBuilder::kFloat64RoundTruncate; | 968 MachineOperatorBuilder::kFloat64RoundTruncate; |
912 } | 969 } |
913 return MachineOperatorBuilder::kNoFlags; | 970 return MachineOperatorBuilder::kNoFlags; |
914 } | 971 } |
915 | 972 |
916 } // namespace compiler | 973 } // namespace compiler |
917 } // namespace internal | 974 } // namespace internal |
918 } // namespace v8 | 975 } // namespace v8 |
OLD | NEW |