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

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

Issue 1339143002: PPC: [builtins] Simplify String constructor code. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/ppc/macro-assembler-ppc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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_PPC 5 #if V8_TARGET_ARCH_PPC
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 134
135 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) { 135 void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
136 // ----------- S t a t e ------------- 136 // ----------- S t a t e -------------
137 // -- r3 : number of arguments 137 // -- r3 : number of arguments
138 // -- r4 : constructor function 138 // -- r4 : constructor function
139 // -- lr : return address 139 // -- lr : return address
140 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) 140 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
141 // -- sp[argc * 4] : receiver 141 // -- sp[argc * 4] : receiver
142 // ----------------------------------- 142 // -----------------------------------
143 Counters* counters = masm->isolate()->counters();
144 __ IncrementCounter(counters->string_ctor_calls(), 1, r5, r6);
145 143
146 Register function = r4; 144 // 1. Load the first argument into r5 and get rid of the rest (including the
147 if (FLAG_debug_code) { 145 // receiver).
148 __ LoadGlobalFunction(Context::STRING_FUNCTION_INDEX, r5); 146 {
149 __ cmp(function, r5); 147 Label no_arguments, done;
150 __ Assert(eq, kUnexpectedStringFunction); 148 __ cmpi(r3, Operand::Zero());
149 __ beq(&no_arguments);
150 __ subi(r5, r3, Operand(1));
151 __ ShiftLeftImm(r5, r5, Operand(kPointerSizeLog2));
152 __ LoadPUX(r5, MemOperand(sp, r5));
153 __ Drop(2);
154 __ b(&done);
155 __ bind(&no_arguments);
156 __ LoadRoot(r5, Heap::kempty_stringRootIndex);
157 __ Drop(1);
158 __ bind(&done);
151 } 159 }
152 160
153 // Load the first arguments in r3 and get rid of the rest. 161 // 2. Make sure r5 is a string.
154 Label no_arguments; 162 {
155 __ cmpi(r3, Operand::Zero()); 163 Label convert, done_convert;
156 __ beq(&no_arguments); 164 __ JumpIfSmi(r5, &convert);
157 // First args = sp[(argc - 1) * 4]. 165 __ CompareObjectType(r5, r6, r6, FIRST_NONSTRING_TYPE);
158 __ subi(r3, r3, Operand(1)); 166 __ blt(&done_convert);
159 __ ShiftLeftImm(r3, r3, Operand(kPointerSizeLog2)); 167 __ bind(&convert);
160 __ add(sp, sp, r3); 168 {
161 __ LoadP(r3, MemOperand(sp)); 169 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
162 // sp now point to args[0], drop args[0] + receiver. 170 ToStringStub stub(masm->isolate());
163 __ Drop(2); 171 __ push(r4);
172 __ mr(r3, r5);
173 __ CallStub(&stub);
174 __ mr(r5, r3);
175 __ pop(r4);
176 }
177 __ bind(&done_convert);
178 }
164 179
165 Register argument = r5; 180 // 3. Allocate a JSValue wrapper for the string.
166 Label not_cached, argument_is_string; 181 {
167 __ LookupNumberStringCache(r3, // Input. 182 // ----------- S t a t e -------------
168 argument, // Result. 183 // -- r4 : constructor function
169 r6, // Scratch. 184 // -- r5 : the first argument
170 r7, // Scratch. 185 // -- lr : return address
171 r8, // Scratch. 186 // -----------------------------------
172 &not_cached);
173 __ IncrementCounter(counters->string_ctor_cached_number(), 1, r6, r7);
174 __ bind(&argument_is_string);
175 187
176 // ----------- S t a t e ------------- 188 Label allocate, done_allocate;
177 // -- r5 : argument converted to string 189 __ Allocate(JSValue::kSize, r3, r6, r7, &allocate, TAG_OBJECT);
178 // -- r4 : constructor function 190 __ bind(&done_allocate);
179 // -- lr : return address
180 // -----------------------------------
181 191
182 Label gc_required; 192 // Initialize the JSValue in eax.
183 __ Allocate(JSValue::kSize, 193 __ LoadGlobalFunctionInitialMap(r4, r6, r7);
184 r3, // Result. 194 __ StoreP(r6, FieldMemOperand(r3, HeapObject::kMapOffset), r0);
185 r6, // Scratch. 195 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
186 r7, // Scratch. 196 __ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
187 &gc_required, TAG_OBJECT); 197 __ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
198 __ StoreP(r5, FieldMemOperand(r3, JSValue::kValueOffset), r0);
199 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize);
200 __ Ret();
188 201
189 // Initialising the String Object. 202 // Fallback to the runtime to allocate in new space.
190 Register map = r6; 203 __ bind(&allocate);
191 __ LoadGlobalFunctionInitialMap(function, map, r7); 204 {
192 if (FLAG_debug_code) { 205 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
193 __ lbz(r7, FieldMemOperand(map, Map::kInstanceSizeOffset)); 206 __ LoadSmiLiteral(r6, Smi::FromInt(JSValue::kSize));
194 __ cmpi(r7, Operand(JSValue::kSize >> kPointerSizeLog2)); 207 __ Push(r4, r5, r6);
195 __ Assert(eq, kUnexpectedStringWrapperInstanceSize); 208 __ CallRuntime(Runtime::kAllocateInNewSpace, 1);
196 __ lbz(r7, FieldMemOperand(map, Map::kUnusedPropertyFieldsOffset)); 209 __ Pop(r4, r5);
197 __ cmpi(r7, Operand::Zero()); 210 }
198 __ Assert(eq, kUnexpectedUnusedPropertiesOfStringWrapper); 211 __ b(&done_allocate);
199 } 212 }
200 __ StoreP(map, FieldMemOperand(r3, HeapObject::kMapOffset), r0);
201
202 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex);
203 __ StoreP(r6, FieldMemOperand(r3, JSObject::kPropertiesOffset), r0);
204 __ StoreP(r6, FieldMemOperand(r3, JSObject::kElementsOffset), r0);
205
206 __ StoreP(argument, FieldMemOperand(r3, JSValue::kValueOffset), r0);
207
208 // Ensure the object is fully initialized.
209 STATIC_ASSERT(JSValue::kSize == 4 * kPointerSize);
210
211 __ Ret();
212
213 // The argument was not found in the number to string cache. Check
214 // if it's a string already before calling the conversion builtin.
215 Label convert_argument;
216 __ bind(&not_cached);
217 __ JumpIfSmi(r3, &convert_argument);
218
219 // Is it a String?
220 __ LoadP(r5, FieldMemOperand(r3, HeapObject::kMapOffset));
221 __ lbz(r6, FieldMemOperand(r5, Map::kInstanceTypeOffset));
222 STATIC_ASSERT(kNotStringTag != 0);
223 __ andi(r0, r6, Operand(kIsNotStringMask));
224 __ bne(&convert_argument, cr0);
225 __ mr(argument, r3);
226 __ IncrementCounter(counters->string_ctor_conversions(), 1, r6, r7);
227 __ b(&argument_is_string);
228
229 // Invoke the conversion builtin and put the result into r5.
230 __ bind(&convert_argument);
231 __ push(function); // Preserve the function.
232 __ IncrementCounter(counters->string_ctor_conversions(), 1, r6, r7);
233 {
234 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
235 ToStringStub stub(masm->isolate());
236 __ CallStub(&stub);
237 }
238 __ pop(function);
239 __ mr(argument, r3);
240 __ b(&argument_is_string);
241
242 // Load the empty string into r5, remove the receiver from the
243 // stack, and jump back to the case where the argument is a string.
244 __ bind(&no_arguments);
245 __ LoadRoot(argument, Heap::kempty_stringRootIndex);
246 __ Drop(1);
247 __ b(&argument_is_string);
248
249 // At this point the argument is already a string. Call runtime to
250 // create a string wrapper.
251 __ bind(&gc_required);
252 __ IncrementCounter(counters->string_ctor_gc_required(), 1, r6, r7);
253 {
254 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
255 __ push(argument);
256 __ CallRuntime(Runtime::kNewStringWrapper, 1);
257 }
258 __ Ret();
259 } 213 }
260 214
261 215
262 static void CallRuntimePassFunction(MacroAssembler* masm, 216 static void CallRuntimePassFunction(MacroAssembler* masm,
263 Runtime::FunctionId function_id) { 217 Runtime::FunctionId function_id) {
264 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); 218 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
265 // Push a copy of the function onto the stack. 219 // Push a copy of the function onto the stack.
266 // Push function as parameter to the runtime call. 220 // Push function as parameter to the runtime call.
267 __ Push(r4, r4); 221 __ Push(r4, r4);
268 222
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 __ bkpt(0); 1784 __ bkpt(0);
1831 } 1785 }
1832 } 1786 }
1833 1787
1834 1788
1835 #undef __ 1789 #undef __
1836 } // namespace internal 1790 } // namespace internal
1837 } // namespace v8 1791 } // namespace v8
1838 1792
1839 #endif // V8_TARGET_ARCH_PPC 1793 #endif // V8_TARGET_ARCH_PPC
OLDNEW
« no previous file with comments | « no previous file | src/ppc/macro-assembler-ppc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698