7c4461add3
This is a reland of commit ab76ffc8bd
.
Original change's description:
> [builtins] use SIMD IndexOf/includes on large arrays
>
> Change-Id: If751e813c7f45a4d18b84e8c0314a54c84894d61
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3639203
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Darius Mercadier <dmercadier@chromium.org>
> Reviewed-by: Toon Verwaest <verwaest@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#80771}
Change-Id: I81dcf3c97a15b95fd42927ff8e91602f109db315
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3672418
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Darius Mercadier <dmercadier@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80840}
152 lines
3.8 KiB
JavaScript
152 lines
3.8 KiB
JavaScript
// Copyright 2022 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.
|
|
|
|
// Large array of packed Smi, and Smi search_element
|
|
(() => {
|
|
let a = [];
|
|
for (let i = 0; i < 200; i++) {
|
|
a[i] = i;
|
|
}
|
|
function testArrayIncludes(idx) {
|
|
return a.includes(idx);
|
|
}
|
|
// Without fromIndex
|
|
for (let i = 0; i < 200; i++) {
|
|
assertEquals(true, testArrayIncludes(i));
|
|
}
|
|
// With fromIndex
|
|
for (let i = 0, from_index = 0; i+from_index < 200; i += 2, from_index++) {
|
|
assertEquals(true, testArrayIncludes(i, from_index));
|
|
}
|
|
})();
|
|
|
|
// Large array of holey Smi, and Smi search_element
|
|
(() => {
|
|
let a = [];
|
|
// Skipping every other item when initializing
|
|
for (let i = 0; i < 200; i+=2) {
|
|
a[i] = i;
|
|
}
|
|
function testArrayIncludes(idx) {
|
|
return a.includes(idx);
|
|
}
|
|
// Without fromIndex
|
|
for (let i = 0; i < 200; i++) {
|
|
if (i % 2 == 0) {
|
|
assertEquals(true, testArrayIncludes(i));
|
|
} else {
|
|
assertEquals(false, testArrayIncludes(i));
|
|
}
|
|
}
|
|
// With fromIndex
|
|
for (let i = 0, from_index = 0; i + from_index < 200; i += 2, from_index++) {
|
|
if (i % 2 == 0) {
|
|
assertEquals(true, testArrayIncludes(i, from_index));
|
|
} else {
|
|
assertEquals(false, testArrayIncludes(i, from_index));
|
|
}
|
|
}
|
|
})();
|
|
|
|
|
|
// Large array of packed Doubles, and Double search_element
|
|
(() => {
|
|
let a = [];
|
|
for (let i = 0; i < 200; i++) {
|
|
a[i] = i + 0.5;
|
|
}
|
|
function testArrayIncludes(idx) {
|
|
return a.includes(idx);
|
|
}
|
|
// Without fromIndex
|
|
for (let i = 0; i < 200; i++) {
|
|
assertEquals(true, testArrayIncludes(i + 0.5));
|
|
}
|
|
// With fromIndex
|
|
for (let i = 0, from_index = 0; i+from_index < 200; i += 2, from_index++) {
|
|
assertEquals(true, testArrayIncludes(i+0.5, from_index));
|
|
}
|
|
})();
|
|
|
|
// Large array of holey Doubles, and Double search_element
|
|
(() => {
|
|
let a = [];
|
|
// Skipping every other item when initializing
|
|
for (let i = 0; i < 200; i+=2) {
|
|
a[i] = i + 0.5;
|
|
}
|
|
function testArrayIncludes(idx) {
|
|
return a.includes(idx);
|
|
}
|
|
// Without fromIndex
|
|
for (let i = 0; i < 200; i++) {
|
|
if (i % 2 == 0) {
|
|
assertEquals(true, testArrayIncludes(i + 0.5));
|
|
} else {
|
|
assertEquals(false, testArrayIncludes(i + 0.5));
|
|
}
|
|
}
|
|
// With fromIndex
|
|
for (let i = 0, from_index = 0; i + from_index < 200; i += 2, from_index++) {
|
|
if (i % 2 == 0) {
|
|
assertEquals(true, testArrayIncludes(i+0.5, from_index));
|
|
} else {
|
|
assertEquals(false, testArrayIncludes(i+0.5, from_index));
|
|
}
|
|
}
|
|
})();
|
|
|
|
// Large array of packed objects, and object search_element
|
|
(() => {
|
|
let a = [];
|
|
let b = [];
|
|
for (let i = 0; i < 200; i++) {
|
|
a[i] = { v: i };
|
|
b[i] = a[i];
|
|
}
|
|
function testArrayIncludes(idx) {
|
|
return a.includes(idx);
|
|
}
|
|
// Without fromIndex
|
|
for (let i = 0; i < 200; i++) {
|
|
assertEquals(true, testArrayIncludes(b[i]));
|
|
}
|
|
// With fromIndex
|
|
for (let i = 0, from_index = 0; i+from_index < 200; i += 2, from_index++) {
|
|
assertEquals(true, testArrayIncludes(b[i], from_index));
|
|
}
|
|
})();
|
|
|
|
// Large array of holey objects, and object search_element
|
|
(() => {
|
|
let a = [];
|
|
let b = [];
|
|
// Skipping every other item when initializing
|
|
for (let i = 0; i < 200; i++) {
|
|
b[i] = { v: i };
|
|
if (i % 2 == 0) {
|
|
a[i] = b[i];
|
|
}
|
|
}
|
|
function testArrayIncludes(idx) {
|
|
return a.includes(idx);
|
|
}
|
|
// Without fromIndex
|
|
for (let i = 0; i < 200; i++) {
|
|
if (i % 2 == 0) {
|
|
assertEquals(true, testArrayIncludes(b[i]));
|
|
} else {
|
|
assertEquals(false, testArrayIncludes(b[i]));
|
|
}
|
|
}
|
|
// With fromIndex
|
|
for (let i = 0, from_index = 0; i + from_index < 200; i += 2, from_index++) {
|
|
if (i % 2 == 0) {
|
|
assertEquals(true, testArrayIncludes(b[i], from_index));
|
|
} else {
|
|
assertEquals(false, testArrayIncludes(b[i], from_index));
|
|
}
|
|
}
|
|
})();
|