Skip to content

Instantly share code, notes, and snippets.

View binji's full-sized avatar

Ben Smith binji

View GitHub Profile
@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 / 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 / test
Created January 26, 2022 01:08
Hello
(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 / 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 / scalar-unrolled-4x.wat
Last active September 11, 2020 20:11
clamp_zero
(func (export "4x_i32") (param i32 i32 i32 i32)
(local $temp i32)
(local $i i32)
local.get 0
i32.const 16
i32.ge_s
if
loop
local.get 2
local.get $i
@binji
binji / chip8.txt
Created June 12, 2020 19:59
chip8 decompiled
export memory mem(initial: 1, max: 0);
global g_a:int = 512;
global g_b:int = 144;
global g_c:int = 0;
global g_d:int = 0;
global g_e:int = 0;
data d_pPpPPPP(offset: 0) =
"\f0\90\90\90\f0` p\f0\10\f0\80\f0\f0\10\f0\10\f0\a0\a0\f0 \f0\80\f0"
@binji
binji / commandline
Created March 28, 2020 01:35
WebAssembly memory reading demo
emcc test.c -o test.js -s EXPORTED_FUNCTIONS='["_get", "_increment"]'
@binji
binji / sign-extension-ops.diff
Created January 16, 2020 18:48
sign-extension-ops.diff
diff -r -u spec/document/core/appendix/index-instructions.rst sign-extension-ops/document/core/appendix/index-instructions.rst
--- spec/document/core/appendix/index-instructions.rst 2019-03-30 12:56:50.472907052 -0700
+++ sign-extension-ops/document/core/appendix/index-instructions.rst 2020-01-16 10:29:11.379288914 -0800
@@ -199,4 +199,10 @@
:math:`\I64.\REINTERPRET\K{\_}\F64` :math:`\hex{BD}` :math:`[\F64] \to [\I64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\F32.\REINTERPRET\K{\_}\I32` :math:`\hex{BE}` :math:`[\I32] \to [\F32]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
:math:`\F64.\REINTERPRET\K{\_}\I64` :math:`\hex{BF}` :math:`[\I64] \to [\F64]` :ref:`validation <valid-cvtop>` :ref:`execution <exec-cvtop>`, :ref:`operator <op-reinterpret>`
+:math:`\I32.\EXTEND\K{8\_s}` :math:`\hex{C0}