Skip to content

Instantly share code, notes, and snippets.

// Auto-generated C API
// Block
BINARYEN_API BinaryenExpressionRef BinaryenBlockGetListAt(BinaryenExpressionRef expr, BinaryenIndex index);
// If
BINARYEN_API BinaryenExpressionRef BinaryenIfGetIfTrue(BinaryenExpressionRef expr);
BINARYEN_API BinaryenExpressionRef BinaryenIfGetCondition(BinaryenExpressionRef expr);
// Loop
@kripken
kripken / a.c
Last active February 1, 2024 22:20
#include <emscripten.h>
extern void launch_missiles();
extern void foo_checkin();
extern void bar_checkin();
void (*mutable_global)() = &launch_missiles;
void benign() {}
--- a.out.js 2024-01-31 09:42:57.311326787 -0800
+++ b.out.js 2024-01-31 09:43:14.131501278 -0800
@@ -1,40 +1,38 @@
var Module = typeof Module != "undefined" ? Module : {};
var moduleOverrides = Object.assign({}, Module);
var arguments_ = [];
var thisProgram = "./this.program";
diff --git a/test/lit/passes/once-reduction.wast b/test/lit/passes/once-reduction.wast
index dd15da5da..7feae8857 100644
--- a/test/lit/passes/once-reduction.wast
+++ b/test/lit/passes/once-reduction.wast
@@ -1349,311 +1349,311 @@
)
;; Corner case: Exported mutable global. We cannot optimize it, since the
;; outside may read and write it.
(module
@kripken
kripken / bench.cpp
Last active January 15, 2025 22:18
Parallel Benchmarks
// Compile with e.g.
//
// ./emcc a.cpp -pthread -sPROXY_TO_PTHREAD -O3 -s INITIAL_MEMORY=1GB
//
#include <atomic>
#include <stdio.h>
#include <stdlib.h>
#include <emscripten.h>
#include <emscripten/threading.h>
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index dec9249c3..b56348b31 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -42,70 +42,76 @@ int unhex(char c) {
}
if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
}
throw wasm::ParseException("invalid hexadecimal");
<script>
var module = WebAssembly.instantiateStreaming(fetch("linked_list.wasm"), {});
</script>
var Module = typeof Module != "undefined" ? Module : {};
(function() {
return this;
}())["Module"] = function() {
var moduleOverrides = Object.assign({}, Module);
var arguments_ = [];
var thisProgram = "./this.program";
var quit_ = (status, toThrow) => {
throw toThrow;
[package]
name = "fannkuch"
version = "0.1.0"
edition = "2021"
[profile.release]
lto = "yes"
panic = "abort"
opt-level = "s"

Trying to avoid quadratic work in 1b

(context: WebAssembly/function-references#44)

An idea I've had is to annotate validated branches. The key thing is that the set of validated branch targets is monotonic - just like the set of set locals. That is, once we see that a branch to $b validates, any subsequent branch must also validate, since we can only add more locals that are set. So as an optimization, the validator could track those until the end of the current block. That basically means to handle the set of valid branch targets in a 1a-like manner, and could be a nice speedup on stuff like this:

  (br_if $b ..) ;; Linear time here.
  (br_if $b ..) ;; But constant time here
  (br_if $b ..) ;; and here!