• 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_TYPED_ARRAY_GEN_H_
6 #define V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
7 
8 #include "src/codegen/code-stub-assembler.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 class TypedArrayBuiltinsAssembler : public CodeStubAssembler {
14  public:
15   using ElementsInfo = TorqueStructTypedArrayElementsInfo;
TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState * state)16   explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state)
17       : CodeStubAssembler(state) {}
18 
19   void SetupTypedArrayEmbedderFields(TNode<JSTypedArray> holder);
20   void AttachBuffer(TNode<JSTypedArray> holder, TNode<JSArrayBuffer> buffer,
21                     TNode<Map> map, TNode<Smi> length,
22                     TNode<UintPtrT> byte_offset);
23 
24   TNode<JSArrayBuffer> AllocateEmptyOnHeapBuffer(TNode<Context> context);
25 
26   TNode<Map> LoadMapForType(TNode<JSTypedArray> array);
27   TNode<BoolT> IsMockArrayBufferAllocatorFlag();
28   TNode<UintPtrT> CalculateExternalPointer(TNode<UintPtrT> backing_store,
29                                            TNode<UintPtrT> byte_offset);
30 
31   // Returns true if kind is either UINT8_ELEMENTS, UINT8_CLAMPED_ELEMENTS,
32   // RAB_GSAB_UINT8_ELEMENTS, or RAB_GSAB_UINT8_CLAMPED_ELEMENTS.
33   TNode<BoolT> IsUint8ElementsKind(TNode<Int32T> kind);
34 
35   // Returns true if kind is either BIGINT64_ELEMENTS, BIGUINT64_ELEMENTS,
36   // RAB_GSAB_BIGINT64_ELEMENTS, or RAB_GSAB_BIGUINT64_ELEMENTS.
37   TNode<BoolT> IsBigInt64ElementsKind(TNode<Int32T> kind);
38 
39   // Returns the byte size of an element for a TypedArray elements kind.
40   TNode<IntPtrT> GetTypedArrayElementSize(TNode<Int32T> elements_kind);
41 
42   // Returns information (byte size and map) about a TypedArray's elements.
43   ElementsInfo GetTypedArrayElementsInfo(TNode<JSTypedArray> typed_array);
44   ElementsInfo GetTypedArrayElementsInfo(TNode<Map> map);
45 
46   TNode<JSFunction> GetDefaultConstructor(TNode<Context> context,
47                                           TNode<JSTypedArray> exemplar);
48 
49   TNode<JSTypedArray> ValidateTypedArray(TNode<Context> context,
50                                          TNode<Object> obj,
51                                          const char* method_name);
52 
53   TNode<UintPtrT> ValidateTypedArrayAndGetLength(TNode<Context> context,
54                                                  TNode<Object> obj,
55                                                  const char* method_name);
56 
57   void CallCMemmove(TNode<RawPtrT> dest_ptr, TNode<RawPtrT> src_ptr,
58                     TNode<UintPtrT> byte_length);
59 
60   void CallCRelaxedMemmove(TNode<RawPtrT> dest_ptr, TNode<RawPtrT> src_ptr,
61                            TNode<UintPtrT> byte_length);
62 
63   void CallCMemcpy(TNode<RawPtrT> dest_ptr, TNode<RawPtrT> src_ptr,
64                    TNode<UintPtrT> byte_length);
65 
66   void CallCRelaxedMemcpy(TNode<RawPtrT> dest_ptr, TNode<RawPtrT> src_ptr,
67                           TNode<UintPtrT> byte_length);
68 
69   void CallCMemset(TNode<RawPtrT> dest_ptr, TNode<IntPtrT> value,
70                    TNode<UintPtrT> length);
71 
72   void CallCCopyFastNumberJSArrayElementsToTypedArray(
73       TNode<Context> context, TNode<JSArray> source, TNode<JSTypedArray> dest,
74       TNode<UintPtrT> source_length, TNode<UintPtrT> offset);
75 
76   void CallCCopyTypedArrayElementsToTypedArray(TNode<JSTypedArray> source,
77                                                TNode<JSTypedArray> dest,
78                                                TNode<UintPtrT> source_length,
79                                                TNode<UintPtrT> offset);
80 
81   void CallCCopyTypedArrayElementsSlice(TNode<JSTypedArray> source,
82                                         TNode<JSTypedArray> dest,
83                                         TNode<UintPtrT> start,
84                                         TNode<UintPtrT> end);
85 
86   using TypedArraySwitchCase = std::function<void(ElementsKind, int, int)>;
87 
88   void DispatchTypedArrayByElementsKind(
89       TNode<Word32T> elements_kind, const TypedArraySwitchCase& case_function);
90 
91   void SetJSTypedArrayOnHeapDataPtr(TNode<JSTypedArray> holder,
92                                     TNode<ByteArray> base,
93                                     TNode<UintPtrT> offset);
94   void SetJSTypedArrayOffHeapDataPtr(TNode<JSTypedArray> holder,
95                                      TNode<RawPtrT> base,
96                                      TNode<UintPtrT> offset);
97   void StoreJSTypedArrayElementFromNumeric(TNode<Context> context,
98                                            TNode<JSTypedArray> typed_array,
99                                            TNode<UintPtrT> index_node,
100                                            TNode<Numeric> value,
101                                            ElementsKind elements_kind);
102   void StoreJSTypedArrayElementFromTagged(TNode<Context> context,
103                                           TNode<JSTypedArray> typed_array,
104                                           TNode<UintPtrT> index_node,
105                                           TNode<Object> value,
106                                           ElementsKind elements_kind,
107                                           Label* if_detached);
108   template <typename TValue>
109   void StoreJSTypedArrayElementFromPreparedValue(
110       TNode<Context> context, TNode<JSTypedArray> typed_array,
111       TNode<UintPtrT> index_node, TNode<TValue> value,
112       ElementsKind elements_kind, Label* if_detached);
113 };
114 
115 }  // namespace internal
116 }  // namespace v8
117 
118 #endif  // V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_
119