Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1079 | 1079 |
| 1080 static bool CanBeImmediateIndex(Value* index) { | 1080 static bool CanBeImmediateIndex(Value* index) { |
| 1081 if (!index->definition()->IsConstant()) return false; | 1081 if (!index->definition()->IsConstant()) return false; |
| 1082 const Object& constant = index->definition()->AsConstant()->value(); | 1082 const Object& constant = index->definition()->AsConstant()->value(); |
| 1083 const Smi& smi_const = Smi::Cast(constant); | 1083 const Smi& smi_const = Smi::Cast(constant); |
| 1084 int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray); | 1084 int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray); |
| 1085 return Utils::IsInt(32, disp); | 1085 return Utils::IsInt(32, disp); |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 | 1088 |
| 1089 LocationSummary* StringCharCodeAtInstr::MakeLocationSummary() const { | |
| 1090 const intptr_t kNumInputs = 2; | |
| 1091 const intptr_t kNumTemps = 0; | |
| 1092 LocationSummary* locs = | |
| 1093 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | |
| 1094 locs->set_in(0, Location::RequiresRegister()); | |
| 1095 // TODO(fschneider): Allow immediate operands for the index. | |
| 1096 locs->set_in(1, Location::RequiresRegister()); | |
| 1097 locs->set_out(Location::RequiresRegister()); | |
| 1098 return locs; | |
| 1099 } | |
| 1100 | |
| 1101 | |
| 1102 void StringCharCodeAtInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | |
| 1103 Register str = locs()->in(0).reg(); | |
| 1104 Register index = locs()->in(1).reg(); | |
| 1105 Register result = locs()->out().reg(); | |
| 1106 | |
| 1107 ASSERT((class_id() == kOneByteStringCid) || | |
| 1108 (class_id() == kTwoByteStringCid)); | |
| 1109 if (class_id() == kOneByteStringCid) { | |
| 1110 __ SmiUntag(index); | |
|
srdjan
2012/11/01 20:32:18
Is it better to tag/untag or to require a temporar
Florian Schneider
2012/11/01 22:58:56
With a quick test, I found no noticable difference
| |
| 1111 __ movzxb(result, FieldAddress(str, | |
| 1112 index, | |
| 1113 TIMES_1, | |
| 1114 OneByteString::data_offset())); | |
| 1115 __ SmiTag(index); // Retag index. | |
| 1116 __ SmiTag(result); | |
| 1117 } else { | |
| 1118 // Don't untag smi-index and use TIMES_1 for two byte strings. | |
| 1119 __ movzxw(result, FieldAddress(str, | |
| 1120 index, | |
| 1121 TIMES_1, | |
| 1122 TwoByteString::data_offset())); | |
| 1123 __ SmiTag(result); | |
| 1124 } | |
| 1125 } | |
| 1126 | |
| 1127 | |
| 1089 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { | 1128 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { |
| 1090 const intptr_t kNumInputs = 2; | 1129 const intptr_t kNumInputs = 2; |
| 1091 const intptr_t kNumTemps = 0; | 1130 const intptr_t kNumTemps = 0; |
| 1092 LocationSummary* locs = | 1131 LocationSummary* locs = |
| 1093 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 1132 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 1094 locs->set_in(0, Location::RequiresRegister()); | 1133 locs->set_in(0, Location::RequiresRegister()); |
| 1095 locs->set_in(1, CanBeImmediateIndex(index()) | 1134 locs->set_in(1, CanBeImmediateIndex(index()) |
| 1096 ? Location::RegisterOrConstant(index()) | 1135 ? Location::RegisterOrConstant(index()) |
| 1097 : Location::RequiresRegister()); | 1136 : Location::RequiresRegister()); |
| 1098 if (representation() == kUnboxedDouble) { | 1137 if (representation() == kUnboxedDouble) { |
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2347 const intptr_t kNumTemps = 0; | 2386 const intptr_t kNumTemps = 0; |
| 2348 LocationSummary* locs = | 2387 LocationSummary* locs = |
| 2349 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 2388 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 2350 locs->set_in(0, Location::RegisterOrConstant(array())); | 2389 locs->set_in(0, Location::RegisterOrConstant(array())); |
| 2351 locs->set_in(1, Location::RegisterOrConstant(index())); | 2390 locs->set_in(1, Location::RegisterOrConstant(index())); |
| 2352 return locs; | 2391 return locs; |
| 2353 } | 2392 } |
| 2354 | 2393 |
| 2355 | 2394 |
| 2356 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 2395 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 2357 const DeoptReasonId deopt_reason = | |
| 2358 (array_type() == kGrowableObjectArrayCid) ? | |
| 2359 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray; | |
| 2360 Label* deopt = compiler->AddDeoptStub(deopt_id(), | 2396 Label* deopt = compiler->AddDeoptStub(deopt_id(), |
| 2361 deopt_reason); | 2397 kDeoptCheckArrayBound); |
| 2362 ASSERT((array_type() == kArrayCid) || | 2398 if (locs()->in(0).IsConstant() && locs()->in(1).IsConstant()) { |
| 2363 (array_type() == kImmutableArrayCid) || | 2399 // Unconditionally deoptimize for constant bounds checks because they |
| 2364 (array_type() == kGrowableObjectArrayCid) || | 2400 // only occur only when index is out-of-bounds. |
| 2365 (array_type() == kFloat64ArrayCid) || | 2401 __ jmp(deopt); |
| 2366 (array_type() == kFloat32ArrayCid)); | 2402 return; |
| 2367 intptr_t length_offset = -1; | |
| 2368 if (array_type() == kGrowableObjectArrayCid) { | |
| 2369 length_offset = GrowableObjectArray::length_offset(); | |
| 2370 } else if (array_type() == kFloat64ArrayCid) { | |
| 2371 length_offset = Float64Array::length_offset(); | |
| 2372 } else if (array_type() == kFloat32ArrayCid) { | |
| 2373 length_offset = Float32Array::length_offset(); | |
| 2374 } else { | |
| 2375 length_offset = Array::length_offset(); | |
| 2376 } | 2403 } |
| 2377 // This case should not have created a bound check instruction. | |
| 2378 ASSERT(!(locs()->in(0).IsConstant() && locs()->in(1).IsConstant())); | |
| 2379 | 2404 |
| 2405 intptr_t length_offset = LengthOffsetFor(array_type()); | |
| 2380 if (locs()->in(1).IsConstant()) { | 2406 if (locs()->in(1).IsConstant()) { |
| 2381 Register receiver = locs()->in(0).reg(); | 2407 Register receiver = locs()->in(0).reg(); |
| 2382 const Object& constant = locs()->in(1).constant(); | 2408 const Object& constant = locs()->in(1).constant(); |
| 2383 ASSERT(constant.IsSmi()); | 2409 ASSERT(constant.IsSmi()); |
| 2384 const int32_t imm = | 2410 const int32_t imm = |
| 2385 reinterpret_cast<int32_t>(constant.raw()); | 2411 reinterpret_cast<int32_t>(constant.raw()); |
| 2386 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm)); | 2412 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm)); |
| 2387 __ j(BELOW_EQUAL, deopt); | 2413 __ j(BELOW_EQUAL, deopt); |
| 2388 } else if (locs()->in(0).IsConstant()) { | 2414 } else if (locs()->in(0).IsConstant()) { |
| 2389 const Object& constant = locs()->in(0).constant(); | 2415 ASSERT(locs()->in(0).constant().IsArray() || |
| 2390 ASSERT(constant.IsArray()); | 2416 locs()->in(0).constant().IsString()); |
| 2391 const Array& array = Array::Cast(constant); | 2417 intptr_t length = locs()->in(0).constant().IsArray() |
| 2418 ? Array::Cast(locs()->in(0).constant()).Length() | |
| 2419 : String::Cast(locs()->in(0).constant()).Length(); | |
| 2392 Register index = locs()->in(1).reg(); | 2420 Register index = locs()->in(1).reg(); |
| 2393 __ cmpl(index, | 2421 __ cmpl(index, |
| 2394 Immediate(reinterpret_cast<int32_t>(Smi::New(array.Length())))); | 2422 Immediate(reinterpret_cast<int32_t>(Smi::New(length)))); |
| 2395 __ j(ABOVE_EQUAL, deopt); | 2423 __ j(ABOVE_EQUAL, deopt); |
| 2396 } else { | 2424 } else { |
| 2397 Register receiver = locs()->in(0).reg(); | 2425 Register receiver = locs()->in(0).reg(); |
| 2398 Register index = locs()->in(1).reg(); | 2426 Register index = locs()->in(1).reg(); |
| 2399 __ cmpl(index, FieldAddress(receiver, length_offset)); | 2427 __ cmpl(index, FieldAddress(receiver, length_offset)); |
| 2400 __ j(ABOVE_EQUAL, deopt); | 2428 __ j(ABOVE_EQUAL, deopt); |
| 2401 } | 2429 } |
| 2402 } | 2430 } |
| 2403 | 2431 |
| 2404 | 2432 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2698 __ pcmpeqq(XMM0, XMM0); // Generate all 1's. | 2726 __ pcmpeqq(XMM0, XMM0); // Generate all 1's. |
| 2699 __ pxor(value, XMM0); | 2727 __ pxor(value, XMM0); |
| 2700 } | 2728 } |
| 2701 | 2729 |
| 2702 | 2730 |
| 2703 } // namespace dart | 2731 } // namespace dart |
| 2704 | 2732 |
| 2705 #undef __ | 2733 #undef __ |
| 2706 | 2734 |
| 2707 #endif // defined TARGET_ARCH_X64 | 2735 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |