Line data Source code
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_TYPED_ARRAY_GEN_H_
6 : #define V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
7 :
8 : #include "src/code-stub-assembler.h"
9 : #include "torque-generated/builtins-typed-array-from-dsl-gen.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 :
14 3808 : class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
15 : public:
16 : using ElementsInfo =
17 : TypedArrayBuiltinsFromDSLAssembler::TypedArrayElementsInfo;
18 : explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
19 3808 : : CodeStubAssembler(state) {}
20 :
21 : template <class... TArgs>
22 : TNode<JSTypedArray> TypedArraySpeciesCreate(const char* method_name,
23 : TNode<Context> context,
24 : TNode<JSTypedArray> exemplar,
25 : TArgs... args);
26 :
27 : void GenerateTypedArrayPrototypeIterationMethod(TNode<Context> context,
28 : TNode<Object> receiver,
29 : const char* method_name,
30 : IterationKind iteration_kind);
31 :
32 : void SetupTypedArray(TNode<JSTypedArray> holder, TNode<Smi> length,
33 : TNode<UintPtrT> byte_offset,
34 : TNode<UintPtrT> byte_length);
35 : void AttachBuffer(TNode<JSTypedArray> holder, TNode<JSArrayBuffer> buffer,
36 : TNode<Map> map, TNode<Smi> length,
37 : TNode<UintPtrT> byte_offset);
38 :
39 : TNode<JSArrayBuffer> AllocateEmptyOnHeapBuffer(TNode<Context> context,
40 : TNode<JSTypedArray> holder,
41 : TNode<UintPtrT> byte_length);
42 :
43 : TNode<FixedTypedArrayBase> AllocateOnHeapElements(TNode<Map> map,
44 : TNode<IntPtrT> byte_length,
45 : TNode<Number> length);
46 :
47 : TNode<Map> LoadMapForType(TNode<JSTypedArray> array);
48 : TNode<BoolT> IsMockArrayBufferAllocatorFlag();
49 : TNode<UintPtrT> CalculateExternalPointer(TNode<UintPtrT> backing_store,
50 : TNode<UintPtrT> byte_offset);
51 : TNode<RawPtrT> LoadDataPtr(TNode<JSTypedArray> typed_array);
52 :
53 : // Returns true if kind is either UINT8_ELEMENTS or UINT8_CLAMPED_ELEMENTS.
54 : TNode<Word32T> IsUint8ElementsKind(TNode<Word32T> kind);
55 :
56 : // Returns true if kind is either BIGINT64_ELEMENTS or BIGUINT64_ELEMENTS.
57 : TNode<Word32T> IsBigInt64ElementsKind(TNode<Word32T> kind);
58 :
59 : // Returns the byte size of an element for a TypedArray elements kind.
60 : TNode<IntPtrT> GetTypedArrayElementSize(TNode<Word32T> elements_kind);
61 :
62 : // Returns information (byte size and map) about a TypedArray's elements.
63 : ElementsInfo GetTypedArrayElementsInfo(TNode<JSTypedArray> typed_array);
64 :
65 : TNode<JSFunction> GetDefaultConstructor(TNode<Context> context,
66 : TNode<JSTypedArray> exemplar);
67 :
68 : TNode<JSTypedArray> TypedArrayCreateByLength(TNode<Context> context,
69 : TNode<Object> constructor,
70 : TNode<Smi> len,
71 : const char* method_name);
72 :
73 : void ThrowIfLengthLessThan(TNode<Context> context,
74 : TNode<JSTypedArray> typed_array,
75 : TNode<Smi> min_length);
76 :
77 : TNode<JSArrayBuffer> GetBuffer(TNode<Context> context,
78 : TNode<JSTypedArray> array);
79 :
80 : TNode<JSTypedArray> ValidateTypedArray(TNode<Context> context,
81 : TNode<Object> obj,
82 : const char* method_name);
83 :
84 : // Fast path for setting a TypedArray (source) onto another TypedArray
85 : // (target) at an element offset.
86 : void SetTypedArraySource(TNode<Context> context, TNode<JSTypedArray> source,
87 : TNode<JSTypedArray> target, TNode<IntPtrT> offset,
88 : Label* call_runtime, Label* if_source_too_large);
89 :
90 : void SetJSArraySource(TNode<Context> context, TNode<JSArray> source,
91 : TNode<JSTypedArray> target, TNode<IntPtrT> offset,
92 : Label* call_runtime, Label* if_source_too_large);
93 :
94 : void CallCMemmove(TNode<RawPtrT> dest_ptr, TNode<RawPtrT> src_ptr,
95 : TNode<UintPtrT> byte_length);
96 :
97 : void CallCMemcpy(TNode<RawPtrT> dest_ptr, TNode<RawPtrT> src_ptr,
98 : TNode<UintPtrT> byte_length);
99 :
100 : void CallCMemset(TNode<RawPtrT> dest_ptr, TNode<IntPtrT> value,
101 : TNode<UintPtrT> length);
102 :
103 : void CallCCopyFastNumberJSArrayElementsToTypedArray(
104 : TNode<Context> context, TNode<JSArray> source, TNode<JSTypedArray> dest,
105 : TNode<IntPtrT> source_length, TNode<IntPtrT> offset);
106 :
107 : void CallCCopyTypedArrayElementsToTypedArray(TNode<JSTypedArray> source,
108 : TNode<JSTypedArray> dest,
109 : TNode<IntPtrT> source_length,
110 : TNode<IntPtrT> offset);
111 :
112 : void CallCCopyTypedArrayElementsSlice(TNode<JSTypedArray> source,
113 : TNode<JSTypedArray> dest,
114 : TNode<IntPtrT> start,
115 : TNode<IntPtrT> end);
116 :
117 : typedef std::function<void(ElementsKind, int, int)> TypedArraySwitchCase;
118 :
119 : void DispatchTypedArrayByElementsKind(
120 : TNode<Word32T> elements_kind, const TypedArraySwitchCase& case_function);
121 :
122 : TNode<BoolT> IsSharedArrayBuffer(TNode<JSArrayBuffer> buffer);
123 : };
124 :
125 : } // namespace internal
126 : } // namespace v8
127 :
128 : #endif // V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
|