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

Side by Side Diff: runtime/vm/intermediate_language_ia32.cc

Issue 11360033: Inline native String.charCodeAt in optimized code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: addressed comments Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 &StubCode::CallNativeCFunctionLabel(), 1073 &StubCode::CallNativeCFunctionLabel(),
1074 PcDescriptors::kOther, 1074 PcDescriptors::kOther,
1075 locs()); 1075 locs());
1076 __ popl(result); 1076 __ popl(result);
1077 } 1077 }
1078 1078
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 if (!constant.IsSmi()) return false;
1083 const Smi& smi_const = Smi::Cast(constant); 1084 const Smi& smi_const = Smi::Cast(constant);
1084 int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray); 1085 int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray);
1085 return Utils::IsInt(32, disp); 1086 return Utils::IsInt(32, disp);
1086 } 1087 }
1087 1088
1088 1089
1090 LocationSummary* StringCharCodeAtInstr::MakeLocationSummary() const {
1091 const intptr_t kNumInputs = 2;
1092 const intptr_t kNumTemps = 0;
1093 LocationSummary* locs =
1094 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
1095 locs->set_in(0, Location::RequiresRegister());
1096 // TODO(fschneider): Allow immediate operands for the index.
1097 locs->set_in(1, Location::RequiresRegister());
1098 locs->set_out(Location::RequiresRegister());
1099 return locs;
1100 }
1101
1102
1103 void StringCharCodeAtInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
1104 Register str = locs()->in(0).reg();
1105 Register index = locs()->in(1).reg();
1106 Register result = locs()->out().reg();
1107
1108 ASSERT((class_id() == kOneByteStringCid) ||
1109 (class_id() == kTwoByteStringCid));
1110 if (class_id() == kOneByteStringCid) {
1111 __ SmiUntag(index);
1112 __ movzxb(result, FieldAddress(str,
1113 index,
1114 TIMES_1,
1115 OneByteString::data_offset()));
1116 __ SmiTag(index); // Retag index.
1117 __ SmiTag(result);
1118 } else {
1119 // Don't untag smi-index and use TIMES_1 for two byte strings.
1120 __ movzxw(result, FieldAddress(str,
1121 index,
1122 TIMES_1,
1123 TwoByteString::data_offset()));
1124 __ SmiTag(result);
1125 }
1126 }
1127
1128
1089 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { 1129 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const {
1090 const intptr_t kNumInputs = 2; 1130 const intptr_t kNumInputs = 2;
1091 const intptr_t kNumTemps = 0; 1131 const intptr_t kNumTemps = 0;
1092 LocationSummary* locs = 1132 LocationSummary* locs =
1093 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 1133 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
1094 locs->set_in(0, Location::RequiresRegister()); 1134 locs->set_in(0, Location::RequiresRegister());
1095 locs->set_in(1, CanBeImmediateIndex(index()) 1135 locs->set_in(1, CanBeImmediateIndex(index())
1096 ? Location::RegisterOrConstant(index()) 1136 ? Location::RegisterOrConstant(index())
1097 : Location::RequiresRegister()); 1137 : Location::RequiresRegister());
1098 if (representation() == kUnboxedDouble) { 1138 if (representation() == kUnboxedDouble) {
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
2347 const intptr_t kNumTemps = 0; 2387 const intptr_t kNumTemps = 0;
2348 LocationSummary* locs = 2388 LocationSummary* locs =
2349 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2389 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2350 locs->set_in(0, Location::RegisterOrConstant(array())); 2390 locs->set_in(0, Location::RegisterOrConstant(array()));
2351 locs->set_in(1, Location::RegisterOrConstant(index())); 2391 locs->set_in(1, Location::RegisterOrConstant(index()));
2352 return locs; 2392 return locs;
2353 } 2393 }
2354 2394
2355 2395
2356 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2396 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2357 const DeoptReasonId deopt_reason =
2358 (array_type() == kGrowableObjectArrayCid) ?
2359 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray;
2360 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2397 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2361 deopt_reason); 2398 kDeoptCheckArrayBound);
2362 ASSERT((array_type() == kArrayCid) || 2399 if (locs()->in(0).IsConstant() && locs()->in(1).IsConstant()) {
2363 (array_type() == kImmutableArrayCid) || 2400 // Unconditionally deoptimize for constant bounds checks because they
2364 (array_type() == kGrowableObjectArrayCid) || 2401 // only occur only when index is out-of-bounds.
2365 (array_type() == kFloat64ArrayCid) || 2402 __ jmp(deopt);
2366 (array_type() == kFloat32ArrayCid)); 2403 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 } 2404 }
2377 // This case should not have created a bound check instruction.
2378 ASSERT(!(locs()->in(0).IsConstant() && locs()->in(1).IsConstant()));
2379 2405
2406 intptr_t length_offset = LengthOffsetFor(array_type());
2380 if (locs()->in(1).IsConstant()) { 2407 if (locs()->in(1).IsConstant()) {
2381 Register receiver = locs()->in(0).reg(); 2408 Register receiver = locs()->in(0).reg();
2382 const Object& constant = locs()->in(1).constant(); 2409 const Object& constant = locs()->in(1).constant();
2383 ASSERT(constant.IsSmi()); 2410 ASSERT(constant.IsSmi());
2384 const int32_t imm = 2411 const int32_t imm =
2385 reinterpret_cast<int32_t>(constant.raw()); 2412 reinterpret_cast<int32_t>(constant.raw());
2386 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm)); 2413 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm));
2387 __ j(BELOW_EQUAL, deopt); 2414 __ j(BELOW_EQUAL, deopt);
2388 } else if (locs()->in(0).IsConstant()) { 2415 } else if (locs()->in(0).IsConstant()) {
2389 const Object& constant = locs()->in(0).constant(); 2416 ASSERT(locs()->in(0).constant().IsArray() ||
2390 ASSERT(constant.IsArray()); 2417 locs()->in(0).constant().IsString());
2391 const Array& array = Array::Cast(constant); 2418 intptr_t length = locs()->in(0).constant().IsArray()
2419 ? Array::Cast(locs()->in(0).constant()).Length()
2420 : String::Cast(locs()->in(0).constant()).Length();
2392 Register index = locs()->in(1).reg(); 2421 Register index = locs()->in(1).reg();
2393 __ cmpl(index, 2422 __ cmpl(index,
2394 Immediate(reinterpret_cast<int32_t>(Smi::New(array.Length())))); 2423 Immediate(reinterpret_cast<int32_t>(Smi::New(length))));
2395 __ j(ABOVE_EQUAL, deopt); 2424 __ j(ABOVE_EQUAL, deopt);
2396 } else { 2425 } else {
2397 Register receiver = locs()->in(0).reg(); 2426 Register receiver = locs()->in(0).reg();
2398 Register index = locs()->in(1).reg(); 2427 Register index = locs()->in(1).reg();
2399 __ cmpl(index, FieldAddress(receiver, length_offset)); 2428 __ cmpl(index, FieldAddress(receiver, length_offset));
2400 __ j(ABOVE_EQUAL, deopt); 2429 __ j(ABOVE_EQUAL, deopt);
2401 } 2430 }
2402 } 2431 }
2403 2432
2404 2433
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 __ pcmpeqq(XMM0, XMM0); // Generate all 1's. 2727 __ pcmpeqq(XMM0, XMM0); // Generate all 1's.
2699 __ pxor(value, XMM0); 2728 __ pxor(value, XMM0);
2700 } 2729 }
2701 2730
2702 2731
2703 } // namespace dart 2732 } // namespace dart
2704 2733
2705 #undef __ 2734 #undef __
2706 2735
2707 #endif // defined TARGET_ARCH_X64 2736 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.cc ('k') | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698