-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
One of the most efficient ways to write math-heavy CPU code is to use the SIMD instruction sets available on many processors. SIMD stands for single instruction, multiple data, and refers to the set of instructions that operate on several values at a time. For instance, if we need to perform some math on a linear array of floating-point numbers, we can use SIMD instructions to do this in blocks of values, potentially up to 512 bits per instruction on modern processors.
In this section, we'll examine how we can make use of SIMD optimizations in Rust through its high-level, cross-platform std::simd module, which is currently only available on nightly Rust. To do this, we must first set up the nightly Rust toolchain, then write and benchmark a SIMD implementation of our matrix multiply.
Rust exposes intrinsics that map to architecture-specific SIMD instructions in the std::arch module. Using these intrinsics effectively...