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_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
10 #include "src/ic/handler-compiler.h" | 10 #include "src/ic/handler-compiler.h" |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 if (exponent_type() == ON_STACK) { | 332 if (exponent_type() == ON_STACK) { |
333 // Detect square root case. Crankshaft detects constant +/-0.5 at | 333 // Detect square root case. Crankshaft detects constant +/-0.5 at |
334 // compile time and uses DoMathPowHalf instead. We then skip this check | 334 // compile time and uses DoMathPowHalf instead. We then skip this check |
335 // for non-constant cases of +/-0.5 as these hardly occur. | 335 // for non-constant cases of +/-0.5 as these hardly occur. |
336 Label continue_sqrt, continue_rsqrt, not_plus_half; | 336 Label continue_sqrt, continue_rsqrt, not_plus_half; |
337 // Test for 0.5. | 337 // Test for 0.5. |
338 // Load double_scratch with 0.5. | 338 // Load double_scratch with 0.5. |
339 __ movq(scratch, V8_UINT64_C(0x3FE0000000000000)); | 339 __ movq(scratch, V8_UINT64_C(0x3FE0000000000000)); |
340 __ Movq(double_scratch, scratch); | 340 __ Movq(double_scratch, scratch); |
341 // Already ruled out NaNs for exponent. | 341 // Already ruled out NaNs for exponent. |
342 __ ucomisd(double_scratch, double_exponent); | 342 __ Ucomisd(double_scratch, double_exponent); |
343 __ j(not_equal, ¬_plus_half, Label::kNear); | 343 __ j(not_equal, ¬_plus_half, Label::kNear); |
344 | 344 |
345 // Calculates square root of base. Check for the special case of | 345 // Calculates square root of base. Check for the special case of |
346 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). | 346 // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
347 // According to IEEE-754, double-precision -Infinity has the highest | 347 // According to IEEE-754, double-precision -Infinity has the highest |
348 // 12 bits set and the lowest 52 bits cleared. | 348 // 12 bits set and the lowest 52 bits cleared. |
349 __ movq(scratch, V8_UINT64_C(0xFFF0000000000000)); | 349 __ movq(scratch, V8_UINT64_C(0xFFF0000000000000)); |
350 __ Movq(double_scratch, scratch); | 350 __ Movq(double_scratch, scratch); |
351 __ ucomisd(double_scratch, double_base); | 351 __ Ucomisd(double_scratch, double_base); |
352 // Comparing -Infinity with NaN results in "unordered", which sets the | 352 // Comparing -Infinity with NaN results in "unordered", which sets the |
353 // zero flag as if both were equal. However, it also sets the carry flag. | 353 // zero flag as if both were equal. However, it also sets the carry flag. |
354 __ j(not_equal, &continue_sqrt, Label::kNear); | 354 __ j(not_equal, &continue_sqrt, Label::kNear); |
355 __ j(carry, &continue_sqrt, Label::kNear); | 355 __ j(carry, &continue_sqrt, Label::kNear); |
356 | 356 |
357 // Set result to Infinity in the special case. | 357 // Set result to Infinity in the special case. |
358 __ Xorpd(double_result, double_result); | 358 __ Xorpd(double_result, double_result); |
359 __ subsd(double_result, double_scratch); | 359 __ subsd(double_result, double_scratch); |
360 __ jmp(&done); | 360 __ jmp(&done); |
361 | 361 |
362 __ bind(&continue_sqrt); | 362 __ bind(&continue_sqrt); |
363 // sqrtsd returns -0 when input is -0. ECMA spec requires +0. | 363 // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
364 __ Xorpd(double_scratch, double_scratch); | 364 __ Xorpd(double_scratch, double_scratch); |
365 __ addsd(double_scratch, double_base); // Convert -0 to 0. | 365 __ addsd(double_scratch, double_base); // Convert -0 to 0. |
366 __ sqrtsd(double_result, double_scratch); | 366 __ sqrtsd(double_result, double_scratch); |
367 __ jmp(&done); | 367 __ jmp(&done); |
368 | 368 |
369 // Test for -0.5. | 369 // Test for -0.5. |
370 __ bind(¬_plus_half); | 370 __ bind(¬_plus_half); |
371 // Load double_scratch with -0.5 by substracting 1. | 371 // Load double_scratch with -0.5 by substracting 1. |
372 __ subsd(double_scratch, double_result); | 372 __ subsd(double_scratch, double_result); |
373 // Already ruled out NaNs for exponent. | 373 // Already ruled out NaNs for exponent. |
374 __ ucomisd(double_scratch, double_exponent); | 374 __ Ucomisd(double_scratch, double_exponent); |
375 __ j(not_equal, &fast_power, Label::kNear); | 375 __ j(not_equal, &fast_power, Label::kNear); |
376 | 376 |
377 // Calculates reciprocal of square root of base. Check for the special | 377 // Calculates reciprocal of square root of base. Check for the special |
378 // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). | 378 // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
379 // According to IEEE-754, double-precision -Infinity has the highest | 379 // According to IEEE-754, double-precision -Infinity has the highest |
380 // 12 bits set and the lowest 52 bits cleared. | 380 // 12 bits set and the lowest 52 bits cleared. |
381 __ movq(scratch, V8_UINT64_C(0xFFF0000000000000)); | 381 __ movq(scratch, V8_UINT64_C(0xFFF0000000000000)); |
382 __ Movq(double_scratch, scratch); | 382 __ Movq(double_scratch, scratch); |
383 __ ucomisd(double_scratch, double_base); | 383 __ Ucomisd(double_scratch, double_base); |
384 // Comparing -Infinity with NaN results in "unordered", which sets the | 384 // Comparing -Infinity with NaN results in "unordered", which sets the |
385 // zero flag as if both were equal. However, it also sets the carry flag. | 385 // zero flag as if both were equal. However, it also sets the carry flag. |
386 __ j(not_equal, &continue_rsqrt, Label::kNear); | 386 __ j(not_equal, &continue_rsqrt, Label::kNear); |
387 __ j(carry, &continue_rsqrt, Label::kNear); | 387 __ j(carry, &continue_rsqrt, Label::kNear); |
388 | 388 |
389 // Set result to 0 in the special case. | 389 // Set result to 0 in the special case. |
390 __ Xorpd(double_result, double_result); | 390 __ Xorpd(double_result, double_result); |
391 __ jmp(&done); | 391 __ jmp(&done); |
392 | 392 |
393 __ bind(&continue_rsqrt); | 393 __ bind(&continue_rsqrt); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 472 |
473 __ bind(&while_false); | 473 __ bind(&while_false); |
474 // If the exponent is negative, return 1/result. | 474 // If the exponent is negative, return 1/result. |
475 __ testl(exponent, exponent); | 475 __ testl(exponent, exponent); |
476 __ j(greater, &done); | 476 __ j(greater, &done); |
477 __ divsd(double_scratch2, double_result); | 477 __ divsd(double_scratch2, double_result); |
478 __ Movsd(double_result, double_scratch2); | 478 __ Movsd(double_result, double_scratch2); |
479 // Test whether result is zero. Bail out to check for subnormal result. | 479 // Test whether result is zero. Bail out to check for subnormal result. |
480 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. | 480 // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
481 __ Xorpd(double_scratch2, double_scratch2); | 481 __ Xorpd(double_scratch2, double_scratch2); |
482 __ ucomisd(double_scratch2, double_result); | 482 __ Ucomisd(double_scratch2, double_result); |
483 // double_exponent aliased as double_scratch2 has already been overwritten | 483 // double_exponent aliased as double_scratch2 has already been overwritten |
484 // and may not have contained the exponent value in the first place when the | 484 // and may not have contained the exponent value in the first place when the |
485 // input was a smi. We reset it with exponent value before bailing out. | 485 // input was a smi. We reset it with exponent value before bailing out. |
486 __ j(not_equal, &done); | 486 __ j(not_equal, &done); |
487 __ Cvtlsi2sd(double_exponent, exponent); | 487 __ Cvtlsi2sd(double_exponent, exponent); |
488 | 488 |
489 // Returning or bailing out. | 489 // Returning or bailing out. |
490 Counters* counters = isolate()->counters(); | 490 Counters* counters = isolate()->counters(); |
491 if (exponent_type() == ON_STACK) { | 491 if (exponent_type() == ON_STACK) { |
492 // The arguments are still on the stack. | 492 // The arguments are still on the stack. |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 __ Set(rax, EQUAL); | 1559 __ Set(rax, EQUAL); |
1560 __ ret(0); | 1560 __ ret(0); |
1561 | 1561 |
1562 __ bind(&heap_number); | 1562 __ bind(&heap_number); |
1563 // It is a heap number, so return equal if it's not NaN. | 1563 // It is a heap number, so return equal if it's not NaN. |
1564 // For NaN, return 1 for every condition except greater and | 1564 // For NaN, return 1 for every condition except greater and |
1565 // greater-equal. Return -1 for them, so the comparison yields | 1565 // greater-equal. Return -1 for them, so the comparison yields |
1566 // false for all conditions except not-equal. | 1566 // false for all conditions except not-equal. |
1567 __ Set(rax, EQUAL); | 1567 __ Set(rax, EQUAL); |
1568 __ Movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); | 1568 __ Movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); |
1569 __ ucomisd(xmm0, xmm0); | 1569 __ Ucomisd(xmm0, xmm0); |
1570 __ setcc(parity_even, rax); | 1570 __ setcc(parity_even, rax); |
1571 // rax is 0 for equal non-NaN heapnumbers, 1 for NaNs. | 1571 // rax is 0 for equal non-NaN heapnumbers, 1 for NaNs. |
1572 if (cc == greater_equal || cc == greater) { | 1572 if (cc == greater_equal || cc == greater) { |
1573 __ negp(rax); | 1573 __ negp(rax); |
1574 } | 1574 } |
1575 __ ret(0); | 1575 __ ret(0); |
1576 | 1576 |
1577 __ bind(¬_identical); | 1577 __ bind(¬_identical); |
1578 } | 1578 } |
1579 | 1579 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 } | 1634 } |
1635 __ bind(&slow); | 1635 __ bind(&slow); |
1636 } | 1636 } |
1637 | 1637 |
1638 // Generate the number comparison code. | 1638 // Generate the number comparison code. |
1639 Label non_number_comparison; | 1639 Label non_number_comparison; |
1640 Label unordered; | 1640 Label unordered; |
1641 FloatingPointHelper::LoadSSE2UnknownOperands(masm, &non_number_comparison); | 1641 FloatingPointHelper::LoadSSE2UnknownOperands(masm, &non_number_comparison); |
1642 __ xorl(rax, rax); | 1642 __ xorl(rax, rax); |
1643 __ xorl(rcx, rcx); | 1643 __ xorl(rcx, rcx); |
1644 __ ucomisd(xmm0, xmm1); | 1644 __ Ucomisd(xmm0, xmm1); |
1645 | 1645 |
1646 // Don't base result on EFLAGS when a NaN is involved. | 1646 // Don't base result on EFLAGS when a NaN is involved. |
1647 __ j(parity_even, &unordered, Label::kNear); | 1647 __ j(parity_even, &unordered, Label::kNear); |
1648 // Return a result of -1, 0, or 1, based on EFLAGS. | 1648 // Return a result of -1, 0, or 1, based on EFLAGS. |
1649 __ setcc(above, rax); | 1649 __ setcc(above, rax); |
1650 __ setcc(below, rcx); | 1650 __ setcc(below, rcx); |
1651 __ subp(rax, rcx); | 1651 __ subp(rax, rcx); |
1652 __ ret(0); | 1652 __ ret(0); |
1653 | 1653 |
1654 // If one of the numbers was NaN, then the result is always false. | 1654 // If one of the numbers was NaN, then the result is always false. |
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3445 __ CompareMap(rdx, isolate()->factory()->heap_number_map()); | 3445 __ CompareMap(rdx, isolate()->factory()->heap_number_map()); |
3446 __ j(not_equal, &maybe_undefined2, Label::kNear); | 3446 __ j(not_equal, &maybe_undefined2, Label::kNear); |
3447 __ Movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); | 3447 __ Movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset)); |
3448 __ jmp(&done); | 3448 __ jmp(&done); |
3449 __ bind(&left_smi); | 3449 __ bind(&left_smi); |
3450 __ SmiToInteger32(rcx, rdx); // Can't clobber rdx yet. | 3450 __ SmiToInteger32(rcx, rdx); // Can't clobber rdx yet. |
3451 __ Cvtlsi2sd(xmm0, rcx); | 3451 __ Cvtlsi2sd(xmm0, rcx); |
3452 | 3452 |
3453 __ bind(&done); | 3453 __ bind(&done); |
3454 // Compare operands | 3454 // Compare operands |
3455 __ ucomisd(xmm0, xmm1); | 3455 __ Ucomisd(xmm0, xmm1); |
3456 | 3456 |
3457 // Don't base result on EFLAGS when a NaN is involved. | 3457 // Don't base result on EFLAGS when a NaN is involved. |
3458 __ j(parity_even, &unordered, Label::kNear); | 3458 __ j(parity_even, &unordered, Label::kNear); |
3459 | 3459 |
3460 // Return a result of -1, 0, or 1, based on EFLAGS. | 3460 // Return a result of -1, 0, or 1, based on EFLAGS. |
3461 // Performing mov, because xor would destroy the flag register. | 3461 // Performing mov, because xor would destroy the flag register. |
3462 __ movl(rax, Immediate(0)); | 3462 __ movl(rax, Immediate(0)); |
3463 __ movl(rcx, Immediate(0)); | 3463 __ movl(rcx, Immediate(0)); |
3464 __ setcc(above, rax); // Add one to zero if carry clear and not equal. | 3464 __ setcc(above, rax); // Add one to zero if carry clear and not equal. |
3465 __ sbbp(rax, rcx); // Subtract one if below (aka. carry set). | 3465 __ sbbp(rax, rcx); // Subtract one if below (aka. carry set). |
(...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5576 kStackSpace, nullptr, return_value_operand, NULL); | 5576 kStackSpace, nullptr, return_value_operand, NULL); |
5577 } | 5577 } |
5578 | 5578 |
5579 | 5579 |
5580 #undef __ | 5580 #undef __ |
5581 | 5581 |
5582 } // namespace internal | 5582 } // namespace internal |
5583 } // namespace v8 | 5583 } // namespace v8 |
5584 | 5584 |
5585 #endif // V8_TARGET_ARCH_X64 | 5585 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |