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 224 : TF_BUILTIN(GlobalIsFinite, CodeStubAssembler) {
14 : Node* context = Parameter(Descriptor::kContext);
15 :
16 56 : 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 56 : 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 112 : GotoIf(TaggedIsSmi(num), &return_true);
29 :
30 : // Check if {num} is a HeapNumber.
31 : Label if_numisheapnumber(this),
32 56 : if_numisnotheapnumber(this, Label::kDeferred);
33 112 : 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 112 : Node* num_value = LoadHeapNumberValue(num);
39 56 : BranchIfFloat64IsNaN(Float64Sub(num_value, num_value), &return_false,
40 112 : &return_true);
41 : }
42 :
43 56 : BIND(&if_numisnotheapnumber);
44 : {
45 : // Need to convert {num} to a Number first.
46 112 : var_num.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, num));
47 56 : Goto(&loop);
48 56 : }
49 : }
50 :
51 56 : BIND(&return_true);
52 112 : Return(TrueConstant());
53 :
54 56 : BIND(&return_false);
55 168 : Return(FalseConstant());
56 56 : }
57 :
58 : // ES6 #sec-isnan-number
59 224 : TF_BUILTIN(GlobalIsNaN, CodeStubAssembler) {
60 : Node* context = Parameter(Descriptor::kContext);
61 :
62 56 : 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 56 : 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 112 : GotoIf(TaggedIsSmi(num), &return_false);
75 :
76 : // Check if {num} is a HeapNumber.
77 : Label if_numisheapnumber(this),
78 56 : if_numisnotheapnumber(this, Label::kDeferred);
79 112 : Branch(IsHeapNumber(num), &if_numisheapnumber, &if_numisnotheapnumber);
80 :
81 56 : BIND(&if_numisheapnumber);
82 : {
83 : // Check if {num} contains a NaN.
84 112 : 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 112 : var_num.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, num));
92 56 : Goto(&loop);
93 56 : }
94 : }
95 :
96 56 : BIND(&return_true);
97 112 : Return(TrueConstant());
98 :
99 56 : BIND(&return_false);
100 168 : Return(FalseConstant());
101 56 : }
102 :
103 : } // namespace internal
104 94089 : } // namespace v8
|