OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_MIPS | 5 #if V8_TARGET_ARCH_MIPS |
6 | 6 |
7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Run the native code for the Array function called as a normal function. | 135 // Run the native code for the Array function called as a normal function. |
136 // Tail call a stub. | 136 // Tail call a stub. |
137 __ mov(a3, a1); | 137 __ mov(a3, a1); |
138 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); | 138 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
139 ArrayConstructorStub stub(masm->isolate()); | 139 ArrayConstructorStub stub(masm->isolate()); |
140 __ TailCallStub(&stub); | 140 __ TailCallStub(&stub); |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 // static | 144 // static |
| 145 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { |
| 146 // ----------- S t a t e ------------- |
| 147 // -- a0 : number of arguments |
| 148 // -- a1 : constructor function |
| 149 // -- ra : return address |
| 150 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
| 151 // -- sp[argc * 4] : receiver |
| 152 // ----------------------------------- |
| 153 |
| 154 // 1. Load the first argument into a0 and get rid of the rest (including the |
| 155 // receiver). |
| 156 Label no_arguments; |
| 157 { |
| 158 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg)); |
| 159 __ Subu(a0, a0, Operand(1)); |
| 160 __ sll(a0, a0, kPointerSizeLog2); |
| 161 __ Addu(sp, a0, sp); |
| 162 __ lw(a0, MemOperand(sp)); |
| 163 __ Drop(2); |
| 164 } |
| 165 |
| 166 // 2a. Convert first argument to number. |
| 167 ToNumberStub stub(masm->isolate()); |
| 168 __ TailCallStub(&stub); |
| 169 |
| 170 // 2b. No arguments, return +0. |
| 171 __ bind(&no_arguments); |
| 172 __ Move(v0, Smi::FromInt(0)); |
| 173 __ DropAndRet(1); |
| 174 } |
| 175 |
| 176 |
| 177 // static |
| 178 void Builtins::Generate_NumberConstructor_ConstructStub(MacroAssembler* masm) { |
| 179 // ----------- S t a t e ------------- |
| 180 // -- a0 : number of arguments |
| 181 // -- a1 : constructor function |
| 182 // -- a3 : new target |
| 183 // -- ra : return address |
| 184 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
| 185 // -- sp[argc * 4] : receiver |
| 186 // ----------------------------------- |
| 187 |
| 188 // 1. Make sure we operate in the context of the called function. |
| 189 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 190 |
| 191 // 2. Load the first argument into a0 and get rid of the rest (including the |
| 192 // receiver). |
| 193 { |
| 194 Label no_arguments, done; |
| 195 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg)); |
| 196 __ Subu(a0, a0, Operand(1)); |
| 197 __ sll(a0, a0, kPointerSizeLog2); |
| 198 __ Addu(sp, a0, sp); |
| 199 __ lw(a0, MemOperand(sp)); |
| 200 __ Drop(2); |
| 201 __ jmp(&done); |
| 202 __ bind(&no_arguments); |
| 203 __ Move(a0, Smi::FromInt(0)); |
| 204 __ Drop(1); |
| 205 __ bind(&done); |
| 206 } |
| 207 |
| 208 // 3. Make sure a0 is a number. |
| 209 { |
| 210 Label done_convert; |
| 211 __ JumpIfSmi(a0, &done_convert); |
| 212 __ GetObjectType(a0, a2, a2); |
| 213 __ Branch(&done_convert, eq, a2, Operand(HEAP_NUMBER_TYPE)); |
| 214 { |
| 215 FrameScope scope(masm, StackFrame::INTERNAL); |
| 216 __ Push(a1, a3); |
| 217 ToNumberStub stub(masm->isolate()); |
| 218 __ CallStub(&stub); |
| 219 __ Move(a0, v0); |
| 220 __ Pop(a1, a3); |
| 221 } |
| 222 __ bind(&done_convert); |
| 223 } |
| 224 |
| 225 // 4. Check if new target and constructor differ. |
| 226 Label new_object; |
| 227 __ Branch(&new_object, ne, a1, Operand(a3)); |
| 228 |
| 229 // 5. Allocate a JSValue wrapper for the number. |
| 230 __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object); |
| 231 __ Ret(); |
| 232 |
| 233 // 6. Fallback to the runtime to create new object. |
| 234 __ bind(&new_object); |
| 235 { |
| 236 FrameScope scope(masm, StackFrame::INTERNAL); |
| 237 __ Push(a0, a1, a3); // first argument, constructor, new target |
| 238 __ CallRuntime(Runtime::kNewObject); |
| 239 __ Pop(a0); |
| 240 } |
| 241 __ Ret(USE_DELAY_SLOT); |
| 242 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot |
| 243 } |
| 244 |
| 245 |
| 246 // static |
145 void Builtins::Generate_StringConstructor(MacroAssembler* masm) { | 247 void Builtins::Generate_StringConstructor(MacroAssembler* masm) { |
146 // ----------- S t a t e ------------- | 248 // ----------- S t a t e ------------- |
147 // -- a0 : number of arguments | 249 // -- a0 : number of arguments |
148 // -- a1 : constructor function | 250 // -- a1 : constructor function |
149 // -- ra : return address | 251 // -- ra : return address |
150 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) | 252 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
151 // -- sp[argc * 4] : receiver | 253 // -- sp[argc * 4] : receiver |
152 // ----------------------------------- | 254 // ----------------------------------- |
153 | 255 |
154 // 1. Load the first argument into a0 and get rid of the rest (including the | 256 // 1. Load the first argument into a0 and get rid of the rest (including the |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { | 306 void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) { |
205 // ----------- S t a t e ------------- | 307 // ----------- S t a t e ------------- |
206 // -- a0 : number of arguments | 308 // -- a0 : number of arguments |
207 // -- a1 : constructor function | 309 // -- a1 : constructor function |
208 // -- a3 : new target | 310 // -- a3 : new target |
209 // -- ra : return address | 311 // -- ra : return address |
210 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) | 312 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
211 // -- sp[argc * 4] : receiver | 313 // -- sp[argc * 4] : receiver |
212 // ----------------------------------- | 314 // ----------------------------------- |
213 | 315 |
214 // 1. Load the first argument into a0 and get rid of the rest (including the | 316 // 1. Make sure we operate in the context of the called function. |
| 317 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 318 |
| 319 // 2. Load the first argument into a0 and get rid of the rest (including the |
215 // receiver). | 320 // receiver). |
216 { | 321 { |
217 Label no_arguments, done; | 322 Label no_arguments, done; |
218 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg)); | 323 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg)); |
219 __ Subu(a0, a0, Operand(1)); | 324 __ Subu(a0, a0, Operand(1)); |
220 __ sll(a0, a0, kPointerSizeLog2); | 325 __ sll(a0, a0, kPointerSizeLog2); |
221 __ Addu(sp, a0, sp); | 326 __ Addu(sp, a0, sp); |
222 __ lw(a0, MemOperand(sp)); | 327 __ lw(a0, MemOperand(sp)); |
223 __ Drop(2); | 328 __ Drop(2); |
224 __ jmp(&done); | 329 __ jmp(&done); |
225 __ bind(&no_arguments); | 330 __ bind(&no_arguments); |
226 __ LoadRoot(a0, Heap::kempty_stringRootIndex); | 331 __ LoadRoot(a0, Heap::kempty_stringRootIndex); |
227 __ Drop(1); | 332 __ Drop(1); |
228 __ bind(&done); | 333 __ bind(&done); |
229 } | 334 } |
230 | 335 |
231 // 2. Make sure a0 is a string. | 336 // 3. Make sure a0 is a string. |
232 { | 337 { |
233 Label convert, done_convert; | 338 Label convert, done_convert; |
234 __ JumpIfSmi(a0, &convert); | 339 __ JumpIfSmi(a0, &convert); |
235 __ GetObjectType(a0, a2, a2); | 340 __ GetObjectType(a0, a2, a2); |
236 __ And(t0, a2, Operand(kIsNotStringMask)); | 341 __ And(t0, a2, Operand(kIsNotStringMask)); |
237 __ Branch(&done_convert, eq, t0, Operand(zero_reg)); | 342 __ Branch(&done_convert, eq, t0, Operand(zero_reg)); |
238 __ bind(&convert); | 343 __ bind(&convert); |
239 { | 344 { |
240 FrameScope scope(masm, StackFrame::INTERNAL); | 345 FrameScope scope(masm, StackFrame::INTERNAL); |
241 ToStringStub stub(masm->isolate()); | 346 ToStringStub stub(masm->isolate()); |
242 __ Push(a1, a3); | 347 __ Push(a1, a3); |
243 __ CallStub(&stub); | 348 __ CallStub(&stub); |
244 __ Move(a0, v0); | 349 __ Move(a0, v0); |
245 __ Pop(a1, a3); | 350 __ Pop(a1, a3); |
246 } | 351 } |
247 __ bind(&done_convert); | 352 __ bind(&done_convert); |
248 } | 353 } |
249 | 354 |
250 // 3. Check if new target and constructor differ. | 355 // 4. Check if new target and constructor differ. |
251 Label new_object; | 356 Label new_object; |
252 __ Branch(&new_object, ne, a1, Operand(a3)); | 357 __ Branch(&new_object, ne, a1, Operand(a3)); |
253 | 358 |
254 // 4. Allocate a JSValue wrapper for the string. | 359 // 5. Allocate a JSValue wrapper for the string. |
255 { | 360 __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object); |
256 // ----------- S t a t e ------------- | 361 __ Ret(); |
257 // -- a0 : the first argument | |
258 // -- a1 : constructor function | |
259 // -- a3 : new target | |
260 // -- ra : return address | |
261 // ----------------------------------- | |
262 __ Allocate(JSValue::kSize, v0, a2, t0, &new_object, TAG_OBJECT); | |
263 | 362 |
264 // Initialize the JSValue in eax. | 363 // 6. Fallback to the runtime to create new object. |
265 __ LoadGlobalFunctionInitialMap(a1, a2, a3); | |
266 __ sw(a2, FieldMemOperand(v0, HeapObject::kMapOffset)); | |
267 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex); | |
268 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset)); | |
269 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset)); | |
270 __ Ret(USE_DELAY_SLOT); | |
271 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); | |
272 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize); | |
273 } | |
274 | |
275 // 5. Fallback to the runtime to create new object. | |
276 __ bind(&new_object); | 364 __ bind(&new_object); |
277 { | 365 { |
278 FrameScope scope(masm, StackFrame::INTERNAL); | 366 FrameScope scope(masm, StackFrame::INTERNAL); |
279 __ Push(a0, a1, a3); // first argument, constructor, new target | 367 __ Push(a0, a1, a3); // first argument, constructor, new target |
280 __ CallRuntime(Runtime::kNewObject); | 368 __ CallRuntime(Runtime::kNewObject); |
281 __ Pop(a0); | 369 __ Pop(a0); |
282 } | 370 } |
283 __ Ret(USE_DELAY_SLOT); | 371 __ Ret(USE_DELAY_SLOT); |
284 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); | 372 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot |
285 } | 373 } |
286 | 374 |
287 | 375 |
288 static void CallRuntimePassFunction( | 376 static void CallRuntimePassFunction( |
289 MacroAssembler* masm, Runtime::FunctionId function_id) { | 377 MacroAssembler* masm, Runtime::FunctionId function_id) { |
290 // ----------- S t a t e ------------- | 378 // ----------- S t a t e ------------- |
291 // -- a1 : target function (preserved for callee) | 379 // -- a1 : target function (preserved for callee) |
292 // -- a3 : new target (preserved for callee) | 380 // -- a3 : new target (preserved for callee) |
293 // ----------------------------------- | 381 // ----------------------------------- |
294 | 382 |
(...skipping 2155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2450 } | 2538 } |
2451 } | 2539 } |
2452 | 2540 |
2453 | 2541 |
2454 #undef __ | 2542 #undef __ |
2455 | 2543 |
2456 } // namespace internal | 2544 } // namespace internal |
2457 } // namespace v8 | 2545 } // namespace v8 |
2458 | 2546 |
2459 #endif // V8_TARGET_ARCH_MIPS | 2547 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |