From Fundamentals to Advanced Optimization
Introduction
- What This Book Is About
- How This Book Is Organized
- What You Will Be Able to Do After Reading
- Prerequisites and Conventions
- A Note on What This Book Does Not Cover
Chapter 1: The Case for SIMD; Why Data-Level Parallelism Matters
- A Simple Example: Tenfold Speedup in Three Lines
- Where Performance Is Actually Spent Today (Amdahl’s Law in Practice)
- Forms of Parallelism: Threads, Pipelines, Superscalar, SIMD, GPUs; How They Relate
- The Memory Wall and Why Vectorization Helps
- When SIMD Wins, When It Does Not, and When to Skip It Entirely
- A Practical Decision Framework Before You Optimize
Chapter 2: CPU Architecture Essentials for SIMD Programmers
- The Modern CPU as a Dataflow Machine (Not a Von Neumann Diagram)
- Registers, Execution Ports, and Instruction Scheduling
- Pipelining, Superscalar Execution, and Instruction-Level Parallelism
- The Memory Hierarchy: Registers, L1/L2/L3 Cache, RAM; Latencies That Matter
- Branch Prediction and Why SIMD Loves Straight-Line Code
- Clock Frequency, Power Budgets, and Turbo Boost Reality
Chapter 3: Understanding Vector Execution from First Principles
- Scalar Versus Vector: The Same Operation, Different Granularity
- What Is a Lane and How Data Lives Inside a Vector Register
- Loading, Transforming, Storing: The Basic SIMD Execution Model
- Endianness, Alignment, and Memory Layout Fundamentals
- Instruction Encoding Widths (128-bit, 256-bit, 512-bit) and What They Mean
- Throughput Versus Latency in Vector Operations
Chapter 4: Compiler Auto-Vectorization and Vectorization Reports
- How Modern Compilers Discover Vectorization Opportunities
- Reading Compiler Vectorization Reports (GCC, Clang, MSVC, ICC)
- Writing Auto-Friendly Code: Loop Structure, Alignment, Dependencies
- Common Reasons Auto-Vectorization Fails and How to Fix Them
- Floating-Point Semantics, Reassociation, and Precision Trade-offs
- When to Trust the Compiler and When to Take Over Manually
Chapter 5: Writing Your First SIMD Code; Intrinsics and Portable Approaches
- Development Environment Setup: Compilers, Flags, Debugging Tools
- Your First Intrinsic: A Complete Scalar-to-SIMD Walkthrough
- How Intrinsics Map to Assembly (and Why That Matters)
- Portable SIMD: C++20 std::simd Proposals, ISPC, and Libraries
- Language Support Beyond C/C++: Rust, Go, Zig, and Others
- Feature Detection: CPUID, IsA Detection, and Runtime Dispatch Basics
Chapter 6: Memory, Alignment, and Data Layout for SIMD
- Aligned Versus Unaligned Loads: Costs, Faults, and Mitigations
- Structure of Arrays (SoA) Versus Array of Structures (AoS): The Fundamental Choice
- Data Rearrangement: When and How to Transpose Between Layouts
- Gather and Scatter: Flexible but Expensive Memory Access
- Prefetching and Streaming Loads for Bandwidth-Bound Code
- Cache Line Effects, False Sharing, and Alignment Strategy
Chapter 7: Vector Operations; Loading, Transforming, Comparing, and Reducing
- Load Patterns: Streaming, Non-Temporal, Masked, and Gather Loads
- Arithmetic Operations: Addition, Subtraction, Multiplication, Division Avoidance
- Comparison and Masking: Generating Masks from Vector Comparisons
- Shuffles, Permutations, and Cross-Lane Data Movement
- Reductions: Summing, Finding Min/Max, Horizontal Operations
- Widening, Narrowing, Saturation, and Type Conversions
Chapter 8: x86 SIMD; SSE Through AVX-512
- The x86 SIMD Evolution: SSE, SSE2, SSE3, SSSE3, SSE4.x Timeline
- AVX and AVX2: 256-Bit Vectors, VEX Encoding, and Integer Multiplies
- AVX-512: Masking, EVEX Encoding, and the Frequency Penalty Debate
- Instruction Selection Strategy: Which Set to Target on Modern Hardware
- Microarchitecture Differences: Intel Versus AMD SIMD Execution
- ABI Considerations and Calling Conventions for SIMD Code
Chapter 9: Arm SIMD; NEON and SVE/SVE2
- NEON Basics: Register File, Data Types, and Instruction Patterns
- Programming NEON: Intrinsics, Assembly, and Portable Approaches
- SVE and SVE2: Predicate-Based Vectoring and Variable Length
- Key Differences Between Arm and x86 SIMD Design Philosophies
- Mobile Versus Server: Power Constraints and Performance Targets
- Cross-Platform SIMD: Writing Code That Runs on Both Families
Chapter 10: Performance Analysis and Optimization Methodology
- Building Trustworthy Microbenchmarks: Pitfalls and Best Practices
- Reading Assembly Output: Disassemblers and Compiler Explorer
- Hardware Performance Counters: What to Measure and How
- Identifying Compute-Bound Versus Memory-Bound Kernels
- The Roofline Model and Where Your Code Lives
- Iterative Optimization: Profile, Hypothesize, Implement, Measure
Chapter 11: Advanced Vectorization Patterns and Software Pipelining
- Loop Unrolling and Multiple Accumulators for Latency Hiding
- Software Pipelining by Hand: Overlapping Independent Operations
- Predicated SIMD: AVX-512 Masks and Arm SVE Predicates
- Branch Elimination Through Vector Comparison and Blending
- Tail Handling Strategies for Non-Multiple-of-Vector-Length Data
- Instruction Scheduling for Maximum Port Utilization
Chapter 12: Case Studies in SIMD Optimization; Part I (Numerical and Array Processing)
- Case Study 1: Image Convolution and Pixel Processing
- Case Study 2: Matrix Multiplication Kernel Optimization
- Case Study 3: Signal Processing ; FFT Butterfly Operations
- Case Study 4: Scientific Computing ; N-Body Force Calculation
Chapter 13: Case Studies in SIMD Optimization; Part II (Systems and Data Processing)
- Case Study 5: Text Parsing, String Search, and Pattern Matching
- Case Study 6: Serialization and Binary Encoding Acceleration
- Case Study 7: Hashing Functions and Cryptographic Primitives
- Case Study 8: Database Predicate Evaluation and Vectorized Execution
Chapter 14: Building, Testing, and Maintaining SIMD Code in Production
- Multiversioning Strategies: Compile-Time Versus Runtime Dispatch
- Testing Across Architectures and Vector Widths
- Debugging Optimized SIMD Code: Tools and Techniques
- Numerical Reproducibility and Floating-Point Determinism
- ABI Stability and Binary Compatibility with SIMD Libraries
- Documentation, Code Review, and Knowledge Transfer for SIMD Teams
Chapter 15: The SIMD Optimization Workflow; A Repeatable Methodology
- The Complete Optimization Decision Tree: Scalar, Auto, Intrinsics, Libraries, GPU
- Step-by-Step SIMD Optimization Checklist for New Codebases
- Integrating SIMD Work Into CI/CD and Performance Regression Testing
- When to Stop Optimizing: Diminishing Returns and Maintenance Cost
- Reference: SIMD Terminology Glossary
- Reference: Common SIMD Operations Cheat Sheet
- Reference: Compiler Flags and Feature Detection Summary
- Reference: Architecture Capability Quick Reference
- Further Resources and Authoritative References