This got reposted in a better form here: https://shift.click/codelet/codelet-atomic-perf-notes. Or look at the history.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! initial version courtesy of @danielhenrymantilla. | |
//! | |
//! extended to support fns with args/return types, | |
//! visibility, #[attributes], unsafe, const, async, | |
//! extern "abi" ... | |
//! | |
//! left as an exercise for later (cuz it sux): | |
//! - generics? | |
//! - where clauses? | |
//! - probably other shit im missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Something like a `flat_map` over a fallible iterator. | |
/// | |
/// Note that the `map` itself is not fallible. | |
/// | |
/// See test at end of file for usage. | |
// | |
// TODO this should probably take `impl IntoIterator<IntoIter = I>` but the | |
// generics here are already so fucking complicated, and i'm worried that | |
// will cause inference errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Wrapper around an `impl std::error::Error` that makes it "mostly" clonable. | |
pub struct ClonableError<E> { | |
error: Option<E>, | |
// tbh these are all anybody cares about for Errors anyway. | |
display: Box<str>, | |
debug: Box<str>, | |
} | |
impl<E> Clone for ClonableError<E> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <cstddef> | |
#include <memory> | |
#include <iostream> | |
#include <cassert> | |
#include <stdexcept> | |
struct XmlNode { | |
struct Attribute { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Coord is a way of storing a 2d integer vector (e.g. vec2i or similar) as a | |
// value type by packing it into a number. It will do what you want in a Map or | |
// Set, you can compare them for equality, and it should be free of alloctions | |
// (at least in Spidermonkey and V8, but probably anywhere else too). | |
// | |
// The downside is that it's a pain to debug, use, and it has ugly syntax. It's | |
// type safe (in typescript) tho. | |
// | |
// Each component is stored as a 15 bit (signed, 2's complement) integer. These |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(test)] | |
#![recursion_limit = "1024"] | |
#![allow(dead_code)] | |
#![feature(stdsimd)] | |
extern crate test; | |
extern crate rand; | |
// Defines a little benchmarking DSL macro. If you've been linked here, it's safe to ignore. | |
#[macro_use] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug, Clone, Default)] | |
pub struct Shape { | |
pub vertices: Vec<V3>, | |
pub tris: Vec<[u16; 3]>, | |
} | |
impl Shape { | |
// ... | |
pub fn new_sphere(radius: f32, bands: (usize, usize)) -> Self { | |
use std::{f32, u16}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// ``` | |
/// # #[allow(dead_code)] fn code_requiring_fma_and_avx() {} | |
/// # #[allow(dead_code)] fn code_requiring_sse41() {} | |
/// # #[allow(dead_code)] fn code_requiring_sse2() {} | |
/// # #[allow(dead_code)] fn fallback_code() {} | |
/// # fn main() { | |
/// let thing = t3m::simd_match! { | |
/// // Comma separate required target features to require both. | |
/// "fma", "avx" => code_requiring_fma_and_avx(), | |
/// "sse4.1" => code_requiring_sse41(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Default, Debug, Clone)] | |
pub struct RadixSorter { | |
// TODO: only need one buffer. | |
unsorted_buf: Vec<(usize, u32)>, | |
pub sorted_buf: Vec<(usize, u32)>, | |
} | |
impl RadixSorter { | |
#[inline] |