Chromium Code Reviews| 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.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 4794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4805 | 4805 |
| 4806 void Builtins::Generate_InterruptCheck(MacroAssembler* masm) { | 4806 void Builtins::Generate_InterruptCheck(MacroAssembler* masm) { |
| 4807 masm->TailCallRuntime(Runtime::kInterrupt); | 4807 masm->TailCallRuntime(Runtime::kInterrupt); |
| 4808 } | 4808 } |
| 4809 | 4809 |
| 4810 | 4810 |
| 4811 void Builtins::Generate_StackCheck(MacroAssembler* masm) { | 4811 void Builtins::Generate_StackCheck(MacroAssembler* masm) { |
| 4812 masm->TailCallRuntime(Runtime::kStackGuard); | 4812 masm->TailCallRuntime(Runtime::kStackGuard); |
| 4813 } | 4813 } |
| 4814 | 4814 |
| 4815 namespace { | |
| 4816 | |
| 4817 void ValidateSharedTypedArray(compiler::CodeStubAssembler* a, | |
| 4818 compiler::Node* tagged, compiler::Node* context) { | |
| 4819 using namespace compiler; | |
| 4820 CodeStubAssembler::Label is_smi(a), not_smi(a), is_typed_array(a), | |
| 4821 not_typed_array(a), is_shared(a), not_shared(a), is_float_or_clamped(a), | |
| 4822 not_float_or_clamped(a), invalid(a); | |
| 4823 | |
| 4824 // Fail if it is not a heap object. | |
| 4825 a->Branch(a->WordIsSmi(tagged), &is_smi, ¬_smi); | |
| 4826 a->Bind(&is_smi); | |
| 4827 a->Goto(&invalid); | |
| 4828 | |
| 4829 // Fail if the array's instance type is not JSTypedArray. | |
| 4830 a->Bind(¬_smi); | |
| 4831 a->Branch(a->WordEqual(a->LoadInstanceType(tagged), | |
| 4832 a->Int32Constant(JS_TYPED_ARRAY_TYPE)), | |
| 4833 &is_typed_array, ¬_typed_array); | |
| 4834 a->Bind(¬_typed_array); | |
| 4835 a->Goto(&invalid); | |
| 4836 | |
| 4837 // Fail if the array's JSArrayBuffer is not shared. | |
| 4838 a->Bind(&is_typed_array); | |
| 4839 Node* is_buffer_shared = | |
| 4840 a->BitFieldDecode<JSArrayBuffer::IsShared>(a->LoadObjectField( | |
| 4841 a->LoadObjectField(tagged, JSTypedArray::kBufferOffset), | |
| 4842 JSArrayBuffer::kBitFieldOffset)); | |
| 4843 a->Branch(is_buffer_shared, &is_shared, ¬_shared); | |
| 4844 a->Bind(¬_shared); | |
| 4845 a->Goto(&invalid); | |
| 4846 | |
| 4847 // Fail if the array's element type is float32, float64 or clamped. | |
| 4848 a->Bind(&is_shared); | |
| 4849 Node* elements_instance_type = a->LoadInstanceType( | |
| 4850 a->LoadObjectField(tagged, JSObject::kElementsOffset)); | |
| 4851 Node* is_float32 = a->WordEqual(elements_instance_type, | |
|
Benedikt Meurer
2016/04/06 05:51:21
You can simplify this to instance_type < FIXED_FLO
binji
2016/04/06 19:26:02
Done.
| |
| 4852 a->Int32Constant(FIXED_FLOAT32_ARRAY_TYPE)); | |
| 4853 Node* is_float64 = a->WordEqual(elements_instance_type, | |
| 4854 a->Int32Constant(FIXED_FLOAT64_ARRAY_TYPE)); | |
| 4855 Node* is_uint8_clamped = a->WordEqual( | |
| 4856 elements_instance_type, a->Int32Constant(FIXED_UINT8_CLAMPED_ARRAY_TYPE)); | |
| 4857 a->Branch(a->WordOr(a->WordOr(is_float32, is_float64), is_uint8_clamped), | |
| 4858 &is_float_or_clamped, ¬_float_or_clamped); | |
| 4859 a->Bind(&is_float_or_clamped); | |
| 4860 a->Goto(&invalid); | |
| 4861 | |
| 4862 a->Bind(&invalid); | |
| 4863 a->CallRuntime(Runtime::kThrowNotIntegerSharedTypedArrayError, context, | |
| 4864 tagged); | |
| 4865 a->Return(a->UndefinedConstant()); | |
| 4866 | |
| 4867 a->Bind(¬_float_or_clamped); | |
| 4868 } | |
| 4869 | |
| 4870 // https://tc39.github.io/ecmascript_sharedmem/shmem.html#Atomics.ValidateAtomic Access | |
| 4871 compiler::Node* ConvertTaggedAtomicIndexToWord32(compiler::CodeStubAssembler* a, | |
| 4872 compiler::Node* tagged, | |
| 4873 compiler::Node* context) { | |
| 4874 using namespace compiler; | |
| 4875 CodeStubAssembler::Variable var_result(a, MachineRepresentation::kWord32); | |
| 4876 | |
| 4877 Callable to_number = CodeFactory::ToNumber(a->isolate()); | |
| 4878 Node* number_index = a->CallStub(to_number, context, tagged); | |
| 4879 CodeStubAssembler::Label done(a, &var_result); | |
| 4880 | |
| 4881 CodeStubAssembler::Label if_numberissmi(a), if_numberisnotsmi(a); | |
| 4882 a->Branch(a->WordIsSmi(number_index), &if_numberissmi, &if_numberisnotsmi); | |
| 4883 | |
| 4884 a->Bind(&if_numberissmi); | |
| 4885 { | |
| 4886 var_result.Bind(a->SmiToWord32(number_index)); | |
| 4887 a->Goto(&done); | |
| 4888 } | |
| 4889 | |
| 4890 a->Bind(&if_numberisnotsmi); | |
| 4891 { | |
| 4892 Node* number_index_value = a->LoadHeapNumberValue(number_index); | |
| 4893 Node* access_index = a->TruncateFloat64ToInt32(number_index_value); | |
| 4894 Node* test_index = a->ChangeInt32ToFloat64(access_index); | |
| 4895 | |
| 4896 CodeStubAssembler::Label if_indexesareequal(a), if_indexesarenotequal(a); | |
| 4897 a->Branch(a->Float64Equal(number_index_value, test_index), | |
| 4898 &if_indexesareequal, &if_indexesarenotequal); | |
| 4899 | |
| 4900 a->Bind(&if_indexesareequal); | |
| 4901 { | |
| 4902 var_result.Bind(access_index); | |
| 4903 a->Goto(&done); | |
| 4904 } | |
| 4905 | |
| 4906 a->Bind(&if_indexesarenotequal); | |
| 4907 a->Return( | |
| 4908 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); | |
| 4909 } | |
| 4910 | |
| 4911 a->Bind(&done); | |
| 4912 return var_result.value(); | |
| 4913 } | |
| 4914 | |
| 4915 void ValidateAtomicIndex(compiler::CodeStubAssembler* a, | |
| 4916 compiler::Node* index_word, | |
| 4917 compiler::Node* array_length_word, | |
| 4918 compiler::Node* context) { | |
| 4919 using namespace compiler; | |
| 4920 // Check if the index is in bounds. If not, throw RangeError. | |
| 4921 CodeStubAssembler::Label if_inbounds(a), if_notinbounds(a); | |
| 4922 a->Branch( | |
| 4923 a->WordOr(a->Int32LessThan(index_word, a->Int32Constant(0)), | |
| 4924 a->Int32GreaterThanOrEqual(index_word, array_length_word)), | |
| 4925 &if_notinbounds, &if_inbounds); | |
| 4926 a->Bind(&if_notinbounds); | |
| 4927 a->Return( | |
| 4928 a->CallRuntime(Runtime::kThrowInvalidAtomicAccessIndexError, context)); | |
| 4929 a->Bind(&if_inbounds); | |
| 4930 } | |
| 4931 | |
| 4932 } // anonymous namespace | |
| 4933 | |
| 4934 void Builtins::Generate_AtomicsLoadCheck(compiler::CodeStubAssembler* a) { | |
| 4935 using namespace compiler; | |
| 4936 Isolate* isolate = a->isolate(); | |
| 4937 Node* array = a->Parameter(1); | |
| 4938 Node* index = a->Parameter(2); | |
| 4939 Node* context = a->Parameter(3 + 2); | |
| 4940 ValidateSharedTypedArray(a, array, context); | |
| 4941 Node* index_word = ConvertTaggedAtomicIndexToWord32(a, index, context); | |
| 4942 Node* array_length_word = a->TruncateTaggedToWord32( | |
| 4943 context, a->LoadObjectField(array, JSTypedArray::kLengthOffset)); | |
| 4944 ValidateAtomicIndex(a, index_word, array_length_word, context); | |
| 4945 | |
| 4946 Callable atomics_load = CodeFactory::AtomicsLoad(isolate); | |
| 4947 Node* target = a->HeapConstant(atomics_load.code()); | |
| 4948 a->Return(a->CallStub(atomics_load.descriptor(), target, context, array, | |
| 4949 index_word)); | |
| 4950 } | |
| 4815 | 4951 |
| 4816 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ | 4952 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ |
| 4817 Handle<Code> Builtins::name() { \ | 4953 Handle<Code> Builtins::name() { \ |
| 4818 Code** code_address = \ | 4954 Code** code_address = \ |
| 4819 reinterpret_cast<Code**>(builtin_address(k##name)); \ | 4955 reinterpret_cast<Code**>(builtin_address(k##name)); \ |
| 4820 return Handle<Code>(code_address); \ | 4956 return Handle<Code>(code_address); \ |
| 4821 } | 4957 } |
| 4822 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ | 4958 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ |
| 4823 Handle<Code> Builtins::name() { \ | 4959 Handle<Code> Builtins::name() { \ |
| 4824 Code** code_address = \ | 4960 Code** code_address = \ |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4841 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | 4977 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) |
| 4842 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4978 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 4843 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4979 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 4844 #undef DEFINE_BUILTIN_ACCESSOR_C | 4980 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 4845 #undef DEFINE_BUILTIN_ACCESSOR_A | 4981 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 4846 #undef DEFINE_BUILTIN_ACCESSOR_T | 4982 #undef DEFINE_BUILTIN_ACCESSOR_T |
| 4847 #undef DEFINE_BUILTIN_ACCESSOR_H | 4983 #undef DEFINE_BUILTIN_ACCESSOR_H |
| 4848 | 4984 |
| 4849 } // namespace internal | 4985 } // namespace internal |
| 4850 } // namespace v8 | 4986 } // namespace v8 |
| OLD | NEW |