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

Unified Diff: src/builtins/builtins-sharedarraybuffer.cc

Issue 2649703002: [Atomics] Make Atomics.compareExchange a builtin using TF (Closed)
Patch Set: PPC and S390 Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/compiler/arm/code-generator-arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-sharedarraybuffer.cc
diff --git a/src/builtins/builtins-sharedarraybuffer.cc b/src/builtins/builtins-sharedarraybuffer.cc
index b651dbd30244a4fec43cfc93624b48b0ea684cc1..4f7abd0d94c95d1e43d348157848e3633834b8e6 100644
--- a/src/builtins/builtins-sharedarraybuffer.cc
+++ b/src/builtins/builtins-sharedarraybuffer.cc
@@ -293,7 +293,6 @@ void Builtins::Generate_AtomicsExchange(compiler::CodeAssemblerState* state) {
#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
- // Node* index_integer = a.ToInteger(context, index);
a.Return(a.CallRuntime(Runtime::kAtomicsExchange, context, array,
index_integer, value_integer));
#else
@@ -348,5 +347,90 @@ void Builtins::Generate_AtomicsExchange(compiler::CodeAssemblerState* state) {
// || V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X
}
+void Builtins::Generate_AtomicsCompareExchange(
Jakob Kummerow 2017/03/09 13:43:42 please use the TF_BUILTIN macro to drop a bunch of
aseemgarg 2017/03/10 19:55:22 Done.
+ compiler::CodeAssemblerState* state) {
+ using compiler::Node;
+ CodeStubAssembler a(state);
+ Node* array = a.Parameter(1);
+ Node* index = a.Parameter(2);
+ Node* old_value = a.Parameter(3);
+ Node* new_value = a.Parameter(4);
+ Node* context = a.Parameter(5 + 2);
+
+ Node* instance_type;
+ Node* backing_store;
+ ValidateSharedTypedArray(&a, array, context, &instance_type, &backing_store);
+
+ Node* index_integer;
+ Node* index_word32 =
+ ConvertTaggedAtomicIndexToWord32(&a, index, context, &index_integer);
+ Node* array_length_word32 = a.TruncateTaggedToWord32(
+ context, a.LoadObjectField(array, JSTypedArray::kLengthOffset));
+ ValidateAtomicIndex(&a, index_word32, array_length_word32, context);
+
+ Node* old_value_integer = a.ToInteger(context, old_value);
+
+ Node* new_value_integer = a.ToInteger(context, new_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
+ a.Return(a.CallRuntime(Runtime::kAtomicsCompareExchange, context, array,
+ index_integer, old_value_integer, new_value_integer));
+#else
+ Node* index_word = a.ChangeUint32ToWord(index_word32);
+
+ Node* old_value_word32 = a.TruncateTaggedToWord32(context, old_value_integer);
+
+ Node* new_value_word32 = a.TruncateTaggedToWord32(context, new_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(&i8);
+ a.Return(a.SmiFromWord32(
+ a.AtomicCompareExchange(MachineType::Int8(), backing_store, index_word,
+ old_value_word32, new_value_word32)));
+
+ a.Bind(&u8);
+ a.Return(a.SmiFromWord32(
+ a.AtomicCompareExchange(MachineType::Uint8(), backing_store, index_word,
+ old_value_word32, new_value_word32)));
+
+ a.Bind(&i16);
+ a.Return(a.SmiFromWord32(a.AtomicCompareExchange(
+ MachineType::Int16(), backing_store, a.WordShl(index_word, 1),
+ old_value_word32, new_value_word32)));
+
+ a.Bind(&u16);
+ a.Return(a.SmiFromWord32(a.AtomicCompareExchange(
+ MachineType::Uint16(), backing_store, a.WordShl(index_word, 1),
+ old_value_word32, new_value_word32)));
+
+ a.Bind(&i32);
+ a.Return(a.ChangeInt32ToTagged(a.AtomicCompareExchange(
+ MachineType::Int32(), backing_store, a.WordShl(index_word, 2),
+ old_value_word32, new_value_word32)));
+
+ a.Bind(&u32);
+ a.Return(a.ChangeUint32ToTagged(a.AtomicCompareExchange(
+ MachineType::Uint32(), backing_store, a.WordShl(index_word, 2),
+ old_value_word32, new_value_word32)));
+
+ // This shouldn't happen, we've already validated the type.
+ a.Bind(&other);
+ a.Return(a.SmiConstant(0));
Jakob Kummerow 2017/03/09 13:43:42 how about "Unreachable();" instead?
aseemgarg 2017/03/10 19:55:22 Done.
+#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
« no previous file with comments | « src/builtins/builtins.h ('k') | src/compiler/arm/code-generator-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698