6 releases
Uses old Rust 2015
0.3.0 | Nov 23, 2017 |
---|---|
0.2.0 | Sep 25, 2017 |
0.1.3 | Jun 24, 2017 |
0.1.2 | Dec 20, 2016 |
#6 in #unroll
64 downloads per month
Used in 3 crates
7KB
90 lines
typenum_loops
A library that provides loops which are fully or partially unrolled at compile time.
extern crate typenum;
extern crate typenum_loops;
use typenum::{U4, U6};
use typenum_loops::Loop;
fn main(){
let arr: &mut[usize] = &mut[0; 4];
// for i in 0..4 {arr[i] = i} fully unrolled by 4
U4::full_unroll(&mut |i| arr[i] = i);
let arr2: &mut[usize] = &mut[0; 13];
// for i in 0..13 {arr2[i] = i} unrolled by 6
U6::partial_unroll(13, &mut |i, _| arr2[i] = i);
}
Note: Very large closures may not be inlined despite attempts to trick llvm by using an empty wrapper fn.
License
MIT
lib.rs
:
#Example
extern crate typenum;
extern crate typenum_loops;
use typenum::{U4, U6};
use typenum_loops::Loop;
fn main(){
let arr: &mut[usize] = &mut[0; 4];
// for i in 0..4 {arr[i] = i} fully unrolled by 4
U4::full_unroll(&mut |i| arr[i] = i);
let arr2: &mut[usize] = &mut[0; 13];
// for i in 0..13 {arr2[i] = i} unrolled by 6
U6::partial_unroll(13, &mut |i, _| arr2[i] = i);
}
Dependencies
~155KB