| 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 3387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3398 class DeferredStringCharCodeAt: public LDeferredCode { | 3398 class DeferredStringCharCodeAt: public LDeferredCode { |
| 3399 public: | 3399 public: |
| 3400 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) | 3400 DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 3401 : LDeferredCode(codegen), instr_(instr) { } | 3401 : LDeferredCode(codegen), instr_(instr) { } |
| 3402 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } | 3402 virtual void Generate() { codegen()->DoDeferredStringCharCodeAt(instr_); } |
| 3403 virtual LInstruction* instr() { return instr_; } | 3403 virtual LInstruction* instr() { return instr_; } |
| 3404 private: | 3404 private: |
| 3405 LStringCharCodeAt* instr_; | 3405 LStringCharCodeAt* instr_; |
| 3406 }; | 3406 }; |
| 3407 | 3407 |
| 3408 Register string = ToRegister(instr->string()); | |
| 3409 Register index = ToRegister(instr->index()); | |
| 3410 Register result = ToRegister(instr->result()); | |
| 3411 | |
| 3412 DeferredStringCharCodeAt* deferred = | 3408 DeferredStringCharCodeAt* deferred = |
| 3413 new DeferredStringCharCodeAt(this, instr); | 3409 new DeferredStringCharCodeAt(this, instr); |
| 3414 | 3410 |
| 3415 // Fetch the instance type of the receiver into result register. | 3411 StringCharCodeAtGenerator::GenerateCharLoad(masm(), |
| 3416 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); | 3412 factory(), |
| 3417 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); | 3413 ToRegister(instr->string()), |
| 3418 | 3414 ToRegister(instr->index()), |
| 3419 // We need special handling for indirect strings. | 3415 ToRegister(instr->result()), |
| 3420 Label check_sequential; | 3416 deferred->entry()); |
| 3421 __ test(result, Immediate(kIsIndirectStringMask)); | |
| 3422 __ j(zero, &check_sequential, Label::kNear); | |
| 3423 | |
| 3424 // Dispatch on the indirect string shape: slice or cons. | |
| 3425 Label cons_string; | |
| 3426 __ test(result, Immediate(kSlicedNotConsMask)); | |
| 3427 __ j(zero, &cons_string, Label::kNear); | |
| 3428 | |
| 3429 // Handle slices. | |
| 3430 Label indirect_string_loaded; | |
| 3431 __ mov(result, FieldOperand(string, SlicedString::kOffsetOffset)); | |
| 3432 __ SmiUntag(result); | |
| 3433 __ add(index, Operand(result)); | |
| 3434 __ mov(string, FieldOperand(string, SlicedString::kParentOffset)); | |
| 3435 __ jmp(&indirect_string_loaded, Label::kNear); | |
| 3436 | |
| 3437 // Handle conses. | |
| 3438 // Check whether the right hand side is the empty string (i.e. if | |
| 3439 // this is really a flat string in a cons string). If that is not | |
| 3440 // the case we would rather go to the runtime system now to flatten | |
| 3441 // the string. | |
| 3442 __ bind(&cons_string); | |
| 3443 __ cmp(FieldOperand(string, ConsString::kSecondOffset), | |
| 3444 Immediate(factory()->empty_string())); | |
| 3445 __ j(not_equal, deferred->entry()); | |
| 3446 __ mov(string, FieldOperand(string, ConsString::kFirstOffset)); | |
| 3447 | |
| 3448 __ bind(&indirect_string_loaded); | |
| 3449 __ mov(result, FieldOperand(string, HeapObject::kMapOffset)); | |
| 3450 __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset)); | |
| 3451 | |
| 3452 // Check whether the string is sequential. The only non-sequential | |
| 3453 // shapes we support have just been unwrapped above. | |
| 3454 // Note that if the original string is a cons or slice with an external | |
| 3455 // string as underlying string, we pass that unpacked underlying string with | |
| 3456 // the adjusted index to the runtime function. | |
| 3457 __ bind(&check_sequential); | |
| 3458 STATIC_ASSERT(kSeqStringTag == 0); | |
| 3459 __ test(result, Immediate(kStringRepresentationMask)); | |
| 3460 __ j(not_zero, deferred->entry()); | |
| 3461 | |
| 3462 // Dispatch on the encoding: ASCII or two-byte. | |
| 3463 Label ascii_string; | |
| 3464 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); | |
| 3465 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); | |
| 3466 __ test(result, Immediate(kStringEncodingMask)); | |
| 3467 __ j(not_zero, &ascii_string, Label::kNear); | |
| 3468 | |
| 3469 // Two-byte string. | |
| 3470 // Load the two-byte character code into the result register. | |
| 3471 Label done; | |
| 3472 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); | |
| 3473 __ movzx_w(result, FieldOperand(string, | |
| 3474 index, | |
| 3475 times_2, | |
| 3476 SeqTwoByteString::kHeaderSize)); | |
| 3477 __ jmp(&done, Label::kNear); | |
| 3478 | |
| 3479 // ASCII string. | |
| 3480 // Load the byte into the result register. | |
| 3481 __ bind(&ascii_string); | |
| 3482 __ movzx_b(result, FieldOperand(string, | |
| 3483 index, | |
| 3484 times_1, | |
| 3485 SeqAsciiString::kHeaderSize)); | |
| 3486 __ bind(&done); | |
| 3487 __ bind(deferred->exit()); | 3417 __ bind(deferred->exit()); |
| 3488 } | 3418 } |
| 3489 | 3419 |
| 3490 | 3420 |
| 3491 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { | 3421 void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 3492 Register string = ToRegister(instr->string()); | 3422 Register string = ToRegister(instr->string()); |
| 3493 Register result = ToRegister(instr->result()); | 3423 Register result = ToRegister(instr->result()); |
| 3494 | 3424 |
| 3495 // TODO(3095996): Get rid of this. For now, we need to make the | 3425 // TODO(3095996): Get rid of this. For now, we need to make the |
| 3496 // result register contain a valid pointer because it is already | 3426 // result register contain a valid pointer because it is already |
| (...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4586 env->deoptimization_index()); | 4516 env->deoptimization_index()); |
| 4587 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); | 4517 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION, safepoint_generator); |
| 4588 } | 4518 } |
| 4589 | 4519 |
| 4590 | 4520 |
| 4591 #undef __ | 4521 #undef __ |
| 4592 | 4522 |
| 4593 } } // namespace v8::internal | 4523 } } // namespace v8::internal |
| 4594 | 4524 |
| 4595 #endif // V8_TARGET_ARCH_IA32 | 4525 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |