Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include "src/builtins/builtins-utils-gen.h"
6 : #include "src/builtins/builtins.h"
7 : #include "src/code-stub-assembler.h"
8 :
9 : namespace v8 {
10 : namespace internal {
11 :
12 : // ES #sec-isfinite-number
13 172 : TF_BUILTIN(GlobalIsFinite, CodeStubAssembler) {
14 : Node* context = Parameter(Descriptor::kContext);
15 :
16 43 : Label return_true(this), return_false(this);
17 :
18 : // We might need to loop once for ToNumber conversion.
19 86 : VARIABLE(var_num, MachineRepresentation::kTagged);
20 43 : Label loop(this, &var_num);
21 43 : var_num.Bind(Parameter(Descriptor::kNumber));
22 43 : Goto(&loop);
23 43 : BIND(&loop);
24 : {
25 43 : Node* num = var_num.value();
26 :
27 : // Check if {num} is a Smi or a HeapObject.
28 43 : GotoIf(TaggedIsSmi(num), &return_true);
29 :
30 : // Check if {num} is a HeapNumber.
31 : Label if_numisheapnumber(this),
32 43 : if_numisnotheapnumber(this, Label::kDeferred);
33 : Branch(IsHeapNumberMap(LoadMap(num)), &if_numisheapnumber,
34 43 : &if_numisnotheapnumber);
35 :
36 43 : BIND(&if_numisheapnumber);
37 : {
38 : // Check if {num} contains a finite, non-NaN value.
39 43 : Node* num_value = LoadHeapNumberValue(num);
40 : BranchIfFloat64IsNaN(Float64Sub(num_value, num_value), &return_false,
41 43 : &return_true);
42 : }
43 :
44 43 : BIND(&if_numisnotheapnumber);
45 : {
46 : // Need to convert {num} to a Number first.
47 43 : Callable callable = CodeFactory::NonNumberToNumber(isolate());
48 43 : var_num.Bind(CallStub(callable, context, num));
49 43 : Goto(&loop);
50 43 : }
51 : }
52 :
53 43 : BIND(&return_true);
54 43 : Return(BooleanConstant(true));
55 :
56 43 : BIND(&return_false);
57 86 : Return(BooleanConstant(false));
58 43 : }
59 :
60 : // ES6 #sec-isnan-number
61 172 : TF_BUILTIN(GlobalIsNaN, CodeStubAssembler) {
62 : Node* context = Parameter(Descriptor::kContext);
63 :
64 43 : Label return_true(this), return_false(this);
65 :
66 : // We might need to loop once for ToNumber conversion.
67 86 : VARIABLE(var_num, MachineRepresentation::kTagged);
68 43 : Label loop(this, &var_num);
69 43 : var_num.Bind(Parameter(Descriptor::kNumber));
70 43 : Goto(&loop);
71 43 : BIND(&loop);
72 : {
73 43 : Node* num = var_num.value();
74 :
75 : // Check if {num} is a Smi or a HeapObject.
76 43 : GotoIf(TaggedIsSmi(num), &return_false);
77 :
78 : // Check if {num} is a HeapNumber.
79 : Label if_numisheapnumber(this),
80 43 : if_numisnotheapnumber(this, Label::kDeferred);
81 : Branch(IsHeapNumberMap(LoadMap(num)), &if_numisheapnumber,
82 43 : &if_numisnotheapnumber);
83 :
84 43 : BIND(&if_numisheapnumber);
85 : {
86 : // Check if {num} contains a NaN.
87 43 : Node* num_value = LoadHeapNumberValue(num);
88 43 : BranchIfFloat64IsNaN(num_value, &return_true, &return_false);
89 : }
90 :
91 43 : BIND(&if_numisnotheapnumber);
92 : {
93 : // Need to convert {num} to a Number first.
94 43 : Callable callable = CodeFactory::NonNumberToNumber(isolate());
95 43 : var_num.Bind(CallStub(callable, context, num));
96 43 : Goto(&loop);
97 43 : }
98 : }
99 :
100 43 : BIND(&return_true);
101 43 : Return(BooleanConstant(true));
102 :
103 43 : BIND(&return_false);
104 86 : Return(BooleanConstant(false));
105 43 : }
106 :
107 : } // namespace internal
108 : } // namespace v8
|