Skip to content

Instantly share code, notes, and snippets.

View binji's full-sized avatar

Ben Smith binji

View GitHub Profile
@binji
binji / donut.lua
Created September 23, 2014 15:56
Lua Port of Obfuscated C Donut
-- See original here http://www.a1k0n.net/2006/09/15/obfuscated-c-donut.html
A=0 B=0 z={}b=
{}E={32,46,44,45,126,
58,59,61,33,42,35,36,64}S
=math.sin C=math.cos F=math.
floor I=io.write T=string.char W=60
P=print H=25 P("\\x1b[2J")for w=1,240
do for o=0,W*H do b[o]=1 z[o]=0 end e=
S(A)g=C(A)m=C(B)n=S(B)for j=0,6.28,.09
@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 / leb128.cc
Last active January 8, 2022 17:31
benchmark for various varint formats
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "benchmark/benchmark.h"
@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 / sprites.py
Created October 27, 2016 16:57
gameboy mode3 sprite timing
#!/usr/bin/env python
import math
import os
import sys
def calculate(scx, expected_cycles, sprites):
buckets = [0] * (((168 + scx + 7) // 8))
scx &= 7
total = scx
if 0 in sprites:
@binji
binji / ThreadOpcodes.md
Last active January 13, 2021 12:11
Thread/Atomics WebAssembly opcode space

Proposed

Name Opcodes Size
is_lock_free 0xff00 1
wake 0xff01 1
i32.wait 0xff02 1
i64.wait 0xff03 1
available 0xff04..0xff0f 12
*.atomic.rmw*.* 0xff10..0xff1b 12
@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 / memcpy.wast
Created August 2, 2017 18:34
memcpy.wast
(module
(import "env" "memory" (memory 1))
(func $memcpy (export "memcpy") (param i32 i32 i32) (result i32)
(local i32)
(block (result i32) ;; label = @1
(set_local 3
(get_local 0))
(if ;; label = @3
(i32.eq
(i32.and
@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))