asm_unroll 0.1.1

Provides unrolled for-loops within inline asm.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 23.07 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 280.16 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • RedRam567/asm_unroll
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • RedRam567

Asm Unroll

Crates.io docs.rs

Provides a macro with extra functionality compared to normal inline assembly in Rust. asm_ext!() allows inline for-loops whose bodies are unrolled into asm lines with literal values.

Example

use asm_unroll::asm_ext;

pub fn sum_array(array: &[i64; 8]) -> i64 {
    let output: i64;

    unsafe {
        asm_ext!(
            // quickly zero a register
            "xor {output:e}, {output:e}",
            // This loop is unrolled and `{i}` is replaced with a literal.
            for i in 0..8 {
                "add {output}, [{array} + 8*{i}]",
            }
            // inputs:
            array = in(reg) array,
            // outputs:
            output = out(reg) output,
            options(nostack),
        );
    }

    output
}

Compiles to this assembly:

push rax

xor eax, eax
add rax, qword ptr [rdi]
add rax, qword ptr [rdi + 8]
add rax, qword ptr [rdi + 16]
add rax, qword ptr [rdi + 24]
add rax, qword ptr [rdi + 32]
add rax, qword ptr [rdi + 40]
add rax, qword ptr [rdi + 48]
add rax, qword ptr [rdi + 56]

pop rcx
ret

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.