OLD | NEW |
---|---|
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 class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler { | 15 class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler { |
16 public: | 16 public: |
17 explicit SharedArrayBufferBuiltinsAssembler( | 17 explicit SharedArrayBufferBuiltinsAssembler( |
18 compiler::CodeAssemblerState* state) | 18 compiler::CodeAssemblerState* state) |
19 : CodeStubAssembler(state) {} | 19 : CodeStubAssembler(state) {} |
20 | 20 |
21 protected: | 21 protected: |
22 typedef Node* (CodeAssembler::*AssemblerFunction)(MachineType type, | |
23 Node* base, Node* offset, | |
24 Node* value); | |
22 void ValidateSharedTypedArray(Node* tagged, Node* context, | 25 void ValidateSharedTypedArray(Node* tagged, Node* context, |
23 Node** out_instance_type, | 26 Node** out_instance_type, |
24 Node** out_backing_store); | 27 Node** out_backing_store); |
25 Node* ConvertTaggedAtomicIndexToWord32(Node* tagged, Node* context, | 28 Node* ConvertTaggedAtomicIndexToWord32(Node* tagged, Node* context, |
26 Node** number_index); | 29 Node** number_index); |
27 void ValidateAtomicIndex(Node* index_word, Node* array_length_word, | 30 void ValidateAtomicIndex(Node* index_word, Node* array_length_word, |
28 Node* context); | 31 Node* context); |
32 void AtomicBinopBuiltinCommon(Node* array, Node* index, Node* value, | |
33 Node* context, AssemblerFunction function, | |
34 Runtime::FunctionId runtime_function); | |
29 }; | 35 }; |
30 | 36 |
31 void SharedArrayBufferBuiltinsAssembler::ValidateSharedTypedArray( | 37 void SharedArrayBufferBuiltinsAssembler::ValidateSharedTypedArray( |
32 Node* tagged, Node* context, Node** out_instance_type, | 38 Node* tagged, Node* context, Node** out_instance_type, |
33 Node** out_backing_store) { | 39 Node** out_backing_store) { |
34 Label not_float_or_clamped(this), invalid(this); | 40 Label not_float_or_clamped(this), invalid(this); |
35 | 41 |
36 // Fail if it is not a heap object. | 42 // Fail if it is not a heap object. |
37 GotoIf(TaggedIsSmi(tagged), &invalid); | 43 GotoIf(TaggedIsSmi(tagged), &invalid); |
38 | 44 |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 MachineType::Uint32(), backing_store, WordShl(index_word, 2), | 401 MachineType::Uint32(), backing_store, WordShl(index_word, 2), |
396 old_value_word32, new_value_word32))); | 402 old_value_word32, new_value_word32))); |
397 | 403 |
398 // This shouldn't happen, we've already validated the type. | 404 // This shouldn't happen, we've already validated the type. |
399 BIND(&other); | 405 BIND(&other); |
400 Unreachable(); | 406 Unreachable(); |
401 #endif // V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64 | 407 #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 | 408 // || V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X |
403 } | 409 } |
404 | 410 |
411 #define BINOP_BUILTIN(op) \ | |
412 TF_BUILTIN(Atomics##op, SharedArrayBufferBuiltinsAssembler) { \ | |
413 Node* array = Parameter(Descriptor::kArray); \ | |
414 Node* index = Parameter(Descriptor::kIndex); \ | |
415 Node* value = Parameter(Descriptor::kValue); \ | |
416 Node* context = Parameter(Descriptor::kContext); \ | |
417 AtomicBinopBuiltinCommon(array, index, value, context, \ | |
418 &CodeAssembler::Atomic##op, \ | |
419 Runtime::kAtomics##op); \ | |
420 } | |
421 BINOP_BUILTIN(Add) | |
422 BINOP_BUILTIN(Sub) | |
423 BINOP_BUILTIN(And) | |
424 BINOP_BUILTIN(Or) | |
425 BINOP_BUILTIN(Xor) | |
426 #undef BINOP_BUILTIN | |
427 | |
428 void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon( | |
429 Node* array, Node* index, Node* value, Node* context, | |
430 AssemblerFunction function, Runtime::FunctionId runtime_function) { | |
431 Node* instance_type; | |
432 Node* backing_store; | |
433 ValidateSharedTypedArray(array, context, &instance_type, &backing_store); | |
434 | |
435 Node* index_integer; | |
436 Node* index_word32 = | |
437 ConvertTaggedAtomicIndexToWord32(index, context, &index_integer); | |
438 Node* array_length_word32 = TruncateTaggedToWord32( | |
439 context, LoadObjectField(array, JSTypedArray::kLengthOffset)); | |
440 ValidateAtomicIndex(index_word32, array_length_word32, context); | |
441 | |
442 Node* value_integer = ToInteger(context, value); | |
Jarin
2017/04/07 09:55:48
This makes me a bit uneasy, are we sure this canno
binji
2017/04/08 20:23:12
I'm fairly certain this is safe, as a typedarray c
aseemgarg
2017/04/10 20:23:37
Moved the JS calls above the validations and added
| |
443 | |
444 #if V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64 || V8_TARGET_ARCH_PPC64 || \ | |
445 V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_S390 || V8_TARGET_ARCH_S390X | |
446 Return(CallRuntime(runtime_function, context, array, index_integer, | |
447 value_integer)); | |
448 #else | |
449 Node* index_word = ChangeUint32ToWord(index_word32); | |
450 | |
451 Node* value_word32 = TruncateTaggedToWord32(context, value_integer); | |
452 | |
453 Label i8(this), u8(this), i16(this), u16(this), i32(this), u32(this), | |
454 other(this); | |
455 int32_t case_values[] = { | |
456 FIXED_INT8_ARRAY_TYPE, FIXED_UINT8_ARRAY_TYPE, FIXED_INT16_ARRAY_TYPE, | |
457 FIXED_UINT16_ARRAY_TYPE, FIXED_INT32_ARRAY_TYPE, FIXED_UINT32_ARRAY_TYPE, | |
458 }; | |
459 Label* case_labels[] = { | |
460 &i8, &u8, &i16, &u16, &i32, &u32, | |
461 }; | |
462 Switch(instance_type, &other, case_values, case_labels, | |
463 arraysize(case_labels)); | |
464 | |
465 Bind(&i8); | |
466 Return(SmiFromWord32((this->*function)(MachineType::Int8(), backing_store, | |
467 index_word, value_word32))); | |
468 | |
469 Bind(&u8); | |
470 Return(SmiFromWord32((this->*function)(MachineType::Uint8(), backing_store, | |
471 index_word, value_word32))); | |
472 | |
473 Bind(&i16); | |
474 Return( | |
475 SmiFromWord32((this->*function)(MachineType::Int16(), backing_store, | |
476 WordShl(index_word, 1), value_word32))); | |
477 | |
478 Bind(&u16); | |
479 Return( | |
480 SmiFromWord32((this->*function)(MachineType::Uint16(), backing_store, | |
481 WordShl(index_word, 1), value_word32))); | |
482 | |
483 Bind(&i32); | |
484 Return(ChangeInt32ToTagged( | |
485 (this->*function)(MachineType::Int32(), backing_store, | |
486 WordShl(index_word, 2), value_word32))); | |
487 | |
488 Bind(&u32); | |
489 Return(ChangeUint32ToTagged( | |
490 (this->*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 |
OLD | NEW |