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

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

Issue 11360033: Inline native String.charCodeAt in optimized code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: fixed a bug in indexed ops and added more tests 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
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_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
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 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 944
945 static bool CanBeImmediateIndex(Value* index) { 945 static bool CanBeImmediateIndex(Value* index) {
946 if (!index->definition()->IsConstant()) return false; 946 if (!index->definition()->IsConstant()) return false;
947 const Object& constant = index->definition()->AsConstant()->value(); 947 const Object& constant = index->definition()->AsConstant()->value();
948 const Smi& smi_const = Smi::Cast(constant); 948 const Smi& smi_const = Smi::Cast(constant);
949 int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray); 949 int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray);
950 return Utils::IsInt(32, disp); 950 return Utils::IsInt(32, disp);
951 } 951 }
952 952
953 953
954 LocationSummary* StringCharCodeAtInstr::MakeLocationSummary() const {
955 const intptr_t kNumInputs = 2;
956 const intptr_t kNumTemps = 0;
957 LocationSummary* locs =
958 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
959 locs->set_in(0, Location::RequiresRegister());
960 // TODO(fschneider): Allow immediate operands for the index.
961 locs->set_in(1, Location::RequiresRegister());
962 locs->set_out(Location::RequiresRegister());
963 return locs;
964 }
965
966
967 void StringCharCodeAtInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
968 Register str = locs()->in(0).reg();
969 Register index = locs()->in(1).reg();
970 Register result = locs()->out().reg();
971
972 ASSERT((class_id() == kOneByteStringCid) ||
973 (class_id() == kTwoByteStringCid));
974 if (class_id() == kOneByteStringCid) {
975 __ SmiUntag(index);
976 __ movzxb(result, FieldAddress(str,
977 index,
978 TIMES_1,
979 OneByteString::data_offset()));
980 __ SmiTag(index); // Retag index.
981 __ SmiTag(result);
982 } else {
983 // Don't untag smi-index and use TIMES_1 for two byte strings.
984 __ movzxw(result, FieldAddress(str,
985 index,
986 TIMES_1,
987 TwoByteString::data_offset()));
988 __ SmiTag(result);
989 }
990 }
991
992
954 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { 993 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const {
955 const intptr_t kNumInputs = 2; 994 const intptr_t kNumInputs = 2;
956 const intptr_t kNumTemps = 0; 995 const intptr_t kNumTemps = 0;
957 LocationSummary* locs = 996 LocationSummary* locs =
958 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 997 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
959 locs->set_in(0, Location::RequiresRegister()); 998 locs->set_in(0, Location::RequiresRegister());
960 locs->set_in(1, CanBeImmediateIndex(index()) 999 locs->set_in(1, CanBeImmediateIndex(index())
961 ? Location::RegisterOrConstant(index()) 1000 ? Location::RegisterOrConstant(index())
962 : Location::RequiresRegister()); 1001 : Location::RequiresRegister());
963 if (representation() == kUnboxedDouble) { 1002 if (representation() == kUnboxedDouble) {
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
2224 const intptr_t kNumTemps = 0; 2263 const intptr_t kNumTemps = 0;
2225 LocationSummary* locs = 2264 LocationSummary* locs =
2226 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2265 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2227 locs->set_in(0, Location::RequiresRegister()); 2266 locs->set_in(0, Location::RequiresRegister());
2228 locs->set_in(1, Location::RegisterOrConstant(index())); 2267 locs->set_in(1, Location::RegisterOrConstant(index()));
2229 return locs; 2268 return locs;
2230 } 2269 }
2231 2270
2232 2271
2233 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2272 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2234 const DeoptReasonId deopt_reason =
2235 (array_type() == kGrowableObjectArrayCid) ?
2236 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray;
2237 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2273 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2238 deopt_reason); 2274 kDeoptCheckArrayBound);
2239 ASSERT((array_type() == kArrayCid) || 2275 if (locs()->in(0).IsConstant() && locs()->in(1).IsConstant()) {
2240 (array_type() == kImmutableArrayCid) || 2276 // Unconditionally deoptimize for constant bounds checks because they
2241 (array_type() == kGrowableObjectArrayCid) || 2277 // only occur only when index is out-of-bounds.
2242 (array_type() == kFloat64ArrayCid) || 2278 __ jmp(deopt);
2243 (array_type() == kFloat32ArrayCid)); 2279 return;
2244 intptr_t length_offset = -1;
2245 if (array_type() == kGrowableObjectArrayCid) {
2246 length_offset = GrowableObjectArray::length_offset();
2247 } else if (array_type() == kFloat64ArrayCid) {
2248 length_offset = Float64Array::length_offset();
2249 } else if (array_type() == kFloat32ArrayCid) {
2250 length_offset = Float32Array::length_offset();
2251 } else {
2252 length_offset = Array::length_offset();
2253 } 2280 }
2254 2281
2255 // This case should not have created a bound check instruction.
2256 ASSERT(!(locs()->in(0).IsConstant() && locs()->in(1).IsConstant()));
2257 2282
2283 intptr_t length_offset = LengthOffsetFor(array_type());
2258 if (locs()->in(1).IsConstant()) { 2284 if (locs()->in(1).IsConstant()) {
2259 Register receiver = locs()->in(0).reg(); 2285 Register receiver = locs()->in(0).reg();
2260 const Object& constant = locs()->in(1).constant(); 2286 const Object& constant = locs()->in(1).constant();
2261 ASSERT(constant.IsSmi()); 2287 ASSERT(constant.IsSmi());
2262 const int64_t imm = 2288 const int64_t imm =
2263 reinterpret_cast<int64_t>(constant.raw()); 2289 reinterpret_cast<int64_t>(constant.raw());
2264 __ cmpq(FieldAddress(receiver, length_offset), Immediate(imm)); 2290 __ cmpq(FieldAddress(receiver, length_offset), Immediate(imm));
2265 __ j(BELOW_EQUAL, deopt); 2291 __ j(BELOW_EQUAL, deopt);
2266 } else if (locs()->in(0).IsConstant()) { 2292 } else if (locs()->in(0).IsConstant()) {
2267 const Object& constant = locs()->in(0).constant(); 2293 ASSERT(locs()->in(0).constant().IsArray() ||
2268 ASSERT(constant.IsArray()); 2294 locs()->in(0).constant().IsString());
2269 const Array& array = Array::Cast(constant); 2295 intptr_t length = locs()->in(0).constant().IsArray()
2296 ? Array::Cast(locs()->in(0).constant()).Length()
2297 : String::Cast(locs()->in(0).constant()).Length();
2270 Register index = locs()->in(1).reg(); 2298 Register index = locs()->in(1).reg();
2271 __ cmpq(index, 2299 __ cmpq(index,
2272 Immediate(reinterpret_cast<int64_t>(Smi::New(array.Length())))); 2300 Immediate(reinterpret_cast<int64_t>(Smi::New(length))));
2273 __ j(ABOVE_EQUAL, deopt); 2301 __ j(ABOVE_EQUAL, deopt);
2274 } else { 2302 } else {
2275 Register receiver = locs()->in(0).reg(); 2303 Register receiver = locs()->in(0).reg();
2276 Register index = locs()->in(1).reg(); 2304 Register index = locs()->in(1).reg();
2277 __ cmpq(index, FieldAddress(receiver, length_offset)); 2305 __ cmpq(index, FieldAddress(receiver, length_offset));
2278 __ j(ABOVE_EQUAL, deopt); 2306 __ j(ABOVE_EQUAL, deopt);
2279 } 2307 }
2280 } 2308 }
2281 2309
2282 2310
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 2360
2333 void ShiftMintOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2361 void ShiftMintOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2334 UNIMPLEMENTED(); 2362 UNIMPLEMENTED();
2335 } 2363 }
2336 2364
2337 } // namespace dart 2365 } // namespace dart
2338 2366
2339 #undef __ 2367 #undef __
2340 2368
2341 #endif // defined TARGET_ARCH_X64 2369 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698