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

Side by Side Diff: src/ia32/stub-cache-ia32.cc

Issue 6295013: Revert r6376 and r6373 which changes external array support. The ARM... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 11 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
« no previous file with comments | « src/ia32/ic-ia32.cc ('k') | src/ic.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 3288 matching lines...) Expand 10 before | Expand all | Expand 10 after
3299 __ bind(&generic_stub_call); 3299 __ bind(&generic_stub_call);
3300 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); 3300 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric);
3301 Handle<Code> generic_construct_stub(code); 3301 Handle<Code> generic_construct_stub(code);
3302 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); 3302 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET);
3303 3303
3304 // Return the generated code. 3304 // Return the generated code.
3305 return GetCode(); 3305 return GetCode();
3306 } 3306 }
3307 3307
3308 3308
3309 MaybeObject* ExternalArrayStubCompiler::CompileKeyedLoadStub(
3310 ExternalArrayType array_type, Code::Flags flags) {
3311 // ----------- S t a t e -------------
3312 // -- eax : key
3313 // -- edx : receiver
3314 // -- esp[0] : return address
3315 // -----------------------------------
3316 Label slow, failed_allocation;
3317
3318 // Check that the object isn't a smi.
3319 __ test(edx, Immediate(kSmiTagMask));
3320 __ j(zero, &slow, not_taken);
3321
3322 // Check that the key is a smi.
3323 __ test(eax, Immediate(kSmiTagMask));
3324 __ j(not_zero, &slow, not_taken);
3325
3326 // Get the map of the receiver.
3327 __ mov(ecx, FieldOperand(edx, HeapObject::kMapOffset));
3328 // Check that the receiver does not require access checks. We need
3329 // to check this explicitly since this generic stub does not perform
3330 // map checks.
3331 __ test_b(FieldOperand(ecx, Map::kBitFieldOffset),
3332 1 << Map::kIsAccessCheckNeeded);
3333 __ j(not_zero, &slow, not_taken);
3334
3335 __ CmpInstanceType(ecx, JS_OBJECT_TYPE);
3336 __ j(not_equal, &slow, not_taken);
3337
3338 // Check that the elements array is the appropriate type of
3339 // ExternalArray.
3340 __ mov(ebx, FieldOperand(edx, JSObject::kElementsOffset));
3341 Handle<Map> map(Heap::MapForExternalArrayType(array_type));
3342 __ cmp(FieldOperand(ebx, HeapObject::kMapOffset),
3343 Immediate(map));
3344 __ j(not_equal, &slow, not_taken);
3345
3346 // eax: key, known to be a smi.
3347 // edx: receiver, known to be a JSObject.
3348 // ebx: elements object, known to be an external array.
3349 // Check that the index is in range.
3350 __ mov(ecx, eax);
3351 __ SmiUntag(ecx); // Untag the index.
3352 __ cmp(ecx, FieldOperand(ebx, ExternalArray::kLengthOffset));
3353 // Unsigned comparison catches both negative and too-large values.
3354 __ j(above_equal, &slow);
3355
3356 __ mov(ebx, FieldOperand(ebx, ExternalArray::kExternalPointerOffset));
3357 // ebx: base pointer of external storage
3358 switch (array_type) {
3359 case kExternalByteArray:
3360 __ movsx_b(ecx, Operand(ebx, ecx, times_1, 0));
3361 break;
3362 case kExternalUnsignedByteArray:
3363 __ movzx_b(ecx, Operand(ebx, ecx, times_1, 0));
3364 break;
3365 case kExternalShortArray:
3366 __ movsx_w(ecx, Operand(ebx, ecx, times_2, 0));
3367 break;
3368 case kExternalUnsignedShortArray:
3369 __ movzx_w(ecx, Operand(ebx, ecx, times_2, 0));
3370 break;
3371 case kExternalIntArray:
3372 case kExternalUnsignedIntArray:
3373 __ mov(ecx, Operand(ebx, ecx, times_4, 0));
3374 break;
3375 case kExternalFloatArray:
3376 __ fld_s(Operand(ebx, ecx, times_4, 0));
3377 break;
3378 default:
3379 UNREACHABLE();
3380 break;
3381 }
3382
3383 // For integer array types:
3384 // ecx: value
3385 // For floating-point array type:
3386 // FP(0): value
3387
3388 if (array_type == kExternalIntArray ||
3389 array_type == kExternalUnsignedIntArray) {
3390 // For the Int and UnsignedInt array types, we need to see whether
3391 // the value can be represented in a Smi. If not, we need to convert
3392 // it to a HeapNumber.
3393 Label box_int;
3394 if (array_type == kExternalIntArray) {
3395 __ cmp(ecx, 0xC0000000);
3396 __ j(sign, &box_int);
3397 } else {
3398 ASSERT_EQ(array_type, kExternalUnsignedIntArray);
3399 // The test is different for unsigned int values. Since we need
3400 // the value to be in the range of a positive smi, we can't
3401 // handle either of the top two bits being set in the value.
3402 __ test(ecx, Immediate(0xC0000000));
3403 __ j(not_zero, &box_int);
3404 }
3405
3406 __ mov(eax, ecx);
3407 __ SmiTag(eax);
3408 __ ret(0);
3409
3410 __ bind(&box_int);
3411
3412 // Allocate a HeapNumber for the int and perform int-to-double
3413 // conversion.
3414 if (array_type == kExternalIntArray) {
3415 __ push(ecx);
3416 __ fild_s(Operand(esp, 0));
3417 __ pop(ecx);
3418 } else {
3419 ASSERT(array_type == kExternalUnsignedIntArray);
3420 // Need to zero-extend the value.
3421 // There's no fild variant for unsigned values, so zero-extend
3422 // to a 64-bit int manually.
3423 __ push(Immediate(0));
3424 __ push(ecx);
3425 __ fild_d(Operand(esp, 0));
3426 __ pop(ecx);
3427 __ pop(ecx);
3428 }
3429 // FP(0): value
3430 __ AllocateHeapNumber(ecx, ebx, edi, &failed_allocation);
3431 // Set the value.
3432 __ mov(eax, ecx);
3433 __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
3434 __ ret(0);
3435 } else if (array_type == kExternalFloatArray) {
3436 // For the floating-point array type, we need to always allocate a
3437 // HeapNumber.
3438 __ AllocateHeapNumber(ecx, ebx, edi, &failed_allocation);
3439 // Set the value.
3440 __ mov(eax, ecx);
3441 __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset));
3442 __ ret(0);
3443 } else {
3444 __ mov(eax, ecx);
3445 __ SmiTag(eax);
3446 __ ret(0);
3447 }
3448
3449 // If we fail allocation of the HeapNumber, we still have a value on
3450 // top of the FPU stack. Remove it.
3451 __ bind(&failed_allocation);
3452 __ ffree();
3453 __ fincstp();
3454 // Fall through to slow case.
3455
3456 // Slow case: Jump to runtime.
3457 __ bind(&slow);
3458 __ IncrementCounter(&Counters::keyed_load_external_array_slow, 1);
3459 // ----------- S t a t e -------------
3460 // -- eax : key
3461 // -- edx : receiver
3462 // -- esp[0] : return address
3463 // -----------------------------------
3464
3465 __ pop(ebx);
3466 __ push(edx); // receiver
3467 __ push(eax); // name
3468 __ push(ebx); // return address
3469
3470 // Perform tail call to the entry.
3471 __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1);
3472
3473 // Return the generated code.
3474 return GetCode(flags);
3475 }
3476
3477
3478 MaybeObject* ExternalArrayStubCompiler::CompileKeyedStoreStub(
3479 ExternalArrayType array_type, Code::Flags flags) {
3480 // ----------- S t a t e -------------
3481 // -- eax : value
3482 // -- ecx : key
3483 // -- edx : receiver
3484 // -- esp[0] : return address
3485 // -----------------------------------
3486 Label slow, check_heap_number;
3487
3488 // Check that the object isn't a smi.
3489 __ test(edx, Immediate(kSmiTagMask));
3490 __ j(zero, &slow);
3491 // Get the map from the receiver.
3492 __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset));
3493 // Check that the receiver does not require access checks. We need
3494 // to do this because this generic stub does not perform map checks.
3495 __ test_b(FieldOperand(edi, Map::kBitFieldOffset),
3496 1 << Map::kIsAccessCheckNeeded);
3497 __ j(not_zero, &slow);
3498 // Check that the key is a smi.
3499 __ test(ecx, Immediate(kSmiTagMask));
3500 __ j(not_zero, &slow);
3501 // Get the instance type from the map of the receiver.
3502 __ CmpInstanceType(edi, JS_OBJECT_TYPE);
3503 __ j(not_equal, &slow);
3504
3505 // Check that the elements array is the appropriate type of
3506 // ExternalArray.
3507 // eax: value
3508 // edx: receiver, a JSObject
3509 // ecx: key, a smi
3510 __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset));
3511 __ CheckMap(edi, Handle<Map>(Heap::MapForExternalArrayType(array_type)),
3512 &slow, true);
3513
3514 // Check that the index is in range.
3515 __ mov(ebx, ecx);
3516 __ SmiUntag(ebx);
3517 __ cmp(ebx, FieldOperand(edi, ExternalArray::kLengthOffset));
3518 // Unsigned comparison catches both negative and too-large values.
3519 __ j(above_equal, &slow);
3520
3521 // Handle both smis and HeapNumbers in the fast path. Go to the
3522 // runtime for all other kinds of values.
3523 // eax: value
3524 // edx: receiver
3525 // ecx: key
3526 // edi: elements array
3527 // ebx: untagged index
3528 __ test(eax, Immediate(kSmiTagMask));
3529 __ j(not_equal, &check_heap_number);
3530 // smi case
3531 __ mov(ecx, eax); // Preserve the value in eax. Key is no longer needed.
3532 __ SmiUntag(ecx);
3533 __ mov(edi, FieldOperand(edi, ExternalArray::kExternalPointerOffset));
3534 // ecx: base pointer of external storage
3535 switch (array_type) {
3536 case kExternalByteArray:
3537 case kExternalUnsignedByteArray:
3538 __ mov_b(Operand(edi, ebx, times_1, 0), ecx);
3539 break;
3540 case kExternalShortArray:
3541 case kExternalUnsignedShortArray:
3542 __ mov_w(Operand(edi, ebx, times_2, 0), ecx);
3543 break;
3544 case kExternalIntArray:
3545 case kExternalUnsignedIntArray:
3546 __ mov(Operand(edi, ebx, times_4, 0), ecx);
3547 break;
3548 case kExternalFloatArray:
3549 // Need to perform int-to-float conversion.
3550 __ push(ecx);
3551 __ fild_s(Operand(esp, 0));
3552 __ pop(ecx);
3553 __ fstp_s(Operand(edi, ebx, times_4, 0));
3554 break;
3555 default:
3556 UNREACHABLE();
3557 break;
3558 }
3559 __ ret(0); // Return the original value.
3560
3561 __ bind(&check_heap_number);
3562 // eax: value
3563 // edx: receiver
3564 // ecx: key
3565 // edi: elements array
3566 // ebx: untagged index
3567 __ cmp(FieldOperand(eax, HeapObject::kMapOffset),
3568 Immediate(Factory::heap_number_map()));
3569 __ j(not_equal, &slow);
3570
3571 // The WebGL specification leaves the behavior of storing NaN and
3572 // +/-Infinity into integer arrays basically undefined. For more
3573 // reproducible behavior, convert these to zero.
3574 __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset));
3575 __ mov(edi, FieldOperand(edi, ExternalArray::kExternalPointerOffset));
3576 // ebx: untagged index
3577 // edi: base pointer of external storage
3578 // top of FPU stack: value
3579 if (array_type == kExternalFloatArray) {
3580 __ fstp_s(Operand(edi, ebx, times_4, 0));
3581 __ ret(0);
3582 } else {
3583 // Perform float-to-int conversion with truncation (round-to-zero)
3584 // behavior.
3585 if (array_type != kExternalIntArray &&
3586 array_type != kExternalUnsignedIntArray) {
3587 if (CpuFeatures::IsSupported(SSE3)) {
3588 CpuFeatures::Scope scope(SSE3);
3589 __ push(ecx); // Make room on stack
3590 __ fisttp_s(Operand(esp, 0));
3591 __ pop(ecx);
3592 } else if (CpuFeatures::IsSupported(SSE2)) {
3593 CpuFeatures::Scope scope(SSE2);
3594 // Free the top of the FP stack, which we don't use in this code
3595 // path.
3596 __ ffree();
3597 __ fincstp();
3598
3599 __ cvttsd2si(ecx, FieldOperand(eax, HeapNumber::kValueOffset));
3600 } else {
3601 // TODO(kbr): consider supporting non-SSE2 processors properly.
3602 // The code in IntegerConvert (code-stubs-ia32.cc) is roughly what
3603 // is needed though the conversion failure case does not need to be
3604 // handled. The code below is not correct; it doesn't truncate, it
3605 // rounds.
3606 __ push(ecx); // Make room on stack
3607 __ fistp_s(Operand(esp, 0));
3608 __ pop(ecx);
3609 }
3610 } else {
3611 bool have_sse3 = CpuFeatures::IsSupported(SSE3);
3612 if (have_sse3 || !CpuFeatures::IsSupported(SSE2)) {
3613 // fisttp stores values as signed integers. To represent the
3614 // entire range of unsigned int arrays, store as a 64-bit
3615 // int and discard the high 32 bits.
3616 // If the value is NaN or +/-infinity, the result is 0x80000000,
3617 // which is automatically zero when taken mod 2^n, n < 32.
3618 __ sub(Operand(esp), Immediate(2 * kPointerSize));
3619 if (have_sse3) {
3620 CpuFeatures::Scope scope(SSE3);
3621 __ fisttp_d(Operand(esp, 0));
3622 } else {
3623 // TODO(kbr): consider supporting non-SSE2 processors properly.
3624 __ fistp_d(Operand(esp, 0));
3625 }
3626 __ pop(ecx);
3627 __ add(Operand(esp), Immediate(kPointerSize));
3628 } else {
3629 ASSERT(CpuFeatures::IsSupported(SSE2));
3630 CpuFeatures::Scope scope(SSE2);
3631 // We can easily implement the correct rounding behavior for the
3632 // range [0, 2^31-1]. For the time being, to keep this code simple,
3633 // use the wrong rounding behavior for values outside this range.
3634 __ movd(xmm0, FieldOperand(eax, HeapNumber::kValueOffset));
3635 __ LoadPowerOf2(xmm1, ecx, 31);
3636 Label is_outside_range;
3637 Label continuation_point;
3638 __ ucomisd(xmm0, xmm1);
3639 __ j(above_equal, &is_outside_range);
3640 // Free the top of the FP stack, which we don't use in this code
3641 // path.
3642 __ ffree();
3643 __ fincstp();
3644 __ cvttsd2si(ecx, FieldOperand(eax, HeapNumber::kValueOffset));
3645 __ jmp(&continuation_point);
3646 __ bind(&is_outside_range);
3647 __ sub(Operand(esp), Immediate(2 * kPointerSize));
3648 __ fistp_d(Operand(esp, 0));
3649 __ pop(ecx);
3650 __ add(Operand(esp), Immediate(kPointerSize));
3651 __ bind(&continuation_point);
3652 }
3653 }
3654 // ecx: untagged integer value
3655 switch (array_type) {
3656 case kExternalByteArray:
3657 case kExternalUnsignedByteArray:
3658 __ mov_b(Operand(edi, ebx, times_1, 0), ecx);
3659 break;
3660 case kExternalShortArray:
3661 case kExternalUnsignedShortArray:
3662 __ mov_w(Operand(edi, ebx, times_2, 0), ecx);
3663 break;
3664 case kExternalIntArray:
3665 case kExternalUnsignedIntArray: {
3666 __ mov(Operand(edi, ebx, times_4, 0), ecx);
3667 break;
3668 }
3669 default:
3670 UNREACHABLE();
3671 break;
3672 }
3673 __ ret(0); // Return original value.
3674 }
3675
3676 // Slow case: call runtime.
3677 __ bind(&slow);
3678 // ----------- S t a t e -------------
3679 // -- eax : value
3680 // -- ecx : key
3681 // -- edx : receiver
3682 // -- esp[0] : return address
3683 // -----------------------------------
3684
3685 __ pop(ebx);
3686 __ push(edx);
3687 __ push(ecx);
3688 __ push(eax);
3689 __ push(ebx);
3690
3691 // Do tail-call to runtime routine.
3692 __ TailCallRuntime(Runtime::kSetProperty, 3, 1);
3693
3694 return GetCode(flags);
3695 }
3696
3697
3698 #undef __ 3309 #undef __
3699 3310
3700 } } // namespace v8::internal 3311 } } // namespace v8::internal
3701 3312
3702 #endif // V8_TARGET_ARCH_IA32 3313 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/ic-ia32.cc ('k') | src/ic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698