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

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

Issue 6902112: Avoid using a register for constant external array indices. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 8 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 07ee7d62dcac1ff852626c3dcc745477de1db9ce..9c245f06aa4ea13a6d000d53d95ce3d78ce3ef5a 100644
--- a/src/ia32/lithium-codegen-ia32.cc
+++ b/src/ia32/lithium-codegen-ia32.cc
@@ -2381,39 +2381,84 @@ void LCodeGen::DoLoadKeyedFastElement(LLoadKeyedFastElement* instr) {
}
+Operand LCodeGen::BuildExternalArrayOperand(LOperand* external_pointer,
+ LOperand* key,
+ ExternalArrayType array_type) {
+ Register external_pointer_reg = ToRegister(external_pointer);
+ ScaleFactor scale_factor = times_1;
+ int element_size = 1;
+ switch (array_type) {
+ case kExternalByteArray:
+ case kExternalUnsignedByteArray:
+ case kExternalPixelArray:
+ scale_factor = times_1;
+ element_size = 1;
+ break;
+ case kExternalShortArray:
+ case kExternalUnsignedShortArray:
+ scale_factor = times_2;
+ element_size = 2;
+ break;
+ case kExternalIntArray:
+ case kExternalUnsignedIntArray:
+ case kExternalFloatArray:
+ scale_factor = times_4;
+ element_size = 4;
+ break;
+ case kExternalDoubleArray:
+ scale_factor = times_8;
+ element_size = 8;
+ break;
+ }
+ int constant_value = 0;
+ Register key_reg;
+ bool key_is_constant = key->IsConstantOperand();
+ if (key_is_constant) {
+ constant_value = ToInteger32(LConstantOperand::cast(key));
+ if (constant_value & 0xF0000000) {
+ Abort("array index constant value too big");
+ }
+ } else {
+ key_reg = ToRegister(key);
+ }
+ if (key_is_constant)
fschneider 2011/04/29 09:13:47 Same comment as for x64 here - { } needed.
Jakob Kummerow 2011/04/29 10:04:16 Done.
+ return Operand(external_pointer_reg, constant_value * element_size);
+ return Operand(external_pointer_reg, key_reg, scale_factor, 0);
+}
+
+
void LCodeGen::DoLoadKeyedSpecializedArrayElement(
LLoadKeyedSpecializedArrayElement* instr) {
- Register external_pointer = ToRegister(instr->external_pointer());
- Register key = ToRegister(instr->key());
ExternalArrayType array_type = instr->array_type();
+ Operand operand(BuildExternalArrayOperand(instr->external_pointer(),
+ instr->key(), array_type));
if (array_type == kExternalFloatArray) {
XMMRegister result(ToDoubleRegister(instr->result()));
- __ movss(result, Operand(external_pointer, key, times_4, 0));
+ __ movss(result, operand);
__ cvtss2sd(result, result);
} else if (array_type == kExternalDoubleArray) {
- __ movdbl(ToDoubleRegister(instr->result()),
- Operand(external_pointer, key, times_8, 0));
+ __ movdbl(ToDoubleRegister(instr->result()), operand);
} else {
Register result(ToRegister(instr->result()));
switch (array_type) {
case kExternalByteArray:
- __ movsx_b(result, Operand(external_pointer, key, times_1, 0));
+ __ movsx_b(result, operand);
break;
case kExternalUnsignedByteArray:
case kExternalPixelArray:
- __ movzx_b(result, Operand(external_pointer, key, times_1, 0));
+ __ movzx_b(result, operand);
break;
case kExternalShortArray:
- __ movsx_w(result, Operand(external_pointer, key, times_2, 0));
+ __ movsx_w(result, operand);
break;
case kExternalUnsignedShortArray:
- __ movzx_w(result, Operand(external_pointer, key, times_2, 0));
+ __ movzx_w(result, operand);
break;
case kExternalIntArray:
- __ mov(result, Operand(external_pointer, key, times_4, 0));
+ __ mov(result, operand);
break;
case kExternalUnsignedIntArray:
- __ mov(result, Operand(external_pointer, key, times_4, 0));
+ __ mov(result, operand);
__ test(result, Operand(result));
// TODO(danno): we could be more clever here, perhaps having a special
// version of the stub that detects if the overflow case actually
@@ -3097,15 +3142,14 @@ void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
void LCodeGen::DoStoreKeyedSpecializedArrayElement(
LStoreKeyedSpecializedArrayElement* instr) {
- Register external_pointer = ToRegister(instr->external_pointer());
- Register key = ToRegister(instr->key());
ExternalArrayType array_type = instr->array_type();
+ Operand operand(BuildExternalArrayOperand(instr->external_pointer(),
+ instr->key(), array_type));
if (array_type == kExternalFloatArray) {
__ cvtsd2ss(xmm0, ToDoubleRegister(instr->value()));
- __ movss(Operand(external_pointer, key, times_4, 0), xmm0);
+ __ movss(operand, xmm0);
} else if (array_type == kExternalDoubleArray) {
- __ movdbl(Operand(external_pointer, key, times_8, 0),
- ToDoubleRegister(instr->value()));
+ __ movdbl(operand, ToDoubleRegister(instr->value()));
} else {
Register value = ToRegister(instr->value());
switch (array_type) {
@@ -3124,20 +3168,20 @@ void LCodeGen::DoStoreKeyedSpecializedArrayElement(
__ setcc(negative, temp); // 1 if negative, 0 if positive.
__ dec_b(temp); // 0 if negative, 255 if positive.
__ bind(&done);
- __ mov_b(Operand(external_pointer, key, times_1, 0), temp);
+ __ mov_b(operand, temp);
break;
}
case kExternalByteArray:
case kExternalUnsignedByteArray:
- __ mov_b(Operand(external_pointer, key, times_1, 0), value);
+ __ mov_b(operand, value);
break;
case kExternalShortArray:
case kExternalUnsignedShortArray:
- __ mov_w(Operand(external_pointer, key, times_2, 0), value);
+ __ mov_w(operand, value);
break;
case kExternalIntArray:
case kExternalUnsignedIntArray:
- __ mov(Operand(external_pointer, key, times_4, 0), value);
+ __ mov(operand, value);
break;
case kExternalFloatArray:
case kExternalDoubleArray:

Powered by Google App Engine
This is Rietveld 408576698