v8/test/mjsunit/compiler/dataview-get.js
Théotime Grohens 249f6069b6 [turbofan] Inline DataView Int8 and Uint8 getters
This CL adds code to inline the Int8 and Uint8 getters for DataView
objects in TurboFan in js-call-reducer.cc, as well as a new test file.

It already improves execution speed compared to the Torque baseline
implementation, and implements most of the architecture needed
for inlining the other DataView getters and setters as well.

Change-Id: I0e62b98fd6ec995f7db5ec42ea1eff1f03572f97
Reviewed-on: https://chromium-review.googlesource.com/1119909
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Michael Stanton <mvstanton@chromium.org>
Commit-Queue: Théotime Grohens <theotime@google.com>
Cr-Commit-Position: refs/heads/master@{#54157}
2018-07-03 08:36:25 +00:00

82 lines
2.2 KiB
JavaScript

// 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 --opt --no-always-opt
var buffer = new ArrayBuffer(64);
var dataview = new DataView(buffer, 8, 24);
var values = [-1, 2, -3, 42];
function readInt8Handled(offset) {
try {
return dataview.getInt8(offset);
} catch (e) {
return e;
}
}
function readUint8(offset) {
return dataview.getUint8(offset);
}
function warmup(f) {
f(0);
f(1);
%OptimizeFunctionOnNextCall(f);
f(2);
f(3);
}
// TurboFan valid getInt8.
for (var i = 0; i < values.length; i++) {
dataview.setInt8(i, values[i]);
}
warmup(readInt8Handled);
assertOptimized(readInt8Handled);
assertEquals(values[0], readInt8Handled(0));
assertEquals(values[1], readInt8Handled(1));
assertEquals(values[2], readInt8Handled(2));
assertEquals(values[3], readInt8Handled(3));
// TurboFan valid getUint8.
dataview.setUint32(4, 0xdeadbeef);
warmup(readUint8);
assertOptimized(readUint8);
assertEquals(0xde, readUint8(4));
assertEquals(0xad, readUint8(5));
assertEquals(0xbe, readUint8(6));
assertEquals(0xef, readUint8(7));
// TurboFan out of bounds read, throw with exception handler.
assertOptimized(readInt8Handled);
assertInstanceof(readInt8Handled(64), RangeError);
assertOptimized(readInt8Handled);
// Without exception handler.
assertOptimized(readUint8);
assertThrows(() => readUint8(64));
assertOptimized(readUint8);
// TurboFan deoptimizations.
assertOptimized(readInt8Handled);
assertInstanceof(readInt8Handled(-1), RangeError); // Negative Smi deopts.
assertUnoptimized(readInt8Handled);
warmup(readInt8Handled);
assertOptimized(readInt8Handled);
assertEquals(values[3], readInt8Handled(3.14)); // Non-Smi index deopts.
assertUnoptimized(readInt8Handled);
// None of the stores wrote out of bounds.
var bytes = new Uint8Array(buffer);
for (var i = 0; i < 8; i++) assertEquals(0, bytes[i]);
for (var i = 24; i < 64; i++) assertEquals(0, bytes[i]);
// TurboFan neutered buffer.
warmup(readInt8Handled);
assertOptimized(readInt8Handled);
%ArrayBufferNeuter(buffer);
assertInstanceof(readInt8Handled(0), TypeError);
assertOptimized(readInt8Handled);