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

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

Issue 490263002: Adds intrinsics for array allocation and string charAt. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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/method_recognizer.h » ('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"
11 #include "vm/flow_graph_compiler.h" 11 #include "vm/flow_graph_compiler.h"
12 #include "vm/instructions.h" 12 #include "vm/instructions.h"
13 #include "vm/object_store.h" 13 #include "vm/object_store.h"
14 #include "vm/symbols.h" 14 #include "vm/symbols.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 DECLARE_FLAG(bool, enable_type_checks); 18 DECLARE_FLAG(bool, enable_type_checks);
19 19
20 // When entering intrinsics code: 20 // When entering intrinsics code:
21 // RBX: IC Data 21 // RBX: IC Data
22 // R10: Arguments descriptor 22 // R10: Arguments descriptor
23 // TOS: Return address 23 // TOS: Return address
24 // The RBX, R10 registers can be destroyed only if there is no slow-path (i.e., 24 // The RBX, R10 registers can be destroyed only if there is no slow-path (i.e.,
25 // the methods returns true). 25 // the methods returns true).
26 26
27 #define __ assembler-> 27 #define __ assembler->
28 28
29 29
30 void Intrinsifier::ObjectArrayAllocate(Assembler* assembler) {
31 Label fall_through;
32 const intptr_t kTypeArgumentsOffset = 2 * kWordSize;
33 const intptr_t kLengthOffset = 1 * kWordSize;
34
35 __ movq(RDI, Address(RSP, kLengthOffset));
36
37 // Compute the size to be allocated, it is based on the array length
38 // and is computed as:
39 // RoundedAllocationSize((array_length * kwordSize) + sizeof(RawArray)).
40 // Check that length is a positive Smi.
41 __ testq(RDI, Immediate(kSmiTagMask));
42 __ j(NOT_ZERO, &fall_through);
43 __ cmpq(RDI, Immediate(0));
44 __ j(LESS, &fall_through);
45 // Check for maximum allowed length.
46 const Immediate& max_len =
47 Immediate(reinterpret_cast<int64_t>(Smi::New(Array::kMaxElements)));
48 __ cmpq(RDI, max_len);
49 __ j(GREATER, &fall_through);
50 const intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1;
51 __ leaq(RDI, Address(RDI, TIMES_4, fixed_size)); // RDI is a Smi.
52 ASSERT(kSmiTagShift == 1);
53 __ andq(RDI, Immediate(-kObjectAlignment));
54
55 Isolate* isolate = Isolate::Current();
56 Heap* heap = isolate->heap();
57
58 __ movq(RAX, Immediate(heap->TopAddress()));
59 __ movq(RAX, Address(RAX, 0));
60
61 // RDI: allocation size.
62 __ movq(RCX, RAX);
63 __ addq(RCX, RDI);
64 __ j(CARRY, &fall_through);
65
66 // Check if the allocation fits into the remaining space.
67 // RAX: potential new object start.
68 // RCX: potential next object start.
69 // RDI: allocation size.
70 __ movq(R13, Immediate(heap->EndAddress()));
71 __ cmpq(RCX, Address(R13, 0));
72 __ j(ABOVE_EQUAL, &fall_through);
73
74 // Successfully allocated the object(s), now update top to point to
75 // next object start and initialize the object.
76 __ movq(R13, Immediate(heap->TopAddress()));
77 __ movq(Address(R13, 0), RCX);
78 __ addq(RAX, Immediate(kHeapObjectTag));
79 __ UpdateAllocationStatsWithSize(kArrayCid, RDI);
80 // Initialize the tags.
81 // RAX: new object start as a tagged pointer.
82 // RDI: allocation size.
83 {
84 Label size_tag_overflow, done;
85 __ cmpq(RDI, Immediate(RawObject::SizeTag::kMaxSizeTag));
86 __ j(ABOVE, &size_tag_overflow, Assembler::kNearJump);
87 __ shlq(RDI, Immediate(RawObject::kSizeTagPos - kObjectAlignmentLog2));
88 __ jmp(&done, Assembler::kNearJump);
89
90 __ Bind(&size_tag_overflow);
91 __ movq(RDI, Immediate(0));
92 __ Bind(&done);
93
94 // Get the class index and insert it into the tags.
95 const Class& cls = Class::Handle(isolate->object_store()->array_class());
96 __ orq(RDI, Immediate(RawObject::ClassIdTag::encode(cls.id())));
97 __ movq(FieldAddress(RAX, Array::tags_offset()), RDI); // Tags.
98 }
99
100 // RAX: new object start as a tagged pointer.
101 // Store the type argument field.
102 __ movq(R13, Address(RSP, kTypeArgumentsOffset));
103 __ StoreIntoObjectNoBarrier(RAX,
104 FieldAddress(RAX, Array::type_arguments_offset()),
105 R13);
106
107 // Set the length field.
108 __ movq(RDI, Address(RSP, kLengthOffset));
109 __ StoreIntoObjectNoBarrier(RAX,
110 FieldAddress(RAX, Array::length_offset()),
111 RDI);
112
113 // Initialize all array elements to raw_null.
114 // RAX: new object start as a tagged pointer.
115 // RCX: new object end address.
116 // RDI: iterator which initially points to the start of the variable
117 // data area to be initialized.
118 __ LoadObject(R12, Object::null_object(), PP);
119 __ leaq(RDI, FieldAddress(RAX, sizeof(RawArray)));
120 Label done;
121 Label init_loop;
122 __ Bind(&init_loop);
123 __ cmpq(RDI, RCX);
124 __ j(ABOVE_EQUAL, &done, Assembler::kNearJump);
125 __ movq(Address(RDI, 0), R12);
126 __ addq(RDI, Immediate(kWordSize));
127 __ jmp(&init_loop, Assembler::kNearJump);
128 __ Bind(&done);
129 __ ret(); // returns the newly allocated object in RAX.
130
131 __ Bind(&fall_through);
132 }
133
134
30 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { 135 void Intrinsifier::ObjectArrayLength(Assembler* assembler) {
31 __ movq(RAX, Address(RSP, + 1 * kWordSize)); 136 __ movq(RAX, Address(RSP, + 1 * kWordSize));
32 __ movq(RAX, FieldAddress(RAX, Array::length_offset())); 137 __ movq(RAX, FieldAddress(RAX, Array::length_offset()));
33 __ ret(); 138 __ ret();
34 } 139 }
35 140
36 141
37 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { 142 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) {
38 ObjectArrayLength(assembler); 143 ObjectArrayLength(assembler);
39 } 144 }
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump); 1403 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump);
1299 ASSERT(kSmiTagShift == 1); 1404 ASSERT(kSmiTagShift == 1);
1300 __ movzxw(RAX, FieldAddress(RAX, RCX, TIMES_1, OneByteString::data_offset())); 1405 __ movzxw(RAX, FieldAddress(RAX, RCX, TIMES_1, OneByteString::data_offset()));
1301 __ SmiTag(RAX); 1406 __ SmiTag(RAX);
1302 __ ret(); 1407 __ ret();
1303 1408
1304 __ Bind(&fall_through); 1409 __ Bind(&fall_through);
1305 } 1410 }
1306 1411
1307 1412
1413 void Intrinsifier::StringBase_charAt(Assembler* assembler) {
1414 Label fall_through, try_two_byte_string;
1415 __ movq(RCX, Address(RSP, + 1 * kWordSize)); // Index.
1416 __ movq(RAX, Address(RSP, + 2 * kWordSize)); // String.
1417 __ testq(RCX, Immediate(kSmiTagMask));
1418 __ j(NOT_ZERO, &fall_through, Assembler::kNearJump); // Non-smi index.
1419 // Range check.
1420 __ cmpq(RCX, FieldAddress(RAX, String::length_offset()));
1421 // Runtime throws exception.
1422 __ j(ABOVE_EQUAL, &fall_through, Assembler::kNearJump);
1423 __ CompareClassId(RAX, kOneByteStringCid);
1424 __ j(NOT_EQUAL, &try_two_byte_string, Assembler::kNearJump);
1425 __ SmiUntag(RCX);
1426 __ movzxb(RCX, FieldAddress(RAX, RCX, TIMES_1, OneByteString::data_offset()));
1427 __ cmpq(RCX, Immediate(Symbols::kNumberOfOneCharCodeSymbols));
1428 __ j(GREATER_EQUAL, &fall_through);
1429 __ movq(RAX,
1430 Immediate(reinterpret_cast<uword>(Symbols::PredefinedAddress())));
1431 __ movq(RAX, Address(RAX,
1432 RCX,
1433 TIMES_8,
1434 Symbols::kNullCharCodeSymbolOffset * kWordSize));
1435 __ ret();
1436
1437 __ Bind(&try_two_byte_string);
1438 __ CompareClassId(RAX, kTwoByteStringCid);
1439 __ j(NOT_EQUAL, &fall_through, Assembler::kNearJump);
1440 ASSERT(kSmiTagShift == 1);
1441 __ movzxw(RCX, FieldAddress(RAX, RCX, TIMES_1, OneByteString::data_offset()));
1442 __ cmpq(RCX, Immediate(Symbols::kNumberOfOneCharCodeSymbols));
1443 __ j(GREATER_EQUAL, &fall_through);
1444 __ movq(RAX,
1445 Immediate(reinterpret_cast<uword>(Symbols::PredefinedAddress())));
1446 __ movq(RAX, Address(RAX,
1447 RCX,
1448 TIMES_8,
1449 Symbols::kNullCharCodeSymbolOffset * kWordSize));
1450 __ ret();
1451
1452 __ Bind(&fall_through);
1453 }
1454
1455
1308 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) { 1456 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) {
1309 Label is_true; 1457 Label is_true;
1310 // Get length. 1458 // Get length.
1311 __ movq(RAX, Address(RSP, + 1 * kWordSize)); // String object. 1459 __ movq(RAX, Address(RSP, + 1 * kWordSize)); // String object.
1312 __ movq(RAX, FieldAddress(RAX, String::length_offset())); 1460 __ movq(RAX, FieldAddress(RAX, String::length_offset()));
1313 __ cmpq(RAX, Immediate(Smi::RawValue(0))); 1461 __ cmpq(RAX, Immediate(Smi::RawValue(0)));
1314 __ j(EQUAL, &is_true, Assembler::kNearJump); 1462 __ j(EQUAL, &is_true, Assembler::kNearJump);
1315 __ LoadObject(RAX, Bool::False(), PP); 1463 __ LoadObject(RAX, Bool::False(), PP);
1316 __ ret(); 1464 __ ret();
1317 __ Bind(&is_true); 1465 __ Bind(&is_true);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 // Set return value to Isolate::current_tag_. 1799 // Set return value to Isolate::current_tag_.
1652 __ movq(RAX, Address(RBX, Isolate::current_tag_offset())); 1800 __ movq(RAX, Address(RBX, Isolate::current_tag_offset()));
1653 __ ret(); 1801 __ ret();
1654 } 1802 }
1655 1803
1656 #undef __ 1804 #undef __
1657 1805
1658 } // namespace dart 1806 } // namespace dart
1659 1807
1660 #endif // defined TARGET_ARCH_X64 1808 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_mips.cc ('k') | runtime/vm/method_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698