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

Side by Side Diff: runtime/vm/intrinsifier_arm.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 | « no previous file | runtime/vm/intrinsifier_arm64.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_ARM. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM.
6 #if defined(TARGET_ARCH_ARM) 6 #if defined(TARGET_ARCH_ARM)
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/cpu.h" 11 #include "vm/cpu.h"
12 #include "vm/flow_graph_compiler.h" 12 #include "vm/flow_graph_compiler.h"
13 #include "vm/object.h" 13 #include "vm/object.h"
14 #include "vm/object_store.h" 14 #include "vm/object_store.h"
15 #include "vm/symbols.h" 15 #include "vm/symbols.h"
16 16
17 namespace dart { 17 namespace dart {
18 18
19 DECLARE_FLAG(bool, enable_type_checks); 19 DECLARE_FLAG(bool, enable_type_checks);
20 20
21 21
22 #define __ assembler-> 22 #define __ assembler->
23 23
24 24
25 void Intrinsifier::ObjectArrayAllocate(Assembler* assembler) {
26 Label fall_through;
27 const intptr_t kTypeArgumentsOffset = 1 * kWordSize;
28 const intptr_t kLengthOffset = 0 * kWordSize;
29
30 __ ldr(R1, Address(SP, kTypeArgumentsOffset));
31 __ ldr(R2, Address(SP, kLengthOffset));
32
33 // Compute the size to be allocated, it is based on the array length
34 // and is computed as:
35 // RoundedAllocationSize((array_length * kwordSize) + sizeof(RawArray)).
36 __ MoveRegister(R3, R2); // Array length.
37
38 // Check that length is a positive Smi.
39 __ tst(R3, Operand(kSmiTagMask));
40 __ b(&fall_through, NE);
41 __ cmp(R3, Operand(0));
42 __ b(&fall_through, LT);
43
44 // Check for maximum allowed length.
45 const intptr_t max_len =
46 reinterpret_cast<int32_t>(Smi::New(Array::kMaxElements));
47 __ CompareImmediate(R3, max_len);
48 __ b(&fall_through, GT);
49
50 const intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1;
51 __ LoadImmediate(R8, fixed_size);
52 __ add(R8, R8, Operand(R3, LSL, 1)); // R3 is a Smi.
53 ASSERT(kSmiTagShift == 1);
54 __ bic(R8, R8, Operand(kObjectAlignment - 1));
55
56 // R8: Allocation size.
57
58 Isolate* isolate = Isolate::Current();
59 Heap* heap = isolate->heap();
60
61 __ LoadImmediate(R6, heap->TopAddress());
62 __ ldr(R0, Address(R6, 0)); // Potential new object start.
63 __ adds(R7, R0, Operand(R8)); // Potential next object start.
64 __ b(&fall_through, VS);
65
66 // Check if the allocation fits into the remaining space.
67 // R0: potential new object start.
68 // R7: potential next object start.
69 // R8: allocation size.
70 __ LoadImmediate(R3, heap->EndAddress());
71 __ ldr(R3, Address(R3, 0));
72 __ cmp(R7, Operand(R3));
73 __ b(&fall_through, CS);
74
75 // Successfully allocated the object(s), now update top to point to
76 // next object start and initialize the object.
77 __ str(R7, Address(R6, 0));
78 __ add(R0, R0, Operand(kHeapObjectTag));
79 __ UpdateAllocationStatsWithSize(kArrayCid, R8, R4);
80
81 // Initialize the tags.
82 // R0: new object start as a tagged pointer.
83 // R7: new object end address.
84 // R8: allocation size.
85 {
86 const intptr_t shift = RawObject::kSizeTagPos - kObjectAlignmentLog2;
87 const Class& cls = Class::Handle(isolate->object_store()->array_class());
88
89 __ CompareImmediate(R8, RawObject::SizeTag::kMaxSizeTag);
90 __ mov(R8, Operand(R8, LSL, shift), LS);
91 __ mov(R8, Operand(0), HI);
92
93 // Get the class index and insert it into the tags.
94 // R8: size and bit tags.
95 __ LoadImmediate(TMP, RawObject::ClassIdTag::encode(cls.id()));
96 __ orr(R8, R8, Operand(TMP));
97 __ str(R8, FieldAddress(R0, Array::tags_offset())); // Store tags.
98 }
99
100 // R0: new object start as a tagged pointer.
101 // R7: new object end address.
102 // Store the type argument field.
103 __ StoreIntoObjectNoBarrier(R0,
104 FieldAddress(R0, Array::type_arguments_offset()),
105 R1);
106
107 // Set the length field.
108 __ StoreIntoObjectNoBarrier(R0,
109 FieldAddress(R0, Array::length_offset()),
110 R2);
111
112 // Initialize all array elements to raw_null.
113 // R0: new object start as a tagged pointer.
114 // R7: new object end address.
115 // R8: iterator which initially points to the start of the variable
116 // data area to be initialized.
117 // R3: null
118 __ LoadImmediate(R3, reinterpret_cast<intptr_t>(Object::null()));
119 __ AddImmediate(R8, R0, sizeof(RawArray) - kHeapObjectTag);
120
121 Label init_loop;
122 __ Bind(&init_loop);
123 __ cmp(R8, Operand(R7));
124 __ str(R3, Address(R8, 0), CC);
125 __ AddImmediate(R8, kWordSize, CC);
126 __ b(&init_loop, CC);
127
128 __ Ret(); // Returns the newly allocated object in R0.
129 // Unable to allocate the array using the fast inline code, just call
130 // into the runtime.
131 __ Bind(&fall_through);
132 }
133
134
25 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { 135 void Intrinsifier::ObjectArrayLength(Assembler* assembler) {
26 __ ldr(R0, Address(SP, 0 * kWordSize)); 136 __ ldr(R0, Address(SP, 0 * kWordSize));
27 __ ldr(R0, FieldAddress(R0, Array::length_offset())); 137 __ ldr(R0, FieldAddress(R0, Array::length_offset()));
28 __ Ret(); 138 __ Ret();
29 } 139 }
30 140
31 141
32 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { 142 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) {
33 ObjectArrayLength(assembler); 143 ObjectArrayLength(assembler);
34 } 144 }
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 ASSERT(kSmiTagShift == 1); 1514 ASSERT(kSmiTagShift == 1);
1405 __ AddImmediate(R0, TwoByteString::data_offset() - kHeapObjectTag); 1515 __ AddImmediate(R0, TwoByteString::data_offset() - kHeapObjectTag);
1406 __ ldrh(R0, Address(R0, R1)); 1516 __ ldrh(R0, Address(R0, R1));
1407 __ SmiTag(R0); 1517 __ SmiTag(R0);
1408 __ Ret(); 1518 __ Ret();
1409 1519
1410 __ Bind(&fall_through); 1520 __ Bind(&fall_through);
1411 } 1521 }
1412 1522
1413 1523
1524 void Intrinsifier::StringBase_charAt(Assembler* assembler) {
1525 Label fall_through, try_two_byte_string;
1526
1527 __ ldr(R1, Address(SP, 0 * kWordSize)); // Index.
1528 __ ldr(R0, Address(SP, 1 * kWordSize)); // String.
1529 __ tst(R1, Operand(kSmiTagMask));
1530 __ b(&fall_through, NE); // Index is not a Smi.
1531 // Range check.
1532 __ ldr(R2, FieldAddress(R0, String::length_offset()));
1533 __ cmp(R1, Operand(R2));
1534 __ b(&fall_through, CS); // Runtime throws exception.
1535
1536 __ CompareClassId(R0, kOneByteStringCid, R3);
1537 __ b(&try_two_byte_string, NE);
1538 __ SmiUntag(R1);
1539 __ AddImmediate(R0, OneByteString::data_offset() - kHeapObjectTag);
1540 __ ldrb(R1, Address(R0, R1));
1541 __ CompareImmediate(R1, Symbols::kNumberOfOneCharCodeSymbols);
1542 __ b(&fall_through, GE);
1543 __ LoadImmediate(R0,
1544 reinterpret_cast<uword>(Symbols::PredefinedAddress()));
1545 __ AddImmediate(R0, Symbols::kNullCharCodeSymbolOffset * kWordSize);
1546 __ ldr(R0, Address(R0, R1, LSL, 2));
1547 __ Ret();
1548
1549 __ Bind(&try_two_byte_string);
1550 __ CompareClassId(R0, kTwoByteStringCid, R3);
1551 __ b(&fall_through, NE);
1552 ASSERT(kSmiTagShift == 1);
1553 __ AddImmediate(R0, TwoByteString::data_offset() - kHeapObjectTag);
1554 __ ldrh(R1, Address(R0, R1));
1555 __ CompareImmediate(R1, Symbols::kNumberOfOneCharCodeSymbols);
1556 __ b(&fall_through, GE);
1557 __ LoadImmediate(R0,
1558 reinterpret_cast<uword>(Symbols::PredefinedAddress()));
1559 __ AddImmediate(R0, Symbols::kNullCharCodeSymbolOffset * kWordSize);
1560 __ ldr(R0, Address(R0, R1, LSL, 2));
1561 __ Ret();
1562
1563 __ Bind(&fall_through);
1564 }
1565
1566
1414 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) { 1567 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) {
1415 __ ldr(R0, Address(SP, 0 * kWordSize)); 1568 __ ldr(R0, Address(SP, 0 * kWordSize));
1416 __ ldr(R0, FieldAddress(R0, String::length_offset())); 1569 __ ldr(R0, FieldAddress(R0, String::length_offset()));
1417 __ cmp(R0, Operand(Smi::RawValue(0))); 1570 __ cmp(R0, Operand(Smi::RawValue(0)));
1418 __ LoadObject(R0, Bool::True(), EQ); 1571 __ LoadObject(R0, Bool::True(), EQ);
1419 __ LoadObject(R0, Bool::False(), NE); 1572 __ LoadObject(R0, Bool::False(), NE);
1420 __ Ret(); 1573 __ Ret();
1421 } 1574 }
1422 1575
1423 1576
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 Isolate* isolate = Isolate::Current(); 1902 Isolate* isolate = Isolate::Current();
1750 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate)); 1903 __ LoadImmediate(R1, reinterpret_cast<uword>(isolate));
1751 // Set return value to Isolate::current_tag_. 1904 // Set return value to Isolate::current_tag_.
1752 __ ldr(R0, Address(R1, Isolate::current_tag_offset())); 1905 __ ldr(R0, Address(R1, Isolate::current_tag_offset()));
1753 __ Ret(); 1906 __ Ret();
1754 } 1907 }
1755 1908
1756 } // namespace dart 1909 } // namespace dart
1757 1910
1758 #endif // defined TARGET_ARCH_ARM 1911 #endif // defined TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/intrinsifier_arm64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698