← Retour au blog
tech 3 September 2026

Implementing FMA and Finding Bugs in C and Rust Standard Libraries

Discover how implementing FMA can uncover subtle bugs in C and Rust standard libraries. Using proven algorithms, explore the challenges and solutions for accurate computations.

Article inspired by the original source
Implementing FMA and finding bugs in C and Rust standard libraries ↗ shnatsel.github.io

Introduction

Implementing FMA (Fused Multiply-Add) is a critical task for developers aiming to enhance the precision of numerical computations. Not only does FMA optimize performance by reducing rounding errors, but it is also essential for accurate trigonometric functions. However, this implementation can reveal subtle bugs, even in well-regarded standard libraries like those of C and Rust.

Why is FMA Important?

FMA performs the calculation \(a * b + c\) in a single operation, thus minimizing rounding errors. It is crucial for applications requiring high precision, such as numerical simulations or scientific computations. Yet, despite its importance, hardware support for FMA is not universal. For example, 15% of machines in the Firefox hardware survey lack AVX2, a technology that includes hardware FMA.

Challenges with Rust and C

When there is no hardware support, Rust and other languages must emulate FMA, which can be inefficient. In Rust, the std::simd library gives up vectorized support and runs FMA in scalar mode, which is slow. To circumvent this problem, a new approach is necessary, like implementing using SIMD (Single Instruction, Multiple Data) which allows efficient vectorization.

The SIMD Approach

To implement FMA without hardware support, using SIMD is crucial. The challenge lies in the astronomical number of possible input combinations. Based on a 2008 algorithm by Sylvie Boldo and Guillaume Melquiond, it is possible to emulate FMA by computing \(a * b + c\) in double precision (f64) and then rounding to single precision (f32). This method has been formally verified for its accuracy.

Results and Performance

The SIMD implementation has shown promising results, with an acceleration up to 5x compared to std::simd. This efficiency is due to eliminating the need to check for hardware FMA availability on each call and managing floating-point exceptions.

Bugs Discovered

The implementation also uncovered bugs in the standard libraries of C and Rust. These bugs often arose from approximating floating-point calculations and rounding errors occurring during conversion between different precisions.

Conclusion

Implementing FMA is not just about performance but also about precision and reliability. Developers must be aware of hardware and software limitations and explore solutions like SIMD to optimize their applications.

Let's discuss your project in 15 minutes.

FMA Rust C SIMD Floating-point
Deepthix newsletter · 100% AI · every Monday 8am

An AI agent reads tech for you.

Our AI agent scans ~200 sources per week and ships the best articles to your inbox Monday 8am. Free. One click to unsubscribe.

Visit the newsletter page →

Want to automate your operations?

Let's talk about your project in 15 minutes.

Book a call