OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/builtins.h" | 5 #include "src/builtins.h" |
6 | 6 |
7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 5133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5144 } | 5144 } |
5145 | 5145 |
5146 | 5146 |
5147 void Builtins::Generate_StackCheck(MacroAssembler* masm) { | 5147 void Builtins::Generate_StackCheck(MacroAssembler* masm) { |
5148 masm->TailCallRuntime(Runtime::kStackGuard); | 5148 masm->TailCallRuntime(Runtime::kStackGuard); |
5149 } | 5149 } |
5150 | 5150 |
5151 namespace { | 5151 namespace { |
5152 | 5152 |
5153 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged, | 5153 void ValidateSharedTypedArray(CodeStubAssembler* a, compiler::Node* tagged, |
5154 compiler::Node* context) { | 5154 compiler::Node* context, |
| 5155 compiler::Node** out_instance_type, |
| 5156 compiler::Node** out_backing_store) { |
5155 using namespace compiler; | 5157 using namespace compiler; |
5156 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a), | 5158 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a), |
5157 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a), | 5159 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a), |
5158 not_float_or_clamped(a), invalid(a); | 5160 not_float_or_clamped(a), invalid(a); |
5159 | 5161 |
5160 // Fail if it is not a heap object. | 5162 // Fail if it is not a heap object. |
5161 a->Branch(a->WordIsSmi(tagged), &is_smi, ¬_smi); | 5163 a->Branch(a->WordIsSmi(tagged), &is_smi, ¬_smi); |
5162 a->Bind(&is_smi); | 5164 a->Bind(&is_smi); |
5163 a->Goto(&invalid); | 5165 a->Goto(&invalid); |
5164 | 5166 |
5165 // Fail if the array's instance type is not JSTypedArray. | 5167 // Fail if the array's instance type is not JSTypedArray. |
5166 a->Bind(¬_smi); | 5168 a->Bind(¬_smi); |
5167 a->Branch(a->WordEqual(a->LoadInstanceType(tagged), | 5169 a->Branch(a->WordEqual(a->LoadInstanceType(tagged), |
5168 a->Int32Constant(JS_TYPED_ARRAY_TYPE)), | 5170 a->Int32Constant(JS_TYPED_ARRAY_TYPE)), |
5169 &is_typed_array, ¬_typed_array); | 5171 &is_typed_array, ¬_typed_array); |
5170 a->Bind(¬_typed_array); | 5172 a->Bind(¬_typed_array); |
5171 a->Goto(&invalid); | 5173 a->Goto(&invalid); |
5172 | 5174 |
5173 // Fail if the array's JSArrayBuffer is not shared. | 5175 // Fail if the array's JSArrayBuffer is not shared. |
5174 a->Bind(&is_typed_array); | 5176 a->Bind(&is_typed_array); |
5175 Node* is_buffer_shared = | 5177 Node* array_buffer = a->LoadObjectField(tagged, JSTypedArray::kBufferOffset); |
5176 a->BitFieldDecode<JSArrayBuffer::IsShared>(a->LoadObjectField( | 5178 Node* is_buffer_shared = a->BitFieldDecode<JSArrayBuffer::IsShared>( |
5177 a->LoadObjectField(tagged, JSTypedArray::kBufferOffset), | 5179 a->LoadObjectField(array_buffer, JSArrayBuffer::kBitFieldOffset)); |
5178 JSArrayBuffer::kBitFieldOffset)); | |
5179 a->Branch(is_buffer_shared, &is_shared, ¬_shared); | 5180 a->Branch(is_buffer_shared, &is_shared, ¬_shared); |
5180 a->Bind(¬_shared); | 5181 a->Bind(¬_shared); |
5181 a->Goto(&invalid); | 5182 a->Goto(&invalid); |
5182 | 5183 |
5183 // Fail if the array's element type is float32, float64 or clamped. | 5184 // Fail if the array's element type is float32, float64 or clamped. |
5184 a->Bind(&is_shared); | 5185 a->Bind(&is_shared); |
5185 Node* elements_instance_type = a->LoadInstanceType( | 5186 Node* elements_instance_type = a->LoadInstanceType( |
5186 a->LoadObjectField(tagged, JSObject::kElementsOffset)); | 5187 a->LoadObjectField(tagged, JSObject::kElementsOffset)); |
5187 STATIC_ASSERT(FIXED_INT8_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); | 5188 STATIC_ASSERT(FIXED_INT8_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); |
5188 STATIC_ASSERT(FIXED_INT16_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); | 5189 STATIC_ASSERT(FIXED_INT16_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); |
5189 STATIC_ASSERT(FIXED_INT32_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); | 5190 STATIC_ASSERT(FIXED_INT32_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); |
5190 STATIC_ASSERT(FIXED_UINT8_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); | 5191 STATIC_ASSERT(FIXED_UINT8_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); |
5191 STATIC_ASSERT(FIXED_UINT16_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); | 5192 STATIC_ASSERT(FIXED_UINT16_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); |
5192 STATIC_ASSERT(FIXED_UINT32_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); | 5193 STATIC_ASSERT(FIXED_UINT32_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE); |
5193 a->Branch(a->Int32LessThan(elements_instance_type, | 5194 a->Branch(a->Int32LessThan(elements_instance_type, |
5194 a->Int32Constant(FIXED_FLOAT32_ARRAY_TYPE)), | 5195 a->Int32Constant(FIXED_FLOAT32_ARRAY_TYPE)), |
5195 ¬_float_or_clamped, &is_float_or_clamped); | 5196 ¬_float_or_clamped, &is_float_or_clamped); |
5196 a->Bind(&is_float_or_clamped); | 5197 a->Bind(&is_float_or_clamped); |
5197 a->Goto(&invalid); | 5198 a->Goto(&invalid); |
5198 | 5199 |
5199 a->Bind(&invalid); | 5200 a->Bind(&invalid); |
5200 a->CallRuntime(Runtime::kThrowNotIntegerSharedTypedArrayError, context, | 5201 a->CallRuntime(Runtime::kThrowNotIntegerSharedTypedArrayError, context, |
5201 tagged); | 5202 tagged); |
5202 a->Return(a->UndefinedConstant()); | 5203 a->Return(a->UndefinedConstant()); |
5203 | 5204 |
5204 a->Bind(¬_float_or_clamped); | 5205 a->Bind(¬_float_or_clamped); |
| 5206 *out_instance_type = elements_instance_type; |
| 5207 |
| 5208 Node* backing_store = |
| 5209 a->LoadObjectField(array_buffer, JSArrayBuffer::kBackingStoreOffset); |
| 5210 Node* byte_offset = a->ChangeUint32ToWord(a->TruncateTaggedToWord32( |
| 5211 context, |
| 5212 a->LoadObjectField(tagged, JSArrayBufferView::kByteOffsetOffset))); |
| 5213 *out_backing_store = a->IntPtrAdd(backing_store, byte_offset); |
5205 } | 5214 } |
5206 | 5215 |
5207 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic
Access | 5216 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic
Access |
5208 compiler::Node* ConvertTaggedAtomicIndexToWord32(CodeStubAssembler* a, | 5217 compiler::Node* ConvertTaggedAtomicIndexToWord32(CodeStubAssembler* a, |
5209 compiler::Node* tagged, | 5218 compiler::Node* tagged, |
5210 compiler::Node* context) { | 5219 compiler::Node* context) { |
5211 using namespace compiler; | 5220 using namespace compiler; |
5212 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32); | 5221 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32); |
5213 | 5222 |
5214 Callable to_number = CodeFactory::ToNumber(a->isolate()); | 5223 Callable to_number = CodeFactory::ToNumber(a->isolate()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5260 a->Int32GreaterThanOrEqual(index_word, array_length_word)), | 5269 a->Int32GreaterThanOrEqual(index_word, array_length_word)), |
5261 &if_notinbounds, &if_inbounds); | 5270 &if_notinbounds, &if_inbounds); |
5262 a->Bind(&if_notinbounds); | 5271 a->Bind(&if_notinbounds); |
5263 a->Return( | 5272 a->Return( |
5264 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); | 5273 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); |
5265 a->Bind(&if_inbounds); | 5274 a->Bind(&if_inbounds); |
5266 } | 5275 } |
5267 | 5276 |
5268 } // anonymous namespace | 5277 } // anonymous namespace |
5269 | 5278 |
5270 void Builtins::Generate_AtomicsLoadCheck(CodeStubAssembler* a) { | 5279 void Builtins::Generate_AtomicsLoad(CodeStubAssembler* a) { |
5271 using namespace compiler; | 5280 using namespace compiler; |
5272 Isolate* isolate = a->isolate(); | |
5273 Node* array = a->Parameter(1); | 5281 Node* array = a->Parameter(1); |
5274 Node* index = a->Parameter(2); | 5282 Node* index = a->Parameter(2); |
5275 Node* context = a->Parameter(3 + 2); | 5283 Node* context = a->Parameter(3 + 2); |
5276 ValidateSharedTypedArray(a, array, context); | 5284 |
5277 Node* index_word = ConvertTaggedAtomicIndexToWord32(a, index, context); | 5285 Node* instance_type; |
5278 Node* array_length_word = a->TruncateTaggedToWord32( | 5286 Node* backing_store; |
| 5287 ValidateSharedTypedArray(a, array, context, &instance_type, &backing_store); |
| 5288 |
| 5289 Node* index_word32 = ConvertTaggedAtomicIndexToWord32(a, index, context); |
| 5290 Node* array_length_word32 = a->TruncateTaggedToWord32( |
5279 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset)); | 5291 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset)); |
5280 ValidateAtomicIndex(a, index_word, array_length_word, context); | 5292 ValidateAtomicIndex(a, index_word32, array_length_word32, context); |
| 5293 Node* index_word = a->ChangeUint32ToWord(index_word32); |
5281 | 5294 |
5282 Callable atomics_load = CodeFactory::AtomicsLoad(isolate); | 5295 CodeStubAssembler::Label i8(a), u8(a), i16(a), u16(a), i32(a), u32(a), |
5283 Node* target = a->HeapConstant(atomics_load.code()); | 5296 other(a); |
5284 a->Return(a->CallStub(atomics_load.descriptor(), target, context, array, | 5297 int32_t case_values[] = { |
5285 index_word)); | 5298 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, |
| 5299 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, |
| 5300 }; |
| 5301 CodeStubAssembler::Label* case_labels[] = { |
| 5302 &i8, &u8, &i16, &u16, &i32, &u32, |
| 5303 }; |
| 5304 a->Switch(instance_type, &other, case_values, case_labels, |
| 5305 arraysize(case_labels)); |
| 5306 |
| 5307 a->Bind(&i8); |
| 5308 a->Return( |
| 5309 a->SmiTag(a->AtomicLoad(MachineType::Int8(), backing_store, index_word))); |
| 5310 |
| 5311 a->Bind(&u8); |
| 5312 a->Return(a->SmiTag( |
| 5313 a->AtomicLoad(MachineType::Uint8(), backing_store, index_word))); |
| 5314 |
| 5315 a->Bind(&i16); |
| 5316 a->Return(a->SmiTag(a->AtomicLoad(MachineType::Int16(), backing_store, |
| 5317 a->WordShl(index_word, 1)))); |
| 5318 |
| 5319 a->Bind(&u16); |
| 5320 a->Return(a->SmiTag(a->AtomicLoad(MachineType::Uint16(), backing_store, |
| 5321 a->WordShl(index_word, 1)))); |
| 5322 |
| 5323 a->Bind(&i32); |
| 5324 a->Return(a->ChangeInt32ToTagged(a->AtomicLoad( |
| 5325 MachineType::Int32(), backing_store, a->WordShl(index_word, 2)))); |
| 5326 |
| 5327 a->Bind(&u32); |
| 5328 a->Return(a->ChangeUint32ToTagged(a->AtomicLoad( |
| 5329 MachineType::Uint32(), backing_store, a->WordShl(index_word, 2)))); |
| 5330 |
| 5331 // This shouldn't happen, we've already validated the type. |
| 5332 a->Bind(&other); |
| 5333 a->Return(a->Int32Constant(0)); |
5286 } | 5334 } |
5287 | 5335 |
5288 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ | 5336 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ |
5289 Handle<Code> Builtins::name() { \ | 5337 Handle<Code> Builtins::name() { \ |
5290 Code** code_address = \ | 5338 Code** code_address = \ |
5291 reinterpret_cast<Code**>(builtin_address(k##name)); \ | 5339 reinterpret_cast<Code**>(builtin_address(k##name)); \ |
5292 return Handle<Code>(code_address); \ | 5340 return Handle<Code>(code_address); \ |
5293 } | 5341 } |
5294 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ | 5342 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ |
5295 Handle<Code> Builtins::name() { \ | 5343 Handle<Code> Builtins::name() { \ |
(...skipping 17 matching lines...) Expand all Loading... |
5313 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 5361 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
5314 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 5362 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
5315 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 5363 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
5316 #undef DEFINE_BUILTIN_ACCESSOR_C | 5364 #undef DEFINE_BUILTIN_ACCESSOR_C |
5317 #undef DEFINE_BUILTIN_ACCESSOR_A | 5365 #undef DEFINE_BUILTIN_ACCESSOR_A |
5318 #undef DEFINE_BUILTIN_ACCESSOR_T | 5366 #undef DEFINE_BUILTIN_ACCESSOR_T |
5319 #undef DEFINE_BUILTIN_ACCESSOR_H | 5367 #undef DEFINE_BUILTIN_ACCESSOR_H |
5320 | 5368 |
5321 } // namespace internal | 5369 } // namespace internal |
5322 } // namespace v8 | 5370 } // namespace v8 |
OLD | NEW |