Commit 545fa6e5 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Fix storing float32 value into float64 heap view.

The valid store types of a {Float64Array} heap view are specified to be
"float?" and "double?". We correctly accepted both types but forgot to
emit the appropriate conversion in the "float?" case. This just adds the
missing conversion expression.

R=clemensh@chromium.org
TEST=mjsunit/regress/regress-crbug-898974
BUG=chromium:898974,v8:8347

Change-Id: I306b10e2088185b1522da29b1a113908ef9925f2
Reviewed-on: https://chromium-review.googlesource.com/c/1301499
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57025}
parent ae45472b
...@@ -1498,10 +1498,15 @@ AsmType* AsmJsParser::AssignmentExpression() { ...@@ -1498,10 +1498,15 @@ AsmType* AsmJsParser::AssignmentExpression() {
FAILn("Illegal type stored to heap view"); FAILn("Illegal type stored to heap view");
} }
if (heap_type->IsA(AsmType::Float32Array()) && if (heap_type->IsA(AsmType::Float32Array()) &&
value->IsA(AsmType::Double())) { value->IsA(AsmType::DoubleQ())) {
// Assignment to a float32 heap can be used to convert doubles. // Assignment to a float32 heap can be used to convert doubles.
current_function_builder_->Emit(kExprF32ConvertF64); current_function_builder_->Emit(kExprF32ConvertF64);
} }
if (heap_type->IsA(AsmType::Float64Array()) &&
value->IsA(AsmType::FloatQ())) {
// Assignment to a float64 heap can be used to convert floats.
current_function_builder_->Emit(kExprF64ConvertF32);
}
ret = value; ret = value;
#define V(array_type, wasmload, wasmstore, type) \ #define V(array_type, wasmload, wasmstore, type) \
if (heap_type->IsA(AsmType::array_type())) { \ if (heap_type->IsA(AsmType::array_type())) { \
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
function Module(global, env, buffer) {
"use asm";
var HEAPF64 = new global.Float64Array(buffer);
var HEAPF32 = new global.Float32Array(buffer);
var Math_fround = global.Math.fround;
function main_d_f() {
HEAPF64[0] = Math_fround(+HEAPF64[0]);
}
function main_d_fq() {
HEAPF64[1] = HEAPF32[4096];
}
function main_f_dq() {
HEAPF32[4] = HEAPF64[4096];
}
return {main_d_f: main_d_f, main_d_fq: main_d_fq, main_f_dq: main_f_dq};
};
let buffer = new ArrayBuffer(4096);
let module = Module(this, undefined, buffer);
let view64 = new Float64Array(buffer);
let view32 = new Float32Array(buffer);
assertEquals(view64[0] = 2.3, view64[0]);
module.main_d_f();
module.main_d_fq();
module.main_f_dq();
assertTrue(%IsAsmWasmCode(Module));
assertEquals(Math.fround(2.3), view64[0]);
assertTrue(isNaN(view64[1]));
assertTrue(isNaN(view32[4]));
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