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 336 : TF_BUILTIN(GlobalIsFinite, CodeStubAssembler) {
14 56 : Node* context = Parameter(Descriptor::kContext);
15 :
16 112 : Label return_true(this), return_false(this);
17 :
18 : // We might need to loop once for ToNumber conversion.
19 112 : VARIABLE(var_num, MachineRepresentation::kTagged);
20 112 : Label loop(this, &var_num);
21 56 : var_num.Bind(Parameter(Descriptor::kNumber));
22 56 : Goto(&loop);
23 56 : BIND(&loop);
24 : {
25 56 : Node* num = var_num.value();
26 :
27 : // Check if {num} is a Smi or a HeapObject.
28 56 : GotoIf(TaggedIsSmi(num), &return_true);
29 :
30 : // Check if {num} is a HeapNumber.
31 112 : Label if_numisheapnumber(this),
32 112 : if_numisnotheapnumber(this, Label::kDeferred);
33 56 : Branch(IsHeapNumber(num), &if_numisheapnumber, &if_numisnotheapnumber);
34 :
35 56 : BIND(&if_numisheapnumber);
36 : {
37 : // Check if {num} contains a finite, non-NaN value.
38 56 : Node* num_value = LoadHeapNumberValue(num);
39 112 : BranchIfFloat64IsNaN(Float64Sub(num_value, num_value), &return_false,
40 56 : &return_true);
41 : }
42 :
43 56 : BIND(&if_numisnotheapnumber);
44 : {
45 : // Need to convert {num} to a Number first.
46 56 : var_num.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, num));
47 56 : Goto(&loop);
48 : }
49 : }
50 :
51 56 : BIND(&return_true);
52 56 : Return(TrueConstant());
53 :
54 56 : BIND(&return_false);
55 56 : Return(FalseConstant());
56 56 : }
57 :
58 : // ES6 #sec-isnan-number
59 336 : TF_BUILTIN(GlobalIsNaN, CodeStubAssembler) {
60 56 : Node* context = Parameter(Descriptor::kContext);
61 :
62 112 : Label return_true(this), return_false(this);
63 :
64 : // We might need to loop once for ToNumber conversion.
65 112 : VARIABLE(var_num, MachineRepresentation::kTagged);
66 112 : Label loop(this, &var_num);
67 56 : var_num.Bind(Parameter(Descriptor::kNumber));
68 56 : Goto(&loop);
69 56 : BIND(&loop);
70 : {
71 56 : Node* num = var_num.value();
72 :
73 : // Check if {num} is a Smi or a HeapObject.
74 56 : GotoIf(TaggedIsSmi(num), &return_false);
75 :
76 : // Check if {num} is a HeapNumber.
77 112 : Label if_numisheapnumber(this),
78 112 : if_numisnotheapnumber(this, Label::kDeferred);
79 56 : Branch(IsHeapNumber(num), &if_numisheapnumber, &if_numisnotheapnumber);
80 :
81 56 : BIND(&if_numisheapnumber);
82 : {
83 : // Check if {num} contains a NaN.
84 56 : Node* num_value = LoadHeapNumberValue(num);
85 56 : BranchIfFloat64IsNaN(num_value, &return_true, &return_false);
86 : }
87 :
88 56 : BIND(&if_numisnotheapnumber);
89 : {
90 : // Need to convert {num} to a Number first.
91 56 : var_num.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, num));
92 56 : Goto(&loop);
93 : }
94 : }
95 :
96 56 : BIND(&return_true);
97 56 : Return(TrueConstant());
98 :
99 56 : BIND(&return_false);
100 56 : Return(FalseConstant());
101 56 : }
102 :
103 : } // namespace internal
104 87414 : } // namespace v8
|