Skip to content

Instantly share code, notes, and snippets.

View Aatch's full-sized avatar

James Miller Aatch

View GitHub Profile
@Aatch
Aatch / test.ll
Last active December 25, 2015 13:28
; ModuleID = 'test.rc'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%struct.Foo = type { [10 x i64] }
%tydesc = type { i64, i64, void ({}*, i8*)*, void ({}*, i8*)*, void ({}*, i8*)*, void ({}*, i8*)*, i64, { i8*, i64 } }
@_rust_crate_map_toplevel = global { i32, i64, [2 x i64] } { i32 1, i64 ptrtoint ([1 x { i64, i64 }]* @_rust_mod_map to i64), [2 x i64] [i64 ptrtoint (i64* @_rust_crate_map_std_0.9-pre_6c65cf4b443341b1 to i64), i64 0] }
@_rust_crate_map_std_0.9-pre_6c65cf4b443341b1 = external global i64
@_rust_mod_map = internal global [1 x { i64, i64 }] zeroinitializer
@Aatch
Aatch / ast.rs
Created December 22, 2013 23:58
Rust-based Parser
use std::hashmap::HashMap;
#[deriving(Eq,Clone,IterBytes)]
pub struct Ident(u32);
#[deriving(Clone)]
pub struct Pos {
col: u16,
row: u16
}
@Aatch
Aatch / gist:8466307
Created January 17, 2014 00:37
Surface Simplification with Quadric Error Metrics - for BlackMoon
; This is written pseudo-code, so hopefully should be fairly self-evident.
;
; A few notes about the general maths which I think will be needed:
;
; Matrices use what is called a "row-major" convention for sizes/indexes,
; this just means that a 2x3 matrix has 2 rows and 3 columns, it also
; means that for a matrix, M, M[1][2] is the number in the second column
; in the first row (I will also use base-1 indexing, since it better
; matches mathematical convention)
;
@Aatch
Aatch / bad.rs
Last active August 29, 2015 14:11
fn test() {
let x : [u8, ..256];
let val = get_val();
if val == 0 {
x = [1, ..256];
return x;
} else if val == 3 {
x = [3, ..256];
return x;
@Aatch
Aatch / if_cfg.rs
Last active August 29, 2015 14:21
Handy macro for complex conditional compilation
// Feel free to copy and modify this code if it's useful to you.
macro_rules! if_cfg {
($(#[cfg($cfg:meta)] $it:item)+ fallback: $els:item) => (
$(#[cfg($cfg)] $it)+
#[cfg(not(any($($cfg),*)))] $els
)
}
if_cfg {
#[cfg(target_arch="x86")]
@Aatch
Aatch / gist:8cea53541fc10eee41a4
Created May 31, 2015 12:13
Ramp Benchmarks 2015-06-01
test int::test::bench_add_1000_10 ... bench: 268 ns/iter (+/- 4)
test int::test::bench_add_1000_1000 ... bench: 1666 ns/iter (+/- 131)
test int::test::bench_add_100_100 ... bench: 205 ns/iter (+/- 33)
test int::test::bench_add_10_10 ... bench: 51 ns/iter (+/- 41)
test int::test::bench_add_1_1 ... bench: 39 ns/iter (+/- 33)
test int::test::bench_div_1000_1000 ... bench: 2359 ns/iter (+/- 4169)
test int::test::bench_div_10_10 ... bench: 58 ns/iter (+/- 135)
test int::test::bench_div_1_1 ... bench: 62 ns/iter (+/- 26)
test int::test::bench_div_20_2 ... bench: 226 ns/iter (+/- 30)
test int::test::bench_div_250_250 ... bench: 117 ns/iter (+/- 1094)
extern crate smallvec;
use std::collections::VecDeque;
use std::io::Read;
use smallvec::SmallVec;
pub type LexResult<T> = std::result::Result<T, Error>;
/**
define void @test() unnamed_addr #0 {
entry-block:
br label %start
start: ; preds = %entry-block
%0 = call i32 @bar()
br label %bb2
end: ; preds = %bb3
ret void
use std::collections::HashSet;
use std::hash::BuildHasherDefault;
use std::default::Default;
use std::hash::Hasher;
pub struct FnvHasher(u64);
impl Default for FnvHasher {
#[inline]
define i32 @foo() unnamed_addr #0 {
entry-block:
%a = alloca i32
%temp0 = alloca {}
%temp3 = alloca {}
br label %start
start: ; preds = %entry-block
store i32 0, i32* %a
br label %bb2