Skip to content

Instantly share code, notes, and snippets.

View binji's full-sized avatar

Ben Smith binji

View GitHub Profile
@binji
binji / build command
Created September 28, 2018 23:03
wasm pthreads demo
emcc -O2 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 -o pthread.js pthread.c
1."compile a potential WebAssembly response". Change step 7: "and resolve returnValue with result".
2. Add section on WebAssembly module Serialization.
2.2. Added Global object cache
3."asynchronously compile a WebAssembly module". Add step 1 "Let promise be a new promise".
3."asynchronously compile a WebAssembly module". Add step 4 "Return promise".
3."compile a WebAssembly module". Change step 2 to unwrap promise.
3."instantiate a WebAssembly Module". add support for imported/exported mutable globals.
3.3. Remove note "Any attempts to detach buffer..."
3.3. Add algorithm "reset the Memory buffer", refactor `memory.grow` and `grow_memory` instruction to use this.
3.4."create a table object". Add step to fetch associated store.
3.5. Add "Globals" section, defining WebAssembly.Global type.
3.6."new Exported Function". Change step 11 to call `SetFunctionLength`.
@binji
binji / questions.md
Created August 17, 2018 19:17
WebAssembly Threads API TAG security+privacy questions
  • 3.1. Does this specification deal with personally-identifiable information?

No.

  • 3.2. Does this specification deal with high-value data?

No.

  • 3.3. Does this specification introduce new state for an origin that persists across browsing sessions?
@binji
binji / core-diffs.txt
Last active August 17, 2018 22:46
WebAssembly spec diffs
2.4.4. Rename current_memory -> memory.size
2.4.4. Rename grow_memory -> memory.grow
2.5.10. Mutable globals may be exported
2.5.11. Clarification that import names need not be unique
3.3.4.5. Rename current_memory -> memory.size
3.3.4.6. Rename grow_memory -> memory.grow
3.3.7.2. Clarification that get_global in a constant expression can only refer to imported globals
3.4.8.5. An exported global can be mutable
3.4.9.5. An imported global can be mutable
3.4.10.
@binji
binji / gist:57b6b4ff318c6dc77f6d2e1fa7b2bada
Last active April 12, 2018 21:10
WebAssembly section 4 review notes
4.2.12. Refers to the stack containing three kinds of entries "values", "labels", and "activations". Section 4.2.12.1 is called "Values", section 4.2.12.2 is called "Labels" but section 4.2.12.3 is called "Frames" instead.
4.2.12.3. The return arity is named but not labeled here. "Activation frames carry the return arity of the respective function". It should be the same as label above where `n` is mentioned explicitly.
4.2.13. "ultimately reducing the entire program to a single trap instruction", this isn't true when calling out to the embedder, right?
4.2.13. Note #3. The link for the label reduction rule is broken, it should go to 4.4.6.2. Also, the rule is different in the note.
4.2.13.2. What does "home" mean in "home module instance"?
62676140: write_apu :(0x10 [NR41], 0x1)
62676160: write_apu :(0x11 [NR42], 0xf0)
62676180: write_apu :(0x12 [NR43], 0xe0)
62676180: write_noise_period :divisor: 8 clock shift: 14 period: 131072
62676268: write_apu :(0x13 [NR44], 0x80)
62676268: write_noise_period :divisor: 8 clock shift: 14 period: 131072
62676268: trigger_nrx4_envelope :(0x13 [NR44]) volume=15, timer=8
62677172: write_apu :(0x14 [NR50], 0x44)
62677768: write_apu :(0x14 [NR50], 0x44)
62678356: write_apu :(0x14 [NR50], 0x44)
@binji
binji / CustomSectionTextFormat.md
Last active April 18, 2022 07:26
CustomSectionTextFormat.md

Custom sections in the text format

This page describes a proposal for representing custom sections in the text format.

Rationale

Currently it is impossible to round-trip a WebAssembly module between the binary and text formats without loss of information because there is no way to

@binji
binji / binary.txt
Created November 26, 2017 03:32
casio loopy disassembler work
c701 6f06 a004 4027 0908 0000 0e00 0080
d401 e000 a002 2402 0900 118c d002 400b
0009 d002 402b 0009 0e00 04b0 0000 0604
2fe6 4f22 d324 430b 0009 d324 430b 0009
d323 430b 0009 d323 430b 0009 d322 430b
0009 ee00 d321 430b 0009 7e01 e207 3e23
8bf8 d31f 430b 0009 d01e a00d 6001 d31e
430b 0009 a00e 0009 b058 0009 a00a 0009
b00a 0009 a006 0009 8800 89f0 8801 89f3
8802 89f5 afe8 0009 4f22 d014 a035 6001
@binji
binji / memcpy.js
Created October 26, 2017 22:18
Bulk Memory benchmark
const page_size = 65536;
const memory_pages = 2048 * 2;
let memory = new WebAssembly.Memory({initial: memory_pages});
let buffer = new Uint8Array(memory.buffer);
let registry = {env: {memory}};
function module(bytes) {
let buffer = new ArrayBuffer(bytes.length);
let view = new Uint8Array(buffer);