builtins-global-gen.cc 3.12 KB
Newer Older
1 2 3 4 5 6
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
7
#include "src/codegen/code-stub-assembler.h"
8 9 10 11

namespace v8 {
namespace internal {

12
// ES #sec-isfinite-number
13
TF_BUILTIN(GlobalIsFinite, CodeStubAssembler) {
14
  auto context = Parameter<Context>(Descriptor::kContext);
15 16 17 18

  Label return_true(this), return_false(this);

  // We might need to loop once for ToNumber conversion.
19
  TVARIABLE(Object, var_num);
20
  Label loop(this, &var_num);
21
  var_num = Parameter<Object>(Descriptor::kNumber);
22
  Goto(&loop);
23
  BIND(&loop);
24
  {
25
    TNode<Object> num = var_num.value();
26 27 28

    // Check if {num} is a Smi or a HeapObject.
    GotoIf(TaggedIsSmi(num), &return_true);
29
    TNode<HeapObject> num_heap_object = CAST(num);
30

31
    // Check if {num_heap_object} is a HeapNumber.
32 33
    Label if_numisheapnumber(this),
        if_numisnotheapnumber(this, Label::kDeferred);
34 35
    Branch(IsHeapNumber(num_heap_object), &if_numisheapnumber,
           &if_numisnotheapnumber);
36

37
    BIND(&if_numisheapnumber);
38
    {
39 40
      // Check if {num_heap_object} contains a finite, non-NaN value.
      TNode<Float64T> num_value = LoadHeapNumberValue(num_heap_object);
41 42 43 44
      BranchIfFloat64IsNaN(Float64Sub(num_value, num_value), &return_false,
                           &return_true);
    }

45
    BIND(&if_numisnotheapnumber);
46
    {
47 48
      // Need to convert {num_heap_object} to a Number first.
      var_num =
49
          CallBuiltin(Builtin::kNonNumberToNumber, context, num_heap_object);
50 51 52 53
      Goto(&loop);
    }
  }

54
  BIND(&return_true);
55
  Return(TrueConstant());
56

57
  BIND(&return_false);
58
  Return(FalseConstant());
59 60
}

61
// ES6 #sec-isnan-number
62
TF_BUILTIN(GlobalIsNaN, CodeStubAssembler) {
63
  auto context = Parameter<Context>(Descriptor::kContext);
64 65 66 67

  Label return_true(this), return_false(this);

  // We might need to loop once for ToNumber conversion.
68
  TVARIABLE(Object, var_num);
69
  Label loop(this, &var_num);
70
  var_num = Parameter<Object>(Descriptor::kNumber);
71
  Goto(&loop);
72
  BIND(&loop);
73
  {
74
    TNode<Object> num = var_num.value();
75 76 77

    // Check if {num} is a Smi or a HeapObject.
    GotoIf(TaggedIsSmi(num), &return_false);
78
    TNode<HeapObject> num_heap_object = CAST(num);
79

80
    // Check if {num_heap_object} is a HeapNumber.
81 82
    Label if_numisheapnumber(this),
        if_numisnotheapnumber(this, Label::kDeferred);
83 84
    Branch(IsHeapNumber(num_heap_object), &if_numisheapnumber,
           &if_numisnotheapnumber);
85

86
    BIND(&if_numisheapnumber);
87
    {
88 89
      // Check if {num_heap_object} contains a NaN.
      TNode<Float64T> num_value = LoadHeapNumberValue(num_heap_object);
90 91 92
      BranchIfFloat64IsNaN(num_value, &return_true, &return_false);
    }

93
    BIND(&if_numisnotheapnumber);
94
    {
95 96
      // Need to convert {num_heap_object} to a Number first.
      var_num =
97
          CallBuiltin(Builtin::kNonNumberToNumber, context, num_heap_object);
98 99 100 101
      Goto(&loop);
    }
  }

102
  BIND(&return_true);
103
  Return(TrueConstant());
104

105
  BIND(&return_false);
106
  Return(FalseConstant());
107 108 109 110
}

}  // namespace internal
}  // namespace v8