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

Side by Side Diff: src/builtins/builtins-sharedarraybuffer-gen.cc

Issue 2799863002: [Atomics] use TFJ builtins for atomic add, sub, and, or, and xor (Closed)
Patch Set: [Atomics] use TFJ builtins for atomic add, sub, and, or, and xor Created 3 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 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 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/builtins-utils-gen.h" 5 #include "src/builtins/builtins-utils-gen.h"
6 #include "src/builtins/builtins.h" 6 #include "src/builtins/builtins.h"
7 #include "src/code-stub-assembler.h" 7 #include "src/code-stub-assembler.h"
8 #include "src/objects.h" 8 #include "src/objects.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 using compiler::Node; 13 using compiler::Node;
14 14
15 typedef std::function<Node*(MachineType type, Node* base, Node* offset,
16 Node* value)>
17 AssemblerFunction;
18
15 class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler { 19 class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler {
16 public: 20 public:
17 explicit SharedArrayBufferBuiltinsAssembler( 21 explicit SharedArrayBufferBuiltinsAssembler(
18 compiler::CodeAssemblerState* state) 22 compiler::CodeAssemblerState* state)
19 : CodeStubAssembler(state) {} 23 : CodeStubAssembler(state) {}
20 24
21 protected: 25 protected:
22 void ValidateSharedTypedArray(Node* tagged, Node* context, 26 void ValidateSharedTypedArray(Node* tagged, Node* context,
23 Node** out_instance_type, 27 Node** out_instance_type,
24 Node** out_backing_store); 28 Node** out_backing_store);
25 Node* ConvertTaggedAtomicIndexToWord32(Node* tagged, Node* context, 29 Node* ConvertTaggedAtomicIndexToWord32(Node* tagged, Node* context,
26 Node** number_index); 30 Node** number_index);
27 void ValidateAtomicIndex(Node* index_word, Node* array_length_word, 31 void ValidateAtomicIndex(Node* index_word, Node* array_length_word,
28 Node* context); 32 Node* context);
33 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.
34 AssemblerFunction function,
35 Runtime::FunctionId runtime_function);
29 }; 36 };
30 37
31 void SharedArrayBufferBuiltinsAssembler::ValidateSharedTypedArray( 38 void SharedArrayBufferBuiltinsAssembler::ValidateSharedTypedArray(
32 Node* tagged, Node* context, Node** out_instance_type, 39 Node* tagged, Node* context, Node** out_instance_type,
33 Node** out_backing_store) { 40 Node** out_backing_store) {
34 Label not_float_or_clamped(this), invalid(this); 41 Label not_float_or_clamped(this), invalid(this);
35 42
36 // Fail if it is not a heap object. 43 // Fail if it is not a heap object.
37 GotoIf(TaggedIsSmi(tagged), &invalid); 44 GotoIf(TaggedIsSmi(tagged), &invalid);
38 45
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 MachineType::Uint32(), backing_store, WordShl(index_word, 2), 402 MachineType::Uint32(), backing_store, WordShl(index_word, 2),
396 old_value_word32, new_value_word32))); 403 old_value_word32, new_value_word32)));
397 404
398 // This shouldn't happen, we've already validated the type. 405 // This shouldn't happen, we've already validated the type.
399 Bind(&other); 406 Bind(&other);
400 Unreachable(); 407 Unreachable();
401 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64 408 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64
402 // || V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X 409 // || V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X
403 } 410 }
404 411
412 #define BINOP_BUILTIN(op) \
413 TF_BUILTIN(Atomics##op, SharedArrayBufferBuiltinsAssembler) { \
414 Node* array = Parameter(Descriptor::kArray); \
415 Node* index = Parameter(Descriptor::kIndex); \
416 Node* value = Parameter(Descriptor::kValue); \
417 Node* context = Parameter(Descriptor::kContext); \
418 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.
419 Node* offset, Node* value) -> Node* { \
420 return Atomic##op(type, base, offset, value); \
421 }; \
422 BinaryBuiltinCommon(array, index, value, context, function, \
423 Runtime::kAtomics##op); \
424 }
425 BINOP_BUILTIN(Add)
426 BINOP_BUILTIN(Sub)
427 BINOP_BUILTIN(And)
428 BINOP_BUILTIN(Or)
429 BINOP_BUILTIN(Xor)
430 #undef BINOP_BUILTIN
431
432 void SharedArrayBufferBuiltinsAssembler::BinaryBuiltinCommon(
433 Node* array, Node* index, Node* value, Node* context,
434 AssemblerFunction function, Runtime::FunctionId runtime_function) {
435 Node* instance_type;
436 Node* backing_store;
437 ValidateSharedTypedArray(array, context, &instance_type, &backing_store);
438
439 Node* index_integer;
440 Node* index_word32 =
441 ConvertTaggedAtomicIndexToWord32(index, context, &index_integer);
442 Node* array_length_word32 = TruncateTaggedToWord32(
443 context, LoadObjectField(array, JSTypedArray::kLengthOffset));
444 ValidateAtomicIndex(index_word32, array_length_word32, context);
445
446 Node* value_integer = ToInteger(context, value);
447
448 #if V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64 || \
449 V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X
450 Return(CallRuntime(runtime_function, context, array, index_integer,
451 value_integer));
452 #else
453 Node* index_word = ChangeUint32ToWord(index_word32);
454
455 Node* value_word32 = TruncateTaggedToWord32(context, value_integer);
456
457 Label i8(this), u8(this), i16(this), u16(this), i32(this), u32(this),
458 other(this);
459 int32_t case_values[] = {
460 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE,
461 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE,
462 };
463 Label* case_labels[] = {
464 &i8, &u8, &i16, &u16, &i32, &u32,
465 };
466 Switch(instance_type, &other, case_values, case_labels,
467 arraysize(case_labels));
468
469 Bind(&i8);
470 Return(SmiFromWord32(
471 function(MachineType::Int8(), backing_store, index_word, value_word32)));
472
473 Bind(&u8);
474 Return(SmiFromWord32(
475 function(MachineType::Uint8(), backing_store, index_word, value_word32)));
476
477 Bind(&i16);
478 Return(SmiFromWord32(function(MachineType::Int16(), backing_store,
479 WordShl(index_word, 1), value_word32)));
480
481 Bind(&u16);
482 Return(SmiFromWord32(function(MachineType::Uint16(), backing_store,
483 WordShl(index_word, 1), value_word32)));
484
485 Bind(&i32);
486 Return(ChangeInt32ToTagged(function(MachineType::Int32(), backing_store,
487 WordShl(index_word, 2), value_word32)));
488
489 Bind(&u32);
490 Return(ChangeUint32ToTagged(function(MachineType::Uint32(), backing_store,
491 WordShl(index_word, 2), value_word32)));
492
493 // This shouldn't happen, we've already validated the type.
494 Bind(&other);
495 Unreachable();
496 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64
497 // || V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X
498 }
499
405 } // namespace internal 500 } // namespace internal
406 } // namespace v8 501 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698