Skip to content

Commit ce16dd9

Browse files
authored
fix: speculative execution in wasm
In #74 we make sure to increment position by a constant whenever in a happy path so that the CPU could proceed through the loop header (`endp - p >= 16`) speculatively instead of blocking and waiting for vector to scalar to fully resolve. This doesn't seem to give an obvious performance boost yet, but potentially might have an effect with the future V8 updates.
1 parent 75d26f1 commit ce16dd9

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/implementation/c/node/table-lookup.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class TableLookup extends Node<frontend.node.TableLookup> {
288288
}
289289

290290
out.push('#ifdef __wasm_simd128__');
291-
out.push(`if (${ctx.endPosArg()} - ${ctx.posArg()} >= 16) {`);
291+
out.push(`while (${ctx.endPosArg()} - ${ctx.posArg()} >= 16) {`);
292292
out.push(' v128_t input;');
293293
out.push(' v128_t mask;');
294294
out.push(' v128_t single;');
@@ -327,21 +327,23 @@ export class TableLookup extends Node<frontend.node.TableLookup> {
327327
out.push(' match_len = __builtin_ctz(');
328328
out.push(' ~wasm_i8x16_bitmask(mask)');
329329
out.push(' );');
330-
out.push(` ${ctx.posArg()} += match_len;`);
331330
out.push(' if (match_len != 16) {');
331+
out.push(` ${ctx.posArg()} += match_len;`);
332332
{
333333
const tmp: string[] = [];
334334
this.tailTo(tmp, this.ref.otherwise!);
335335
ctx.indent(out, tmp, ' ');
336336
}
337337
out.push(' }');
338+
out.push(` ${ctx.posArg()} += 16;`);
339+
out.push('}');
338340

339-
const tmp: string[] = [];
340-
this.tailTo(tmp, {
341-
noAdvance: true,
342-
node: edge.node,
343-
});
344-
ctx.indent(out, tmp, ' ');
341+
out.push(`if (${ctx.posArg()} == ${ctx.endPosArg()}) {`);
342+
{
343+
const tmp: string[] = [];
344+
this.pause(tmp);
345+
this.compilation.indent(out, tmp, ' ');
346+
}
345347
out.push('}');
346348

347349
out.push('#endif /* __wasm_simd128__ */');

0 commit comments

Comments
 (0)