Skip to content

Instantly share code, notes, and snippets.

View eira-fransham's full-sized avatar

Eira Fransham eira-fransham

  • Berlin
View GitHub Profile
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
trait DisplayField {
fn display_field(&self, field: u64, f: &mut fmt::Formatter);
}
; 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]
@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)
@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 / playground.rs
Created May 24, 2019 14:06 — forked from rust-play/playground.rs
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;
old
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;
-- Unless otherwise specified, all the different input/output bit sizes are needed. You might be able to write helpers to
-- make this easier.
adc
add
-- I'm sure you know this but just to make 100% certain: all of the `***ss`/`***sd` instructions operate on IEEE754
-- floats and so need to use separate Low IR actions to the integer operations. Futhermore, `div` has signed and unsigned
-- integer variants, plus single- and double-precision float variants. So that might look like `DivIntS(NumBits)`,
-- `DivIntU(NumBits)` and `DivFloat(FloatSize)` where `FloatSize` is an enum of `Single`,`Double`.
addsd
def fn::61800aab { .. } -> { Output0 }:
%87fc4ed5: { Sine, Saw, Square } = Synth {
$Freq = 0.5Hz,
}
return {
Output0 = %87fc4ed5->Saw,
}
def fn::bbd34d0d { .. } -> { Output0 }:
use std::{
borrow::{Borrow, ToOwned},
marker::PhantomData,
ops::{Deref, Drop},
ptr::{self, NonNull},
};
pub unsafe trait Cursed<T: ?Sized>: Borrow<T> + Sized {
fn borrowed(borowed: &T) -> Option<NonNull<T>>;
fn owned(self) -> Option<NonNull<T>>;