Skip to content

Instantly share code, notes, and snippets.

View auroranockert's full-sized avatar

Aurora Nockert auroranockert

View GitHub Profile

Hello Rust Dev!

I implemented OpenCL-style[0] accessors for SIMD types in Rust[1], the code quality isn't near merge-worthy yet, but I wanted some input.

For some code-examples, go to https://github.com/jensnockert/rust/tree/simd/src/test/run-pass/simd-test and check it out, you should be able to get the idea of how they work.

Note that I didn't add any actual syntax for vector types yet (since it would be highly controversial and I don't know what would be the best option), so I just added a simd!(name: T * n) syntax extension that declares a new type that maps down to a LLVM <n * T>.

My preference for syntax right now would be simd!(n x T) if I can get that to parse, or simd!(T, ..n). And then you would declare a type with type f32x4 = simd(4 x f32); and it would magically work. Another option would be some variant of the [T, ..n] syntax used for fixed-length vectors.

define <4 x float> @"_ZN7vupdate17_1f893621e1a881317_0$x2e0E"({ i64, %tydesc*, i8*, i8*, i8 }*, <4 x float>) #1 {
static_allocas:
%2 = alloca <4 x float>
%3 = alloca <4 x float>
%4 = alloca <4 x float>
%5 = alloca [2 x float]
br label %"function top level"
"function top level": ; preds = %static_allocas
store <4 x float> %1, <4 x float>* %3
use std::io;
simd!(u32x4: u32 * 4)
simd!(f32x2: f32 * 2)
simd!(f32x4: f32 * 4)
fn vcopy(a:f32x4) -> f32x4 {
a
}
use std::io;
simd!(u32x4: u32 * 4)
simd!(f32x4: f32 * 4)
fn vcopy(a:f32x4) -> f32x4 {
a
}
fn vsplat(a:f32) -> f32x4 {
compile_and_link: x86_64-apple-darwin/stage0/lib/rustc/x86_64-apple-darwin/lib/libsyntax.dylib
/bin/sh: line 1: 73165 Abort trap: 6 x86_64-apple-darwin/stage0/bin/rustc --cfg stage0 -O --target=x86_64-apple-darwin -o x86_64-apple-darwin/stage0/lib/rustc/x86_64-apple-darwin/lib/libsyntax.dylib /Users/Jens/Code/Git/rust/src/libsyntax/syntax.rs
make: *** [x86_64-apple-darwin/stage0/lib/rustc/x86_64-apple-darwin/lib/libsyntax.dylib] Error 134
use std::io;
use std::unstable::simd;
fn main () {
let x = simd::f64x2(1.0, 2.0);
io::println(fmt!("Result of vector addition is (%f, %f)", x.s0 as float, x.s1 as float))
}
use std::io;
macro_rules! Q(($M:ident, $T:ident, $S:ty, $L:ty, $Q:expr) => (mod $M {
pub struct $T { value: $S }
static K:$L = 1 << ($Q - 1);
impl $T {
pub fn init(value: $S) -> $T {
$T { value: value }
impl Interpolate for float {
fn linear(x: float, y: float, t: float) -> float { // TODO: Test
t.mul_add(y - x, x)
}
fn cosine(x: float, y: float, t: float) -> float { // TODO: Test
(0.5 * (1.0 - (t * Real::pi()).cos())).mul_add(y - x, x)
}
fn smooth(x: float, y: float, t: float) -> float { // TODO: Test
#[link(name = "cl", vers = "0.1", uuid = "1205b5b0-fbd0-4eeb-bfac-e85947419b4e")];
#[license = "MIT"];
#[crate_type = "lib"];
#[author = "Jens Nockert"];
#[comment = "OpenCL library for Rust"];
#[desc = "Trying to make OpenCL more usable from Rust, uses the openlc.rs bindings."];
@auroranockert
auroranockert / base.rs
Last active December 12, 2015 05:08
Rust Numeric (Very much first draft, influenza may have had some bad influence)
trait Eq {
fn eq(&self, other: &Self) -> bool;
fn ne(&self, other: &Self) -> bool; // TODO: Default implementation?
}
trait Ord: Eq {
fn lt(&self, other: &Self) -> bool;
fn le(&self, other: &Self) -> bool;
fn ge(&self, other: &Self) -> bool;
fn gt(&self, other: &Self) -> bool;