Commit efb1b5e4 authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm] Speed up some tests in grow-memory

Rework testMemoryGrowPreservesDataMemOp tests so that they only test the
first and last 5 offsets within the page, instead of every offset.

Slight logic change: instead of storing the value C - offset (where C is
a constant that is different for 32 and 16 memops), we store just the
value offset. This allows us to combine the logic for all 3 memops (32,
16, and 8). But we need to add a modulo so that in the 8 bit case, we
don't store a value that exceeds the maximum (the other cases will never
hit a case that exceeds the max).

Bug: v8:7783
Change-Id: Ibfdc77555ba2ca26391eba303050a03538f6012d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2117633Reviewed-by: 's avatarDeepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66879}
parent 820a3bda
...@@ -245,78 +245,55 @@ function testMemoryGrowCurrentMemory() { ...@@ -245,78 +245,55 @@ function testMemoryGrowCurrentMemory() {
testMemoryGrowCurrentMemory(); testMemoryGrowCurrentMemory();
function testMemoryGrowPreservesDataMemOp32() { function testMemoryGrowPreservesDataMemOpBase(size, load_fn, store_fn) {
var builder = genMemoryGrowBuilder(); var builder = genMemoryGrowBuilder();
builder.addMemory(1, undefined, false); builder.addMemory(1, undefined, false);
var module = builder.instantiate(); var module = builder.instantiate();
var offset, val; var offset;
function peek() { return module.exports.load(offset); } var load = module.exports[load_fn];
function poke(value) { return module.exports.store(offset, value); } var store = module.exports[store_fn];
function peek() { return load(offset); }
function poke(value) { return store(offset, value); }
function growMem(pages) { return module.exports.grow_memory(pages); } function growMem(pages) { return module.exports.grow_memory(pages); }
// Maximum unsigned integer of size bits.
const max = Math.pow(2, (size * 8)) - 1;
for(offset = 0; offset <= (kPageSize - 4); offset+=4) { // Check the first 5 offsets.
poke(100000 - offset); for(offset = 0; offset <= (4*size); offset+=size) {
assertEquals(100000 - offset, peek()); poke(offset % max);
} assertEquals(offset % max, peek());
assertEquals(1, growMem(3));
for(offset = 0; offset <= (kPageSize - 4); offset+=4) {
assertEquals(100000 - offset, peek());
} }
}
testMemoryGrowPreservesDataMemOp32();
function testMemoryGrowPreservesDataMemOp16() {
var builder = genMemoryGrowBuilder();
builder.addMemory(1, undefined, false);
var module = builder.instantiate();
var offset, val;
function peek() { return module.exports.load16(offset); }
function poke(value) { return module.exports.store16(offset, value); }
function growMem(pages) { return module.exports.grow_memory(pages); }
for(offset = 0; offset <= (kPageSize - 2); offset+=2) { // Check the last 5 valid offsets.
poke(65535 - offset); for(offset = kPageSize - 5*size; offset <= (kPageSize - size); offset+=size) {
assertEquals(65535 - offset, peek()); poke(offset % max);
assertEquals(offset % max, peek());
} }
assertEquals(1, growMem(3)); assertEquals(1, growMem(3));
for(offset = 0; offset <= (kPageSize - 2); offset+=2) { // Check the first 5 offsets are preserved by growMem.
assertEquals(65535 - offset, peek()); for(offset = 0; offset <= (4*size); offset+=size) {
assertEquals(offset % max, peek());
} }
}
testMemoryGrowPreservesDataMemOp16();
function testMemoryGrowPreservesDataMemOp8() {
var builder = genMemoryGrowBuilder();
builder.addMemory(1, undefined, false);
var module = builder.instantiate();
var offset, val = 0;
function peek() { return module.exports.load8(offset); }
function poke(value) { return module.exports.store8(offset, value); }
function growMem(pages) { return module.exports.grow_memory(pages); }
for(offset = 0; offset <= (kPageSize - 1); offset++, val++) { // Check the last 5 valid offsets are preserved by growMem.
poke(val); for(offset = kPageSize - 5*size; offset <= (kPageSize - size); offset+=size) {
assertEquals(val, peek()); assertEquals(offset % max, peek());
if (val == 255) val = 0;
} }
}
assertEquals(1, growMem(3)); (function testMemoryGrowPreservesDataMemOp32() {
testMemoryGrowPreservesDataMemOpBase(4, "load", "store");
val = 0; })();
for(offset = 0; offset <= (kPageSize - 1); offset++, val++) { (function testMemoryGrowPreservesDataMemOp16() {
assertEquals(val, peek()); testMemoryGrowPreservesDataMemOpBase(2, "load16", "store16");
if (val == 255) val = 0; })();
}
}
testMemoryGrowPreservesDataMemOp8(); (function testMemoryGrowPreservesDataMemOp8() {
testMemoryGrowPreservesDataMemOpBase(1, "load8", "store8");
})();
function testMemoryGrowOutOfBoundsOffset() { function testMemoryGrowOutOfBoundsOffset() {
var builder = genMemoryGrowBuilder(); var builder = genMemoryGrowBuilder();
......
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