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

Side by Side Diff: src/ia32/lithium-codegen-ia32.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Support for RegExp. Removed methods related to truncate. Created 9 years, 4 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 | Annotate | Revision Log
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 3119 matching lines...) Expand 10 before | Expand all | Expand 10 after
3130 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { 3130 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
3131 class DeferredStringCharCodeAt: public LDeferredCode { 3131 class DeferredStringCharCodeAt: public LDeferredCode {
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());
Vitaly Repeshko 2011/08/12 19:01:00 Simplified version using three (writable) register
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, two_byte_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);
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 __ mov(string, FieldOperand(string, SlicedString::kParentOffset));
3188 __ mov(result, FieldOperand(string, HeapObject::kMapOffset));
3189 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset));
3190 __ add(string, Operand(offset));
3191 // Check for ASCII or two-byte string.
3192 STATIC_ASSERT(kAsciiStringTag != 0);
3193 __ test(result, Immediate(kStringEncodingMask));
3194 __ j(not_zero, &ascii_string, Label::kNear);
3195 __ add(string, Operand(offset));
3196 __ jmp(&two_byte_string, Label::kNear);
3178 3197
3179 // ConsString. 3198 // ConsString.
3180 // Check whether the right hand side is the empty string (i.e. if 3199 // 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 3200 // 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 3201 // the case we would rather go to the runtime system now to flatten
3183 // the string. 3202 // the string.
3203 __ bind(&cons_string);
3184 __ cmp(FieldOperand(string, ConsString::kSecondOffset), 3204 __ cmp(FieldOperand(string, ConsString::kSecondOffset),
3185 Immediate(factory()->empty_string())); 3205 Immediate(factory()->empty_string()));
3186 __ j(not_equal, deferred->entry()); 3206 __ j(not_equal, deferred->entry());
3187 // Get the first of the two strings and load its instance type. 3207 // Get the first of the two strings and load its instance type.
3188 __ mov(string, FieldOperand(string, ConsString::kFirstOffset)); 3208 __ mov(string, FieldOperand(string, ConsString::kFirstOffset));
3189 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); 3209 __ mov(result, FieldOperand(string, HeapObject::kMapOffset));
3190 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); 3210 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset));
3191 // If the first cons component is also non-flat, then go to runtime. 3211 // If the first cons component is also non-flat, then go to runtime.
3192 STATIC_ASSERT(kSeqStringTag == 0); 3212 STATIC_ASSERT(kSeqStringTag == 0);
3193 __ test(result, Immediate(kStringRepresentationMask)); 3213 __ test(result, Immediate(kStringRepresentationMask));
3194 __ j(not_zero, deferred->entry()); 3214 __ j(not_zero, deferred->entry());
3195 3215
3196 // Check for ASCII or two-byte string. 3216 // Check for ASCII or two-byte string.
3197 __ bind(&flat_string); 3217 __ bind(&flat_string);
3198 STATIC_ASSERT(kAsciiStringTag != 0); 3218 STATIC_ASSERT(kAsciiStringTag != 0);
3199 __ test(result, Immediate(kStringEncodingMask)); 3219 __ test(result, Immediate(kStringEncodingMask));
3200 __ j(not_zero, &ascii_string, Label::kNear); 3220 __ j(not_zero, &ascii_string, Label::kNear);
3201 3221
3202 // Two-byte string. 3222 // Two-byte string.
3203 // Load the two-byte character code into the result register. 3223 // Load the two-byte character code into the result register.
3224 __ bind(&two_byte_string);
3204 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); 3225 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
3205 if (instr->index()->IsConstantOperand()) { 3226 if (instr->index()->IsConstantOperand()) {
3206 __ movzx_w(result, 3227 __ movzx_w(result,
3207 FieldOperand(string, 3228 FieldOperand(string,
3208 SeqTwoByteString::kHeaderSize + 3229 SeqTwoByteString::kHeaderSize +
3209 (kUC16Size * const_index))); 3230 (kUC16Size * const_index)));
3210 } else { 3231 } else {
3211 __ movzx_w(result, FieldOperand(string, 3232 __ movzx_w(result, FieldOperand(string,
3212 index, 3233 index,
3213 times_2, 3234 times_2,
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
4308 env->deoptimization_index()); 4329 env->deoptimization_index());
4309 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); 4330 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator);
4310 } 4331 }
4311 4332
4312 4333
4313 #undef __ 4334 #undef __
4314 4335
4315 } } // namespace v8::internal 4336 } } // namespace v8::internal
4316 4337
4317 #endif // V8_TARGET_ARCH_IA32 4338 #endif // V8_TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698