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

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

Issue 1641083003: [builtins] Make Math.max and Math.min fast by default. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: SKIP unrelated ignition failures. Created 4 years, 10 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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_IA32 5 #if V8_TARGET_ARCH_IA32
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/codegen.h" 8 #include "src/codegen.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 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1409
1410 // Run the native code for the Array function called as a normal function. 1410 // Run the native code for the Array function called as a normal function.
1411 // tail call a stub 1411 // tail call a stub
1412 __ mov(ebx, masm->isolate()->factory()->undefined_value()); 1412 __ mov(ebx, masm->isolate()->factory()->undefined_value());
1413 ArrayConstructorStub stub(masm->isolate()); 1413 ArrayConstructorStub stub(masm->isolate());
1414 __ TailCallStub(&stub); 1414 __ TailCallStub(&stub);
1415 } 1415 }
1416 1416
1417 1417
1418 // static 1418 // static
1419 void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) {
1420 // ----------- S t a t e -------------
1421 // -- eax : number of arguments
1422 // -- esp[0] : return address
1423 // -- esp[(argc - n) * 8] : arg[n] (zero-based)
1424 // -- esp[(argc + 1) * 8] : receiver
1425 // -----------------------------------
1426 Condition const cc = (kind == MathMaxMinKind::kMin) ? below : above;
1427 Heap::RootListIndex const root_index =
1428 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex
1429 : Heap::kMinusInfinityValueRootIndex;
1430 XMMRegister const reg = (kind == MathMaxMinKind::kMin) ? xmm1 : xmm0;
1431
1432 // Load the accumulator with the default return value (either -Infinity or
1433 // +Infinity), with the tagged value in edx and the double value in xmm0.
1434 __ LoadRoot(edx, root_index);
1435 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
1436 __ Move(ecx, eax);
1437
1438 Label done_loop, loop;
1439 __ bind(&loop);
1440 {
1441 // Check if all parameters done.
1442 __ test(ecx, ecx);
1443 __ j(zero, &done_loop);
1444
1445 // Load the next parameter tagged value into ebx.
1446 __ mov(ebx, Operand(esp, ecx, times_pointer_size, 0));
1447
1448 // Load the double value of the parameter into xmm1, maybe converting the
1449 // parameter to a number first using the ToNumberStub if necessary.
1450 Label convert, convert_smi, convert_number, done_convert;
1451 __ bind(&convert);
1452 __ JumpIfSmi(ebx, &convert_smi);
1453 __ JumpIfRoot(FieldOperand(ebx, HeapObject::kMapOffset),
1454 Heap::kHeapNumberMapRootIndex, &convert_number);
1455 {
1456 // Parameter is not a Number, use the ToNumberStub to convert it.
1457 FrameScope scope(masm, StackFrame::INTERNAL);
1458 __ SmiTag(eax);
1459 __ SmiTag(ecx);
1460 __ Push(eax);
1461 __ Push(ecx);
1462 __ Push(edx);
1463 __ mov(eax, ebx);
1464 ToNumberStub stub(masm->isolate());
1465 __ CallStub(&stub);
1466 __ mov(ebx, eax);
1467 __ Pop(edx);
1468 __ Pop(ecx);
1469 __ Pop(eax);
1470 {
1471 // Restore the double accumulator value (xmm0).
1472 Label restore_smi, done_restore;
1473 __ JumpIfSmi(edx, &restore_smi, Label::kNear);
1474 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
1475 __ jmp(&done_restore, Label::kNear);
1476 __ bind(&restore_smi);
1477 __ SmiUntag(edx);
1478 __ Cvtsi2sd(xmm0, edx);
1479 __ SmiTag(edx);
1480 __ bind(&done_restore);
1481 }
1482 __ SmiUntag(ecx);
1483 __ SmiUntag(eax);
1484 }
1485 __ jmp(&convert);
1486 __ bind(&convert_number);
1487 __ movsd(xmm1, FieldOperand(ebx, HeapNumber::kValueOffset));
1488 __ jmp(&done_convert, Label::kNear);
1489 __ bind(&convert_smi);
1490 __ SmiUntag(ebx);
1491 __ Cvtsi2sd(xmm1, ebx);
1492 __ SmiTag(ebx);
1493 __ bind(&done_convert);
1494
1495 // Perform the actual comparison with the accumulator value on the left hand
1496 // side (xmm0) and the next parameter value on the right hand side (xmm1).
1497 Label compare_equal, compare_nan, compare_swap, done_compare;
1498 __ ucomisd(xmm0, xmm1);
1499 __ j(parity_even, &compare_nan, Label::kNear);
1500 __ j(cc, &done_compare, Label::kNear);
1501 __ j(equal, &compare_equal, Label::kNear);
1502
1503 // Result is on the right hand side.
1504 __ bind(&compare_swap);
1505 __ movaps(xmm0, xmm1);
1506 __ mov(edx, ebx);
1507 __ jmp(&done_compare, Label::kNear);
1508
1509 // At least one side is NaN, which means that the result will be NaN too.
1510 __ bind(&compare_nan);
1511 __ LoadRoot(edx, Heap::kNanValueRootIndex);
1512 __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset));
1513 __ jmp(&done_compare, Label::kNear);
1514
1515 // Left and right hand side are equal, check for -0 vs. +0.
1516 __ bind(&compare_equal);
1517 __ movmskpd(edi, reg);
1518 __ test(edi, Immediate(1));
1519 __ j(not_zero, &compare_swap);
1520
1521 __ bind(&done_compare);
1522 __ dec(ecx);
1523 __ jmp(&loop);
1524 }
1525
1526 __ bind(&done_loop);
1527 __ PopReturnAddressTo(ecx);
1528 __ lea(esp, Operand(esp, eax, times_pointer_size, kPointerSize));
1529 __ PushReturnAddressFrom(ecx);
1530 __ mov(eax, edx);
1531 __ Ret();
1532 }
1533
1534 // static
1419 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) { 1535 void Builtins::Generate_NumberConstructor(MacroAssembler* masm) {
1420 // ----------- S t a t e ------------- 1536 // ----------- S t a t e -------------
1421 // -- eax : number of arguments 1537 // -- eax : number of arguments
1422 // -- edi : constructor function 1538 // -- edi : constructor function
1423 // -- esp[0] : return address 1539 // -- esp[0] : return address
1424 // -- esp[(argc - n) * 4] : arg[n] (zero-based) 1540 // -- esp[(argc - n) * 4] : arg[n] (zero-based)
1425 // -- esp[(argc + 1) * 4] : receiver 1541 // -- esp[(argc + 1) * 4] : receiver
1426 // ----------------------------------- 1542 // -----------------------------------
1427 1543
1428 // 1. Load the first argument into eax and get rid of the rest (including the 1544 // 1. Load the first argument into eax and get rid of the rest (including the
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2675 2791
2676 __ bind(&ok); 2792 __ bind(&ok);
2677 __ ret(0); 2793 __ ret(0);
2678 } 2794 }
2679 2795
2680 #undef __ 2796 #undef __
2681 } // namespace internal 2797 } // namespace internal
2682 } // namespace v8 2798 } // namespace v8
2683 2799
2684 #endif // V8_TARGET_ARCH_IA32 2800 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« src/arm64/builtins-arm64.cc ('K') | « src/builtins.h ('k') | src/js/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698