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

Side by Side Diff: src/mips/builtins-mips.cc

Issue 8395030: MIPS: port Refactor and clean up array allocation across platforms. (Closed)
Patch Set: port Further improvements upon r9747. Created 9 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 __ lw(result, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); 81 __ lw(result, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX)));
82 __ lw(result, 82 __ lw(result,
83 FieldMemOperand(result, GlobalObject::kGlobalContextOffset)); 83 FieldMemOperand(result, GlobalObject::kGlobalContextOffset));
84 // Load the Array function from the global context. 84 // Load the Array function from the global context.
85 __ lw(result, 85 __ lw(result,
86 MemOperand(result, 86 MemOperand(result,
87 Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); 87 Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX)));
88 } 88 }
89 89
90 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 91 // Allocate an empty JSArray. The allocated array is put into the result
98 // register. An elements backing store is allocated with size initial_capacity 92 // register. An elements backing store is allocated with size initial_capacity
99 // and filled with the hole values. 93 // and filled with the hole values.
100 static void AllocateEmptyJSArray(MacroAssembler* masm, 94 static void AllocateEmptyJSArray(MacroAssembler* masm,
101 Register array_function, 95 Register array_function,
102 Register result, 96 Register result,
103 Register scratch1, 97 Register scratch1,
104 Register scratch2, 98 Register scratch2,
105 Register scratch3, 99 Register scratch3,
106 int initial_capacity,
107 Label* gc_required) { 100 Label* gc_required) {
108 ASSERT(initial_capacity > 0); 101 const int initial_capacity = JSArray::kPreallocatedArrayElements;
102 STATIC_ASSERT(initial_capacity >= 0);
109 // Load the initial map from the array function. 103 // Load the initial map from the array function.
110 __ lw(scratch1, FieldMemOperand(array_function, 104 __ lw(scratch1, FieldMemOperand(array_function,
111 JSFunction::kPrototypeOrInitialMapOffset)); 105 JSFunction::kPrototypeOrInitialMapOffset));
112 106
113 // Allocate the JSArray object together with space for a fixed array with the 107 // Allocate the JSArray object together with space for a fixed array with the
114 // requested elements. 108 // requested elements.
115 int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity); 109 int size = JSArray::kSize + FixedArray::SizeFor(initial_capacity);
116 __ AllocateInNewSpace(size, 110 __ AllocateInNewSpace(size,
117 result, 111 result,
118 scratch2, 112 scratch2,
(...skipping 29 matching lines...) Expand all
148 // scratch2: start of next object 142 // scratch2: start of next object
149 __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex); 143 __ LoadRoot(scratch3, Heap::kFixedArrayMapRootIndex);
150 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); 144 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset);
151 __ sw(scratch3, MemOperand(scratch1)); 145 __ sw(scratch3, MemOperand(scratch1));
152 __ Addu(scratch1, scratch1, kPointerSize); 146 __ Addu(scratch1, scratch1, kPointerSize);
153 __ li(scratch3, Operand(Smi::FromInt(initial_capacity))); 147 __ li(scratch3, Operand(Smi::FromInt(initial_capacity)));
154 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); 148 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset);
155 __ sw(scratch3, MemOperand(scratch1)); 149 __ sw(scratch3, MemOperand(scratch1));
156 __ Addu(scratch1, scratch1, kPointerSize); 150 __ Addu(scratch1, scratch1, kPointerSize);
157 151
158 // Fill the FixedArray with the hole value. 152 // Fill the FixedArray with the hole value. Inline the code if short.
153 if (initial_capacity == 0) return;
159 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize); 154 ASSERT_EQ(2 * kPointerSize, FixedArray::kHeaderSize);
160 ASSERT(initial_capacity <= kLoopUnfoldLimit);
161 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex); 155 __ LoadRoot(scratch3, Heap::kTheHoleValueRootIndex);
162 for (int i = 0; i < initial_capacity; i++) { 156 static const int kLoopUnfoldLimit = 4;
157 if (initial_capacity <= kLoopUnfoldLimit) {
158 for (int i = 0; i < initial_capacity; i++) {
159 __ sw(scratch3, MemOperand(scratch1, i * kPointerSize));
160 }
161 } else {
162 Label loop, entry;
163 __ Addu(scratch2, scratch1, Operand(initial_capacity * kPointerSize));
164 __ Branch(&entry);
165 __ bind(&loop);
163 __ sw(scratch3, MemOperand(scratch1)); 166 __ sw(scratch3, MemOperand(scratch1));
164 __ Addu(scratch1, scratch1, kPointerSize); 167 __ Addu(scratch1, scratch1, kPointerSize);
168 __ bind(&entry);
169 __ Branch(&loop, lt, scratch1, Operand(scratch2));
165 } 170 }
166 } 171 }
167 172
168 173
169 // Allocate a JSArray with the number of elements stored in a register. The 174 // 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 175 // 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 176 // 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 177 // 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 178 // 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 179 // (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 180 // 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 181 // otherwise it is left uninitialized. When the backing store is filled the
177 // register elements_array_storage is scratched. 182 // register elements_array_storage is scratched.
178 static void AllocateJSArray(MacroAssembler* masm, 183 static void AllocateJSArray(MacroAssembler* masm,
179 Register array_function, // Array function. 184 Register array_function, // Array function.
180 Register array_size, // As a smi. 185 Register array_size, // As a smi, cannot be 0.
181 Register result, 186 Register result,
182 Register elements_array_storage, 187 Register elements_array_storage,
183 Register elements_array_end, 188 Register elements_array_end,
184 Register scratch1, 189 Register scratch1,
185 Register scratch2, 190 Register scratch2,
186 bool fill_with_hole, 191 bool fill_with_hole,
187 Label* gc_required) { 192 Label* gc_required) {
188 Label not_empty, allocated;
189
190 // Load the initial map from the array function. 193 // Load the initial map from the array function.
191 __ lw(elements_array_storage, 194 __ lw(elements_array_storage,
192 FieldMemOperand(array_function, 195 FieldMemOperand(array_function,
193 JSFunction::kPrototypeOrInitialMapOffset)); 196 JSFunction::kPrototypeOrInitialMapOffset));
194 197
195 // Check whether an empty sized array is requested. 198 if (FLAG_debug_code) { // Assert that array size is not zero.
196 __ Branch(&not_empty, ne, array_size, Operand(zero_reg)); 199 __ Assert(ne, "array size is unexpectedly 0", array_size, Operand(zero_reg)) ;
197 200 }
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 201
210 // Allocate the JSArray object together with space for a FixedArray with the 202 // Allocate the JSArray object together with space for a FixedArray with the
211 // requested number of elements. 203 // requested number of elements.
212 __ bind(&not_empty);
213 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); 204 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
214 __ li(elements_array_end, 205 __ li(elements_array_end,
215 (JSArray::kSize + FixedArray::kHeaderSize) / kPointerSize); 206 (JSArray::kSize + FixedArray::kHeaderSize) / kPointerSize);
216 __ sra(scratch1, array_size, kSmiTagSize); 207 __ sra(scratch1, array_size, kSmiTagSize);
217 __ Addu(elements_array_end, elements_array_end, scratch1); 208 __ Addu(elements_array_end, elements_array_end, scratch1);
218 __ AllocateInNewSpace( 209 __ AllocateInNewSpace(
219 elements_array_end, 210 elements_array_end,
220 result, 211 result,
221 scratch1, 212 scratch1,
222 scratch2, 213 scratch2,
223 gc_required, 214 gc_required,
224 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); 215 static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS));
225 216
226 // Allocated the JSArray. Now initialize the fields except for the elements 217 // Allocated the JSArray. Now initialize the fields except for the elements
227 // array. 218 // array.
228 // result: JSObject 219 // result: JSObject
229 // elements_array_storage: initial map 220 // elements_array_storage: initial map
230 // array_size: size of array (smi) 221 // array_size: size of array (smi)
231 __ bind(&allocated);
232 __ sw(elements_array_storage, FieldMemOperand(result, JSObject::kMapOffset)); 222 __ sw(elements_array_storage, FieldMemOperand(result, JSObject::kMapOffset));
233 __ LoadRoot(elements_array_storage, Heap::kEmptyFixedArrayRootIndex); 223 __ LoadRoot(elements_array_storage, Heap::kEmptyFixedArrayRootIndex);
234 __ sw(elements_array_storage, 224 __ sw(elements_array_storage,
235 FieldMemOperand(result, JSArray::kPropertiesOffset)); 225 FieldMemOperand(result, JSArray::kPropertiesOffset));
236 // Field JSArray::kElementsOffset is initialized later. 226 // Field JSArray::kElementsOffset is initialized later.
237 __ sw(array_size, FieldMemOperand(result, JSArray::kLengthOffset)); 227 __ sw(array_size, FieldMemOperand(result, JSArray::kLengthOffset));
238 228
239 // Calculate the location of the elements array and set elements array member 229 // Calculate the location of the elements array and set elements array member
240 // of the JSArray. 230 // of the JSArray.
241 // result: JSObject 231 // result: JSObject
(...skipping 13 matching lines...) Expand all
255 // array_size: size of array (smi) 245 // array_size: size of array (smi)
256 __ LoadRoot(scratch1, Heap::kFixedArrayMapRootIndex); 246 __ LoadRoot(scratch1, Heap::kFixedArrayMapRootIndex);
257 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset); 247 ASSERT_EQ(0 * kPointerSize, FixedArray::kMapOffset);
258 __ sw(scratch1, MemOperand(elements_array_storage)); 248 __ sw(scratch1, MemOperand(elements_array_storage));
259 __ Addu(elements_array_storage, elements_array_storage, kPointerSize); 249 __ Addu(elements_array_storage, elements_array_storage, kPointerSize);
260 250
261 // Length of the FixedArray is the number of pre-allocated elements if 251 // 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 252 // 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. 253 // JSArrays. The length of a FixedArray is stored as a smi.
264 STATIC_ASSERT(kSmiTag == 0); 254 STATIC_ASSERT(kSmiTag == 0);
265 __ li(at, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
266 __ movz(array_size, at, array_size);
267 255
268 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset); 256 ASSERT_EQ(1 * kPointerSize, FixedArray::kLengthOffset);
269 __ sw(array_size, MemOperand(elements_array_storage)); 257 __ sw(array_size, MemOperand(elements_array_storage));
270 __ Addu(elements_array_storage, elements_array_storage, kPointerSize); 258 __ Addu(elements_array_storage, elements_array_storage, kPointerSize);
271 259
272 // Calculate elements array and elements array end. 260 // Calculate elements array and elements array end.
273 // result: JSObject 261 // result: JSObject
274 // elements_array_storage: elements array element storage 262 // elements_array_storage: elements array element storage
275 // array_size: smi-tagged size of elements array 263 // array_size: smi-tagged size of elements array
276 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); 264 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
(...skipping 28 matching lines...) Expand all
305 // sp[0]: last argument 293 // sp[0]: last argument
306 // This function is used for both construct and normal calls of Array. The only 294 // 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 295 // 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 296 // 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. 297 // 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 298 // Both registers are preserved by this code so no need to differentiate between
311 // construct call and normal call. 299 // construct call and normal call.
312 static void ArrayNativeCode(MacroAssembler* masm, 300 static void ArrayNativeCode(MacroAssembler* masm,
313 Label* call_generic_code) { 301 Label* call_generic_code) {
314 Counters* counters = masm->isolate()->counters(); 302 Counters* counters = masm->isolate()->counters();
315 Label argc_one_or_more, argc_two_or_more; 303 Label argc_one_or_more, argc_two_or_more, not_empty_array, empty_array;
316 304
317 // Check for array construction with zero arguments or one. 305 // Check for array construction with zero arguments or one.
318 __ Branch(&argc_one_or_more, ne, a0, Operand(zero_reg)); 306 __ Branch(&argc_one_or_more, ne, a0, Operand(zero_reg));
319 // Handle construction of an empty array. 307 // Handle construction of an empty array.
308 __ bind(&empty_array);
320 AllocateEmptyJSArray(masm, 309 AllocateEmptyJSArray(masm,
321 a1, 310 a1,
322 a2, 311 a2,
323 a3, 312 a3,
324 t0, 313 t0,
325 t1, 314 t1,
326 JSArray::kPreallocatedArrayElements,
327 call_generic_code); 315 call_generic_code);
328 __ IncrementCounter(counters->array_function_native(), 1, a3, t0); 316 __ IncrementCounter(counters->array_function_native(), 1, a3, t0);
329 // Setup return value, remove receiver from stack and return. 317 // Setup return value, remove receiver from stack and return.
330 __ mov(v0, a2); 318 __ mov(v0, a2);
331 __ Addu(sp, sp, Operand(kPointerSize)); 319 __ Addu(sp, sp, Operand(kPointerSize));
332 __ Ret(); 320 __ Ret();
333 321
334 // Check for one argument. Bail out if argument is not smi or if it is 322 // Check for one argument. Bail out if argument is not smi or if it is
335 // negative. 323 // negative.
336 __ bind(&argc_one_or_more); 324 __ bind(&argc_one_or_more);
337 __ Branch(&argc_two_or_more, ne, a0, Operand(1)); 325 __ Branch(&argc_two_or_more, ne, a0, Operand(1));
338 326
339 STATIC_ASSERT(kSmiTag == 0); 327 STATIC_ASSERT(kSmiTag == 0);
340 __ lw(a2, MemOperand(sp)); // Get the argument from the stack. 328 __ lw(a2, MemOperand(sp)); // Get the argument from the stack.
329 __ Branch(&not_empty_array, ne, a2, Operand(zero_reg));
330 __ Drop(1); // Adjust stack.
331 __ mov(a0, zero_reg); // Treat this as a call with argc of zero.
332 __ Branch(&empty_array);
333
334 __ bind(&not_empty_array);
341 __ And(a3, a2, Operand(kIntptrSignBit | kSmiTagMask)); 335 __ And(a3, a2, Operand(kIntptrSignBit | kSmiTagMask));
342 __ Branch(call_generic_code, eq, a3, Operand(zero_reg)); 336 __ Branch(call_generic_code, eq, a3, Operand(zero_reg));
343 337
344 // Handle construction of an empty array of a certain size. Bail out if size 338 // Handle construction of an empty array of a certain size. Bail out if size
345 // is too large to actually allocate an elements array. 339 // is too large to actually allocate an elements array.
346 STATIC_ASSERT(kSmiTag == 0); 340 STATIC_ASSERT(kSmiTag == 0);
347 __ Branch(call_generic_code, Ugreater_equal, a2, 341 __ Branch(call_generic_code, Ugreater_equal, a2,
348 Operand(JSObject::kInitialMaxFastElementArray << kSmiTagSize)); 342 Operand(JSObject::kInitialMaxFastElementArray << kSmiTagSize));
349 343
350 // a0: argc 344 // a0: argc
(...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 __ bind(&dont_adapt_arguments); 1681 __ bind(&dont_adapt_arguments);
1688 __ Jump(a3); 1682 __ Jump(a3);
1689 } 1683 }
1690 1684
1691 1685
1692 #undef __ 1686 #undef __
1693 1687
1694 } } // namespace v8::internal 1688 } } // namespace v8::internal
1695 1689
1696 #endif // V8_TARGET_ARCH_MIPS 1690 #endif // V8_TARGET_ARCH_MIPS
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698