Index: src/arm/code-stubs-arm.cc |
diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc |
index 758d35f3a61e2ec1cad0cdced7ffe253d4a14b89..75ef1ff968d7596a99a03e5ebf4b292efbce593a 100644 |
--- a/src/arm/code-stubs-arm.cc |
+++ b/src/arm/code-stubs-arm.cc |
@@ -350,7 +350,7 @@ void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor( |
} |
-void NewStringAddStub::InitializeInterfaceDescriptor( |
+void StringAddStub::InitializeInterfaceDescriptor( |
Isolate* isolate, |
CodeStubInterfaceDescriptor* descriptor) { |
static Register registers[] = { r1, r0 }; |
@@ -4433,362 +4433,6 @@ void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
} |
-void StringAddStub::Generate(MacroAssembler* masm) { |
- Label call_runtime, call_builtin; |
- Builtins::JavaScript builtin_id = Builtins::ADD; |
- |
- Counters* counters = masm->isolate()->counters(); |
- |
- // Stack on entry: |
- // sp[0]: second argument (right). |
- // sp[4]: first argument (left). |
- |
- // Load the two arguments. |
- __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); // First argument. |
- __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument. |
- |
- // Make sure that both arguments are strings if not known in advance. |
- // Otherwise, at least one of the arguments is definitely a string, |
- // and we convert the one that is not known to be a string. |
- if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
- ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT); |
- ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT); |
- __ JumpIfEitherSmi(r0, r1, &call_runtime); |
- // Load instance types. |
- __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
- __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
- __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
- __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
- STATIC_ASSERT(kStringTag == 0); |
- // If either is not a string, go to runtime. |
- __ tst(r4, Operand(kIsNotStringMask)); |
- __ tst(r5, Operand(kIsNotStringMask), eq); |
- __ b(ne, &call_runtime); |
- } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
- ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0); |
- GenerateConvertArgument( |
- masm, 1 * kPointerSize, r0, r2, r3, r4, r5, &call_builtin); |
- builtin_id = Builtins::STRING_ADD_RIGHT; |
- } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
- ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0); |
- GenerateConvertArgument( |
- masm, 0 * kPointerSize, r1, r2, r3, r4, r5, &call_builtin); |
- builtin_id = Builtins::STRING_ADD_LEFT; |
- } |
- |
- // Both arguments are strings. |
- // r0: first string |
- // r1: second string |
- // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
- // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
- { |
- Label strings_not_empty; |
- // Check if either of the strings are empty. In that case return the other. |
- __ ldr(r2, FieldMemOperand(r0, String::kLengthOffset)); |
- __ ldr(r3, FieldMemOperand(r1, String::kLengthOffset)); |
- STATIC_ASSERT(kSmiTag == 0); |
- __ cmp(r2, Operand(Smi::FromInt(0))); // Test if first string is empty. |
- __ mov(r0, Operand(r1), LeaveCC, eq); // If first is empty, return second. |
- STATIC_ASSERT(kSmiTag == 0); |
- // Else test if second string is empty. |
- __ cmp(r3, Operand(Smi::FromInt(0)), ne); |
- __ b(ne, &strings_not_empty); // If either string was empty, return r0. |
- |
- __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
- __ add(sp, sp, Operand(2 * kPointerSize)); |
- __ Ret(); |
- |
- __ bind(&strings_not_empty); |
- } |
- |
- __ SmiUntag(r2); |
- __ SmiUntag(r3); |
- // Both strings are non-empty. |
- // r0: first string |
- // r1: second string |
- // r2: length of first string |
- // r3: length of second string |
- // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
- // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
- // Look at the length of the result of adding the two strings. |
- Label string_add_flat_result, longer_than_two; |
- // Adding two lengths can't overflow. |
- STATIC_ASSERT(String::kMaxLength < String::kMaxLength * 2); |
- __ add(r6, r2, Operand(r3)); |
- // Use the string table when adding two one character strings, as it |
- // helps later optimizations to return a string here. |
- __ cmp(r6, Operand(2)); |
- __ b(ne, &longer_than_two); |
- |
- // Check that both strings are non-external ASCII strings. |
- if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) { |
- __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
- __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
- __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
- __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
- } |
- __ JumpIfBothInstanceTypesAreNotSequentialAscii(r4, r5, r6, r3, |
- &call_runtime); |
- |
- // Get the two characters forming the sub string. |
- __ ldrb(r2, FieldMemOperand(r0, SeqOneByteString::kHeaderSize)); |
- __ ldrb(r3, FieldMemOperand(r1, SeqOneByteString::kHeaderSize)); |
- |
- // Try to lookup two character string in string table. If it is not found |
- // just allocate a new one. |
- Label make_two_character_string; |
- StringHelper::GenerateTwoCharacterStringTableProbe( |
- masm, r2, r3, r6, r0, r4, r5, r9, &make_two_character_string); |
- __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
- __ add(sp, sp, Operand(2 * kPointerSize)); |
- __ Ret(); |
- |
- __ bind(&make_two_character_string); |
- // Resulting string has length 2 and first chars of two strings |
- // are combined into single halfword in r2 register. |
- // So we can fill resulting string without two loops by a single |
- // halfword store instruction (which assumes that processor is |
- // in a little endian mode) |
- __ mov(r6, Operand(2)); |
- __ AllocateAsciiString(r0, r6, r4, r5, r9, &call_runtime); |
- __ strh(r2, FieldMemOperand(r0, SeqOneByteString::kHeaderSize)); |
- __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
- __ add(sp, sp, Operand(2 * kPointerSize)); |
- __ Ret(); |
- |
- __ bind(&longer_than_two); |
- // Check if resulting string will be flat. |
- __ cmp(r6, Operand(ConsString::kMinLength)); |
- __ b(lt, &string_add_flat_result); |
- // Handle exceptionally long strings in the runtime system. |
- STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0); |
- ASSERT(IsPowerOf2(String::kMaxLength + 1)); |
- // kMaxLength + 1 is representable as shifted literal, kMaxLength is not. |
- __ cmp(r6, Operand(String::kMaxLength + 1)); |
- __ b(hs, &call_runtime); |
- |
- // If result is not supposed to be flat, allocate a cons string object. |
- // If both strings are ASCII the result is an ASCII cons string. |
- if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) { |
- __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
- __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
- __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
- __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
- } |
- Label non_ascii, allocated, ascii_data; |
- STATIC_ASSERT(kTwoByteStringTag == 0); |
- __ tst(r4, Operand(kStringEncodingMask)); |
- __ tst(r5, Operand(kStringEncodingMask), ne); |
- __ b(eq, &non_ascii); |
- |
- // Allocate an ASCII cons string. |
- __ bind(&ascii_data); |
- __ AllocateAsciiConsString(r3, r6, r4, r5, &call_runtime); |
- __ bind(&allocated); |
- // Fill the fields of the cons string. |
- Label skip_write_barrier, after_writing; |
- ExternalReference high_promotion_mode = ExternalReference:: |
- new_space_high_promotion_mode_active_address(masm->isolate()); |
- __ mov(r4, Operand(high_promotion_mode)); |
- __ ldr(r4, MemOperand(r4, 0)); |
- __ cmp(r4, Operand::Zero()); |
- __ b(eq, &skip_write_barrier); |
- |
- __ str(r0, FieldMemOperand(r3, ConsString::kFirstOffset)); |
- __ RecordWriteField(r3, |
- ConsString::kFirstOffset, |
- r0, |
- r4, |
- kLRHasNotBeenSaved, |
- kDontSaveFPRegs); |
- __ str(r1, FieldMemOperand(r3, ConsString::kSecondOffset)); |
- __ RecordWriteField(r3, |
- ConsString::kSecondOffset, |
- r1, |
- r4, |
- kLRHasNotBeenSaved, |
- kDontSaveFPRegs); |
- __ jmp(&after_writing); |
- |
- __ bind(&skip_write_barrier); |
- __ str(r0, FieldMemOperand(r3, ConsString::kFirstOffset)); |
- __ str(r1, FieldMemOperand(r3, ConsString::kSecondOffset)); |
- |
- __ bind(&after_writing); |
- |
- __ mov(r0, Operand(r3)); |
- __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
- __ add(sp, sp, Operand(2 * kPointerSize)); |
- __ Ret(); |
- |
- __ bind(&non_ascii); |
- // At least one of the strings is two-byte. Check whether it happens |
- // to contain only one byte characters. |
- // r4: first instance type. |
- // r5: second instance type. |
- __ tst(r4, Operand(kOneByteDataHintMask)); |
- __ tst(r5, Operand(kOneByteDataHintMask), ne); |
- __ b(ne, &ascii_data); |
- __ eor(r4, r4, Operand(r5)); |
- STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
- __ and_(r4, r4, Operand(kOneByteStringTag | kOneByteDataHintTag)); |
- __ cmp(r4, Operand(kOneByteStringTag | kOneByteDataHintTag)); |
- __ b(eq, &ascii_data); |
- |
- // Allocate a two byte cons string. |
- __ AllocateTwoByteConsString(r3, r6, r4, r5, &call_runtime); |
- __ jmp(&allocated); |
- |
- // We cannot encounter sliced strings or cons strings here since: |
- STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
- // Handle creating a flat result from either external or sequential strings. |
- // Locate the first characters' locations. |
- // r0: first string |
- // r1: second string |
- // r2: length of first string |
- // r3: length of second string |
- // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
- // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
- // r6: sum of lengths. |
- Label first_prepared, second_prepared; |
- __ bind(&string_add_flat_result); |
- if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) { |
- __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
- __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
- __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
- __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
- } |
- |
- // Check whether both strings have same encoding |
- __ eor(ip, r4, Operand(r5)); |
- ASSERT(__ ImmediateFitsAddrMode1Instruction(kStringEncodingMask)); |
- __ tst(ip, Operand(kStringEncodingMask)); |
- __ b(ne, &call_runtime); |
- |
- STATIC_ASSERT(kSeqStringTag == 0); |
- __ tst(r4, Operand(kStringRepresentationMask)); |
- STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
- __ add(r6, |
- r0, |
- Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag), |
- LeaveCC, |
- eq); |
- __ b(eq, &first_prepared); |
- // External string: rule out short external string and load string resource. |
- STATIC_ASSERT(kShortExternalStringTag != 0); |
- __ tst(r4, Operand(kShortExternalStringMask)); |
- __ b(ne, &call_runtime); |
- __ ldr(r6, FieldMemOperand(r0, ExternalString::kResourceDataOffset)); |
- __ bind(&first_prepared); |
- |
- STATIC_ASSERT(kSeqStringTag == 0); |
- __ tst(r5, Operand(kStringRepresentationMask)); |
- STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
- __ add(r1, |
- r1, |
- Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag), |
- LeaveCC, |
- eq); |
- __ b(eq, &second_prepared); |
- // External string: rule out short external string and load string resource. |
- STATIC_ASSERT(kShortExternalStringTag != 0); |
- __ tst(r5, Operand(kShortExternalStringMask)); |
- __ b(ne, &call_runtime); |
- __ ldr(r1, FieldMemOperand(r1, ExternalString::kResourceDataOffset)); |
- __ bind(&second_prepared); |
- |
- Label non_ascii_string_add_flat_result; |
- // r6: first character of first string |
- // r1: first character of second string |
- // r2: length of first string. |
- // r3: length of second string. |
- // Both strings have the same encoding. |
- STATIC_ASSERT(kTwoByteStringTag == 0); |
- __ tst(r5, Operand(kStringEncodingMask)); |
- __ b(eq, &non_ascii_string_add_flat_result); |
- |
- __ add(r2, r2, Operand(r3)); |
- __ AllocateAsciiString(r0, r2, r4, r5, r9, &call_runtime); |
- __ sub(r2, r2, Operand(r3)); |
- __ add(r5, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
- // r0: result string. |
- // r6: first character of first string. |
- // r1: first character of second string. |
- // r2: length of first string. |
- // r3: length of second string. |
- // r5: first character of result. |
- StringHelper::GenerateCopyCharacters(masm, r5, r6, r2, r4, true); |
- // r5: next character of result. |
- StringHelper::GenerateCopyCharacters(masm, r5, r1, r3, r4, true); |
- __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
- __ add(sp, sp, Operand(2 * kPointerSize)); |
- __ Ret(); |
- |
- __ bind(&non_ascii_string_add_flat_result); |
- __ add(r2, r2, Operand(r3)); |
- __ AllocateTwoByteString(r0, r2, r4, r5, r9, &call_runtime); |
- __ sub(r2, r2, Operand(r3)); |
- __ add(r5, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
- // r0: result string. |
- // r6: first character of first string. |
- // r1: first character of second string. |
- // r2: length of first string. |
- // r3: length of second string. |
- // r5: first character of result. |
- StringHelper::GenerateCopyCharacters(masm, r5, r6, r2, r4, false); |
- // r5: next character of result. |
- StringHelper::GenerateCopyCharacters(masm, r5, r1, r3, r4, false); |
- __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
- __ add(sp, sp, Operand(2 * kPointerSize)); |
- __ Ret(); |
- |
- // Just jump to runtime to add the two strings. |
- __ bind(&call_runtime); |
- __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
- |
- if (call_builtin.is_linked()) { |
- __ bind(&call_builtin); |
- __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
- } |
-} |
- |
- |
-void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
- __ push(r0); |
- __ push(r1); |
-} |
- |
- |
-void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm) { |
- __ pop(r1); |
- __ pop(r0); |
-} |
- |
- |
-void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
- int stack_offset, |
- Register arg, |
- Register scratch1, |
- Register scratch2, |
- Register scratch3, |
- Register scratch4, |
- Label* slow) { |
- // First check if the argument is already a string. |
- Label not_string, done; |
- __ JumpIfSmi(arg, ¬_string); |
- __ CompareObjectType(arg, scratch1, scratch1, FIRST_NONSTRING_TYPE); |
- __ b(lt, &done); |
- |
- // Check the number to string cache. |
- __ bind(¬_string); |
- // Puts the cached result into scratch1. |
- __ LookupNumberStringCache(arg, scratch1, scratch2, scratch3, scratch4, slow); |
- __ mov(arg, scratch1); |
- __ str(arg, MemOperand(sp, stack_offset)); |
- __ bind(&done); |
-} |
- |
- |
void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
ASSERT(state_ == CompareIC::SMI); |
Label miss; |