Skip to content

Instantly share code, notes, and snippets.

Jef Vurich

View GitHub Profile
View lightbeam-wasmtime.sh
#! /bin/sh
(cd $(dirname $0) && cargo run --release --features lightbeam -- --env 'RUST_BACKTRACE=1' --lightbeam "$@")
View wasmtime-benchmarks.diff
name cranelift.bench ns/iter lightbeam.bench ns/iter diff ns/iter diff % speedup
+ misc::br_cannot_share_cc::compile 165,109 109,143 (1 MB/s) -55,966 -33.90% x 1.51
+ misc::br_cannot_share_cc::run 1,421 1,318 -103 -7.25% x 1.08
+ misc::call_indirect::compile 2,369,666 1,037,499 (1 MB/s) -1,332,167 -56.22% x 2.28
+ misc::call_indirect::run 7,676 7,513 -163 -2.12% x 1.02
+ misc::control_flow::compile 1,120,041 854,382 -265,659 -23.72% x 1.31
+ misc::control_flow::run 5,848 5,472 -376 -6.43% x 1.07
+ misc::div_rem::compile 593,102 402,117 -190,985 -32.20% x 1.47
+ misc::div_rem::run
View sketchy-vec.rs
use alloc::alloc;
use core::{
alloc::Layout,
convert::{TryFrom, TryInto},
fmt,
mem::{self, ManuallyDrop},
num::NonZeroU32,
ops::{self, Drop},
ptr,
@Vurich
Vurich / lib.rs
Last active Apr 14, 2020
Rust prime sieve, intended to be compiled to Wasm, combined with a `main.rs` which generates assert statements to test execution of the resultant WebAssembly.
View lib.rs
pub fn sieve(limit: usize) -> Option<impl Iterator<Item = usize>> {
let mk_func = |cmpsts: Vec<_>| {
move |i| {
if i < 0 {
Some(2)
} else {
if cmpsts.get(i as usize >> 5)? & (1u32 << (i & 31)) == 0 {
Some((i + i + 3) as usize)
} else {
None
View cursed-cow.rs
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>>;
View octahack-output
def fn::61800aab { .. } -> { Output0 }:
%87fc4ed5: { Sine, Saw, Square } = Synth {
$Freq = 0.5Hz,
}
return {
Output0 = %87fc4ed5->Saw,
}
def fn::bbd34d0d { .. } -> { Output0 }:
View Necessary x86 instrs for Lightbeam.txt
-- 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
View wasmtime-module-dsl.rs
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
Vurich / playground.rs
Created May 24, 2019 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View playground.rs
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
@Vurich
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 https://gist.github.com/Vurich/8d50d64540fdc533d75adc3aea2c3589
View sieve_test.wast
(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)
You can’t perform that action at this time.