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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
394 // sqrtsd returns -0 when input is -0. ECMA spec requires +0. | 394 // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
395 __ Xorpd(double_exponent, double_exponent); | 395 __ Xorpd(double_exponent, double_exponent); |
396 __ addsd(double_exponent, double_base); // Convert -0 to +0. | 396 __ Addsd(double_exponent, double_base); // Convert -0 to +0. |
397 __ Sqrtsd(double_exponent, double_exponent); | 397 __ Sqrtsd(double_exponent, double_exponent); |
398 __ divsd(double_result, double_exponent); | 398 __ Divsd(double_result, double_exponent); |
399 __ jmp(&done); | 399 __ jmp(&done); |
400 } | 400 } |
401 | 401 |
402 // Using FPU instructions to calculate power. | 402 // Using FPU instructions to calculate power. |
403 Label fast_power_failed; | 403 Label fast_power_failed; |
404 __ bind(&fast_power); | 404 __ bind(&fast_power); |
405 __ fnclex(); // Clear flags to catch exceptions later. | 405 __ fnclex(); // Clear flags to catch exceptions later. |
406 // Transfer (B)ase and (E)xponent onto the FPU register stack. | 406 // Transfer (B)ase and (E)xponent onto the FPU register stack. |
407 __ subp(rsp, Immediate(kDoubleSize)); | 407 __ subp(rsp, Immediate(kDoubleSize)); |
408 __ Movsd(Operand(rsp, 0), double_exponent); | 408 __ Movsd(Operand(rsp, 0), double_exponent); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 __ j(zero, &while_false, Label::kNear); | 458 __ j(zero, &while_false, Label::kNear); |
459 __ shrl(scratch, Immediate(1)); | 459 __ shrl(scratch, Immediate(1)); |
460 // Above condition means CF==0 && ZF==0. This means that the | 460 // Above condition means CF==0 && ZF==0. This means that the |
461 // bit that has been shifted out is 0 and the result is not 0. | 461 // bit that has been shifted out is 0 and the result is not 0. |
462 __ j(above, &while_true, Label::kNear); | 462 __ j(above, &while_true, Label::kNear); |
463 __ Movsd(double_result, double_scratch); | 463 __ Movsd(double_result, double_scratch); |
464 __ j(zero, &while_false, Label::kNear); | 464 __ j(zero, &while_false, Label::kNear); |
465 | 465 |
466 __ bind(&while_true); | 466 __ bind(&while_true); |
467 __ shrl(scratch, Immediate(1)); | 467 __ shrl(scratch, Immediate(1)); |
468 __ mulsd(double_scratch, double_scratch); | 468 __ Mulsd(double_scratch, double_scratch); |
469 __ j(above, &while_true, Label::kNear); | 469 __ j(above, &while_true, Label::kNear); |
470 __ mulsd(double_result, double_scratch); | 470 __ Mulsd(double_result, double_scratch); |
471 __ j(not_zero, &while_true); | 471 __ j(not_zero, &while_true); |
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); |
(...skipping 5107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5595 kStackSpace, nullptr, return_value_operand, NULL); | 5595 kStackSpace, nullptr, return_value_operand, NULL); |
5596 } | 5596 } |
5597 | 5597 |
5598 | 5598 |
5599 #undef __ | 5599 #undef __ |
5600 | 5600 |
5601 } // namespace internal | 5601 } // namespace internal |
5602 } // namespace v8 | 5602 } // namespace v8 |
5603 | 5603 |
5604 #endif // V8_TARGET_ARCH_X64 | 5604 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |