Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: src/code-stub-assembler.cc

Issue 2146293003: [builtins] implement Array.prototype.includes in TurboFan (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix BranchIfSimd128Equal Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/code-stub-assembler.h" 5 #include "src/code-stub-assembler.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/frames-inl.h" 7 #include "src/frames-inl.h"
8 #include "src/frames.h" 8 #include "src/frames.h"
9 #include "src/ic/stub-cache.h" 9 #include "src/ic/stub-cache.h"
10 10
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 464
465 Node* CodeStubAssembler::WordIsSmi(Node* a) { 465 Node* CodeStubAssembler::WordIsSmi(Node* a) {
466 return WordEqual(WordAnd(a, IntPtrConstant(kSmiTagMask)), IntPtrConstant(0)); 466 return WordEqual(WordAnd(a, IntPtrConstant(kSmiTagMask)), IntPtrConstant(0));
467 } 467 }
468 468
469 Node* CodeStubAssembler::WordIsPositiveSmi(Node* a) { 469 Node* CodeStubAssembler::WordIsPositiveSmi(Node* a) {
470 return WordEqual(WordAnd(a, IntPtrConstant(kSmiTagMask | kSmiSignMask)), 470 return WordEqual(WordAnd(a, IntPtrConstant(kSmiTagMask | kSmiSignMask)),
471 IntPtrConstant(0)); 471 IntPtrConstant(0));
472 } 472 }
473 473
474 void CodeStubAssembler::BranchIfSameValueZero(Node* a, Node* b, Node* context,
475 Label* if_true, Label* if_false) {
476 Node* number_map = HeapNumberMapConstant();
477 Label a_isnumber(this), a_isnotnumber(this), b_isnumber(this), a_isnan(this),
478 float_not_equal(this);
479 // If register A and register B are identical, goto `if_true`
480 GotoIf(WordEqual(a, b), if_true);
481 // If either register A or B are Smis, goto `if_false`
482 GotoIf(Word32Or(WordIsSmi(a), WordIsSmi(b)), if_false);
483 // GotoIf(WordIsSmi(b), if_false);
484
485 Node* a_map = LoadMap(a);
486 Node* b_map = LoadMap(b);
487 Branch(WordEqual(a_map, number_map), &a_isnumber, &a_isnotnumber);
488
489 // If both register A and B are HeapNumbers, return true if they are equal,
490 // or if both are NaN
491 Bind(&a_isnumber);
492 {
493 Branch(WordEqual(b_map, number_map), &b_isnumber, if_false);
494
495 Bind(&b_isnumber);
496 Node* a_value = LoadHeapNumberValue(a);
497 Node* b_value = LoadHeapNumberValue(b);
498 BranchIfFloat64Equal(a_value, b_value, if_true, &float_not_equal);
499
500 Bind(&float_not_equal);
501 BranchIfFloat64IsNaN(a_value, &a_isnan, if_false);
502
503 Bind(&a_isnan);
504 BranchIfFloat64IsNaN(a_value, if_true, if_false);
505 }
506
507 Bind(&a_isnotnumber);
508 {
509 Label a_isstring(this), a_isnotstring(this);
510 Node* a_instance_type = LoadMapInstanceType(a_map);
511
512 Branch(Int32LessThan(a_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
513 &a_isstring, &a_isnotstring);
514
515 Bind(&a_isstring);
516 {
517 Label b_isstring(this), b_isnotstring(this);
518 Node* b_instance_type = LoadInstanceType(b_map);
519
520 Branch(
521 Int32LessThan(b_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
522 &b_isstring, if_false);
523
524 Bind(&b_isstring);
525 {
526 Callable callable = CodeFactory::StringEqual(isolate());
527 Node* result = CallStub(callable, context, a, b);
528 Branch(WordEqual(BooleanConstant(true), result), if_true, if_false);
529 }
530 }
531
532 Bind(&a_isnotstring);
533 {
534 // Check if {lhs} is a Simd128Value.
535 Label a_issimd128value(this);
536 Branch(Word32Equal(a_instance_type, Int32Constant(SIMD128_VALUE_TYPE)),
537 &a_issimd128value, if_false);
538
539 Bind(&a_issimd128value);
540 {
541 // Load the map of {rhs}.
542 BranchIfSimd128Equal(a, a_map, b, b_map, if_true, if_false);
543 }
544 }
545 }
546 }
547
548 void CodeStubAssembler::BranchIfSimd128Equal(Node* lhs, Node* lhs_map,
549 Node* rhs, Node* rhs_map,
550 Label* if_equal,
551 Label* if_notequal) {
552 Label if_mapsame(this), if_mapnotsame(this);
553 Branch(WordEqual(lhs_map, rhs_map), &if_mapsame, &if_mapnotsame);
554
555 Bind(&if_mapsame);
556 {
557 // Both {lhs} and {rhs} are Simd128Values with the same map, need special
558 // handling for Float32x4 because of NaN comparisons.
559 Label if_float32x4(this), if_notfloat32x4(this);
560 Node* float32x4_map = HeapConstant(factory()->float32x4_map());
561 Branch(WordEqual(lhs_map, float32x4_map), &if_float32x4, &if_notfloat32x4);
562
563 Bind(&if_float32x4);
564 {
565 // Both {lhs} and {rhs} are Float32x4, compare the lanes individually
566 // using a floating point comparison.
567 for (int offset = Float32x4::kValueOffset - kHeapObjectTag;
568 offset < Float32x4::kSize - kHeapObjectTag;
569 offset += sizeof(float)) {
570 // Load the floating point values for {lhs} and {rhs}.
571 Node* lhs_value =
572 Load(MachineType::Float32(), lhs, IntPtrConstant(offset));
573 Node* rhs_value =
574 Load(MachineType::Float32(), rhs, IntPtrConstant(offset));
575
576 // Perform a floating point comparison.
577 Label if_valueequal(this), if_valuenotequal(this);
578 Branch(Float32Equal(lhs_value, rhs_value), &if_valueequal,
579 &if_valuenotequal);
580 Bind(&if_valuenotequal);
581 Goto(if_notequal);
582 Bind(&if_valueequal);
583 }
584
585 // All 4 lanes match, {lhs} and {rhs} considered equal.
586 Goto(if_equal);
587 }
588
589 Bind(&if_notfloat32x4);
590 {
591 // For other Simd128Values we just perform a bitwise comparison.
592 for (int offset = Simd128Value::kValueOffset - kHeapObjectTag;
593 offset < Simd128Value::kSize - kHeapObjectTag;
594 offset += kPointerSize) {
595 // Load the word values for {lhs} and {rhs}.
596 Node* lhs_value =
597 Load(MachineType::Pointer(), lhs, IntPtrConstant(offset));
598 Node* rhs_value =
599 Load(MachineType::Pointer(), rhs, IntPtrConstant(offset));
600
601 // Perform a bitwise word-comparison.
602 Label if_valueequal(this), if_valuenotequal(this);
603 Branch(WordEqual(lhs_value, rhs_value), &if_valueequal,
604 &if_valuenotequal);
605 Bind(&if_valuenotequal);
606 Goto(if_notequal);
607 Bind(&if_valueequal);
608 }
609
610 // Bitwise comparison succeeded, {lhs} and {rhs} considered equal.
611 Goto(if_equal);
612 }
613 }
614
615 Bind(&if_mapnotsame);
616 Goto(if_notequal);
617 }
618
619 void CodeStubAssembler::BranchIfFastJSArray(Node* object, Node* context,
620 Label* if_true, Label* if_false) {
621 Node* int32_zero = Int32Constant(0);
622 Node* int32_one = Int32Constant(1);
623
624 Node* empty_elements = LoadRoot(Heap::kEmptyFixedArrayRootIndex);
625
626 Variable last_map(this, MachineRepresentation::kTagged);
627 Label check_prototype(this);
628
629 // Bailout if Smi
630 GotoIf(WordIsSmi(object), if_false);
631
632 Node* map = LoadMap(object);
633 last_map.Bind(map);
634
635 // Bailout if instance type is not JS_ARRAY_TYPE
636 GotoIf(WordNotEqual(LoadMapInstanceType(map), Int32Constant(JS_ARRAY_TYPE)),
637 if_false);
638
639 Node* bit_field2 = LoadMapBitField2(map);
640 Node* elements_kind = BitFieldDecode<Map::ElementsKindBits>(bit_field2);
641
642 // Bailout if slow receiver elements
643 GotoIf(
644 Int32GreaterThan(elements_kind, Int32Constant(LAST_FAST_ELEMENTS_KIND)),
645 if_false);
646
647 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == (FAST_SMI_ELEMENTS | 1));
648 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == (FAST_ELEMENTS | 1));
649 STATIC_ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == (FAST_DOUBLE_ELEMENTS | 1));
650
651 // Check prototype chain if receiver does not have packed elements
652 Node* holey_elements = Word32And(elements_kind, int32_one);
653 Branch(Word32Equal(holey_elements, int32_zero), if_true, &check_prototype);
654
655 Bind(&check_prototype);
656 {
657 Label loop_body(this, &last_map);
658 Goto(&loop_body);
659 Bind(&loop_body);
660 Node* current_map = last_map.value();
661 Node* proto = LoadObjectField(current_map, Map::kPrototypeOffset);
662
663 // End loop
664 GotoIf(WordEqual(proto, NullConstant()), if_true);
665
666 // ASSERT: proto->IsHeapObject()
667 Node* proto_map = LoadMap(proto);
668
669 // Bailout if a Proxy, API Object, or JSValue wrapper found in prototype
670 // Because of this bailout, it's not necessary to check for interceptors or
671 // access checks on the prototype chain.
672 GotoIf(Int32LessThanOrEqual(LoadMapInstanceType(proto_map),
673 Int32Constant(LAST_CUSTOM_ELEMENTS_RECEIVER)),
674 if_false);
675
676 // Bailout if prototype contains non-empty elements
677 GotoUnless(WordEqual(LoadElements(proto), empty_elements), if_false);
678
679 last_map.Bind(proto_map);
680 Goto(&loop_body);
681 }
682 }
683
474 Node* CodeStubAssembler::AllocateRawUnaligned(Node* size_in_bytes, 684 Node* CodeStubAssembler::AllocateRawUnaligned(Node* size_in_bytes,
475 AllocationFlags flags, 685 AllocationFlags flags,
476 Node* top_address, 686 Node* top_address,
477 Node* limit_address) { 687 Node* limit_address) {
478 Node* top = Load(MachineType::Pointer(), top_address); 688 Node* top = Load(MachineType::Pointer(), top_address);
479 Node* limit = Load(MachineType::Pointer(), limit_address); 689 Node* limit = Load(MachineType::Pointer(), limit_address);
480 690
481 // If there's not enough space, call the runtime. 691 // If there's not enough space, call the runtime.
482 Variable result(this, MachineRepresentation::kTagged); 692 Variable result(this, MachineRepresentation::kTagged);
483 Label runtime_call(this, Label::kDeferred), no_runtime_call(this); 693 Label runtime_call(this, Label::kDeferred), no_runtime_call(this);
(...skipping 2792 matching lines...) Expand 10 before | Expand all | Expand 10 after
3276 Heap::kTheHoleValueRootIndex); 3486 Heap::kTheHoleValueRootIndex);
3277 3487
3278 // Store the WeakCell in the feedback vector. 3488 // Store the WeakCell in the feedback vector.
3279 StoreFixedArrayElement(feedback_vector, slot, cell, UPDATE_WRITE_BARRIER, 3489 StoreFixedArrayElement(feedback_vector, slot, cell, UPDATE_WRITE_BARRIER,
3280 CodeStubAssembler::SMI_PARAMETERS); 3490 CodeStubAssembler::SMI_PARAMETERS);
3281 return cell; 3491 return cell;
3282 } 3492 }
3283 3493
3284 } // namespace internal 3494 } // namespace internal
3285 } // namespace v8 3495 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698