Andrew Top | 63c7ad4 | 2019-11-25 16:10:13 -0800 | [diff] [blame] | 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: |
| 17 | explicit DataViewBuiltinsAssembler(compiler::CodeAssemblerState* state) |
| 18 | : CodeStubAssembler(state) {} |
| 19 | |
| 20 | TNode<Uint8T> LoadUint8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) { |
| 21 | return UncheckedCast<Uint8T>( |
| 22 | Load(MachineType::Uint8(), data_pointer, offset)); |
| 23 | } |
| 24 | |
| 25 | TNode<Int8T> LoadInt8(TNode<RawPtrT> data_pointer, TNode<UintPtrT> offset) { |
| 26 | return UncheckedCast<Int8T>( |
| 27 | Load(MachineType::Int8(), data_pointer, offset)); |
| 28 | } |
| 29 | |
| 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 | |
| 36 | int32_t DataViewElementSize(ElementsKind elements_kind) { |
| 37 | return ElementsKindToByteSize(elements_kind); |
| 38 | } |
| 39 | |
| 40 | TNode<Uint32T> DataViewEncodeBigIntBits(bool sign, int32_t digits) { |
| 41 | return Unsigned(Int32Constant(BigInt::SignBits::encode(sign) | |
| 42 | BigInt::LengthBits::encode(digits))); |
| 43 | } |
| 44 | |
| 45 | TNode<Uint32T> DataViewDecodeBigIntLength(TNode<BigInt> value) { |
| 46 | TNode<Word32T> bitfield = LoadBigIntBitfield(value); |
| 47 | return DecodeWord32<BigIntBase::LengthBits>(bitfield); |
| 48 | } |
| 49 | |
| 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_ |