Skip to content

Instantly share code, notes, and snippets.

Jef Vurich

Block or report user

Report or block Vurich

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
use cranelift_codegen::ir::types;
use cranelift_codegen::{ir, isa};
use cranelift_entity::PrimaryMap;
use cranelift_wasm::{DefinedFuncIndex, Global as WasmGlobal, GlobalInit};
use hlist::{Cons, Here, Nil, There};
use std::any::Any;
use std::cell::RefCell;
use std::collections::HashMap;
use std::marker::PhantomData;
use std::rc::Rc;
Vurich /
Created May 24, 2019 — forked from rust-play/
Code shared from the Rust Playground
use std::iter::repeat;
fn aks_coefficients(k: usize) -> Vec<i64> {
let mut coefficients = vec![0; k + 1];
coefficients[0] = 1;
for i in 1..(k + 1) {
coefficients[i] = -(1..i).fold(coefficients[0], |prev, j|{
let old = coefficients[j];
coefficients[j] = old - prev;
Vurich / sieve_test.wast
Last active Mar 18, 2019
Complex Rust test-case for Wasmtime (Wast version, with embedded `$log2` that isn't generated by default) - Rust version here
View sieve_test.wast
(type $t0 (func (param i32)))
(type $t1 (func (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)))
(type $t2 (func (param i32 i32)))
(type $t3 (func (param i32) (result i32)))
(type $t4 (func (param i32 i32 i32)))
(type $t5 (func (param i32 i32) (result i32)))
(type $t6 (func (param i32 i32 i32) (result i32)))
(type $t7 (func (param f64) (result f64)))
(func $log2 (type $t7) (param $p0 f64) (result f64)
Vurich /
Last active Mar 18, 2019
Complex Rust test-case for Wasmtime - Wast version here
use std::iter;
fn optimized_sieve(limit: usize) -> impl Iterator<Item = usize> {
let map_func = |cmpsts: Vec<u32>| {
move |i| {
if i < 0 {
} else {
if cmpsts[i as usize >> 5] & (1u32 << (i & 31)) == 0 {
Some((i + i + 3) as usize)
View call_indirect.asm
; rdi = vmctx
mov [rsp + 0x20], rdi
; eax = callee_idx
mov eax, 0
mov [rsp + 0x34], eax
mov rax, [rsp + 0x20]
; eax = vmctx->tables[table_idx].len
mov eax, [rax + 0x68]
; ecx = callee_idx
mov ecx, [rsp + 0x34]
trait DisplayField {
fn display_field(&self, field: u64, f: &mut fmt::Formatter);
View microwasm_example.asm
def .L1_end :: [i32, i32]:
def .L2 :: [i32, i32] num_callers=1:
def .L3 :: [i32, i32] has_backwards_callers:
def .L3_end :: [i32, i32]:
def .L4 :: [i32, i32] num_callers=1:
const 0i32
const 1i32
swap 1
View diff for the lazy.diff
diff --git a/content/posts/ b/content/posts/
index f8a944c..34bb3a5 100644
--- a/content/posts/
+++ b/content/posts/
@@ -7,7 +7,9 @@ draft: false
> ### Preamble
> This article assumes some familiarity with virtual machines, compilers and WebAssembly, but I'll try to link to relevant information where necessary so even if you're not you can follow along.
> <br/><br/>
-> Also, this series is going to come off as if I dislike WebAssembly. I love WebAssembly! In fact, I love it so much that I want it to be the best that it can be, and this series is me working through my complaints with the design in the hope that some or all of these issues can be addressed soon, while the ink is still fresh on the specification.
+> Also, this series is going to come off as if I dislike WebAssembly. I love WebAssembly! I wrote a [whole article about how great it is][wasm-on-the-blockchain]! In fact, I love i
View fib_indirect.S
push rbp
mov rbp, rsp
sub rsp, 0x10
xor eax, eax
cmp rsi, 0
sete al
test eax, eax
; If `rsi` is _not_ zero, then jump to .fib-then
je .fib_then
View lightbeam-spec-loop-compilation
(call $assert-return (call $as-binary-operand) (i32.const 12))
(call $assert-return (call $break-bare) (i32.const 19))
(call $assert-return (call $break-value) (i32.const 18))
(call $assert-return (call $break-repeated) (i32.const 18))
(call $assert-return (call $break-inner) (i32.const 0x7))
(func $dummy)
You can’t perform that action at this time.