Commit 13412d66 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Fixed a problem with float32 stack parameters on 32 bit machines.

The code generation for pushing call parameters on the stack does not
distinguish between float32 and float64 parameters because both are
stored in the same registers. Therefore float32 parameters require two
words on the stack.  The wasm linkage, however, only considered one word
on the stack for float32 parameters, which caused the problem that
float32 parameters were not located correctly on the stack. I fixed the
problem by considering two words for float32 parameters on the stack.

R=bradnelson@chromium.org

Review URL: https://codereview.chromium.org/1529773003

Cr-Commit-Position: refs/heads/master@{#32893}
parent 35e5b682
......@@ -178,7 +178,11 @@ struct Allocator {
return type == kAstF32 || type == kAstF64;
}
int Words(LocalType type) {
if (kPointerSize < 8 && (type == kAstI64 || type == kAstF64)) {
// The code generation for pushing parameters on the stack does not
// distinguish between float32 and float64. Therefore also float32 needs
// two words.
if (kPointerSize < 8 &&
(type == kAstI64 || type == kAstF64 || type == kAstF32)) {
return 2;
}
return 1;
......
......@@ -2609,6 +2609,58 @@ TEST(Run_WasmCallEmpty) {
}
TEST(Run_WasmCallF32StackParameter) {
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; i++) param_types[i] = kAstF32;
FunctionSig sig(1, 19, param_types);
TestingModule module;
WasmFunctionCompiler t(&sig);
BUILD(t, WASM_GET_LOCAL(17));
unsigned index = t.CompileAndAdd(&module);
// Build the calling function.
WasmRunner<float> r;
r.env()->module = &module;
BUILD(r, WASM_CALL_FUNCTION(
index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f),
WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f),
WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f),
WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f),
WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f),
WASM_F32(128.5f), WASM_F32(256.5f), WASM_F32(512.5f)));
float result = r.Call();
CHECK_EQ(256.5f, result);
}
TEST(Run_WasmCallF64StackParameter) {
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; i++) param_types[i] = kAstF64;
FunctionSig sig(1, 19, param_types);
TestingModule module;
WasmFunctionCompiler t(&sig);
BUILD(t, WASM_GET_LOCAL(17));
unsigned index = t.CompileAndAdd(&module);
// Build the calling function.
WasmRunner<double> r;
r.env()->module = &module;
BUILD(r, WASM_CALL_FUNCTION(index, WASM_F64(1.0), WASM_F64(2.0),
WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0),
WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0),
WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5),
WASM_F64(4.5), WASM_F64(8.5), WASM_F64(16.5),
WASM_F64(32.5), WASM_F64(64.5), WASM_F64(128.5),
WASM_F64(256.5), WASM_F64(512.5)));
float result = r.Call();
CHECK_EQ(256.5, result);
}
TEST(Run_WasmCallVoid) {
const byte kMemOffset = 8;
const int32_t kElemNum = kMemOffset / sizeof(int32_t);
......
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