| 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 | 20 |
| 21 #define __ assembler-> | 21 #define __ assembler-> |
| 22 | 22 |
| 23 void Intrinsifier::List_Allocate(Assembler* assembler) { | |
| 24 const intptr_t kTypeArgumentsOffset = 1 * kWordSize; | |
| 25 const intptr_t kArrayLengthOffset = 0 * kWordSize; | |
| 26 Label fall_through; | |
| 27 | |
| 28 // Compute the size to be allocated, it is based on the array length | |
| 29 // and is computed as: | |
| 30 // RoundedAllocationSize((array_length * kwordSize) + sizeof(RawArray)). | |
| 31 __ lw(T3, Address(SP, kArrayLengthOffset)); // Array length. | |
| 32 | |
| 33 // Check that length is a positive Smi. | |
| 34 __ andi(CMPRES1, T3, Immediate(kSmiTagMask)); | |
| 35 __ bne(CMPRES1, ZR, &fall_through); | |
| 36 __ bltz(T3, &fall_through); | |
| 37 | |
| 38 // Check for maximum allowed length. | |
| 39 const intptr_t max_len = | |
| 40 reinterpret_cast<int32_t>(Smi::New(Array::kMaxElements)); | |
| 41 __ BranchUnsignedGreater(T3, max_len, &fall_through); | |
| 42 | |
| 43 const intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1; | |
| 44 __ LoadImmediate(T2, fixed_size); | |
| 45 __ sll(T3, T3, 1); // T3 is a Smi. | |
| 46 __ addu(T2, T2, T3); | |
| 47 ASSERT(kSmiTagShift == 1); | |
| 48 __ LoadImmediate(T3, ~(kObjectAlignment - 1)); | |
| 49 __ and_(T2, T2, T3); | |
| 50 | |
| 51 // T2: Allocation size. | |
| 52 | |
| 53 Isolate* isolate = Isolate::Current(); | |
| 54 Heap* heap = isolate->heap(); | |
| 55 | |
| 56 __ LoadImmediate(T3, heap->TopAddress()); | |
| 57 __ lw(T0, Address(T3, 0)); // Potential new object start. | |
| 58 | |
| 59 __ AdduDetectOverflow(T1, T0, T2, CMPRES1); // Potential next object start. | |
| 60 __ bltz(CMPRES1, &fall_through); // CMPRES1 < 0 on overflow. | |
| 61 | |
| 62 // Check if the allocation fits into the remaining space. | |
| 63 // T0: potential new object start. | |
| 64 // T1: potential next object start. | |
| 65 // T2: allocation size. | |
| 66 __ LoadImmediate(T4, heap->TopAddress()); | |
| 67 __ lw(T4, Address(T4, 0)); | |
| 68 __ BranchUnsignedGreaterEqual(T1, T4, &fall_through); | |
| 69 | |
| 70 // Successfully allocated the object(s), now update top to point to | |
| 71 // next object start and initialize the object. | |
| 72 __ sw(T1, Address(T3, 0)); | |
| 73 __ addiu(T0, T0, Immediate(kHeapObjectTag)); | |
| 74 __ UpdateAllocationStatsWithSize(kArrayCid, T2, T4); | |
| 75 | |
| 76 // Initialize the tags. | |
| 77 // T0: new object start as a tagged pointer. | |
| 78 // T1: new object end address. | |
| 79 // T2: allocation size. | |
| 80 { | |
| 81 Label overflow, done; | |
| 82 const intptr_t shift = RawObject::kSizeTagPos - kObjectAlignmentLog2; | |
| 83 const Class& cls = Class::Handle(isolate->object_store()->array_class()); | |
| 84 | |
| 85 __ BranchUnsignedGreater(T2, RawObject::SizeTag::kMaxSizeTag, &overflow); | |
| 86 __ b(&done); | |
| 87 __ delay_slot()->sll(T2, T2, shift); | |
| 88 __ Bind(&overflow); | |
| 89 __ mov(T2, ZR); | |
| 90 __ Bind(&done); | |
| 91 | |
| 92 // Get the class index and insert it into the tags. | |
| 93 // T2: size and bit tags. | |
| 94 __ LoadImmediate(TMP, RawObject::ClassIdTag::encode(cls.id())); | |
| 95 __ or_(T2, T2, TMP); | |
| 96 __ sw(T2, FieldAddress(T0, Array::tags_offset())); // Store tags. | |
| 97 } | |
| 98 | |
| 99 // T0: new object start as a tagged pointer. | |
| 100 // T1: new object end address. | |
| 101 // Store the type argument field. | |
| 102 __ lw(T2, Address(SP, kTypeArgumentsOffset)); // Type argument. | |
| 103 __ StoreIntoObjectNoBarrier(T0, | |
| 104 FieldAddress(T0, Array::type_arguments_offset()), | |
| 105 T2); | |
| 106 | |
| 107 // Set the length field. | |
| 108 __ lw(T2, Address(SP, kArrayLengthOffset)); // Array Length. | |
| 109 __ StoreIntoObjectNoBarrier(T0, | |
| 110 FieldAddress(T0, Array::length_offset()), | |
| 111 T2); | |
| 112 | |
| 113 __ LoadImmediate(T7, reinterpret_cast<int32_t>(Object::null())); | |
| 114 // Initialize all array elements to raw_null. | |
| 115 // T0: new object start as a tagged pointer. | |
| 116 // T1: new object end address. | |
| 117 // T2: iterator which initially points to the start of the variable | |
| 118 // data area to be initialized. | |
| 119 // T7: null | |
| 120 __ AddImmediate(T2, T0, sizeof(RawArray) - kHeapObjectTag); | |
| 121 | |
| 122 Label done; | |
| 123 Label init_loop; | |
| 124 __ Bind(&init_loop); | |
| 125 __ BranchUnsignedGreaterEqual(T2, T1, &done); | |
| 126 __ sw(T7, Address(T2, 0)); | |
| 127 __ b(&init_loop); | |
| 128 __ delay_slot()->addiu(T2, T2, Immediate(kWordSize)); | |
| 129 __ Bind(&done); | |
| 130 | |
| 131 __ Ret(); // Returns the newly allocated object in V0. | |
| 132 __ delay_slot()->mov(V0, T0); | |
| 133 __ Bind(&fall_through); | |
| 134 } | |
| 135 | |
| 136 | 23 |
| 137 void Intrinsifier::Array_getLength(Assembler* assembler) { | 24 void Intrinsifier::Array_getLength(Assembler* assembler) { |
| 138 __ lw(V0, Address(SP, 0 * kWordSize)); | 25 __ lw(V0, Address(SP, 0 * kWordSize)); |
| 139 __ Ret(); | 26 __ Ret(); |
| 140 __ delay_slot()->lw(V0, FieldAddress(V0, Array::length_offset())); | 27 __ delay_slot()->lw(V0, FieldAddress(V0, Array::length_offset())); |
| 141 } | 28 } |
| 142 | 29 |
| 143 | 30 |
| 144 void Intrinsifier::ImmutableList_getLength(Assembler* assembler) { | 31 void Intrinsifier::ImmutableList_getLength(Assembler* assembler) { |
| 145 return Array_getLength(assembler); | 32 return Array_getLength(assembler); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 static int GetScaleFactor(intptr_t size) { | 440 static int GetScaleFactor(intptr_t size) { |
| 554 switch (size) { | 441 switch (size) { |
| 555 case 1: return 0; | 442 case 1: return 0; |
| 556 case 2: return 1; | 443 case 2: return 1; |
| 557 case 4: return 2; | 444 case 4: return 2; |
| 558 case 8: return 3; | 445 case 8: return 3; |
| 559 case 16: return 4; | 446 case 16: return 4; |
| 560 } | 447 } |
| 561 UNREACHABLE(); | 448 UNREACHABLE(); |
| 562 return -1; | 449 return -1; |
| 563 }; | 450 } |
| 564 | 451 |
| 565 | 452 |
| 566 #define TYPED_DATA_ALLOCATOR(clazz) \ | 453 #define TYPED_DATA_ALLOCATOR(clazz) \ |
| 567 void Intrinsifier::TypedData_##clazz##_new(Assembler* assembler) { \ | 454 void Intrinsifier::TypedData_##clazz##_new(Assembler* assembler) { \ |
| 568 intptr_t size = TypedData::ElementSizeInBytes(kTypedData##clazz##Cid); \ | 455 intptr_t size = TypedData::ElementSizeInBytes(kTypedData##clazz##Cid); \ |
| 569 intptr_t max_len = TypedData::MaxElements(kTypedData##clazz##Cid); \ | 456 intptr_t max_len = TypedData::MaxElements(kTypedData##clazz##Cid); \ |
| 570 int shift = GetScaleFactor(size); \ | 457 int shift = GetScaleFactor(size); \ |
| 571 TYPED_ARRAY_ALLOCATION(TypedData, kTypedData##clazz##Cid, max_len, shift); \ | 458 TYPED_ARRAY_ALLOCATION(TypedData, kTypedData##clazz##Cid, max_len, shift); \ |
| 572 } \ | 459 } \ |
| 573 void Intrinsifier::TypedData_##clazz##_factory(Assembler* assembler) { \ | 460 void Intrinsifier::TypedData_##clazz##_factory(Assembler* assembler) { \ |
| (...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1814 Isolate* isolate = Isolate::Current(); | 1701 Isolate* isolate = Isolate::Current(); |
| 1815 __ LoadImmediate(V0, reinterpret_cast<uword>(isolate)); | 1702 __ LoadImmediate(V0, reinterpret_cast<uword>(isolate)); |
| 1816 // Set return value. | 1703 // Set return value. |
| 1817 __ Ret(); | 1704 __ Ret(); |
| 1818 __ delay_slot()->lw(V0, Address(V0, Isolate::current_tag_offset())); | 1705 __ delay_slot()->lw(V0, Address(V0, Isolate::current_tag_offset())); |
| 1819 } | 1706 } |
| 1820 | 1707 |
| 1821 } // namespace dart | 1708 } // namespace dart |
| 1822 | 1709 |
| 1823 #endif // defined TARGET_ARCH_MIPS | 1710 #endif // defined TARGET_ARCH_MIPS |
| OLD | NEW |