| 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 3403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3414 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { | 3414 void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 3415 class DeferredStringCharCodeAt: public LDeferredCode { | 3415 class DeferredStringCharCodeAt: public LDeferredCode { |
| 3416 public: | 3416 public: |
| 3417 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) | 3417 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 3418 : LDeferredCode(codegen), instr_(instr) { } | 3418 : LDeferredCode(codegen), instr_(instr) { } |
| 3419 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } | 3419 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
| 3420 private: | 3420 private: |
| 3421 LStringCharCodeAt* instr_; | 3421 LStringCharCodeAt* instr_; |
| 3422 }; | 3422 }; |
| 3423 | 3423 |
| 3424 Register scratch = scratch0(); | |
| 3425 Register string = ToRegister(instr->string()); | 3424 Register string = ToRegister(instr->string()); |
| 3426 Register index = no_reg; | 3425 Register index = ToRegister(instr->index()); |
| 3427 int const_index = -1; | |
| 3428 if (instr->index()->IsConstantOperand()) { | |
| 3429 const_index = ToInteger32(LConstantOperand::cast(instr->index())); | |
| 3430 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); | |
| 3431 if (!Smi::IsValid(const_index)) { | |
| 3432 // Guaranteed to be out of bounds because of the assert above. | |
| 3433 // So the bounds check that must dominate this instruction must | |
| 3434 // have deoptimized already. | |
| 3435 if (FLAG_debug_code) { | |
| 3436 __ Abort("StringCharCodeAt: out of bounds index."); | |
| 3437 } | |
| 3438 // No code needs to be generated. | |
| 3439 return; | |
| 3440 } | |
| 3441 } else { | |
| 3442 index = ToRegister(instr->index()); | |
| 3443 } | |
| 3444 Register result = ToRegister(instr->result()); | 3426 Register result = ToRegister(instr->result()); |
| 3445 | 3427 |
| 3446 DeferredStringCharCodeAt* deferred = | 3428 DeferredStringCharCodeAt* deferred = |
| 3447 new DeferredStringCharCodeAt(this, instr); | 3429 new DeferredStringCharCodeAt(this, instr); |
| 3448 | 3430 |
| 3449 Label flat_string, ascii_string, done; | |
| 3450 | |
| 3451 // Fetch the instance type of the receiver into result register. | 3431 // Fetch the instance type of the receiver into result register. |
| 3452 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); | 3432 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 3453 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | 3433 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); |
| 3454 | 3434 |
| 3455 // We need special handling for non-flat strings. | 3435 // We need special handling for indirect strings. |
| 3456 STATIC_ASSERT(kSeqStringTag == 0); | 3436 Label check_sequential; |
| 3457 __ tst(result, Operand(kStringRepresentationMask)); | 3437 __ tst(result, Operand(kIsIndirectStringMask)); |
| 3458 __ b(eq, &flat_string); | 3438 __ b(eq, &check_sequential); |
| 3459 | 3439 |
| 3460 // Handle non-flat strings. | 3440 // Dispatch on the indirect string shape: slice or cons. |
| 3461 __ tst(result, Operand(kIsConsStringMask)); | 3441 Label cons_string; |
| 3462 __ b(eq, deferred->entry()); | 3442 const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag; |
| 3443 ASSERT(IsPowerOf2(kSlicedNotConsMask) && kSlicedNotConsMask != 0); |
| 3444 __ tst(result, Operand(kSlicedNotConsMask)); |
| 3445 __ b(eq, &cons_string); |
| 3463 | 3446 |
| 3464 // ConsString. | 3447 // Handle slices. |
| 3448 Label indirect_string_loaded; |
| 3449 __ ldr(result, FieldMemOperand(string, SlicedString::kOffsetOffset)); |
| 3450 __ add(index, index, Operand(result, ASR, kSmiTagSize)); |
| 3451 __ ldr(string, FieldMemOperand(string, SlicedString::kParentOffset)); |
| 3452 __ jmp(&indirect_string_loaded); |
| 3453 |
| 3454 // Handle conses. |
| 3465 // Check whether the right hand side is the empty string (i.e. if | 3455 // Check whether the right hand side is the empty string (i.e. if |
| 3466 // this is really a flat string in a cons string). If that is not | 3456 // this is really a flat string in a cons string). If that is not |
| 3467 // the case we would rather go to the runtime system now to flatten | 3457 // the case we would rather go to the runtime system now to flatten |
| 3468 // the string. | 3458 // the string. |
| 3469 __ ldr(scratch, FieldMemOperand(string, ConsString::kSecondOffset)); | 3459 __ bind(&cons_string); |
| 3460 __ ldr(result, FieldMemOperand(string, ConsString::kSecondOffset)); |
| 3470 __ LoadRoot(ip, Heap::kEmptyStringRootIndex); | 3461 __ LoadRoot(ip, Heap::kEmptyStringRootIndex); |
| 3471 __ cmp(scratch, ip); | 3462 __ cmp(result, ip); |
| 3472 __ b(ne, deferred->entry()); | 3463 __ b(ne, deferred->entry()); |
| 3473 // Get the first of the two strings and load its instance type. | 3464 // Get the first of the two strings and load its instance type. |
| 3474 __ ldr(string, FieldMemOperand(string, ConsString::kFirstOffset)); | 3465 __ ldr(string, FieldMemOperand(string, ConsString::kFirstOffset)); |
| 3466 |
| 3467 __ bind(&indirect_string_loaded); |
| 3475 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); | 3468 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 3476 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | 3469 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); |
| 3477 // If the first cons component is also non-flat, then go to runtime. | 3470 |
| 3471 // Check whether the string is sequential. The only non-sequential |
| 3472 // shapes we support have just been unwrapped above. |
| 3473 __ bind(&check_sequential); |
| 3478 STATIC_ASSERT(kSeqStringTag == 0); | 3474 STATIC_ASSERT(kSeqStringTag == 0); |
| 3479 __ tst(result, Operand(kStringRepresentationMask)); | 3475 __ tst(result, Operand(kStringRepresentationMask)); |
| 3480 __ b(ne, deferred->entry()); | 3476 __ b(ne, deferred->entry()); |
| 3481 | 3477 |
| 3482 // Check for 1-byte or 2-byte string. | 3478 // Dispatch on the encoding: ASCII or two-byte. |
| 3483 __ bind(&flat_string); | 3479 Label ascii_string; |
| 3484 STATIC_ASSERT(kAsciiStringTag != 0); | 3480 STATIC_ASSERT(kAsciiStringTag != 0); |
| 3485 __ tst(result, Operand(kStringEncodingMask)); | 3481 __ tst(result, Operand(kStringEncodingMask)); |
| 3486 __ b(ne, &ascii_string); | 3482 __ b(ne, &ascii_string); |
| 3487 | 3483 |
| 3488 // 2-byte string. | 3484 // Two-byte string. |
| 3489 // Load the 2-byte character code into the result register. | 3485 // Load the two-byte character code into the result register. |
| 3490 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); | 3486 Label done; |
| 3491 if (instr->index()->IsConstantOperand()) { | 3487 __ add(result, |
| 3492 __ ldrh(result, | 3488 string, |
| 3493 FieldMemOperand(string, | 3489 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3494 SeqTwoByteString::kHeaderSize + 2 * const_index)); | 3490 __ ldrh(result, MemOperand(result, index, LSL, 1)); |
| 3495 } else { | |
| 3496 __ add(scratch, | |
| 3497 string, | |
| 3498 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); | |
| 3499 __ ldrh(result, MemOperand(scratch, index, LSL, 1)); | |
| 3500 } | |
| 3501 __ jmp(&done); | 3491 __ jmp(&done); |
| 3502 | 3492 |
| 3503 // ASCII string. | 3493 // ASCII string. |
| 3504 // Load the byte into the result register. | 3494 // Load the byte into the result register. |
| 3505 __ bind(&ascii_string); | 3495 __ bind(&ascii_string); |
| 3506 if (instr->index()->IsConstantOperand()) { | 3496 __ add(result, |
| 3507 __ ldrb(result, FieldMemOperand(string, | 3497 string, |
| 3508 SeqAsciiString::kHeaderSize + const_index)); | 3498 Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 3509 } else { | 3499 __ ldrb(result, MemOperand(result, index)); |
| 3510 __ add(scratch, | 3500 |
| 3511 string, | |
| 3512 Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); | |
| 3513 __ ldrb(result, MemOperand(scratch, index)); | |
| 3514 } | |
| 3515 __ bind(&done); | 3501 __ bind(&done); |
| 3516 __ bind(deferred->exit()); | 3502 __ bind(deferred->exit()); |
| 3517 } | 3503 } |
| 3518 | 3504 |
| 3519 | 3505 |
| 3520 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { | 3506 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 3521 Register string = ToRegister(instr->string()); | 3507 Register string = ToRegister(instr->string()); |
| 3522 Register result = ToRegister(instr->result()); | 3508 Register result = ToRegister(instr->result()); |
| 3523 Register scratch = scratch0(); | 3509 Register scratch = scratch0(); |
| 3524 | 3510 |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4485 ASSERT(osr_pc_offset_ == -1); | 4471 ASSERT(osr_pc_offset_ == -1); |
| 4486 osr_pc_offset_ = masm()->pc_offset(); | 4472 osr_pc_offset_ = masm()->pc_offset(); |
| 4487 } | 4473 } |
| 4488 | 4474 |
| 4489 | 4475 |
| 4490 | 4476 |
| 4491 | 4477 |
| 4492 #undef __ | 4478 #undef __ |
| 4493 | 4479 |
| 4494 } } // namespace v8::internal | 4480 } } // namespace v8::internal |
| OLD | NEW |