| 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 3491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3502 class DeferredStringCharCodeAt: public LDeferredCode { | 3502 class DeferredStringCharCodeAt: public LDeferredCode { |
| 3503 public: | 3503 public: |
| 3504 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) | 3504 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 3505 : LDeferredCode(codegen), instr_(instr) { } | 3505 : LDeferredCode(codegen), instr_(instr) { } |
| 3506 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } | 3506 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
| 3507 virtual LInstruction* instr() { return instr_; } | 3507 virtual LInstruction* instr() { return instr_; } |
| 3508 private: | 3508 private: |
| 3509 LStringCharCodeAt* instr_; | 3509 LStringCharCodeAt* instr_; |
| 3510 }; | 3510 }; |
| 3511 | 3511 |
| 3512 Register temp = scratch1(); | |
| 3513 Register string = ToRegister(instr->string()); | |
| 3514 Register index = ToRegister(instr->index()); | |
| 3515 Register result = ToRegister(instr->result()); | |
| 3516 DeferredStringCharCodeAt* deferred = | 3512 DeferredStringCharCodeAt* deferred = |
| 3517 new DeferredStringCharCodeAt(this, instr); | 3513 new DeferredStringCharCodeAt(this, instr); |
| 3518 | 3514 StringCharLoadGenerator::Generate(masm(), |
| 3519 // Fetch the instance type of the receiver into result register. | 3515 ToRegister(instr->string()), |
| 3520 __ lw(result, FieldMemOperand(string, HeapObject::kMapOffset)); | 3516 ToRegister(instr->index()), |
| 3521 __ lbu(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | 3517 ToRegister(instr->result()), |
| 3522 | 3518 deferred->entry()); |
| 3523 // We need special handling for indirect strings. | |
| 3524 Label check_sequential; | |
| 3525 __ And(temp, result, kIsIndirectStringMask); | |
| 3526 __ Branch(&check_sequential, eq, temp, Operand(zero_reg)); | |
| 3527 | |
| 3528 // Dispatch on the indirect string shape: slice or cons. | |
| 3529 Label cons_string; | |
| 3530 __ And(temp, result, kSlicedNotConsMask); | |
| 3531 __ Branch(&cons_string, eq, temp, Operand(zero_reg)); | |
| 3532 | |
| 3533 // Handle slices. | |
| 3534 Label indirect_string_loaded; | |
| 3535 __ lw(result, FieldMemOperand(string, SlicedString::kOffsetOffset)); | |
| 3536 __ sra(temp, result, kSmiTagSize); | |
| 3537 __ addu(index, index, temp); | |
| 3538 __ lw(string, FieldMemOperand(string, SlicedString::kParentOffset)); | |
| 3539 __ jmp(&indirect_string_loaded); | |
| 3540 | |
| 3541 // Handle conses. | |
| 3542 // Check whether the right hand side is the empty string (i.e. if | |
| 3543 // this is really a flat string in a cons string). If that is not | |
| 3544 // the case we would rather go to the runtime system now to flatten | |
| 3545 // the string. | |
| 3546 __ bind(&cons_string); | |
| 3547 __ lw(result, FieldMemOperand(string, ConsString::kSecondOffset)); | |
| 3548 __ LoadRoot(temp, Heap::kEmptyStringRootIndex); | |
| 3549 __ Branch(deferred->entry(), ne, result, Operand(temp)); | |
| 3550 // Get the first of the two strings and load its instance type. | |
| 3551 __ lw(string, FieldMemOperand(string, ConsString::kFirstOffset)); | |
| 3552 | |
| 3553 __ bind(&indirect_string_loaded); | |
| 3554 __ lw(result, FieldMemOperand(string, HeapObject::kMapOffset)); | |
| 3555 __ lbu(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | |
| 3556 | |
| 3557 // Check whether the string is sequential. The only non-sequential | |
| 3558 // shapes we support have just been unwrapped above. | |
| 3559 // Note that if the original string is a cons or slice with an external | |
| 3560 // string as underlying string, we pass that unpacked underlying string with | |
| 3561 // the adjusted index to the runtime function. | |
| 3562 __ bind(&check_sequential); | |
| 3563 STATIC_ASSERT(kSeqStringTag == 0); | |
| 3564 __ And(temp, result, Operand(kStringRepresentationMask)); | |
| 3565 __ Branch(deferred->entry(), ne, temp, Operand(zero_reg)); | |
| 3566 | |
| 3567 // Dispatch on the encoding: ASCII or two-byte. | |
| 3568 Label ascii_string; | |
| 3569 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); | |
| 3570 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); | |
| 3571 __ And(temp, result, Operand(kStringEncodingMask)); | |
| 3572 __ Branch(&ascii_string, ne, temp, Operand(zero_reg)); | |
| 3573 | |
| 3574 // Two-byte string. | |
| 3575 // Load the two-byte character code into the result register. | |
| 3576 Label done; | |
| 3577 __ Addu(result, | |
| 3578 string, | |
| 3579 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); | |
| 3580 __ sll(temp, index, 1); | |
| 3581 __ Addu(result, result, temp); | |
| 3582 __ lhu(result, MemOperand(result, 0)); | |
| 3583 __ Branch(&done); | |
| 3584 | |
| 3585 // ASCII string. | |
| 3586 // Load the byte into the result register. | |
| 3587 __ bind(&ascii_string); | |
| 3588 __ Addu(result, | |
| 3589 string, | |
| 3590 Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); | |
| 3591 __ Addu(result, result, index); | |
| 3592 __ lbu(result, MemOperand(result, 0)); | |
| 3593 | |
| 3594 __ bind(&done); | |
| 3595 __ bind(deferred->exit()); | 3519 __ bind(deferred->exit()); |
| 3596 } | 3520 } |
| 3597 | 3521 |
| 3598 | 3522 |
| 3599 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { | 3523 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 3600 Register string = ToRegister(instr->string()); | 3524 Register string = ToRegister(instr->string()); |
| 3601 Register result = ToRegister(instr->result()); | 3525 Register result = ToRegister(instr->result()); |
| 3602 Register scratch = scratch0(); | 3526 Register scratch = scratch0(); |
| 3603 | 3527 |
| 3604 // TODO(3095996): Get rid of this. For now, we need to make the | 3528 // TODO(3095996): Get rid of this. For now, we need to make the |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4631 ASSERT(!environment->HasBeenRegistered()); | 4555 ASSERT(!environment->HasBeenRegistered()); |
| 4632 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 4556 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
| 4633 ASSERT(osr_pc_offset_ == -1); | 4557 ASSERT(osr_pc_offset_ == -1); |
| 4634 osr_pc_offset_ = masm()->pc_offset(); | 4558 osr_pc_offset_ = masm()->pc_offset(); |
| 4635 } | 4559 } |
| 4636 | 4560 |
| 4637 | 4561 |
| 4638 #undef __ | 4562 #undef __ |
| 4639 | 4563 |
| 4640 } } // namespace v8::internal | 4564 } } // namespace v8::internal |
| OLD | NEW |