Commit a50f54c1 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[csa][cleanup] Partly TNodify SharedArrayBuffer's AssemblerFunction

As a drive-by, rename "sanity check" to "check" in sharedarraybuffer.

Bug: v8:6949, v8:10933
Change-Id: Ifa2eac381ed309a099b018de4033816ebe3d828d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2429410
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70307}
parent c7c8472d
......@@ -19,10 +19,10 @@ class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler {
: CodeStubAssembler(state) {}
protected:
using AssemblerFunction = Node* (CodeAssembler::*)(MachineType type,
Node* base, Node* offset,
Node* value,
Node* value_high);
using AssemblerFunction =
Node* (CodeAssembler::*)(MachineType type, TNode<RawPtrT> base,
TNode<UintPtrT> offset, Node* value,
base::Optional<TNode<UintPtrT>> value_high);
TNode<JSArrayBuffer> ValidateIntegerTypedArray(
TNode<Object> maybe_array, TNode<Context> context,
TNode<Int32T>* out_elements_kind, TNode<RawPtrT>* out_backing_store,
......@@ -32,8 +32,8 @@ class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler {
TNode<Object> index,
TNode<Context> context);
inline void DebugSanityCheckAtomicIndex(TNode<JSTypedArray> array,
TNode<UintPtrT> index);
inline void DebugCheckAtomicIndex(TNode<JSTypedArray> array,
TNode<UintPtrT> index);
void AtomicBinopBuiltinCommon(TNode<Object> maybe_array, TNode<Object> index,
TNode<Object> value, TNode<Context> context,
......@@ -127,7 +127,7 @@ TNode<UintPtrT> SharedArrayBufferBuiltinsAssembler::ValidateAtomicAccess(
return index_uintptr;
}
void SharedArrayBufferBuiltinsAssembler::DebugSanityCheckAtomicIndex(
void SharedArrayBufferBuiltinsAssembler::DebugCheckAtomicIndex(
TNode<JSTypedArray> array, TNode<UintPtrT> index) {
// In Debug mode, we re-validate the index as a sanity check because ToInteger
// above calls out to JavaScript. Atomics work on ArrayBuffers, which may be
......@@ -295,7 +295,7 @@ TF_BUILTIN(AtomicsStore, SharedArrayBufferBuiltinsAssembler) {
TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
// Steps 8-13.
//
......@@ -336,7 +336,7 @@ TF_BUILTIN(AtomicsStore, SharedArrayBufferBuiltinsAssembler) {
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_low);
TVARIABLE(UintPtrT, var_high);
......@@ -405,7 +405,7 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
// buffer to become detached.
GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer);
......@@ -424,29 +424,31 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
BIND(&i8);
Return(SmiFromInt32(AtomicExchange(MachineType::Int8(), backing_store,
index_word, value_word32)));
index_word, value_word32, base::nullopt)));
BIND(&u8);
Return(SmiFromInt32(AtomicExchange(MachineType::Uint8(), backing_store,
index_word, value_word32)));
index_word, value_word32, base::nullopt)));
BIND(&i16);
Return(SmiFromInt32(AtomicExchange(MachineType::Int16(), backing_store,
WordShl(index_word, 1), value_word32)));
WordShl(index_word, UintPtrConstant(1)),
value_word32, base::nullopt)));
BIND(&u16);
Return(SmiFromInt32(AtomicExchange(MachineType::Uint16(), backing_store,
WordShl(index_word, 1), value_word32)));
WordShl(index_word, UintPtrConstant(1)),
value_word32, base::nullopt)));
BIND(&i32);
Return(ChangeInt32ToTagged(AtomicExchange(MachineType::Int32(), backing_store,
WordShl(index_word, 2),
value_word32)));
Return(ChangeInt32ToTagged(AtomicExchange(
MachineType::Int32(), backing_store,
WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&u32);
Return(ChangeUint32ToTagged(
AtomicExchange(MachineType::Uint32(), backing_store,
WordShl(index_word, 2), value_word32)));
Return(ChangeUint32ToTagged(AtomicExchange(
MachineType::Uint32(), backing_store,
WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&big);
// 4. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value).
......@@ -455,7 +457,7 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_low);
TVARIABLE(UintPtrT, var_high);
......@@ -469,14 +471,14 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
// This uses Uint64() intentionally: AtomicExchange is not implemented for
// Int64(), which is fine because the machine instruction only cares
// about words.
Return(BigIntFromSigned64(AtomicExchange(MachineType::Uint64(), backing_store,
WordShl(index_word, 3),
var_low.value(), high)));
Return(BigIntFromSigned64(AtomicExchange(
MachineType::Uint64(), backing_store,
WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
BIND(&u64);
Return(BigIntFromUnsigned64(
AtomicExchange(MachineType::Uint64(), backing_store,
WordShl(index_word, 3), var_low.value(), high)));
Return(BigIntFromUnsigned64(AtomicExchange(
MachineType::Uint64(), backing_store,
WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
// This shouldn't happen, we've already validated the type.
BIND(&other);
......@@ -540,7 +542,7 @@ TF_BUILTIN(AtomicsCompareExchange, SharedArrayBufferBuiltinsAssembler) {
// buffer to become detached.
GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
TNode<Word32T> old_value_word32 =
TruncateTaggedToWord32(context, old_value_integer);
......@@ -600,7 +602,7 @@ TF_BUILTIN(AtomicsCompareExchange, SharedArrayBufferBuiltinsAssembler) {
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_old_low);
TVARIABLE(UintPtrT, var_old_high);
......@@ -703,7 +705,7 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
// buffer to become detached.
GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer);
......@@ -721,33 +723,29 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
arraysize(case_labels));
BIND(&i8);
Return(SmiFromInt32((this->*function)(MachineType::Int8(), backing_store,
index_word, value_word32, nullptr)));
Return(
SmiFromInt32((this->*function)(MachineType::Int8(), backing_store,
index_word, value_word32, base::nullopt)));
BIND(&u8);
Return(SmiFromInt32((this->*function)(MachineType::Uint8(), backing_store,
index_word, value_word32, nullptr)));
Return(
SmiFromInt32((this->*function)(MachineType::Uint8(), backing_store,
index_word, value_word32, base::nullopt)));
BIND(&i16);
Return(SmiFromInt32((this->*function)(MachineType::Int16(), backing_store,
WordShl(index_word, 1), value_word32,
nullptr)));
WordShl(index_word, UintPtrConstant(1)),
value_word32, base::nullopt)));
BIND(&u16);
Return(SmiFromInt32((this->*function)(MachineType::Uint16(), backing_store,
WordShl(index_word, 1), value_word32,
nullptr)));
WordShl(index_word, UintPtrConstant(1)),
value_word32, base::nullopt)));
BIND(&i32);
Return(ChangeInt32ToTagged(
(this->*function)(MachineType::Int32(), backing_store,
WordShl(index_word, 2), value_word32, nullptr)));
Return(ChangeInt32ToTagged((this->*function)(
MachineType::Int32(), backing_store,
WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&u32);
Return(ChangeUint32ToTagged(
(this->*function)(MachineType::Uint32(), backing_store,
WordShl(index_word, 2), value_word32, nullptr)));
Return(ChangeUint32ToTagged((this->*function)(
MachineType::Uint32(), backing_store,
WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&big);
// 4. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value).
TNode<BigInt> value_bigint = ToBigInt(context, value);
......@@ -755,7 +753,7 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word);
DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_low);
TVARIABLE(UintPtrT, var_high);
......@@ -769,15 +767,13 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
// This uses Uint64() intentionally: Atomic* ops are not implemented for
// Int64(), which is fine because the machine instructions only care
// about words.
Return(BigIntFromSigned64(
(this->*function)(MachineType::Uint64(), backing_store,
WordShl(index_word, 3), var_low.value(), high)));
Return(BigIntFromSigned64((this->*function)(
MachineType::Uint64(), backing_store,
WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
BIND(&u64);
Return(BigIntFromUnsigned64(
(this->*function)(MachineType::Uint64(), backing_store,
WordShl(index_word, 3), var_low.value(), high)));
Return(BigIntFromUnsigned64((this->*function)(
MachineType::Uint64(), backing_store,
WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
// This shouldn't happen, we've already validated the type.
BIND(&other);
Unreachable();
......
......@@ -802,19 +802,21 @@ Node* CodeAssembler::AtomicStore(MachineRepresentation rep, Node* base,
return raw_assembler()->AtomicStore(rep, base, offset, value, value_high);
}
#define ATOMIC_FUNCTION(name) \
Node* CodeAssembler::Atomic##name(MachineType type, Node* base, \
Node* offset, Node* value, \
Node* value_high) { \
return raw_assembler()->Atomic##name(type, base, offset, value, \
value_high); \
#define ATOMIC_FUNCTION(name) \
Node* CodeAssembler::Atomic##name( \
MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset, \
Node* value, base::Optional<TNode<UintPtrT>> value_high) { \
Node* value_high_node = nullptr; \
if (value_high) value_high_node = *value_high; \
return raw_assembler()->Atomic##name(type, base, offset, value, \
value_high_node); \
}
ATOMIC_FUNCTION(Exchange)
ATOMIC_FUNCTION(Add)
ATOMIC_FUNCTION(Sub)
ATOMIC_FUNCTION(And)
ATOMIC_FUNCTION(Or)
ATOMIC_FUNCTION(Xor)
ATOMIC_FUNCTION(Exchange)
#undef ATOMIC_FUNCTION
Node* CodeAssembler::AtomicCompareExchange(MachineType type, Node* base,
......
......@@ -783,31 +783,31 @@ class V8_EXPORT_PRIVATE CodeAssembler {
Node* AtomicStore(MachineRepresentation rep, Node* base, Node* offset,
Node* value, Node* value_high = nullptr);
Node* AtomicAdd(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicSub(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicAnd(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicOr(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicXor(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
// Exchange value at raw memory location
Node* AtomicExchange(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicExchange(MachineType type, TNode<RawPtrT> base,
TNode<UintPtrT> offset, Node* value,
base::Optional<TNode<UintPtrT>> value_high);
// Compare and Exchange value at raw memory location
Node* AtomicCompareExchange(MachineType type, Node* base, Node* offset,
Node* old_value, Node* new_value,
Node* old_value_high = nullptr,
Node* new_value_high = nullptr);
Node* AtomicAdd(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicSub(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicAnd(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicOr(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicXor(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
// Store a value to the root array.
Node* StoreRoot(RootIndex root_index, Node* value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment