Chromium Code Reviews| 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 3406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); | 3424 Register scratch = scratch0(); |
| 3425 Register string = ToRegister(instr->string()); | 3425 Register string = ToRegister(instr->string()); |
| 3426 Register index = no_reg; | 3426 Register index = no_reg; |
| 3427 int const_index = -1; | 3427 int const_index = 0; |
| 3428 if (instr->index()->IsConstantOperand()) { | 3428 if (instr->index()->IsConstantOperand()) { |
| 3429 const_index = ToInteger32(LConstantOperand::cast(instr->index())); | 3429 const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 3430 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); | 3430 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); |
| 3431 if (!Smi::IsValid(const_index)) { | 3431 if (!Smi::IsValid(const_index)) { |
| 3432 // Guaranteed to be out of bounds because of the assert above. | 3432 // Guaranteed to be out of bounds because of the assert above. |
| 3433 // So the bounds check that must dominate this instruction must | 3433 // So the bounds check that must dominate this instruction must |
| 3434 // have deoptimized already. | 3434 // have deoptimized already. |
| 3435 if (FLAG_debug_code) { | 3435 if (FLAG_debug_code) { |
| 3436 __ Abort("StringCharCodeAt: out of bounds index."); | 3436 __ Abort("StringCharCodeAt: out of bounds index."); |
| 3437 } | 3437 } |
| 3438 // No code needs to be generated. | 3438 // No code needs to be generated. |
| 3439 return; | 3439 return; |
| 3440 } | 3440 } |
| 3441 } else { | 3441 } else { |
| 3442 index = ToRegister(instr->index()); | 3442 index = ToRegister(instr->index()); |
| 3443 } | 3443 } |
| 3444 Register result = ToRegister(instr->result()); | 3444 Register result = ToRegister(instr->result()); |
| 3445 | 3445 |
| 3446 DeferredStringCharCodeAt* deferred = | 3446 DeferredStringCharCodeAt* deferred = |
| 3447 new DeferredStringCharCodeAt(this, instr); | 3447 new DeferredStringCharCodeAt(this, instr); |
| 3448 | 3448 |
| 3449 Label flat_string, ascii_string, done; | 3449 Label flat_string, ascii_string, cons_string, sliced_ascii_string, done; |
| 3450 | 3450 |
| 3451 // Fetch the instance type of the receiver into result register. | 3451 // Fetch the instance type of the receiver into result register. |
| 3452 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); | 3452 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 3453 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | 3453 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); |
| 3454 | 3454 |
| 3455 // We need special handling for non-flat strings. | 3455 // We need special handling for non-flat strings. |
| 3456 STATIC_ASSERT(kSeqStringTag == 0); | 3456 STATIC_ASSERT(kSeqStringTag == 0); |
| 3457 __ tst(result, Operand(kStringRepresentationMask)); | 3457 __ tst(result, Operand(kStringRepresentationMask)); |
| 3458 __ b(eq, &flat_string); | 3458 __ b(eq, &flat_string); |
| 3459 | 3459 |
| 3460 // Handle non-flat strings. | 3460 // Handle non-flat strings. |
| 3461 __ tst(result, Operand(kIsConsStringMask)); | 3461 __ and_(result, result, Operand(kStringRepresentationMask)); |
| 3462 __ cmp(result, Operand(kConsStringTag)); | |
| 3463 __ b(eq, &cons_string); | |
| 3464 __ cmp(result, Operand(kExternalStringTag)); | |
| 3462 __ b(eq, deferred->entry()); | 3465 __ b(eq, deferred->entry()); |
| 3463 | 3466 |
| 3467 // SlicedString. | |
| 3468 // Unpack slice, add offset and retrieve the result char. | |
| 3469 __ ldr(scratch, FieldMemOperand(string, SlicedString::kOffsetOffset)); | |
| 3470 __ ldr(string, FieldMemOperand(string, SlicedString::kParentOffset)); | |
| 3471 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); | |
| 3472 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | |
| 3473 // Check for 1-byte or 2-byte string. | |
| 3474 STATIC_ASSERT(kAsciiStringTag != 0); | |
| 3475 __ tst(result, Operand(kStringEncodingMask)); | |
| 3476 __ b(ne, &sliced_ascii_string); | |
| 3477 if (!instr->index()->IsConstantOperand()) { | |
| 3478 // Double the index before adding to the smi-tagged offset. | |
| 3479 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); | |
| 3480 __ add(scratch, scratch, Operand(index, LSL, 1)); | |
| 3481 } | |
| 3482 __ add(result, | |
| 3483 string, | |
| 3484 Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag | |
|
antonm
2011/08/04 12:18:48
nit: apparently v8 style is not to start continuat
| |
| 3485 + 2 * const_index)); | |
| 3486 __ ldrh(result, MemOperand(result, scratch)); | |
| 3487 __ jmp(&done); | |
| 3488 __ bind(&sliced_ascii_string); | |
| 3489 if (!instr->index()->IsConstantOperand()) { | |
| 3490 // Smi-untag the offset before adding to the index. | |
| 3491 __ add(scratch, index, Operand(scratch, LSR, kSmiTagSize)); | |
| 3492 } else { | |
| 3493 __ SmiUntag(scratch, scratch); | |
| 3494 } | |
| 3495 __ add(result, | |
| 3496 string, | |
| 3497 Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag + const_index)); | |
| 3498 __ ldrb(result, MemOperand(result, scratch)); | |
| 3499 __ jmp(&done); | |
| 3500 | |
| 3464 // ConsString. | 3501 // ConsString. |
| 3465 // Check whether the right hand side is the empty string (i.e. if | 3502 // 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 | 3503 // 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 | 3504 // the case we would rather go to the runtime system now to flatten |
| 3468 // the string. | 3505 // the string. |
| 3506 __ bind(&cons_string); | |
| 3469 __ ldr(scratch, FieldMemOperand(string, ConsString::kSecondOffset)); | 3507 __ ldr(scratch, FieldMemOperand(string, ConsString::kSecondOffset)); |
| 3470 __ LoadRoot(ip, Heap::kEmptyStringRootIndex); | 3508 __ LoadRoot(ip, Heap::kEmptyStringRootIndex); |
| 3471 __ cmp(scratch, ip); | 3509 __ cmp(scratch, ip); |
| 3472 __ b(ne, deferred->entry()); | 3510 __ b(ne, deferred->entry()); |
| 3473 // Get the first of the two strings and load its instance type. | 3511 // Get the first of the two strings and load its instance type. |
| 3474 __ ldr(string, FieldMemOperand(string, ConsString::kFirstOffset)); | 3512 __ ldr(string, FieldMemOperand(string, ConsString::kFirstOffset)); |
| 3475 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); | 3513 __ ldr(result, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 3476 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); | 3514 __ ldrb(result, FieldMemOperand(result, Map::kInstanceTypeOffset)); |
| 3477 // If the first cons component is also non-flat, then go to runtime. | 3515 // If the first cons component is also non-flat, then go to runtime. |
| 3478 STATIC_ASSERT(kSeqStringTag == 0); | 3516 STATIC_ASSERT(kSeqStringTag == 0); |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4485 ASSERT(osr_pc_offset_ == -1); | 4523 ASSERT(osr_pc_offset_ == -1); |
| 4486 osr_pc_offset_ = masm()->pc_offset(); | 4524 osr_pc_offset_ = masm()->pc_offset(); |
| 4487 } | 4525 } |
| 4488 | 4526 |
| 4489 | 4527 |
| 4490 | 4528 |
| 4491 | 4529 |
| 4492 #undef __ | 4530 #undef __ |
| 4493 | 4531 |
| 4494 } } // namespace v8::internal | 4532 } } // namespace v8::internal |
| OLD | NEW |