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

Side by Side Diff: src/full-codegen/ia32/full-codegen-ia32.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
« no previous file with comments | « src/full-codegen/full-codegen.h ('k') | src/full-codegen/mips/full-codegen-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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_IA32 5 #if V8_TARGET_ARCH_IA32
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 3307 matching lines...) Expand 10 before | Expand all | Expand 10 after
3318 void FullCodeGenerator::EmitGetSuperConstructor(CallRuntime* expr) { 3318 void FullCodeGenerator::EmitGetSuperConstructor(CallRuntime* expr) {
3319 ZoneList<Expression*>* args = expr->arguments(); 3319 ZoneList<Expression*>* args = expr->arguments();
3320 DCHECK_EQ(1, args->length()); 3320 DCHECK_EQ(1, args->length());
3321 VisitForAccumulatorValue(args->at(0)); 3321 VisitForAccumulatorValue(args->at(0));
3322 __ AssertFunction(eax); 3322 __ AssertFunction(eax);
3323 __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); 3323 __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset));
3324 __ mov(eax, FieldOperand(eax, Map::kPrototypeOffset)); 3324 __ mov(eax, FieldOperand(eax, Map::kPrototypeOffset));
3325 context()->Plug(eax); 3325 context()->Plug(eax);
3326 } 3326 }
3327 3327
3328
3329 void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) {
3330 Label bailout, done, one_char_separator, long_separator,
3331 non_trivial_array, not_size_one_array, loop,
3332 loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry;
3333
3334 ZoneList<Expression*>* args = expr->arguments();
3335 DCHECK(args->length() == 2);
3336 // We will leave the separator on the stack until the end of the function.
3337 VisitForStackValue(args->at(1));
3338 // Load this to eax (= array)
3339 VisitForAccumulatorValue(args->at(0));
3340 // All aliases of the same register have disjoint lifetimes.
3341 Register array = eax;
3342 Register elements = no_reg; // Will be eax.
3343
3344 Register index = edx;
3345
3346 Register string_length = ecx;
3347
3348 Register string = esi;
3349
3350 Register scratch = ebx;
3351
3352 Register array_length = edi;
3353 Register result_pos = no_reg; // Will be edi.
3354
3355 // Separator operand is already pushed.
3356 Operand separator_operand = Operand(esp, 2 * kPointerSize);
3357 Operand result_operand = Operand(esp, 1 * kPointerSize);
3358 Operand array_length_operand = Operand(esp, 0);
3359 __ sub(esp, Immediate(2 * kPointerSize));
3360 __ cld();
3361 // Check that the array is a JSArray
3362 __ JumpIfSmi(array, &bailout);
3363 __ CmpObjectType(array, JS_ARRAY_TYPE, scratch);
3364 __ j(not_equal, &bailout);
3365
3366 // Check that the array has fast elements.
3367 __ CheckFastElements(scratch, &bailout);
3368
3369 // If the array has length zero, return the empty string.
3370 __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset));
3371 __ SmiUntag(array_length);
3372 __ j(not_zero, &non_trivial_array);
3373 __ mov(result_operand, isolate()->factory()->empty_string());
3374 __ jmp(&done);
3375
3376 // Save the array length.
3377 __ bind(&non_trivial_array);
3378 __ mov(array_length_operand, array_length);
3379
3380 // Save the FixedArray containing array's elements.
3381 // End of array's live range.
3382 elements = array;
3383 __ mov(elements, FieldOperand(array, JSArray::kElementsOffset));
3384 array = no_reg;
3385
3386
3387 // Check that all array elements are sequential one-byte strings, and
3388 // accumulate the sum of their lengths, as a smi-encoded value.
3389 __ Move(index, Immediate(0));
3390 __ Move(string_length, Immediate(0));
3391 // Loop condition: while (index < length).
3392 // Live loop registers: index, array_length, string,
3393 // scratch, string_length, elements.
3394 if (generate_debug_code_) {
3395 __ cmp(index, array_length);
3396 __ Assert(less, kNoEmptyArraysHereInEmitFastOneByteArrayJoin);
3397 }
3398 __ bind(&loop);
3399 __ mov(string, FieldOperand(elements,
3400 index,
3401 times_pointer_size,
3402 FixedArray::kHeaderSize));
3403 __ JumpIfSmi(string, &bailout);
3404 __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset));
3405 __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
3406 __ and_(scratch, Immediate(
3407 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
3408 __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag);
3409 __ j(not_equal, &bailout);
3410 __ add(string_length,
3411 FieldOperand(string, SeqOneByteString::kLengthOffset));
3412 __ j(overflow, &bailout);
3413 __ add(index, Immediate(1));
3414 __ cmp(index, array_length);
3415 __ j(less, &loop);
3416
3417 // If array_length is 1, return elements[0], a string.
3418 __ cmp(array_length, 1);
3419 __ j(not_equal, &not_size_one_array);
3420 __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize));
3421 __ mov(result_operand, scratch);
3422 __ jmp(&done);
3423
3424 __ bind(&not_size_one_array);
3425
3426 // End of array_length live range.
3427 result_pos = array_length;
3428 array_length = no_reg;
3429
3430 // Live registers:
3431 // string_length: Sum of string lengths, as a smi.
3432 // elements: FixedArray of strings.
3433
3434 // Check that the separator is a flat one-byte string.
3435 __ mov(string, separator_operand);
3436 __ JumpIfSmi(string, &bailout);
3437 __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset));
3438 __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
3439 __ and_(scratch, Immediate(
3440 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
3441 __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag);
3442 __ j(not_equal, &bailout);
3443
3444 // Add (separator length times array_length) - separator length
3445 // to string_length.
3446 __ mov(scratch, separator_operand);
3447 __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset));
3448 __ sub(string_length, scratch); // May be negative, temporarily.
3449 __ imul(scratch, array_length_operand);
3450 __ j(overflow, &bailout);
3451 __ add(string_length, scratch);
3452 __ j(overflow, &bailout);
3453
3454 __ shr(string_length, 1);
3455
3456 // Bailout for large object allocations.
3457 __ cmp(string_length, Page::kMaxRegularHeapObjectSize);
3458 __ j(greater, &bailout);
3459
3460 // Live registers and stack values:
3461 // string_length
3462 // elements
3463 __ AllocateOneByteString(result_pos, string_length, scratch, index, string,
3464 &bailout);
3465 __ mov(result_operand, result_pos);
3466 __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize));
3467
3468
3469 __ mov(string, separator_operand);
3470 __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset),
3471 Immediate(Smi::FromInt(1)));
3472 __ j(equal, &one_char_separator);
3473 __ j(greater, &long_separator);
3474
3475
3476 // Empty separator case
3477 __ mov(index, Immediate(0));
3478 __ jmp(&loop_1_condition);
3479 // Loop condition: while (index < length).
3480 __ bind(&loop_1);
3481 // Each iteration of the loop concatenates one string to the result.
3482 // Live values in registers:
3483 // index: which element of the elements array we are adding to the result.
3484 // result_pos: the position to which we are currently copying characters.
3485 // elements: the FixedArray of strings we are joining.
3486
3487 // Get string = array[index].
3488 __ mov(string, FieldOperand(elements, index,
3489 times_pointer_size,
3490 FixedArray::kHeaderSize));
3491 __ mov(string_length,
3492 FieldOperand(string, String::kLengthOffset));
3493 __ shr(string_length, 1);
3494 __ lea(string,
3495 FieldOperand(string, SeqOneByteString::kHeaderSize));
3496 __ CopyBytes(string, result_pos, string_length, scratch);
3497 __ add(index, Immediate(1));
3498 __ bind(&loop_1_condition);
3499 __ cmp(index, array_length_operand);
3500 __ j(less, &loop_1); // End while (index < length).
3501 __ jmp(&done);
3502
3503
3504
3505 // One-character separator case
3506 __ bind(&one_char_separator);
3507 // Replace separator with its one-byte character value.
3508 __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize));
3509 __ mov_b(separator_operand, scratch);
3510
3511 __ Move(index, Immediate(0));
3512 // Jump into the loop after the code that copies the separator, so the first
3513 // element is not preceded by a separator
3514 __ jmp(&loop_2_entry);
3515 // Loop condition: while (index < length).
3516 __ bind(&loop_2);
3517 // Each iteration of the loop concatenates one string to the result.
3518 // Live values in registers:
3519 // index: which element of the elements array we are adding to the result.
3520 // result_pos: the position to which we are currently copying characters.
3521
3522 // Copy the separator character to the result.
3523 __ mov_b(scratch, separator_operand);
3524 __ mov_b(Operand(result_pos, 0), scratch);
3525 __ inc(result_pos);
3526
3527 __ bind(&loop_2_entry);
3528 // Get string = array[index].
3529 __ mov(string, FieldOperand(elements, index,
3530 times_pointer_size,
3531 FixedArray::kHeaderSize));
3532 __ mov(string_length,
3533 FieldOperand(string, String::kLengthOffset));
3534 __ shr(string_length, 1);
3535 __ lea(string,
3536 FieldOperand(string, SeqOneByteString::kHeaderSize));
3537 __ CopyBytes(string, result_pos, string_length, scratch);
3538 __ add(index, Immediate(1));
3539
3540 __ cmp(index, array_length_operand);
3541 __ j(less, &loop_2); // End while (index < length).
3542 __ jmp(&done);
3543
3544
3545 // Long separator case (separator is more than one character).
3546 __ bind(&long_separator);
3547
3548 __ Move(index, Immediate(0));
3549 // Jump into the loop after the code that copies the separator, so the first
3550 // element is not preceded by a separator
3551 __ jmp(&loop_3_entry);
3552 // Loop condition: while (index < length).
3553 __ bind(&loop_3);
3554 // Each iteration of the loop concatenates one string to the result.
3555 // Live values in registers:
3556 // index: which element of the elements array we are adding to the result.
3557 // result_pos: the position to which we are currently copying characters.
3558
3559 // Copy the separator to the result.
3560 __ mov(string, separator_operand);
3561 __ mov(string_length,
3562 FieldOperand(string, String::kLengthOffset));
3563 __ shr(string_length, 1);
3564 __ lea(string,
3565 FieldOperand(string, SeqOneByteString::kHeaderSize));
3566 __ CopyBytes(string, result_pos, string_length, scratch);
3567
3568 __ bind(&loop_3_entry);
3569 // Get string = array[index].
3570 __ mov(string, FieldOperand(elements, index,
3571 times_pointer_size,
3572 FixedArray::kHeaderSize));
3573 __ mov(string_length,
3574 FieldOperand(string, String::kLengthOffset));
3575 __ shr(string_length, 1);
3576 __ lea(string,
3577 FieldOperand(string, SeqOneByteString::kHeaderSize));
3578 __ CopyBytes(string, result_pos, string_length, scratch);
3579 __ add(index, Immediate(1));
3580
3581 __ cmp(index, array_length_operand);
3582 __ j(less, &loop_3); // End while (index < length).
3583 __ jmp(&done);
3584
3585
3586 __ bind(&bailout);
3587 __ mov(result_operand, isolate()->factory()->undefined_value());
3588 __ bind(&done);
3589 __ mov(eax, result_operand);
3590 // Drop temp values from the stack, and restore context register.
3591 __ add(esp, Immediate(3 * kPointerSize));
3592
3593 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3594 context()->Plug(eax);
3595 }
3596
3328 3597
3329 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) { 3598 void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
3330 DCHECK(expr->arguments()->length() == 0); 3599 DCHECK(expr->arguments()->length() == 0);
3331 ExternalReference debug_is_active = 3600 ExternalReference debug_is_active =
3332 ExternalReference::debug_is_active_address(isolate()); 3601 ExternalReference::debug_is_active_address(isolate());
3333 __ movzx_b(eax, Operand::StaticVariable(debug_is_active)); 3602 __ movzx_b(eax, Operand::StaticVariable(debug_is_active));
3334 __ SmiTag(eax); 3603 __ SmiTag(eax);
3335 context()->Plug(eax); 3604 context()->Plug(eax);
3336 } 3605 }
3337 3606
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
4178 Assembler::target_address_at(call_target_address, 4447 Assembler::target_address_at(call_target_address,
4179 unoptimized_code)); 4448 unoptimized_code));
4180 return OSR_AFTER_STACK_CHECK; 4449 return OSR_AFTER_STACK_CHECK;
4181 } 4450 }
4182 4451
4183 4452
4184 } // namespace internal 4453 } // namespace internal
4185 } // namespace v8 4454 } // namespace v8
4186 4455
4187 #endif // V8_TARGET_ARCH_IA32 4456 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/full-codegen/full-codegen.h ('k') | src/full-codegen/mips/full-codegen-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698