OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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_ARM64 | 5 #if V8_TARGET_ARCH_ARM64 |
6 | 6 |
7 #include "src/arm64/frames-arm64.h" | 7 #include "src/arm64/frames-arm64.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // static | 140 // static |
141 void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) { | 141 void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) { |
142 // ----------- S t a t e ------------- | 142 // ----------- S t a t e ------------- |
143 // -- x0 : number of arguments | 143 // -- x0 : number of arguments |
144 // -- lr : return address | 144 // -- lr : return address |
145 // -- sp[(argc - n) * 8] : arg[n] (zero-based) | 145 // -- sp[(argc - n) * 8] : arg[n] (zero-based) |
146 // -- sp[(argc + 1) * 8] : receiver | 146 // -- sp[(argc + 1) * 8] : receiver |
147 // ----------------------------------- | 147 // ----------------------------------- |
148 ASM_LOCATION("Builtins::Generate_MathMaxMin"); | 148 ASM_LOCATION("Builtins::Generate_MathMaxMin"); |
149 | 149 |
150 Condition const cc_done = (kind == MathMaxMinKind::kMin) ? mi : gt; | |
151 Condition const cc_swap = (kind == MathMaxMinKind::kMin) ? gt : mi; | |
152 Heap::RootListIndex const root_index = | 150 Heap::RootListIndex const root_index = |
153 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex | 151 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex |
154 : Heap::kMinusInfinityValueRootIndex; | 152 : Heap::kMinusInfinityValueRootIndex; |
155 DoubleRegister const reg = (kind == MathMaxMinKind::kMin) ? d2 : d1; | |
156 | 153 |
157 // Load the accumulator with the default return value (either -Infinity or | 154 // Load the accumulator with the default return value (either -Infinity or |
158 // +Infinity), with the tagged value in x1 and the double value in d1. | 155 // +Infinity), with the tagged value in x1 and the double value in d1. |
159 __ LoadRoot(x1, root_index); | 156 __ LoadRoot(x1, root_index); |
160 __ Ldr(d1, FieldMemOperand(x1, HeapNumber::kValueOffset)); | 157 __ Ldr(d1, FieldMemOperand(x1, HeapNumber::kValueOffset)); |
161 __ Mov(x4, x0); | 158 |
| 159 // Remember how many slots to drop (including the receiver). |
| 160 __ Add(x4, x0, 1); |
162 | 161 |
163 Label done_loop, loop; | 162 Label done_loop, loop; |
164 __ Bind(&loop); | 163 __ Bind(&loop); |
165 { | 164 { |
166 // Check if all parameters done. | 165 // Check if all parameters done. |
167 __ Subs(x0, x0, 1); | 166 __ Subs(x0, x0, 1); |
168 __ B(lt, &done_loop); | 167 __ B(lt, &done_loop); |
169 | 168 |
170 // Load the next parameter tagged value into x2. | 169 // Load the next parameter tagged value into x2. |
171 __ Peek(x2, Operand(x0, LSL, kPointerSizeLog2)); | 170 __ Peek(x2, Operand(x0, LSL, kPointerSizeLog2)); |
172 | 171 |
173 // Load the double value of the parameter into d2, maybe converting the | 172 // Load the double value of the parameter into d2, maybe converting the |
174 // parameter to a number first using the ToNumberStub if necessary. | 173 // parameter to a number first using the ToNumberStub if necessary. |
175 Label convert, convert_smi, convert_number, done_convert; | 174 Label convert_smi, convert_number, done_convert; |
176 __ Bind(&convert); | |
177 __ JumpIfSmi(x2, &convert_smi); | 175 __ JumpIfSmi(x2, &convert_smi); |
178 __ Ldr(x3, FieldMemOperand(x2, HeapObject::kMapOffset)); | 176 __ JumpIfHeapNumber(x2, &convert_number); |
179 __ JumpIfRoot(x3, Heap::kHeapNumberMapRootIndex, &convert_number); | |
180 { | 177 { |
181 // Parameter is not a Number, use the ToNumberStub to convert it. | 178 // Parameter is not a Number, use the ToNumberStub to convert it. |
182 FrameScope scope(masm, StackFrame::INTERNAL); | 179 FrameScope scope(masm, StackFrame::INTERNAL); |
183 __ SmiTag(x0); | 180 __ SmiTag(x0); |
184 __ SmiTag(x4); | 181 __ SmiTag(x4); |
185 __ Push(x0, x1, x4); | 182 __ Push(x0, x1, x4); |
186 __ Mov(x0, x2); | 183 __ Mov(x0, x2); |
187 ToNumberStub stub(masm->isolate()); | 184 ToNumberStub stub(masm->isolate()); |
188 __ CallStub(&stub); | 185 __ CallStub(&stub); |
189 __ Mov(x2, x0); | 186 __ Mov(x2, x0); |
190 __ Pop(x4, x1, x0); | 187 __ Pop(x4, x1, x0); |
191 { | 188 { |
192 // Restore the double accumulator value (d1). | 189 // Restore the double accumulator value (d1). |
193 Label restore_smi, done_restore; | 190 Label done_restore; |
194 __ JumpIfSmi(x1, &restore_smi); | 191 __ SmiUntagToDouble(d1, x1, kSpeculativeUntag); |
| 192 __ JumpIfSmi(x1, &done_restore); |
195 __ Ldr(d1, FieldMemOperand(x1, HeapNumber::kValueOffset)); | 193 __ Ldr(d1, FieldMemOperand(x1, HeapNumber::kValueOffset)); |
196 __ B(&done_restore); | 194 __ Bind(&done_restore); |
197 __ Bind(&restore_smi); | |
198 __ SmiUntagToDouble(d1, x1); | |
199 __ bind(&done_restore); | |
200 } | 195 } |
201 __ SmiUntag(x4); | 196 __ SmiUntag(x4); |
202 __ SmiUntag(x0); | 197 __ SmiUntag(x0); |
203 } | 198 } |
204 __ B(&convert); | 199 __ AssertNumber(x2); |
| 200 __ JumpIfSmi(x2, &convert_smi); |
| 201 |
205 __ Bind(&convert_number); | 202 __ Bind(&convert_number); |
206 __ Ldr(d2, FieldMemOperand(x2, HeapNumber::kValueOffset)); | 203 __ Ldr(d2, FieldMemOperand(x2, HeapNumber::kValueOffset)); |
207 __ B(&done_convert); | 204 __ B(&done_convert); |
| 205 |
208 __ Bind(&convert_smi); | 206 __ Bind(&convert_smi); |
209 __ SmiUntagToDouble(d2, x2); | 207 __ SmiUntagToDouble(d2, x2); |
210 __ Bind(&done_convert); | 208 __ Bind(&done_convert); |
211 | 209 |
212 // Perform the actual comparison with the accumulator value on the left hand | 210 // We can use a single fmin/fmax for the operation itself, but we then need |
213 // side (d1) and the next parameter value on the right hand side (d2). | 211 // to work out which HeapNumber (or smi) the result came from. |
214 Label compare_nan, compare_swap; | 212 __ Fmov(x11, d1); |
215 __ Fcmp(d1, d2); | 213 if (kind == MathMaxMinKind::kMin) { |
216 __ B(cc_done, &loop); | 214 __ Fmin(d1, d1, d2); |
217 __ B(cc_swap, &compare_swap); | 215 } else { |
218 __ B(vs, &compare_nan); | 216 DCHECK(kind == MathMaxMinKind::kMax); |
219 | 217 __ Fmax(d1, d1, d2); |
220 // Left and right hand side are equal, check for -0 vs. +0. | 218 } |
221 __ Fmov(x3, reg); | 219 __ Fmov(x10, d1); |
222 __ TestAndBranchIfAllClear(x3, V8_INT64_C(0x8000000000000000), &loop); | 220 __ Cmp(x10, x11); |
223 | 221 __ Csel(x1, x1, x2, eq); |
224 // Result is on the right hand side. | |
225 __ Bind(&compare_swap); | |
226 __ Fmov(d1, d2); | |
227 __ Mov(x1, x2); | |
228 __ B(&loop); | |
229 | |
230 // At least one side is NaN, which means that the result will be NaN too. | |
231 __ Bind(&compare_nan); | |
232 __ LoadRoot(x1, Heap::kNanValueRootIndex); | |
233 __ Ldr(d1, FieldMemOperand(x1, HeapNumber::kValueOffset)); | |
234 __ B(&loop); | 222 __ B(&loop); |
235 } | 223 } |
236 | 224 |
237 __ Bind(&done_loop); | 225 __ Bind(&done_loop); |
238 __ Mov(x0, x1); | 226 __ Mov(x0, x1); |
239 __ Drop(x4); | 227 __ Drop(x4); |
240 __ Drop(1); | |
241 __ Ret(); | 228 __ Ret(); |
242 } | 229 } |
243 | 230 |
244 // static | 231 // static |
245 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { | 232 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { |
246 // ----------- S t a t e ------------- | 233 // ----------- S t a t e ------------- |
247 // -- x0 : number of arguments | 234 // -- x0 : number of arguments |
248 // -- x1 : constructor function | 235 // -- x1 : constructor function |
249 // -- lr : return address | 236 // -- lr : return address |
250 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based) | 237 // -- sp[(argc - n - 1) * 8] : arg[n] (zero based) |
(...skipping 2598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2849 } | 2836 } |
2850 } | 2837 } |
2851 | 2838 |
2852 | 2839 |
2853 #undef __ | 2840 #undef __ |
2854 | 2841 |
2855 } // namespace internal | 2842 } // namespace internal |
2856 } // namespace v8 | 2843 } // namespace v8 |
2857 | 2844 |
2858 #endif // V8_TARGET_ARCH_ARM | 2845 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |