Crates.io | lower |
lib.rs | lower |
version | 0.2.0 |
source | src |
created_at | 2024-02-17 01:18:49.601244 |
updated_at | 2025-02-03 08:05:19.76849 |
description | desugar math where the compiler wont |
homepage | |
repository | https://github.com/bend-n/lower-plus.git |
max_upload_size | |
id | 1142927 |
size | 5,538 |
lowers expressions to their "desugared" form.
e.g
a * b + c
=> (a.mul(b)).add(c)
note that it is extremely pervasive, so
lower::math! { fn main() -> u8 {
const X: u8 = 31 * 2;
return 2 * X + 2;
} }
expands to
fn main() -> u8 {
const X: u8 = 31.mul(2);
return (2.mul(X)).add(2);
}
it should work for most expressions.
also implements some modules that let it work with some core intrinsics (f*_fast
, f*_algebraic
). (nightly only!)
rust added an amazing feature called algebraic math (thanks orlp), allowing us to use f*_algebraic
. however, dont you hate it when your
fn madd<const N: usize>(x: [[f32; 3]; N]) -> [f32; N] {
x.map(|[a, b, c]| a * b + c) // not optimized! cant use `(v)fmadd`
}
turns into
fn madd<const N: usize>(x: [[f32; 3]; N]) -> [f32; N] {
x.map(|[a, b, c]| core::intrinsics::fadd_algebraic(core::intrinsics::fmul_algebraic(a, b), c)) // readability in shambles
}
this crate allows you to
fn madd<const N: usize>(x: [[f32; 3]; N]) -> [f32; N] {
// wow! such readability! ultimate simd!
lower::algebraic! { x.map(|[a, b, c]| a * b + c) }
}