• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_DATA_VIEW_GEN_H_
6 #define V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_
7 
8 #include "src/codegen/code-stub-assembler.h"
9 #include "src/objects/bigint.h"
10 #include "src/objects/elements-kind.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class DataViewBuiltinsAssembler : public CodeStubAssembler {
16  public:
DataViewBuiltinsAssembler(compiler::CodeAssemblerState * state)17   explicit DataViewBuiltinsAssembler(compiler::CodeAssemblerState* state)
18       : CodeStubAssembler(state) {}
19 
LoadUint8(TNode<RawPtrT> data_pointer,TNode<UintPtrT> offset)20   TNode<Uint8T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) {
21     return UncheckedCast<Uint8T>(
22         Load(MachineType::Uint8(), data_pointer, offset));
23   }
24 
LoadInt8(TNode<RawPtrT> data_pointer,TNode<UintPtrT> offset)25   TNode<Int8T> LoadInt8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) {
26     return UncheckedCast<Int8T>(
27         Load(MachineType::Int8(), data_pointer, offset));
28   }
29 
StoreWord8(TNode<RawPtrT> data_pointer,TNode<UintPtrT> offset,TNode<Word32T> value)30   void StoreWord8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset,
31                   TNode<Word32T> value) {
32     StoreNoWriteBarrier(MachineRepresentation::kWord8, data_pointer, offset,
33                         value);
34   }
35 
DataViewElementSize(ElementsKind elements_kind)36   int32_t DataViewElementSize(ElementsKind elements_kind) {
37     return ElementsKindToByteSize(elements_kind);
38   }
39 
DataViewEncodeBigIntBits(bool sign,int32_t digits)40   TNode<Uint32T> DataViewEncodeBigIntBits(bool sign, int32_t digits) {
41     return Unsigned(Int32Constant(BigInt::SignBits::encode(sign) |
42                                   BigInt::LengthBits::encode(digits)));
43   }
44 
DataViewDecodeBigIntLength(TNode<BigInt> value)45   TNode<Uint32T> DataViewDecodeBigIntLength(TNode<BigInt> value) {
46     TNode<Word32T> bitfield = LoadBigIntBitfield(value);
47     return DecodeWord32<BigIntBase::LengthBits>(bitfield);
48   }
49 
DataViewDecodeBigIntSign(TNode<BigInt> value)50   TNode<Uint32T> DataViewDecodeBigIntSign(TNode<BigInt> value) {
51     TNode<Word32T> bitfield = LoadBigIntBitfield(value);
52     return DecodeWord32<BigIntBase::SignBits>(bitfield);
53   }
54 };
55 
56 }  // namespace internal
57 }  // namespace v8
58 
59 #endif  // V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_
60