Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: src/builtins.cc

Issue 1617503003: [Atomics] code stubs for atomic operations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: smi dcheck Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.h" 7 #include "src/api.h"
8 #include "src/api-arguments.h" 8 #include "src/api-arguments.h"
9 #include "src/api-natives.h" 9 #include "src/api-natives.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 4904 matching lines...) Expand 10 before | Expand all | Expand 10 after
4915 4915
4916 void Builtins::Generate_InterruptCheck(MacroAssembler* masm) { 4916 void Builtins::Generate_InterruptCheck(MacroAssembler* masm) {
4917 masm->TailCallRuntime(Runtime::kInterrupt); 4917 masm->TailCallRuntime(Runtime::kInterrupt);
4918 } 4918 }
4919 4919
4920 4920
4921 void Builtins::Generate_StackCheck(MacroAssembler* masm) { 4921 void Builtins::Generate_StackCheck(MacroAssembler* masm) {
4922 masm->TailCallRuntime(Runtime::kStackGuard); 4922 masm->TailCallRuntime(Runtime::kStackGuard);
4923 } 4923 }
4924 4924
4925 namespace {
4926
4927 void ValidateSharedTypedArray(compiler::CodeStubAssembler* a,
4928 compiler::Node* tagged, compiler::Node* context) {
4929 using namespace compiler;
4930 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a),
4931 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a),
4932 not_float_or_clamped(a), invalid(a);
4933
4934 // Fail if it is not a heap object.
4935 a->Branch(a->WordIsSmi(tagged), &is_smi, &not_smi);
4936 a->Bind(&is_smi);
4937 a->Goto(&invalid);
4938
4939 // Fail if the array's instance type is not JSTypedArray.
4940 a->Bind(&not_smi);
4941 a->Branch(a->WordEqual(a->LoadInstanceType(tagged),
4942 a->Int32Constant(JS_TYPED_ARRAY_TYPE)),
4943 &is_typed_array, &not_typed_array);
4944 a->Bind(&not_typed_array);
4945 a->Goto(&invalid);
4946
4947 // Fail if the array's JSArrayBuffer is not shared.
4948 a->Bind(&is_typed_array);
4949 Node* is_buffer_shared =
4950 a->BitFieldDecode<JSArrayBuffer::IsShared>(a->LoadObjectField(
4951 a->LoadObjectField(tagged, JSTypedArray::kBufferOffset),
4952 JSArrayBuffer::kBitFieldOffset));
4953 a->Branch(is_buffer_shared, &is_shared, &not_shared);
4954 a->Bind(&not_shared);
4955 a->Goto(&invalid);
4956
4957 // Fail if the array's element type is float32, float64 or clamped.
4958 a->Bind(&is_shared);
4959 Node* elements_instance_type = a->LoadInstanceType(
4960 a->LoadObjectField(tagged, JSObject::kElementsOffset));
4961 STATIC_ASSERT(FIXED_INT8_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE);
4962 STATIC_ASSERT(FIXED_INT16_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE);
4963 STATIC_ASSERT(FIXED_INT32_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE);
4964 STATIC_ASSERT(FIXED_UINT8_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE);
4965 STATIC_ASSERT(FIXED_UINT16_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE);
4966 STATIC_ASSERT(FIXED_UINT32_ARRAY_TYPE < FIXED_FLOAT32_ARRAY_TYPE);
4967 a->Branch(a->Int32LessThan(elements_instance_type,
4968 a->Int32Constant(FIXED_FLOAT32_ARRAY_TYPE)),
4969 &not_float_or_clamped, &is_float_or_clamped);
4970 a->Bind(&is_float_or_clamped);
4971 a->Goto(&invalid);
4972
4973 a->Bind(&invalid);
4974 a->CallRuntime(Runtime::kThrowNotIntegerSharedTypedArrayError, context,
4975 tagged);
4976 a->Return(a->UndefinedConstant());
4977
4978 a->Bind(&not_float_or_clamped);
4979 }
4980
4981 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access
4982 compiler::Node* ConvertTaggedAtomicIndexToWord32(compiler::CodeStubAssembler* a,
4983 compiler::Node* tagged,
4984 compiler::Node* context) {
4985 using namespace compiler;
4986 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32);
4987
4988 Callable to_number = CodeFactory::ToNumber(a->isolate());
4989 Node* number_index = a->CallStub(to_number, context, tagged);
4990 CodeStubAssembler::Label done(a, &var_result);
4991
4992 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a);
4993 a->Branch(a->WordIsSmi(number_index), &if_numberissmi, &if_numberisnotsmi);
4994
4995 a->Bind(&if_numberissmi);
4996 {
4997 var_result.Bind(a->SmiToWord32(number_index));
4998 a->Goto(&done);
4999 }
5000
5001 a->Bind(&if_numberisnotsmi);
5002 {
5003 Node* number_index_value = a->LoadHeapNumberValue(number_index);
5004 Node* access_index = a->TruncateFloat64ToInt32(number_index_value);
5005 Node* test_index = a->ChangeInt32ToFloat64(access_index);
5006
5007 CodeStubAssembler::Label if_indexesareequal(a), if_indexesarenotequal(a);
5008 a->Branch(a->Float64Equal(number_index_value, test_index),
5009 &if_indexesareequal, &if_indexesarenotequal);
5010
5011 a->Bind(&if_indexesareequal);
5012 {
5013 var_result.Bind(access_index);
5014 a->Goto(&done);
5015 }
5016
5017 a->Bind(&if_indexesarenotequal);
5018 a->Return(
5019 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context));
5020 }
5021
5022 a->Bind(&done);
5023 return var_result.value();
5024 }
5025
5026 void ValidateAtomicIndex(compiler::CodeStubAssembler* a,
5027 compiler::Node* index_word,
5028 compiler::Node* array_length_word,
5029 compiler::Node* context) {
5030 using namespace compiler;
5031 // Check if the index is in bounds. If not, throw RangeError.
5032 CodeStubAssembler::Label if_inbounds(a), if_notinbounds(a);
5033 a->Branch(
5034 a->WordOr(a->Int32LessThan(index_word, a->Int32Constant(0)),
5035 a->Int32GreaterThanOrEqual(index_word, array_length_word)),
5036 &if_notinbounds, &if_inbounds);
5037 a->Bind(&if_notinbounds);
5038 a->Return(
5039 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context));
5040 a->Bind(&if_inbounds);
5041 }
5042
5043 } // anonymous namespace
5044
5045 void Builtins::Generate_AtomicsLoadCheck(compiler::CodeStubAssembler* a) {
5046 using namespace compiler;
5047 Isolate* isolate = a->isolate();
5048 Node* array = a->Parameter(1);
5049 Node* index = a->Parameter(2);
5050 Node* context = a->Parameter(3 + 2);
5051 ValidateSharedTypedArray(a, array, context);
5052 Node* index_word = ConvertTaggedAtomicIndexToWord32(a, index, context);
5053 Node* array_length_word = a->TruncateTaggedToWord32(
5054 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset));
5055 ValidateAtomicIndex(a, index_word, array_length_word, context);
5056
5057 Callable atomics_load = CodeFactory::AtomicsLoad(isolate);
5058 Node* target = a->HeapConstant(atomics_load.code());
5059 a->Return(a->CallStub(atomics_load.descriptor(), target, context, array,
5060 index_word));
5061 }
4925 5062
4926 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ 5063 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \
4927 Handle<Code> Builtins::name() { \ 5064 Handle<Code> Builtins::name() { \
4928 Code** code_address = \ 5065 Code** code_address = \
4929 reinterpret_cast<Code**>(builtin_address(k##name)); \ 5066 reinterpret_cast<Code**>(builtin_address(k##name)); \
4930 return Handle<Code>(code_address); \ 5067 return Handle<Code>(code_address); \
4931 } 5068 }
4932 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ 5069 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \
4933 Handle<Code> Builtins::name() { \ 5070 Handle<Code> Builtins::name() { \
4934 Code** code_address = \ 5071 Code** code_address = \
(...skipping 16 matching lines...) Expand all
4951 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 5088 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
4952 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 5089 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4953 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 5090 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4954 #undef DEFINE_BUILTIN_ACCESSOR_C 5091 #undef DEFINE_BUILTIN_ACCESSOR_C
4955 #undef DEFINE_BUILTIN_ACCESSOR_A 5092 #undef DEFINE_BUILTIN_ACCESSOR_A
4956 #undef DEFINE_BUILTIN_ACCESSOR_T 5093 #undef DEFINE_BUILTIN_ACCESSOR_T
4957 #undef DEFINE_BUILTIN_ACCESSOR_H 5094 #undef DEFINE_BUILTIN_ACCESSOR_H
4958 5095
4959 } // namespace internal 5096 } // namespace internal
4960 } // namespace v8 5097 } // namespace v8
OLDNEW
« src/arm64/code-stubs-arm64.cc ('K') | « src/builtins.h ('k') | src/code-factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698