fast image operations
Diffstat (limited to 'src/math.rs')
-rw-r--r--src/math.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/math.rs b/src/math.rs
new file mode 100644
index 0000000..08e8457
--- /dev/null
+++ b/src/math.rs
@@ -0,0 +1,22 @@
+//! utility math
+/// Calculates `a * b + c`, with hardware support if possible.
+#[allow(clippy::suboptimal_flops)]
+pub fn madd(a: f32, b: f32, c: f32) -> f32 {
+ if cfg!(target_feature = "fma") {
+ a.mul_add(b, c)
+ } else {
+ a * b + c
+ }
+}
+
+/// helps
+pub trait FExt {
+ /// Calculates `a * b + c`, with hardware support if possible.
+ fn madd(self, a: f32, b: f32) -> Self;
+}
+
+impl FExt for f32 {
+ fn madd(self, a: f32, b: f32) -> Self {
+ madd(self, a, b)
+ }
+}