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

Side by Side Diff: runtime/vm/intrinsifier_mips.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_ia32.cc ('k') | runtime/vm/intrinsifier_x64.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_MIPS. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS.
6 #if defined(TARGET_ARCH_MIPS) 6 #if defined(TARGET_ARCH_MIPS)
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
21 #define __ assembler-> 21 #define __ assembler->
22 22
23 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 __ lw(A0, Address(SP, kTypeArgumentsOffset));
30 __ lw(A1, 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 __ mov(T3, A1); // Array length.
36
37 // Check that length is a positive Smi.
38 __ andi(CMPRES1, T3, Immediate(kSmiTagMask));
39 __ bne(CMPRES1, ZR, &fall_through);
40 __ bltz(T3, &fall_through);
41
42 // Check for maximum allowed length.
43 const intptr_t max_len =
44 reinterpret_cast<int32_t>(Smi::New(Array::kMaxElements));
45 __ BranchUnsignedGreater(T3, max_len, &fall_through);
46
47 const intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1;
48 __ LoadImmediate(T2, fixed_size);
49 __ sll(T3, T3, 1); // T3 is a Smi.
50 __ addu(T2, T2, T3);
51 ASSERT(kSmiTagShift == 1);
52 __ LoadImmediate(T3, ~(kObjectAlignment - 1));
53 __ and_(T2, T2, T3);
54
55 // T2: Allocation size.
56
57 Isolate* isolate = Isolate::Current();
58 Heap* heap = isolate->heap();
59
60 __ LoadImmediate(T3, heap->TopAddress());
61 __ lw(T0, Address(T3, 0)); // Potential new object start.
62
63 __ AdduDetectOverflow(T1, T0, T2, CMPRES1); // Potential next object start.
64 __ bltz(CMPRES1, &fall_through); // CMPRES1 < 0 on overflow.
65
66 // Check if the allocation fits into the remaining space.
67 // T0: potential new object start.
68 // T1: potential next object start.
69 // T2: allocation size.
70 __ LoadImmediate(T4, heap->EndAddress());
71 __ lw(T4, Address(T4, 0));
72 __ BranchUnsignedGreaterEqual(T1, T4, &fall_through);
73
74 // Successfully allocated the object(s), now update top to point to
75 // next object start and initialize the object.
76 __ sw(T1, Address(T3, 0));
77 __ addiu(T0, T0, Immediate(kHeapObjectTag));
78 __ UpdateAllocationStatsWithSize(kArrayCid, T2, T4);
79
80 // Initialize the tags.
81 // T0: new object start as a tagged pointer.
82 // T1: new object end address.
83 // T2: allocation size.
84 {
85 Label overflow, done;
86 const intptr_t shift = RawObject::kSizeTagPos - kObjectAlignmentLog2;
87 const Class& cls = Class::Handle(isolate->object_store()->array_class());
88
89 __ BranchUnsignedGreater(T2, RawObject::SizeTag::kMaxSizeTag, &overflow);
90 __ b(&done);
91 __ delay_slot()->sll(T2, T2, shift);
92 __ Bind(&overflow);
93 __ mov(T2, ZR);
94 __ Bind(&done);
95
96 // Get the class index and insert it into the tags.
97 // T2: size and bit tags.
98 __ LoadImmediate(TMP, RawObject::ClassIdTag::encode(cls.id()));
99 __ or_(T2, T2, TMP);
100 __ sw(T2, FieldAddress(T0, Array::tags_offset())); // Store tags.
101 }
102
103 // T0: new object start as a tagged pointer.
104 // T1: new object end address.
105 // Store the type argument field.
106 __ StoreIntoObjectNoBarrier(T0,
107 FieldAddress(T0, Array::type_arguments_offset()),
108 A0);
109
110 // Set the length field.
111 __ StoreIntoObjectNoBarrier(T0,
112 FieldAddress(T0, Array::length_offset()),
113 A1);
114
115 __ LoadImmediate(T7, reinterpret_cast<int32_t>(Object::null()));
116 // Initialize all array elements to raw_null.
117 // T0: new object start as a tagged pointer.
118 // T1: new object end address.
119 // T2: iterator which initially points to the start of the variable
120 // data area to be initialized.
121 // T7: null.
122 __ AddImmediate(T2, T0, sizeof(RawArray) - kHeapObjectTag);
123
124 Label done;
125 Label init_loop;
126 __ Bind(&init_loop);
127 __ BranchUnsignedGreaterEqual(T2, T1, &done);
128 __ sw(T7, Address(T2, 0));
129 __ b(&init_loop);
130 __ delay_slot()->addiu(T2, T2, Immediate(kWordSize));
131 __ Bind(&done);
132
133 __ Ret(); // Returns the newly allocated object in V0.
134 __ delay_slot()->mov(V0, T0);
135 __ Bind(&fall_through);
136 }
137
138
24 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { 139 void Intrinsifier::ObjectArrayLength(Assembler* assembler) {
25 __ lw(V0, Address(SP, 0 * kWordSize)); 140 __ lw(V0, Address(SP, 0 * kWordSize));
26 __ Ret(); 141 __ Ret();
27 __ delay_slot()->lw(V0, FieldAddress(V0, Array::length_offset())); 142 __ delay_slot()->lw(V0, FieldAddress(V0, Array::length_offset()));
28 } 143 }
29 144
30 145
31 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { 146 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) {
32 ObjectArrayLength(assembler); 147 ObjectArrayLength(assembler);
33 } 148 }
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 __ SmiUntag(T1); 1547 __ SmiUntag(T1);
1433 __ addu(T2, T0, T1); 1548 __ addu(T2, T0, T1);
1434 __ lbu(V0, FieldAddress(T2, OneByteString::data_offset())); 1549 __ lbu(V0, FieldAddress(T2, OneByteString::data_offset()));
1435 __ Ret(); 1550 __ Ret();
1436 __ delay_slot()->SmiTag(V0); 1551 __ delay_slot()->SmiTag(V0);
1437 1552
1438 __ Bind(&try_two_byte_string); 1553 __ Bind(&try_two_byte_string);
1439 __ BranchNotEqual(CMPRES1, kTwoByteStringCid, &fall_through); 1554 __ BranchNotEqual(CMPRES1, kTwoByteStringCid, &fall_through);
1440 ASSERT(kSmiTagShift == 1); 1555 ASSERT(kSmiTagShift == 1);
1441 __ addu(T2, T0, T1); 1556 __ addu(T2, T0, T1);
1442 __ lhu(V0, FieldAddress(T2, OneByteString::data_offset())); 1557 __ lhu(V0, FieldAddress(T2, TwoByteString::data_offset()));
1443 __ Ret(); 1558 __ Ret();
1444 __ delay_slot()->SmiTag(V0); 1559 __ delay_slot()->SmiTag(V0);
1445 1560
1446 __ Bind(&fall_through); 1561 __ Bind(&fall_through);
1447 } 1562 }
1448 1563
1449 1564
1565 void Intrinsifier::StringBase_charAt(Assembler* assembler) {
1566 Label fall_through, try_two_byte_string;
1567
1568 __ lw(T1, Address(SP, 0 * kWordSize)); // Index.
1569 __ lw(T0, Address(SP, 1 * kWordSize)); // String.
1570
1571 // Checks.
1572 __ andi(CMPRES1, T1, Immediate(kSmiTagMask));
1573 __ bne(T1, ZR, &fall_through); // Index is not a Smi.
1574 __ lw(T2, FieldAddress(T0, String::length_offset())); // Range check.
1575 // Runtime throws exception.
1576 __ BranchUnsignedGreaterEqual(T1, T2, &fall_through);
1577 __ LoadClassId(CMPRES1, T0); // Class ID check.
1578 __ BranchNotEqual(CMPRES1, kOneByteStringCid, &try_two_byte_string);
1579
1580 // Grab byte and return.
1581 __ SmiUntag(T1);
1582 __ addu(T2, T0, T1);
1583 __ lbu(T2, FieldAddress(T2, OneByteString::data_offset()));
1584 __ BranchUnsignedGreaterEqual(
1585 T2, Symbols::kNumberOfOneCharCodeSymbols, &fall_through);
1586 __ LoadImmediate(
1587 V0, reinterpret_cast<uword>(Symbols::PredefinedAddress()));
1588 __ AddImmediate(V0, Symbols::kNullCharCodeSymbolOffset * kWordSize);
1589 __ sll(T2, T2, 2);
1590 __ addu(T2, T2, V0);
1591 __ Ret();
1592 __ delay_slot()->lw(V0, Address(T2));
1593
1594 __ Bind(&try_two_byte_string);
1595 __ BranchNotEqual(CMPRES1, kTwoByteStringCid, &fall_through);
1596 ASSERT(kSmiTagShift == 1);
1597 __ addu(T2, T0, T1);
1598 __ lhu(T2, FieldAddress(T2, TwoByteString::data_offset()));
1599 __ BranchUnsignedGreaterEqual(
1600 T2, Symbols::kNumberOfOneCharCodeSymbols, &fall_through);
1601 __ LoadImmediate(V0,
1602 reinterpret_cast<uword>(Symbols::PredefinedAddress()));
1603 __ AddImmediate(V0, Symbols::kNullCharCodeSymbolOffset * kWordSize);
1604 __ sll(T2, T2, 2);
1605 __ addu(T2, T2, V0);
1606 __ Ret();
1607 __ delay_slot()->lw(V0, Address(T2));
1608
1609 __ Bind(&fall_through);
1610 }
1611
1612
1450 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) { 1613 void Intrinsifier::StringBaseIsEmpty(Assembler* assembler) {
1451 Label is_true; 1614 Label is_true;
1452 1615
1453 __ lw(T0, Address(SP, 0 * kWordSize)); 1616 __ lw(T0, Address(SP, 0 * kWordSize));
1454 __ lw(T0, FieldAddress(T0, String::length_offset())); 1617 __ lw(T0, FieldAddress(T0, String::length_offset()));
1455 1618
1456 __ beq(T0, ZR, &is_true); 1619 __ beq(T0, ZR, &is_true);
1457 __ LoadObject(V0, Bool::False()); 1620 __ LoadObject(V0, Bool::False());
1458 __ Ret(); 1621 __ Ret();
1459 __ Bind(&is_true); 1622 __ Bind(&is_true);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 Isolate* isolate = Isolate::Current(); 1949 Isolate* isolate = Isolate::Current();
1787 __ LoadImmediate(V0, reinterpret_cast<uword>(isolate)); 1950 __ LoadImmediate(V0, reinterpret_cast<uword>(isolate));
1788 // Set return value. 1951 // Set return value.
1789 __ Ret(); 1952 __ Ret();
1790 __ delay_slot()->lw(V0, Address(V0, Isolate::current_tag_offset())); 1953 __ delay_slot()->lw(V0, Address(V0, Isolate::current_tag_offset()));
1791 } 1954 }
1792 1955
1793 } // namespace dart 1956 } // namespace dart
1794 1957
1795 #endif // defined TARGET_ARCH_MIPS 1958 #endif // defined TARGET_ARCH_MIPS
OLDNEW
« no previous file with comments | « runtime/vm/intrinsifier_ia32.cc ('k') | runtime/vm/intrinsifier_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698