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

Side by Side Diff: src/arm/code-stubs-arm.cc

Issue 8510005: Simplify StringCharCodeAt in non-crankshaft codegen. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/arm/full-codegen-arm.cc » ('j') | src/ia32/code-stubs-ia32.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5040 matching lines...) Expand 10 before | Expand all | Expand 10 after
5051 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); 5051 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
5052 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); 5052 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
5053 // If the receiver is not a string trigger the non-string case. 5053 // If the receiver is not a string trigger the non-string case.
5054 __ tst(result_, Operand(kIsNotStringMask)); 5054 __ tst(result_, Operand(kIsNotStringMask));
5055 __ b(ne, receiver_not_string_); 5055 __ b(ne, receiver_not_string_);
5056 5056
5057 // If the index is non-smi trigger the non-smi case. 5057 // If the index is non-smi trigger the non-smi case.
5058 __ JumpIfNotSmi(index_, &index_not_smi_); 5058 __ JumpIfNotSmi(index_, &index_not_smi_);
5059 5059
5060 // Put smi-tagged index into scratch register. 5060 // Put smi-tagged index into scratch register.
5061 __ mov(scratch_, index_);
5062 __ bind(&got_smi_index_); 5061 __ bind(&got_smi_index_);
5063 5062
5064 // Check for index out of range. 5063 // Check for index out of range.
5065 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset)); 5064 __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset));
5066 __ cmp(ip, Operand(scratch_)); 5065 __ cmp(ip, Operand(index_));
5067 __ b(ls, index_out_of_range_); 5066 __ b(ls, index_out_of_range_);
5068 5067
5069 // We need special handling for non-flat strings. 5068 // We need special handling for non-flat strings.
5070 STATIC_ASSERT(kSeqStringTag == 0); 5069 STATIC_ASSERT(kSeqStringTag == 0);
5071 __ tst(result_, Operand(kStringRepresentationMask)); 5070 __ tst(result_, Operand(kStringRepresentationMask));
5072 __ b(eq, &flat_string); 5071 __ b(eq, &flat_string);
5073 5072
5074 // Handle non-flat strings. 5073 // Handle non-flat strings.
5075 __ and_(result_, result_, Operand(kStringRepresentationMask)); 5074 __ and_(result_, result_, Operand(kStringRepresentationMask));
5076 STATIC_ASSERT(kConsStringTag < kExternalStringTag); 5075 STATIC_ASSERT(kConsStringTag < kExternalStringTag);
5077 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); 5076 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
5078 __ cmp(result_, Operand(kExternalStringTag)); 5077 __ cmp(result_, Operand(kExternalStringTag));
5079 __ b(gt, &sliced_string); 5078 __ b(gt, &sliced_string);
5080 __ b(eq, &call_runtime_); 5079 __ b(eq, &call_runtime_);
5081 5080
5082 // ConsString. 5081 // ConsString.
5083 // Check whether the right hand side is the empty string (i.e. if 5082 // Check whether the right hand side is the empty string (i.e. if
5084 // this is really a flat string in a cons string). If that is not 5083 // this is really a flat string in a cons string). If that is not
5085 // the case we would rather go to the runtime system now to flatten 5084 // the case we would rather go to the runtime system now to flatten
5086 // the string. 5085 // the string.
5087 Label assure_seq_string; 5086 Label assure_seq_string;
5088 __ ldr(result_, FieldMemOperand(object_, ConsString::kSecondOffset)); 5087 __ ldr(result_, FieldMemOperand(object_, ConsString::kSecondOffset));
5089 __ LoadRoot(ip, Heap::kEmptyStringRootIndex); 5088 __ LoadRoot(ip, Heap::kEmptyStringRootIndex);
5090 __ cmp(result_, Operand(ip)); 5089 __ cmp(result_, Operand(ip));
5091 __ b(ne, &call_runtime_); 5090 __ b(ne, &call_runtime_);
5092 // Get the first of the two strings and load its instance type. 5091 // Get the first of the two parts.
5093 __ ldr(result_, FieldMemOperand(object_, ConsString::kFirstOffset)); 5092 __ ldr(object_, FieldMemOperand(object_, ConsString::kFirstOffset));
5094 __ jmp(&assure_seq_string); 5093 __ jmp(&assure_seq_string);
5095 5094
5096 // SlicedString, unpack and add offset. 5095 // SlicedString, unpack and add offset.
5097 __ bind(&sliced_string); 5096 __ bind(&sliced_string);
5098 __ ldr(result_, FieldMemOperand(object_, SlicedString::kOffsetOffset)); 5097 __ ldr(result_, FieldMemOperand(object_, SlicedString::kOffsetOffset));
5099 __ add(scratch_, scratch_, result_); 5098 __ add(index_, index_, result_);
5100 __ ldr(result_, FieldMemOperand(object_, SlicedString::kParentOffset)); 5099 __ ldr(object_, FieldMemOperand(object_, SlicedString::kParentOffset));
5101 5100
5102 // Assure that we are dealing with a sequential string. Go to runtime if not. 5101 // Assure that we are dealing with a sequential string. Go to runtime if not.
5103 __ bind(&assure_seq_string); 5102 __ bind(&assure_seq_string);
5104 __ ldr(result_, FieldMemOperand(result_, HeapObject::kMapOffset)); 5103 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
5105 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); 5104 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
5106 // Check that parent is not an external string. Go to runtime otherwise. 5105 // Check that parent is not an external string. Go to runtime otherwise.
5106 // Note that if the original string is a cons or slice with an external
5107 // string as underlying string, we pass that unpacked underlying string with
5108 // the updated index to the runtime function.
5107 STATIC_ASSERT(kSeqStringTag == 0); 5109 STATIC_ASSERT(kSeqStringTag == 0);
5108 __ tst(result_, Operand(kStringRepresentationMask)); 5110 __ tst(result_, Operand(kStringRepresentationMask));
5109 __ b(ne, &call_runtime_); 5111 __ b(ne, &call_runtime_);
5110 // Actually fetch the parent string if it is confirmed to be sequential.
5111 STATIC_ASSERT(SlicedString::kParentOffset == ConsString::kFirstOffset);
5112 __ ldr(object_, FieldMemOperand(object_, SlicedString::kParentOffset));
5113 5112
5114 // Check for 1-byte or 2-byte string. 5113 // Check for 1-byte or 2-byte string.
5115 __ bind(&flat_string); 5114 __ bind(&flat_string);
5116 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); 5115 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0);
5117 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); 5116 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
5118 __ tst(result_, Operand(kStringEncodingMask)); 5117 __ tst(result_, Operand(kStringEncodingMask));
5119 __ b(ne, &ascii_string); 5118 __ b(ne, &ascii_string);
5120 5119
5121 // 2-byte string. 5120 // 2-byte string.
5122 // Load the 2-byte character code into the result register. We can 5121 // Load the 2-byte character code into the result register. We can
5123 // add without shifting since the smi tag size is the log2 of the 5122 // add without shifting since the smi tag size is the log2 of the
5124 // number of bytes in a two-byte character. 5123 // number of bytes in a two-byte character.
5125 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1 && kSmiShiftSize == 0); 5124 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1 && kSmiShiftSize == 0);
5126 __ add(scratch_, object_, Operand(scratch_)); 5125 __ add(index_, object_, Operand(index_));
5127 __ ldrh(result_, FieldMemOperand(scratch_, SeqTwoByteString::kHeaderSize)); 5126 __ ldrh(result_, FieldMemOperand(index_, SeqTwoByteString::kHeaderSize));
5128 __ jmp(&got_char_code); 5127 __ jmp(&got_char_code);
5129 5128
5130 // ASCII string. 5129 // ASCII string.
5131 // Load the byte into the result register. 5130 // Load the byte into the result register.
5132 __ bind(&ascii_string); 5131 __ bind(&ascii_string);
5133 __ add(scratch_, object_, Operand(scratch_, LSR, kSmiTagSize)); 5132 __ add(index_, object_, Operand(index_, LSR, kSmiTagSize));
5134 __ ldrb(result_, FieldMemOperand(scratch_, SeqAsciiString::kHeaderSize)); 5133 __ ldrb(result_, FieldMemOperand(index_, SeqAsciiString::kHeaderSize));
5135 5134
5136 __ bind(&got_char_code); 5135 __ bind(&got_char_code);
5137 __ mov(result_, Operand(result_, LSL, kSmiTagSize)); 5136 __ mov(result_, Operand(result_, LSL, kSmiTagSize));
5138 __ bind(&exit_); 5137 __ bind(&exit_);
5139 } 5138 }
5140 5139
5141 5140
5142 void StringCharCodeAtGenerator::GenerateSlow( 5141 void StringCharCodeAtGenerator::GenerateSlow(
5143 MacroAssembler* masm, 5142 MacroAssembler* masm,
5144 const RuntimeCallHelper& call_helper) { 5143 const RuntimeCallHelper& call_helper) {
5145 __ Abort("Unexpected fallthrough to CharCodeAt slow case"); 5144 __ Abort("Unexpected fallthrough to CharCodeAt slow case");
5146 5145
5147 // Index is not a smi. 5146 // Index is not a smi.
5148 __ bind(&index_not_smi_); 5147 __ bind(&index_not_smi_);
5149 // If index is a heap number, try converting it to an integer. 5148 // If index is a heap number, try converting it to an integer.
5150 __ CheckMap(index_, 5149 __ CheckMap(index_,
5151 scratch_, 5150 result_,
5152 Heap::kHeapNumberMapRootIndex, 5151 Heap::kHeapNumberMapRootIndex,
5153 index_not_number_, 5152 index_not_number_,
5154 DONT_DO_SMI_CHECK); 5153 DONT_DO_SMI_CHECK);
5155 call_helper.BeforeCall(masm); 5154 call_helper.BeforeCall(masm);
5156 __ Push(object_, index_); 5155 __ push(object_);
5157 __ push(index_); // Consumed by runtime conversion function. 5156 __ push(index_); // Consumed by runtime conversion function.
5158 if (index_flags_ == STRING_INDEX_IS_NUMBER) { 5157 if (index_flags_ == STRING_INDEX_IS_NUMBER) {
5159 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); 5158 __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
5160 } else { 5159 } else {
5161 ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); 5160 ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
5162 // NumberToSmi discards numbers that are not exact integers. 5161 // NumberToSmi discards numbers that are not exact integers.
5163 __ CallRuntime(Runtime::kNumberToSmi, 1); 5162 __ CallRuntime(Runtime::kNumberToSmi, 1);
5164 } 5163 }
5165 // Save the conversion result before the pop instructions below 5164 // Save the conversion result before the pop instructions below
5166 // have a chance to overwrite it. 5165 // have a chance to overwrite it.
5167 __ Move(scratch_, r0); 5166 __ Move(index_, r0);
5168 __ pop(index_);
5169 __ pop(object_); 5167 __ pop(object_);
5170 // Reload the instance type. 5168 // Reload the instance type.
5171 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); 5169 __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset));
5172 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); 5170 __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset));
5173 call_helper.AfterCall(masm); 5171 call_helper.AfterCall(masm);
5174 // If index is still not a smi, it must be out of range. 5172 // If index is still not a smi, it must be out of range.
5175 __ JumpIfNotSmi(scratch_, index_out_of_range_); 5173 __ JumpIfNotSmi(index_, index_out_of_range_);
5176 // Otherwise, return to the fast path. 5174 // Otherwise, return to the fast path.
5177 __ jmp(&got_smi_index_); 5175 __ jmp(&got_smi_index_);
5178 5176
5179 // Call runtime. We get here when the receiver is a string and the 5177 // Call runtime. We get here when the receiver is a string and the
5180 // index is a number, but the code of getting the actual character 5178 // index is a number, but the code of getting the actual character
5181 // is too complex (e.g., when the string needs to be flattened). 5179 // is too complex (e.g., when the string needs to be flattened).
5182 __ bind(&call_runtime_); 5180 __ bind(&call_runtime_);
5183 call_helper.BeforeCall(masm); 5181 call_helper.BeforeCall(masm);
5184 __ Push(object_, index_); 5182 __ Push(object_, index_);
5185 __ CallRuntime(Runtime::kStringCharCodeAt, 2); 5183 __ CallRuntime(Runtime::kStringCharCodeAt, 2);
(...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after
7185 __ bind(&need_incremental); 7183 __ bind(&need_incremental);
7186 7184
7187 // Fall through when we need to inform the incremental marker. 7185 // Fall through when we need to inform the incremental marker.
7188 } 7186 }
7189 7187
7190 #undef __ 7188 #undef __
7191 7189
7192 } } // namespace v8::internal 7190 } } // namespace v8::internal
7193 7191
7194 #endif // V8_TARGET_ARCH_ARM 7192 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | src/arm/full-codegen-arm.cc » ('j') | src/ia32/code-stubs-ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698