OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 29 matching lines...) Expand all Loading... |
40 namespace v8 { | 40 namespace v8 { |
41 namespace internal { | 41 namespace internal { |
42 | 42 |
43 | 43 |
44 #define __ ACCESS_MASM(masm) | 44 #define __ ACCESS_MASM(masm) |
45 | 45 |
46 | 46 |
47 void Builtins::Generate_Adaptor(MacroAssembler* masm, | 47 void Builtins::Generate_Adaptor(MacroAssembler* masm, |
48 CFunctionId id, | 48 CFunctionId id, |
49 BuiltinExtraArguments extra_args) { | 49 BuiltinExtraArguments extra_args) { |
50 UNIMPLEMENTED_MIPS(); | 50 // ----------- S t a t e ------------- |
| 51 // -- a0 : number of arguments excluding receiver |
| 52 // -- a1 : called function (only guaranteed when |
| 53 // -- extra_args requires it) |
| 54 // -- cp : context |
| 55 // -- sp[0] : last argument |
| 56 // -- ... |
| 57 // -- sp[4 * (argc - 1)] : first argument |
| 58 // -- sp[4 * agrc] : receiver |
| 59 // ----------------------------------- |
| 60 |
| 61 // Insert extra arguments. |
| 62 int num_extra_args = 0; |
| 63 if (extra_args == NEEDS_CALLED_FUNCTION) { |
| 64 num_extra_args = 1; |
| 65 __ push(a1); |
| 66 } else { |
| 67 ASSERT(extra_args == NO_EXTRA_ARGUMENTS); |
| 68 } |
| 69 |
| 70 // JumpToExternalReference expects a0 to contain the number of arguments |
| 71 // including the receiver and the extra arguments. |
| 72 __ Addu(a0, a0, Operand(num_extra_args + 1)); |
| 73 __ JumpToExternalReference(ExternalReference(id, masm->isolate())); |
| 74 } |
| 75 |
| 76 |
| 77 // Load the built-in Array function from the current context. |
| 78 static void GenerateLoadArrayFunction(MacroAssembler* masm, Register result) { |
| 79 // Load the global context. |
| 80 |
| 81 __ lw(result, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 82 __ lw(result, |
| 83 FieldMemOperand(result, GlobalObject::kGlobalContextOffset)); |
| 84 // Load the Array function from the global context. |
| 85 __ lw(result, |
| 86 MemOperand(result, |
| 87 Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 88 } |
| 89 |
| 90 |
| 91 // This constant has the same value as JSArray::kPreallocatedArrayElements and |
| 92 // if JSArray::kPreallocatedArrayElements is changed handling of loop unfolding |
| 93 // below should be reconsidered. |
| 94 static const int kLoopUnfoldLimit = 4; |
| 95 |
| 96 |
| 97 // Allocate an empty JSArray. The allocated array is put into the result |
| 98 // register. An elements backing store is allocated with size initial_capacity |
| 99 // and filled with the hole values. |
| 100 static void AllocateEmptyJSArray(MacroAssembler* masm, |
| 101 Register array_function, |
| 102 Register result, |
| 103 Register scratch1, |
| 104 Register scratch2, |
| 105 Register scratch3, |
| 106 int initial_capacity, |
| 107 Label* gc_required) { |
| 108 ASSERT(initial_capacity > 0); |
| 109 // Load the initial map from the array function. |
| 110 __ lw(scratch1, FieldMemOperand(array_function, |
| 111 JSFunction::kPrototypeOrInitialMapOffset)); |
| 112 |
| 113 // Allocate the JSArray object together with space for a fixed array with the |
| 114 // requested elements. |
| 115 int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity); |
| 116 __ AllocateInNewSpace(size, |
| 117 result, |
| 118 scratch2, |
| 119 scratch3, |
| 120 gc_required, |
| 121 TAG_OBJECT); |
| 122 // Allocated the JSArray. Now initialize the fields except for the elements |
| 123 // array. |
| 124 // result: JSObject |
| 125 // scratch1: initial map |
| 126 // scratch2: start of next object |
| 127 __ sw(scratch1, FieldMemOperand(result, JSObject::kMapOffset)); |
| 128 __ LoadRoot(scratch1, Heap::kEmptyFixedArrayRootIndex); |
| 129 __ sw(scratch1, FieldMemOperand(result, JSArray::kPropertiesOffset)); |
| 130 // Field JSArray::kElementsOffset is initialized later. |
| 131 __ mov(scratch3, zero_reg); |
| 132 __ sw(scratch3, FieldMemOperand(result, JSArray::kLengthOffset)); |
| 133 |
| 134 // Calculate the location of the elements array and set elements array member |
| 135 // of the JSArray. |
| 136 // result: JSObject |
| 137 // scratch2: start of next object |
| 138 __ Addu(scratch1, result, Operand(JSArray::kSize)); |
| 139 __ sw(scratch1, FieldMemOperand(result, JSArray::kElementsOffset)); |
| 140 |
| 141 // Clear the heap tag on the elements array. |
| 142 __ And(scratch1, scratch1, Operand(~kHeapObjectTagMask)); |
| 143 |
| 144 // Initialize the FixedArray and fill it with holes. FixedArray length is |
| 145 // stored as a smi. |
| 146 // result: JSObject |
| 147 // scratch1: elements array (untagged) |
| 148 // scratch2: start of next object |
| 149 __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); |
| 150 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); |
| 151 __ sw(scratch3, MemOperand(scratch1)); |
| 152 __ Addu(scratch1, scratch1, kPointerSize); |
| 153 __ li(scratch3, Operand(Smi::FromInt(initial_capacity))); |
| 154 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); |
| 155 __ sw(scratch3, MemOperand(scratch1)); |
| 156 __ Addu(scratch1, scratch1, kPointerSize); |
| 157 |
| 158 // Fill the FixedArray with the hole value. |
| 159 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); |
| 160 ASSERT(initial_capacity <= kLoopUnfoldLimit); |
| 161 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); |
| 162 for (int i = 0; i < initial_capacity; i++) { |
| 163 __ sw(scratch3, MemOperand(scratch1)); |
| 164 __ Addu(scratch1, scratch1, kPointerSize); |
| 165 } |
| 166 } |
| 167 |
| 168 |
| 169 // Allocate a JSArray with the number of elements stored in a register. The |
| 170 // register array_function holds the built-in Array function and the register |
| 171 // array_size holds the size of the array as a smi. The allocated array is put |
| 172 // into the result register and beginning and end of the FixedArray elements |
| 173 // storage is put into registers elements_array_storage and elements_array_end |
| 174 // (see below for when that is not the case). If the parameter fill_with_holes |
| 175 // is true the allocated elements backing store is filled with the hole values |
| 176 // otherwise it is left uninitialized. When the backing store is filled the |
| 177 // register elements_array_storage is scratched. |
| 178 static void AllocateJSArray(MacroAssembler* masm, |
| 179 Register array_function, // Array function. |
| 180 Register array_size, // As a smi. |
| 181 Register result, |
| 182 Register elements_array_storage, |
| 183 Register elements_array_end, |
| 184 Register scratch1, |
| 185 Register scratch2, |
| 186 bool fill_with_hole, |
| 187 Label* gc_required) { |
| 188 Label not_empty, allocated; |
| 189 |
| 190 // Load the initial map from the array function. |
| 191 __ lw(elements_array_storage, |
| 192 FieldMemOperand(array_function, |
| 193 JSFunction::kPrototypeOrInitialMapOffset)); |
| 194 |
| 195 // Check whether an empty sized array is requested. |
| 196 __ Branch(¬_empty, ne, array_size, Operand(zero_reg)); |
| 197 |
| 198 // If an empty array is requested allocate a small elements array anyway. This |
| 199 // keeps the code below free of special casing for the empty array. |
| 200 int size = JSArray::kSize + |
| 201 FixedArray::SizeFor(JSArray::kPreallocatedArrayElements); |
| 202 __ AllocateInNewSpace(size, |
| 203 result, |
| 204 elements_array_end, |
| 205 scratch1, |
| 206 gc_required, |
| 207 TAG_OBJECT); |
| 208 __ Branch(&allocated); |
| 209 |
| 210 // Allocate the JSArray object together with space for a FixedArray with the |
| 211 // requested number of elements. |
| 212 __ bind(¬_empty); |
| 213 ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
| 214 __ li(elements_array_end, |
| 215 (JSArray::kSize + FixedArray::kHeaderSize) / kPointerSize); |
| 216 __ sra(scratch1, array_size, kSmiTagSize); |
| 217 __ Addu(elements_array_end, elements_array_end, scratch1); |
| 218 __ AllocateInNewSpace( |
| 219 elements_array_end, |
| 220 result, |
| 221 scratch1, |
| 222 scratch2, |
| 223 gc_required, |
| 224 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
| 225 |
| 226 // Allocated the JSArray. Now initialize the fields except for the elements |
| 227 // array. |
| 228 // result: JSObject |
| 229 // elements_array_storage: initial map |
| 230 // array_size: size of array (smi) |
| 231 __ bind(&allocated); |
| 232 __ sw(elements_array_storage, FieldMemOperand(result, JSObject::kMapOffset)); |
| 233 __ LoadRoot(elements_array_storage, Heap::kEmptyFixedArrayRootIndex); |
| 234 __ sw(elements_array_storage, |
| 235 FieldMemOperand(result, JSArray::kPropertiesOffset)); |
| 236 // Field JSArray::kElementsOffset is initialized later. |
| 237 __ sw(array_size, FieldMemOperand(result, JSArray::kLengthOffset)); |
| 238 |
| 239 // Calculate the location of the elements array and set elements array member |
| 240 // of the JSArray. |
| 241 // result: JSObject |
| 242 // array_size: size of array (smi) |
| 243 __ Addu(elements_array_storage, result, Operand(JSArray::kSize)); |
| 244 __ sw(elements_array_storage, |
| 245 FieldMemOperand(result, JSArray::kElementsOffset)); |
| 246 |
| 247 // Clear the heap tag on the elements array. |
| 248 __ And(elements_array_storage, |
| 249 elements_array_storage, |
| 250 Operand(~kHeapObjectTagMask)); |
| 251 // Initialize the fixed array and fill it with holes. FixedArray length is |
| 252 // stored as a smi. |
| 253 // result: JSObject |
| 254 // elements_array_storage: elements array (untagged) |
| 255 // array_size: size of array (smi) |
| 256 __ LoadRoot(scratch1, Heap::kFixedArrayMapRootIndex); |
| 257 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); |
| 258 __ sw(scratch1, MemOperand(elements_array_storage)); |
| 259 __ Addu(elements_array_storage, elements_array_storage, kPointerSize); |
| 260 |
| 261 // Length of the FixedArray is the number of pre-allocated elements if |
| 262 // the actual JSArray has length 0 and the size of the JSArray for non-empty |
| 263 // JSArrays. The length of a FixedArray is stored as a smi. |
| 264 ASSERT(kSmiTag == 0); |
| 265 __ li(at, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements))); |
| 266 __ movz(array_size, at, array_size); |
| 267 |
| 268 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); |
| 269 __ sw(array_size, MemOperand(elements_array_storage)); |
| 270 __ Addu(elements_array_storage, elements_array_storage, kPointerSize); |
| 271 |
| 272 // Calculate elements array and elements array end. |
| 273 // result: JSObject |
| 274 // elements_array_storage: elements array element storage |
| 275 // array_size: smi-tagged size of elements array |
| 276 ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); |
| 277 __ sll(elements_array_end, array_size, kPointerSizeLog2 - kSmiTagSize); |
| 278 __ Addu(elements_array_end, elements_array_storage, elements_array_end); |
| 279 |
| 280 // Fill the allocated FixedArray with the hole value if requested. |
| 281 // result: JSObject |
| 282 // elements_array_storage: elements array element storage |
| 283 // elements_array_end: start of next object |
| 284 if (fill_with_hole) { |
| 285 Label loop, entry; |
| 286 __ LoadRoot(scratch1, Heap::kTheHoleValueRootIndex); |
| 287 __ Branch(&entry); |
| 288 __ bind(&loop); |
| 289 __ sw(scratch1, MemOperand(elements_array_storage)); |
| 290 __ Addu(elements_array_storage, elements_array_storage, kPointerSize); |
| 291 |
| 292 __ bind(&entry); |
| 293 __ Branch(&loop, lt, elements_array_storage, Operand(elements_array_end)); |
| 294 } |
| 295 } |
| 296 |
| 297 |
| 298 // Create a new array for the built-in Array function. This function allocates |
| 299 // the JSArray object and the FixedArray elements array and initializes these. |
| 300 // If the Array cannot be constructed in native code the runtime is called. This |
| 301 // function assumes the following state: |
| 302 // a0: argc |
| 303 // a1: constructor (built-in Array function) |
| 304 // ra: return address |
| 305 // sp[0]: last argument |
| 306 // This function is used for both construct and normal calls of Array. The only |
| 307 // difference between handling a construct call and a normal call is that for a |
| 308 // construct call the constructor function in a1 needs to be preserved for |
| 309 // entering the generic code. In both cases argc in a0 needs to be preserved. |
| 310 // Both registers are preserved by this code so no need to differentiate between |
| 311 // construct call and normal call. |
| 312 static void ArrayNativeCode(MacroAssembler* masm, |
| 313 Label* call_generic_code) { |
| 314 Counters* counters = masm->isolate()->counters(); |
| 315 Label argc_one_or_more, argc_two_or_more; |
| 316 |
| 317 // Check for array construction with zero arguments or one. |
| 318 __ Branch(&argc_one_or_more, ne, a0, Operand(zero_reg)); |
| 319 // Handle construction of an empty array. |
| 320 AllocateEmptyJSArray(masm, |
| 321 a1, |
| 322 a2, |
| 323 a3, |
| 324 t0, |
| 325 t1, |
| 326 JSArray::kPreallocatedArrayElements, |
| 327 call_generic_code); |
| 328 __ IncrementCounter(counters->array_function_native(), 1, a3, t0); |
| 329 // Setup return value, remove receiver from stack and return. |
| 330 __ mov(v0, a2); |
| 331 __ Addu(sp, sp, Operand(kPointerSize)); |
| 332 __ Ret(); |
| 333 |
| 334 // Check for one argument. Bail out if argument is not smi or if it is |
| 335 // negative. |
| 336 __ bind(&argc_one_or_more); |
| 337 __ Branch(&argc_two_or_more, ne, a0, Operand(1)); |
| 338 |
| 339 ASSERT(kSmiTag == 0); |
| 340 __ lw(a2, MemOperand(sp)); // Get the argument from the stack. |
| 341 __ And(a3, a2, Operand(kIntptrSignBit | kSmiTagMask)); |
| 342 __ Branch(call_generic_code, eq, a3, Operand(zero_reg)); |
| 343 |
| 344 // Handle construction of an empty array of a certain size. Bail out if size |
| 345 // is too large to actually allocate an elements array. |
| 346 ASSERT(kSmiTag == 0); |
| 347 __ Branch(call_generic_code, ge, a2, |
| 348 Operand(JSObject::kInitialMaxFastElementArray << kSmiTagSize)); |
| 349 |
| 350 // a0: argc |
| 351 // a1: constructor |
| 352 // a2: array_size (smi) |
| 353 // sp[0]: argument |
| 354 AllocateJSArray(masm, |
| 355 a1, |
| 356 a2, |
| 357 a3, |
| 358 t0, |
| 359 t1, |
| 360 t2, |
| 361 t3, |
| 362 true, |
| 363 call_generic_code); |
| 364 __ IncrementCounter(counters->array_function_native(), 1, a2, t0); |
| 365 |
| 366 // Setup return value, remove receiver and argument from stack and return. |
| 367 __ mov(v0, a3); |
| 368 __ Addu(sp, sp, Operand(2 * kPointerSize)); |
| 369 __ Ret(); |
| 370 |
| 371 // Handle construction of an array from a list of arguments. |
| 372 __ bind(&argc_two_or_more); |
| 373 __ sll(a2, a0, kSmiTagSize); // Convert argc to a smi. |
| 374 |
| 375 // a0: argc |
| 376 // a1: constructor |
| 377 // a2: array_size (smi) |
| 378 // sp[0]: last argument |
| 379 AllocateJSArray(masm, |
| 380 a1, |
| 381 a2, |
| 382 a3, |
| 383 t0, |
| 384 t1, |
| 385 t2, |
| 386 t3, |
| 387 false, |
| 388 call_generic_code); |
| 389 __ IncrementCounter(counters->array_function_native(), 1, a2, t2); |
| 390 |
| 391 // Fill arguments as array elements. Copy from the top of the stack (last |
| 392 // element) to the array backing store filling it backwards. Note: |
| 393 // elements_array_end points after the backing store. |
| 394 // a0: argc |
| 395 // a3: JSArray |
| 396 // t0: elements_array storage start (untagged) |
| 397 // t1: elements_array_end (untagged) |
| 398 // sp[0]: last argument |
| 399 |
| 400 Label loop, entry; |
| 401 __ Branch(&entry); |
| 402 __ bind(&loop); |
| 403 __ pop(a2); |
| 404 __ Addu(t1, t1, -kPointerSize); |
| 405 __ sw(a2, MemOperand(t1)); |
| 406 __ bind(&entry); |
| 407 __ Branch(&loop, lt, t0, Operand(t1)); |
| 408 |
| 409 // Remove caller arguments and receiver from the stack, setup return value and |
| 410 // return. |
| 411 // a0: argc |
| 412 // a3: JSArray |
| 413 // sp[0]: receiver |
| 414 __ Addu(sp, sp, Operand(kPointerSize)); |
| 415 __ mov(v0, a3); |
| 416 __ Ret(); |
51 } | 417 } |
52 | 418 |
53 | 419 |
54 void Builtins::Generate_ArrayCode(MacroAssembler* masm) { | 420 void Builtins::Generate_ArrayCode(MacroAssembler* masm) { |
55 UNIMPLEMENTED_MIPS(); | 421 // ----------- S t a t e ------------- |
| 422 // -- a0 : number of arguments |
| 423 // -- ra : return address |
| 424 // -- sp[...]: constructor arguments |
| 425 // ----------------------------------- |
| 426 Label generic_array_code; |
| 427 |
| 428 // Get the Array function. |
| 429 GenerateLoadArrayFunction(masm, a1); |
| 430 |
| 431 if (FLAG_debug_code) { |
| 432 // Initial map for the builtin Array functions should be maps. |
| 433 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 434 __ And(t0, a2, Operand(kSmiTagMask)); |
| 435 __ Assert(ne, "Unexpected initial map for Array function (1)", |
| 436 t0, Operand(zero_reg)); |
| 437 __ GetObjectType(a2, a3, t0); |
| 438 __ Assert(eq, "Unexpected initial map for Array function (2)", |
| 439 t0, Operand(MAP_TYPE)); |
| 440 } |
| 441 |
| 442 // Run the native code for the Array function called as a normal function. |
| 443 ArrayNativeCode(masm, &generic_array_code); |
| 444 |
| 445 // Jump to the generic array code if the specialized code cannot handle |
| 446 // the construction. |
| 447 __ bind(&generic_array_code); |
| 448 |
| 449 Handle<Code> array_code = |
| 450 masm->isolate()->builtins()->ArrayCodeGeneric(); |
| 451 __ Jump(array_code, RelocInfo::CODE_TARGET); |
56 } | 452 } |
57 | 453 |
58 | 454 |
59 void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) { | 455 void Builtins::Generate_ArrayConstructCode(MacroAssembler* masm) { |
60 UNIMPLEMENTED_MIPS(); | 456 // ----------- S t a t e ------------- |
| 457 // -- a0 : number of arguments |
| 458 // -- a1 : constructor function |
| 459 // -- ra : return address |
| 460 // -- sp[...]: constructor arguments |
| 461 // ----------------------------------- |
| 462 Label generic_constructor; |
| 463 |
| 464 if (FLAG_debug_code) { |
| 465 // The array construct code is only set for the builtin and internal |
| 466 // Array functions which always have a map. |
| 467 // Initial map for the builtin Array function should be a map. |
| 468 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 469 __ And(t0, a2, Operand(kSmiTagMask)); |
| 470 __ Assert(ne, "Unexpected initial map for Array function (3)", |
| 471 t0, Operand(zero_reg)); |
| 472 __ GetObjectType(a2, a3, t0); |
| 473 __ Assert(eq, "Unexpected initial map for Array function (4)", |
| 474 t0, Operand(MAP_TYPE)); |
| 475 } |
| 476 |
| 477 // Run the native code for the Array function called as a constructor. |
| 478 ArrayNativeCode(masm, &generic_constructor); |
| 479 |
| 480 // Jump to the generic construct code in case the specialized code cannot |
| 481 // handle the construction. |
| 482 __ bind(&generic_constructor); |
| 483 |
| 484 Handle<Code> generic_construct_stub = |
| 485 masm->isolate()->builtins()->JSConstructStubGeneric(); |
| 486 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
61 } | 487 } |
62 | 488 |
63 | 489 |
64 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { | 490 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { |
65 UNIMPLEMENTED_MIPS(); | 491 // ----------- S t a t e ------------- |
| 492 // -- a0 : number of arguments |
| 493 // -- a1 : constructor function |
| 494 // -- ra : return address |
| 495 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
| 496 // -- sp[argc * 4] : receiver |
| 497 // ----------------------------------- |
| 498 Counters* counters = masm->isolate()->counters(); |
| 499 __ IncrementCounter(counters->string_ctor_calls(), 1, a2, a3); |
| 500 |
| 501 Register function = a1; |
| 502 if (FLAG_debug_code) { |
| 503 __ LoadGlobalFunction(Context::STRING_FUNCTION_INDEX, a2); |
| 504 __ Assert(eq, "Unexpected String function", function, Operand(a2)); |
| 505 } |
| 506 |
| 507 // Load the first arguments in a0 and get rid of the rest. |
| 508 Label no_arguments; |
| 509 __ Branch(&no_arguments, eq, a0, Operand(zero_reg)); |
| 510 // First args = sp[(argc - 1) * 4]. |
| 511 __ Subu(a0, a0, Operand(1)); |
| 512 __ sll(a0, a0, kPointerSizeLog2); |
| 513 __ Addu(sp, a0, sp); |
| 514 __ lw(a0, MemOperand(sp)); |
| 515 // sp now point to args[0], drop args[0] + receiver. |
| 516 __ Drop(2); |
| 517 |
| 518 Register argument = a2; |
| 519 Label not_cached, argument_is_string; |
| 520 NumberToStringStub::GenerateLookupNumberStringCache( |
| 521 masm, |
| 522 a0, // Input. |
| 523 argument, // Result. |
| 524 a3, // Scratch. |
| 525 t0, // Scratch. |
| 526 t1, // Scratch. |
| 527 false, // Is it a Smi? |
| 528 ¬_cached); |
| 529 __ IncrementCounter(counters->string_ctor_cached_number(), 1, a3, t0); |
| 530 __ bind(&argument_is_string); |
| 531 |
| 532 // ----------- S t a t e ------------- |
| 533 // -- a2 : argument converted to string |
| 534 // -- a1 : constructor function |
| 535 // -- ra : return address |
| 536 // ----------------------------------- |
| 537 |
| 538 Label gc_required; |
| 539 __ AllocateInNewSpace(JSValue::kSize, |
| 540 v0, // Result. |
| 541 a3, // Scratch. |
| 542 t0, // Scratch. |
| 543 &gc_required, |
| 544 TAG_OBJECT); |
| 545 |
| 546 // Initialising the String Object. |
| 547 Register map = a3; |
| 548 __ LoadGlobalFunctionInitialMap(function, map, t0); |
| 549 if (FLAG_debug_code) { |
| 550 __ lbu(t0, FieldMemOperand(map, Map::kInstanceSizeOffset)); |
| 551 __ Assert(eq, "Unexpected string wrapper instance size", |
| 552 t0, Operand(JSValue::kSize >> kPointerSizeLog2)); |
| 553 __ lbu(t0, FieldMemOperand(map, Map::kUnusedPropertyFieldsOffset)); |
| 554 __ Assert(eq, "Unexpected unused properties of string wrapper", |
| 555 t0, Operand(zero_reg)); |
| 556 } |
| 557 __ sw(map, FieldMemOperand(v0, HeapObject::kMapOffset)); |
| 558 |
| 559 __ LoadRoot(a3, Heap::kEmptyFixedArrayRootIndex); |
| 560 __ sw(a3, FieldMemOperand(v0, JSObject::kPropertiesOffset)); |
| 561 __ sw(a3, FieldMemOperand(v0, JSObject::kElementsOffset)); |
| 562 |
| 563 __ sw(argument, FieldMemOperand(v0, JSValue::kValueOffset)); |
| 564 |
| 565 // Ensure the object is fully initialized. |
| 566 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize); |
| 567 |
| 568 __ Ret(); |
| 569 |
| 570 // The argument was not found in the number to string cache. Check |
| 571 // if it's a string already before calling the conversion builtin. |
| 572 Label convert_argument; |
| 573 __ bind(¬_cached); |
| 574 __ JumpIfSmi(a0, &convert_argument); |
| 575 |
| 576 // Is it a String? |
| 577 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset)); |
| 578 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset)); |
| 579 ASSERT(kNotStringTag != 0); |
| 580 __ And(t0, a3, Operand(kIsNotStringMask)); |
| 581 __ Branch(&convert_argument, ne, t0, Operand(zero_reg)); |
| 582 __ mov(argument, a0); |
| 583 __ IncrementCounter(counters->string_ctor_conversions(), 1, a3, t0); |
| 584 __ Branch(&argument_is_string); |
| 585 |
| 586 // Invoke the conversion builtin and put the result into a2. |
| 587 __ bind(&convert_argument); |
| 588 __ push(function); // Preserve the function. |
| 589 __ IncrementCounter(counters->string_ctor_conversions(), 1, a3, t0); |
| 590 __ EnterInternalFrame(); |
| 591 __ push(v0); |
| 592 __ InvokeBuiltin(Builtins::TO_STRING, CALL_FUNCTION); |
| 593 __ LeaveInternalFrame(); |
| 594 __ pop(function); |
| 595 __ mov(argument, v0); |
| 596 __ Branch(&argument_is_string); |
| 597 |
| 598 // Load the empty string into a2, remove the receiver from the |
| 599 // stack, and jump back to the case where the argument is a string. |
| 600 __ bind(&no_arguments); |
| 601 __ LoadRoot(argument, Heap::kEmptyStringRootIndex); |
| 602 __ Drop(1); |
| 603 __ Branch(&argument_is_string); |
| 604 |
| 605 // At this point the argument is already a string. Call runtime to |
| 606 // create a string wrapper. |
| 607 __ bind(&gc_required); |
| 608 __ IncrementCounter(counters->string_ctor_gc_required(), 1, a3, t0); |
| 609 __ EnterInternalFrame(); |
| 610 __ push(argument); |
| 611 __ CallRuntime(Runtime::kNewStringWrapper, 1); |
| 612 __ LeaveInternalFrame(); |
| 613 __ Ret(); |
66 } | 614 } |
67 | 615 |
68 | 616 |
69 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { | 617 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { |
70 UNIMPLEMENTED_MIPS(); | 618 // ----------- S t a t e ------------- |
| 619 // -- a0 : number of arguments |
| 620 // -- a1 : constructor function |
| 621 // -- ra : return address |
| 622 // -- sp[...]: constructor arguments |
| 623 // ----------------------------------- |
| 624 |
| 625 Label non_function_call; |
| 626 // Check that the function is not a smi. |
| 627 __ And(t0, a1, Operand(kSmiTagMask)); |
| 628 __ Branch(&non_function_call, eq, t0, Operand(zero_reg)); |
| 629 // Check that the function is a JSFunction. |
| 630 __ GetObjectType(a1, a2, a2); |
| 631 __ Branch(&non_function_call, ne, a2, Operand(JS_FUNCTION_TYPE)); |
| 632 |
| 633 // Jump to the function-specific construct stub. |
| 634 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 635 __ lw(a2, FieldMemOperand(a2, SharedFunctionInfo::kConstructStubOffset)); |
| 636 __ Addu(t9, a2, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 637 __ Jump(Operand(t9)); |
| 638 |
| 639 // a0: number of arguments |
| 640 // a1: called object |
| 641 __ bind(&non_function_call); |
| 642 // CALL_NON_FUNCTION expects the non-function constructor as receiver |
| 643 // (instead of the original receiver from the call site). The receiver is |
| 644 // stack element argc. |
| 645 // Set expected number of arguments to zero (not changing a0). |
| 646 __ mov(a2, zero_reg); |
| 647 __ GetBuiltinEntry(a3, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 648 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 649 RelocInfo::CODE_TARGET); |
| 650 } |
| 651 |
| 652 |
| 653 static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
| 654 bool is_api_function, |
| 655 bool count_constructions) { |
| 656 // Should never count constructions for api objects. |
| 657 ASSERT(!is_api_function || !count_constructions); |
| 658 |
| 659 Isolate* isolate = masm->isolate(); |
| 660 |
| 661 // ----------- S t a t e ------------- |
| 662 // -- a0 : number of arguments |
| 663 // -- a1 : constructor function |
| 664 // -- ra : return address |
| 665 // -- sp[...]: constructor arguments |
| 666 // ----------------------------------- |
| 667 |
| 668 // Enter a construct frame. |
| 669 __ EnterConstructFrame(); |
| 670 |
| 671 // Preserve the two incoming parameters on the stack. |
| 672 __ sll(a0, a0, kSmiTagSize); // Tag arguments count. |
| 673 __ MultiPushReversed(a0.bit() | a1.bit()); |
| 674 |
| 675 // Use t7 to hold undefined, which is used in several places below. |
| 676 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex); |
| 677 |
| 678 Label rt_call, allocated; |
| 679 // Try to allocate the object without transitioning into C code. If any of the |
| 680 // preconditions is not met, the code bails out to the runtime call. |
| 681 if (FLAG_inline_new) { |
| 682 Label undo_allocation; |
| 683 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 684 ExternalReference debug_step_in_fp = |
| 685 ExternalReference::debug_step_in_fp_address(isolate); |
| 686 __ li(a2, Operand(debug_step_in_fp)); |
| 687 __ lw(a2, MemOperand(a2)); |
| 688 __ Branch(&rt_call, ne, a2, Operand(zero_reg)); |
| 689 #endif |
| 690 |
| 691 // Load the initial map and verify that it is in fact a map. |
| 692 // a1: constructor function |
| 693 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset)); |
| 694 __ And(t0, a2, Operand(kSmiTagMask)); |
| 695 __ Branch(&rt_call, eq, t0, Operand(zero_reg)); |
| 696 __ GetObjectType(a2, a3, t4); |
| 697 __ Branch(&rt_call, ne, t4, Operand(MAP_TYPE)); |
| 698 |
| 699 // Check that the constructor is not constructing a JSFunction (see comments |
| 700 // in Runtime_NewObject in runtime.cc). In which case the initial map's |
| 701 // instance type would be JS_FUNCTION_TYPE. |
| 702 // a1: constructor function |
| 703 // a2: initial map |
| 704 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceTypeOffset)); |
| 705 __ Branch(&rt_call, eq, a3, Operand(JS_FUNCTION_TYPE)); |
| 706 |
| 707 if (count_constructions) { |
| 708 Label allocate; |
| 709 // Decrease generous allocation count. |
| 710 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 711 MemOperand constructor_count = |
| 712 FieldMemOperand(a3, SharedFunctionInfo::kConstructionCountOffset); |
| 713 __ lbu(t0, constructor_count); |
| 714 __ Subu(t0, t0, Operand(1)); |
| 715 __ sb(t0, constructor_count); |
| 716 __ Branch(&allocate, ne, t0, Operand(zero_reg)); |
| 717 |
| 718 __ Push(a1, a2); |
| 719 |
| 720 __ push(a1); // Constructor. |
| 721 // The call will replace the stub, so the countdown is only done once. |
| 722 __ CallRuntime(Runtime::kFinalizeInstanceSize, 1); |
| 723 |
| 724 __ pop(a2); |
| 725 __ pop(a1); |
| 726 |
| 727 __ bind(&allocate); |
| 728 } |
| 729 |
| 730 // Now allocate the JSObject on the heap. |
| 731 // a1: constructor function |
| 732 // a2: initial map |
| 733 __ lbu(a3, FieldMemOperand(a2, Map::kInstanceSizeOffset)); |
| 734 __ AllocateInNewSpace(a3, t4, t5, t6, &rt_call, SIZE_IN_WORDS); |
| 735 |
| 736 // Allocated the JSObject, now initialize the fields. Map is set to initial |
| 737 // map and properties and elements are set to empty fixed array. |
| 738 // a1: constructor function |
| 739 // a2: initial map |
| 740 // a3: object size |
| 741 // t4: JSObject (not tagged) |
| 742 __ LoadRoot(t6, Heap::kEmptyFixedArrayRootIndex); |
| 743 __ mov(t5, t4); |
| 744 __ sw(a2, MemOperand(t5, JSObject::kMapOffset)); |
| 745 __ sw(t6, MemOperand(t5, JSObject::kPropertiesOffset)); |
| 746 __ sw(t6, MemOperand(t5, JSObject::kElementsOffset)); |
| 747 __ Addu(t5, t5, Operand(3*kPointerSize)); |
| 748 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset); |
| 749 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset); |
| 750 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset); |
| 751 |
| 752 // Fill all the in-object properties with appropriate filler. |
| 753 // a1: constructor function |
| 754 // a2: initial map |
| 755 // a3: object size (in words) |
| 756 // t4: JSObject (not tagged) |
| 757 // t5: First in-object property of JSObject (not tagged) |
| 758 __ sll(t0, a3, kPointerSizeLog2); |
| 759 __ addu(t6, t4, t0); // End of object. |
| 760 ASSERT_EQ(3 * kPointerSize, JSObject::kHeaderSize); |
| 761 { Label loop, entry; |
| 762 if (count_constructions) { |
| 763 // To allow for truncation. |
| 764 __ LoadRoot(t7, Heap::kOnePointerFillerMapRootIndex); |
| 765 } else { |
| 766 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex); |
| 767 } |
| 768 __ jmp(&entry); |
| 769 __ bind(&loop); |
| 770 __ sw(t7, MemOperand(t5, 0)); |
| 771 __ addiu(t5, t5, kPointerSize); |
| 772 __ bind(&entry); |
| 773 __ Branch(&loop, Uless, t5, Operand(t6)); |
| 774 } |
| 775 |
| 776 // Add the object tag to make the JSObject real, so that we can continue and |
| 777 // jump into the continuation code at any time from now on. Any failures |
| 778 // need to undo the allocation, so that the heap is in a consistent state |
| 779 // and verifiable. |
| 780 __ Addu(t4, t4, Operand(kHeapObjectTag)); |
| 781 |
| 782 // Check if a non-empty properties array is needed. Continue with allocated |
| 783 // object if not fall through to runtime call if it is. |
| 784 // a1: constructor function |
| 785 // t4: JSObject |
| 786 // t5: start of next object (not tagged) |
| 787 __ lbu(a3, FieldMemOperand(a2, Map::kUnusedPropertyFieldsOffset)); |
| 788 // The field instance sizes contains both pre-allocated property fields and |
| 789 // in-object properties. |
| 790 __ lw(a0, FieldMemOperand(a2, Map::kInstanceSizesOffset)); |
| 791 __ And(t6, |
| 792 a0, |
| 793 Operand(0x000000FF << Map::kPreAllocatedPropertyFieldsByte * 8)); |
| 794 __ srl(t0, t6, Map::kPreAllocatedPropertyFieldsByte * 8); |
| 795 __ Addu(a3, a3, Operand(t0)); |
| 796 __ And(t6, a0, Operand(0x000000FF << Map::kInObjectPropertiesByte * 8)); |
| 797 __ srl(t0, t6, Map::kInObjectPropertiesByte * 8); |
| 798 __ subu(a3, a3, t0); |
| 799 |
| 800 // Done if no extra properties are to be allocated. |
| 801 __ Branch(&allocated, eq, a3, Operand(zero_reg)); |
| 802 __ Assert(greater_equal, "Property allocation count failed.", |
| 803 a3, Operand(zero_reg)); |
| 804 |
| 805 // Scale the number of elements by pointer size and add the header for |
| 806 // FixedArrays to the start of the next object calculation from above. |
| 807 // a1: constructor |
| 808 // a3: number of elements in properties array |
| 809 // t4: JSObject |
| 810 // t5: start of next object |
| 811 __ Addu(a0, a3, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| 812 __ AllocateInNewSpace( |
| 813 a0, |
| 814 t5, |
| 815 t6, |
| 816 a2, |
| 817 &undo_allocation, |
| 818 static_cast<AllocationFlags>(RESULT_CONTAINS_TOP | SIZE_IN_WORDS)); |
| 819 |
| 820 // Initialize the FixedArray. |
| 821 // a1: constructor |
| 822 // a3: number of elements in properties array (un-tagged) |
| 823 // t4: JSObject |
| 824 // t5: start of next object |
| 825 __ LoadRoot(t6, Heap::kFixedArrayMapRootIndex); |
| 826 __ mov(a2, t5); |
| 827 __ sw(t6, MemOperand(a2, JSObject::kMapOffset)); |
| 828 __ sll(a0, a3, kSmiTagSize); |
| 829 __ sw(a0, MemOperand(a2, FixedArray::kLengthOffset)); |
| 830 __ Addu(a2, a2, Operand(2 * kPointerSize)); |
| 831 |
| 832 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset); |
| 833 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); |
| 834 |
| 835 // Initialize the fields to undefined. |
| 836 // a1: constructor |
| 837 // a2: First element of FixedArray (not tagged) |
| 838 // a3: number of elements in properties array |
| 839 // t4: JSObject |
| 840 // t5: FixedArray (not tagged) |
| 841 __ sll(t3, a3, kPointerSizeLog2); |
| 842 __ addu(t6, a2, t3); // End of object. |
| 843 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); |
| 844 { Label loop, entry; |
| 845 if (count_constructions) { |
| 846 __ LoadRoot(t7, Heap::kUndefinedValueRootIndex); |
| 847 } else if (FLAG_debug_code) { |
| 848 __ LoadRoot(t8, Heap::kUndefinedValueRootIndex); |
| 849 __ Assert(eq, "Undefined value not loaded.", t7, Operand(t8)); |
| 850 } |
| 851 __ jmp(&entry); |
| 852 __ bind(&loop); |
| 853 __ sw(t7, MemOperand(a2)); |
| 854 __ addiu(a2, a2, kPointerSize); |
| 855 __ bind(&entry); |
| 856 __ Branch(&loop, less, a2, Operand(t6)); |
| 857 } |
| 858 |
| 859 // Store the initialized FixedArray into the properties field of |
| 860 // the JSObject. |
| 861 // a1: constructor function |
| 862 // t4: JSObject |
| 863 // t5: FixedArray (not tagged) |
| 864 __ Addu(t5, t5, Operand(kHeapObjectTag)); // Add the heap tag. |
| 865 __ sw(t5, FieldMemOperand(t4, JSObject::kPropertiesOffset)); |
| 866 |
| 867 // Continue with JSObject being successfully allocated. |
| 868 // a1: constructor function |
| 869 // a4: JSObject |
| 870 __ jmp(&allocated); |
| 871 |
| 872 // Undo the setting of the new top so that the heap is verifiable. For |
| 873 // example, the map's unused properties potentially do not match the |
| 874 // allocated objects unused properties. |
| 875 // t4: JSObject (previous new top) |
| 876 __ bind(&undo_allocation); |
| 877 __ UndoAllocationInNewSpace(t4, t5); |
| 878 } |
| 879 |
| 880 __ bind(&rt_call); |
| 881 // Allocate the new receiver object using the runtime call. |
| 882 // a1: constructor function |
| 883 __ push(a1); // Argument for Runtime_NewObject. |
| 884 __ CallRuntime(Runtime::kNewObject, 1); |
| 885 __ mov(t4, v0); |
| 886 |
| 887 // Receiver for constructor call allocated. |
| 888 // t4: JSObject |
| 889 __ bind(&allocated); |
| 890 __ push(t4); |
| 891 |
| 892 // Push the function and the allocated receiver from the stack. |
| 893 // sp[0]: receiver (newly allocated object) |
| 894 // sp[1]: constructor function |
| 895 // sp[2]: number of arguments (smi-tagged) |
| 896 __ lw(a1, MemOperand(sp, kPointerSize)); |
| 897 __ MultiPushReversed(a1.bit() | t4.bit()); |
| 898 |
| 899 // Reload the number of arguments from the stack. |
| 900 // a1: constructor function |
| 901 // sp[0]: receiver |
| 902 // sp[1]: constructor function |
| 903 // sp[2]: receiver |
| 904 // sp[3]: constructor function |
| 905 // sp[4]: number of arguments (smi-tagged) |
| 906 __ lw(a3, MemOperand(sp, 4 * kPointerSize)); |
| 907 |
| 908 // Setup pointer to last argument. |
| 909 __ Addu(a2, fp, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 910 |
| 911 // Setup number of arguments for function call below. |
| 912 __ srl(a0, a3, kSmiTagSize); |
| 913 |
| 914 // Copy arguments and receiver to the expression stack. |
| 915 // a0: number of arguments |
| 916 // a1: constructor function |
| 917 // a2: address of last argument (caller sp) |
| 918 // a3: number of arguments (smi-tagged) |
| 919 // sp[0]: receiver |
| 920 // sp[1]: constructor function |
| 921 // sp[2]: receiver |
| 922 // sp[3]: constructor function |
| 923 // sp[4]: number of arguments (smi-tagged) |
| 924 Label loop, entry; |
| 925 __ jmp(&entry); |
| 926 __ bind(&loop); |
| 927 __ sll(t0, a3, kPointerSizeLog2 - kSmiTagSize); |
| 928 __ Addu(t0, a2, Operand(t0)); |
| 929 __ lw(t1, MemOperand(t0)); |
| 930 __ push(t1); |
| 931 __ bind(&entry); |
| 932 __ Addu(a3, a3, Operand(-2)); |
| 933 __ Branch(&loop, greater_equal, a3, Operand(zero_reg)); |
| 934 |
| 935 // Call the function. |
| 936 // a0: number of arguments |
| 937 // a1: constructor function |
| 938 if (is_api_function) { |
| 939 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 940 Handle<Code> code = |
| 941 masm->isolate()->builtins()->HandleApiCallConstruct(); |
| 942 ParameterCount expected(0); |
| 943 __ InvokeCode(code, expected, expected, |
| 944 RelocInfo::CODE_TARGET, CALL_FUNCTION); |
| 945 } else { |
| 946 ParameterCount actual(a0); |
| 947 __ InvokeFunction(a1, actual, CALL_FUNCTION); |
| 948 } |
| 949 |
| 950 // Pop the function from the stack. |
| 951 // v0: result |
| 952 // sp[0]: constructor function |
| 953 // sp[2]: receiver |
| 954 // sp[3]: constructor function |
| 955 // sp[4]: number of arguments (smi-tagged) |
| 956 __ Pop(); |
| 957 |
| 958 // Restore context from the frame. |
| 959 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 960 |
| 961 // If the result is an object (in the ECMA sense), we should get rid |
| 962 // of the receiver and use the result; see ECMA-262 section 13.2.2-7 |
| 963 // on page 74. |
| 964 Label use_receiver, exit; |
| 965 |
| 966 // If the result is a smi, it is *not* an object in the ECMA sense. |
| 967 // v0: result |
| 968 // sp[0]: receiver (newly allocated object) |
| 969 // sp[1]: constructor function |
| 970 // sp[2]: number of arguments (smi-tagged) |
| 971 __ And(t0, v0, Operand(kSmiTagMask)); |
| 972 __ Branch(&use_receiver, eq, t0, Operand(zero_reg)); |
| 973 |
| 974 // If the type of the result (stored in its map) is less than |
| 975 // FIRST_JS_OBJECT_TYPE, it is not an object in the ECMA sense. |
| 976 __ GetObjectType(v0, a3, a3); |
| 977 __ Branch(&exit, greater_equal, a3, Operand(FIRST_JS_OBJECT_TYPE)); |
| 978 |
| 979 // Throw away the result of the constructor invocation and use the |
| 980 // on-stack receiver as the result. |
| 981 __ bind(&use_receiver); |
| 982 __ lw(v0, MemOperand(sp)); |
| 983 |
| 984 // Remove receiver from the stack, remove caller arguments, and |
| 985 // return. |
| 986 __ bind(&exit); |
| 987 // v0: result |
| 988 // sp[0]: receiver (newly allocated object) |
| 989 // sp[1]: constructor function |
| 990 // sp[2]: number of arguments (smi-tagged) |
| 991 __ lw(a1, MemOperand(sp, 2 * kPointerSize)); |
| 992 __ LeaveConstructFrame(); |
| 993 __ sll(t0, a1, kPointerSizeLog2 - 1); |
| 994 __ Addu(sp, sp, t0); |
| 995 __ Addu(sp, sp, kPointerSize); |
| 996 __ IncrementCounter(isolate->counters()->constructed_objects(), 1, a1, a2); |
| 997 __ Ret(); |
71 } | 998 } |
72 | 999 |
73 | 1000 |
74 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { | 1001 void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { |
75 UNIMPLEMENTED_MIPS(); | 1002 Generate_JSConstructStubHelper(masm, false, true); |
76 } | 1003 } |
77 | 1004 |
78 | 1005 |
79 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { | 1006 void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
80 UNIMPLEMENTED_MIPS(); | 1007 Generate_JSConstructStubHelper(masm, false, false); |
81 } | 1008 } |
82 | 1009 |
83 | 1010 |
84 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { | 1011 void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
85 UNIMPLEMENTED_MIPS(); | 1012 Generate_JSConstructStubHelper(masm, true, false); |
| 1013 } |
| 1014 |
| 1015 |
| 1016 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm, |
| 1017 bool is_construct) { |
| 1018 // Called from JSEntryStub::GenerateBody |
| 1019 |
| 1020 // ----------- S t a t e ------------- |
| 1021 // -- a0: code entry |
| 1022 // -- a1: function |
| 1023 // -- a2: reveiver_pointer |
| 1024 // -- a3: argc |
| 1025 // -- s0: argv |
| 1026 // ----------------------------------- |
| 1027 |
| 1028 // Clear the context before we push it when entering the JS frame. |
| 1029 __ mov(cp, zero_reg); |
| 1030 |
| 1031 // Enter an internal frame. |
| 1032 __ EnterInternalFrame(); |
| 1033 |
| 1034 // Set up the context from the function argument. |
| 1035 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 1036 |
| 1037 // Set up the roots register. |
| 1038 ExternalReference roots_address = |
| 1039 ExternalReference::roots_address(masm->isolate()); |
| 1040 __ li(s6, Operand(roots_address)); |
| 1041 |
| 1042 // Push the function and the receiver onto the stack. |
| 1043 __ Push(a1, a2); |
| 1044 |
| 1045 // Copy arguments to the stack in a loop. |
| 1046 // a3: argc |
| 1047 // s0: argv, ie points to first arg |
| 1048 Label loop, entry; |
| 1049 __ sll(t0, a3, kPointerSizeLog2); |
| 1050 __ addu(t2, s0, t0); |
| 1051 __ b(&entry); |
| 1052 __ nop(); // Branch delay slot nop. |
| 1053 // t2 points past last arg. |
| 1054 __ bind(&loop); |
| 1055 __ lw(t0, MemOperand(s0)); // Read next parameter. |
| 1056 __ addiu(s0, s0, kPointerSize); |
| 1057 __ lw(t0, MemOperand(t0)); // Dereference handle. |
| 1058 __ push(t0); // Push parameter. |
| 1059 __ bind(&entry); |
| 1060 __ Branch(&loop, ne, s0, Operand(t2)); |
| 1061 |
| 1062 // Initialize all JavaScript callee-saved registers, since they will be seen |
| 1063 // by the garbage collector as part of handlers. |
| 1064 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 1065 __ mov(s1, t0); |
| 1066 __ mov(s2, t0); |
| 1067 __ mov(s3, t0); |
| 1068 __ mov(s4, t0); |
| 1069 __ mov(s5, t0); |
| 1070 // s6 holds the root address. Do not clobber. |
| 1071 // s7 is cp. Do not init. |
| 1072 |
| 1073 // Invoke the code and pass argc as a0. |
| 1074 __ mov(a0, a3); |
| 1075 if (is_construct) { |
| 1076 __ Call(masm->isolate()->builtins()->JSConstructCall(), |
| 1077 RelocInfo::CODE_TARGET); |
| 1078 } else { |
| 1079 ParameterCount actual(a0); |
| 1080 __ InvokeFunction(a1, actual, CALL_FUNCTION); |
| 1081 } |
| 1082 |
| 1083 __ LeaveInternalFrame(); |
| 1084 |
| 1085 __ Jump(ra); |
86 } | 1086 } |
87 | 1087 |
88 | 1088 |
89 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { | 1089 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { |
90 UNIMPLEMENTED_MIPS(); | 1090 Generate_JSEntryTrampolineHelper(masm, false); |
91 } | 1091 } |
92 | 1092 |
93 | 1093 |
94 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { | 1094 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { |
95 UNIMPLEMENTED_MIPS(); | 1095 Generate_JSEntryTrampolineHelper(masm, true); |
96 } | 1096 } |
97 | 1097 |
98 | 1098 |
99 void Builtins::Generate_LazyCompile(MacroAssembler* masm) { | 1099 void Builtins::Generate_LazyCompile(MacroAssembler* masm) { |
100 UNIMPLEMENTED_MIPS(); | 1100 // Enter an internal frame. |
| 1101 __ EnterInternalFrame(); |
| 1102 |
| 1103 // Preserve the function. |
| 1104 __ push(a1); |
| 1105 |
| 1106 // Push the function on the stack as the argument to the runtime function. |
| 1107 __ push(a1); |
| 1108 // Call the runtime function. |
| 1109 __ CallRuntime(Runtime::kLazyCompile, 1); |
| 1110 // Calculate the entry point. |
| 1111 __ addiu(t9, v0, Code::kHeaderSize - kHeapObjectTag); |
| 1112 // Restore saved function. |
| 1113 __ pop(a1); |
| 1114 |
| 1115 // Tear down temporary frame. |
| 1116 __ LeaveInternalFrame(); |
| 1117 |
| 1118 // Do a tail-call of the compiled function. |
| 1119 __ Jump(t9); |
101 } | 1120 } |
102 | 1121 |
103 | 1122 |
104 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) { | 1123 void Builtins::Generate_LazyRecompile(MacroAssembler* masm) { |
105 UNIMPLEMENTED_MIPS(); | 1124 // Enter an internal frame. |
106 } | 1125 __ EnterInternalFrame(); |
107 | 1126 |
108 | 1127 // Preserve the function. |
| 1128 __ push(a1); |
| 1129 |
| 1130 // Push the function on the stack as the argument to the runtime function. |
| 1131 __ push(a1); |
| 1132 __ CallRuntime(Runtime::kLazyRecompile, 1); |
| 1133 // Calculate the entry point. |
| 1134 __ Addu(t9, v0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 1135 // Restore saved function. |
| 1136 __ pop(a1); |
| 1137 |
| 1138 // Tear down temporary frame. |
| 1139 __ LeaveInternalFrame(); |
| 1140 |
| 1141 // Do a tail-call of the compiled function. |
| 1142 __ Jump(t9); |
| 1143 } |
| 1144 |
| 1145 |
| 1146 // These functions are called from C++ but cannot be used in live code. |
109 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { | 1147 void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) { |
110 UNIMPLEMENTED_MIPS(); | 1148 __ Abort("Call to unimplemented function in builtins-mips.cc"); |
111 } | 1149 } |
112 | 1150 |
113 | 1151 |
114 void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) { | 1152 void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) { |
115 UNIMPLEMENTED_MIPS(); | 1153 __ Abort("Call to unimplemented function in builtins-mips.cc"); |
116 } | 1154 } |
117 | 1155 |
118 | 1156 |
119 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) { | 1157 void Builtins::Generate_NotifyOSR(MacroAssembler* masm) { |
120 UNIMPLEMENTED_MIPS(); | 1158 __ Abort("Call to unimplemented function in builtins-mips.cc"); |
121 } | 1159 } |
122 | 1160 |
123 | 1161 |
124 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { | 1162 void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) { |
125 UNIMPLEMENTED_MIPS(); | 1163 __ Abort("Call to unimplemented function in builtins-mips.cc"); |
126 } | 1164 } |
127 | 1165 |
128 | 1166 |
129 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { | 1167 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { |
130 UNIMPLEMENTED_MIPS(); | 1168 // 1. Make sure we have at least one argument. |
| 1169 // a0: actual number of arguments |
| 1170 { Label done; |
| 1171 __ Branch(&done, ne, a0, Operand(zero_reg)); |
| 1172 __ LoadRoot(t2, Heap::kUndefinedValueRootIndex); |
| 1173 __ push(t2); |
| 1174 __ Addu(a0, a0, Operand(1)); |
| 1175 __ bind(&done); |
| 1176 } |
| 1177 |
| 1178 // 2. Get the function to call (passed as receiver) from the stack, check |
| 1179 // if it is a function. |
| 1180 // a0: actual number of arguments |
| 1181 Label non_function; |
| 1182 __ sll(at, a0, kPointerSizeLog2); |
| 1183 __ addu(at, sp, at); |
| 1184 __ lw(a1, MemOperand(at)); |
| 1185 __ And(at, a1, Operand(kSmiTagMask)); |
| 1186 __ Branch(&non_function, eq, at, Operand(zero_reg)); |
| 1187 __ GetObjectType(a1, a2, a2); |
| 1188 __ Branch(&non_function, ne, a2, Operand(JS_FUNCTION_TYPE)); |
| 1189 |
| 1190 // 3a. Patch the first argument if necessary when calling a function. |
| 1191 // a0: actual number of arguments |
| 1192 // a1: function |
| 1193 Label shift_arguments; |
| 1194 { Label convert_to_object, use_global_receiver, patch_receiver; |
| 1195 // Change context eagerly in case we need the global receiver. |
| 1196 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 1197 |
| 1198 // Do not transform the receiver for strict mode functions. |
| 1199 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 1200 __ lw(a3, FieldMemOperand(a2, SharedFunctionInfo::kCompilerHintsOffset)); |
| 1201 __ And(t0, a3, Operand(1 << (SharedFunctionInfo::kStrictModeFunction + |
| 1202 kSmiTagSize))); |
| 1203 __ Branch(&shift_arguments, ne, t0, Operand(zero_reg)); |
| 1204 |
| 1205 // Do not transform the receiver for native (shared already in r2). |
| 1206 __ lw(a2, FieldMemOperand(a2, SharedFunctionInfo::kScriptOffset)); |
| 1207 __ LoadRoot(a3, Heap::kUndefinedValueRootIndex); |
| 1208 __ Branch(&shift_arguments, eq, a2, Operand(a3)); |
| 1209 __ lw(a2, FieldMemOperand(a2, Script::kTypeOffset)); |
| 1210 __ sra(a2, a2, kSmiTagSize); |
| 1211 __ Branch(&shift_arguments, eq, a2, Operand(Script::TYPE_NATIVE)); |
| 1212 |
| 1213 // Compute the receiver in non-strict mode. |
| 1214 // Load first argument in a2. a2 = -kPointerSize(sp + n_args << 2). |
| 1215 __ sll(at, a0, kPointerSizeLog2); |
| 1216 __ addu(a2, sp, at); |
| 1217 __ lw(a2, MemOperand(a2, -kPointerSize)); |
| 1218 // a0: actual number of arguments |
| 1219 // a1: function |
| 1220 // a2: first argument |
| 1221 __ JumpIfSmi(a2, &convert_to_object, t2); |
| 1222 |
| 1223 // Heap::kUndefinedValueRootIndex is already in a3. |
| 1224 __ Branch(&use_global_receiver, eq, a2, Operand(a3)); |
| 1225 __ LoadRoot(a3, Heap::kNullValueRootIndex); |
| 1226 __ Branch(&use_global_receiver, eq, a2, Operand(a3)); |
| 1227 |
| 1228 __ GetObjectType(a2, a3, a3); |
| 1229 __ Branch(&convert_to_object, lt, a3, Operand(FIRST_JS_OBJECT_TYPE)); |
| 1230 __ Branch(&shift_arguments, le, a3, Operand(LAST_JS_OBJECT_TYPE)); |
| 1231 |
| 1232 __ bind(&convert_to_object); |
| 1233 __ EnterInternalFrame(); // In order to preserve argument count. |
| 1234 __ sll(a0, a0, kSmiTagSize); // Smi tagged. |
| 1235 __ push(a0); |
| 1236 |
| 1237 __ push(a2); |
| 1238 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1239 __ mov(a2, v0); |
| 1240 |
| 1241 __ pop(a0); |
| 1242 __ sra(a0, a0, kSmiTagSize); // Un-tag. |
| 1243 __ LeaveInternalFrame(); |
| 1244 // Restore the function to a1. |
| 1245 __ sll(at, a0, kPointerSizeLog2); |
| 1246 __ addu(at, sp, at); |
| 1247 __ lw(a1, MemOperand(at)); |
| 1248 __ Branch(&patch_receiver); |
| 1249 |
| 1250 // Use the global receiver object from the called function as the |
| 1251 // receiver. |
| 1252 __ bind(&use_global_receiver); |
| 1253 const int kGlobalIndex = |
| 1254 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 1255 __ lw(a2, FieldMemOperand(cp, kGlobalIndex)); |
| 1256 __ lw(a2, FieldMemOperand(a2, GlobalObject::kGlobalContextOffset)); |
| 1257 __ lw(a2, FieldMemOperand(a2, kGlobalIndex)); |
| 1258 __ lw(a2, FieldMemOperand(a2, GlobalObject::kGlobalReceiverOffset)); |
| 1259 |
| 1260 __ bind(&patch_receiver); |
| 1261 __ sll(at, a0, kPointerSizeLog2); |
| 1262 __ addu(a3, sp, at); |
| 1263 __ sw(a2, MemOperand(a3, -kPointerSize)); |
| 1264 |
| 1265 __ Branch(&shift_arguments); |
| 1266 } |
| 1267 |
| 1268 // 3b. Patch the first argument when calling a non-function. The |
| 1269 // CALL_NON_FUNCTION builtin expects the non-function callee as |
| 1270 // receiver, so overwrite the first argument which will ultimately |
| 1271 // become the receiver. |
| 1272 // a0: actual number of arguments |
| 1273 // a1: function |
| 1274 __ bind(&non_function); |
| 1275 // Restore the function in case it has been modified. |
| 1276 __ sll(at, a0, kPointerSizeLog2); |
| 1277 __ addu(a2, sp, at); |
| 1278 __ sw(a1, MemOperand(a2, -kPointerSize)); |
| 1279 // Clear a1 to indicate a non-function being called. |
| 1280 __ mov(a1, zero_reg); |
| 1281 |
| 1282 // 4. Shift arguments and return address one slot down on the stack |
| 1283 // (overwriting the original receiver). Adjust argument count to make |
| 1284 // the original first argument the new receiver. |
| 1285 // a0: actual number of arguments |
| 1286 // a1: function |
| 1287 __ bind(&shift_arguments); |
| 1288 { Label loop; |
| 1289 // Calculate the copy start address (destination). Copy end address is sp. |
| 1290 __ sll(at, a0, kPointerSizeLog2); |
| 1291 __ addu(a2, sp, at); |
| 1292 |
| 1293 __ bind(&loop); |
| 1294 __ lw(at, MemOperand(a2, -kPointerSize)); |
| 1295 __ sw(at, MemOperand(a2)); |
| 1296 __ Subu(a2, a2, Operand(kPointerSize)); |
| 1297 __ Branch(&loop, ne, a2, Operand(sp)); |
| 1298 // Adjust the actual number of arguments and remove the top element |
| 1299 // (which is a copy of the last argument). |
| 1300 __ Subu(a0, a0, Operand(1)); |
| 1301 __ Pop(); |
| 1302 } |
| 1303 |
| 1304 // 5a. Call non-function via tail call to CALL_NON_FUNCTION builtin. |
| 1305 // a0: actual number of arguments |
| 1306 // a1: function |
| 1307 { Label function; |
| 1308 __ Branch(&function, ne, a1, Operand(zero_reg)); |
| 1309 __ mov(a2, zero_reg); // expected arguments is 0 for CALL_NON_FUNCTION |
| 1310 __ GetBuiltinEntry(a3, Builtins::CALL_NON_FUNCTION); |
| 1311 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 1312 RelocInfo::CODE_TARGET); |
| 1313 __ bind(&function); |
| 1314 } |
| 1315 |
| 1316 // 5b. Get the code to call from the function and check that the number of |
| 1317 // expected arguments matches what we're providing. If so, jump |
| 1318 // (tail-call) to the code in register edx without checking arguments. |
| 1319 // a0: actual number of arguments |
| 1320 // a1: function |
| 1321 __ lw(a3, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 1322 __ lw(a2, |
| 1323 FieldMemOperand(a3, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 1324 __ sra(a2, a2, kSmiTagSize); |
| 1325 __ lw(a3, FieldMemOperand(a1, JSFunction::kCodeEntryOffset)); |
| 1326 // Check formal and actual parameter counts. |
| 1327 __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
| 1328 RelocInfo::CODE_TARGET, ne, a2, Operand(a0)); |
| 1329 |
| 1330 ParameterCount expected(0); |
| 1331 __ InvokeCode(a3, expected, expected, JUMP_FUNCTION); |
131 } | 1332 } |
132 | 1333 |
133 | 1334 |
134 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { | 1335 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { |
135 UNIMPLEMENTED_MIPS(); | 1336 const int kIndexOffset = -5 * kPointerSize; |
| 1337 const int kLimitOffset = -4 * kPointerSize; |
| 1338 const int kArgsOffset = 2 * kPointerSize; |
| 1339 const int kRecvOffset = 3 * kPointerSize; |
| 1340 const int kFunctionOffset = 4 * kPointerSize; |
| 1341 |
| 1342 __ EnterInternalFrame(); |
| 1343 |
| 1344 __ lw(a0, MemOperand(fp, kFunctionOffset)); // Get the function. |
| 1345 __ push(a0); |
| 1346 __ lw(a0, MemOperand(fp, kArgsOffset)); // Get the args array. |
| 1347 __ push(a0); |
| 1348 // Returns (in v0) number of arguments to copy to stack as Smi. |
| 1349 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_FUNCTION); |
| 1350 |
| 1351 // Check the stack for overflow. We are not trying need to catch |
| 1352 // interruptions (e.g. debug break and preemption) here, so the "real stack |
| 1353 // limit" is checked. |
| 1354 Label okay; |
| 1355 __ LoadRoot(a2, Heap::kRealStackLimitRootIndex); |
| 1356 // Make a2 the space we have left. The stack might already be overflowed |
| 1357 // here which will cause a2 to become negative. |
| 1358 __ subu(a2, sp, a2); |
| 1359 // Check if the arguments will overflow the stack. |
| 1360 __ sll(t0, v0, kPointerSizeLog2 - kSmiTagSize); |
| 1361 __ Branch(&okay, gt, a2, Operand(t0)); // Signed comparison. |
| 1362 |
| 1363 // Out of stack space. |
| 1364 __ lw(a1, MemOperand(fp, kFunctionOffset)); |
| 1365 __ push(a1); |
| 1366 __ push(v0); |
| 1367 __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_FUNCTION); |
| 1368 // End of stack check. |
| 1369 |
| 1370 // Push current limit and index. |
| 1371 __ bind(&okay); |
| 1372 __ push(v0); // Limit. |
| 1373 __ mov(a1, zero_reg); // Initial index. |
| 1374 __ push(a1); |
| 1375 |
| 1376 // Change context eagerly to get the right global object if necessary. |
| 1377 __ lw(a0, MemOperand(fp, kFunctionOffset)); |
| 1378 __ lw(cp, FieldMemOperand(a0, JSFunction::kContextOffset)); |
| 1379 // Load the shared function info while the function is still in a0. |
| 1380 __ lw(a1, FieldMemOperand(a0, JSFunction::kSharedFunctionInfoOffset)); |
| 1381 |
| 1382 // Compute the receiver. |
| 1383 Label call_to_object, use_global_receiver, push_receiver; |
| 1384 __ lw(a0, MemOperand(fp, kRecvOffset)); |
| 1385 |
| 1386 // Do not transform the receiver for strict mode functions. |
| 1387 __ lw(a2, FieldMemOperand(a1, SharedFunctionInfo::kCompilerHintsOffset)); |
| 1388 __ And(t0, a2, Operand(1 << (SharedFunctionInfo::kStrictModeFunction + |
| 1389 kSmiTagSize))); |
| 1390 __ Branch(&push_receiver, ne, t0, Operand(zero_reg)); |
| 1391 |
| 1392 // Do not transform the receiver for native (shared already in a1). |
| 1393 __ lw(a1, FieldMemOperand(a1, SharedFunctionInfo::kScriptOffset)); |
| 1394 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex); |
| 1395 __ Branch(&push_receiver, eq, a1, Operand(a2)); |
| 1396 __ lw(a1, FieldMemOperand(a1, Script::kTypeOffset)); |
| 1397 __ sra(a1, a1, kSmiTagSize); |
| 1398 __ Branch(&push_receiver, eq, a1, Operand(Script::TYPE_NATIVE)); |
| 1399 |
| 1400 // Compute the receiver in non-strict mode. |
| 1401 __ And(t0, a0, Operand(kSmiTagMask)); |
| 1402 __ Branch(&call_to_object, eq, t0, Operand(zero_reg)); |
| 1403 __ LoadRoot(a1, Heap::kNullValueRootIndex); |
| 1404 __ Branch(&use_global_receiver, eq, a0, Operand(a1)); |
| 1405 // Heap::kUndefinedValueRootIndex is already in a2. |
| 1406 __ Branch(&use_global_receiver, eq, a0, Operand(a2)); |
| 1407 |
| 1408 // Check if the receiver is already a JavaScript object. |
| 1409 // a0: receiver |
| 1410 __ GetObjectType(a0, a1, a1); |
| 1411 __ Branch(&call_to_object, lt, a1, Operand(FIRST_JS_OBJECT_TYPE)); |
| 1412 __ Branch(&push_receiver, le, a1, Operand(LAST_JS_OBJECT_TYPE)); |
| 1413 |
| 1414 // Convert the receiver to a regular object. |
| 1415 // a0: receiver |
| 1416 __ bind(&call_to_object); |
| 1417 __ push(a0); |
| 1418 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1419 __ mov(a0, v0); // Put object in a0 to match other paths to push_receiver. |
| 1420 __ Branch(&push_receiver); |
| 1421 |
| 1422 // Use the current global receiver object as the receiver. |
| 1423 __ bind(&use_global_receiver); |
| 1424 const int kGlobalOffset = |
| 1425 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize; |
| 1426 __ lw(a0, FieldMemOperand(cp, kGlobalOffset)); |
| 1427 __ lw(a0, FieldMemOperand(a0, GlobalObject::kGlobalContextOffset)); |
| 1428 __ lw(a0, FieldMemOperand(a0, kGlobalOffset)); |
| 1429 __ lw(a0, FieldMemOperand(a0, GlobalObject::kGlobalReceiverOffset)); |
| 1430 |
| 1431 // Push the receiver. |
| 1432 // a0: receiver |
| 1433 __ bind(&push_receiver); |
| 1434 __ push(a0); |
| 1435 |
| 1436 // Copy all arguments from the array to the stack. |
| 1437 Label entry, loop; |
| 1438 __ lw(a0, MemOperand(fp, kIndexOffset)); |
| 1439 __ Branch(&entry); |
| 1440 |
| 1441 // Load the current argument from the arguments array and push it to the |
| 1442 // stack. |
| 1443 // a0: current argument index |
| 1444 __ bind(&loop); |
| 1445 __ lw(a1, MemOperand(fp, kArgsOffset)); |
| 1446 __ push(a1); |
| 1447 __ push(a0); |
| 1448 |
| 1449 // Call the runtime to access the property in the arguments array. |
| 1450 __ CallRuntime(Runtime::kGetProperty, 2); |
| 1451 __ push(v0); |
| 1452 |
| 1453 // Use inline caching to access the arguments. |
| 1454 __ lw(a0, MemOperand(fp, kIndexOffset)); |
| 1455 __ Addu(a0, a0, Operand(1 << kSmiTagSize)); |
| 1456 __ sw(a0, MemOperand(fp, kIndexOffset)); |
| 1457 |
| 1458 // Test if the copy loop has finished copying all the elements from the |
| 1459 // arguments object. |
| 1460 __ bind(&entry); |
| 1461 __ lw(a1, MemOperand(fp, kLimitOffset)); |
| 1462 __ Branch(&loop, ne, a0, Operand(a1)); |
| 1463 // Invoke the function. |
| 1464 ParameterCount actual(a0); |
| 1465 __ sra(a0, a0, kSmiTagSize); |
| 1466 __ lw(a1, MemOperand(fp, kFunctionOffset)); |
| 1467 __ InvokeFunction(a1, actual, CALL_FUNCTION); |
| 1468 |
| 1469 // Tear down the internal frame and remove function, receiver and args. |
| 1470 __ LeaveInternalFrame(); |
| 1471 __ Addu(sp, sp, Operand(3 * kPointerSize)); |
| 1472 __ Ret(); |
| 1473 } |
| 1474 |
| 1475 |
| 1476 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) { |
| 1477 __ sll(a0, a0, kSmiTagSize); |
| 1478 __ li(t0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 1479 __ MultiPush(a0.bit() | a1.bit() | t0.bit() | fp.bit() | ra.bit()); |
| 1480 __ Addu(fp, sp, Operand(3 * kPointerSize)); |
| 1481 } |
| 1482 |
| 1483 |
| 1484 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) { |
| 1485 // ----------- S t a t e ------------- |
| 1486 // -- v0 : result being passed through |
| 1487 // ----------------------------------- |
| 1488 // Get the number of arguments passed (as a smi), tear down the frame and |
| 1489 // then tear down the parameters. |
| 1490 __ lw(a1, MemOperand(fp, -3 * kPointerSize)); |
| 1491 __ mov(sp, fp); |
| 1492 __ MultiPop(fp.bit() | ra.bit()); |
| 1493 __ sll(t0, a1, kPointerSizeLog2 - kSmiTagSize); |
| 1494 __ Addu(sp, sp, t0); |
| 1495 // Adjust for the receiver. |
| 1496 __ Addu(sp, sp, Operand(kPointerSize)); |
136 } | 1497 } |
137 | 1498 |
138 | 1499 |
139 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { | 1500 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { |
140 UNIMPLEMENTED_MIPS(); | 1501 // State setup as expected by MacroAssembler::InvokePrologue. |
141 } | 1502 // ----------- S t a t e ------------- |
142 | 1503 // -- a0: actual arguments count |
143 | 1504 // -- a1: function (passed through to callee) |
| 1505 // -- a2: expected arguments count |
| 1506 // -- a3: callee code entry |
| 1507 // ----------------------------------- |
| 1508 |
| 1509 Label invoke, dont_adapt_arguments; |
| 1510 |
| 1511 Label enough, too_few; |
| 1512 __ Branch(&dont_adapt_arguments, eq, |
| 1513 a2, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); |
| 1514 // We use Uless as the number of argument should always be greater than 0. |
| 1515 __ Branch(&too_few, Uless, a0, Operand(a2)); |
| 1516 |
| 1517 { // Enough parameters: actual >= expected. |
| 1518 // a0: actual number of arguments as a smi |
| 1519 // a1: function |
| 1520 // a2: expected number of arguments |
| 1521 // a3: code entry to call |
| 1522 __ bind(&enough); |
| 1523 EnterArgumentsAdaptorFrame(masm); |
| 1524 |
| 1525 // Calculate copy start address into a0 and copy end address into a2. |
| 1526 __ sll(a0, a0, kPointerSizeLog2 - kSmiTagSize); |
| 1527 __ Addu(a0, fp, a0); |
| 1528 // Adjust for return address and receiver. |
| 1529 __ Addu(a0, a0, Operand(2 * kPointerSize)); |
| 1530 // Compute copy end address. |
| 1531 __ sll(a2, a2, kPointerSizeLog2); |
| 1532 __ subu(a2, a0, a2); |
| 1533 |
| 1534 // Copy the arguments (including the receiver) to the new stack frame. |
| 1535 // a0: copy start address |
| 1536 // a1: function |
| 1537 // a2: copy end address |
| 1538 // a3: code entry to call |
| 1539 |
| 1540 Label copy; |
| 1541 __ bind(©); |
| 1542 __ lw(t0, MemOperand(a0)); |
| 1543 __ push(t0); |
| 1544 __ Branch(USE_DELAY_SLOT, ©, ne, a0, Operand(a2)); |
| 1545 __ addiu(a0, a0, -kPointerSize); // In delay slot. |
| 1546 |
| 1547 __ jmp(&invoke); |
| 1548 } |
| 1549 |
| 1550 { // Too few parameters: Actual < expected. |
| 1551 __ bind(&too_few); |
| 1552 EnterArgumentsAdaptorFrame(masm); |
| 1553 |
| 1554 // TODO(MIPS): Optimize these loops. |
| 1555 |
| 1556 // Calculate copy start address into a0 and copy end address is fp. |
| 1557 // a0: actual number of arguments as a smi |
| 1558 // a1: function |
| 1559 // a2: expected number of arguments |
| 1560 // a3: code entry to call |
| 1561 __ sll(a0, a0, kPointerSizeLog2 - kSmiTagSize); |
| 1562 __ Addu(a0, fp, a0); |
| 1563 // Adjust for return address and receiver. |
| 1564 __ Addu(a0, a0, Operand(2 * kPointerSize)); |
| 1565 // Compute copy end address. Also adjust for return address. |
| 1566 __ Addu(t1, fp, kPointerSize); |
| 1567 |
| 1568 // Copy the arguments (including the receiver) to the new stack frame. |
| 1569 // a0: copy start address |
| 1570 // a1: function |
| 1571 // a2: expected number of arguments |
| 1572 // a3: code entry to call |
| 1573 // t1: copy end address |
| 1574 Label copy; |
| 1575 __ bind(©); |
| 1576 __ lw(t0, MemOperand(a0)); // Adjusted above for return addr and receiver. |
| 1577 __ push(t0); |
| 1578 __ Subu(a0, a0, kPointerSize); |
| 1579 __ Branch(©, ne, a0, Operand(t1)); |
| 1580 |
| 1581 // Fill the remaining expected arguments with undefined. |
| 1582 // a1: function |
| 1583 // a2: expected number of arguments |
| 1584 // a3: code entry to call |
| 1585 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 1586 __ sll(t2, a2, kPointerSizeLog2); |
| 1587 __ Subu(a2, fp, Operand(t2)); |
| 1588 __ Addu(a2, a2, Operand(-4 * kPointerSize)); // Adjust for frame. |
| 1589 |
| 1590 Label fill; |
| 1591 __ bind(&fill); |
| 1592 __ push(t0); |
| 1593 __ Branch(&fill, ne, sp, Operand(a2)); |
| 1594 } |
| 1595 |
| 1596 // Call the entry point. |
| 1597 __ bind(&invoke); |
| 1598 |
| 1599 __ Call(a3); |
| 1600 |
| 1601 // Exit frame and return. |
| 1602 LeaveArgumentsAdaptorFrame(masm); |
| 1603 __ Ret(); |
| 1604 |
| 1605 |
| 1606 // ------------------------------------------- |
| 1607 // Don't adapt arguments. |
| 1608 // ------------------------------------------- |
| 1609 __ bind(&dont_adapt_arguments); |
| 1610 __ Jump(a3); |
| 1611 } |
| 1612 |
| 1613 |
144 #undef __ | 1614 #undef __ |
145 | 1615 |
146 } } // namespace v8::internal | 1616 } } // namespace v8::internal |
147 | 1617 |
148 #endif // V8_TARGET_ARCH_MIPS | 1618 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |