Skip to content

Commit

Permalink
Bug 1737266 - inline memory.copy and memory.fill in ion for memory64.…
Browse files Browse the repository at this point in the history
… r=rhunt

A completely straightforward adaptation of existing code for 32-bit.

I opted not to do this for baseline, indeed I think that the implementation
of this for baseline on mem32 was a bridge too far.  Discuss.

Differential Revision: https://phabricator.services.mozilla.com/D142040
  • Loading branch information
Lars T Hansen committed Mar 31, 2022
1 parent a271baf commit 17e28f7
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions js/src/wasm/WasmIonCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,16 +1726,17 @@ class FunctionCompiler {

MDefinition* loadTableField(const TableDesc& table, unsigned fieldOffset,
MIRType type) {
uint32_t globalDataOffset =
wasm::Instance::offsetOfGlobalArea() + table.globalDataOffset + fieldOffset;
uint32_t globalDataOffset = wasm::Instance::offsetOfGlobalArea() +
table.globalDataOffset + fieldOffset;
auto* load = MWasmLoadTls::New(alloc(), tlsPointer_, globalDataOffset, type,
AliasSet::Load(AliasSet::WasmTableMeta));
curBlock_->add(load);
return load;
}

MDefinition* loadTableLength(const TableDesc& table) {
return loadTableField(table, offsetof(TableInstanceData, length), MIRType::Int32);
return loadTableField(table, offsetof(TableInstanceData, length),
MIRType::Int32);
}

MDefinition* loadTableElements(const TableDesc& table) {
Expand Down Expand Up @@ -4836,12 +4837,8 @@ static bool EmitMemCopyCall(FunctionCompiler& f, MDefinition* dst,
return f.builtinInstanceMethodCall(callee, bytecodeOffset, args);
}

static bool EmitMemCopyInlineM32(FunctionCompiler& f, MDefinition* dst,
MDefinition* src, MDefinition* len) {
MOZ_ASSERT(MaxInlineMemoryCopyLength != 0);

MOZ_ASSERT(len->isConstant() && len->type() == MIRType::Int32);
uint32_t length = len->toConstant()->toInt32();
static bool EmitMemCopyInline(FunctionCompiler& f, MDefinition* dst,
MDefinition* src, uint32_t length) {
MOZ_ASSERT(length != 0 && length <= MaxInlineMemoryCopyLength);

// Compute the number of copies of each width we will need to do
Expand Down Expand Up @@ -4986,13 +4983,15 @@ static bool EmitMemCopy(FunctionCompiler& f) {
return true;
}

if (f.isMem32()) {
if (len->isConstant() && len->type() == MIRType::Int32 &&
len->toConstant()->toInt32() != 0 &&
uint32_t(len->toConstant()->toInt32()) <= MaxInlineMemoryCopyLength) {
return EmitMemCopyInlineM32(f, dst, src, len);
if (len->isConstant()) {
uint64_t length = f.isMem32() ? len->toConstant()->toInt32()
: len->toConstant()->toInt64();
static_assert(MaxInlineMemoryCopyLength <= UINT32_MAX);
if (length != 0 && length <= MaxInlineMemoryCopyLength) {
return EmitMemCopyInline(f, dst, src, uint32_t(length));
}
}

return EmitMemCopyCall(f, dst, src, len);
}

Expand Down Expand Up @@ -5113,16 +5112,10 @@ static bool EmitMemFillCall(FunctionCompiler& f, MDefinition* start,
return f.builtinInstanceMethodCall(callee, bytecodeOffset, args);
}

static bool EmitMemFillInlineM32(FunctionCompiler& f, MDefinition* start,
MDefinition* val, MDefinition* len) {
MOZ_ASSERT(MaxInlineMemoryFillLength != 0);

MOZ_ASSERT(len->isConstant() && len->type() == MIRType::Int32 &&
val->isConstant() && val->type() == MIRType::Int32);

uint32_t length = len->toConstant()->toInt32();
uint32_t value = val->toConstant()->toInt32();
static bool EmitMemFillInline(FunctionCompiler& f, MDefinition* start,
MDefinition* val, uint32_t length) {
MOZ_ASSERT(length != 0 && length <= MaxInlineMemoryFillLength);
uint32_t value = val->toConstant()->toInt32();

// Compute the number of copies of each width we will need to do
size_t remainder = length;
Expand Down Expand Up @@ -5218,14 +5211,15 @@ static bool EmitMemFill(FunctionCompiler& f) {
return true;
}

if (f.isMem32()) {
if (len->isConstant() && len->type() == MIRType::Int32 &&
len->toConstant()->toInt32() != 0 &&
uint32_t(len->toConstant()->toInt32()) <= MaxInlineMemoryFillLength &&
val->isConstant() && val->type() == MIRType::Int32) {
return EmitMemFillInlineM32(f, start, val, len);
if (len->isConstant() && val->isConstant()) {
uint64_t length = f.isMem32() ? len->toConstant()->toInt32()
: len->toConstant()->toInt64();
static_assert(MaxInlineMemoryFillLength <= UINT32_MAX);
if (length != 0 && length <= MaxInlineMemoryFillLength) {
return EmitMemFillInline(f, start, val, uint32_t(length));
}
}

return EmitMemFillCall(f, start, val, len);
}

Expand Down

0 comments on commit 17e28f7

Please sign in to comment.