| OLD | NEW |
| 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 5071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5082 if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); | 5082 if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); |
| 5083 if (!include_number_compare_) stream->Add("_NO_NUMBER"); | 5083 if (!include_number_compare_) stream->Add("_NO_NUMBER"); |
| 5084 if (!include_smi_compare_) stream->Add("_NO_SMI"); | 5084 if (!include_smi_compare_) stream->Add("_NO_SMI"); |
| 5085 } | 5085 } |
| 5086 | 5086 |
| 5087 | 5087 |
| 5088 // ------------------------------------------------------------------------- | 5088 // ------------------------------------------------------------------------- |
| 5089 // StringCharCodeAtGenerator | 5089 // StringCharCodeAtGenerator |
| 5090 | 5090 |
| 5091 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { | 5091 void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5092 Label flat_string; | |
| 5093 Label ascii_string; | |
| 5094 Label got_char_code; | |
| 5095 Label sliced_string; | |
| 5096 | |
| 5097 // If the receiver is a smi trigger the non-string case. | 5092 // If the receiver is a smi trigger the non-string case. |
| 5098 STATIC_ASSERT(kSmiTag == 0); | 5093 STATIC_ASSERT(kSmiTag == 0); |
| 5099 __ JumpIfSmi(object_, receiver_not_string_); | 5094 __ JumpIfSmi(object_, receiver_not_string_); |
| 5100 | 5095 |
| 5101 // Fetch the instance type of the receiver into result register. | 5096 // Fetch the instance type of the receiver into result register. |
| 5102 __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); | 5097 __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5103 __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); | 5098 __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5104 // If the receiver is not a string trigger the non-string case. | 5099 // If the receiver is not a string trigger the non-string case. |
| 5105 __ test(result_, Immediate(kIsNotStringMask)); | 5100 __ test(result_, Immediate(kIsNotStringMask)); |
| 5106 __ j(not_zero, receiver_not_string_); | 5101 __ j(not_zero, receiver_not_string_); |
| 5107 | 5102 |
| 5108 // If the index is non-smi trigger the non-smi case. | 5103 // If the index is non-smi trigger the non-smi case. |
| 5109 STATIC_ASSERT(kSmiTag == 0); | 5104 STATIC_ASSERT(kSmiTag == 0); |
| 5110 __ JumpIfNotSmi(index_, &index_not_smi_); | 5105 __ JumpIfNotSmi(index_, &index_not_smi_); |
| 5111 __ bind(&got_smi_index_); | 5106 __ bind(&got_smi_index_); |
| 5112 | 5107 |
| 5113 // Check for index out of range. | 5108 // Check for index out of range. |
| 5114 __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); | 5109 __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
| 5115 __ j(above_equal, index_out_of_range_); | 5110 __ j(above_equal, index_out_of_range_); |
| 5116 | 5111 |
| 5117 // We need special handling for non-flat strings. | 5112 __ SmiUntag(index_); |
| 5118 STATIC_ASSERT(kSeqStringTag == 0); | |
| 5119 __ test(result_, Immediate(kStringRepresentationMask)); | |
| 5120 __ j(zero, &flat_string); | |
| 5121 | 5113 |
| 5122 // Handle non-flat strings. | 5114 Factory* factory = masm->isolate()->factory(); |
| 5123 __ and_(result_, kStringRepresentationMask); | 5115 GenerateCharLoad(masm, factory, object_, index_, result_, &call_runtime_); |
| 5124 STATIC_ASSERT(kConsStringTag < kExternalStringTag); | |
| 5125 STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); | |
| 5126 __ cmp(result_, kExternalStringTag); | |
| 5127 __ j(greater, &sliced_string, Label::kNear); | |
| 5128 __ j(equal, &call_runtime_); | |
| 5129 | 5116 |
| 5130 // ConsString. | |
| 5131 // Check whether the right hand side is the empty string (i.e. if | |
| 5132 // this is really a flat string in a cons string). If that is not | |
| 5133 // the case we would rather go to the runtime system now to flatten | |
| 5134 // the string. | |
| 5135 Label assure_seq_string; | |
| 5136 __ cmp(FieldOperand(object_, ConsString::kSecondOffset), | |
| 5137 Immediate(masm->isolate()->factory()->empty_string())); | |
| 5138 __ j(not_equal, &call_runtime_); | |
| 5139 // Get the first of the two parts. | |
| 5140 __ mov(object_, FieldOperand(object_, ConsString::kFirstOffset)); | |
| 5141 __ jmp(&assure_seq_string, Label::kNear); | |
| 5142 | |
| 5143 // SlicedString, unpack and add offset. | |
| 5144 __ bind(&sliced_string); | |
| 5145 __ add(index_, FieldOperand(object_, SlicedString::kOffsetOffset)); | |
| 5146 __ mov(object_, FieldOperand(object_, SlicedString::kParentOffset)); | |
| 5147 | |
| 5148 // Assure that we are dealing with a sequential string. Go to runtime if not. | |
| 5149 // Note that if the original string is a cons or slice with an external | |
| 5150 // string as underlying string, we pass that unpacked underlying string with | |
| 5151 // the adjusted index to the runtime function. | |
| 5152 __ bind(&assure_seq_string); | |
| 5153 __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); | |
| 5154 __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); | |
| 5155 STATIC_ASSERT(kSeqStringTag == 0); | |
| 5156 __ test(result_, Immediate(kStringRepresentationMask)); | |
| 5157 __ j(not_zero, &call_runtime_); | |
| 5158 | |
| 5159 // Check for 1-byte or 2-byte string. | |
| 5160 __ bind(&flat_string); | |
| 5161 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); | |
| 5162 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); | |
| 5163 __ test(result_, Immediate(kStringEncodingMask)); | |
| 5164 __ j(not_zero, &ascii_string, Label::kNear); | |
| 5165 | |
| 5166 // 2-byte string. | |
| 5167 // Load the 2-byte character code into the result register. | |
| 5168 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); | |
| 5169 __ movzx_w(result_, FieldOperand(object_, | |
| 5170 index_, times_1, // Scratch is smi-tagged. | |
| 5171 SeqTwoByteString::kHeaderSize)); | |
| 5172 __ jmp(&got_char_code, Label::kNear); | |
| 5173 | |
| 5174 // ASCII string. | |
| 5175 // Load the byte into the result register. | |
| 5176 __ bind(&ascii_string); | |
| 5177 __ SmiUntag(index_); | |
| 5178 __ movzx_b(result_, FieldOperand(object_, | |
| 5179 index_, times_1, | |
| 5180 SeqAsciiString::kHeaderSize)); | |
| 5181 __ bind(&got_char_code); | |
| 5182 __ SmiTag(result_); | 5117 __ SmiTag(result_); |
| 5183 __ bind(&exit_); | 5118 __ bind(&exit_); |
| 5184 } | 5119 } |
| 5185 | 5120 |
| 5186 | 5121 |
| 5122 void StringCharCodeAtGenerator::GenerateCharLoad(MacroAssembler* masm, |
| 5123 Factory* factory, |
| 5124 Register string, |
| 5125 Register index, |
| 5126 Register result, |
| 5127 Label* call_runtime) { |
| 5128 // Fetch the instance type of the receiver into result register. |
| 5129 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); |
| 5130 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); |
| 5131 |
| 5132 // We need special handling for indirect strings. |
| 5133 Label check_sequential; |
| 5134 __ test(result, Immediate(kIsIndirectStringMask)); |
| 5135 __ j(zero, &check_sequential); |
| 5136 |
| 5137 // Dispatch on the indirect string shape: slice or cons. |
| 5138 Label cons_string; |
| 5139 __ test(result, Immediate(kSlicedNotConsMask)); |
| 5140 __ j(zero, &cons_string); |
| 5141 |
| 5142 // Handle slices. |
| 5143 Label indirect_string_loaded; |
| 5144 __ mov(result, FieldOperand(string, SlicedString::kOffsetOffset)); |
| 5145 __ SmiUntag(result); |
| 5146 __ add(index, result); |
| 5147 __ mov(string, FieldOperand(string, SlicedString::kParentOffset)); |
| 5148 __ jmp(&indirect_string_loaded); |
| 5149 |
| 5150 // Handle external strings. |
| 5151 Label external_string, two_byte_external, done, revert_index_call_runtime; |
| 5152 __ bind(&external_string); |
| 5153 if (FLAG_debug_code) { |
| 5154 // Assert that we do not have a cons or slice (indirect strings) here. |
| 5155 __ test(result, Immediate(kIsIndirectStringMask)); |
| 5156 __ Assert(zero, "external string expected, but not found"); |
| 5157 } |
| 5158 __ test(result, Immediate(kBufferedStringMask)); |
| 5159 __ j(zero, call_runtime); |
| 5160 __ mov(result, FieldOperand(string, ExternalString::kBufferIndexOffset)); |
| 5161 __ SmiUntag(result); |
| 5162 __ sub(index, result); |
| 5163 __ j(negative, &revert_index_call_runtime); |
| 5164 |
| 5165 __ cmp(FieldOperand(string, HeapObject::kMapOffset), |
| 5166 Immediate(factory->external_buffered_string_map())); |
| 5167 __ j(equal, &two_byte_external, Label::kNear); |
| 5168 __ cmp(FieldOperand(string, HeapObject::kMapOffset), |
| 5169 Immediate(factory->external_buffered_symbol_map())); |
| 5170 __ j(equal, &two_byte_external, Label::kNear); |
| 5171 |
| 5172 // Ascii string. |
| 5173 __ cmp(index, Immediate(ExternalAsciiString::kBufferedChars)); |
| 5174 __ j(greater_equal, &revert_index_call_runtime); |
| 5175 __ movzx_b(result, FieldOperand(string, |
| 5176 index, |
| 5177 times_1, |
| 5178 ExternalString::kBufferContentOffset)); |
| 5179 __ jmp(&done); |
| 5180 |
| 5181 __ bind(&two_byte_external); |
| 5182 // Two-byte string. |
| 5183 __ cmp(index, Immediate(ExternalTwoByteString::kBufferedChars)); |
| 5184 __ j(greater_equal, &revert_index_call_runtime); |
| 5185 __ movzx_w(result, FieldOperand(string, |
| 5186 index, |
| 5187 times_2, |
| 5188 ExternalString::kBufferContentOffset)); |
| 5189 __ jmp(&done); |
| 5190 __ bind(&revert_index_call_runtime); |
| 5191 __ add(index, result); |
| 5192 __ jmp(call_runtime); |
| 5193 |
| 5194 // Handle conses. |
| 5195 // Check whether the right hand side is the empty string (i.e. if |
| 5196 // this is really a flat string in a cons string). If that is not |
| 5197 // the case we would rather go to the runtime system now to flatten |
| 5198 // the string. |
| 5199 __ bind(&cons_string); |
| 5200 __ cmp(FieldOperand(string, ConsString::kSecondOffset), |
| 5201 Immediate(factory->empty_string())); |
| 5202 __ j(not_equal, call_runtime); |
| 5203 __ mov(string, FieldOperand(string, ConsString::kFirstOffset)); |
| 5204 |
| 5205 __ bind(&indirect_string_loaded); |
| 5206 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); |
| 5207 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); |
| 5208 |
| 5209 // Check whether the string is sequential. The only non-sequential |
| 5210 // shapes we support have just been unwrapped above. |
| 5211 // Note that if the original string is a cons or slice with an external |
| 5212 // string as underlying string, we pass that unpacked underlying string with |
| 5213 // the adjusted index to the runtime function. |
| 5214 __ bind(&check_sequential); |
| 5215 STATIC_ASSERT(kSeqStringTag == 0); |
| 5216 __ test(result, Immediate(kStringRepresentationMask)); |
| 5217 __ j(not_zero, &external_string); |
| 5218 |
| 5219 // Dispatch on the encoding: ASCII or two-byte. |
| 5220 Label ascii_string; |
| 5221 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); |
| 5222 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5223 __ test(result, Immediate(kStringEncodingMask)); |
| 5224 __ j(not_zero, &ascii_string, Label::kNear); |
| 5225 |
| 5226 // Two-byte string. |
| 5227 // Load the two-byte character code into the result register. |
| 5228 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 5229 __ movzx_w(result, FieldOperand(string, |
| 5230 index, |
| 5231 times_2, |
| 5232 SeqTwoByteString::kHeaderSize)); |
| 5233 __ jmp(&done, Label::kNear); |
| 5234 |
| 5235 // Ascii string. |
| 5236 // Load the byte into the result register. |
| 5237 __ bind(&ascii_string); |
| 5238 __ movzx_b(result, FieldOperand(string, |
| 5239 index, |
| 5240 times_1, |
| 5241 SeqAsciiString::kHeaderSize)); |
| 5242 __ bind(&done); |
| 5243 } |
| 5244 |
| 5245 |
| 5187 void StringCharCodeAtGenerator::GenerateSlow( | 5246 void StringCharCodeAtGenerator::GenerateSlow( |
| 5188 MacroAssembler* masm, | 5247 MacroAssembler* masm, |
| 5189 const RuntimeCallHelper& call_helper) { | 5248 const RuntimeCallHelper& call_helper) { |
| 5190 __ Abort("Unexpected fallthrough to CharCodeAt slow case"); | 5249 __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5191 | 5250 |
| 5192 // Index is not a smi. | 5251 // Index is not a smi. |
| 5193 __ bind(&index_not_smi_); | 5252 __ bind(&index_not_smi_); |
| 5194 // If index is a heap number, try converting it to an integer. | 5253 // If index is a heap number, try converting it to an integer. |
| 5195 __ CheckMap(index_, | 5254 __ CheckMap(index_, |
| 5196 masm->isolate()->factory()->heap_number_map(), | 5255 masm->isolate()->factory()->heap_number_map(), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 5221 __ JumpIfNotSmi(index_, index_out_of_range_); | 5280 __ JumpIfNotSmi(index_, index_out_of_range_); |
| 5222 // Otherwise, return to the fast path. | 5281 // Otherwise, return to the fast path. |
| 5223 __ jmp(&got_smi_index_); | 5282 __ jmp(&got_smi_index_); |
| 5224 | 5283 |
| 5225 // Call runtime. We get here when the receiver is a string and the | 5284 // Call runtime. We get here when the receiver is a string and the |
| 5226 // index is a number, but the code of getting the actual character | 5285 // index is a number, but the code of getting the actual character |
| 5227 // is too complex (e.g., when the string needs to be flattened). | 5286 // is too complex (e.g., when the string needs to be flattened). |
| 5228 __ bind(&call_runtime_); | 5287 __ bind(&call_runtime_); |
| 5229 call_helper.BeforeCall(masm); | 5288 call_helper.BeforeCall(masm); |
| 5230 __ push(object_); | 5289 __ push(object_); |
| 5290 __ SmiTag(index_); |
| 5231 __ push(index_); | 5291 __ push(index_); |
| 5232 __ CallRuntime(Runtime::kStringCharCodeAt, 2); | 5292 __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5233 if (!result_.is(eax)) { | 5293 if (!result_.is(eax)) { |
| 5234 __ mov(result_, eax); | 5294 __ mov(result_, eax); |
| 5235 } | 5295 } |
| 5236 call_helper.AfterCall(masm); | 5296 call_helper.AfterCall(masm); |
| 5237 __ jmp(&exit_); | 5297 __ jmp(&exit_); |
| 5238 | 5298 |
| 5239 __ Abort("Unexpected fallthrough from CharCodeAt slow case"); | 5299 __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5240 } | 5300 } |
| (...skipping 1866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7107 false); | 7167 false); |
| 7108 __ pop(edx); | 7168 __ pop(edx); |
| 7109 __ ret(0); | 7169 __ ret(0); |
| 7110 } | 7170 } |
| 7111 | 7171 |
| 7112 #undef __ | 7172 #undef __ |
| 7113 | 7173 |
| 7114 } } // namespace v8::internal | 7174 } } // namespace v8::internal |
| 7115 | 7175 |
| 7116 #endif // V8_TARGET_ARCH_IA32 | 7176 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |