| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 #include "src/builtins/builtins-utils-gen.h" | 5 #include "src/builtins/builtins-utils-gen.h" |
| 6 #include "src/builtins/builtins.h" | 6 #include "src/builtins/builtins.h" |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 { | 41 { |
| 42 // Load the current {x} value. | 42 // Load the current {x} value. |
| 43 Node* x = var_x.value(); | 43 Node* x = var_x.value(); |
| 44 | 44 |
| 45 // Check if {x} is a Smi or a HeapObject. | 45 // Check if {x} is a Smi or a HeapObject. |
| 46 Label if_xissmi(this), if_xisnotsmi(this); | 46 Label if_xissmi(this), if_xisnotsmi(this); |
| 47 Branch(TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi); | 47 Branch(TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi); |
| 48 | 48 |
| 49 Bind(&if_xissmi); | 49 Bind(&if_xissmi); |
| 50 { | 50 { |
| 51 // Check if {x} is already positive. | 51 Label if_overflow(this, Label::kDeferred), if_notoverflow(this); |
| 52 Label if_xispositive(this), if_xisnotpositive(this); | 52 Node* pair = NULL; |
| 53 BranchIfSmiLessThanOrEqual(SmiConstant(Smi::FromInt(0)), x, | |
| 54 &if_xispositive, &if_xisnotpositive); | |
| 55 | 53 |
| 56 Bind(&if_xispositive); | 54 // check if support abs function |
| 57 { | 55 if (IsIntPtrAbsWithOverflowSupported()) { |
| 58 // Just return the input {x}. | 56 pair = IntPtrAbsWithOverflow(x); |
| 59 Return(x); | 57 Node* overflow = Projection(1, pair); |
| 58 Branch(overflow, &if_overflow, &if_notoverflow); |
| 59 } else { |
| 60 // Check if {x} is already positive. |
| 61 Label if_xispositive(this), if_xisnotpositive(this); |
| 62 BranchIfSmiLessThanOrEqual(SmiConstant(Smi::FromInt(0)), x, |
| 63 &if_xispositive, &if_xisnotpositive); |
| 64 |
| 65 Bind(&if_xispositive); |
| 66 { |
| 67 // Just return the input {x}. |
| 68 Return(x); |
| 69 } |
| 70 |
| 71 Bind(&if_xisnotpositive); |
| 72 { |
| 73 // Try to negate the {x} value. |
| 74 pair = |
| 75 IntPtrSubWithOverflow(IntPtrConstant(0), BitcastTaggedToWord(x)); |
| 76 Node* overflow = Projection(1, pair); |
| 77 Branch(overflow, &if_overflow, &if_notoverflow); |
| 78 } |
| 60 } | 79 } |
| 61 | 80 |
| 62 Bind(&if_xisnotpositive); | 81 Bind(&if_notoverflow); |
| 63 { | 82 { |
| 64 // Try to negate the {x} value. | 83 // There is a Smi representation for negated {x}. |
| 65 Node* pair = | 84 Node* result = Projection(0, pair); |
| 66 IntPtrSubWithOverflow(IntPtrConstant(0), BitcastTaggedToWord(x)); | 85 Return(BitcastWordToTagged(result)); |
| 67 Node* overflow = Projection(1, pair); | 86 } |
| 68 Label if_overflow(this, Label::kDeferred), if_notoverflow(this); | |
| 69 Branch(overflow, &if_overflow, &if_notoverflow); | |
| 70 | 87 |
| 71 Bind(&if_notoverflow); | 88 Bind(&if_overflow); |
| 72 { | 89 { Return(NumberConstant(0.0 - Smi::kMinValue)); } |
| 73 // There is a Smi representation for negated {x}. | |
| 74 Node* result = Projection(0, pair); | |
| 75 Return(BitcastWordToTagged(result)); | |
| 76 } | |
| 77 | |
| 78 Bind(&if_overflow); | |
| 79 { Return(NumberConstant(0.0 - Smi::kMinValue)); } | |
| 80 } | |
| 81 } | 90 } |
| 82 | 91 |
| 83 Bind(&if_xisnotsmi); | 92 Bind(&if_xisnotsmi); |
| 84 { | 93 { |
| 85 // Check if {x} is a HeapNumber. | 94 // Check if {x} is a HeapNumber. |
| 86 Label if_xisheapnumber(this), if_xisnotheapnumber(this, Label::kDeferred); | 95 Label if_xisheapnumber(this), if_xisnotheapnumber(this, Label::kDeferred); |
| 87 Branch(IsHeapNumberMap(LoadMap(x)), &if_xisheapnumber, | 96 Branch(IsHeapNumberMap(LoadMap(x)), &if_xisheapnumber, |
| 88 &if_xisnotheapnumber); | 97 &if_xisnotheapnumber); |
| 89 | 98 |
| 90 Bind(&if_xisheapnumber); | 99 Bind(&if_xisheapnumber); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 TF_BUILTIN(MathMin, MathBuiltinsAssembler) { | 529 TF_BUILTIN(MathMin, MathBuiltinsAssembler) { |
| 521 // TODO(ishell): use constants from Descriptor once the JSFunction linkage | 530 // TODO(ishell): use constants from Descriptor once the JSFunction linkage |
| 522 // arguments are reordered. | 531 // arguments are reordered. |
| 523 Node* context = Parameter(BuiltinDescriptor::kContext); | 532 Node* context = Parameter(BuiltinDescriptor::kContext); |
| 524 Node* argc = Parameter(BuiltinDescriptor::kArgumentsCount); | 533 Node* argc = Parameter(BuiltinDescriptor::kArgumentsCount); |
| 525 MathMaxMin(context, argc, &CodeStubAssembler::Float64Min, V8_INFINITY); | 534 MathMaxMin(context, argc, &CodeStubAssembler::Float64Min, V8_INFINITY); |
| 526 } | 535 } |
| 527 | 536 |
| 528 } // namespace internal | 537 } // namespace internal |
| 529 } // namespace v8 | 538 } // namespace v8 |
| OLD | NEW |