pub trait Alignment: Sealed { }Expand description
Marker trait controlling SIMD alignment for math types.
Math types such as Vector are generic over A: Alignment, which controls whether the type is SIMD-aligned:
Aligned: The type may be SIMD-aligned when doing so improves performance.Unaligned: The type is never SIMD-aligned.
§Background
SIMD
instructions
can significantly improve the performance of math code, but they require
stricter memory
alignment than scalar
code. For example, a Vec3<f32> must be aligned to 16 bytes to efficiently
use SIMD. This increases its size from 12 bytes to 16 bytes, introducing 4
bytes of padding.
In many cases padding is worthwhile for performance, but in other cases such as storing large arrays, minimizing memory usage is more important.
To support both cases, math types such as Vector are
generic over A: Alignment, allowing SIMD alignment to be enabled or
disabled as needed. The default type aliases (e.g.,
Vec2<T>, Vec3<T>) use Aligned. Aliases
ending in U (e.g., Vec2U<T>, Vec3U<T>)
use Unaligned.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.