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

Side by Side Diff: src/full-codegen/ppc/full-codegen-ppc.cc

Issue 1709693002: Revert of [fullcodegen] Remove the hacky %_FastOneByteArrayJoin intrinsic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 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 #if V8_TARGET_ARCH_PPC 5 #if V8_TARGET_ARCH_PPC
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 3421 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 ZoneList<Expression*>* args = expr->arguments(); 3432 ZoneList<Expression*>* args = expr->arguments();
3433 DCHECK_EQ(1, args->length()); 3433 DCHECK_EQ(1, args->length());
3434 VisitForAccumulatorValue(args->at(0)); 3434 VisitForAccumulatorValue(args->at(0));
3435 __ AssertFunction(r3); 3435 __ AssertFunction(r3);
3436 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset)); 3436 __ LoadP(r3, FieldMemOperand(r3, HeapObject::kMapOffset));
3437 __ LoadP(r3, FieldMemOperand(r3, Map::kPrototypeOffset)); 3437 __ LoadP(r3, FieldMemOperand(r3, Map::kPrototypeOffset));
3438 context()->Plug(r3); 3438 context()->Plug(r3);
3439 } 3439 }
3440 3440
3441 3441
3442 void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) {
3443 Label bailout, done, one_char_separator, long_separator, non_trivial_array,
3444 not_size_one_array, loop, empty_separator_loop, one_char_separator_loop,
3445 one_char_separator_loop_entry, long_separator_loop;
3446 ZoneList<Expression*>* args = expr->arguments();
3447 DCHECK(args->length() == 2);
3448 VisitForStackValue(args->at(1));
3449 VisitForAccumulatorValue(args->at(0));
3450
3451 // All aliases of the same register have disjoint lifetimes.
3452 Register array = r3;
3453 Register elements = no_reg; // Will be r3.
3454 Register result = no_reg; // Will be r3.
3455 Register separator = r4;
3456 Register array_length = r5;
3457 Register result_pos = no_reg; // Will be r5
3458 Register string_length = r6;
3459 Register string = r7;
3460 Register element = r8;
3461 Register elements_end = r9;
3462 Register scratch1 = r10;
3463 Register scratch2 = r11;
3464
3465 // Separator operand is on the stack.
3466 __ pop(separator);
3467
3468 // Check that the array is a JSArray.
3469 __ JumpIfSmi(array, &bailout);
3470 __ CompareObjectType(array, scratch1, scratch2, JS_ARRAY_TYPE);
3471 __ bne(&bailout);
3472
3473 // Check that the array has fast elements.
3474 __ CheckFastElements(scratch1, scratch2, &bailout);
3475
3476 // If the array has length zero, return the empty string.
3477 __ LoadP(array_length, FieldMemOperand(array, JSArray::kLengthOffset));
3478 __ SmiUntag(array_length);
3479 __ cmpi(array_length, Operand::Zero());
3480 __ bne(&non_trivial_array);
3481 __ LoadRoot(r3, Heap::kempty_stringRootIndex);
3482 __ b(&done);
3483
3484 __ bind(&non_trivial_array);
3485
3486 // Get the FixedArray containing array's elements.
3487 elements = array;
3488 __ LoadP(elements, FieldMemOperand(array, JSArray::kElementsOffset));
3489 array = no_reg; // End of array's live range.
3490
3491 // Check that all array elements are sequential one-byte strings, and
3492 // accumulate the sum of their lengths, as a smi-encoded value.
3493 __ li(string_length, Operand::Zero());
3494 __ addi(element, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3495 __ ShiftLeftImm(elements_end, array_length, Operand(kPointerSizeLog2));
3496 __ add(elements_end, element, elements_end);
3497 // Loop condition: while (element < elements_end).
3498 // Live values in registers:
3499 // elements: Fixed array of strings.
3500 // array_length: Length of the fixed array of strings (not smi)
3501 // separator: Separator string
3502 // string_length: Accumulated sum of string lengths (smi).
3503 // element: Current array element.
3504 // elements_end: Array end.
3505 if (generate_debug_code_) {
3506 __ cmpi(array_length, Operand::Zero());
3507 __ Assert(gt, kNoEmptyArraysHereInEmitFastOneByteArrayJoin);
3508 }
3509 __ bind(&loop);
3510 __ LoadP(string, MemOperand(element));
3511 __ addi(element, element, Operand(kPointerSize));
3512 __ JumpIfSmi(string, &bailout);
3513 __ LoadP(scratch1, FieldMemOperand(string, HeapObject::kMapOffset));
3514 __ lbz(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3515 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
3516 __ LoadP(scratch1, FieldMemOperand(string, SeqOneByteString::kLengthOffset));
3517
3518 __ AddAndCheckForOverflow(string_length, string_length, scratch1, scratch2,
3519 r0);
3520 __ BranchOnOverflow(&bailout);
3521
3522 __ cmp(element, elements_end);
3523 __ blt(&loop);
3524
3525 // If array_length is 1, return elements[0], a string.
3526 __ cmpi(array_length, Operand(1));
3527 __ bne(&not_size_one_array);
3528 __ LoadP(r3, FieldMemOperand(elements, FixedArray::kHeaderSize));
3529 __ b(&done);
3530
3531 __ bind(&not_size_one_array);
3532
3533 // Live values in registers:
3534 // separator: Separator string
3535 // array_length: Length of the array.
3536 // string_length: Sum of string lengths (smi).
3537 // elements: FixedArray of strings.
3538
3539 // Check that the separator is a flat one-byte string.
3540 __ JumpIfSmi(separator, &bailout);
3541 __ LoadP(scratch1, FieldMemOperand(separator, HeapObject::kMapOffset));
3542 __ lbz(scratch1, FieldMemOperand(scratch1, Map::kInstanceTypeOffset));
3543 __ JumpIfInstanceTypeIsNotSequentialOneByte(scratch1, scratch2, &bailout);
3544
3545 // Add (separator length times array_length) - separator length to the
3546 // string_length to get the length of the result string.
3547 __ LoadP(scratch1,
3548 FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
3549 __ sub(string_length, string_length, scratch1);
3550 #if V8_TARGET_ARCH_PPC64
3551 __ SmiUntag(scratch1, scratch1);
3552 __ Mul(scratch2, array_length, scratch1);
3553 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
3554 // zero.
3555 __ ShiftRightImm(ip, scratch2, Operand(31), SetRC);
3556 __ bne(&bailout, cr0);
3557 __ SmiTag(scratch2, scratch2);
3558 #else
3559 // array_length is not smi but the other values are, so the result is a smi
3560 __ mullw(scratch2, array_length, scratch1);
3561 __ mulhw(ip, array_length, scratch1);
3562 // Check for smi overflow. No overflow if higher 33 bits of 64-bit result are
3563 // zero.
3564 __ cmpi(ip, Operand::Zero());
3565 __ bne(&bailout);
3566 __ cmpwi(scratch2, Operand::Zero());
3567 __ blt(&bailout);
3568 #endif
3569
3570 __ AddAndCheckForOverflow(string_length, string_length, scratch2, scratch1,
3571 r0);
3572 __ BranchOnOverflow(&bailout);
3573 __ SmiUntag(string_length);
3574
3575 // Bailout for large object allocations.
3576 __ Cmpi(string_length, Operand(Page::kMaxRegularHeapObjectSize), r0);
3577 __ bgt(&bailout);
3578
3579 // Get first element in the array to free up the elements register to be used
3580 // for the result.
3581 __ addi(element, elements, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
3582 result = elements; // End of live range for elements.
3583 elements = no_reg;
3584 // Live values in registers:
3585 // element: First array element
3586 // separator: Separator string
3587 // string_length: Length of result string (not smi)
3588 // array_length: Length of the array.
3589 __ AllocateOneByteString(result, string_length, scratch1, scratch2,
3590 elements_end, &bailout);
3591 // Prepare for looping. Set up elements_end to end of the array. Set
3592 // result_pos to the position of the result where to write the first
3593 // character.
3594 __ ShiftLeftImm(elements_end, array_length, Operand(kPointerSizeLog2));
3595 __ add(elements_end, element, elements_end);
3596 result_pos = array_length; // End of live range for array_length.
3597 array_length = no_reg;
3598 __ addi(result_pos, result,
3599 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3600
3601 // Check the length of the separator.
3602 __ LoadP(scratch1,
3603 FieldMemOperand(separator, SeqOneByteString::kLengthOffset));
3604 __ CmpSmiLiteral(scratch1, Smi::FromInt(1), r0);
3605 __ beq(&one_char_separator);
3606 __ bgt(&long_separator);
3607
3608 // Empty separator case
3609 __ bind(&empty_separator_loop);
3610 // Live values in registers:
3611 // result_pos: the position to which we are currently copying characters.
3612 // element: Current array element.
3613 // elements_end: Array end.
3614
3615 // Copy next array element to the result.
3616 __ LoadP(string, MemOperand(element));
3617 __ addi(element, element, Operand(kPointerSize));
3618 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
3619 __ SmiUntag(string_length);
3620 __ addi(string, string,
3621 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3622 __ CopyBytes(string, result_pos, string_length, scratch1);
3623 __ cmp(element, elements_end);
3624 __ blt(&empty_separator_loop); // End while (element < elements_end).
3625 DCHECK(result.is(r3));
3626 __ b(&done);
3627
3628 // One-character separator case
3629 __ bind(&one_char_separator);
3630 // Replace separator with its one-byte character value.
3631 __ lbz(separator, FieldMemOperand(separator, SeqOneByteString::kHeaderSize));
3632 // Jump into the loop after the code that copies the separator, so the first
3633 // element is not preceded by a separator
3634 __ b(&one_char_separator_loop_entry);
3635
3636 __ bind(&one_char_separator_loop);
3637 // Live values in registers:
3638 // result_pos: the position to which we are currently copying characters.
3639 // element: Current array element.
3640 // elements_end: Array end.
3641 // separator: Single separator one-byte char (in lower byte).
3642
3643 // Copy the separator character to the result.
3644 __ stb(separator, MemOperand(result_pos));
3645 __ addi(result_pos, result_pos, Operand(1));
3646
3647 // Copy next array element to the result.
3648 __ bind(&one_char_separator_loop_entry);
3649 __ LoadP(string, MemOperand(element));
3650 __ addi(element, element, Operand(kPointerSize));
3651 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
3652 __ SmiUntag(string_length);
3653 __ addi(string, string,
3654 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3655 __ CopyBytes(string, result_pos, string_length, scratch1);
3656 __ cmpl(element, elements_end);
3657 __ blt(&one_char_separator_loop); // End while (element < elements_end).
3658 DCHECK(result.is(r3));
3659 __ b(&done);
3660
3661 // Long separator case (separator is more than one character). Entry is at the
3662 // label long_separator below.
3663 __ bind(&long_separator_loop);
3664 // Live values in registers:
3665 // result_pos: the position to which we are currently copying characters.
3666 // element: Current array element.
3667 // elements_end: Array end.
3668 // separator: Separator string.
3669
3670 // Copy the separator to the result.
3671 __ LoadP(string_length, FieldMemOperand(separator, String::kLengthOffset));
3672 __ SmiUntag(string_length);
3673 __ addi(string, separator,
3674 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3675 __ CopyBytes(string, result_pos, string_length, scratch1);
3676
3677 __ bind(&long_separator);
3678 __ LoadP(string, MemOperand(element));
3679 __ addi(element, element, Operand(kPointerSize));
3680 __ LoadP(string_length, FieldMemOperand(string, String::kLengthOffset));
3681 __ SmiUntag(string_length);
3682 __ addi(string, string,
3683 Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag));
3684 __ CopyBytes(string, result_pos, string_length, scratch1);
3685 __ cmpl(element, elements_end);
3686 __ blt(&long_separator_loop); // End while (element < elements_end).
3687 DCHECK(result.is(r3));
3688 __ b(&done);
3689
3690 __ bind(&bailout);
3691 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
3692 __ bind(&done);
3693 context()->Plug(r3);
3694 }
3695
3696
3442 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) { 3697 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
3443 DCHECK(expr->arguments()->length() == 0); 3698 DCHECK(expr->arguments()->length() == 0);
3444 ExternalReference debug_is_active = 3699 ExternalReference debug_is_active =
3445 ExternalReference::debug_is_active_address(isolate()); 3700 ExternalReference::debug_is_active_address(isolate());
3446 __ mov(ip, Operand(debug_is_active)); 3701 __ mov(ip, Operand(debug_is_active));
3447 __ lbz(r3, MemOperand(ip)); 3702 __ lbz(r3, MemOperand(ip));
3448 __ SmiTag(r3); 3703 __ SmiTag(r3);
3449 context()->Plug(r3); 3704 context()->Plug(r3);
3450 } 3705 }
3451 3706
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
4274 return ON_STACK_REPLACEMENT; 4529 return ON_STACK_REPLACEMENT;
4275 } 4530 }
4276 4531
4277 DCHECK(interrupt_address == 4532 DCHECK(interrupt_address ==
4278 isolate->builtins()->OsrAfterStackCheck()->entry()); 4533 isolate->builtins()->OsrAfterStackCheck()->entry());
4279 return OSR_AFTER_STACK_CHECK; 4534 return OSR_AFTER_STACK_CHECK;
4280 } 4535 }
4281 } // namespace internal 4536 } // namespace internal
4282 } // namespace v8 4537 } // namespace v8
4283 #endif // V8_TARGET_ARCH_PPC 4538 #endif // V8_TARGET_ARCH_PPC
OLDNEW
« no previous file with comments | « src/full-codegen/mips64/full-codegen-mips64.cc ('k') | src/full-codegen/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698