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

Side by Side Diff: runtime/vm/intrinsifier_arm64.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_arm.cc ('k') | runtime/vm/intrinsifier_ia32.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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_ARM64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64.
6 #if defined(TARGET_ARCH_ARM64) 6 #if defined(TARGET_ARCH_ARM64)
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/object.h" 12 #include "vm/object.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
20 #define __ assembler-> 21 #define __ assembler->
21 22
22 23
24 void Intrinsifier::ObjectArrayAllocate(Assembler* assembler) {
25 Label fall_through;
26 const intptr_t kTypeArgumentsOffset = 1 * kWordSize;
27 const intptr_t kLengthOffset = 0 * kWordSize;
28
29 __ ldr(R1, Address(SP, kTypeArgumentsOffset));
30 __ ldr(R2, Address(SP, kLengthOffset));
31
32 // Compute the size to be allocated, it is based on the array length
33 // and is computed as:
34 // RoundedAllocationSize((array_length * kwordSize) + sizeof(RawArray)).
35 // Assert that length is a Smi.
36 __ tsti(R2, kSmiTagMask);
37 __ b(&fall_through, NE);
38
39 __ cmp(R2, Operand(0));
40 __ b(&fall_through, LT);
41 __ LoadFieldFromOffset(R8, CTX, Context::isolate_offset(), kNoPP);
42 __ LoadFromOffset(R8, R8, Isolate::heap_offset(), kNoPP);
43 __ LoadFromOffset(R8, R8, Heap::new_space_offset(), kNoPP);
44
45 // Calculate and align allocation size.
46 // Load new object start and calculate next object start.
47 // R1: array element type.
48 // R2: array length as Smi.
49 // R8: points to new space object.
50 __ LoadFromOffset(R0, R8, Scavenger::top_offset(), kNoPP);
51 intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1;
52 __ LoadImmediate(R3, fixed_size, kNoPP);
53 __ add(R3, R3, Operand(R2, LSL, 2)); // R2 is Smi.
54 ASSERT(kSmiTagShift == 1);
55 __ andi(R3, R3, ~(kObjectAlignment - 1));
56 __ adds(R7, R3, Operand(R0));
57 __ b(&fall_through, VS);
58
59 // Check if the allocation fits into the remaining space.
60 // R0: potential new object start.
61 // R1: array element type.
62 // R2: array length as Smi.
63 // R3: array size.
64 // R7: potential next object start.
65 // R8: points to new space object.
66 __ LoadFromOffset(TMP, R8, Scavenger::end_offset(), kNoPP);
67 __ CompareRegisters(R7, TMP);
68 __ b(&fall_through, CS); // Branch if unsigned higher or equal.
69
70 // Successfully allocated the object(s), now update top to point to
71 // next object start and initialize the object.
72 // R0: potential new object start.
73 // R3: array size.
74 // R7: potential next object start.
75 // R8: Points to new space object.
76 __ StoreToOffset(R7, R8, Scavenger::top_offset(), kNoPP);
77 __ add(R0, R0, Operand(kHeapObjectTag));
78 __ UpdateAllocationStatsWithSize(kArrayCid, R3, kNoPP);
79
80 // R0: new object start as a tagged pointer.
81 // R1: array element type.
82 // R2: array length as Smi.
83 // R3: array size.
84 // R7: new object end address.
85
86 // Store the type argument field.
87 __ StoreIntoObjectOffsetNoBarrier(
88 R0, Array::type_arguments_offset(), R1, PP);
89
90 // Set the length field.
91 __ StoreIntoObjectOffsetNoBarrier(R0, Array::length_offset(), R2, PP);
92
93 // Calculate the size tag.
94 // R0: new object start as a tagged pointer.
95 // R2: array length as Smi.
96 // R3: array size.
97 // R7: new object end address.
98 const intptr_t shift = RawObject::kSizeTagPos - kObjectAlignmentLog2;
99 __ CompareImmediate(R3, RawObject::SizeTag::kMaxSizeTag, kNoPP);
100 // If no size tag overflow, shift R1 left, else set R1 to zero.
101 __ Lsl(TMP, R3, shift);
102 __ csel(R1, TMP, R1, LS);
103 __ csel(R1, ZR, R1, HI);
104
105 // Get the class index and insert it into the tags.
106 __ LoadImmediate(TMP, RawObject::ClassIdTag::encode(kArrayCid), kNoPP);
107 __ orr(R1, R1, Operand(TMP));
108 __ StoreFieldToOffset(R1, R0, Array::tags_offset(), kNoPP);
109
110 // Initialize all array elements to raw_null.
111 // R0: new object start as a tagged pointer.
112 // R7: new object end address.
113 // R2: array length as Smi.
114 __ AddImmediate(R1, R0, Array::data_offset() - kHeapObjectTag, kNoPP);
115 // R1: iterator which initially points to the start of the variable
116 // data area to be initialized.
117 __ LoadObject(TMP, Object::null_object(), PP);
118 Label loop, done;
119 __ Bind(&loop);
120 // TODO(cshapiro): StoreIntoObjectNoBarrier
121 __ CompareRegisters(R1, R7);
122 __ b(&done, CS);
123 __ str(TMP, Address(R1)); // Store if unsigned lower.
124 __ AddImmediate(R1, R1, kWordSize, kNoPP);
125 __ b(&loop); // Loop until R1 == R7.
126 __ Bind(&done);
127
128 // Done allocating and initializing the array.
129 // R0: new object.
130 // R2: array length as Smi (preserved for the caller.)
131 __ ret();
132 __ Bind(&fall_through);
133 }
134
135
23 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { 136 void Intrinsifier::ObjectArrayLength(Assembler* assembler) {
24 __ ldr(R0, Address(SP, 0 * kWordSize)); 137 __ ldr(R0, Address(SP, 0 * kWordSize));
25 __ ldr(R0, FieldAddress(R0, Array::length_offset())); 138 __ ldr(R0, FieldAddress(R0, Array::length_offset()));
26 __ ret(); 139 __ ret();
27 } 140 }
28 141
29 142
30 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { 143 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) {
31 ObjectArrayLength(assembler); 144 ObjectArrayLength(assembler);
32 } 145 }
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 ASSERT(kSmiTagShift == 1); 1400 ASSERT(kSmiTagShift == 1);
1288 __ AddImmediate(R0, R0, TwoByteString::data_offset() - kHeapObjectTag, kNoPP); 1401 __ AddImmediate(R0, R0, TwoByteString::data_offset() - kHeapObjectTag, kNoPP);
1289 __ ldr(R0, Address(R0, R1), kUnsignedHalfword); 1402 __ ldr(R0, Address(R0, R1), kUnsignedHalfword);
1290 __ SmiTag(R0); 1403 __ SmiTag(R0);
1291 __ ret(); 1404 __ ret();
1292 1405
1293 __ Bind(&fall_through); 1406 __ Bind(&fall_through);
1294 } 1407 }
1295 1408
1296 1409
1410 void Intrinsifier::StringBase_charAt(Assembler* assembler) {
1411 Label fall_through, try_two_byte_string;
1412
1413 __ ldr(R1, Address(SP, 0 * kWordSize)); // Index.
1414 __ ldr(R0, Address(SP, 1 * kWordSize)); // String.
1415 __ tsti(R1, kSmiTagMask);
1416 __ b(&fall_through, NE); // Index is not a Smi.
1417 // Range check.
1418 __ ldr(R2, FieldAddress(R0, String::length_offset()));
1419 __ cmp(R1, Operand(R2));
1420 __ b(&fall_through, CS); // Runtime throws exception.
1421
1422 __ CompareClassId(R0, kOneByteStringCid, kNoPP);
1423 __ b(&try_two_byte_string, NE);
1424 __ SmiUntag(R1);
1425 __ AddImmediate(R0, R0, OneByteString::data_offset() - kHeapObjectTag, kNoPP);
1426 __ ldr(R1, Address(R0, R1), kUnsignedByte);
1427 __ CompareImmediate(R1, Symbols::kNumberOfOneCharCodeSymbols, kNoPP);
1428 __ b(&fall_through, GE);
1429 __ LoadImmediate(
1430 R0, reinterpret_cast<uword>(Symbols::PredefinedAddress()), kNoPP);
1431 __ AddImmediate(
1432 R0, R0, Symbols::kNullCharCodeSymbolOffset * kWordSize, kNoPP);
1433 __ ldr(R0, Address(R0, R1, UXTX, Address::Scaled));
1434 __ ret();
1435
1436 __ Bind(&try_two_byte_string);
1437 __ CompareClassId(R0, kTwoByteStringCid, kNoPP);
1438 __ b(&fall_through, NE);
1439 ASSERT(kSmiTagShift == 1);
1440 __ AddImmediate(R0, R0, TwoByteString::data_offset() - kHeapObjectTag, kNoPP);
1441 __ ldr(R1, Address(R0, R1), kUnsignedHalfword);
1442 __ CompareImmediate(R1, Symbols::kNumberOfOneCharCodeSymbols, kNoPP);
1443 __ b(&fall_through, GE);
1444 __ LoadImmediate(
1445 R0, reinterpret_cast<uword>(Symbols::PredefinedAddress()), kNoPP);
1446 __ AddImmediate(
1447 R0, R0, Symbols::kNullCharCodeSymbolOffset * kWordSize, kNoPP);
1448 __ ldr(R0, Address(R0, R1, UXTX, Address::Scaled));
1449 __ ret();
1450
1451 __ Bind(&fall_through);
1452 }
1453
1454
1297 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) { 1455 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) {
1298 __ ldr(R0, Address(SP, 0 * kWordSize)); 1456 __ ldr(R0, Address(SP, 0 * kWordSize));
1299 __ ldr(R0, FieldAddress(R0, String::length_offset())); 1457 __ ldr(R0, FieldAddress(R0, String::length_offset()));
1300 __ cmp(R0, Operand(Smi::RawValue(0))); 1458 __ cmp(R0, Operand(Smi::RawValue(0)));
1301 __ LoadObject(R0, Bool::True(), PP); 1459 __ LoadObject(R0, Bool::True(), PP);
1302 __ LoadObject(TMP, Bool::False(), PP); 1460 __ LoadObject(TMP, Bool::False(), PP);
1303 __ csel(R0, TMP, R0, NE); 1461 __ csel(R0, TMP, R0, NE);
1304 __ ret(); 1462 __ ret();
1305 } 1463 }
1306 1464
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 Isolate* isolate = Isolate::Current(); 1794 Isolate* isolate = Isolate::Current();
1637 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate), kNoPP); 1795 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate), kNoPP);
1638 // Set return value to Isolate::current_tag_. 1796 // Set return value to Isolate::current_tag_.
1639 __ ldr(R0, Address(R1, Isolate::current_tag_offset())); 1797 __ ldr(R0, Address(R1, Isolate::current_tag_offset()));
1640 __ ret(); 1798 __ ret();
1641 } 1799 }
1642 1800
1643 } // namespace dart 1801 } // namespace dart
1644 1802
1645 #endif // defined TARGET_ARCH_ARM64 1803 #endif // defined TARGET_ARCH_ARM64
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_arm.cc ('k') | runtime/vm/intrinsifier_ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698