Index: src/builtins/builtins-sharedarraybuffer.cc |
diff --git a/src/builtins/builtins-sharedarraybuffer.cc b/src/builtins/builtins-sharedarraybuffer.cc |
index 53caf1fe21640ef1afb948c0f94c0bf8d2a1ee93..0a0e4064967e1f123e2bcc90aea82f629993bb5c 100644 |
--- a/src/builtins/builtins-sharedarraybuffer.cc |
+++ b/src/builtins/builtins-sharedarraybuffer.cc |
@@ -266,5 +266,71 @@ void Builtins::Generate_AtomicsStore(compiler::CodeAssemblerState* state) { |
a.Return(a.SmiConstant(0)); |
} |
+void Builtins::Generate_AtomicsExchange(compiler::CodeAssemblerState* state) { |
+ using compiler::Node; |
+ CodeStubAssembler a(state); |
+ Node* array = a.Parameter(1); |
+ Node* index = a.Parameter(2); |
+ Node* value = a.Parameter(3); |
+ Node* context = a.Parameter(4 + 2); |
+ |
+ Node* instance_type; |
+ Node* backing_store; |
+ ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store); |
+ |
+ Node* index_word32 = ConvertTaggedAtomicIndexToWord32(&a, index, context); |
+ Node* array_length_word32 = a.TruncateTaggedToWord32( |
+ context, a.LoadObjectField(array, JSTypedArray::kLengthOffset)); |
+ ValidateAtomicIndex(&a, index_word32, array_length_word32, context); |
+ Node* index_word = a.ChangeUint32ToWord(index_word32); |
+ |
+ Node* value_integer = a.ToInteger(context, value); |
+ Node* value_word32 = a.TruncateTaggedToWord32(context, value_integer); |
+ |
+ CodeStubAssembler::Label i8(&a), u8(&a), i16(&a), u16(&a), i32(&a), u32(&a), |
+ other(&a); |
+ 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, |
+ }; |
+ CodeStubAssembler::Label* case_labels[] = { |
+ &i8, &u8, &i16, &u16, &i32, &u32, |
+ }; |
+ a.Switch(instance_type, &other, case_values, case_labels, |
+ arraysize(case_labels)); |
+ |
+ a.Bind(&u8); |
binji
2017/01/13 00:08:50
nit: I'd prefer matching the order of the case lab
aseemgarg
2017/01/14 01:48:19
Done.
|
+ a.Return(a.SmiFromWord32(a.AtomicExchange(MachineType::Uint8(), backing_store, |
+ index_word, value_word32))); |
+ |
+ a.Bind(&i8); |
+ a.Return(a.SmiFromWord32(a.AtomicExchange(MachineType::Int8(), backing_store, |
+ index_word, value_word32))); |
+ |
+ a.Bind(&u16); |
+ a.Return(a.SmiFromWord32( |
+ a.AtomicExchange(MachineType::Uint16(), backing_store, |
+ a.WordShl(index_word, 1), value_word32))); |
+ |
+ a.Bind(&i16); |
+ a.Return(a.SmiFromWord32(a.AtomicExchange(MachineType::Int16(), backing_store, |
+ a.WordShl(index_word, 1), |
+ value_word32))); |
+ |
+ a.Bind(&u32); |
+ a.Return(a.ChangeUint32ToTagged( |
+ a.AtomicExchange(MachineType::Uint32(), backing_store, |
+ a.WordShl(index_word, 2), value_word32))); |
+ |
+ a.Bind(&i32); |
+ a.Return(a.ChangeInt32ToTagged( |
+ a.AtomicExchange(MachineType::Int32(), backing_store, |
+ a.WordShl(index_word, 2), value_word32))); |
+ |
+ // This shouldn't happen, we've already validated the type. |
+ a.Bind(&other); |
+ a.Return(a.SmiConstant(0)); |
+} |
+ |
} // namespace internal |
} // namespace v8 |