OLD | NEW |
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 Loading... |
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 |
| 3114 Operand elements = Operand(esp, 3 * kPointerSize); |
| 3115 __ push(scratch); |
| 3116 |
| 3117 Operand result = Operand(esp, 2 * kPointerSize); |
| 3118 __ push(scratch); |
| 3119 |
| 3120 Operand padding_chars = Operand(esp, 1 * kPointerSize); |
| 3121 __ push(scratch); |
| 3122 |
| 3123 Operand array_length = Operand(esp, 0); |
| 3124 __ push(scratch); |
| 3125 |
| 3126 |
| 3127 // Check that eax is a JSArray |
| 3128 __ test(array, Immediate(kSmiTagMask)); |
| 3129 __ j(zero, &bailout); |
| 3130 __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 3131 __ j(not_equal, &bailout); |
| 3132 |
| 3133 // Check that the array has fast elements. |
| 3134 __ cmpb(FieldOperand(scratch, Map::kBitField2Offset), |
| 3135 1 << Map::kHasFastElements); |
| 3136 // If the array is empty, return the empty string. |
| 3137 __ mov(scratch, FieldOperand(array, JSArray::kLengthOffset)); |
| 3138 __ sar(scratch, 1); |
| 3139 Label non_trivial; |
| 3140 __ j(not_zero, &non_trivial); |
| 3141 __ mov(result, Factory::empty_string()); |
| 3142 __ jmp(&done); |
| 3143 |
| 3144 __ bind(&non_trivial); |
| 3145 __ mov(array_length, scratch); |
| 3146 |
| 3147 __ mov(scratch, FieldOperand(array, JSArray::kElementsOffset)); |
| 3148 __ mov(elements, scratch); |
| 3149 |
| 3150 // End of array's live range. |
| 3151 result_pos = array; |
| 3152 array = no_reg; |
| 3153 |
| 3154 |
| 3155 // Check that the separator is a flat ascii string. |
| 3156 __ mov(current_string, separator); |
| 3157 __ test(current_string, Immediate(kSmiTagMask)); |
| 3158 __ j(zero, &bailout); |
| 3159 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset)); |
| 3160 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3161 __ and_(scratch, Immediate( |
| 3162 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 3163 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag); |
| 3164 __ j(not_equal, &bailout); |
| 3165 // If the separator is the empty string, replace it with NULL. |
| 3166 // The test for NULL is quicker than the empty string test, in a loop. |
| 3167 __ cmp(FieldOperand(current_string, SeqAsciiString::kLengthOffset), |
| 3168 Immediate(0)); |
| 3169 Label separator_checked; |
| 3170 __ j(not_zero, &separator_checked); |
| 3171 __ mov(separator, Immediate(0)); |
| 3172 __ bind(&separator_checked); |
| 3173 |
| 3174 // Check that elements[0] is a flat ascii string, and copy it in new space. |
| 3175 __ mov(scratch, elements); |
| 3176 __ mov(current_string, FieldOperand(scratch, FixedArray::kHeaderSize)); |
| 3177 __ test(current_string, Immediate(kSmiTagMask)); |
| 3178 __ j(zero, &bailout); |
| 3179 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset)); |
| 3180 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3181 __ and_(scratch, Immediate( |
| 3182 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 3183 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag); |
| 3184 __ j(not_equal, &bailout); |
| 3185 |
| 3186 // Allocate space to copy it. Round up the size to the alignment granularity. |
| 3187 __ mov(current_string_length, |
| 3188 FieldOperand(current_string, String::kLengthOffset)); |
| 3189 __ shr(current_string_length, 1); |
| 3190 |
| 3191 // Live registers and stack values: |
| 3192 // current_string_length: length of elements[0]. |
| 3193 |
| 3194 // New string result in new space = elements[0] |
| 3195 __ AllocateAsciiString(result_pos, current_string_length, scratch_2, |
| 3196 index, no_reg, &bailout); |
| 3197 __ mov(result, result_pos); |
| 3198 |
| 3199 // Adjust current_string_length to include padding bytes at end of string. |
| 3200 // Keep track of the number of padding bytes. |
| 3201 __ mov(new_padding_chars, current_string_length); |
| 3202 __ add(Operand(current_string_length), Immediate(kObjectAlignmentMask)); |
| 3203 __ and_(Operand(current_string_length), Immediate(~kObjectAlignmentMask)); |
| 3204 __ sub(new_padding_chars, Operand(current_string_length)); |
| 3205 __ neg(new_padding_chars); |
| 3206 __ mov(padding_chars, new_padding_chars); |
| 3207 |
| 3208 Label copy_loop_1_entry; |
| 3209 Label copy_loop_1; |
| 3210 __ test(current_string_length, Operand(current_string_length)); |
| 3211 __ jmp(©_loop_1_entry); |
| 3212 __ bind(©_loop_1); |
| 3213 __ sub(Operand(current_string_length), Immediate(kPointerSize)); |
| 3214 __ mov(scratch, FieldOperand(current_string, current_string_length, |
| 3215 times_1, SeqAsciiString::kHeaderSize)); |
| 3216 __ mov(FieldOperand(result_pos, current_string_length, |
| 3217 times_1, SeqAsciiString::kHeaderSize), |
| 3218 scratch); |
| 3219 __ bind(©_loop_1_entry); |
| 3220 __ j(not_zero, ©_loop_1); |
| 3221 |
| 3222 __ mov(index, Immediate(1)); |
| 3223 // Loop condition: while (index < length). |
| 3224 Label loop; |
| 3225 __ bind(&loop); |
| 3226 __ cmp(index, array_length); |
| 3227 __ j(greater_equal, &done); |
| 3228 |
| 3229 // If the separator is the empty string, signalled by NULL, skip it. |
| 3230 Label separator_done; |
| 3231 __ mov(current_string, separator); |
| 3232 __ test(current_string, Operand(current_string)); |
| 3233 __ j(zero, &separator_done); |
| 3234 |
| 3235 // Append separator to result. It is known to be a flat ascii string. |
| 3236 // Extend the result by the length of the separator. |
| 3237 __ mov(current_string_length, |
| 3238 FieldOperand(current_string, String::kLengthOffset)); |
| 3239 __ shr(current_string_length, 1); |
| 3240 __ sub(current_string_length, padding_chars); |
| 3241 __ mov(new_padding_chars, current_string_length); |
| 3242 __ add(Operand(current_string_length), Immediate(kObjectAlignmentMask)); |
| 3243 __ and_(Operand(current_string_length), Immediate(~kObjectAlignmentMask)); |
| 3244 __ sub(new_padding_chars, Operand(current_string_length)); |
| 3245 __ neg(new_padding_chars); |
| 3246 // We need an allocation even if current_string_length is 0, to fetch |
| 3247 // result_pos. Consider using a faster fetch of result_pos in that case. |
| 3248 __ AllocateInNewSpace(current_string_length, result_pos, scratch, no_reg, |
| 3249 &bailout, NO_ALLOCATION_FLAGS); |
| 3250 __ sub(result_pos, padding_chars); |
| 3251 __ mov(padding_chars, new_padding_chars); |
| 3252 |
| 3253 // Copy separator to the end of result. |
| 3254 __ mov(current_string_length, |
| 3255 FieldOperand(current_string, String::kLengthOffset)); |
| 3256 __ mov(scratch, result); |
| 3257 __ mov(scratch_2, current_string_length); |
| 3258 __ add(scratch_2, FieldOperand(scratch, String::kLengthOffset)); |
| 3259 __ mov(FieldOperand(scratch, String::kLengthOffset), scratch_2); |
| 3260 __ shr(current_string_length, 1); |
| 3261 __ lea(current_string, |
| 3262 FieldOperand(current_string, SeqAsciiString::kHeaderSize)); |
| 3263 // Loop condition: while (--current_string_length >= 0). |
| 3264 Label copy_loop_2; |
| 3265 Label copy_loop_2_entry; |
| 3266 __ jmp(©_loop_2_entry); |
| 3267 __ bind(©_loop_2); |
| 3268 __ mov_b(scratch, |
| 3269 Operand(current_string, current_string_length, times_1, 0)); |
| 3270 __ mov_b(Operand(result_pos, current_string_length, times_1, 0), |
| 3271 scratch); |
| 3272 __ bind(©_loop_2_entry); |
| 3273 __ sub(Operand(current_string_length), Immediate(1)); |
| 3274 __ j(greater_equal, ©_loop_2); |
| 3275 |
| 3276 __ bind(&separator_done); |
| 3277 |
| 3278 // Add next element of array to the end of the result. |
| 3279 // Get current_string = array[index]. |
| 3280 __ mov(scratch, elements); |
| 3281 __ mov(current_string, FieldOperand(scratch, index, |
| 3282 times_pointer_size, |
| 3283 FixedArray::kHeaderSize)); |
| 3284 // If current != flat ascii string drop result, return undefined. |
| 3285 __ test(current_string, Immediate(kSmiTagMask)); |
| 3286 __ j(zero, &bailout); |
| 3287 __ mov(scratch, FieldOperand(current_string, HeapObject::kMapOffset)); |
| 3288 __ mov_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3289 __ and_(scratch, Immediate( |
| 3290 kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
| 3291 __ cmp(scratch, kStringTag | kAsciiStringTag | kSeqStringTag); |
| 3292 __ j(not_equal, &bailout); |
| 3293 |
| 3294 // extend result by length(current) |
| 3295 __ mov(current_string_length, |
| 3296 FieldOperand(current_string, String::kLengthOffset)); |
| 3297 __ shr(current_string_length, 1); |
| 3298 __ sub(current_string_length, padding_chars); |
| 3299 __ mov(new_padding_chars, current_string_length); |
| 3300 __ add(Operand(current_string_length), Immediate(kObjectAlignmentMask)); |
| 3301 __ and_(Operand(current_string_length), Immediate(~kObjectAlignmentMask)); |
| 3302 __ sub(new_padding_chars, Operand(current_string_length)); |
| 3303 __ neg(new_padding_chars); |
| 3304 __ AllocateInNewSpace(current_string_length, result_pos, scratch, no_reg, |
| 3305 &bailout, NO_ALLOCATION_FLAGS); |
| 3306 __ sub(result_pos, padding_chars); |
| 3307 __ mov(padding_chars, new_padding_chars); |
| 3308 |
| 3309 // copy current to end of result |
| 3310 __ mov(current_string_length, |
| 3311 FieldOperand(current_string, String::kLengthOffset)); |
| 3312 __ mov(scratch, result); |
| 3313 __ mov(scratch_2, current_string_length); |
| 3314 __ add(scratch_2, FieldOperand(scratch, String::kLengthOffset)); |
| 3315 __ mov(FieldOperand(scratch, String::kLengthOffset), scratch_2); |
| 3316 __ shr(current_string_length, 1); |
| 3317 __ lea(current_string, |
| 3318 FieldOperand(current_string, SeqAsciiString::kHeaderSize)); |
| 3319 Label copy_loop_3; |
| 3320 Label copy_loop_3_entry; |
| 3321 __ jmp(©_loop_3_entry); |
| 3322 __ bind(©_loop_3); |
| 3323 __ mov_b(scratch, |
| 3324 Operand(current_string, current_string_length, times_1, 0)); |
| 3325 __ mov_b(Operand(result_pos, current_string_length, times_1, 0), |
| 3326 scratch); |
| 3327 __ bind(©_loop_3_entry); |
| 3328 __ sub(Operand(current_string_length), Immediate(1)); |
| 3329 __ j(greater_equal, ©_loop_3); |
| 3330 |
| 3331 __ add(Operand(index), Immediate(1)); |
| 3332 // end while |
| 3333 __ jmp(&loop); |
| 3334 // return current |
| 3335 |
| 3336 __ bind(&bailout); |
| 3337 __ mov(result, Factory::undefined_value()); |
| 3338 __ bind(&done); |
| 3339 __ mov(eax, result); |
| 3340 // Drop temp values from the stack, and restore context register. |
| 3341 __ add(Operand(esp), Immediate(5 * kPointerSize)); |
| 3342 |
| 3343 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 3344 context()->Plug(eax); |
| 3345 } |
| 3346 |
| 3347 |
3087 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { | 3348 void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
3088 Handle<String> name = expr->name(); | 3349 Handle<String> name = expr->name(); |
3089 if (name->length() > 0 && name->Get(0) == '_') { | 3350 if (name->length() > 0 && name->Get(0) == '_') { |
3090 Comment cmnt(masm_, "[ InlineRuntimeCall"); | 3351 Comment cmnt(masm_, "[ InlineRuntimeCall"); |
3091 EmitInlineRuntimeCall(expr); | 3352 EmitInlineRuntimeCall(expr); |
3092 return; | 3353 return; |
3093 } | 3354 } |
3094 | 3355 |
3095 Comment cmnt(masm_, "[ CallRuntime"); | 3356 Comment cmnt(masm_, "[ CallRuntime"); |
3096 ZoneList<Expression*>* args = expr->arguments(); | 3357 ZoneList<Expression*>* args = expr->arguments(); |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3758 // And return. | 4019 // And return. |
3759 __ ret(0); | 4020 __ ret(0); |
3760 } | 4021 } |
3761 | 4022 |
3762 | 4023 |
3763 #undef __ | 4024 #undef __ |
3764 | 4025 |
3765 } } // namespace v8::internal | 4026 } } // namespace v8::internal |
3766 | 4027 |
3767 #endif // V8_TARGET_ARCH_IA32 | 4028 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |