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

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

Powered by Google App Engine
This is Rietveld 408576698