Skip to content

Instantly share code, notes, and snippets.

View eira-fransham's full-sized avatar

Eira Fransham eira-fransham

  • Berlin
View GitHub Profile
@eira-fransham
eira-fransham / sieve_test.wast
Last active March 18, 2019 10:20
Complex Rust test-case for Wasmtime (Wast version, with embedded `$log2` that isn't generated by default) - Rust version here https://gist.github.com/Vurich/8d50d64540fdc533d75adc3aea2c3589
(module
(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)
@eira-fransham
eira-fransham / sieve_test.rs
Last active March 18, 2019 10:20
Complex Rust test-case for Wasmtime - Wast version here https://gist.github.com/Vurich/22f60343228079e37ba97a9111cccf08
use std::iter;
fn optimized_sieve(limit: usize) -> impl Iterator<Item = usize> {
let map_func = |cmpsts: Vec<u32>| {
move |i| {
if i < 0 {
Some(2)
} else {
if cmpsts[i as usize >> 5] & (1u32 << (i & 31)) == 0 {
Some((i + i + 3) as usize)
; 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);
}
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:
.fn_0:
const 0i32
const 1i32
swap 1
diff --git a/content/posts/wasm-is-not-a-stack-machine.md b/content/posts/wasm-is-not-a-stack-machine.md
index f8a944c..34bb3a5 100644
--- a/content/posts/wasm-is-not-a-stack-machine.md
+++ b/content/posts/wasm-is-not-a-stack-machine.md
@@ -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
fib:
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
INPUT:
(module
(func
(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)
@eira-fransham
eira-fransham / lightbeam-fib-comparison
Last active January 17, 2019 10:28
Lightbeam fibonacci generated code before and after #12
push rbp | push rbp
mov rbp, rsp | mov rbp, rsp
sub rsp, 0x20 | sub rsp, 0x10
mov edx, 1 | mov qword ptr [rsp + 8], rdi
xor eax, eax | mov eax, 0
cmp esi, 2 | push rax
setb al | mov rax, qword ptr [rsp + 0x10]
test eax, eax | push rax
je 0x2d | pop rax
jmp 0x8e | pop rcx
push rbp
mov rbp, rsp
sub rsp, 0x10
mov qword ptr [rsp + 8], rdi
mov eax, 0
push rax
mov rax, qword ptr [rsp + 0x10]
push rax
pop rax
pop rcx