|
26 | 26 | //!
|
27 | 27 | //! // Compute squared Euclidean distance
|
28 | 28 | //! let l2sq_dist = i8::l2sq(a, b);
|
| 29 | +//! |
| 30 | +//! // Optimize performance by flushing denormals |
| 31 | +//! simsimd::capabilities::flush_denormals(); |
29 | 32 | //! ```
|
30 | 33 | //!
|
31 | 34 | //! ## Traits
|
@@ -130,6 +133,9 @@ extern "C" {
|
130 | 133 | fn simsimd_uses_sapphire() -> i32;
|
131 | 134 | fn simsimd_uses_turin() -> i32;
|
132 | 135 | fn simsimd_uses_sierra() -> i32;
|
| 136 | + |
| 137 | + fn simsimd_flush_denormals() -> i32; |
| 138 | + fn simsimd_uses_dynamic_dispatch() -> i32; |
133 | 139 | }
|
134 | 140 |
|
135 | 141 | /// A half-precision floating point number.
|
@@ -207,6 +213,29 @@ pub mod capabilities {
|
207 | 213 | pub fn uses_sierra() -> bool {
|
208 | 214 | unsafe { crate::simsimd_uses_sierra() != 0 }
|
209 | 215 | }
|
| 216 | + |
| 217 | + /// Flushes denormalized numbers to zero on the current CPU architecture. |
| 218 | + /// |
| 219 | + /// This function should be called on each thread before any SIMD operations |
| 220 | + /// to avoid performance penalties. When facing denormalized values, |
| 221 | + /// Fused-Multiply-Add (FMA) operations can be up to 30x slower. |
| 222 | + /// |
| 223 | + /// # Returns |
| 224 | + /// |
| 225 | + /// Returns `true` if the operation was successful, `false` otherwise. |
| 226 | + pub fn flush_denormals() -> bool { |
| 227 | + unsafe { crate::simsimd_flush_denormals() != 0 } |
| 228 | + } |
| 229 | + |
| 230 | + /// Checks if the library is using dynamic dispatch for function selection. |
| 231 | + /// |
| 232 | + /// # Returns |
| 233 | + /// |
| 234 | + /// Returns `true` if dynamic dispatch is enabled, `false` otherwise. |
| 235 | + /// Currently always returns `false` as dynamic dispatch is not implemented. |
| 236 | + pub fn uses_dynamic_dispatch() -> bool { |
| 237 | + unsafe { crate::simsimd_uses_dynamic_dispatch() != 0 } |
| 238 | + } |
210 | 239 | }
|
211 | 240 |
|
212 | 241 | /// `SpatialSimilarity` provides a set of trait methods for computing similarity
|
|
0 commit comments