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 3121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3132 public: | 3132 public: |
3133 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) | 3133 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
3134 : LDeferredCode(codegen), instr_(instr) { } | 3134 : LDeferredCode(codegen), instr_(instr) { } |
3135 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } | 3135 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
3136 private: | 3136 private: |
3137 LStringCharCodeAt* instr_; | 3137 LStringCharCodeAt* instr_; |
3138 }; | 3138 }; |
3139 | 3139 |
3140 Register string = ToRegister(instr->string()); | 3140 Register string = ToRegister(instr->string()); |
3141 Register index = no_reg; | 3141 Register index = no_reg; |
3142 Register offset = ToRegister(instr->TempAt(0)); | |
3142 int const_index = -1; | 3143 int const_index = -1; |
3143 if (instr->index()->IsConstantOperand()) { | 3144 if (instr->index()->IsConstantOperand()) { |
3144 const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 3145 const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
3145 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); | 3146 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
3146 if (!Smi::IsValid(const_index)) { | 3147 if (!Smi::IsValid(const_index)) { |
3147 // Guaranteed to be out of bounds because of the assert above. | 3148 // Guaranteed to be out of bounds because of the assert above. |
3148 // So the bounds check that must dominate this instruction must | 3149 // So the bounds check that must dominate this instruction must |
3149 // have deoptimized already. | 3150 // have deoptimized already. |
3150 if (FLAG_debug_code) { | 3151 if (FLAG_debug_code) { |
3151 __ Abort("StringCharCodeAt: out of bounds index."); | 3152 __ Abort("StringCharCodeAt: out of bounds index."); |
3152 } | 3153 } |
3153 // No code needs to be generated. | 3154 // No code needs to be generated. |
3154 return; | 3155 return; |
3155 } | 3156 } |
3156 } else { | 3157 } else { |
3157 index = ToRegister(instr->index()); | 3158 index = ToRegister(instr->index()); |
3158 } | 3159 } |
3159 Register result = ToRegister(instr->result()); | 3160 Register result = ToRegister(instr->result()); |
3160 | 3161 |
3161 DeferredStringCharCodeAt* deferred = | 3162 DeferredStringCharCodeAt* deferred = |
3162 new DeferredStringCharCodeAt(this, instr); | 3163 new DeferredStringCharCodeAt(this, instr); |
3163 | 3164 |
3164 Label flat_string, ascii_string, done; | 3165 Label flat_string, ascii_string, cons_string, sliced_ascii_string, done; |
3165 | 3166 |
3166 // Fetch the instance type of the receiver into result register. | 3167 // Fetch the instance type of the receiver into result register. |
3167 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); | 3168 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); |
3168 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); | 3169 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); |
3169 | 3170 |
3170 // We need special handling for non-flat strings. | 3171 // We need special handling for non-flat strings. |
3171 STATIC_ASSERT(kSeqStringTag == 0); | 3172 STATIC_ASSERT(kSeqStringTag == 0); |
3172 __ test(result, Immediate(kStringRepresentationMask)); | 3173 __ test(result, Immediate(kStringRepresentationMask)); |
3173 __ j(zero, &flat_string, Label::kNear); | 3174 __ j(zero, &flat_string, Label::kNear); |
3174 | 3175 |
3175 // Handle non-flat strings. | 3176 // Handle non-flat strings. |
3176 __ test(result, Immediate(kIsConsStringMask)); | 3177 __ and_(result, kStringRepresentationMask); |
Vitaly Repeshko
2011/08/05 12:14:14
Too much code now. Either put it behind the flag o
| |
3177 __ j(zero, deferred->entry()); | 3178 __ cmp(result, kConsStringTag); |
3179 __ j(equal, &cons_string, Label::kNear); | |
3180 __ cmp(result, kExternalStringTag); | |
3181 __ j(equal, deferred->entry()); | |
3182 | |
3183 // SlicedString. | |
3184 // Unpack slice, add offset and retrieve the result char. | |
3185 __ mov(offset, FieldOperand(string, SlicedString::kOffsetOffset)); | |
3186 __ SmiUntag(offset); | |
3187 if (instr->index()->IsConstantOperand()) { | |
3188 __ add(Operand(offset), Immediate(const_index)); | |
3189 } else { | |
3190 __ add(offset, Operand(index)); | |
3191 } | |
3192 __ mov(string, FieldOperand(string, SlicedString::kParentOffset)); | |
3193 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); | |
3194 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); | |
3195 // Check for ASCII or two-byte string. | |
3196 STATIC_ASSERT(kAsciiStringTag != 0); | |
3197 __ test(result, Immediate(kStringEncodingMask)); | |
3198 __ j(not_zero, &sliced_ascii_string, Label::kNear); | |
3199 __ movzx_w(result, FieldOperand(string, | |
3200 offset, | |
3201 times_2, | |
3202 SeqTwoByteString::kHeaderSize)); | |
3203 __ jmp(&done, Label::kNear); | |
3204 __ bind(&sliced_ascii_string); | |
3205 __ movzx_b(result, FieldOperand(string, | |
3206 offset, | |
3207 times_1, | |
3208 SeqAsciiString::kHeaderSize)); | |
3209 __ jmp(&done, Label::kNear); | |
3178 | 3210 |
3179 // ConsString. | 3211 // ConsString. |
3180 // Check whether the right hand side is the empty string (i.e. if | 3212 // Check whether the right hand side is the empty string (i.e. if |
3181 // this is really a flat string in a cons string). If that is not | 3213 // this is really a flat string in a cons string). If that is not |
3182 // the case we would rather go to the runtime system now to flatten | 3214 // the case we would rather go to the runtime system now to flatten |
3183 // the string. | 3215 // the string. |
3216 __ bind(&cons_string); | |
3184 __ cmp(FieldOperand(string, ConsString::kSecondOffset), | 3217 __ cmp(FieldOperand(string, ConsString::kSecondOffset), |
3185 Immediate(factory()->empty_string())); | 3218 Immediate(factory()->empty_string())); |
3186 __ j(not_equal, deferred->entry()); | 3219 __ j(not_equal, deferred->entry()); |
3187 // Get the first of the two strings and load its instance type. | 3220 // Get the first of the two strings and load its instance type. |
3188 __ mov(string, FieldOperand(string, ConsString::kFirstOffset)); | 3221 __ mov(string, FieldOperand(string, ConsString::kFirstOffset)); |
3189 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); | 3222 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); |
3190 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); | 3223 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); |
3191 // If the first cons component is also non-flat, then go to runtime. | 3224 // If the first cons component is also non-flat, then go to runtime. |
3192 STATIC_ASSERT(kSeqStringTag == 0); | 3225 STATIC_ASSERT(kSeqStringTag == 0); |
3193 __ test(result, Immediate(kStringRepresentationMask)); | 3226 __ test(result, Immediate(kStringRepresentationMask)); |
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4308 env->deoptimization_index()); | 4341 env->deoptimization_index()); |
4309 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); | 4342 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); |
4310 } | 4343 } |
4311 | 4344 |
4312 | 4345 |
4313 #undef __ | 4346 #undef __ |
4314 | 4347 |
4315 } } // namespace v8::internal | 4348 } } // namespace v8::internal |
4316 | 4349 |
4317 #endif // V8_TARGET_ARCH_IA32 | 4350 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |