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 "torque-generated/builtins-base-from-dsl-gen.h" 9 10 namespace v8 { 11 namespace internal { 12 13 class TypedArrayBuiltinsAssembler : public BaseBuiltinsFromDSLAssembler { 14 public: TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState * state)15 explicit TypedArrayBuiltinsAssembler(compiler::CodeAssemblerState* state) 16 : BaseBuiltinsFromDSLAssembler(state) {} 17 18 TNode<JSTypedArray> SpeciesCreateByLength(TNode<Context> context, 19 TNode<JSTypedArray> exemplar, 20 TNode<Smi> len, 21 const char* method_name); 22 23 protected: 24 void GenerateTypedArrayPrototypeGetter(Node* context, Node* receiver, 25 const char* method_name, 26 int object_offset); 27 void GenerateTypedArrayPrototypeIterationMethod(TNode<Context> context, 28 TNode<Object> receiver, 29 const char* method_name, 30 IterationKind iteration_kind); 31 32 void ConstructByLength(TNode<Context> context, TNode<JSTypedArray> holder, 33 TNode<Object> length, TNode<Smi> element_size); 34 void ConstructByArrayBuffer(TNode<Context> context, 35 TNode<JSTypedArray> holder, 36 TNode<JSArrayBuffer> buffer, 37 TNode<Object> byte_offset, TNode<Object> length, 38 TNode<Smi> element_size); 39 void ConstructByTypedArray(TNode<Context> context, TNode<JSTypedArray> holder, 40 TNode<JSTypedArray> typed_array, 41 TNode<Smi> element_size); 42 void ConstructByArrayLike(TNode<Context> context, TNode<JSTypedArray> holder, 43 TNode<HeapObject> array_like, 44 TNode<Object> initial_length, 45 TNode<Smi> element_size, 46 TNode<JSReceiver> buffer_constructor); 47 void ConstructByIterable(TNode<Context> context, TNode<JSTypedArray> holder, 48 TNode<JSReceiver> iterable, 49 TNode<JSReceiver> iterator_fn, 50 TNode<Smi> element_size); 51 52 void SetupTypedArray(TNode<JSTypedArray> holder, TNode<Smi> length, 53 TNode<Number> byte_offset, TNode<Number> byte_length); 54 void AttachBuffer(TNode<JSTypedArray> holder, TNode<JSArrayBuffer> buffer, 55 TNode<Map> map, TNode<Smi> length, 56 TNode<Number> byte_offset); 57 58 TNode<Map> LoadMapForType(TNode<JSTypedArray> array); 59 TNode<UintPtrT> CalculateExternalPointer(TNode<UintPtrT> backing_store, 60 TNode<Number> byte_offset); 61 Node* LoadDataPtr(Node* typed_array); 62 TNode<BoolT> ByteLengthIsValid(TNode<Number> byte_length); 63 64 // Returns true if kind is either UINT8_ELEMENTS or UINT8_CLAMPED_ELEMENTS. 65 TNode<Word32T> IsUint8ElementsKind(TNode<Word32T> kind); 66 67 // Returns true if kind is either BIGINT64_ELEMENTS or BIGUINT64_ELEMENTS. 68 TNode<Word32T> IsBigInt64ElementsKind(TNode<Word32T> kind); 69 70 // Returns the byte size of an element for a TypedArray elements kind. 71 TNode<IntPtrT> GetTypedArrayElementSize(TNode<Word32T> elements_kind); 72 LoadTypedArrayBuffer(TNode<JSTypedArray> typed_array)73 TNode<JSArrayBuffer> LoadTypedArrayBuffer(TNode<JSTypedArray> typed_array) { 74 return LoadObjectField<JSArrayBuffer>(typed_array, 75 JSTypedArray::kBufferOffset); 76 } 77 78 TNode<Object> GetDefaultConstructor(TNode<Context> context, 79 TNode<JSTypedArray> exemplar); 80 81 TNode<Object> TypedArraySpeciesConstructor(TNode<Context> context, 82 TNode<JSTypedArray> exemplar); 83 84 TNode<JSTypedArray> SpeciesCreateByArrayBuffer(TNode<Context> context, 85 TNode<JSTypedArray> exemplar, 86 TNode<JSArrayBuffer> buffer, 87 TNode<Number> byte_offset, 88 TNode<Smi> len, 89 const char* method_name); 90 91 TNode<JSTypedArray> CreateByLength(TNode<Context> context, 92 TNode<Object> constructor, TNode<Smi> len, 93 const char* method_name); 94 95 TNode<JSArrayBuffer> GetBuffer(TNode<Context> context, 96 TNode<JSTypedArray> array); 97 98 TNode<JSTypedArray> ValidateTypedArray(TNode<Context> context, 99 TNode<Object> obj, 100 const char* method_name); 101 102 // Fast path for setting a TypedArray (source) onto another TypedArray 103 // (target) at an element offset. 104 void SetTypedArraySource(TNode<Context> context, TNode<JSTypedArray> source, 105 TNode<JSTypedArray> target, TNode<IntPtrT> offset, 106 Label* call_runtime, Label* if_source_too_large); 107 108 void SetJSArraySource(TNode<Context> context, TNode<JSArray> source, 109 TNode<JSTypedArray> target, TNode<IntPtrT> offset, 110 Label* call_runtime, Label* if_source_too_large); 111 112 void CallCMemmove(TNode<IntPtrT> dest_ptr, TNode<IntPtrT> src_ptr, 113 TNode<IntPtrT> byte_length); 114 115 void CallCCopyFastNumberJSArrayElementsToTypedArray( 116 TNode<Context> context, TNode<JSArray> source, TNode<JSTypedArray> dest, 117 TNode<IntPtrT> source_length, TNode<IntPtrT> offset); 118 119 void CallCCopyTypedArrayElementsToTypedArray(TNode<JSTypedArray> source, 120 TNode<JSTypedArray> dest, 121 TNode<IntPtrT> source_length, 122 TNode<IntPtrT> offset); 123 124 void CallCCopyTypedArrayElementsSlice(TNode<JSTypedArray> source, 125 TNode<JSTypedArray> dest, 126 TNode<IntPtrT> start, 127 TNode<IntPtrT> end); 128 129 typedef std::function<void(ElementsKind, int, int)> TypedArraySwitchCase; 130 131 void DispatchTypedArrayByElementsKind( 132 TNode<Word32T> elements_kind, const TypedArraySwitchCase& case_function); 133 }; 134 135 } // namespace internal 136 } // namespace v8 137 138 #endif // V8_BUILTINS_BUILTINS_TYPED_ARRAY_GEN_H_ 139