crunchy/lib.rs
1//! The crunchy unroller - deterministically unroll constant loops. For number "crunching".
2//!
3//! The Rust optimizer will unroll constant loops that don't use the loop variable, like this:
4//!
5//! ```ignore
6//! for _ in 0..100 {
7//! println!("Hello!");
8//! }
9//! ```
10//!
11//! However, using the loop variable will cause it to never unroll the loop. This is unfortunate because it means that you can't
12//! constant-fold the loop variable, and if you end up stomping on the registers it will have to do a load for each iteration.
13//! This crate ensures that your code is unrolled and const-folded. It only works on literals,
14//! unfortunately, but there's a work-around:
15//!
16//! ```ignore
17//! debug_assert_eq!(MY_CONSTANT, 100);
18//! unroll! {
19//! for i in 0..100 {
20//! println!("Iteration {}", i);
21//! }
22//! }
23//! ```
24//! This means that your tests will catch if you redefine the constant.
25//!
26//! To default maximum number of loops to unroll is `64`, but that can be easily increased using the cargo features:
27//!
28//! * `limit_128`
29//! * `limit_256`
30//! * `limit_512`
31//! * `limit_1024`
32//! * `limit_2048`
33
34#![cfg_attr(not(feature = "std"), no_std)]
35
36#[cfg(target_os = "windows")]
37include!(concat!(env!("OUT_DIR"), "\\lib.rs"));
38
39#[cfg(not(target_os = "windows"))]
40include!(concat!(env!("OUT_DIR"), "/lib.rs"));