| OLD | NEW |
| 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 | |
| 21 #define __ assembler-> | 20 #define __ assembler-> |
| 22 | 21 |
| 23 | 22 |
| 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 | |
| 139 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { | 23 void Intrinsifier::ObjectArrayLength(Assembler* assembler) { |
| 140 __ lw(V0, Address(SP, 0 * kWordSize)); | 24 __ lw(V0, Address(SP, 0 * kWordSize)); |
| 141 __ Ret(); | 25 __ Ret(); |
| 142 __ delay_slot()->lw(V0, FieldAddress(V0, Array::length_offset())); | 26 __ delay_slot()->lw(V0, FieldAddress(V0, Array::length_offset())); |
| 143 } | 27 } |
| 144 | 28 |
| 145 | 29 |
| 146 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { | 30 void Intrinsifier::ImmutableArrayLength(Assembler* assembler) { |
| 147 ObjectArrayLength(assembler); | 31 ObjectArrayLength(assembler); |
| 148 } | 32 } |
| (...skipping 1800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 Isolate* isolate = Isolate::Current(); | 1833 Isolate* isolate = Isolate::Current(); |
| 1950 __ LoadImmediate(V0, reinterpret_cast<uword>(isolate)); | 1834 __ LoadImmediate(V0, reinterpret_cast<uword>(isolate)); |
| 1951 // Set return value. | 1835 // Set return value. |
| 1952 __ Ret(); | 1836 __ Ret(); |
| 1953 __ delay_slot()->lw(V0, Address(V0, Isolate::current_tag_offset())); | 1837 __ delay_slot()->lw(V0, Address(V0, Isolate::current_tag_offset())); |
| 1954 } | 1838 } |
| 1955 | 1839 |
| 1956 } // namespace dart | 1840 } // namespace dart |
| 1957 | 1841 |
| 1958 #endif // defined TARGET_ARCH_MIPS | 1842 #endif // defined TARGET_ARCH_MIPS |
| OLD | NEW |