SIMD Matters
Box2D 3.0 solves contact constraints with SIMD by using greedy graph coloring to group constraints so no body appears twice within a color. Each color is split into 4- or 8-wide blocks for SSE2/Neon/AVX2, with body velocities gathered into wide structs and scattered back afterward. Colors persist across time steps using per-color body bitsets, and static bodies are excluded to keep the color count low. On a 5050-body pyramid benchmark, SSE2 is about 2x faster than scalar and AVX2 about 14% faster than SSE2, while compiler auto-vectorization of a scalar struct-of-floats fallback fails to match hand-written SSE2.
Related posts
- Box2D 3.1
Box2D mediumAdeptBox2D 3.1 fixes most bugs and build problems from 3.0 and adds an experimental geometric character mover built from collision queries and a specialized solver that runs outside the physics world. A rewritten sensor system no longer piggybacks on contacts: it ignores body type and sleep state, runs at the end of the step for undelayed, deterministic, multithreaded begin/end events, and exposes current overlaps. Rolling resistance and tangent speed (conveyor belts) are new shape surface properties using the SIMD contact solver. SSE2 is now the default on x64 instead of AVX2, Neon is optimized for Apple Silicon, continuous collision is about twice as fast, and GJK is 20% faster.
- SIMD for Collision
Box2D hardMasterBox3D uses wide SIMD to speed up the edge-edge phase of the Separating Axis Test, testing one edge of hull A against four edges of hull B at once using structure-of-arrays data. For 32-point convex hulls with 89 edges (7921 edge-edge pairs), SSE2 makes the whole simulation more than twice as fast as scalar code in a 5120-hull pile benchmark, and simply compiling with AVX2 enabled adds roughly another 10%. SAT is preferred over GJK/EPA because it needs no collision margin and avoids EPA's numerical brittleness. Its quadratic cost is bounded by Box3D's 128-edge hull limit, and the optimization does almost nothing for box-box collisions.
- Box2D 3.2
Box2D easyNoviceBox2D 3.2 runs roughly three times faster than 3.1, with the speedup broken down by source: contact recycling (~40%), solver algorithm refinement (~20%), AVX2 runtime dispatch (~15%), solver optimization (~10%) and broad-phase optimization (~10%), which compound multiplicatively. Following Jolt, body positions now use double precision while heavy math stays single-precision, raising the usable world size from about 16km to 1000km with little performance or memory cost. The release also adds recording and replay for debugging, which lays groundwork for snapshot/restore features such as rewind and networking, plus a new dynamic character mover.
- Platform-independent SIMD in Go
The Go Blog hardMaster
Go 1.27 adds an experimental, size-agnostic `simd` package, loosely modeled on Highway for C++. It hides differences in vector width, masking schemes and instruction sets across AVX/AVX2/AVX512, NEON and wasm, and falls back to emulation on platforms without SIMD support. Vector types such as `simd.Float32s` have no fixed length; they load from and store to slices and expose only operations in the cross-platform intersection, with gaps filled by emulation. When an operation is missing, code can drop into the architecture-specific `archsimd` package via `ToArch()`/`FromArch`, and the compiler specializes away the type switch, as shown with a lookup-table popcount implementation for AVX/AVX2.
- Arch-specific SIMD in Go
The Go Blog hardMaster
Go 1.27 extends the experimental architecture-specific SIMD API (simd/archsimd, enabled with GOEXPERIMENT=simd) from amd64 to arm64 NEON and wasm 128-bit SIMD. The design uses typed vector structs, readable method names unified across architectures, opaque mask types that the compiler peepholes into masked instructions, and new zero-cost reinterpretation methods (ToBits, ReshapeToUint<W>s) that replace Go 1.26's As<Type> methods. Worked examples reverse bits with GFNI affine transforms and transpose an 8x8 matrix with AVX2 lane-grouped permutes. Practical advice: guard code with CPU feature checks, which avoid SIGILL and also enable fused AVX-512 lowering; write loop bounds as i < len-n+1 so bounds checks are eliminated; and pass vectors as separate values rather than arrays or structs so they stay in registers.