| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3030 __ bind(&miss_force_generic); | 3030 __ bind(&miss_force_generic); |
| 3031 // ----------- S t a t e ------------- | 3031 // ----------- S t a t e ------------- |
| 3032 // -- rax : key | 3032 // -- rax : key |
| 3033 // -- rdx : receiver | 3033 // -- rdx : receiver |
| 3034 // -- rsp[0] : return address | 3034 // -- rsp[0] : return address |
| 3035 // ----------------------------------- | 3035 // ----------------------------------- |
| 3036 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric); | 3036 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_MissForceGeneric); |
| 3037 } | 3037 } |
| 3038 | 3038 |
| 3039 | 3039 |
| 3040 static void GenerateSmiKeyCheck(MacroAssembler* masm, | |
| 3041 Register key, | |
| 3042 Register scratch, | |
| 3043 XMMRegister xmm_scratch0, | |
| 3044 XMMRegister xmm_scratch1, | |
| 3045 Label* fail) { | |
| 3046 // Check that key is a smi or a heap number containing a smi and branch | |
| 3047 // if the check fails. | |
| 3048 Label key_ok; | |
| 3049 __ JumpIfSmi(key, &key_ok); | |
| 3050 __ CheckMap(key, | |
| 3051 masm->isolate()->factory()->heap_number_map(), | |
| 3052 fail, | |
| 3053 DONT_DO_SMI_CHECK); | |
| 3054 __ movsd(xmm_scratch0, FieldOperand(key, HeapNumber::kValueOffset)); | |
| 3055 __ cvttsd2si(scratch, xmm_scratch0); | |
| 3056 __ cvtlsi2sd(xmm_scratch1, scratch); | |
| 3057 __ ucomisd(xmm_scratch1, xmm_scratch0); | |
| 3058 __ j(not_equal, fail); | |
| 3059 __ j(parity_even, fail); // NaN. | |
| 3060 __ Integer32ToSmi(key, scratch); | |
| 3061 __ bind(&key_ok); | |
| 3062 } | |
| 3063 | |
| 3064 | |
| 3065 void KeyedStoreStubCompiler::GenerateStoreExternalArray( | |
| 3066 MacroAssembler* masm, | |
| 3067 ElementsKind elements_kind) { | |
| 3068 // ----------- S t a t e ------------- | |
| 3069 // -- rax : value | |
| 3070 // -- rcx : key | |
| 3071 // -- rdx : receiver | |
| 3072 // -- rsp[0] : return address | |
| 3073 // ----------------------------------- | |
| 3074 Label slow, miss_force_generic; | |
| 3075 | |
| 3076 // This stub is meant to be tail-jumped to, the receiver must already | |
| 3077 // have been verified by the caller to not be a smi. | |
| 3078 | |
| 3079 // Check that the key is a smi or a heap number convertible to a smi. | |
| 3080 GenerateSmiKeyCheck(masm, rcx, rbx, xmm0, xmm1, &miss_force_generic); | |
| 3081 | |
| 3082 // Check that the index is in range. | |
| 3083 __ movq(rbx, FieldOperand(rdx, JSObject::kElementsOffset)); | |
| 3084 __ SmiToInteger32(rdi, rcx); // Untag the index. | |
| 3085 __ cmpq(rcx, FieldOperand(rbx, ExternalArray::kLengthOffset)); | |
| 3086 // Unsigned comparison catches both negative and too-large values. | |
| 3087 __ j(above_equal, &miss_force_generic); | |
| 3088 | |
| 3089 // Handle both smis and HeapNumbers in the fast path. Go to the | |
| 3090 // runtime for all other kinds of values. | |
| 3091 // rax: value | |
| 3092 // rcx: key (a smi) | |
| 3093 // rdx: receiver (a JSObject) | |
| 3094 // rbx: elements array | |
| 3095 // rdi: untagged key | |
| 3096 Label check_heap_number; | |
| 3097 if (elements_kind == EXTERNAL_PIXEL_ELEMENTS) { | |
| 3098 // Float to pixel conversion is only implemented in the runtime for now. | |
| 3099 __ JumpIfNotSmi(rax, &slow); | |
| 3100 } else { | |
| 3101 __ JumpIfNotSmi(rax, &check_heap_number, Label::kNear); | |
| 3102 } | |
| 3103 // No more branches to slow case on this path. Key and receiver not needed. | |
| 3104 __ SmiToInteger32(rdx, rax); | |
| 3105 __ movq(rbx, FieldOperand(rbx, ExternalArray::kExternalPointerOffset)); | |
| 3106 // rbx: base pointer of external storage | |
| 3107 switch (elements_kind) { | |
| 3108 case EXTERNAL_PIXEL_ELEMENTS: | |
| 3109 { // Clamp the value to [0..255]. | |
| 3110 Label done; | |
| 3111 __ testl(rdx, Immediate(0xFFFFFF00)); | |
| 3112 __ j(zero, &done, Label::kNear); | |
| 3113 __ setcc(negative, rdx); // 1 if negative, 0 if positive. | |
| 3114 __ decb(rdx); // 0 if negative, 255 if positive. | |
| 3115 __ bind(&done); | |
| 3116 } | |
| 3117 __ movb(Operand(rbx, rdi, times_1, 0), rdx); | |
| 3118 break; | |
| 3119 case EXTERNAL_BYTE_ELEMENTS: | |
| 3120 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | |
| 3121 __ movb(Operand(rbx, rdi, times_1, 0), rdx); | |
| 3122 break; | |
| 3123 case EXTERNAL_SHORT_ELEMENTS: | |
| 3124 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | |
| 3125 __ movw(Operand(rbx, rdi, times_2, 0), rdx); | |
| 3126 break; | |
| 3127 case EXTERNAL_INT_ELEMENTS: | |
| 3128 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | |
| 3129 __ movl(Operand(rbx, rdi, times_4, 0), rdx); | |
| 3130 break; | |
| 3131 case EXTERNAL_FLOAT_ELEMENTS: | |
| 3132 // Need to perform int-to-float conversion. | |
| 3133 __ cvtlsi2ss(xmm0, rdx); | |
| 3134 __ movss(Operand(rbx, rdi, times_4, 0), xmm0); | |
| 3135 break; | |
| 3136 case EXTERNAL_DOUBLE_ELEMENTS: | |
| 3137 // Need to perform int-to-float conversion. | |
| 3138 __ cvtlsi2sd(xmm0, rdx); | |
| 3139 __ movsd(Operand(rbx, rdi, times_8, 0), xmm0); | |
| 3140 break; | |
| 3141 case FAST_ELEMENTS: | |
| 3142 case FAST_SMI_ELEMENTS: | |
| 3143 case FAST_DOUBLE_ELEMENTS: | |
| 3144 case FAST_HOLEY_ELEMENTS: | |
| 3145 case FAST_HOLEY_SMI_ELEMENTS: | |
| 3146 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
| 3147 case DICTIONARY_ELEMENTS: | |
| 3148 case NON_STRICT_ARGUMENTS_ELEMENTS: | |
| 3149 UNREACHABLE(); | |
| 3150 break; | |
| 3151 } | |
| 3152 __ ret(0); | |
| 3153 | |
| 3154 // TODO(danno): handle heap number -> pixel array conversion | |
| 3155 if (elements_kind != EXTERNAL_PIXEL_ELEMENTS) { | |
| 3156 __ bind(&check_heap_number); | |
| 3157 // rax: value | |
| 3158 // rcx: key (a smi) | |
| 3159 // rdx: receiver (a JSObject) | |
| 3160 // rbx: elements array | |
| 3161 // rdi: untagged key | |
| 3162 __ CmpObjectType(rax, HEAP_NUMBER_TYPE, kScratchRegister); | |
| 3163 __ j(not_equal, &slow); | |
| 3164 // No more branches to slow case on this path. | |
| 3165 | |
| 3166 // The WebGL specification leaves the behavior of storing NaN and | |
| 3167 // +/-Infinity into integer arrays basically undefined. For more | |
| 3168 // reproducible behavior, convert these to zero. | |
| 3169 __ movsd(xmm0, FieldOperand(rax, HeapNumber::kValueOffset)); | |
| 3170 __ movq(rbx, FieldOperand(rbx, ExternalArray::kExternalPointerOffset)); | |
| 3171 // rdi: untagged index | |
| 3172 // rbx: base pointer of external storage | |
| 3173 // top of FPU stack: value | |
| 3174 if (elements_kind == EXTERNAL_FLOAT_ELEMENTS) { | |
| 3175 __ cvtsd2ss(xmm0, xmm0); | |
| 3176 __ movss(Operand(rbx, rdi, times_4, 0), xmm0); | |
| 3177 __ ret(0); | |
| 3178 } else if (elements_kind == EXTERNAL_DOUBLE_ELEMENTS) { | |
| 3179 __ movsd(Operand(rbx, rdi, times_8, 0), xmm0); | |
| 3180 __ ret(0); | |
| 3181 } else { | |
| 3182 // Perform float-to-int conversion with truncation (round-to-zero) | |
| 3183 // behavior. | |
| 3184 // Fast path: use machine instruction to convert to int64. If that | |
| 3185 // fails (out-of-range), go into the runtime. | |
| 3186 __ cvttsd2siq(r8, xmm0); | |
| 3187 __ Set(kScratchRegister, V8_UINT64_C(0x8000000000000000)); | |
| 3188 __ cmpq(r8, kScratchRegister); | |
| 3189 __ j(equal, &slow); | |
| 3190 | |
| 3191 // rdx: value (converted to an untagged integer) | |
| 3192 // rdi: untagged index | |
| 3193 // rbx: base pointer of external storage | |
| 3194 switch (elements_kind) { | |
| 3195 case EXTERNAL_BYTE_ELEMENTS: | |
| 3196 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | |
| 3197 __ movb(Operand(rbx, rdi, times_1, 0), r8); | |
| 3198 break; | |
| 3199 case EXTERNAL_SHORT_ELEMENTS: | |
| 3200 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | |
| 3201 __ movw(Operand(rbx, rdi, times_2, 0), r8); | |
| 3202 break; | |
| 3203 case EXTERNAL_INT_ELEMENTS: | |
| 3204 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | |
| 3205 __ movl(Operand(rbx, rdi, times_4, 0), r8); | |
| 3206 break; | |
| 3207 case EXTERNAL_PIXEL_ELEMENTS: | |
| 3208 case EXTERNAL_FLOAT_ELEMENTS: | |
| 3209 case EXTERNAL_DOUBLE_ELEMENTS: | |
| 3210 case FAST_ELEMENTS: | |
| 3211 case FAST_SMI_ELEMENTS: | |
| 3212 case FAST_DOUBLE_ELEMENTS: | |
| 3213 case FAST_HOLEY_ELEMENTS: | |
| 3214 case FAST_HOLEY_SMI_ELEMENTS: | |
| 3215 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
| 3216 case DICTIONARY_ELEMENTS: | |
| 3217 case NON_STRICT_ARGUMENTS_ELEMENTS: | |
| 3218 UNREACHABLE(); | |
| 3219 break; | |
| 3220 } | |
| 3221 __ ret(0); | |
| 3222 } | |
| 3223 } | |
| 3224 | |
| 3225 // Slow case: call runtime. | |
| 3226 __ bind(&slow); | |
| 3227 | |
| 3228 // ----------- S t a t e ------------- | |
| 3229 // -- rax : value | |
| 3230 // -- rcx : key | |
| 3231 // -- rdx : receiver | |
| 3232 // -- rsp[0] : return address | |
| 3233 // ----------------------------------- | |
| 3234 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow); | |
| 3235 | |
| 3236 // Miss case: call runtime. | |
| 3237 __ bind(&miss_force_generic); | |
| 3238 | |
| 3239 // ----------- S t a t e ------------- | |
| 3240 // -- rax : value | |
| 3241 // -- rcx : key | |
| 3242 // -- rdx : receiver | |
| 3243 // -- rsp[0] : return address | |
| 3244 // ----------------------------------- | |
| 3245 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric); | |
| 3246 } | |
| 3247 | |
| 3248 | |
| 3249 void KeyedStoreStubCompiler::GenerateStoreFastElement( | |
| 3250 MacroAssembler* masm, | |
| 3251 bool is_js_array, | |
| 3252 ElementsKind elements_kind, | |
| 3253 KeyedAccessStoreMode store_mode) { | |
| 3254 // ----------- S t a t e ------------- | |
| 3255 // -- rax : value | |
| 3256 // -- rcx : key | |
| 3257 // -- rdx : receiver | |
| 3258 // -- rsp[0] : return address | |
| 3259 // ----------------------------------- | |
| 3260 Label miss_force_generic, transition_elements_kind, finish_store, grow; | |
| 3261 Label check_capacity, slow; | |
| 3262 | |
| 3263 // This stub is meant to be tail-jumped to, the receiver must already | |
| 3264 // have been verified by the caller to not be a smi. | |
| 3265 | |
| 3266 // Check that the key is a smi or a heap number convertible to a smi. | |
| 3267 GenerateSmiKeyCheck(masm, rcx, rbx, xmm0, xmm1, &miss_force_generic); | |
| 3268 | |
| 3269 if (IsFastSmiElementsKind(elements_kind)) { | |
| 3270 __ JumpIfNotSmi(rax, &transition_elements_kind); | |
| 3271 } | |
| 3272 | |
| 3273 // Get the elements array and make sure it is a fast element array, not 'cow'. | |
| 3274 __ movq(rdi, FieldOperand(rdx, JSObject::kElementsOffset)); | |
| 3275 // Check that the key is within bounds. | |
| 3276 if (is_js_array) { | |
| 3277 __ SmiCompare(rcx, FieldOperand(rdx, JSArray::kLengthOffset)); | |
| 3278 if (IsGrowStoreMode(store_mode)) { | |
| 3279 __ j(above_equal, &grow); | |
| 3280 } else { | |
| 3281 __ j(above_equal, &miss_force_generic); | |
| 3282 } | |
| 3283 } else { | |
| 3284 __ SmiCompare(rcx, FieldOperand(rdi, FixedArray::kLengthOffset)); | |
| 3285 __ j(above_equal, &miss_force_generic); | |
| 3286 } | |
| 3287 | |
| 3288 __ CompareRoot(FieldOperand(rdi, HeapObject::kMapOffset), | |
| 3289 Heap::kFixedArrayMapRootIndex); | |
| 3290 __ j(not_equal, &miss_force_generic); | |
| 3291 | |
| 3292 __ bind(&finish_store); | |
| 3293 if (IsFastSmiElementsKind(elements_kind)) { | |
| 3294 __ SmiToInteger32(rcx, rcx); | |
| 3295 __ movq(FieldOperand(rdi, rcx, times_pointer_size, FixedArray::kHeaderSize), | |
| 3296 rax); | |
| 3297 } else { | |
| 3298 // Do the store and update the write barrier. | |
| 3299 ASSERT(IsFastObjectElementsKind(elements_kind)); | |
| 3300 __ SmiToInteger32(rcx, rcx); | |
| 3301 __ lea(rcx, | |
| 3302 FieldOperand(rdi, rcx, times_pointer_size, FixedArray::kHeaderSize)); | |
| 3303 __ movq(Operand(rcx, 0), rax); | |
| 3304 // Make sure to preserve the value in register rax. | |
| 3305 __ movq(rbx, rax); | |
| 3306 __ RecordWrite(rdi, rcx, rbx, kDontSaveFPRegs); | |
| 3307 } | |
| 3308 | |
| 3309 // Done. | |
| 3310 __ ret(0); | |
| 3311 | |
| 3312 // Handle store cache miss. | |
| 3313 __ bind(&miss_force_generic); | |
| 3314 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric); | |
| 3315 | |
| 3316 __ bind(&transition_elements_kind); | |
| 3317 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss); | |
| 3318 | |
| 3319 if (is_js_array && IsGrowStoreMode(store_mode)) { | |
| 3320 // Grow the array by a single element if possible. | |
| 3321 __ bind(&grow); | |
| 3322 | |
| 3323 // Make sure the array is only growing by a single element, anything else | |
| 3324 // must be handled by the runtime. Flags are already set by previous | |
| 3325 // compare. | |
| 3326 __ j(not_equal, &miss_force_generic); | |
| 3327 | |
| 3328 // Check for the empty array, and preallocate a small backing store if | |
| 3329 // possible. | |
| 3330 __ movq(rdi, FieldOperand(rdx, JSObject::kElementsOffset)); | |
| 3331 __ CompareRoot(rdi, Heap::kEmptyFixedArrayRootIndex); | |
| 3332 __ j(not_equal, &check_capacity); | |
| 3333 | |
| 3334 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements); | |
| 3335 __ Allocate(size, rdi, rbx, r8, &slow, TAG_OBJECT); | |
| 3336 | |
| 3337 // rax: value | |
| 3338 // rcx: key | |
| 3339 // rdx: receiver | |
| 3340 // rdi: elements | |
| 3341 // Make sure that the backing store can hold additional elements. | |
| 3342 __ Move(FieldOperand(rdi, JSObject::kMapOffset), | |
| 3343 masm->isolate()->factory()->fixed_array_map()); | |
| 3344 __ Move(FieldOperand(rdi, FixedArray::kLengthOffset), | |
| 3345 Smi::FromInt(JSArray::kPreallocatedArrayElements)); | |
| 3346 __ LoadRoot(rbx, Heap::kTheHoleValueRootIndex); | |
| 3347 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) { | |
| 3348 __ movq(FieldOperand(rdi, FixedArray::SizeFor(i)), rbx); | |
| 3349 } | |
| 3350 | |
| 3351 // Store the element at index zero. | |
| 3352 __ movq(FieldOperand(rdi, FixedArray::SizeFor(0)), rax); | |
| 3353 | |
| 3354 // Install the new backing store in the JSArray. | |
| 3355 __ movq(FieldOperand(rdx, JSObject::kElementsOffset), rdi); | |
| 3356 __ RecordWriteField(rdx, JSObject::kElementsOffset, rdi, rbx, | |
| 3357 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
| 3358 | |
| 3359 // Increment the length of the array. | |
| 3360 __ Move(FieldOperand(rdx, JSArray::kLengthOffset), Smi::FromInt(1)); | |
| 3361 __ ret(0); | |
| 3362 | |
| 3363 __ bind(&check_capacity); | |
| 3364 // Check for cow elements, in general they are not handled by this stub. | |
| 3365 __ CompareRoot(FieldOperand(rdi, HeapObject::kMapOffset), | |
| 3366 Heap::kFixedCOWArrayMapRootIndex); | |
| 3367 __ j(equal, &miss_force_generic); | |
| 3368 | |
| 3369 // rax: value | |
| 3370 // rcx: key | |
| 3371 // rdx: receiver | |
| 3372 // rdi: elements | |
| 3373 // Make sure that the backing store can hold additional elements. | |
| 3374 __ cmpq(rcx, FieldOperand(rdi, FixedArray::kLengthOffset)); | |
| 3375 __ j(above_equal, &slow); | |
| 3376 | |
| 3377 // Grow the array and finish the store. | |
| 3378 __ SmiAddConstant(FieldOperand(rdx, JSArray::kLengthOffset), | |
| 3379 Smi::FromInt(1)); | |
| 3380 __ jmp(&finish_store); | |
| 3381 | |
| 3382 __ bind(&slow); | |
| 3383 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow); | |
| 3384 } | |
| 3385 } | |
| 3386 | |
| 3387 | |
| 3388 void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement( | |
| 3389 MacroAssembler* masm, | |
| 3390 bool is_js_array, | |
| 3391 KeyedAccessStoreMode store_mode) { | |
| 3392 // ----------- S t a t e ------------- | |
| 3393 // -- rax : value | |
| 3394 // -- rcx : key | |
| 3395 // -- rdx : receiver | |
| 3396 // -- rsp[0] : return address | |
| 3397 // ----------------------------------- | |
| 3398 Label miss_force_generic, transition_elements_kind, finish_store; | |
| 3399 Label grow, slow, check_capacity, restore_key_transition_elements_kind; | |
| 3400 | |
| 3401 // This stub is meant to be tail-jumped to, the receiver must already | |
| 3402 // have been verified by the caller to not be a smi. | |
| 3403 | |
| 3404 // Check that the key is a smi or a heap number convertible to a smi. | |
| 3405 GenerateSmiKeyCheck(masm, rcx, rbx, xmm0, xmm1, &miss_force_generic); | |
| 3406 | |
| 3407 // Get the elements array. | |
| 3408 __ movq(rdi, FieldOperand(rdx, JSObject::kElementsOffset)); | |
| 3409 __ AssertFastElements(rdi); | |
| 3410 | |
| 3411 // Check that the key is within bounds. | |
| 3412 if (is_js_array) { | |
| 3413 __ SmiCompare(rcx, FieldOperand(rdx, JSArray::kLengthOffset)); | |
| 3414 if (IsGrowStoreMode(store_mode)) { | |
| 3415 __ j(above_equal, &grow); | |
| 3416 } else { | |
| 3417 __ j(above_equal, &miss_force_generic); | |
| 3418 } | |
| 3419 } else { | |
| 3420 __ SmiCompare(rcx, FieldOperand(rdi, FixedDoubleArray::kLengthOffset)); | |
| 3421 __ j(above_equal, &miss_force_generic); | |
| 3422 } | |
| 3423 | |
| 3424 // Handle smi values specially | |
| 3425 __ bind(&finish_store); | |
| 3426 __ SmiToInteger32(rcx, rcx); | |
| 3427 __ StoreNumberToDoubleElements(rax, rdi, rcx, xmm0, | |
| 3428 &restore_key_transition_elements_kind); | |
| 3429 __ ret(0); | |
| 3430 | |
| 3431 // Handle store cache miss, replacing the ic with the generic stub. | |
| 3432 __ bind(&miss_force_generic); | |
| 3433 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_MissForceGeneric); | |
| 3434 | |
| 3435 __ bind(&restore_key_transition_elements_kind); | |
| 3436 // Restore smi-tagging of rcx. | |
| 3437 __ Integer32ToSmi(rcx, rcx); | |
| 3438 __ bind(&transition_elements_kind); | |
| 3439 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Miss); | |
| 3440 | |
| 3441 if (is_js_array && IsGrowStoreMode(store_mode)) { | |
| 3442 // Grow the array by a single element if possible. | |
| 3443 __ bind(&grow); | |
| 3444 | |
| 3445 // Make sure the array is only growing by a single element, anything else | |
| 3446 // must be handled by the runtime. Flags are already set by previous | |
| 3447 // compare. | |
| 3448 __ j(not_equal, &miss_force_generic); | |
| 3449 | |
| 3450 // Transition on values that can't be stored in a FixedDoubleArray. | |
| 3451 Label value_is_smi; | |
| 3452 __ JumpIfSmi(rax, &value_is_smi); | |
| 3453 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), | |
| 3454 Heap::kHeapNumberMapRootIndex); | |
| 3455 __ j(not_equal, &transition_elements_kind); | |
| 3456 __ bind(&value_is_smi); | |
| 3457 | |
| 3458 // Check for the empty array, and preallocate a small backing store if | |
| 3459 // possible. | |
| 3460 __ movq(rdi, FieldOperand(rdx, JSObject::kElementsOffset)); | |
| 3461 __ CompareRoot(rdi, Heap::kEmptyFixedArrayRootIndex); | |
| 3462 __ j(not_equal, &check_capacity); | |
| 3463 | |
| 3464 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements); | |
| 3465 __ Allocate(size, rdi, rbx, r8, &slow, TAG_OBJECT); | |
| 3466 | |
| 3467 // rax: value | |
| 3468 // rcx: key | |
| 3469 // rdx: receiver | |
| 3470 // rdi: elements | |
| 3471 // Initialize the new FixedDoubleArray. Leave elements unitialized for | |
| 3472 // efficiency, they are guaranteed to be initialized before use. | |
| 3473 __ Move(FieldOperand(rdi, JSObject::kMapOffset), | |
| 3474 masm->isolate()->factory()->fixed_double_array_map()); | |
| 3475 __ Move(FieldOperand(rdi, FixedDoubleArray::kLengthOffset), | |
| 3476 Smi::FromInt(JSArray::kPreallocatedArrayElements)); | |
| 3477 | |
| 3478 // Increment the length of the array. | |
| 3479 __ SmiToInteger32(rcx, rcx); | |
| 3480 __ StoreNumberToDoubleElements(rax, rdi, rcx, xmm0, | |
| 3481 &restore_key_transition_elements_kind); | |
| 3482 | |
| 3483 __ movq(r8, BitCast<int64_t, uint64_t>(kHoleNanInt64), RelocInfo::NONE64); | |
| 3484 for (int i = 1; i < JSArray::kPreallocatedArrayElements; i++) { | |
| 3485 __ movq(FieldOperand(rdi, FixedDoubleArray::OffsetOfElementAt(i)), r8); | |
| 3486 } | |
| 3487 | |
| 3488 // Install the new backing store in the JSArray. | |
| 3489 __ movq(FieldOperand(rdx, JSObject::kElementsOffset), rdi); | |
| 3490 __ RecordWriteField(rdx, JSObject::kElementsOffset, rdi, rbx, | |
| 3491 kDontSaveFPRegs, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); | |
| 3492 | |
| 3493 // Increment the length of the array. | |
| 3494 __ Move(FieldOperand(rdx, JSArray::kLengthOffset), Smi::FromInt(1)); | |
| 3495 __ movq(rdi, FieldOperand(rdx, JSObject::kElementsOffset)); | |
| 3496 __ ret(0); | |
| 3497 | |
| 3498 __ bind(&check_capacity); | |
| 3499 // rax: value | |
| 3500 // rcx: key | |
| 3501 // rdx: receiver | |
| 3502 // rdi: elements | |
| 3503 // Make sure that the backing store can hold additional elements. | |
| 3504 __ cmpq(rcx, FieldOperand(rdi, FixedDoubleArray::kLengthOffset)); | |
| 3505 __ j(above_equal, &slow); | |
| 3506 | |
| 3507 // Grow the array and finish the store. | |
| 3508 __ SmiAddConstant(FieldOperand(rdx, JSArray::kLengthOffset), | |
| 3509 Smi::FromInt(1)); | |
| 3510 __ jmp(&finish_store); | |
| 3511 | |
| 3512 __ bind(&slow); | |
| 3513 TailCallBuiltin(masm, Builtins::kKeyedStoreIC_Slow); | |
| 3514 } | |
| 3515 } | |
| 3516 | |
| 3517 | |
| 3518 #undef __ | 3040 #undef __ |
| 3519 | 3041 |
| 3520 } } // namespace v8::internal | 3042 } } // namespace v8::internal |
| 3521 | 3043 |
| 3522 #endif // V8_TARGET_ARCH_X64 | 3044 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |