| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 11 matching lines...) Expand all Loading... |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_X64_MACRO_ASSEMBLER_X64_H_ | 28 #ifndef V8_X64_MACRO_ASSEMBLER_X64_H_ |
| 29 #define V8_X64_MACRO_ASSEMBLER_X64_H_ | 29 #define V8_X64_MACRO_ASSEMBLER_X64_H_ |
| 30 | 30 |
| 31 #include "assembler.h" | 31 #include "assembler.h" |
| 32 #include "v8globals.h" |
| 32 | 33 |
| 33 namespace v8 { | 34 namespace v8 { |
| 34 namespace internal { | 35 namespace internal { |
| 35 | 36 |
| 36 // Flags used for the AllocateInNewSpace functions. | 37 // Flags used for the AllocateInNewSpace functions. |
| 37 enum AllocationFlags { | 38 enum AllocationFlags { |
| 38 // No special flags. | 39 // No special flags. |
| 39 NO_ALLOCATION_FLAGS = 0, | 40 NO_ALLOCATION_FLAGS = 0, |
| 40 // Return the pointer to the allocated already tagged as a heap object. | 41 // Return the pointer to the allocated already tagged as a heap object. |
| 41 TAG_OBJECT = 1 << 0, | 42 TAG_OBJECT = 1 << 0, |
| 42 // The content of the result register already contains the allocation top in | 43 // The content of the result register already contains the allocation top in |
| 43 // new space. | 44 // new space. |
| 44 RESULT_CONTAINS_TOP = 1 << 1 | 45 RESULT_CONTAINS_TOP = 1 << 1 |
| 45 }; | 46 }; |
| 46 | 47 |
| 48 |
| 47 // Default scratch register used by MacroAssembler (and other code that needs | 49 // Default scratch register used by MacroAssembler (and other code that needs |
| 48 // a spare register). The register isn't callee save, and not used by the | 50 // a spare register). The register isn't callee save, and not used by the |
| 49 // function calling convention. | 51 // function calling convention. |
| 50 static const Register kScratchRegister = { 10 }; // r10. | 52 static const Register kScratchRegister = { 10 }; // r10. |
| 51 static const Register kSmiConstantRegister = { 12 }; // r12 (callee save). | 53 static const Register kSmiConstantRegister = { 12 }; // r12 (callee save). |
| 52 static const Register kRootRegister = { 13 }; // r13 (callee save). | 54 static const Register kRootRegister = { 13 }; // r13 (callee save). |
| 53 // Value of smi in kSmiConstantRegister. | 55 // Value of smi in kSmiConstantRegister. |
| 54 static const int kSmiConstantRegisterValue = 1; | 56 static const int kSmiConstantRegisterValue = 1; |
| 55 // Actual value of root register is offset from the root array's start | 57 // Actual value of root register is offset from the root array's start |
| 56 // to take advantage of negitive 8-bit displacement values. | 58 // to take advantage of negitive 8-bit displacement values. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // RecordWriteHelper only works if the object is not in new | 146 // RecordWriteHelper only works if the object is not in new |
| 145 // space. | 147 // space. |
| 146 void RecordWriteHelper(Register object, | 148 void RecordWriteHelper(Register object, |
| 147 Register addr, | 149 Register addr, |
| 148 Register scratch, | 150 Register scratch, |
| 149 SaveFPRegsMode save_fp); | 151 SaveFPRegsMode save_fp); |
| 150 | 152 |
| 151 // Check if object is in new space. The condition cc can be equal or | 153 // Check if object is in new space. The condition cc can be equal or |
| 152 // not_equal. If it is equal a jump will be done if the object is on new | 154 // not_equal. If it is equal a jump will be done if the object is on new |
| 153 // space. The register scratch can be object itself, but it will be clobbered. | 155 // space. The register scratch can be object itself, but it will be clobbered. |
| 154 template <typename LabelType> | |
| 155 void InNewSpace(Register object, | 156 void InNewSpace(Register object, |
| 156 Register scratch, | 157 Register scratch, |
| 157 Condition cc, | 158 Condition cc, |
| 158 LabelType* branch); | 159 Label* branch, |
| 160 Label::Distance near_jump = Label::kFar); |
| 159 | 161 |
| 160 // For page containing |object| mark region covering [object+offset] | 162 // For page containing |object| mark region covering [object+offset] |
| 161 // dirty. |object| is the object being stored into, |value| is the | 163 // dirty. |object| is the object being stored into, |value| is the |
| 162 // object being stored. If |offset| is zero, then the |scratch| | 164 // object being stored. If |offset| is zero, then the |scratch| |
| 163 // register contains the array index into the elements array | 165 // register contains the array index into the elements array |
| 164 // represented as an untagged 32-bit integer. All registers are | 166 // represented as an untagged 32-bit integer. All registers are |
| 165 // clobbered by the operation. RecordWrite filters out smis so it | 167 // clobbered by the operation. RecordWrite filters out smis so it |
| 166 // does not update the write barrier if the value is a smi. | 168 // does not update the write barrier if the value is a smi. |
| 167 void RecordWrite(Register object, | 169 void RecordWrite(Register object, |
| 168 int offset, | 170 int offset, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // Divide a positive smi's integer value by a power of two. | 330 // Divide a positive smi's integer value by a power of two. |
| 329 // Provides result as 32-bit integer value. | 331 // Provides result as 32-bit integer value. |
| 330 void PositiveSmiDivPowerOfTwoToInteger32(Register dst, | 332 void PositiveSmiDivPowerOfTwoToInteger32(Register dst, |
| 331 Register src, | 333 Register src, |
| 332 int power); | 334 int power); |
| 333 | 335 |
| 334 // Perform the logical or of two smi values and return a smi value. | 336 // Perform the logical or of two smi values and return a smi value. |
| 335 // If either argument is not a smi, jump to on_not_smis and retain | 337 // If either argument is not a smi, jump to on_not_smis and retain |
| 336 // the original values of source registers. The destination register | 338 // the original values of source registers. The destination register |
| 337 // may be changed if it's not one of the source registers. | 339 // may be changed if it's not one of the source registers. |
| 338 template <typename LabelType> | |
| 339 void SmiOrIfSmis(Register dst, | 340 void SmiOrIfSmis(Register dst, |
| 340 Register src1, | 341 Register src1, |
| 341 Register src2, | 342 Register src2, |
| 342 LabelType* on_not_smis); | 343 Label* on_not_smis, |
| 344 Label::Distance near_jump = Label::kFar); |
| 343 | 345 |
| 344 | 346 |
| 345 // Simple comparison of smis. Both sides must be known smis to use these, | 347 // Simple comparison of smis. Both sides must be known smis to use these, |
| 346 // otherwise use Cmp. | 348 // otherwise use Cmp. |
| 347 void SmiCompare(Register smi1, Register smi2); | 349 void SmiCompare(Register smi1, Register smi2); |
| 348 void SmiCompare(Register dst, Smi* src); | 350 void SmiCompare(Register dst, Smi* src); |
| 349 void SmiCompare(Register dst, const Operand& src); | 351 void SmiCompare(Register dst, const Operand& src); |
| 350 void SmiCompare(const Operand& dst, Register src); | 352 void SmiCompare(const Operand& dst, Register src); |
| 351 void SmiCompare(const Operand& dst, Smi* src); | 353 void SmiCompare(const Operand& dst, Smi* src); |
| 352 // Compare the int32 in src register to the value of the smi stored at dst. | 354 // Compare the int32 in src register to the value of the smi stored at dst. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 392 |
| 391 // Check whether src is a Smi, and set dst to zero if it is a smi, | 393 // Check whether src is a Smi, and set dst to zero if it is a smi, |
| 392 // and to one if it isn't. | 394 // and to one if it isn't. |
| 393 void CheckSmiToIndicator(Register dst, Register src); | 395 void CheckSmiToIndicator(Register dst, Register src); |
| 394 void CheckSmiToIndicator(Register dst, const Operand& src); | 396 void CheckSmiToIndicator(Register dst, const Operand& src); |
| 395 | 397 |
| 396 // Test-and-jump functions. Typically combines a check function | 398 // Test-and-jump functions. Typically combines a check function |
| 397 // above with a conditional jump. | 399 // above with a conditional jump. |
| 398 | 400 |
| 399 // Jump if the value cannot be represented by a smi. | 401 // Jump if the value cannot be represented by a smi. |
| 400 template <typename LabelType> | 402 void JumpIfNotValidSmiValue(Register src, Label* on_invalid, |
| 401 void JumpIfNotValidSmiValue(Register src, LabelType* on_invalid); | 403 Label::Distance near_jump = Label::kFar); |
| 402 | 404 |
| 403 // Jump if the unsigned integer value cannot be represented by a smi. | 405 // Jump if the unsigned integer value cannot be represented by a smi. |
| 404 template <typename LabelType> | 406 void JumpIfUIntNotValidSmiValue(Register src, Label* on_invalid, |
| 405 void JumpIfUIntNotValidSmiValue(Register src, LabelType* on_invalid); | 407 Label::Distance near_jump = Label::kFar); |
| 406 | 408 |
| 407 // Jump to label if the value is a tagged smi. | 409 // Jump to label if the value is a tagged smi. |
| 408 template <typename LabelType> | 410 void JumpIfSmi(Register src, |
| 409 void JumpIfSmi(Register src, LabelType* on_smi); | 411 Label* on_smi, |
| 412 Label::Distance near_jump = Label::kFar); |
| 410 | 413 |
| 411 // Jump to label if the value is not a tagged smi. | 414 // Jump to label if the value is not a tagged smi. |
| 412 template <typename LabelType> | 415 void JumpIfNotSmi(Register src, |
| 413 void JumpIfNotSmi(Register src, LabelType* on_not_smi); | 416 Label* on_not_smi, |
| 417 Label::Distance near_jump = Label::kFar); |
| 414 | 418 |
| 415 // Jump to label if the value is not a non-negative tagged smi. | 419 // Jump to label if the value is not a non-negative tagged smi. |
| 416 template <typename LabelType> | 420 void JumpUnlessNonNegativeSmi(Register src, |
| 417 void JumpUnlessNonNegativeSmi(Register src, LabelType* on_not_smi); | 421 Label* on_not_smi, |
| 422 Label::Distance near_jump = Label::kFar); |
| 418 | 423 |
| 419 // Jump to label if the value, which must be a tagged smi, has value equal | 424 // Jump to label if the value, which must be a tagged smi, has value equal |
| 420 // to the constant. | 425 // to the constant. |
| 421 template <typename LabelType> | |
| 422 void JumpIfSmiEqualsConstant(Register src, | 426 void JumpIfSmiEqualsConstant(Register src, |
| 423 Smi* constant, | 427 Smi* constant, |
| 424 LabelType* on_equals); | 428 Label* on_equals, |
| 429 Label::Distance near_jump = Label::kFar); |
| 425 | 430 |
| 426 // Jump if either or both register are not smi values. | 431 // Jump if either or both register are not smi values. |
| 427 template <typename LabelType> | |
| 428 void JumpIfNotBothSmi(Register src1, | 432 void JumpIfNotBothSmi(Register src1, |
| 429 Register src2, | 433 Register src2, |
| 430 LabelType* on_not_both_smi); | 434 Label* on_not_both_smi, |
| 435 Label::Distance near_jump = Label::kFar); |
| 431 | 436 |
| 432 // Jump if either or both register are not non-negative smi values. | 437 // Jump if either or both register are not non-negative smi values. |
| 433 template <typename LabelType> | |
| 434 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2, | 438 void JumpUnlessBothNonNegativeSmi(Register src1, Register src2, |
| 435 LabelType* on_not_both_smi); | 439 Label* on_not_both_smi, |
| 440 Label::Distance near_jump = Label::kFar); |
| 436 | 441 |
| 437 // Operations on tagged smi values. | 442 // Operations on tagged smi values. |
| 438 | 443 |
| 439 // Smis represent a subset of integers. The subset is always equivalent to | 444 // Smis represent a subset of integers. The subset is always equivalent to |
| 440 // a two's complement interpretation of a fixed number of bits. | 445 // a two's complement interpretation of a fixed number of bits. |
| 441 | 446 |
| 442 // Optimistically adds an integer constant to a supposed smi. | 447 // Optimistically adds an integer constant to a supposed smi. |
| 443 // If the src is not a smi, or the result is not a smi, jump to | 448 // If the src is not a smi, or the result is not a smi, jump to |
| 444 // the label. | 449 // the label. |
| 445 template <typename LabelType> | |
| 446 void SmiTryAddConstant(Register dst, | 450 void SmiTryAddConstant(Register dst, |
| 447 Register src, | 451 Register src, |
| 448 Smi* constant, | 452 Smi* constant, |
| 449 LabelType* on_not_smi_result); | 453 Label* on_not_smi_result, |
| 454 Label::Distance near_jump = Label::kFar); |
| 450 | 455 |
| 451 // Add an integer constant to a tagged smi, giving a tagged smi as result. | 456 // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 452 // No overflow testing on the result is done. | 457 // No overflow testing on the result is done. |
| 453 void SmiAddConstant(Register dst, Register src, Smi* constant); | 458 void SmiAddConstant(Register dst, Register src, Smi* constant); |
| 454 | 459 |
| 455 // Add an integer constant to a tagged smi, giving a tagged smi as result. | 460 // Add an integer constant to a tagged smi, giving a tagged smi as result. |
| 456 // No overflow testing on the result is done. | 461 // No overflow testing on the result is done. |
| 457 void SmiAddConstant(const Operand& dst, Smi* constant); | 462 void SmiAddConstant(const Operand& dst, Smi* constant); |
| 458 | 463 |
| 459 // Add an integer constant to a tagged smi, giving a tagged smi as result, | 464 // Add an integer constant to a tagged smi, giving a tagged smi as result, |
| 460 // or jumping to a label if the result cannot be represented by a smi. | 465 // or jumping to a label if the result cannot be represented by a smi. |
| 461 template <typename LabelType> | |
| 462 void SmiAddConstant(Register dst, | 466 void SmiAddConstant(Register dst, |
| 463 Register src, | 467 Register src, |
| 464 Smi* constant, | 468 Smi* constant, |
| 465 LabelType* on_not_smi_result); | 469 Label* on_not_smi_result, |
| 470 Label::Distance near_jump = Label::kFar); |
| 466 | 471 |
| 467 // Subtract an integer constant from a tagged smi, giving a tagged smi as | 472 // Subtract an integer constant from a tagged smi, giving a tagged smi as |
| 468 // result. No testing on the result is done. Sets the N and Z flags | 473 // result. No testing on the result is done. Sets the N and Z flags |
| 469 // based on the value of the resulting integer. | 474 // based on the value of the resulting integer. |
| 470 void SmiSubConstant(Register dst, Register src, Smi* constant); | 475 void SmiSubConstant(Register dst, Register src, Smi* constant); |
| 471 | 476 |
| 472 // Subtract an integer constant from a tagged smi, giving a tagged smi as | 477 // Subtract an integer constant from a tagged smi, giving a tagged smi as |
| 473 // result, or jumping to a label if the result cannot be represented by a smi. | 478 // result, or jumping to a label if the result cannot be represented by a smi. |
| 474 template <typename LabelType> | |
| 475 void SmiSubConstant(Register dst, | 479 void SmiSubConstant(Register dst, |
| 476 Register src, | 480 Register src, |
| 477 Smi* constant, | 481 Smi* constant, |
| 478 LabelType* on_not_smi_result); | 482 Label* on_not_smi_result, |
| 483 Label::Distance near_jump = Label::kFar); |
| 479 | 484 |
| 480 // Negating a smi can give a negative zero or too large positive value. | 485 // Negating a smi can give a negative zero or too large positive value. |
| 481 // NOTICE: This operation jumps on success, not failure! | 486 // NOTICE: This operation jumps on success, not failure! |
| 482 template <typename LabelType> | |
| 483 void SmiNeg(Register dst, | 487 void SmiNeg(Register dst, |
| 484 Register src, | 488 Register src, |
| 485 LabelType* on_smi_result); | 489 Label* on_smi_result, |
| 490 Label::Distance near_jump = Label::kFar); |
| 486 | 491 |
| 487 // Adds smi values and return the result as a smi. | 492 // Adds smi values and return the result as a smi. |
| 488 // If dst is src1, then src1 will be destroyed, even if | 493 // If dst is src1, then src1 will be destroyed, even if |
| 489 // the operation is unsuccessful. | 494 // the operation is unsuccessful. |
| 490 template <typename LabelType> | |
| 491 void SmiAdd(Register dst, | 495 void SmiAdd(Register dst, |
| 492 Register src1, | 496 Register src1, |
| 493 Register src2, | 497 Register src2, |
| 494 LabelType* on_not_smi_result); | 498 Label* on_not_smi_result, |
| 495 template <typename LabelType> | 499 Label::Distance near_jump = Label::kFar); |
| 496 void SmiAdd(Register dst, | 500 void SmiAdd(Register dst, |
| 497 Register src1, | 501 Register src1, |
| 498 const Operand& src2, | 502 const Operand& src2, |
| 499 LabelType* on_not_smi_result); | 503 Label* on_not_smi_result, |
| 504 Label::Distance near_jump = Label::kFar); |
| 500 | 505 |
| 501 void SmiAdd(Register dst, | 506 void SmiAdd(Register dst, |
| 502 Register src1, | 507 Register src1, |
| 503 Register src2); | 508 Register src2); |
| 504 | 509 |
| 505 // Subtracts smi values and return the result as a smi. | 510 // Subtracts smi values and return the result as a smi. |
| 506 // If dst is src1, then src1 will be destroyed, even if | 511 // If dst is src1, then src1 will be destroyed, even if |
| 507 // the operation is unsuccessful. | 512 // the operation is unsuccessful. |
| 508 template <typename LabelType> | |
| 509 void SmiSub(Register dst, | 513 void SmiSub(Register dst, |
| 510 Register src1, | 514 Register src1, |
| 511 Register src2, | 515 Register src2, |
| 512 LabelType* on_not_smi_result); | 516 Label* on_not_smi_result, |
| 517 Label::Distance near_jump = Label::kFar); |
| 513 | 518 |
| 514 void SmiSub(Register dst, | 519 void SmiSub(Register dst, |
| 515 Register src1, | 520 Register src1, |
| 516 Register src2); | 521 Register src2); |
| 517 | 522 |
| 518 template <typename LabelType> | |
| 519 void SmiSub(Register dst, | 523 void SmiSub(Register dst, |
| 520 Register src1, | 524 Register src1, |
| 521 const Operand& src2, | 525 const Operand& src2, |
| 522 LabelType* on_not_smi_result); | 526 Label* on_not_smi_result, |
| 527 Label::Distance near_jump = Label::kFar); |
| 523 | 528 |
| 524 void SmiSub(Register dst, | 529 void SmiSub(Register dst, |
| 525 Register src1, | 530 Register src1, |
| 526 const Operand& src2); | 531 const Operand& src2); |
| 527 | 532 |
| 528 // Multiplies smi values and return the result as a smi, | 533 // Multiplies smi values and return the result as a smi, |
| 529 // if possible. | 534 // if possible. |
| 530 // If dst is src1, then src1 will be destroyed, even if | 535 // If dst is src1, then src1 will be destroyed, even if |
| 531 // the operation is unsuccessful. | 536 // the operation is unsuccessful. |
| 532 template <typename LabelType> | |
| 533 void SmiMul(Register dst, | 537 void SmiMul(Register dst, |
| 534 Register src1, | 538 Register src1, |
| 535 Register src2, | 539 Register src2, |
| 536 LabelType* on_not_smi_result); | 540 Label* on_not_smi_result, |
| 541 Label::Distance near_jump = Label::kFar); |
| 537 | 542 |
| 538 // Divides one smi by another and returns the quotient. | 543 // Divides one smi by another and returns the quotient. |
| 539 // Clobbers rax and rdx registers. | 544 // Clobbers rax and rdx registers. |
| 540 template <typename LabelType> | |
| 541 void SmiDiv(Register dst, | 545 void SmiDiv(Register dst, |
| 542 Register src1, | 546 Register src1, |
| 543 Register src2, | 547 Register src2, |
| 544 LabelType* on_not_smi_result); | 548 Label* on_not_smi_result, |
| 549 Label::Distance near_jump = Label::kFar); |
| 545 | 550 |
| 546 // Divides one smi by another and returns the remainder. | 551 // Divides one smi by another and returns the remainder. |
| 547 // Clobbers rax and rdx registers. | 552 // Clobbers rax and rdx registers. |
| 548 template <typename LabelType> | |
| 549 void SmiMod(Register dst, | 553 void SmiMod(Register dst, |
| 550 Register src1, | 554 Register src1, |
| 551 Register src2, | 555 Register src2, |
| 552 LabelType* on_not_smi_result); | 556 Label* on_not_smi_result, |
| 557 Label::Distance near_jump = Label::kFar); |
| 553 | 558 |
| 554 // Bitwise operations. | 559 // Bitwise operations. |
| 555 void SmiNot(Register dst, Register src); | 560 void SmiNot(Register dst, Register src); |
| 556 void SmiAnd(Register dst, Register src1, Register src2); | 561 void SmiAnd(Register dst, Register src1, Register src2); |
| 557 void SmiOr(Register dst, Register src1, Register src2); | 562 void SmiOr(Register dst, Register src1, Register src2); |
| 558 void SmiXor(Register dst, Register src1, Register src2); | 563 void SmiXor(Register dst, Register src1, Register src2); |
| 559 void SmiAndConstant(Register dst, Register src1, Smi* constant); | 564 void SmiAndConstant(Register dst, Register src1, Smi* constant); |
| 560 void SmiOrConstant(Register dst, Register src1, Smi* constant); | 565 void SmiOrConstant(Register dst, Register src1, Smi* constant); |
| 561 void SmiXorConstant(Register dst, Register src1, Smi* constant); | 566 void SmiXorConstant(Register dst, Register src1, Smi* constant); |
| 562 | 567 |
| 563 void SmiShiftLeftConstant(Register dst, | 568 void SmiShiftLeftConstant(Register dst, |
| 564 Register src, | 569 Register src, |
| 565 int shift_value); | 570 int shift_value); |
| 566 template <typename LabelType> | |
| 567 void SmiShiftLogicalRightConstant(Register dst, | 571 void SmiShiftLogicalRightConstant(Register dst, |
| 568 Register src, | 572 Register src, |
| 569 int shift_value, | 573 int shift_value, |
| 570 LabelType* on_not_smi_result); | 574 Label* on_not_smi_result, |
| 575 Label::Distance near_jump = Label::kFar); |
| 571 void SmiShiftArithmeticRightConstant(Register dst, | 576 void SmiShiftArithmeticRightConstant(Register dst, |
| 572 Register src, | 577 Register src, |
| 573 int shift_value); | 578 int shift_value); |
| 574 | 579 |
| 575 // Shifts a smi value to the left, and returns the result if that is a smi. | 580 // Shifts a smi value to the left, and returns the result if that is a smi. |
| 576 // Uses and clobbers rcx, so dst may not be rcx. | 581 // Uses and clobbers rcx, so dst may not be rcx. |
| 577 void SmiShiftLeft(Register dst, | 582 void SmiShiftLeft(Register dst, |
| 578 Register src1, | 583 Register src1, |
| 579 Register src2); | 584 Register src2); |
| 580 // Shifts a smi value to the right, shifting in zero bits at the top, and | 585 // Shifts a smi value to the right, shifting in zero bits at the top, and |
| 581 // returns the unsigned intepretation of the result if that is a smi. | 586 // returns the unsigned intepretation of the result if that is a smi. |
| 582 // Uses and clobbers rcx, so dst may not be rcx. | 587 // Uses and clobbers rcx, so dst may not be rcx. |
| 583 template <typename LabelType> | |
| 584 void SmiShiftLogicalRight(Register dst, | 588 void SmiShiftLogicalRight(Register dst, |
| 585 Register src1, | 589 Register src1, |
| 586 Register src2, | 590 Register src2, |
| 587 LabelType* on_not_smi_result); | 591 Label* on_not_smi_result, |
| 592 Label::Distance near_jump = Label::kFar); |
| 588 // Shifts a smi value to the right, sign extending the top, and | 593 // Shifts a smi value to the right, sign extending the top, and |
| 589 // returns the signed intepretation of the result. That will always | 594 // returns the signed intepretation of the result. That will always |
| 590 // be a valid smi value, since it's numerically smaller than the | 595 // be a valid smi value, since it's numerically smaller than the |
| 591 // original. | 596 // original. |
| 592 // Uses and clobbers rcx, so dst may not be rcx. | 597 // Uses and clobbers rcx, so dst may not be rcx. |
| 593 void SmiShiftArithmeticRight(Register dst, | 598 void SmiShiftArithmeticRight(Register dst, |
| 594 Register src1, | 599 Register src1, |
| 595 Register src2); | 600 Register src2); |
| 596 | 601 |
| 597 // Specialized operations | 602 // Specialized operations |
| 598 | 603 |
| 599 // Select the non-smi register of two registers where exactly one is a | 604 // Select the non-smi register of two registers where exactly one is a |
| 600 // smi. If neither are smis, jump to the failure label. | 605 // smi. If neither are smis, jump to the failure label. |
| 601 template <typename LabelType> | |
| 602 void SelectNonSmi(Register dst, | 606 void SelectNonSmi(Register dst, |
| 603 Register src1, | 607 Register src1, |
| 604 Register src2, | 608 Register src2, |
| 605 LabelType* on_not_smis); | 609 Label* on_not_smis, |
| 610 Label::Distance near_jump = Label::kFar); |
| 606 | 611 |
| 607 // Converts, if necessary, a smi to a combination of number and | 612 // Converts, if necessary, a smi to a combination of number and |
| 608 // multiplier to be used as a scaled index. | 613 // multiplier to be used as a scaled index. |
| 609 // The src register contains a *positive* smi value. The shift is the | 614 // The src register contains a *positive* smi value. The shift is the |
| 610 // power of two to multiply the index value by (e.g. | 615 // power of two to multiply the index value by (e.g. |
| 611 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2). | 616 // to index by smi-value * kPointerSize, pass the smi and kPointerSizeLog2). |
| 612 // The returned index register may be either src or dst, depending | 617 // The returned index register may be either src or dst, depending |
| 613 // on what is most efficient. If src and dst are different registers, | 618 // on what is most efficient. If src and dst are different registers, |
| 614 // src is always unchanged. | 619 // src is always unchanged. |
| 615 SmiIndex SmiToIndex(Register dst, Register src, int shift); | 620 SmiIndex SmiToIndex(Register dst, Register src, int shift); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 631 movq(dst, constant); | 636 movq(dst, constant); |
| 632 } | 637 } |
| 633 | 638 |
| 634 void Push(Smi* smi); | 639 void Push(Smi* smi); |
| 635 void Test(const Operand& dst, Smi* source); | 640 void Test(const Operand& dst, Smi* source); |
| 636 | 641 |
| 637 // --------------------------------------------------------------------------- | 642 // --------------------------------------------------------------------------- |
| 638 // String macros. | 643 // String macros. |
| 639 | 644 |
| 640 // If object is a string, its map is loaded into object_map. | 645 // If object is a string, its map is loaded into object_map. |
| 641 template <typename LabelType> | |
| 642 void JumpIfNotString(Register object, | 646 void JumpIfNotString(Register object, |
| 643 Register object_map, | 647 Register object_map, |
| 644 LabelType* not_string); | 648 Label* not_string, |
| 649 Label::Distance near_jump = Label::kFar); |
| 645 | 650 |
| 646 | 651 |
| 647 template <typename LabelType> | 652 void JumpIfNotBothSequentialAsciiStrings( |
| 648 void JumpIfNotBothSequentialAsciiStrings(Register first_object, | 653 Register first_object, |
| 649 Register second_object, | 654 Register second_object, |
| 650 Register scratch1, | 655 Register scratch1, |
| 651 Register scratch2, | 656 Register scratch2, |
| 652 LabelType* on_not_both_flat_ascii); | 657 Label* on_not_both_flat_ascii, |
| 658 Label::Distance near_jump = Label::kFar); |
| 653 | 659 |
| 654 // Check whether the instance type represents a flat ascii string. Jump to the | 660 // Check whether the instance type represents a flat ascii string. Jump to the |
| 655 // label if not. If the instance type can be scratched specify same register | 661 // label if not. If the instance type can be scratched specify same register |
| 656 // for both instance type and scratch. | 662 // for both instance type and scratch. |
| 657 template <typename LabelType> | |
| 658 void JumpIfInstanceTypeIsNotSequentialAscii( | 663 void JumpIfInstanceTypeIsNotSequentialAscii( |
| 659 Register instance_type, | 664 Register instance_type, |
| 660 Register scratch, | 665 Register scratch, |
| 661 LabelType *on_not_flat_ascii_string); | 666 Label*on_not_flat_ascii_string, |
| 667 Label::Distance near_jump = Label::kFar); |
| 662 | 668 |
| 663 template <typename LabelType> | |
| 664 void JumpIfBothInstanceTypesAreNotSequentialAscii( | 669 void JumpIfBothInstanceTypesAreNotSequentialAscii( |
| 665 Register first_object_instance_type, | 670 Register first_object_instance_type, |
| 666 Register second_object_instance_type, | 671 Register second_object_instance_type, |
| 667 Register scratch1, | 672 Register scratch1, |
| 668 Register scratch2, | 673 Register scratch2, |
| 669 LabelType* on_fail); | 674 Label* on_fail, |
| 675 Label::Distance near_jump = Label::kFar); |
| 670 | 676 |
| 671 // --------------------------------------------------------------------------- | 677 // --------------------------------------------------------------------------- |
| 672 // Macro instructions. | 678 // Macro instructions. |
| 673 | 679 |
| 674 // Load a register with a long value as efficiently as possible. | 680 // Load a register with a long value as efficiently as possible. |
| 675 void Set(Register dst, int64_t x); | 681 void Set(Register dst, int64_t x); |
| 676 void Set(const Operand& dst, int64_t x); | 682 void Set(const Operand& dst, int64_t x); |
| 677 | 683 |
| 678 // Move if the registers are not identical. | 684 // Move if the registers are not identical. |
| 679 void Move(Register target, Register source); | 685 void Move(Register target, Register source); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 // Compare instance type for map. | 753 // Compare instance type for map. |
| 748 // Always use unsigned comparisons: above and below, not less and greater. | 754 // Always use unsigned comparisons: above and below, not less and greater. |
| 749 void CmpInstanceType(Register map, InstanceType type); | 755 void CmpInstanceType(Register map, InstanceType type); |
| 750 | 756 |
| 751 // Check if the map of an object is equal to a specified map and | 757 // Check if the map of an object is equal to a specified map and |
| 752 // branch to label if not. Skip the smi check if not required | 758 // branch to label if not. Skip the smi check if not required |
| 753 // (object is known to be a heap object) | 759 // (object is known to be a heap object) |
| 754 void CheckMap(Register obj, | 760 void CheckMap(Register obj, |
| 755 Handle<Map> map, | 761 Handle<Map> map, |
| 756 Label* fail, | 762 Label* fail, |
| 757 bool is_heap_object); | 763 SmiCheckType smi_check_type); |
| 764 |
| 765 // Check if the map of an object is equal to a specified map and branch to a |
| 766 // specified target if equal. Skip the smi check if not required (object is |
| 767 // known to be a heap object) |
| 768 void DispatchMap(Register obj, |
| 769 Handle<Map> map, |
| 770 Handle<Code> success, |
| 771 SmiCheckType smi_check_type); |
| 758 | 772 |
| 759 // Check if the object in register heap_object is a string. Afterwards the | 773 // Check if the object in register heap_object is a string. Afterwards the |
| 760 // register map contains the object map and the register instance_type | 774 // register map contains the object map and the register instance_type |
| 761 // contains the instance_type. The registers map and instance_type can be the | 775 // contains the instance_type. The registers map and instance_type can be the |
| 762 // same in which case it contains the instance type afterwards. Either of the | 776 // same in which case it contains the instance type afterwards. Either of the |
| 763 // registers map and instance_type can be the same as heap_object. | 777 // registers map and instance_type can be the same as heap_object. |
| 764 Condition IsObjectStringType(Register heap_object, | 778 Condition IsObjectStringType(Register heap_object, |
| 765 Register map, | 779 Register map, |
| 766 Register instance_type); | 780 Register instance_type); |
| 767 | 781 |
| 768 // FCmp compares and pops the two values on top of the FPU stack. | 782 // FCmp compares and pops the two values on top of the FPU stack. |
| 769 // The flag results are similar to integer cmp, but requires unsigned | 783 // The flag results are similar to integer cmp, but requires unsigned |
| 770 // jcc instructions (je, ja, jae, jb, jbe, je, and jz). | 784 // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 771 void FCmp(); | 785 void FCmp(); |
| 772 | 786 |
| 787 void ClampUint8(Register reg); |
| 788 |
| 789 void ClampDoubleToUint8(XMMRegister input_reg, |
| 790 XMMRegister temp_xmm_reg, |
| 791 Register result_reg, |
| 792 Register temp_reg); |
| 793 |
| 773 // Abort execution if argument is not a number. Used in debug code. | 794 // Abort execution if argument is not a number. Used in debug code. |
| 774 void AbortIfNotNumber(Register object); | 795 void AbortIfNotNumber(Register object); |
| 775 | 796 |
| 776 // Abort execution if argument is a smi. Used in debug code. | 797 // Abort execution if argument is a smi. Used in debug code. |
| 777 void AbortIfSmi(Register object); | 798 void AbortIfSmi(Register object); |
| 778 | 799 |
| 779 // Abort execution if argument is not a smi. Used in debug code. | 800 // Abort execution if argument is not a smi. Used in debug code. |
| 780 void AbortIfNotSmi(Register object); | 801 void AbortIfNotSmi(Register object); |
| 781 void AbortIfNotSmi(const Operand& object); | 802 void AbortIfNotSmi(const Operand& object); |
| 782 | 803 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 | 1126 |
| 1106 static int SafepointRegisterStackIndex(Register reg) { | 1127 static int SafepointRegisterStackIndex(Register reg) { |
| 1107 return SafepointRegisterStackIndex(reg.code()); | 1128 return SafepointRegisterStackIndex(reg.code()); |
| 1108 } | 1129 } |
| 1109 | 1130 |
| 1110 private: | 1131 private: |
| 1111 // Order general registers are pushed by Pushad. | 1132 // Order general registers are pushed by Pushad. |
| 1112 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15. | 1133 // rax, rcx, rdx, rbx, rsi, rdi, r8, r9, r11, r14, r15. |
| 1113 static int kSafepointPushRegisterIndices[Register::kNumRegisters]; | 1134 static int kSafepointPushRegisterIndices[Register::kNumRegisters]; |
| 1114 static const int kNumSafepointSavedRegisters = 11; | 1135 static const int kNumSafepointSavedRegisters = 11; |
| 1136 static const int kSmiShift = kSmiTagSize + kSmiShiftSize; |
| 1115 | 1137 |
| 1116 bool generating_stub_; | 1138 bool generating_stub_; |
| 1117 bool allow_stub_calls_; | 1139 bool allow_stub_calls_; |
| 1118 bool root_array_available_; | 1140 bool root_array_available_; |
| 1119 | 1141 |
| 1120 // Returns a register holding the smi value. The register MUST NOT be | 1142 // Returns a register holding the smi value. The register MUST NOT be |
| 1121 // modified. It may be the "smi 1 constant" register. | 1143 // modified. It may be the "smi 1 constant" register. |
| 1122 Register GetSmiConstant(Smi* value); | 1144 Register GetSmiConstant(Smi* value); |
| 1123 | 1145 |
| 1124 // Moves the smi value to the destination register. | 1146 // Moves the smi value to the destination register. |
| 1125 void LoadSmiConstant(Register dst, Smi* value); | 1147 void LoadSmiConstant(Register dst, Smi* value); |
| 1126 | 1148 |
| 1127 // This handle will be patched with the code object on installation. | 1149 // This handle will be patched with the code object on installation. |
| 1128 Handle<Object> code_object_; | 1150 Handle<Object> code_object_; |
| 1129 | 1151 |
| 1130 // Helper functions for generating invokes. | 1152 // Helper functions for generating invokes. |
| 1131 template <typename LabelType> | |
| 1132 void InvokePrologue(const ParameterCount& expected, | 1153 void InvokePrologue(const ParameterCount& expected, |
| 1133 const ParameterCount& actual, | 1154 const ParameterCount& actual, |
| 1134 Handle<Code> code_constant, | 1155 Handle<Code> code_constant, |
| 1135 Register code_register, | 1156 Register code_register, |
| 1136 LabelType* done, | 1157 Label* done, |
| 1137 InvokeFlag flag, | 1158 InvokeFlag flag, |
| 1138 const CallWrapper& call_wrapper); | 1159 const CallWrapper& call_wrapper, |
| 1160 Label::Distance near_jump = Label::kFar); |
| 1139 | 1161 |
| 1140 // Activation support. | 1162 // Activation support. |
| 1141 void EnterFrame(StackFrame::Type type); | 1163 void EnterFrame(StackFrame::Type type); |
| 1142 void LeaveFrame(StackFrame::Type type); | 1164 void LeaveFrame(StackFrame::Type type); |
| 1143 | 1165 |
| 1144 void EnterExitFramePrologue(bool save_rax); | 1166 void EnterExitFramePrologue(bool save_rax); |
| 1145 | 1167 |
| 1146 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack | 1168 // Allocates arg_stack_space * kPointerSize memory (not GCed) on the stack |
| 1147 // accessible via StackSpaceOperand. | 1169 // accessible via StackSpaceOperand. |
| 1148 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles); | 1170 void EnterExitFrameEpilogue(int arg_stack_space, bool save_doubles); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \ | 1276 masm->call(x64_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 1255 masm->pop(rax); \ | 1277 masm->pop(rax); \ |
| 1256 masm->popad(); \ | 1278 masm->popad(); \ |
| 1257 masm->popfd(); \ | 1279 masm->popfd(); \ |
| 1258 } \ | 1280 } \ |
| 1259 masm-> | 1281 masm-> |
| 1260 #else | 1282 #else |
| 1261 #define ACCESS_MASM(masm) masm-> | 1283 #define ACCESS_MASM(masm) masm-> |
| 1262 #endif | 1284 #endif |
| 1263 | 1285 |
| 1264 // ----------------------------------------------------------------------------- | |
| 1265 // Template implementations. | |
| 1266 | |
| 1267 static int kSmiShift = kSmiTagSize + kSmiShiftSize; | |
| 1268 | |
| 1269 | |
| 1270 template <typename LabelType> | |
| 1271 void MacroAssembler::SmiNeg(Register dst, | |
| 1272 Register src, | |
| 1273 LabelType* on_smi_result) { | |
| 1274 if (dst.is(src)) { | |
| 1275 ASSERT(!dst.is(kScratchRegister)); | |
| 1276 movq(kScratchRegister, src); | |
| 1277 neg(dst); // Low 32 bits are retained as zero by negation. | |
| 1278 // Test if result is zero or Smi::kMinValue. | |
| 1279 cmpq(dst, kScratchRegister); | |
| 1280 j(not_equal, on_smi_result); | |
| 1281 movq(src, kScratchRegister); | |
| 1282 } else { | |
| 1283 movq(dst, src); | |
| 1284 neg(dst); | |
| 1285 cmpq(dst, src); | |
| 1286 // If the result is zero or Smi::kMinValue, negation failed to create a smi. | |
| 1287 j(not_equal, on_smi_result); | |
| 1288 } | |
| 1289 } | |
| 1290 | |
| 1291 | |
| 1292 template <typename LabelType> | |
| 1293 void MacroAssembler::SmiAdd(Register dst, | |
| 1294 Register src1, | |
| 1295 Register src2, | |
| 1296 LabelType* on_not_smi_result) { | |
| 1297 ASSERT_NOT_NULL(on_not_smi_result); | |
| 1298 ASSERT(!dst.is(src2)); | |
| 1299 if (dst.is(src1)) { | |
| 1300 movq(kScratchRegister, src1); | |
| 1301 addq(kScratchRegister, src2); | |
| 1302 j(overflow, on_not_smi_result); | |
| 1303 movq(dst, kScratchRegister); | |
| 1304 } else { | |
| 1305 movq(dst, src1); | |
| 1306 addq(dst, src2); | |
| 1307 j(overflow, on_not_smi_result); | |
| 1308 } | |
| 1309 } | |
| 1310 | |
| 1311 | |
| 1312 template <typename LabelType> | |
| 1313 void MacroAssembler::SmiAdd(Register dst, | |
| 1314 Register src1, | |
| 1315 const Operand& src2, | |
| 1316 LabelType* on_not_smi_result) { | |
| 1317 ASSERT_NOT_NULL(on_not_smi_result); | |
| 1318 if (dst.is(src1)) { | |
| 1319 movq(kScratchRegister, src1); | |
| 1320 addq(kScratchRegister, src2); | |
| 1321 j(overflow, on_not_smi_result); | |
| 1322 movq(dst, kScratchRegister); | |
| 1323 } else { | |
| 1324 ASSERT(!src2.AddressUsesRegister(dst)); | |
| 1325 movq(dst, src1); | |
| 1326 addq(dst, src2); | |
| 1327 j(overflow, on_not_smi_result); | |
| 1328 } | |
| 1329 } | |
| 1330 | |
| 1331 | |
| 1332 template <typename LabelType> | |
| 1333 void MacroAssembler::SmiSub(Register dst, | |
| 1334 Register src1, | |
| 1335 Register src2, | |
| 1336 LabelType* on_not_smi_result) { | |
| 1337 ASSERT_NOT_NULL(on_not_smi_result); | |
| 1338 ASSERT(!dst.is(src2)); | |
| 1339 if (dst.is(src1)) { | |
| 1340 cmpq(dst, src2); | |
| 1341 j(overflow, on_not_smi_result); | |
| 1342 subq(dst, src2); | |
| 1343 } else { | |
| 1344 movq(dst, src1); | |
| 1345 subq(dst, src2); | |
| 1346 j(overflow, on_not_smi_result); | |
| 1347 } | |
| 1348 } | |
| 1349 | |
| 1350 | |
| 1351 template <typename LabelType> | |
| 1352 void MacroAssembler::SmiSub(Register dst, | |
| 1353 Register src1, | |
| 1354 const Operand& src2, | |
| 1355 LabelType* on_not_smi_result) { | |
| 1356 ASSERT_NOT_NULL(on_not_smi_result); | |
| 1357 if (dst.is(src1)) { | |
| 1358 movq(kScratchRegister, src2); | |
| 1359 cmpq(src1, kScratchRegister); | |
| 1360 j(overflow, on_not_smi_result); | |
| 1361 subq(src1, kScratchRegister); | |
| 1362 } else { | |
| 1363 movq(dst, src1); | |
| 1364 subq(dst, src2); | |
| 1365 j(overflow, on_not_smi_result); | |
| 1366 } | |
| 1367 } | |
| 1368 | |
| 1369 | |
| 1370 template <typename LabelType> | |
| 1371 void MacroAssembler::SmiMul(Register dst, | |
| 1372 Register src1, | |
| 1373 Register src2, | |
| 1374 LabelType* on_not_smi_result) { | |
| 1375 ASSERT(!dst.is(src2)); | |
| 1376 ASSERT(!dst.is(kScratchRegister)); | |
| 1377 ASSERT(!src1.is(kScratchRegister)); | |
| 1378 ASSERT(!src2.is(kScratchRegister)); | |
| 1379 | |
| 1380 if (dst.is(src1)) { | |
| 1381 NearLabel failure, zero_correct_result; | |
| 1382 movq(kScratchRegister, src1); // Create backup for later testing. | |
| 1383 SmiToInteger64(dst, src1); | |
| 1384 imul(dst, src2); | |
| 1385 j(overflow, &failure); | |
| 1386 | |
| 1387 // Check for negative zero result. If product is zero, and one | |
| 1388 // argument is negative, go to slow case. | |
| 1389 NearLabel correct_result; | |
| 1390 testq(dst, dst); | |
| 1391 j(not_zero, &correct_result); | |
| 1392 | |
| 1393 movq(dst, kScratchRegister); | |
| 1394 xor_(dst, src2); | |
| 1395 j(positive, &zero_correct_result); // Result was positive zero. | |
| 1396 | |
| 1397 bind(&failure); // Reused failure exit, restores src1. | |
| 1398 movq(src1, kScratchRegister); | |
| 1399 jmp(on_not_smi_result); | |
| 1400 | |
| 1401 bind(&zero_correct_result); | |
| 1402 Set(dst, 0); | |
| 1403 | |
| 1404 bind(&correct_result); | |
| 1405 } else { | |
| 1406 SmiToInteger64(dst, src1); | |
| 1407 imul(dst, src2); | |
| 1408 j(overflow, on_not_smi_result); | |
| 1409 // Check for negative zero result. If product is zero, and one | |
| 1410 // argument is negative, go to slow case. | |
| 1411 NearLabel correct_result; | |
| 1412 testq(dst, dst); | |
| 1413 j(not_zero, &correct_result); | |
| 1414 // One of src1 and src2 is zero, the check whether the other is | |
| 1415 // negative. | |
| 1416 movq(kScratchRegister, src1); | |
| 1417 xor_(kScratchRegister, src2); | |
| 1418 j(negative, on_not_smi_result); | |
| 1419 bind(&correct_result); | |
| 1420 } | |
| 1421 } | |
| 1422 | |
| 1423 | |
| 1424 template <typename LabelType> | |
| 1425 void MacroAssembler::SmiTryAddConstant(Register dst, | |
| 1426 Register src, | |
| 1427 Smi* constant, | |
| 1428 LabelType* on_not_smi_result) { | |
| 1429 // Does not assume that src is a smi. | |
| 1430 ASSERT_EQ(static_cast<int>(1), static_cast<int>(kSmiTagMask)); | |
| 1431 ASSERT_EQ(0, kSmiTag); | |
| 1432 ASSERT(!dst.is(kScratchRegister)); | |
| 1433 ASSERT(!src.is(kScratchRegister)); | |
| 1434 | |
| 1435 JumpIfNotSmi(src, on_not_smi_result); | |
| 1436 Register tmp = (dst.is(src) ? kScratchRegister : dst); | |
| 1437 LoadSmiConstant(tmp, constant); | |
| 1438 addq(tmp, src); | |
| 1439 j(overflow, on_not_smi_result); | |
| 1440 if (dst.is(src)) { | |
| 1441 movq(dst, tmp); | |
| 1442 } | |
| 1443 } | |
| 1444 | |
| 1445 | |
| 1446 template <typename LabelType> | |
| 1447 void MacroAssembler::SmiAddConstant(Register dst, | |
| 1448 Register src, | |
| 1449 Smi* constant, | |
| 1450 LabelType* on_not_smi_result) { | |
| 1451 if (constant->value() == 0) { | |
| 1452 if (!dst.is(src)) { | |
| 1453 movq(dst, src); | |
| 1454 } | |
| 1455 } else if (dst.is(src)) { | |
| 1456 ASSERT(!dst.is(kScratchRegister)); | |
| 1457 | |
| 1458 LoadSmiConstant(kScratchRegister, constant); | |
| 1459 addq(kScratchRegister, src); | |
| 1460 j(overflow, on_not_smi_result); | |
| 1461 movq(dst, kScratchRegister); | |
| 1462 } else { | |
| 1463 LoadSmiConstant(dst, constant); | |
| 1464 addq(dst, src); | |
| 1465 j(overflow, on_not_smi_result); | |
| 1466 } | |
| 1467 } | |
| 1468 | |
| 1469 | |
| 1470 template <typename LabelType> | |
| 1471 void MacroAssembler::SmiSubConstant(Register dst, | |
| 1472 Register src, | |
| 1473 Smi* constant, | |
| 1474 LabelType* on_not_smi_result) { | |
| 1475 if (constant->value() == 0) { | |
| 1476 if (!dst.is(src)) { | |
| 1477 movq(dst, src); | |
| 1478 } | |
| 1479 } else if (dst.is(src)) { | |
| 1480 ASSERT(!dst.is(kScratchRegister)); | |
| 1481 if (constant->value() == Smi::kMinValue) { | |
| 1482 // Subtracting min-value from any non-negative value will overflow. | |
| 1483 // We test the non-negativeness before doing the subtraction. | |
| 1484 testq(src, src); | |
| 1485 j(not_sign, on_not_smi_result); | |
| 1486 LoadSmiConstant(kScratchRegister, constant); | |
| 1487 subq(dst, kScratchRegister); | |
| 1488 } else { | |
| 1489 // Subtract by adding the negation. | |
| 1490 LoadSmiConstant(kScratchRegister, Smi::FromInt(-constant->value())); | |
| 1491 addq(kScratchRegister, dst); | |
| 1492 j(overflow, on_not_smi_result); | |
| 1493 movq(dst, kScratchRegister); | |
| 1494 } | |
| 1495 } else { | |
| 1496 if (constant->value() == Smi::kMinValue) { | |
| 1497 // Subtracting min-value from any non-negative value will overflow. | |
| 1498 // We test the non-negativeness before doing the subtraction. | |
| 1499 testq(src, src); | |
| 1500 j(not_sign, on_not_smi_result); | |
| 1501 LoadSmiConstant(dst, constant); | |
| 1502 // Adding and subtracting the min-value gives the same result, it only | |
| 1503 // differs on the overflow bit, which we don't check here. | |
| 1504 addq(dst, src); | |
| 1505 } else { | |
| 1506 // Subtract by adding the negation. | |
| 1507 LoadSmiConstant(dst, Smi::FromInt(-(constant->value()))); | |
| 1508 addq(dst, src); | |
| 1509 j(overflow, on_not_smi_result); | |
| 1510 } | |
| 1511 } | |
| 1512 } | |
| 1513 | |
| 1514 | |
| 1515 template <typename LabelType> | |
| 1516 void MacroAssembler::SmiDiv(Register dst, | |
| 1517 Register src1, | |
| 1518 Register src2, | |
| 1519 LabelType* on_not_smi_result) { | |
| 1520 ASSERT(!src1.is(kScratchRegister)); | |
| 1521 ASSERT(!src2.is(kScratchRegister)); | |
| 1522 ASSERT(!dst.is(kScratchRegister)); | |
| 1523 ASSERT(!src2.is(rax)); | |
| 1524 ASSERT(!src2.is(rdx)); | |
| 1525 ASSERT(!src1.is(rdx)); | |
| 1526 | |
| 1527 // Check for 0 divisor (result is +/-Infinity). | |
| 1528 NearLabel positive_divisor; | |
| 1529 testq(src2, src2); | |
| 1530 j(zero, on_not_smi_result); | |
| 1531 | |
| 1532 if (src1.is(rax)) { | |
| 1533 movq(kScratchRegister, src1); | |
| 1534 } | |
| 1535 SmiToInteger32(rax, src1); | |
| 1536 // We need to rule out dividing Smi::kMinValue by -1, since that would | |
| 1537 // overflow in idiv and raise an exception. | |
| 1538 // We combine this with negative zero test (negative zero only happens | |
| 1539 // when dividing zero by a negative number). | |
| 1540 | |
| 1541 // We overshoot a little and go to slow case if we divide min-value | |
| 1542 // by any negative value, not just -1. | |
| 1543 NearLabel safe_div; | |
| 1544 testl(rax, Immediate(0x7fffffff)); | |
| 1545 j(not_zero, &safe_div); | |
| 1546 testq(src2, src2); | |
| 1547 if (src1.is(rax)) { | |
| 1548 j(positive, &safe_div); | |
| 1549 movq(src1, kScratchRegister); | |
| 1550 jmp(on_not_smi_result); | |
| 1551 } else { | |
| 1552 j(negative, on_not_smi_result); | |
| 1553 } | |
| 1554 bind(&safe_div); | |
| 1555 | |
| 1556 SmiToInteger32(src2, src2); | |
| 1557 // Sign extend src1 into edx:eax. | |
| 1558 cdq(); | |
| 1559 idivl(src2); | |
| 1560 Integer32ToSmi(src2, src2); | |
| 1561 // Check that the remainder is zero. | |
| 1562 testl(rdx, rdx); | |
| 1563 if (src1.is(rax)) { | |
| 1564 NearLabel smi_result; | |
| 1565 j(zero, &smi_result); | |
| 1566 movq(src1, kScratchRegister); | |
| 1567 jmp(on_not_smi_result); | |
| 1568 bind(&smi_result); | |
| 1569 } else { | |
| 1570 j(not_zero, on_not_smi_result); | |
| 1571 } | |
| 1572 if (!dst.is(src1) && src1.is(rax)) { | |
| 1573 movq(src1, kScratchRegister); | |
| 1574 } | |
| 1575 Integer32ToSmi(dst, rax); | |
| 1576 } | |
| 1577 | |
| 1578 | |
| 1579 template <typename LabelType> | |
| 1580 void MacroAssembler::SmiMod(Register dst, | |
| 1581 Register src1, | |
| 1582 Register src2, | |
| 1583 LabelType* on_not_smi_result) { | |
| 1584 ASSERT(!dst.is(kScratchRegister)); | |
| 1585 ASSERT(!src1.is(kScratchRegister)); | |
| 1586 ASSERT(!src2.is(kScratchRegister)); | |
| 1587 ASSERT(!src2.is(rax)); | |
| 1588 ASSERT(!src2.is(rdx)); | |
| 1589 ASSERT(!src1.is(rdx)); | |
| 1590 ASSERT(!src1.is(src2)); | |
| 1591 | |
| 1592 testq(src2, src2); | |
| 1593 j(zero, on_not_smi_result); | |
| 1594 | |
| 1595 if (src1.is(rax)) { | |
| 1596 movq(kScratchRegister, src1); | |
| 1597 } | |
| 1598 SmiToInteger32(rax, src1); | |
| 1599 SmiToInteger32(src2, src2); | |
| 1600 | |
| 1601 // Test for the edge case of dividing Smi::kMinValue by -1 (will overflow). | |
| 1602 NearLabel safe_div; | |
| 1603 cmpl(rax, Immediate(Smi::kMinValue)); | |
| 1604 j(not_equal, &safe_div); | |
| 1605 cmpl(src2, Immediate(-1)); | |
| 1606 j(not_equal, &safe_div); | |
| 1607 // Retag inputs and go slow case. | |
| 1608 Integer32ToSmi(src2, src2); | |
| 1609 if (src1.is(rax)) { | |
| 1610 movq(src1, kScratchRegister); | |
| 1611 } | |
| 1612 jmp(on_not_smi_result); | |
| 1613 bind(&safe_div); | |
| 1614 | |
| 1615 // Sign extend eax into edx:eax. | |
| 1616 cdq(); | |
| 1617 idivl(src2); | |
| 1618 // Restore smi tags on inputs. | |
| 1619 Integer32ToSmi(src2, src2); | |
| 1620 if (src1.is(rax)) { | |
| 1621 movq(src1, kScratchRegister); | |
| 1622 } | |
| 1623 // Check for a negative zero result. If the result is zero, and the | |
| 1624 // dividend is negative, go slow to return a floating point negative zero. | |
| 1625 NearLabel smi_result; | |
| 1626 testl(rdx, rdx); | |
| 1627 j(not_zero, &smi_result); | |
| 1628 testq(src1, src1); | |
| 1629 j(negative, on_not_smi_result); | |
| 1630 bind(&smi_result); | |
| 1631 Integer32ToSmi(dst, rdx); | |
| 1632 } | |
| 1633 | |
| 1634 | |
| 1635 template <typename LabelType> | |
| 1636 void MacroAssembler::SmiShiftLogicalRightConstant( | |
| 1637 Register dst, Register src, int shift_value, LabelType* on_not_smi_result) { | |
| 1638 // Logic right shift interprets its result as an *unsigned* number. | |
| 1639 if (dst.is(src)) { | |
| 1640 UNIMPLEMENTED(); // Not used. | |
| 1641 } else { | |
| 1642 movq(dst, src); | |
| 1643 if (shift_value == 0) { | |
| 1644 testq(dst, dst); | |
| 1645 j(negative, on_not_smi_result); | |
| 1646 } | |
| 1647 shr(dst, Immediate(shift_value + kSmiShift)); | |
| 1648 shl(dst, Immediate(kSmiShift)); | |
| 1649 } | |
| 1650 } | |
| 1651 | |
| 1652 | |
| 1653 template <typename LabelType> | |
| 1654 void MacroAssembler::SmiShiftLogicalRight(Register dst, | |
| 1655 Register src1, | |
| 1656 Register src2, | |
| 1657 LabelType* on_not_smi_result) { | |
| 1658 ASSERT(!dst.is(kScratchRegister)); | |
| 1659 ASSERT(!src1.is(kScratchRegister)); | |
| 1660 ASSERT(!src2.is(kScratchRegister)); | |
| 1661 ASSERT(!dst.is(rcx)); | |
| 1662 // dst and src1 can be the same, because the one case that bails out | |
| 1663 // is a shift by 0, which leaves dst, and therefore src1, unchanged. | |
| 1664 NearLabel result_ok; | |
| 1665 if (src1.is(rcx) || src2.is(rcx)) { | |
| 1666 movq(kScratchRegister, rcx); | |
| 1667 } | |
| 1668 if (!dst.is(src1)) { | |
| 1669 movq(dst, src1); | |
| 1670 } | |
| 1671 SmiToInteger32(rcx, src2); | |
| 1672 orl(rcx, Immediate(kSmiShift)); | |
| 1673 shr_cl(dst); // Shift is rcx modulo 0x1f + 32. | |
| 1674 shl(dst, Immediate(kSmiShift)); | |
| 1675 testq(dst, dst); | |
| 1676 if (src1.is(rcx) || src2.is(rcx)) { | |
| 1677 NearLabel positive_result; | |
| 1678 j(positive, &positive_result); | |
| 1679 if (src1.is(rcx)) { | |
| 1680 movq(src1, kScratchRegister); | |
| 1681 } else { | |
| 1682 movq(src2, kScratchRegister); | |
| 1683 } | |
| 1684 jmp(on_not_smi_result); | |
| 1685 bind(&positive_result); | |
| 1686 } else { | |
| 1687 j(negative, on_not_smi_result); // src2 was zero and src1 negative. | |
| 1688 } | |
| 1689 } | |
| 1690 | |
| 1691 | |
| 1692 template <typename LabelType> | |
| 1693 void MacroAssembler::SelectNonSmi(Register dst, | |
| 1694 Register src1, | |
| 1695 Register src2, | |
| 1696 LabelType* on_not_smis) { | |
| 1697 ASSERT(!dst.is(kScratchRegister)); | |
| 1698 ASSERT(!src1.is(kScratchRegister)); | |
| 1699 ASSERT(!src2.is(kScratchRegister)); | |
| 1700 ASSERT(!dst.is(src1)); | |
| 1701 ASSERT(!dst.is(src2)); | |
| 1702 // Both operands must not be smis. | |
| 1703 #ifdef DEBUG | |
| 1704 if (allow_stub_calls()) { // Check contains a stub call. | |
| 1705 Condition not_both_smis = NegateCondition(CheckBothSmi(src1, src2)); | |
| 1706 Check(not_both_smis, "Both registers were smis in SelectNonSmi."); | |
| 1707 } | |
| 1708 #endif | |
| 1709 ASSERT_EQ(0, kSmiTag); | |
| 1710 ASSERT_EQ(0, Smi::FromInt(0)); | |
| 1711 movl(kScratchRegister, Immediate(kSmiTagMask)); | |
| 1712 and_(kScratchRegister, src1); | |
| 1713 testl(kScratchRegister, src2); | |
| 1714 // If non-zero then both are smis. | |
| 1715 j(not_zero, on_not_smis); | |
| 1716 | |
| 1717 // Exactly one operand is a smi. | |
| 1718 ASSERT_EQ(1, static_cast<int>(kSmiTagMask)); | |
| 1719 // kScratchRegister still holds src1 & kSmiTag, which is either zero or one. | |
| 1720 subq(kScratchRegister, Immediate(1)); | |
| 1721 // If src1 is a smi, then scratch register all 1s, else it is all 0s. | |
| 1722 movq(dst, src1); | |
| 1723 xor_(dst, src2); | |
| 1724 and_(dst, kScratchRegister); | |
| 1725 // If src1 is a smi, dst holds src1 ^ src2, else it is zero. | |
| 1726 xor_(dst, src1); | |
| 1727 // If src1 is a smi, dst is src2, else it is src1, i.e., the non-smi. | |
| 1728 } | |
| 1729 | |
| 1730 | |
| 1731 template <typename LabelType> | |
| 1732 void MacroAssembler::JumpIfSmi(Register src, LabelType* on_smi) { | |
| 1733 ASSERT_EQ(0, kSmiTag); | |
| 1734 Condition smi = CheckSmi(src); | |
| 1735 j(smi, on_smi); | |
| 1736 } | |
| 1737 | |
| 1738 | |
| 1739 template <typename LabelType> | |
| 1740 void MacroAssembler::JumpIfNotSmi(Register src, LabelType* on_not_smi) { | |
| 1741 Condition smi = CheckSmi(src); | |
| 1742 j(NegateCondition(smi), on_not_smi); | |
| 1743 } | |
| 1744 | |
| 1745 | |
| 1746 template <typename LabelType> | |
| 1747 void MacroAssembler::JumpUnlessNonNegativeSmi( | |
| 1748 Register src, LabelType* on_not_smi_or_negative) { | |
| 1749 Condition non_negative_smi = CheckNonNegativeSmi(src); | |
| 1750 j(NegateCondition(non_negative_smi), on_not_smi_or_negative); | |
| 1751 } | |
| 1752 | |
| 1753 | |
| 1754 template <typename LabelType> | |
| 1755 void MacroAssembler::JumpIfSmiEqualsConstant(Register src, | |
| 1756 Smi* constant, | |
| 1757 LabelType* on_equals) { | |
| 1758 SmiCompare(src, constant); | |
| 1759 j(equal, on_equals); | |
| 1760 } | |
| 1761 | |
| 1762 | |
| 1763 template <typename LabelType> | |
| 1764 void MacroAssembler::JumpIfNotValidSmiValue(Register src, | |
| 1765 LabelType* on_invalid) { | |
| 1766 Condition is_valid = CheckInteger32ValidSmiValue(src); | |
| 1767 j(NegateCondition(is_valid), on_invalid); | |
| 1768 } | |
| 1769 | |
| 1770 | |
| 1771 template <typename LabelType> | |
| 1772 void MacroAssembler::JumpIfUIntNotValidSmiValue(Register src, | |
| 1773 LabelType* on_invalid) { | |
| 1774 Condition is_valid = CheckUInteger32ValidSmiValue(src); | |
| 1775 j(NegateCondition(is_valid), on_invalid); | |
| 1776 } | |
| 1777 | |
| 1778 | |
| 1779 template <typename LabelType> | |
| 1780 void MacroAssembler::JumpIfNotBothSmi(Register src1, | |
| 1781 Register src2, | |
| 1782 LabelType* on_not_both_smi) { | |
| 1783 Condition both_smi = CheckBothSmi(src1, src2); | |
| 1784 j(NegateCondition(both_smi), on_not_both_smi); | |
| 1785 } | |
| 1786 | |
| 1787 | |
| 1788 template <typename LabelType> | |
| 1789 void MacroAssembler::JumpUnlessBothNonNegativeSmi(Register src1, | |
| 1790 Register src2, | |
| 1791 LabelType* on_not_both_smi) { | |
| 1792 Condition both_smi = CheckBothNonNegativeSmi(src1, src2); | |
| 1793 j(NegateCondition(both_smi), on_not_both_smi); | |
| 1794 } | |
| 1795 | |
| 1796 | |
| 1797 template <typename LabelType> | |
| 1798 void MacroAssembler::SmiOrIfSmis(Register dst, Register src1, Register src2, | |
| 1799 LabelType* on_not_smis) { | |
| 1800 if (dst.is(src1) || dst.is(src2)) { | |
| 1801 ASSERT(!src1.is(kScratchRegister)); | |
| 1802 ASSERT(!src2.is(kScratchRegister)); | |
| 1803 movq(kScratchRegister, src1); | |
| 1804 or_(kScratchRegister, src2); | |
| 1805 JumpIfNotSmi(kScratchRegister, on_not_smis); | |
| 1806 movq(dst, kScratchRegister); | |
| 1807 } else { | |
| 1808 movq(dst, src1); | |
| 1809 or_(dst, src2); | |
| 1810 JumpIfNotSmi(dst, on_not_smis); | |
| 1811 } | |
| 1812 } | |
| 1813 | |
| 1814 | |
| 1815 template <typename LabelType> | |
| 1816 void MacroAssembler::JumpIfNotString(Register object, | |
| 1817 Register object_map, | |
| 1818 LabelType* not_string) { | |
| 1819 Condition is_smi = CheckSmi(object); | |
| 1820 j(is_smi, not_string); | |
| 1821 CmpObjectType(object, FIRST_NONSTRING_TYPE, object_map); | |
| 1822 j(above_equal, not_string); | |
| 1823 } | |
| 1824 | |
| 1825 | |
| 1826 template <typename LabelType> | |
| 1827 void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register first_object, | |
| 1828 Register second_object, | |
| 1829 Register scratch1, | |
| 1830 Register scratch2, | |
| 1831 LabelType* on_fail) { | |
| 1832 // Check that both objects are not smis. | |
| 1833 Condition either_smi = CheckEitherSmi(first_object, second_object); | |
| 1834 j(either_smi, on_fail); | |
| 1835 | |
| 1836 // Load instance type for both strings. | |
| 1837 movq(scratch1, FieldOperand(first_object, HeapObject::kMapOffset)); | |
| 1838 movq(scratch2, FieldOperand(second_object, HeapObject::kMapOffset)); | |
| 1839 movzxbl(scratch1, FieldOperand(scratch1, Map::kInstanceTypeOffset)); | |
| 1840 movzxbl(scratch2, FieldOperand(scratch2, Map::kInstanceTypeOffset)); | |
| 1841 | |
| 1842 // Check that both are flat ascii strings. | |
| 1843 ASSERT(kNotStringTag != 0); | |
| 1844 const int kFlatAsciiStringMask = | |
| 1845 kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; | |
| 1846 const int kFlatAsciiStringTag = ASCII_STRING_TYPE; | |
| 1847 | |
| 1848 andl(scratch1, Immediate(kFlatAsciiStringMask)); | |
| 1849 andl(scratch2, Immediate(kFlatAsciiStringMask)); | |
| 1850 // Interleave the bits to check both scratch1 and scratch2 in one test. | |
| 1851 ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); | |
| 1852 lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); | |
| 1853 cmpl(scratch1, | |
| 1854 Immediate(kFlatAsciiStringTag + (kFlatAsciiStringTag << 3))); | |
| 1855 j(not_equal, on_fail); | |
| 1856 } | |
| 1857 | |
| 1858 | |
| 1859 template <typename LabelType> | |
| 1860 void MacroAssembler::JumpIfInstanceTypeIsNotSequentialAscii( | |
| 1861 Register instance_type, | |
| 1862 Register scratch, | |
| 1863 LabelType *failure) { | |
| 1864 if (!scratch.is(instance_type)) { | |
| 1865 movl(scratch, instance_type); | |
| 1866 } | |
| 1867 | |
| 1868 const int kFlatAsciiStringMask = | |
| 1869 kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; | |
| 1870 | |
| 1871 andl(scratch, Immediate(kFlatAsciiStringMask)); | |
| 1872 cmpl(scratch, Immediate(kStringTag | kSeqStringTag | kAsciiStringTag)); | |
| 1873 j(not_equal, failure); | |
| 1874 } | |
| 1875 | |
| 1876 | |
| 1877 template <typename LabelType> | |
| 1878 void MacroAssembler::JumpIfBothInstanceTypesAreNotSequentialAscii( | |
| 1879 Register first_object_instance_type, | |
| 1880 Register second_object_instance_type, | |
| 1881 Register scratch1, | |
| 1882 Register scratch2, | |
| 1883 LabelType* on_fail) { | |
| 1884 // Load instance type for both strings. | |
| 1885 movq(scratch1, first_object_instance_type); | |
| 1886 movq(scratch2, second_object_instance_type); | |
| 1887 | |
| 1888 // Check that both are flat ascii strings. | |
| 1889 ASSERT(kNotStringTag != 0); | |
| 1890 const int kFlatAsciiStringMask = | |
| 1891 kIsNotStringMask | kStringRepresentationMask | kStringEncodingMask; | |
| 1892 const int kFlatAsciiStringTag = ASCII_STRING_TYPE; | |
| 1893 | |
| 1894 andl(scratch1, Immediate(kFlatAsciiStringMask)); | |
| 1895 andl(scratch2, Immediate(kFlatAsciiStringMask)); | |
| 1896 // Interleave the bits to check both scratch1 and scratch2 in one test. | |
| 1897 ASSERT_EQ(0, kFlatAsciiStringMask & (kFlatAsciiStringMask << 3)); | |
| 1898 lea(scratch1, Operand(scratch1, scratch2, times_8, 0)); | |
| 1899 cmpl(scratch1, | |
| 1900 Immediate(kFlatAsciiStringTag + (kFlatAsciiStringTag << 3))); | |
| 1901 j(not_equal, on_fail); | |
| 1902 } | |
| 1903 | |
| 1904 | |
| 1905 template <typename LabelType> | |
| 1906 void MacroAssembler::InNewSpace(Register object, | |
| 1907 Register scratch, | |
| 1908 Condition cc, | |
| 1909 LabelType* branch) { | |
| 1910 if (Serializer::enabled()) { | |
| 1911 // Can't do arithmetic on external references if it might get serialized. | |
| 1912 // The mask isn't really an address. We load it as an external reference in | |
| 1913 // case the size of the new space is different between the snapshot maker | |
| 1914 // and the running system. | |
| 1915 if (scratch.is(object)) { | |
| 1916 movq(kScratchRegister, ExternalReference::new_space_mask(isolate())); | |
| 1917 and_(scratch, kScratchRegister); | |
| 1918 } else { | |
| 1919 movq(scratch, ExternalReference::new_space_mask(isolate())); | |
| 1920 and_(scratch, object); | |
| 1921 } | |
| 1922 movq(kScratchRegister, ExternalReference::new_space_start(isolate())); | |
| 1923 cmpq(scratch, kScratchRegister); | |
| 1924 j(cc, branch); | |
| 1925 } else { | |
| 1926 ASSERT(is_int32(static_cast<int64_t>(HEAP->NewSpaceMask()))); | |
| 1927 intptr_t new_space_start = | |
| 1928 reinterpret_cast<intptr_t>(HEAP->NewSpaceStart()); | |
| 1929 movq(kScratchRegister, -new_space_start, RelocInfo::NONE); | |
| 1930 if (scratch.is(object)) { | |
| 1931 addq(scratch, kScratchRegister); | |
| 1932 } else { | |
| 1933 lea(scratch, Operand(object, kScratchRegister, times_1, 0)); | |
| 1934 } | |
| 1935 and_(scratch, Immediate(static_cast<int32_t>(HEAP->NewSpaceMask()))); | |
| 1936 j(cc, branch); | |
| 1937 } | |
| 1938 } | |
| 1939 | |
| 1940 | |
| 1941 template <typename LabelType> | |
| 1942 void MacroAssembler::InvokePrologue(const ParameterCount& expected, | |
| 1943 const ParameterCount& actual, | |
| 1944 Handle<Code> code_constant, | |
| 1945 Register code_register, | |
| 1946 LabelType* done, | |
| 1947 InvokeFlag flag, | |
| 1948 const CallWrapper& call_wrapper) { | |
| 1949 bool definitely_matches = false; | |
| 1950 NearLabel invoke; | |
| 1951 if (expected.is_immediate()) { | |
| 1952 ASSERT(actual.is_immediate()); | |
| 1953 if (expected.immediate() == actual.immediate()) { | |
| 1954 definitely_matches = true; | |
| 1955 } else { | |
| 1956 Set(rax, actual.immediate()); | |
| 1957 if (expected.immediate() == | |
| 1958 SharedFunctionInfo::kDontAdaptArgumentsSentinel) { | |
| 1959 // Don't worry about adapting arguments for built-ins that | |
| 1960 // don't want that done. Skip adaption code by making it look | |
| 1961 // like we have a match between expected and actual number of | |
| 1962 // arguments. | |
| 1963 definitely_matches = true; | |
| 1964 } else { | |
| 1965 Set(rbx, expected.immediate()); | |
| 1966 } | |
| 1967 } | |
| 1968 } else { | |
| 1969 if (actual.is_immediate()) { | |
| 1970 // Expected is in register, actual is immediate. This is the | |
| 1971 // case when we invoke function values without going through the | |
| 1972 // IC mechanism. | |
| 1973 cmpq(expected.reg(), Immediate(actual.immediate())); | |
| 1974 j(equal, &invoke); | |
| 1975 ASSERT(expected.reg().is(rbx)); | |
| 1976 Set(rax, actual.immediate()); | |
| 1977 } else if (!expected.reg().is(actual.reg())) { | |
| 1978 // Both expected and actual are in (different) registers. This | |
| 1979 // is the case when we invoke functions using call and apply. | |
| 1980 cmpq(expected.reg(), actual.reg()); | |
| 1981 j(equal, &invoke); | |
| 1982 ASSERT(actual.reg().is(rax)); | |
| 1983 ASSERT(expected.reg().is(rbx)); | |
| 1984 } | |
| 1985 } | |
| 1986 | |
| 1987 if (!definitely_matches) { | |
| 1988 Handle<Code> adaptor = isolate()->builtins()->ArgumentsAdaptorTrampoline(); | |
| 1989 if (!code_constant.is_null()) { | |
| 1990 movq(rdx, code_constant, RelocInfo::EMBEDDED_OBJECT); | |
| 1991 addq(rdx, Immediate(Code::kHeaderSize - kHeapObjectTag)); | |
| 1992 } else if (!code_register.is(rdx)) { | |
| 1993 movq(rdx, code_register); | |
| 1994 } | |
| 1995 | |
| 1996 if (flag == CALL_FUNCTION) { | |
| 1997 call_wrapper.BeforeCall(CallSize(adaptor)); | |
| 1998 Call(adaptor, RelocInfo::CODE_TARGET); | |
| 1999 call_wrapper.AfterCall(); | |
| 2000 jmp(done); | |
| 2001 } else { | |
| 2002 Jump(adaptor, RelocInfo::CODE_TARGET); | |
| 2003 } | |
| 2004 bind(&invoke); | |
| 2005 } | |
| 2006 } | |
| 2007 | |
| 2008 | |
| 2009 } } // namespace v8::internal | 1286 } } // namespace v8::internal |
| 2010 | 1287 |
| 2011 #endif // V8_X64_MACRO_ASSEMBLER_X64_H_ | 1288 #endif // V8_X64_MACRO_ASSEMBLER_X64_H_ |
| OLD | NEW |