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

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

Issue 5122005: Add a fast case to Array.join when all the elements and the separator are fla... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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 | « src/ia32/codegen-ia32.cc ('k') | src/ia32/macro-assembler-ia32.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 3066 matching lines...) Expand 10 before | Expand all | Expand 10 after
3077 __ AbortIfNotString(eax); 3077 __ AbortIfNotString(eax);
3078 } 3078 }
3079 3079
3080 __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); 3080 __ mov(eax, FieldOperand(eax, String::kHashFieldOffset));
3081 __ IndexFromHash(eax, eax); 3081 __ IndexFromHash(eax, eax);
3082 3082
3083 context()->Plug(eax); 3083 context()->Plug(eax);
3084 } 3084 }
3085 3085
3086 3086
3087 void FullCodeGenerator::EmitFastAsciiArrayJoin(ZoneList<Expression*>* args) {
3088 Label bailout;
3089 Label done;
3090
3091 ASSERT(args->length() == 2);
3092 // We will leave the separator on the stack until the end of the function.
3093 VisitForStackValue(args->at(1));
3094 // Load this to eax (= array)
3095 VisitForAccumulatorValue(args->at(0));
3096
3097 // All aliases of the same register have disjoint lifetimes.
3098 Register array = eax;
3099 Register result_pos = no_reg;
3100
3101 Register index = edi;
3102
3103 Register current_string_length = ecx; // Will be ecx when live.
3104
3105 Register current_string = edx;
3106
3107 Register scratch = ebx;
3108
3109 Register scratch_2 = esi;
3110 Register new_padding_chars = scratch_2;
3111
3112 Operand separator = Operand(esp, 4 * kPointerSize); // Already pushed.
3113 Operand elements = Operand(esp, 3 * kPointerSize);
3114 Operand result = Operand(esp, 2 * kPointerSize);
3115 Operand padding_chars = Operand(esp, 1 * kPointerSize);
3116 Operand array_length = Operand(esp, 0);
3117 __ sub(Operand(esp), Immediate(4 * kPointerSize));
3118
3119
3120 // Check that eax is a JSArray
3121 __ test(array, Immediate(kSmiTagMask));
3122 __ j(zero, &bailout);
3123 __ CmpObjectType(array, JS_ARRAY_TYPE, scratch);
3124 __ j(not_equal, &bailout);
3125
3126 // Check that the array has fast elements.
3127 __ test_b(FieldOperand(scratch, Map::kBitField2Offset),
3128 1 << Map::kHasFastElements);
3129 __ j(zero, &bailout);
3130
3131 // If the array is empty, return the empty string.
3132 __ mov(scratch, FieldOperand(array, JSArray::kLengthOffset));
3133 __ sar(scratch, 1);
3134 Label non_trivial;
3135 __ j(not_zero, &non_trivial);
3136 __ mov(result, Factory::empty_string());
3137 __ jmp(&done);
3138
3139 __ bind(&non_trivial);
3140 __ mov(array_length, scratch);
3141
3142 __ mov(scratch, FieldOperand(array, JSArray::kElementsOffset));
3143 __ mov(elements, scratch);
3144
3145 // End of array's live range.
3146 result_pos = array;
3147 array = no_reg;
3148
3149
3150 // Check that the separator is a flat ascii string.
3151 __ mov(current_string, separator);
3152 __ test(current_string, Immediate(kSmiTagMask));
3153 __ j(zero, &bailout);
3154 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset));
3155 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
3156 __ and_(scratch, Immediate(
3157 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
3158 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag);
3159 __ j(not_equal, &bailout);
3160 // If the separator is the empty string, replace it with NULL.
3161 // The test for NULL is quicker than the empty string test, in a loop.
3162 __ cmp(FieldOperand(current_string, SeqAsciiString::kLengthOffset),
3163 Immediate(0));
3164 Label separator_checked;
3165 __ j(not_zero, &separator_checked);
3166 __ mov(separator, Immediate(0));
3167 __ bind(&separator_checked);
3168
3169 // Check that elements[0] is a flat ascii string, and copy it in new space.
3170 __ mov(scratch, elements);
3171 __ mov(current_string, FieldOperand(scratch, FixedArray::kHeaderSize));
3172 __ test(current_string, Immediate(kSmiTagMask));
3173 __ j(zero, &bailout);
3174 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset));
3175 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
3176 __ and_(scratch, Immediate(
3177 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
3178 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag);
3179 __ j(not_equal, &bailout);
3180
3181 // Allocate space to copy it. Round up the size to the alignment granularity.
3182 __ mov(current_string_length,
3183 FieldOperand(current_string, String::kLengthOffset));
3184 __ shr(current_string_length, 1);
3185
3186 // Live registers and stack values:
3187 // current_string_length: length of elements[0].
3188
3189 // New string result in new space = elements[0]
3190 __ AllocateAsciiString(result_pos, current_string_length, scratch_2,
3191 index, no_reg, &bailout);
3192 __ mov(result, result_pos);
3193
3194 // Adjust current_string_length to include padding bytes at end of string.
3195 // Keep track of the number of padding bytes.
3196 __ mov(new_padding_chars, current_string_length);
3197 __ add(Operand(current_string_length), Immediate(kObjectAlignmentMask));
3198 __ and_(Operand(current_string_length), Immediate(~kObjectAlignmentMask));
3199 __ sub(new_padding_chars, Operand(current_string_length));
3200 __ neg(new_padding_chars);
3201 __ mov(padding_chars, new_padding_chars);
3202
3203 Label copy_loop_1_done;
3204 Label copy_loop_1;
3205 __ test(current_string_length, Operand(current_string_length));
3206 __ j(zero, &copy_loop_1_done);
3207 __ bind(&copy_loop_1);
3208 __ sub(Operand(current_string_length), Immediate(kPointerSize));
3209 __ mov(scratch, FieldOperand(current_string, current_string_length,
3210 times_1, SeqAsciiString::kHeaderSize));
3211 __ mov(FieldOperand(result_pos, current_string_length,
3212 times_1, SeqAsciiString::kHeaderSize),
3213 scratch);
3214 __ j(not_zero, &copy_loop_1);
3215 __ bind(&copy_loop_1_done);
3216
3217 __ mov(index, Immediate(1));
3218 // Loop condition: while (index < length).
3219 Label loop;
3220 __ bind(&loop);
3221 __ cmp(index, array_length);
3222 __ j(greater_equal, &done);
3223
3224 // If the separator is the empty string, signalled by NULL, skip it.
3225 Label separator_done;
3226 __ mov(current_string, separator);
3227 __ test(current_string, Operand(current_string));
3228 __ j(zero, &separator_done);
3229
3230 // Append separator to result. It is known to be a flat ascii string.
3231 __ AppendStringToTopOfNewSpace(current_string, current_string_length,
3232 result_pos, scratch, scratch_2, result,
3233 padding_chars, &bailout);
3234 __ bind(&separator_done);
3235
3236 // Add next element of array to the end of the result.
3237 // Get current_string = array[index].
3238 __ mov(scratch, elements);
3239 __ mov(current_string, FieldOperand(scratch, index,
3240 times_pointer_size,
3241 FixedArray::kHeaderSize));
3242 // If current != flat ascii string drop result, return undefined.
3243 __ test(current_string, Immediate(kSmiTagMask));
3244 __ j(zero, &bailout);
3245 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset));
3246 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset));
3247 __ and_(scratch, Immediate(
3248 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask));
3249 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag);
3250 __ j(not_equal, &bailout);
3251
3252 // Append current to the result.
3253 __ AppendStringToTopOfNewSpace(current_string, current_string_length,
3254 result_pos, scratch, scratch_2, result,
3255 padding_chars, &bailout);
3256 __ add(Operand(index), Immediate(1));
3257 __ jmp(&loop); // End while (index < length).
3258
3259 __ bind(&bailout);
3260 __ mov(result, Factory::undefined_value());
3261 __ bind(&done);
3262 __ mov(eax, result);
3263 // Drop temp values from the stack, and restore context register.
3264 __ add(Operand(esp), Immediate(5 * kPointerSize));
3265
3266 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3267 context()->Plug(eax);
3268 }
3269
3270
3087 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { 3271 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) {
3088 Handle<String> name = expr->name(); 3272 Handle<String> name = expr->name();
3089 if (name->length() > 0 && name->Get(0) == '_') { 3273 if (name->length() > 0 && name->Get(0) == '_') {
3090 Comment cmnt(masm_, "[ InlineRuntimeCall"); 3274 Comment cmnt(masm_, "[ InlineRuntimeCall");
3091 EmitInlineRuntimeCall(expr); 3275 EmitInlineRuntimeCall(expr);
3092 return; 3276 return;
3093 } 3277 }
3094 3278
3095 Comment cmnt(masm_, "[ CallRuntime"); 3279 Comment cmnt(masm_, "[ CallRuntime");
3096 ZoneList<Expression*>* args = expr->arguments(); 3280 ZoneList<Expression*>* args = expr->arguments();
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
3758 // And return. 3942 // And return.
3759 __ ret(0); 3943 __ ret(0);
3760 } 3944 }
3761 3945
3762 3946
3763 #undef __ 3947 #undef __
3764 3948
3765 } } // namespace v8::internal 3949 } } // namespace v8::internal
3766 3950
3767 #endif // V8_TARGET_ARCH_IA32 3951 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | src/ia32/macro-assembler-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698