Skip to content

Instantly share code, notes, and snippets.

@luqmana
Last active December 16, 2015 15:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luqmana/5457029 to your computer and use it in GitHub Desktop.
Save luqmana/5457029 to your computer and use it in GitHub Desktop.
fn libc_rsqrt(f: &f32) -> f32 {
1.0/f32::sqrt(*f)
}
fn llvm_rsqrt(f: &f32) -> f32 {
1.0/core::unstable::intrinsics::sqrtf32(*f)
}
fn asm_rsqrt(f: &f32) -> f32 {
let mut b = &0.0f32;
unsafe {
asm!("rsqrtss ($0), %xmm0\n\t\
movss %xmm0, ($0)"
:"=r"(b)
:"0"(f)
:"xmm0"
);
*b
}
}
fn main() {
io::println(fmt!("libc: %?", libc_rsqrt(&64.0)));
io::println(fmt!("llvm: %?", llvm_rsqrt(&64.0)));
io::println(fmt!("rsqrt: %?", asm_rsqrt(&64.0)));
}
@brendanzab
Copy link

Just implemented this. Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment