Skip to content

Instantly share code, notes, and snippets.

View binji's full-sized avatar

Ben Smith binji

View GitHub Profile
@binji
binji / notes.md
Created November 25, 2022 05:14
Compiling LLVM/Clang for Wasm notes
  • How to Cross Compile LLVM: https://llvm.org/docs/HowToCrossCompileLLVM.html
  • Building LLVM with CMake: https://llvm.org/docs/CMake.html
  • Hints from wasi-sdk Makefile: https://github.com/CraneStation/wasi-sdk/blob/master/Makefile
  • Try compiling natively (needed for llvm-tblgen and clang-tblgen)
    • cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;WebAssembly" -DLLVM_ENABLE_PROJECTS="lld;clang" ../llvm
  • Try building LLVM with WASI:
  • cmake -G Ninja -DCMAKE_AR=”/usr/local/google/home/binji/dev/llvm-project/build/bin/llvm-ar” -DCMAKE_RANLIB=”/usr/local/google/home/binji/dev/llvm-project/build/bin/llvm-ranlib” -DCMAKE_C_COMPILER="/usr/local/google/home/binji/dev/wasi-sdk-5.0/opt/wasi-sdk/bin/clang" -DCMAKE_CXX_COMPILER="/usr/local/google/home/binji/dev/wasi-sdk-5.0/opt/wasi-sdk/bin/clang++" -DCMAKE_CROSSCOMPILING=True -DCMAKE_INSTALL_PREFIX=/usr/local/google/home/binji/dev/wasi-clang -DLLVM_TABLEGEN=/usr/local/google/home/binji/dev/llvm-project/build/bin/llvm-tblgen -DCLANG_TABLEGEN=/
@binji
binji / tharte.c
Created January 25, 2024 17:19
Parsing/executing tom harte tests for NES in C
#include "common.h"
#include "options.h"
#include "vec.h"
#include "third_party/json.h"
#define HOOK(name, ...)
#define DEBUG(...) (void)0
// See s_opcode_bits below
@binji
binji / LICENSE
Last active January 3, 2024 23:37
pokegb.cc w/o macros
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
@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 / test
Created January 26, 2022 01:08
Hello
@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);
@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"
(import "env" "memory" (memory 1))
(import "env" "text" (func $text (param i32 i32 i32)))
;; The current game mode. 0: init, 1: wait, 2: reset, 3:game, 4:winning
(global $mode (mut i32) (i32.const 0))
;; The mode timer, in frames.
(global $mode-timer (mut i32) (i32.const 60))
;; The maximum wall to render or collide against. Used to clear the maze.
(global $max-wall-addr (mut i32) (i32.const 0x2778))
;; Memory map:
;;
;; [0x19a3 .. 0x019a4] x, y mouse click position
;; [0x1a60 .. 0x01aa0] 16 RGBA colors u32[16]
;; [0x1aa0 .. 0x01ea0] 16x16 emojis 4bpp u8[8][128]
;; [0x1ea0 .. 0x01ef0] 8x8 digits 1bpp u8[10][8]
;; [0x1ef0 .. 0x01f18] gameover 1bpp u8[5][8]
;; [0x1f18 .. 0x01f60] 18 match patterns u32[18]
;; [0x1f60 .. 0x01ff0] 18 shift masks u64[18]
;; [0x20a0 .. 0x020e0] 8x8 grid bitmap u64[8]
@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