• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 #ifndef V8_BUILTINS_BUILTINS_BIGINT_GEN_H_
6 #define V8_BUILTINS_BUILTINS_BIGINT_GEN_H_
7 
8 #include "src/codegen/code-stub-assembler.h"
9 #include "src/objects/bigint.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 class BigIntBuiltinsAssembler : public CodeStubAssembler {
15  public:
BigIntBuiltinsAssembler(compiler::CodeAssemblerState * state)16   explicit BigIntBuiltinsAssembler(compiler::CodeAssemblerState* state)
17       : CodeStubAssembler(state) {}
18 
ReadBigIntLength(TNode<BigInt> value)19   TNode<IntPtrT> ReadBigIntLength(TNode<BigInt> value) {
20     TNode<Word32T> bitfield = LoadBigIntBitfield(value);
21     return ChangeInt32ToIntPtr(
22         Signed(DecodeWord32<BigIntBase::LengthBits>(bitfield)));
23   }
24 
ReadBigIntSign(TNode<BigInt> value)25   TNode<Uint32T> ReadBigIntSign(TNode<BigInt> value) {
26     TNode<Word32T> bitfield = LoadBigIntBitfield(value);
27     return DecodeWord32<BigIntBase::SignBits>(bitfield);
28   }
29 
WriteBigIntSignAndLength(TNode<BigInt> bigint,TNode<Uint32T> sign,TNode<IntPtrT> length)30   void WriteBigIntSignAndLength(TNode<BigInt> bigint, TNode<Uint32T> sign,
31                                 TNode<IntPtrT> length) {
32     STATIC_ASSERT(BigIntBase::SignBits::kShift == 0);
33     TNode<Uint32T> bitfield = Unsigned(
34         Word32Or(Word32Shl(TruncateIntPtrToInt32(length),
35                            Int32Constant(BigIntBase::LengthBits::kShift)),
36                  Word32And(sign, Int32Constant(BigIntBase::SignBits::kMask))));
37     StoreBigIntBitfield(bigint, bitfield);
38   }
39 
CppAbsoluteAddAndCanonicalize(TNode<BigInt> result,TNode<BigInt> x,TNode<BigInt> y)40   void CppAbsoluteAddAndCanonicalize(TNode<BigInt> result, TNode<BigInt> x,
41                                      TNode<BigInt> y) {
42     TNode<ExternalReference> mutable_big_int_absolute_add_and_canonicalize =
43         ExternalConstant(
44             ExternalReference::
45                 mutable_big_int_absolute_add_and_canonicalize_function());
46     CallCFunction(mutable_big_int_absolute_add_and_canonicalize,
47                   MachineType::AnyTagged(),
48                   std::make_pair(MachineType::AnyTagged(), result),
49                   std::make_pair(MachineType::AnyTagged(), x),
50                   std::make_pair(MachineType::AnyTagged(), y));
51   }
52 
CppAbsoluteSubAndCanonicalize(TNode<BigInt> result,TNode<BigInt> x,TNode<BigInt> y)53   void CppAbsoluteSubAndCanonicalize(TNode<BigInt> result, TNode<BigInt> x,
54                                      TNode<BigInt> y) {
55     TNode<ExternalReference> mutable_big_int_absolute_sub_and_canonicalize =
56         ExternalConstant(
57             ExternalReference::
58                 mutable_big_int_absolute_sub_and_canonicalize_function());
59     CallCFunction(mutable_big_int_absolute_sub_and_canonicalize,
60                   MachineType::AnyTagged(),
61                   std::make_pair(MachineType::AnyTagged(), result),
62                   std::make_pair(MachineType::AnyTagged(), x),
63                   std::make_pair(MachineType::AnyTagged(), y));
64   }
65 
CppAbsoluteCompare(TNode<BigInt> x,TNode<BigInt> y)66   TNode<Int32T> CppAbsoluteCompare(TNode<BigInt> x, TNode<BigInt> y) {
67     TNode<ExternalReference> mutable_big_int_absolute_compare =
68         ExternalConstant(
69             ExternalReference::mutable_big_int_absolute_compare_function());
70     TNode<Int32T> result = UncheckedCast<Int32T>(
71         CallCFunction(mutable_big_int_absolute_compare, MachineType::Int32(),
72                       std::make_pair(MachineType::AnyTagged(), x),
73                       std::make_pair(MachineType::AnyTagged(), y)));
74     return result;
75   }
76 };
77 
78 }  // namespace internal
79 }  // namespace v8
80 #endif  // V8_BUILTINS_BUILTINS_BIGINT_GEN_H_
81