Commit d67a44bf authored by Eric Leese's avatar Eric Leese Committed by Commit Bot

Always encode floats as little-endian

Change-Id: I7dd05e5b5feffceb1dd3b2a055c308266aea7c94
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1995272Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarMilad Farazmand <miladfar@ca.ibm.com>
Commit-Queue: Eric Leese <leese@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65702}
parent 87c16da5
......@@ -3,10 +3,8 @@
// found in the LICENSE file.
// Used for encoding f32 and double constants to bits.
let f32_view = new Float32Array(1);
let f32_bytes_view = new Uint8Array(f32_view.buffer);
let f64_view = new Float64Array(1);
let f64_bytes_view = new Uint8Array(f64_view.buffer);
let byte_view = new Uint8Array(8);
let data_view = new DataView(byte_view.buffer);
// The bytes function receives one of
// - several arguments, each of which is either a number or a string of length
......@@ -1078,13 +1076,13 @@ class WasmModuleBuilder {
break;
case kWasmF32:
section.emit_u8(kExprF32Const);
f32_view[0] = global.init;
section.emit_bytes(f32_bytes_view);
data_view.setFloat32(0, global.init, true);
section.emit_bytes(byte_view.subarray(0, 4));
break;
case kWasmF64:
section.emit_u8(kExprF64Const);
f64_view[0] = global.init;
section.emit_bytes(f64_bytes_view);
data_view.setFloat64(0, global.init, true);
section.emit_bytes(byte_view);
break;
case kWasmAnyFunc:
case kWasmAnyRef:
......@@ -1423,18 +1421,18 @@ function wasmI32Const(val) {
}
function wasmF32Const(f) {
f32_view[0] = f;
// Write in little-endian order at offset 0.
data_view.setFloat32(0, f, true);
return [
kExprF32Const, f32_bytes_view[0], f32_bytes_view[1], f32_bytes_view[2],
f32_bytes_view[3]
kExprF32Const, byte_view[0], byte_view[1], byte_view[2], byte_view[3]
];
}
function wasmF64Const(f) {
f64_view[0] = f;
// Write in little-endian order at offset 0.
data_view.setFloat64(0, f, true);
return [
kExprF64Const, f64_bytes_view[0], f64_bytes_view[1], f64_bytes_view[2],
f64_bytes_view[3], f64_bytes_view[4], f64_bytes_view[5], f64_bytes_view[6],
f64_bytes_view[7]
kExprF64Const, byte_view[0], byte_view[1], byte_view[2],
byte_view[3], byte_view[4], byte_view[5], byte_view[6], byte_view[7]
];
}
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