builtins-global-gen.cc 2.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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"
#include "src/code-stub-assembler.h"

namespace v8 {
namespace internal {

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

  Label return_true(this), return_false(this);

  // We might need to loop once for ToNumber conversion.
19
  VARIABLE(var_num, MachineRepresentation::kTagged);
20
  Label loop(this, &var_num);
21
  var_num.Bind(Parameter(Descriptor::kNumber));
22
  Goto(&loop);
23
  BIND(&loop);
24 25 26 27 28 29 30 31 32
  {
    Node* num = var_num.value();

    // Check if {num} is a Smi or a HeapObject.
    GotoIf(TaggedIsSmi(num), &return_true);

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

35
    BIND(&if_numisheapnumber);
36 37 38 39 40 41 42
    {
      // Check if {num} contains a finite, non-NaN value.
      Node* num_value = LoadHeapNumberValue(num);
      BranchIfFloat64IsNaN(Float64Sub(num_value, num_value), &return_false,
                           &return_true);
    }

43
    BIND(&if_numisnotheapnumber);
44 45
    {
      // Need to convert {num} to a Number first.
46
      var_num.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, num));
47 48 49 50
      Goto(&loop);
    }
  }

51
  BIND(&return_true);
52
  Return(TrueConstant());
53

54
  BIND(&return_false);
55
  Return(FalseConstant());
56 57
}

58
// ES6 #sec-isnan-number
59
TF_BUILTIN(GlobalIsNaN, CodeStubAssembler) {
60
  Node* context = Parameter(Descriptor::kContext);
61 62 63 64

  Label return_true(this), return_false(this);

  // We might need to loop once for ToNumber conversion.
65
  VARIABLE(var_num, MachineRepresentation::kTagged);
66
  Label loop(this, &var_num);
67
  var_num.Bind(Parameter(Descriptor::kNumber));
68
  Goto(&loop);
69
  BIND(&loop);
70 71 72 73 74 75 76 77 78
  {
    Node* num = var_num.value();

    // Check if {num} is a Smi or a HeapObject.
    GotoIf(TaggedIsSmi(num), &return_false);

    // Check if {num} is a HeapNumber.
    Label if_numisheapnumber(this),
        if_numisnotheapnumber(this, Label::kDeferred);
79
    Branch(IsHeapNumber(num), &if_numisheapnumber, &if_numisnotheapnumber);
80

81
    BIND(&if_numisheapnumber);
82 83 84 85 86 87
    {
      // Check if {num} contains a NaN.
      Node* num_value = LoadHeapNumberValue(num);
      BranchIfFloat64IsNaN(num_value, &return_true, &return_false);
    }

88
    BIND(&if_numisnotheapnumber);
89 90
    {
      // Need to convert {num} to a Number first.
91
      var_num.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, num));
92 93 94 95
      Goto(&loop);
    }
  }

96
  BIND(&return_true);
97
  Return(TrueConstant());
98

99
  BIND(&return_false);
100
  Return(FalseConstant());
101 102 103 104
}

}  // namespace internal
}  // namespace v8