Skip to content

Instantly share code, notes, and snippets.

View binji's full-sized avatar

Ben Smith binji

View GitHub Profile
@binji
binji / banner.lua
Created September 23, 2014 15:58
PNaCl Banner in Lua
t=0 A={64,36,35,42,33,61,59,58,126,45,44,46,32}L={0,254,195,3,224,135,231,127,
124,60,128,255,120,158,207,199,241,252,192,121,30,31,61,227,1,223,243,188,63,251
,190,193,28,156,62,248,143,7,126}D={2,3,3,4,1,5,6,7,8,9,10,1,11,12,13,14,15,16,4
,1,10,14,7,17,18,10,1,19,3,20,21,15,15,3,22,21,11,7,17,18,23,2,24,25,13,14,15,26
,27,13,21,11,7,8,28,29,19,7,25,13,2,3,30,3,8,21,11,7,25,10,29,31,7,32,13,21,19,
27,27,13,33,34,7,25,10,35,15,16,24,20,21,19,24,27,8,36,37,7,25,10,10,31,38,39,13
}B=bit32 M=math I=io.write T=string.char P=print S=M.sin C=M.cos F=M.floor b={}
for i=1,1200 do b[i]=0 end for i,v in ipairs(D)do w=L[v]for j=1,8 do if B.band(w
,1)==1 then b[160-48+i*8+j]=1 end w=B.rshift(w,1)end end P("\\x1b[2J") for w=1,
4720 do P("\\x1b[H")s=1.06*S(t*.07)^2 for i=1,1200 do x=s*((i%60)-34)+34 y=s*(F(i
@binji
binji / sample output
Last active April 25, 2016 04:13
simple thread pool w/ bump allocator
doing stuff...
doing stuff...
chunk 0: used: 50000 size: 65536
chunk 1: used: 37020 size: 65536
chunk 2: used: 51000 size: 65536
chunk 3: used: 44000 size: 65536
chunk 4: used: 58000 size: 65536
chunk 5: used: 63000 size: 65536
chunk 6: used: 41000 size: 65536
chunk 7: used: 56000 size: 65536
@binji
binji / switch.json
Created April 25, 2016 19:29
sexpr-wasm spec json
{"modules": [
{"filename": "switch-spec.0.wasm", "commands": [
{"type": "assert_return", "name": "$assert_return_0", "file": "third_party/testsuite/switch.wast", "line": 125},
{"type": "assert_return", "name": "$assert_return_1", "file": "third_party/testsuite/switch.wast", "line": 126},
{"type": "assert_return", "name": "$assert_return_2", "file": "third_party/testsuite/switch.wast", "line": 127},
{"type": "assert_return", "name": "$assert_return_3", "file": "third_party/testsuite/switch.wast", "line": 128},
{"type": "assert_return", "name": "$assert_return_4", "file": "third_party/testsuite/switch.wast", "line": 129},
{"type": "assert_return", "name": "$assert_return_5", "file": "third_party/testsuite/switch.wast", "line": 130},
{"type": "assert_return", "name": "$assert_return_6", "file": "third_party/testsuite/switch.wast", "line": 131},
{"type": "assert_return", "name": "$assert_return_7", "file": "third_party/testsuite/switch.wast", "line": 132},
@binji
binji / add.wat
Last active September 21, 2017 18:39
Simple WebAssembly Example
;; Convert this to add.wasm by running:
;;
;; wat2wasm add.wat -o add.wasm
;;
(module
(func (export "add") (param i32 i32) (result i32)
get_local 0
get_local 1
i32.add))
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 / 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"?
@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 / Bulk.md
Last active May 18, 2018 20:38
Bulk Memory Operations

Bulk Memory Operations

Motivation

Some people have mentioned that memcpy and memmove functions are hot when profiling some WebAssembly benchmarks. Some examples:

I've been looking at perf profiles for wasm unity benchmark a bit recently and see that some

@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?
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`.