Skip to content

Instantly share code, notes, and snippets.

A Composable, Efficient, and Expressive 2-Instruction Design for Stack-Switching

The following is a design for stack-switching that has a number of useful properties that seem to make it a good fit for the needs of this extension to WebAssembly. I have made an effort to address all the concerns that have been expressed throughout the lifetime of the Stacks subgroup to the best of my understanding of them. For example, I have checked that all prior proposals have a straightforward and efficient translation into this design, and I have identified a composability property that this design (but no prior proposal) satisfies. Please let me know your thoughts, and I am happy to provide a translation if anyone requests one.

The Design

When one performs a call $func, the currently executing function is conceptually left in a suspended state: it stores its current state (e.g. the values of its locals) as a frame on the stack and provides a code address to use to resume the function.

@RossTate
RossTate / Makefile
Created October 24, 2022 15:01
WebAssembly-Call Performance-Analysis Benchmark Suite
CC=gcc
OPT=-O1
NATIVE=whole-optimal whole-unguarded whole-switch whole-vtable separate-direct-unguarded separate-direct-switch separate-vtable-constant separate-vtable-extern
WAT2WASM=wat2wasm --output=-
BASE64=openssl base64 -A
WASM=whole-optimal whole-unguarded whole-switch whole-vtable list-direct-unguarded list-direct-switch sort-direct list-vtable sort-vtable-constant sort-vtable-extern
JAVAC=javac
JAVA=java
.PHONY: run-native test-native native wasm b64 html run-java test-java java all clean