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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 JSObject::kElementsOffset, | 360 JSObject::kElementsOffset, |
| 361 r11, | 361 r11, |
| 362 r15, | 362 r15, |
| 363 kDontSaveFPRegs, | 363 kDontSaveFPRegs, |
| 364 EMIT_REMEMBERED_SET, | 364 EMIT_REMEMBERED_SET, |
| 365 OMIT_SMI_CHECK); | 365 OMIT_SMI_CHECK); |
| 366 __ pop(rax); | 366 __ pop(rax); |
| 367 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 367 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 | |
| 371 void StringCharLoadGenerator::Generate(MacroAssembler* masm, | |
| 372 Register string, | |
| 373 Register index, | |
| 374 Register result, | |
| 375 Label* call_runtime) { | |
| 376 // Fetch the instance type of the receiver into result register. | |
| 377 __ movq(result, FieldOperand(string, HeapObject::kMapOffset)); | |
| 378 __ movzxbl(result, FieldOperand(result, Map::kInstanceTypeOffset)); | |
| 379 | |
| 380 // We need special handling for indirect strings. | |
| 381 Label check_sequential; | |
| 382 __ testb(result, Immediate(kIsIndirectStringMask)); | |
| 383 __ j(zero, &check_sequential); | |
| 384 | |
| 385 // Dispatch on the indirect string shape: slice or cons. | |
| 386 Label cons_string; | |
| 387 __ testb(result, Immediate(kSlicedNotConsMask)); | |
| 388 __ j(zero, &cons_string, Label::kNear); | |
| 389 | |
| 390 // Handle slices. | |
| 391 Label indirect_string_loaded; | |
| 392 __ SmiToInteger32(result, FieldOperand(string, SlicedString::kOffsetOffset)); | |
| 393 __ addq(index, result); | |
| 394 __ movq(string, FieldOperand(string, SlicedString::kParentOffset)); | |
| 395 __ jmp(&indirect_string_loaded, Label::kNear); | |
| 396 | |
| 397 // Handle external strings. | |
|
Yang
2011/11/23 14:04:07
The interesting part starts here.
| |
| 398 Label external_string, ascii_external, done; | |
| 399 __ bind(&external_string); | |
| 400 if (FLAG_debug_code) { | |
| 401 // Assert that we do not have a cons or slice (indirect strings) here. | |
| 402 // Sequential strings have already been ruled out. | |
| 403 __ testb(result, Immediate(kIsIndirectStringMask)); | |
| 404 __ Assert(zero, "external string expected, but not found"); | |
| 405 } | |
| 406 // Rule out short external strings. | |
| 407 STATIC_CHECK(kShortExternalStringTag != 0); | |
| 408 __ testb(result, Immediate(kShortExternalStringTag)); | |
|
Lasse Reichstein
2011/11/24 09:52:55
kShortExternalStringMask
| |
| 409 __ j(not_zero, call_runtime); | |
| 410 // Check encoding. | |
| 411 STATIC_ASSERT(kTwoByteStringTag == 0); | |
| 412 __ testb(result, Immediate(kStringEncodingMask)); | |
| 413 __ movq(result, FieldOperand(string, ExternalString::kResourceDataOffset)); | |
| 414 __ j(not_equal, &ascii_external, Label::kNear); | |
| 415 // Two-byte string. | |
| 416 __ movzxwl(result, Operand(result, index, times_2, 0)); | |
| 417 __ jmp(&done); | |
| 418 __ bind(&ascii_external); | |
| 419 // Ascii string. | |
| 420 __ movzxbl(result, Operand(result, index, times_1, 0)); | |
| 421 __ jmp(&done); | |
| 422 | |
| 423 // Handle conses. | |
| 424 // Check whether the right hand side is the empty string (i.e. if | |
| 425 // this is really a flat string in a cons string). If that is not | |
| 426 // the case we would rather go to the runtime system now to flatten | |
| 427 // the string. | |
| 428 __ bind(&cons_string); | |
| 429 __ CompareRoot(FieldOperand(string, ConsString::kSecondOffset), | |
| 430 Heap::kEmptyStringRootIndex); | |
| 431 __ j(not_equal, call_runtime); | |
| 432 __ movq(string, FieldOperand(string, ConsString::kFirstOffset)); | |
| 433 | |
| 434 __ bind(&indirect_string_loaded); | |
| 435 __ movq(result, FieldOperand(string, HeapObject::kMapOffset)); | |
| 436 __ movzxbl(result, FieldOperand(result, Map::kInstanceTypeOffset)); | |
| 437 | |
| 438 // Check whether the string is sequential. The only non-sequential | |
|
Lasse Reichstein
2011/11/24 09:52:55
Slightly confusing comment. How about something li
| |
| 439 // shapes we support have just been unwrapped above. | |
| 440 // Note that if the original string is a cons or slice with an external | |
| 441 // string as underlying string, we pass that unpacked underlying string with | |
| 442 // the adjusted index to the runtime function. | |
| 443 __ bind(&check_sequential); | |
| 444 STATIC_ASSERT(kSeqStringTag == 0); | |
| 445 __ testb(result, Immediate(kStringRepresentationMask)); | |
| 446 __ j(not_zero, &external_string); | |
| 447 | |
| 448 // Dispatch on the encoding: ASCII or two-byte. | |
| 449 Label ascii_string; | |
| 450 STATIC_ASSERT((kStringEncodingMask & kAsciiStringTag) != 0); | |
| 451 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); | |
| 452 __ testb(result, Immediate(kStringEncodingMask)); | |
| 453 __ j(not_zero, &ascii_string, Label::kNear); | |
| 454 | |
| 455 // Two-byte string. | |
| 456 // Load the two-byte character code into the result register. | |
| 457 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); | |
| 458 __ movzxwl(result, FieldOperand(string, | |
| 459 index, | |
| 460 times_2, | |
| 461 SeqTwoByteString::kHeaderSize)); | |
| 462 __ jmp(&done, Label::kNear); | |
| 463 | |
| 464 // ASCII string. | |
| 465 // Load the byte into the result register. | |
| 466 __ bind(&ascii_string); | |
| 467 __ movzxbl(result, FieldOperand(string, | |
| 468 index, | |
| 469 times_1, | |
| 470 SeqAsciiString::kHeaderSize)); | |
| 471 __ bind(&done); | |
| 472 } | |
| 473 | |
| 370 #undef __ | 474 #undef __ |
| 371 | 475 |
| 372 } } // namespace v8::internal | 476 } } // namespace v8::internal |
| 373 | 477 |
| 374 #endif // V8_TARGET_ARCH_X64 | 478 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |