builtins-bigint-gen.cc 1.96 KB
Newer Older
1 2 3 4
// 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.

5
#include "src/builtins/builtins-bigint-gen.h"
6 7
#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
8
#include "src/codegen/code-stub-assembler.h"
9 10 11 12 13 14 15 16 17 18 19

namespace v8 {
namespace internal {

// https://tc39.github.io/proposal-bigint/#sec-to-big-int64
TF_BUILTIN(BigIntToI64, CodeStubAssembler) {
  if (!Is64()) {
    Unreachable();
    return;
  }

20 21
  auto value = Parameter<Object>(Descriptor::kArgument);
  auto context = Parameter<Context>(Descriptor::kContext);
22 23 24 25 26 27
  TNode<BigInt> n = ToBigInt(context, value);

  TVARIABLE(UintPtrT, var_low);
  TVARIABLE(UintPtrT, var_high);

  BigIntToRawBytes(n, &var_low, &var_high);
28
  Return(var_low.value());
29 30 31 32 33 34 35 36 37
}

// https://tc39.github.io/proposal-bigint/#sec-to-big-int64
TF_BUILTIN(BigIntToI32Pair, CodeStubAssembler) {
  if (!Is32()) {
    Unreachable();
    return;
  }

38 39
  auto value = Parameter<Object>(Descriptor::kArgument);
  auto context = Parameter<Context>(Descriptor::kContext);
40 41 42 43 44 45
  TNode<BigInt> bigint = ToBigInt(context, value);

  TVARIABLE(UintPtrT, var_low);
  TVARIABLE(UintPtrT, var_high);

  BigIntToRawBytes(bigint, &var_low, &var_high);
46
  Return(var_low.value(), var_high.value());
47 48 49 50 51 52 53 54 55
}

// https://tc39.github.io/proposal-bigint/#sec-bigint-constructor-number-value
TF_BUILTIN(I64ToBigInt, CodeStubAssembler) {
  if (!Is64()) {
    Unreachable();
    return;
  }

56
  auto argument = UncheckedParameter<IntPtrT>(Descriptor::kArgument);
57 58 59 60

  Return(BigIntFromInt64(argument));
}

61 62 63 64 65 66 67
// https://tc39.github.io/proposal-bigint/#sec-bigint-constructor-number-value
TF_BUILTIN(I32PairToBigInt, CodeStubAssembler) {
  if (!Is32()) {
    Unreachable();
    return;
  }

68 69
  auto low = UncheckedParameter<IntPtrT>(Descriptor::kLow);
  auto high = UncheckedParameter<IntPtrT>(Descriptor::kHigh);
70 71 72 73

  Return(BigIntFromInt32Pair(low, high));
}

74 75
}  // namespace internal
}  // namespace v8