Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Unified Diff: src/ia32/lithium-codegen-ia32.cc

Issue 7477045: Tentative implementation of string slices (hidden under the flag --string-slices). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Implemented some changes suggested by Anton. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/ia32/lithium-codegen-ia32.cc
diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc
index e2a18eb2fc96d8d0ec43548a0f3b6547cd4e4777..cb99f170c958f5128d77b8fc7cc7890d085ccb86 100644
--- a/src/ia32/lithium-codegen-ia32.cc
+++ b/src/ia32/lithium-codegen-ia32.cc
@@ -3139,6 +3139,7 @@ void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
Register string = ToRegister(instr->string());
Register index = no_reg;
+ Register offset = ToRegister(instr->TempAt(0));
int const_index = -1;
if (instr->index()->IsConstantOperand()) {
const_index = ToInteger32(LConstantOperand::cast(instr->index()));
@@ -3161,7 +3162,7 @@ void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
DeferredStringCharCodeAt* deferred =
new DeferredStringCharCodeAt(this, instr);
- Label flat_string, ascii_string, done;
+ Label flat_string, ascii_string, cons_string, sliced_ascii_string, done;
// Fetch the instance type of the receiver into result register.
__ mov(result, FieldOperand(string, HeapObject::kMapOffset));
@@ -3173,14 +3174,46 @@ void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) {
__ j(zero, &flat_string, Label::kNear);
// Handle non-flat strings.
- __ test(result, Immediate(kIsConsStringMask));
- __ j(zero, deferred->entry());
+ __ and_(result, kStringRepresentationMask);
Vitaly Repeshko 2011/08/05 12:14:14 Too much code now. Either put it behind the flag o
+ __ cmp(result, kConsStringTag);
+ __ j(equal, &cons_string, Label::kNear);
+ __ cmp(result, kExternalStringTag);
+ __ j(equal, deferred->entry());
+
+ // SlicedString.
+ // Unpack slice, add offset and retrieve the result char.
+ __ mov(offset, FieldOperand(string, SlicedString::kOffsetOffset));
+ __ SmiUntag(offset);
+ if (instr->index()->IsConstantOperand()) {
+ __ add(Operand(offset), Immediate(const_index));
+ } else {
+ __ add(offset, Operand(index));
+ }
+ __ mov(string, FieldOperand(string, SlicedString::kParentOffset));
+ __ mov(result, FieldOperand(string, HeapObject::kMapOffset));
+ __ movzx_b(result, FieldOperand(result, Map::kInstanceTypeOffset));
+ // Check for ASCII or two-byte string.
+ STATIC_ASSERT(kAsciiStringTag != 0);
+ __ test(result, Immediate(kStringEncodingMask));
+ __ j(not_zero, &sliced_ascii_string, Label::kNear);
+ __ movzx_w(result, FieldOperand(string,
+ offset,
+ times_2,
+ SeqTwoByteString::kHeaderSize));
+ __ jmp(&done, Label::kNear);
+ __ bind(&sliced_ascii_string);
+ __ movzx_b(result, FieldOperand(string,
+ offset,
+ times_1,
+ SeqAsciiString::kHeaderSize));
+ __ jmp(&done, Label::kNear);
// ConsString.
// Check whether the right hand side is the empty string (i.e. if
// this is really a flat string in a cons string). If that is not
// the case we would rather go to the runtime system now to flatten
// the string.
+ __ bind(&cons_string);
__ cmp(FieldOperand(string, ConsString::kSecondOffset),
Immediate(factory()->empty_string()));
__ j(not_equal, deferred->entry());

Powered by Google App Engine
This is Rietveld 408576698