Skip to content

Instantly share code, notes, and snippets.

View djg's full-sized avatar
💭
I may be slow to respond.

Dan Glastonbury djg

💭
I may be slow to respond.
View GitHub Profile
@djg
djg / macros.rs
Created May 27, 2019 00:55
Simulating named parameters with rust macros
#[macro_export]
macro_rules! signal_build {
($name:expr, $shape:expr, $reset:expr, $reset_less:expr) => {
Signal::signal($name, Shape::from($shape), $reset, $reset_less)
};
}
#[macro_export(local_inner_macros)]
macro_rules! signal_collect {
(($_:expr, $shape:expr, $reset:expr, $reset_less:expr) name: $name:expr, $($k:ident: $v:expr,)*) => {
@djg
djg / level2.asm
Last active May 16, 2019 04:47
Rust Output At Different Opt Levels
example::test:
push rax
cmp rsi, 50
jbe .LBB23_1
mov eax, dword ptr [rdx]
mov dword ptr [rdi], eax
mov eax, dword ptr [rdx + 4]
mov dword ptr [rdi + 4], eax
mov eax, dword ptr [rdx + 8]
mov dword ptr [rdi + 8], eax
@djg
djg / CommonItemPropertiesPoke.asm
Last active May 15, 2019 00:16
Rust generated code for webrender_api::CommonItemProperties
beagle_bros_test::poke:
cmp rsi, 60
jbe LBB29_8
movups xmm0, xmmword, ptr, [rdx, +, 64]
movups xmmword, ptr, [rdi], xmm0
cmp dword, ptr, [rdx], 1
jne LBB29_2
mov byte, ptr, [rdi, +, 16], 1
mov rax, qword, ptr, [rdx, +, 8]
mov qword, ptr, [rdi, +, 17], rax
@djg
djg / gist:9e6bd46486d4f44cc3662ef8cc44a8ce
Created February 14, 2019 05:44
Belgium/Dutch/Euro Sound of Adelaide '91-'93
In no particular order:
Space Master - I Need You (Master Mix) https://www.youtube.com/watch?v=Qg0VjVXVoXk
Afrika Bambaataa - Feeling Irie https://www.youtube.com/watch?v=z2VdfIA7N7o
House Pimps - Zulu Nation https://www.youtube.com/watch?v=zrXnzJ0Mn0E
The Badman Presents N.D.X. - Come With Me https://www.youtube.com/watch?v=EUDW_LWbtQM
Tainted Two - The Megablast https://www.youtube.com/watch?v=oHd8Sk-7WIU
Digital Domain - I Need Relief https://www.youtube.com/watch?v=zrXnzJ0Mn0E
Problem house - Party people https://www.youtube.com/watch?v=MNQitcvJKlw
DJ Hype - Shot in The Dark (Q Bass Remix) https://www.youtube.com/watch?v=0O40o6RvoH8
Mig-29 - Mig-29 (Love Mix) https://www.youtube.com/watch?v=4oqqMbmIhkQ
@djg
djg / fhdl.rs
Created January 18, 2019 02:34
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{
fold::Fold,
parse::{Parse, ParseStream, Result},
parse_quote,
punctuated::Punctuated,
Expr, ExprLit, FieldValue, Ident, ItemFn, LitStr, Local, Member, Pat, Stmt, Token,
};
@djg
djg / image.rs
Created December 16, 2018 23:36
WebRender ImageKey and ImageTemplate
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct ImageKey {
pub common: PrimKeyCommonData,
pub key: ApiImageKey,
pub stretch_size: SizeKey,
pub tile_spacing: SizeKey,
pub color: ColorU,
pub sub_rect: Option<DeviceIntRect>,
@djg
djg / gross.rs
Created September 14, 2018 02:49
SIMD in Rust is kinda gross.
// Type your code here, or load an example.
#[cfg(target_arch = "x86")]
use std::arch::x86::__m128;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::__m128;
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2"))]
pub struct Ray {
pub pt: __m128,
pub dir: __m128,
@djg
djg / halpstahp.rs
Created September 14, 2018 02:30
functional programming cry for help
pub fn hit_zip(aabb: &Aabb, r: &Ray, t_min: f32, t_max: f32) -> bool {
r.direction
.iter()
.zip(
r.point
.iter()
.zip(aabb.min.iter().zip(aabb.max.iter())),
).all(|(d, (p, (min, max)))| {
let inv_d = 1. / d;
let t0 = (min - p) * inv_d;
@djg
djg / after.cpp
Created March 15, 2018 06:59
verilated-rs generated binds to verilator simulation class.
#include <Vtop.h>
extern "C" {
// CONSTRUCTORS
Vtop*
top_new() {
return new Vtop();
}
void
// Samples are delta-encoded
pub fn unpack_sample<T: Default + ops::AddAssign + Clone>(input: &[u8])
-> Result<Vec<T>, &'static str> {
if input.len() % mem::size_of::<T>() != 0 {
return Err("packed sample data is not aligned");
}
let packed_sample: &[T] = unsafe {
slice::from_raw_parts(input.as_ptr() as *const T,
input.len() / mem::size_of::<T>())