builtins-data-view-gen.h 1.93 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2018 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.

#ifndef V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_
#define V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_

8
#include "src/codegen/code-stub-assembler.h"
9
#include "src/objects/bigint.h"
10
#include "src/objects/elements-kind.h"
11 12 13 14

namespace v8 {
namespace internal {

15
class DataViewBuiltinsAssembler : public CodeStubAssembler {
16 17
 public:
  explicit DataViewBuiltinsAssembler(compiler::CodeAssemblerState* state)
18
      : CodeStubAssembler(state) {}
19

20 21
  TNode<Uint8T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) {
    return UncheckedCast<Uint8T>(
22 23 24
        Load(MachineType::Uint8(), data_pointer, offset));
  }

25 26
  TNode<Int8T> LoadInt8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) {
    return UncheckedCast<Int8T>(
27 28
        Load(MachineType::Int8(), data_pointer, offset));
  }
29

30
  void StoreWord8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset,
31 32 33 34 35
                  TNode<Word32T> value) {
    StoreNoWriteBarrier(MachineRepresentation::kWord8, data_pointer, offset,
                        value);
  }

36 37 38 39
  int32_t DataViewElementSize(ElementsKind elements_kind) {
    return ElementsKindToByteSize(elements_kind);
  }

40 41 42
  TNode<Uint32T> DataViewEncodeBigIntBits(bool sign, int32_t digits) {
    return Unsigned(Int32Constant(BigInt::SignBits::encode(sign) |
                                  BigInt::LengthBits::encode(digits)));
43
  }
44

45 46 47
  TNode<Uint32T> DataViewDecodeBigIntLength(TNode<BigInt> value) {
    TNode<Word32T> bitfield = LoadBigIntBitfield(value);
    return DecodeWord32<BigIntBase::LengthBits>(bitfield);
48 49
  }

50 51 52
  TNode<Uint32T> DataViewDecodeBigIntSign(TNode<BigInt> value) {
    TNode<Word32T> bitfield = LoadBigIntBitfield(value);
    return DecodeWord32<BigIntBase::SignBits>(bitfield);
53
  }
54
};
55

56 57 58 59
}  // namespace internal
}  // namespace v8

#endif  // V8_BUILTINS_BUILTINS_DATA_VIEW_GEN_H_