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

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

Issue 12335138: Intrinsify OnebyteString's hashcode. Next step is to inline it. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intrinsifier_mips.cc ('k') | runtime/vm/object.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/intrinsifier.h" 8 #include "vm/intrinsifier.h"
9 9
10 #include "vm/assembler.h" 10 #include "vm/assembler.h"
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 __ cmpq(RAX, Immediate(Smi::RawValue(0))); 1387 __ cmpq(RAX, Immediate(Smi::RawValue(0)));
1388 __ j(EQUAL, &is_true, Assembler::kNearJump); 1388 __ j(EQUAL, &is_true, Assembler::kNearJump);
1389 __ LoadObject(RAX, Bool::False()); 1389 __ LoadObject(RAX, Bool::False());
1390 __ ret(); 1390 __ ret();
1391 __ Bind(&is_true); 1391 __ Bind(&is_true);
1392 __ LoadObject(RAX, Bool::True()); 1392 __ LoadObject(RAX, Bool::True());
1393 __ ret(); 1393 __ ret();
1394 return true; 1394 return true;
1395 } 1395 }
1396 1396
1397
1398 bool Intrinsifier::OneByteString_getHashCode(Assembler* assembler) {
1399 Label compute_hash;
1400 __ movq(RBX, Address(RSP, + 1 * kWordSize)); // OneByteString object.
1401 __ movq(RAX, FieldAddress(RBX, String::hash_offset()));
1402 __ cmpq(RAX, Immediate(0));
1403 __ j(EQUAL, &compute_hash, Assembler::kNearJump);
1404 __ ret();
1405
1406 __ Bind(&compute_hash);
1407 // Hash not yet computed, use algorithm of class StringHasher.
1408 __ movq(RCX, FieldAddress(RBX, String::length_offset()));
1409 __ SmiUntag(RCX);
1410 __ xorq(RAX, RAX);
1411 __ xorq(RDI, RDI);
1412 // RBX: Instance of OneByteString.
1413 // RCX: String length, untagged integer.
1414 // RDI: Loop counter, untagged integer.
1415 // RAX: Hash code, untagged integer.
1416 Label loop, done, set_hash_code;
1417 __ Bind(&loop);
1418 __ cmpq(RDI, RCX);
1419 __ j(EQUAL, &done, Assembler::kNearJump);
1420 // Add to hash code: (hash_ is uint32)
1421 // hash_ += ch;
1422 // hash_ += hash_ << 10;
1423 // hash_ ^= hash_ >> 6;
1424 // Get one characters (ch).
1425 __ movzxb(RDX, FieldAddress(RBX, RDI, TIMES_1, OneByteString::data_offset()));
1426 // RDX: ch and temporary.
1427 __ addl(RAX, RDX);
1428 __ movq(RDX, RAX);
1429 __ shll(RDX, Immediate(10));
1430 __ addl(RAX, RDX);
1431 __ movq(RDX, RAX);
1432 __ shrl(RDX, Immediate(6));
1433 __ xorl(RAX, RDX);
1434
1435 __ incq(RDI);
1436 __ jmp(&loop, Assembler::kNearJump);
1437
1438 __ Bind(&done);
1439 // Finalize:
1440 // hash_ += hash_ << 3;
1441 // hash_ ^= hash_ >> 11;
1442 // hash_ += hash_ << 15;
1443 __ movq(RDX, RAX);
1444 __ shll(RDX, Immediate(3));
1445 __ addl(RAX, RDX);
1446 __ movq(RDX, RAX);
1447 __ shrl(RDX, Immediate(11));
1448 __ xorl(RAX, RDX);
1449 __ movq(RDX, RAX);
1450 __ shll(RDX, Immediate(15));
1451 __ addl(RAX, RDX);
1452 // hash_ = hash_ & ((static_cast<intptr_t>(1) << bits) - 1);
1453 __ andl(RAX,
1454 Immediate(((static_cast<intptr_t>(1) << String::kHashBits) - 1)));
1455
1456 // return hash_ == 0 ? 1 : hash_;
1457 __ cmpq(RAX, Immediate(0));
1458 __ j(NOT_EQUAL, &set_hash_code, Assembler::kNearJump);
1459 __ incq(RAX);
1460 __ Bind(&set_hash_code);
1461 __ SmiTag(RAX);
1462 __ movq(FieldAddress(RBX, String::hash_offset()), RAX);
1463 __ ret();
1464 return true;
1465 }
1466
1467
1397 #undef __ 1468 #undef __
1398 1469
1399 } // namespace dart 1470 } // namespace dart
1400 1471
1401 #endif // defined TARGET_ARCH_X64 1472 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_mips.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698