OLD | NEW |
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 __ mr(r6, r4); | 129 __ mr(r6, r4); |
130 // Run the native code for the Array function called as a normal function. | 130 // Run the native code for the Array function called as a normal function. |
131 // tail call a stub | 131 // tail call a stub |
132 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); | 132 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); |
133 ArrayConstructorStub stub(masm->isolate()); | 133 ArrayConstructorStub stub(masm->isolate()); |
134 __ TailCallStub(&stub); | 134 __ TailCallStub(&stub); |
135 } | 135 } |
136 | 136 |
137 | 137 |
138 // static | 138 // static |
| 139 void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) { |
| 140 // ----------- S t a t e ------------- |
| 141 // -- r3 : number of arguments |
| 142 // -- lr : return address |
| 143 // -- sp[(argc - n) * 8] : arg[n] (zero-based) |
| 144 // -- sp[(argc + 1) * 8] : receiver |
| 145 // ----------------------------------- |
| 146 Condition const cond_done = (kind == MathMaxMinKind::kMin) ? lt : gt; |
| 147 Heap::RootListIndex const root_index = |
| 148 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex |
| 149 : Heap::kMinusInfinityValueRootIndex; |
| 150 DoubleRegister const reg = (kind == MathMaxMinKind::kMin) ? d2 : d1; |
| 151 |
| 152 // Load the accumulator with the default return value (either -Infinity or |
| 153 // +Infinity), with the tagged value in r4 and the double value in d1. |
| 154 __ LoadRoot(r4, root_index); |
| 155 __ lfd(d1, FieldMemOperand(r4, HeapNumber::kValueOffset)); |
| 156 |
| 157 // Setup state for loop |
| 158 // r5: address of arg[0] + kPointerSize |
| 159 // r6: number of arguments |
| 160 __ ShiftLeftImm(r5, r3, Operand(kPointerSizeLog2)); |
| 161 __ add(r5, sp, r5); |
| 162 __ mr(r6, r3); |
| 163 |
| 164 Label done_loop, loop; |
| 165 __ bind(&loop); |
| 166 { |
| 167 // Check if all parameters done. |
| 168 __ cmpl(r5, sp); |
| 169 __ ble(&done_loop); |
| 170 |
| 171 // Load the next parameter tagged value into r3. |
| 172 __ LoadPU(r3, MemOperand(r5, -kPointerSize)); |
| 173 |
| 174 // Load the double value of the parameter into d2, maybe converting the |
| 175 // parameter to a number first using the ToNumberStub if necessary. |
| 176 Label convert, convert_smi, convert_number, done_convert; |
| 177 __ bind(&convert); |
| 178 __ JumpIfSmi(r3, &convert_smi); |
| 179 __ LoadP(r7, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 180 __ JumpIfRoot(r7, Heap::kHeapNumberMapRootIndex, &convert_number); |
| 181 { |
| 182 // Parameter is not a Number, use the ToNumberStub to convert it. |
| 183 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL); |
| 184 __ SmiTag(r6); |
| 185 __ Push(r4, r5, r6); |
| 186 ToNumberStub stub(masm->isolate()); |
| 187 __ CallStub(&stub); |
| 188 __ Pop(r4, r5, r6); |
| 189 __ SmiUntag(r6); |
| 190 { |
| 191 // Restore the double accumulator value (d1). |
| 192 Label restore_smi, done_restore; |
| 193 __ JumpIfSmi(r4, &restore_smi); |
| 194 __ lfd(d1, FieldMemOperand(r4, HeapNumber::kValueOffset)); |
| 195 __ b(&done_restore); |
| 196 __ bind(&restore_smi); |
| 197 __ SmiToDouble(d1, r4); |
| 198 __ bind(&done_restore); |
| 199 } |
| 200 } |
| 201 __ b(&convert); |
| 202 __ bind(&convert_number); |
| 203 __ lfd(d2, FieldMemOperand(r3, HeapNumber::kValueOffset)); |
| 204 __ b(&done_convert); |
| 205 __ bind(&convert_smi); |
| 206 __ SmiToDouble(d2, r3); |
| 207 __ bind(&done_convert); |
| 208 |
| 209 // Perform the actual comparison with the accumulator value on the left hand |
| 210 // side (d1) and the next parameter value on the right hand side (d2). |
| 211 Label compare_nan, compare_swap; |
| 212 __ fcmpu(d1, d2); |
| 213 __ bunordered(&compare_nan); |
| 214 __ b(cond_done, &loop); |
| 215 __ b(CommuteCondition(cond_done), &compare_swap); |
| 216 |
| 217 // Left and right hand side are equal, check for -0 vs. +0. |
| 218 #if V8_TARGET_ARCH_PPC64 |
| 219 __ MovDoubleToInt64(r7, reg); |
| 220 __ rotldi(r7, r7, 1); |
| 221 __ cmpi(r7, Operand(1)); |
| 222 #else |
| 223 __ MovDoubleToInt64(r7, r8, reg); |
| 224 __ cmpi(r8, Operand::Zero()); |
| 225 __ bne(&loop); |
| 226 __ lis(r8, Operand(SIGN_EXT_IMM16(0x8000))); |
| 227 __ cmp(r7, r8); |
| 228 #endif |
| 229 __ bne(&loop); |
| 230 |
| 231 // Update accumulator. Result is on the right hand side. |
| 232 __ bind(&compare_swap); |
| 233 __ fmr(d1, d2); |
| 234 __ mr(r4, r3); |
| 235 __ b(&loop); |
| 236 |
| 237 // At least one side is NaN, which means that the result will be NaN too. |
| 238 // We still need to visit the rest of the arguments. |
| 239 __ bind(&compare_nan); |
| 240 __ LoadRoot(r4, Heap::kNanValueRootIndex); |
| 241 __ lfd(d1, FieldMemOperand(r4, HeapNumber::kValueOffset)); |
| 242 __ b(&loop); |
| 243 } |
| 244 |
| 245 __ bind(&done_loop); |
| 246 __ mr(r3, r4); |
| 247 __ Drop(r6); |
| 248 __ Ret(1); |
| 249 } |
| 250 |
| 251 // static |
139 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { | 252 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { |
140 // ----------- S t a t e ------------- | 253 // ----------- S t a t e ------------- |
141 // -- r3 : number of arguments | 254 // -- r3 : number of arguments |
142 // -- r4 : constructor function | 255 // -- r4 : constructor function |
143 // -- lr : return address | 256 // -- lr : return address |
144 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) | 257 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based) |
145 // -- sp[argc * 4] : receiver | 258 // -- sp[argc * 4] : receiver |
146 // ----------------------------------- | 259 // ----------------------------------- |
147 | 260 |
148 // 1. Load the first argument into r3 and get rid of the rest (including the | 261 // 1. Load the first argument into r3 and get rid of the rest (including the |
(...skipping 2519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2668 __ bkpt(0); | 2781 __ bkpt(0); |
2669 } | 2782 } |
2670 } | 2783 } |
2671 | 2784 |
2672 | 2785 |
2673 #undef __ | 2786 #undef __ |
2674 } // namespace internal | 2787 } // namespace internal |
2675 } // namespace v8 | 2788 } // namespace v8 |
2676 | 2789 |
2677 #endif // V8_TARGET_ARCH_PPC | 2790 #endif // V8_TARGET_ARCH_PPC |
OLD | NEW |