Commit 4f426e10 authored by ivica.bogosavljevic's avatar ivica.bogosavljevic Committed by Commit bot

MIPS: Fix int64->int32 lowering in wasm-to-interpeter entry on big-endian archs.

WASM interpreter requires that parameters are stored in big-endian natural
memory order (higher bits on lower addresses and lower bits on higher address).
On the other hand, WASM compiled code naturally stores data in memory in
little-endian order. This CL implements big-endian support for passing
double and int64 parameters to WASM interpreter.

TEST=cctest/test-wasm-interpreter-entry/TestArgumentPassing_int64,
     cctest/test-wasm-interpreter-entry/TestArgumentPassing_AllTypes

Review-Url: https://codereview.chromium.org/2721053002
Cr-Commit-Position: refs/heads/master@{#43568}
parent 0832bae3
......@@ -2977,30 +2977,30 @@ void WasmGraphBuilder::BuildWasmInterpreterEntry(
Node* param = Param(param_index++);
bool is_i64_as_two_params =
jsgraph()->machine()->Is32() && sig->GetParam(i) == wasm::kWasmI64;
MachineRepresentation param_rep =
is_i64_as_two_params ? wasm::kWasmI32 : sig->GetParam(i);
StoreRepresentation store_rep(param_rep, WriteBarrierKind::kNoWriteBarrier);
*effect_ =
graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer,
Int32Constant(offset), param, *effect_, *control_);
if (is_i64_as_two_params) {
offset += 1 << ElementSizeLog2Of(wasm::kWasmI32);
} else {
offset += RoundUpToMultipleOfPowOf2(1 << ElementSizeLog2Of(param_rep), 8);
}
StoreRepresentation store_rep(wasm::kWasmI32,
WriteBarrierKind::kNoWriteBarrier);
*effect_ =
graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer,
Int32Constant(offset + kInt64LowerHalfMemoryOffset),
param, *effect_, *control_);
// TODO(clemensh): Respect endianess here. Might need to swap upper and
// lower word.
if (is_i64_as_two_params) {
// Also store the upper half.
param = Param(param_index++);
StoreRepresentation store_rep(wasm::kWasmI32,
*effect_ =
graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer,
Int32Constant(offset + kInt64UpperHalfMemoryOffset),
param, *effect_, *control_);
offset += 8;
} else {
MachineRepresentation param_rep = sig->GetParam(i);
StoreRepresentation store_rep(param_rep,
WriteBarrierKind::kNoWriteBarrier);
*effect_ =
graph()->NewNode(jsgraph()->machine()->Store(store_rep), arg_buffer,
Int32Constant(offset), param, *effect_, *control_);
offset += 1 << ElementSizeLog2Of(wasm::kWasmI32);
offset += RoundUpToMultipleOfPowOf2(1 << ElementSizeLog2Of(param_rep), 8);
}
DCHECK(IsAligned(offset, 8));
......
......@@ -520,6 +520,15 @@ const int kMinComplexMemCopy = 8;
// ----------------------------------------------------------------------------
// Miscellaneous
// Memory offset for lower and higher bits in a 64 bit integer.
#if defined(V8_TARGET_LITTLE_ENDIAN)
static const int kInt64LowerHalfMemoryOffset = 0;
static const int kInt64UpperHalfMemoryOffset = 4;
#elif defined(V8_TARGET_BIG_ENDIAN)
static const int kInt64LowerHalfMemoryOffset = 4;
static const int kInt64UpperHalfMemoryOffset = 0;
#endif // V8_TARGET_LITTLE_ENDIAN
// A static resource holds a static instance that can be reserved in
// a local scope using an instance of Access. Attempts to re-reserve
// the instance will cause an error.
......
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