Chromium Code Reviews| Index: src/builtins/builtins-sharedarraybuffer-gen.cc |
| diff --git a/src/builtins/builtins-sharedarraybuffer-gen.cc b/src/builtins/builtins-sharedarraybuffer-gen.cc |
| index a3acbd55c893107b36ed699673ea39b7f05d6bc7..6a9828b8b5f8f3a772451762943c43331cb9f6af 100644 |
| --- a/src/builtins/builtins-sharedarraybuffer-gen.cc |
| +++ b/src/builtins/builtins-sharedarraybuffer-gen.cc |
| @@ -12,6 +12,10 @@ namespace internal { |
| using compiler::Node; |
| +typedef std::function<Node*(MachineType type, Node* base, Node* offset, |
| + Node* value)> |
| + AssemblerFunction; |
| + |
| class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler { |
| public: |
| explicit SharedArrayBufferBuiltinsAssembler( |
| @@ -26,6 +30,9 @@ class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler { |
| Node** number_index); |
| void ValidateAtomicIndex(Node* index_word, Node* array_length_word, |
| Node* context); |
| + void BinaryBuiltinCommon(Node* array, Node* index, Node* value, Node* context, |
|
binji
2017/04/06 19:04:50
I think AtomicsRMW is a better name for this.
n/m
aseemgarg
2017/04/06 21:03:56
Done.
|
| + AssemblerFunction function, |
| + Runtime::FunctionId runtime_function); |
| }; |
| void SharedArrayBufferBuiltinsAssembler::ValidateSharedTypedArray( |
| @@ -402,5 +409,93 @@ TF_BUILTIN(AtomicsCompareExchange, SharedArrayBufferBuiltinsAssembler) { |
| // || V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X |
| } |
| +#define BINOP_BUILTIN(op) \ |
| + TF_BUILTIN(Atomics##op, SharedArrayBufferBuiltinsAssembler) { \ |
| + Node* array = Parameter(Descriptor::kArray); \ |
| + Node* index = Parameter(Descriptor::kIndex); \ |
| + Node* value = Parameter(Descriptor::kValue); \ |
| + Node* context = Parameter(Descriptor::kContext); \ |
| + AssemblerFunction function = [&](MachineType type, Node* base, \ |
|
binji
2017/04/06 19:04:50
Since this lambda is just forwarding the values th
aseemgarg
2017/04/06 21:03:56
Done.
|
| + Node* offset, Node* value) -> Node* { \ |
| + return Atomic##op(type, base, offset, value); \ |
| + }; \ |
| + BinaryBuiltinCommon(array, index, value, context, function, \ |
| + Runtime::kAtomics##op); \ |
| + } |
| +BINOP_BUILTIN(Add) |
| +BINOP_BUILTIN(Sub) |
| +BINOP_BUILTIN(And) |
| +BINOP_BUILTIN(Or) |
| +BINOP_BUILTIN(Xor) |
| +#undef BINOP_BUILTIN |
| + |
| +void SharedArrayBufferBuiltinsAssembler::BinaryBuiltinCommon( |
| + Node* array, Node* index, Node* value, Node* context, |
| + AssemblerFunction function, Runtime::FunctionId runtime_function) { |
| + Node* instance_type; |
| + Node* backing_store; |
| + ValidateSharedTypedArray(array, context, &instance_type, &backing_store); |
| + |
| + Node* index_integer; |
| + Node* index_word32 = |
| + ConvertTaggedAtomicIndexToWord32(index, context, &index_integer); |
| + Node* array_length_word32 = TruncateTaggedToWord32( |
| + context, LoadObjectField(array, JSTypedArray::kLengthOffset)); |
| + ValidateAtomicIndex(index_word32, array_length_word32, context); |
| + |
| + Node* value_integer = ToInteger(context, value); |
| + |
| +#if V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64 || \ |
| + V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X |
| + Return(CallRuntime(runtime_function, context, array, index_integer, |
| + value_integer)); |
| +#else |
| + Node* index_word = ChangeUint32ToWord(index_word32); |
| + |
| + Node* value_word32 = TruncateTaggedToWord32(context, value_integer); |
| + |
| + Label i8(this), u8(this), i16(this), u16(this), i32(this), u32(this), |
| + other(this); |
| + int32_t case_values[] = { |
| + FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, |
| + FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, |
| + }; |
| + Label* case_labels[] = { |
| + &i8, &u8, &i16, &u16, &i32, &u32, |
| + }; |
| + Switch(instance_type, &other, case_values, case_labels, |
| + arraysize(case_labels)); |
| + |
| + Bind(&i8); |
| + Return(SmiFromWord32( |
| + function(MachineType::Int8(), backing_store, index_word, value_word32))); |
| + |
| + Bind(&u8); |
| + Return(SmiFromWord32( |
| + function(MachineType::Uint8(), backing_store, index_word, value_word32))); |
| + |
| + Bind(&i16); |
| + Return(SmiFromWord32(function(MachineType::Int16(), backing_store, |
| + WordShl(index_word, 1), value_word32))); |
| + |
| + Bind(&u16); |
| + Return(SmiFromWord32(function(MachineType::Uint16(), backing_store, |
| + WordShl(index_word, 1), value_word32))); |
| + |
| + Bind(&i32); |
| + Return(ChangeInt32ToTagged(function(MachineType::Int32(), backing_store, |
| + WordShl(index_word, 2), value_word32))); |
| + |
| + Bind(&u32); |
| + Return(ChangeUint32ToTagged(function(MachineType::Uint32(), backing_store, |
| + WordShl(index_word, 2), value_word32))); |
| + |
| + // This shouldn't happen, we've already validated the type. |
| + Bind(&other); |
| + Unreachable(); |
| +#endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64 |
| + // || V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X |
| +} |
| + |
| } // namespace internal |
| } // namespace v8 |