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