• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-bigint-gen.h"
6 #include "src/builtins/builtins-utils-gen.h"
7 #include "src/builtins/builtins.h"
8 #include "src/codegen/code-stub-assembler.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 // https://tc39.github.io/proposal-bigint/#sec-to-big-int64
TF_BUILTIN(BigIntToI64,CodeStubAssembler)14 TF_BUILTIN(BigIntToI64, CodeStubAssembler) {
15   if (!Is64()) {
16     Unreachable();
17     return;
18   }
19 
20   auto value = Parameter<Object>(Descriptor::kArgument);
21   auto context = Parameter<Context>(Descriptor::kContext);
22   TNode<BigInt> n = ToBigInt(context, value);
23 
24   TVARIABLE(UintPtrT, var_low);
25   TVARIABLE(UintPtrT, var_high);
26 
27   BigIntToRawBytes(n, &var_low, &var_high);
28   Return(var_low.value());
29 }
30 
31 // https://tc39.github.io/proposal-bigint/#sec-to-big-int64
TF_BUILTIN(BigIntToI32Pair,CodeStubAssembler)32 TF_BUILTIN(BigIntToI32Pair, CodeStubAssembler) {
33   if (!Is32()) {
34     Unreachable();
35     return;
36   }
37 
38   auto value = Parameter<Object>(Descriptor::kArgument);
39   auto context = Parameter<Context>(Descriptor::kContext);
40   TNode<BigInt> bigint = ToBigInt(context, value);
41 
42   TVARIABLE(UintPtrT, var_low);
43   TVARIABLE(UintPtrT, var_high);
44 
45   BigIntToRawBytes(bigint, &var_low, &var_high);
46   Return(var_low.value(), var_high.value());
47 }
48 
49 // https://tc39.github.io/proposal-bigint/#sec-bigint-constructor-number-value
TF_BUILTIN(I64ToBigInt,CodeStubAssembler)50 TF_BUILTIN(I64ToBigInt, CodeStubAssembler) {
51   if (!Is64()) {
52     Unreachable();
53     return;
54   }
55 
56   auto argument = UncheckedParameter<IntPtrT>(Descriptor::kArgument);
57 
58   Return(BigIntFromInt64(argument));
59 }
60 
61 // https://tc39.github.io/proposal-bigint/#sec-bigint-constructor-number-value
TF_BUILTIN(I32PairToBigInt,CodeStubAssembler)62 TF_BUILTIN(I32PairToBigInt, CodeStubAssembler) {
63   if (!Is32()) {
64     Unreachable();
65     return;
66   }
67 
68   auto low = UncheckedParameter<IntPtrT>(Descriptor::kLow);
69   auto high = UncheckedParameter<IntPtrT>(Descriptor::kHigh);
70 
71   Return(BigIntFromInt32Pair(low, high));
72 }
73 
74 }  // namespace internal
75 }  // namespace v8
76