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

Side by Side Diff: runtime/vm/assembler_mips.cc

Issue 13228002: First two codegen tests passing on SIMMIPS (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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/assembler_mips.h ('k') | runtime/vm/code_generator_test.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" 5 #include "vm/globals.h"
6 #if defined(TARGET_ARCH_MIPS) 6 #if defined(TARGET_ARCH_MIPS)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 lui(rd, Immediate(offset_high)); 69 lui(rd, Immediate(offset_high));
70 addu(rd, rd, PP); 70 addu(rd, rd, PP);
71 lw(rd, Address(rd, offset_low)); 71 lw(rd, Address(rd, offset_low));
72 } else { 72 } else {
73 lw(rd, Address(PP, offset_low)); 73 lw(rd, Address(PP, offset_low));
74 } 74 }
75 } 75 }
76 } 76 }
77 77
78 78
79 void Assembler::LoadObject(Register rd, const Object& object) {
80 // Smi's and VM heap objects are never relocated; do not use object pool.
81 if (object.IsSmi()) {
82 LoadImmediate(rd, reinterpret_cast<int32_t>(object.raw()));
83 } else if (object.InVMHeap()) {
84 // Make sure that class CallPattern is able to decode this load immediate.
85 int32_t object_raw = reinterpret_cast<int32_t>(object.raw());
86 const uint16_t object_low = Utils::Low16Bits(object_raw);
87 const uint16_t object_high = Utils::High16Bits(object_raw);
88 lui(rd, Immediate(object_high));
89 ori(rd, rd, Immediate(object_low));
90 } else {
91 // Make sure that class CallPattern is able to decode this load from the
92 // object pool.
93 const int32_t offset =
94 Array::data_offset() + 4*AddObject(object) - kHeapObjectTag;
95 LoadWordFromPoolOffset(rd, offset);
96 }
97 }
98
99
79 int32_t Assembler::AddObject(const Object& obj) { 100 int32_t Assembler::AddObject(const Object& obj) {
80 ASSERT(obj.IsNotTemporaryScopedHandle()); 101 ASSERT(obj.IsNotTemporaryScopedHandle());
81 ASSERT(obj.IsOld()); 102 ASSERT(obj.IsOld());
82 if (object_pool_.IsNull()) { 103 if (object_pool_.IsNull()) {
83 // The object pool cannot be used in the vm isolate. 104 // The object pool cannot be used in the vm isolate.
84 ASSERT(Isolate::Current() != Dart::vm_isolate()); 105 ASSERT(Isolate::Current() != Dart::vm_isolate());
85 object_pool_ = GrowableObjectArray::New(Heap::kOld); 106 object_pool_ = GrowableObjectArray::New(Heap::kOld);
86 } 107 }
87 for (int i = 0; i < object_pool_.Length(); i++) { 108 for (int i = 0; i < object_pool_.Length(); i++) {
88 if (object_pool_.At(i) == obj.raw()) { 109 if (object_pool_.At(i) == obj.raw()) {
89 return i; 110 return i;
90 } 111 }
91 } 112 }
92 object_pool_.Add(obj, Heap::kOld); 113 object_pool_.Add(obj, Heap::kOld);
93 return object_pool_.Length() - 1; 114 return object_pool_.Length() - 1;
94 } 115 }
95 116
96 117
118 void Assembler::PushObject(const Object& object) {
119 LoadObject(TMP, object);
120 Push(TMP);
121 }
122
123
124 void Assembler::CompareObject(Register rd, Register rn, const Object& object) {
125 ASSERT(rn != TMP);
126 LoadObject(TMP, object);
127 subu(rd, rn, TMP);
128 }
129
130
131 void Assembler::GetPC(Register rd) {
132 Label next;
133
134 mov(TMP, RA); // Save the return address.
135 bal(&next); // Branch and link to the next instruction.
136
137 // This instruction is the return address for the bal, so rd will
138 // have the PC of this mov instruction.
139 Bind(&next);
140 mov(rd, RA);
141
142 mov(RA, TMP); // Restore the return address.
143 return;
144 }
145
146
147 // Pushes registers onto the stack starting with R31.
148 void Assembler::PushList(RegList regs) {
regis 2013/03/28 21:43:25 I am not sure why you need this, since it is reall
149 for (int i = kNumberOfCpuRegisters - 1; i >= 0; i--) {
150 if ((regs & (1 << i)) != 0) {
151 Push(static_cast<Register>(i));
152 }
153 }
154 }
155
156
157 // Pops from stack into registers starting with R30.
158 void Assembler::PopList(RegList regs) {
regis 2013/03/28 21:43:25 ditto
159 for (int i = 0; i < kNumberOfCpuRegisters; i++) {
160 if ((regs & (1 << i)) != 0) {
161 Pop(static_cast<Register>(i));
162 }
163 }
164 }
165
166
167 static int NumRegsBelowFP(RegList regs) {
regis 2013/03/28 21:43:25 I do not think you will need this either if you do
168 int count = 0;
169 for (int i = 0; i < FP; i++) {
170 if ((regs & (1 << i)) != 0) {
171 count++;
172 }
173 }
174 return count;
175 }
176
177
178 void Assembler::EnterStubFrame() {
179 // Push 0 as saved PC for stub frames.
180 mov(TMP, RA);
181 mov(RA, ZR);
182
183 // We don't use EnterFrame here because TMP is the RA we want to restore.
184 // If we used EnterFrame, it would call PushList, and not push in the right
185 // order.
186 Push(RA);
187 Push(FP);
188 Push(TMP);
189 addiu(FP, SP, Immediate(1 * kWordSize));
regis 2013/03/28 21:43:25 The sequence above is not optimal. Do not use Push
190 }
191
192
193 void Assembler::LeaveStubFrame() {
194 addiu(SP, FP, Immediate(-1 * kWordSize));
195 Pop(RA);
196 Pop(FP);
regis 2013/03/28 21:43:25 Do not use Pop. Emit loads and only then adjust th
197
198 // Adjust SP for null PC pushed in EnterStubFrame.
199 addiu(SP, SP, Immediate(kWordSize));
200 }
201
202
203 void Assembler::EnterFrame(RegList regs, intptr_t frame_space) {
204 if (prologue_offset_ == -1) {
205 prologue_offset_ = CodeSize();
206 }
207 PushList(regs);
208 if ((regs & (1 << FP)) != 0) {
209 // Set FP to the saved previous FP.
210 addiu(FP, SP, Immediate(kWordSize * NumRegsBelowFP(regs)));
211 }
212 addiu(SP, SP, Immediate(-frame_space));
213 }
214
215
216 void Assembler::LeaveFrame(RegList regs) {
217 if ((regs & (1 << FP)) != 0) {
218 // Use FP to set SP.
219 addiu(SP, FP, Immediate(-kWordSize * NumRegsBelowFP(regs)));
220 }
221 PopList(regs);
222 }
223
224
225 void Assembler::EnterDartFrame(intptr_t frame_size) {
226 const intptr_t offset = CodeSize();
227
228 // Save PC in frame for fast identification of corresponding code.
229 GetPC(T0);
230 Push(T0);
231
232 // Note that callee-saved registers can be added to the register list.
233 EnterFrame((1 << PP) | (1 << FP) | (1 << RA), 0);
234
235 if (offset != 0) {
236 // Adjust saved PC for any intrinsic code that could have been generated
237 // before a frame is created. Use PP as temp register.
238 lw(PP, Address(FP, 2 * kWordSize));
239 addiu(PP, PP, Immediate(-offset));
240 sw(PP, Address(FP, 2 * kWordSize));
241 }
242
243 // Grab the PC again for looking up the pool pointer.
244 GetPC(T0);
245
246 // Setup pool pointer for this dart function.
247 const intptr_t object_pool_pc_dist =
248 Instructions::HeaderSize() - Instructions::object_pool_offset() +
249 CodeSize() - (2 * Instr::kInstrSize);
250 lw(PP, Address(T0 /* PC - 8 */, -object_pool_pc_dist));
251
252 // Reserve space for locals.
253 addiu(SP, SP, Immediate(-frame_size));
254 }
255
256
257 void Assembler::LeaveDartFrame() {
258 LeaveFrame((1 << PP) | (1 << FP) | (1 << RA));
259 // Adjust SP for PC pushed in EnterDartFrame.
260 addiu(SP, SP, Immediate(kWordSize));
261 }
262
263
97 int32_t Assembler::AddExternalLabel(const ExternalLabel* label) { 264 int32_t Assembler::AddExternalLabel(const ExternalLabel* label) {
98 if (object_pool_.IsNull()) { 265 if (object_pool_.IsNull()) {
99 // The object pool cannot be used in the vm isolate. 266 // The object pool cannot be used in the vm isolate.
100 ASSERT(Isolate::Current() != Dart::vm_isolate()); 267 ASSERT(Isolate::Current() != Dart::vm_isolate());
101 object_pool_ = GrowableObjectArray::New(Heap::kOld); 268 object_pool_ = GrowableObjectArray::New(Heap::kOld);
102 } 269 }
103 const word address = label->address(); 270 const word address = label->address();
104 ASSERT(Utils::IsAligned(address, 4)); 271 ASSERT(Utils::IsAligned(address, 4));
105 // The address is stored in the object array as a RawSmi. 272 // The address is stored in the object array as a RawSmi.
106 const Smi& smi = Smi::Handle(Smi::New(address >> kSmiTagShift)); 273 const Smi& smi = Smi::Handle(Smi::New(address >> kSmiTagShift));
(...skipping 12 matching lines...) Expand all
119 b(&stop); 286 b(&stop);
120 Emit(reinterpret_cast<int32_t>(message)); 287 Emit(reinterpret_cast<int32_t>(message));
121 Bind(&stop); 288 Bind(&stop);
122 break_(Instr::kStopMessageCode); 289 break_(Instr::kStopMessageCode);
123 } 290 }
124 291
125 } // namespace dart 292 } // namespace dart
126 293
127 #endif // defined TARGET_ARCH_MIPS 294 #endif // defined TARGET_ARCH_MIPS
128 295
OLDNEW
« no previous file with comments | « runtime/vm/assembler_mips.h ('k') | runtime/vm/code_generator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698