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

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: Some more suggested changes. Created 9 years, 3 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 3120 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
3141 Register index = no_reg; 3141 Register index = ToRegister(instr->index());
3142 int const_index = -1;
3143 if (instr->index()->IsConstantOperand()) {
3144 const_index = ToInteger32(LConstantOperand::cast(instr->index()));
3145 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
3146 if (!Smi::IsValid(const_index)) {
3147 // Guaranteed to be out of bounds because of the assert above.
3148 // So the bounds check that must dominate this instruction must
3149 // have deoptimized already.
3150 if (FLAG_debug_code) {
3151 __ Abort("StringCharCodeAt: out of bounds index.");
3152 }
3153 // No code needs to be generated.
3154 return;
3155 }
3156 } else {
3157 index = ToRegister(instr->index());
3158 }
3159 Register result = ToRegister(instr->result()); 3142 Register result = ToRegister(instr->result());
3160 3143
3161 DeferredStringCharCodeAt* deferred = 3144 DeferredStringCharCodeAt* deferred =
3162 new DeferredStringCharCodeAt(this, instr); 3145 new DeferredStringCharCodeAt(this, instr);
3163 3146
3164 Label flat_string, ascii_string, done;
3165
3166 // Fetch the instance type of the receiver into result register. 3147 // Fetch the instance type of the receiver into result register.
3167 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); 3148 __ mov(result, FieldOperand(string, HeapObject::kMapOffset));
3168 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); 3149 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset));
3169 3150
3170 // We need special handling for non-flat strings. 3151 // We need special handling for indirect strings.
3171 STATIC_ASSERT(kSeqStringTag == 0); 3152 Label check_sequential;
3172 __ test(result, Immediate(kStringRepresentationMask)); 3153 __ test(result, Immediate(kIsIndirectStringMask));
3173 __ j(zero, &flat_string, Label::kNear); 3154 __ j(zero, &check_sequential, Label::kNear);
3174 3155
3175 // Handle non-flat strings. 3156 // Dispatch on the indirect string shape: slice or cons.
3176 __ test(result, Immediate(kIsConsStringMask)); 3157 Label cons_string;
3177 __ j(zero, deferred->entry()); 3158 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
3159 ASSERT(IsPowerOf2(kSlicedNotConsMask) && kSlicedNotConsMask != 0);
3160 __ test(result, Immediate(kSlicedNotConsMask));
3161 __ j(zero, &cons_string, Label::kNear);
3178 3162
3179 // ConsString. 3163 // Handle slices.
3164 Label indirect_string_loaded;
3165 __ mov(result, FieldOperand(string, SlicedString::kOffsetOffset));
3166 __ SmiUntag(result);
3167 __ add(index, Operand(result));
3168 __ mov(string, FieldOperand(string, SlicedString::kParentOffset));
3169 __ jmp(&indirect_string_loaded, Label::kNear);
3170
3171 // Handle conses.
3180 // Check whether the right hand side is the empty string (i.e. if 3172 // 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 3173 // 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 3174 // the case we would rather go to the runtime system now to flatten
3183 // the string. 3175 // the string.
3176 __ bind(&cons_string);
3184 __ cmp(FieldOperand(string, ConsString::kSecondOffset), 3177 __ cmp(FieldOperand(string, ConsString::kSecondOffset),
3185 Immediate(factory()->empty_string())); 3178 Immediate(factory()->empty_string()));
3186 __ j(not_equal, deferred->entry()); 3179 __ j(not_equal, deferred->entry());
3187 // Get the first of the two strings and load its instance type.
3188 __ mov(string, FieldOperand(string, ConsString::kFirstOffset)); 3180 __ mov(string, FieldOperand(string, ConsString::kFirstOffset));
3181
3182 __ bind(&indirect_string_loaded);
3189 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); 3183 __ mov(result, FieldOperand(string, HeapObject::kMapOffset));
3190 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); 3184 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset));
3191 // If the first cons component is also non-flat, then go to runtime. 3185
3186 // Check whether the string is sequential. The only non-sequential
3187 // shapes we support have just been unwrapped above.
3188 __ bind(&check_sequential);
3192 STATIC_ASSERT(kSeqStringTag == 0); 3189 STATIC_ASSERT(kSeqStringTag == 0);
3193 __ test(result, Immediate(kStringRepresentationMask)); 3190 __ test(result, Immediate(kStringRepresentationMask));
3194 __ j(not_zero, deferred->entry()); 3191 __ j(not_zero, deferred->entry());
3195 3192
3196 // Check for ASCII or two-byte string. 3193 // Dispatch on the encoding: ASCII or two-byte.
3197 __ bind(&flat_string); 3194 Label ascii_string;
3198 STATIC_ASSERT(kAsciiStringTag != 0); 3195 STATIC_ASSERT(kAsciiStringTag != 0);
3199 __ test(result, Immediate(kStringEncodingMask)); 3196 __ test(result, Immediate(kStringEncodingMask));
3200 __ j(not_zero, &ascii_string, Label::kNear); 3197 __ j(not_zero, &ascii_string, Label::kNear);
3201 3198
3202 // Two-byte string. 3199 // Two-byte string.
3203 // Load the two-byte character code into the result register. 3200 // Load the two-byte character code into the result register.
3201 Label done;
3204 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); 3202 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
3205 if (instr->index()->IsConstantOperand()) { 3203 __ movzx_w(result, FieldOperand(string,
3206 __ movzx_w(result, 3204 index,
3207 FieldOperand(string, 3205 times_2,
3208 SeqTwoByteString::kHeaderSize + 3206 SeqTwoByteString::kHeaderSize));
3209 (kUC16Size * const_index)));
3210 } else {
3211 __ movzx_w(result, FieldOperand(string,
3212 index,
3213 times_2,
3214 SeqTwoByteString::kHeaderSize));
3215 }
3216 __ jmp(&done, Label::kNear); 3207 __ jmp(&done, Label::kNear);
3217 3208
3218 // ASCII string. 3209 // ASCII string.
3219 // Load the byte into the result register. 3210 // Load the byte into the result register.
3220 __ bind(&ascii_string); 3211 __ bind(&ascii_string);
3221 if (instr->index()->IsConstantOperand()) { 3212 __ movzx_b(result, FieldOperand(string,
3222 __ movzx_b(result, FieldOperand(string, 3213 index,
3223 SeqAsciiString::kHeaderSize + const_index)); 3214 times_1,
3224 } else { 3215 SeqAsciiString::kHeaderSize));
3225 __ movzx_b(result, FieldOperand(string,
3226 index,
3227 times_1,
3228 SeqAsciiString::kHeaderSize));
3229 }
3230 __ bind(&done); 3216 __ bind(&done);
3231 __ bind(deferred->exit()); 3217 __ bind(deferred->exit());
3232 } 3218 }
3233 3219
3234 3220
3235 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { 3221 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) {
3236 Register string = ToRegister(instr->string()); 3222 Register string = ToRegister(instr->string());
3237 Register result = ToRegister(instr->result()); 3223 Register result = ToRegister(instr->result());
3238 3224
3239 // TODO(3095996): Get rid of this. For now, we need to make the 3225 // TODO(3095996): Get rid of this. For now, we need to make the
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
4308 env->deoptimization_index()); 4294 env->deoptimization_index());
4309 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); 4295 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator);
4310 } 4296 }
4311 4297
4312 4298
4313 #undef __ 4299 #undef __
4314 4300
4315 } } // namespace v8::internal 4301 } } // namespace v8::internal
4316 4302
4317 #endif // V8_TARGET_ARCH_IA32 4303 #endif // V8_TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698