SIMD Math Optimization
Bibliothèque mathématique haute performance utilisant intrinsics SIMD (SSE/AVX) pour moteurs de jeu
C++ · SIMD · SSE · AVX · Performance · Math
Bibliothèque mathématique haute performance utilisant les instructions SIMD pour les opérations vectorielles et matricielles.
Contexte
Projet école GTech3, compétition d'optimisation, 4 semaines. Projet individuel.
Implémentation d'opérations mathématiques avec intrinsics SIMD pour atteindre le débit maximal.
Cahier des Charges École
- Implémenter des opérations vectorielles SIMD
- Benchmarker vs scalaire, speedup minimum 4x
- Intrinsics x86 (pas d'asm inline), SSE4.2 minimum
Mon Implémentation
Au-delà des vecteurs demandés :
- Hiérarchie complète : Vec2, Vec3, Vec4, Mat4, Quaternion
- AVX en plus de SSE : 8 floats vs 4
- Quaternions SIMD : rotations optimisées
- Data layouts optimisés : support SoA
- Runtime dispatch : détection CPU automatique
Liens
Code disponible sur demande.
Architecture SIMD
Hiérarchie de types avec dispatch runtime :
┌─────────────────────────────────────────┐
│ Runtime CPU Detection │
│ (SSE4.2 / AVX / AVX2 disponible?) │
└──────────────┬──────────────────────────┘
│
┌─────────┴─────────┐
▼ ▼
┌─────────┐ ┌─────────┐
│ SSE │ │ AVX │
│ 128-bit │ │ 256-bit │
│ 4 floats│ │ 8 floats│
└─────────┘ └─────────┘
Stack Détaillé
| Tech | Version | Rôle |
|---|---|---|
| C++ | 17 | Langage core |
| SSE4.2 | x86 intrinsics | Registres 128-bit |
| AVX/AVX2 | x86 intrinsics | Registres 256-bit |
| CMake | 3.x | Build system |
Types Implémentés
- Vec2, Vec3, Vec4 (SIMD)
- Mat4 (SIMD)
- Quaternion (SIMD)
- Support SoA (Structure of Arrays) pour batch
Techniques d'Optimisation
- Alignement mémoire (16/32 bytes)
- Data layout SoA vs AoS
- Patterns cache-friendly
- Élimination de branches
- Runtime dispatch SSE/AVX
Benchmarks
| Opération | Scalaire | SIMD | Speedup |
|---|---|---|---|
| Vec4 dot | 4 ops | 1 op | ~4x |
| Mat4 mul | 64 ops | 16 ops | ~4x |
| Batch transform | N ops | N/4 ops | ~4x |