Commit 2a9a770c authored by bradnelson's avatar bradnelson Committed by Commit bot

Convert float64 to float32 when coerced with a heapf32 assignment.

BUG= https://code.google.com/p/v8/issues/detail?id=4203
TEST=mjsunit/asm-wasm
R=titzer@chromium.org,aseemgarg@chromium.org
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#34404}
parent 318a09ea
......@@ -694,6 +694,12 @@ class AsmWasmBuilderImpl : public AstVisitor {
is_set_op_ = true;
RECURSE(Visit(expr->target()));
DCHECK(!is_set_op_);
// Assignment to heapf32 from float64 converts.
if (TypeOf(expr->value()) == kAstF64 && expr->target()->IsProperty() &&
expr->target()->AsProperty()->obj()->bounds().lower->Is(
cache_.kFloat32Array)) {
current_function_builder_->Emit(kExprF32ConvertF64);
}
RECURSE(Visit(expr->value()));
if (in_init) {
UnLoadInitFunction();
......
......@@ -2348,3 +2348,21 @@ TEST(Imports) {
}
CHECK_TYPES_END
}
TEST(StoreFloatFromDouble) {
CHECK_FUNC_TYPES_BEGIN(
"function bar() { f32[0] = 0.0; }\n"
"function foo() { bar(); }") {
CHECK_EXPR(FunctionLiteral, FUNC_V_TYPE) {
CHECK_EXPR(Assignment, Bounds(cache.kAsmDouble)) {
CHECK_EXPR(Property, Bounds::Unbounded()) {
CHECK_VAR(f32, Bounds(cache.kFloat32Array));
CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum));
}
CHECK_EXPR(Literal, Bounds(cache.kAsmDouble));
}
}
CHECK_SKIP();
}
CHECK_FUNC_TYPES_END
}
......@@ -1433,6 +1433,24 @@ TestForeignVariables();
}); // TODO(bradnelson): Enable when Math.fround implementation lands.
(function TestDoubleToFloatAssignment() {
function Module(stdlib, foreign, heap) {
"use asm";
var HEAPF32 = new stdlib.Float32Array(heap);
var fround = stdlib.Math.fround;
function func() {
var a = 1.23;
HEAPF32[0] = a;
return +HEAPF32[0];
}
return {func: func};
}
var m = _WASMEXP_.instantiateModuleFromAsm(Module.toString());
assertEquals(1.23, m.func());
});
(function TestIntegerMultiplyBothWays() {
function Module(stdlib, foreign, heap) {
"use asm";
......
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