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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 static Register registers[] = { rax }; | 168 static Register registers[] = { rax }; |
169 descriptor->register_param_count_ = 1; | 169 descriptor->register_param_count_ = 1; |
170 descriptor->register_params_ = registers; | 170 descriptor->register_params_ = registers; |
171 descriptor->deoptimization_handler_ = | 171 descriptor->deoptimization_handler_ = |
172 FUNCTION_ADDR(CompareNilIC_Miss); | 172 FUNCTION_ADDR(CompareNilIC_Miss); |
173 descriptor->SetMissHandler( | 173 descriptor->SetMissHandler( |
174 ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); | 174 ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
175 } | 175 } |
176 | 176 |
177 | 177 |
| 178 void ToBooleanStub::InitializeInterfaceDescriptor( |
| 179 Isolate* isolate, |
| 180 CodeStubInterfaceDescriptor* descriptor) { |
| 181 static Register registers[] = { rax }; |
| 182 descriptor->register_param_count_ = 1; |
| 183 descriptor->register_params_ = registers; |
| 184 descriptor->deoptimization_handler_ = |
| 185 FUNCTION_ADDR(ToBooleanIC_Miss); |
| 186 descriptor->SetMissHandler( |
| 187 ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 188 } |
| 189 |
| 190 |
178 #define __ ACCESS_MASM(masm) | 191 #define __ ACCESS_MASM(masm) |
179 | 192 |
180 | 193 |
181 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { | 194 void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
182 // Update the static counter each time a new code stub is generated. | 195 // Update the static counter each time a new code stub is generated. |
183 Isolate* isolate = masm->isolate(); | 196 Isolate* isolate = masm->isolate(); |
184 isolate->counters()->code_stubs()->Increment(); | 197 isolate->counters()->code_stubs()->Increment(); |
185 | 198 |
186 CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); | 199 CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
187 int param_count = descriptor->register_param_count_; | 200 int param_count = descriptor->register_param_count_; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // Return and remove the on-stack parameter. | 468 // Return and remove the on-stack parameter. |
456 __ movq(rsi, rax); | 469 __ movq(rsi, rax); |
457 __ ret(2 * kPointerSize); | 470 __ ret(2 * kPointerSize); |
458 | 471 |
459 // Need to collect. Call into runtime system. | 472 // Need to collect. Call into runtime system. |
460 __ bind(&gc); | 473 __ bind(&gc); |
461 __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); | 474 __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
462 } | 475 } |
463 | 476 |
464 | 477 |
465 // The stub expects its argument on the stack and returns its result in tos_: | |
466 // zero for false, and a non-zero value for true. | |
467 void ToBooleanStub::Generate(MacroAssembler* masm) { | |
468 // This stub overrides SometimesSetsUpAFrame() to return false. That means | |
469 // we cannot call anything that could cause a GC from this stub. | |
470 Label patch; | |
471 const Register argument = rax; | |
472 const Register map = rdx; | |
473 | |
474 if (!types_.IsEmpty()) { | |
475 __ movq(argument, Operand(rsp, 1 * kPointerSize)); | |
476 } | |
477 | |
478 // undefined -> false | |
479 CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); | |
480 | |
481 // Boolean -> its value | |
482 CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); | |
483 CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); | |
484 | |
485 // 'null' -> false. | |
486 CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); | |
487 | |
488 if (types_.Contains(SMI)) { | |
489 // Smis: 0 -> false, all other -> true | |
490 Label not_smi; | |
491 __ JumpIfNotSmi(argument, ¬_smi, Label::kNear); | |
492 // argument contains the correct return value already | |
493 if (!tos_.is(argument)) { | |
494 __ movq(tos_, argument); | |
495 } | |
496 __ ret(1 * kPointerSize); | |
497 __ bind(¬_smi); | |
498 } else if (types_.NeedsMap()) { | |
499 // If we need a map later and have a Smi -> patch. | |
500 __ JumpIfSmi(argument, &patch, Label::kNear); | |
501 } | |
502 | |
503 if (types_.NeedsMap()) { | |
504 __ movq(map, FieldOperand(argument, HeapObject::kMapOffset)); | |
505 | |
506 if (types_.CanBeUndetectable()) { | |
507 __ testb(FieldOperand(map, Map::kBitFieldOffset), | |
508 Immediate(1 << Map::kIsUndetectable)); | |
509 // Undetectable -> false. | |
510 Label not_undetectable; | |
511 __ j(zero, ¬_undetectable, Label::kNear); | |
512 __ Set(tos_, 0); | |
513 __ ret(1 * kPointerSize); | |
514 __ bind(¬_undetectable); | |
515 } | |
516 } | |
517 | |
518 if (types_.Contains(SPEC_OBJECT)) { | |
519 // spec object -> true. | |
520 Label not_js_object; | |
521 __ CmpInstanceType(map, FIRST_SPEC_OBJECT_TYPE); | |
522 __ j(below, ¬_js_object, Label::kNear); | |
523 // argument contains the correct return value already. | |
524 if (!tos_.is(argument)) { | |
525 __ Set(tos_, 1); | |
526 } | |
527 __ ret(1 * kPointerSize); | |
528 __ bind(¬_js_object); | |
529 } | |
530 | |
531 if (types_.Contains(STRING)) { | |
532 // String value -> false iff empty. | |
533 Label not_string; | |
534 __ CmpInstanceType(map, FIRST_NONSTRING_TYPE); | |
535 __ j(above_equal, ¬_string, Label::kNear); | |
536 __ movq(tos_, FieldOperand(argument, String::kLengthOffset)); | |
537 __ ret(1 * kPointerSize); // the string length is OK as the return value | |
538 __ bind(¬_string); | |
539 } | |
540 | |
541 if (types_.Contains(HEAP_NUMBER)) { | |
542 // heap number -> false iff +0, -0, or NaN. | |
543 Label not_heap_number, false_result; | |
544 __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); | |
545 __ j(not_equal, ¬_heap_number, Label::kNear); | |
546 __ xorps(xmm0, xmm0); | |
547 __ ucomisd(xmm0, FieldOperand(argument, HeapNumber::kValueOffset)); | |
548 __ j(zero, &false_result, Label::kNear); | |
549 // argument contains the correct return value already. | |
550 if (!tos_.is(argument)) { | |
551 __ Set(tos_, 1); | |
552 } | |
553 __ ret(1 * kPointerSize); | |
554 __ bind(&false_result); | |
555 __ Set(tos_, 0); | |
556 __ ret(1 * kPointerSize); | |
557 __ bind(¬_heap_number); | |
558 } | |
559 | |
560 __ bind(&patch); | |
561 GenerateTypeTransition(masm); | |
562 } | |
563 | |
564 | |
565 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { | 478 void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
566 __ PushCallerSaved(save_doubles_); | 479 __ PushCallerSaved(save_doubles_); |
567 const int argument_count = 1; | 480 const int argument_count = 1; |
568 __ PrepareCallCFunction(argument_count); | 481 __ PrepareCallCFunction(argument_count); |
569 __ LoadAddress(arg_reg_1, | 482 __ LoadAddress(arg_reg_1, |
570 ExternalReference::isolate_address(masm->isolate())); | 483 ExternalReference::isolate_address(masm->isolate())); |
571 | 484 |
572 AllowExternalCallThatCantCauseGC scope(masm); | 485 AllowExternalCallThatCantCauseGC scope(masm); |
573 __ CallCFunction( | 486 __ CallCFunction( |
574 ExternalReference::store_buffer_overflow_function(masm->isolate()), | 487 ExternalReference::store_buffer_overflow_function(masm->isolate()), |
575 argument_count); | 488 argument_count); |
576 __ PopCallerSaved(save_doubles_); | 489 __ PopCallerSaved(save_doubles_); |
577 __ ret(0); | 490 __ ret(0); |
578 } | 491 } |
579 | 492 |
580 | 493 |
581 void ToBooleanStub::CheckOddball(MacroAssembler* masm, | |
582 Type type, | |
583 Heap::RootListIndex value, | |
584 bool result) { | |
585 const Register argument = rax; | |
586 if (types_.Contains(type)) { | |
587 // If we see an expected oddball, return its ToBoolean value tos_. | |
588 Label different_value; | |
589 __ CompareRoot(argument, value); | |
590 __ j(not_equal, &different_value, Label::kNear); | |
591 if (!result) { | |
592 // If we have to return zero, there is no way around clearing tos_. | |
593 __ Set(tos_, 0); | |
594 } else if (!tos_.is(argument)) { | |
595 // If we have to return non-zero, we can re-use the argument if it is the | |
596 // same register as the result, because we never see Smi-zero here. | |
597 __ Set(tos_, 1); | |
598 } | |
599 __ ret(1 * kPointerSize); | |
600 __ bind(&different_value); | |
601 } | |
602 } | |
603 | |
604 | |
605 void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { | |
606 __ pop(rcx); // Get return address, operand is now on top of stack. | |
607 __ Push(Smi::FromInt(tos_.code())); | |
608 __ Push(Smi::FromInt(types_.ToByte())); | |
609 __ push(rcx); // Push return address. | |
610 // Patch the caller to an appropriate specialized stub and return the | |
611 // operation result to the caller of the stub. | |
612 __ TailCallExternalReference( | |
613 ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), | |
614 3, | |
615 1); | |
616 } | |
617 | |
618 | |
619 class FloatingPointHelper : public AllStatic { | 494 class FloatingPointHelper : public AllStatic { |
620 public: | 495 public: |
621 enum ConvertUndefined { | 496 enum ConvertUndefined { |
622 CONVERT_UNDEFINED_TO_ZERO, | 497 CONVERT_UNDEFINED_TO_ZERO, |
623 BAILOUT_ON_UNDEFINED | 498 BAILOUT_ON_UNDEFINED |
624 }; | 499 }; |
625 // Load the operands from rdx and rax into xmm0 and xmm1, as doubles. | 500 // Load the operands from rdx and rax into xmm0 and xmm1, as doubles. |
626 // If the operands are not both numbers, jump to not_numbers. | 501 // If the operands are not both numbers, jump to not_numbers. |
627 // Leaves rdx and rax unchanged. SmiOperands assumes both are smis. | 502 // Leaves rdx and rax unchanged. SmiOperands assumes both are smis. |
628 // NumberOperands assumes both are smis or heap numbers. | 503 // NumberOperands assumes both are smis or heap numbers. |
(...skipping 6425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7054 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); | 6929 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
7055 } | 6930 } |
7056 } | 6931 } |
7057 | 6932 |
7058 | 6933 |
7059 #undef __ | 6934 #undef __ |
7060 | 6935 |
7061 } } // namespace v8::internal | 6936 } } // namespace v8::internal |
7062 | 6937 |
7063 #endif // V8_TARGET_ARCH_X64 | 6938 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |