Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Box2D 5 min read Deep dive hardMaster

SIMD for Collision

Box3D 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.

Assumes: SIMD intrinsicsconvex hull collision detectionstructure of arrays layout

Related posts

  • Inscribed Spheres

    Box2D hardMaster

    Inscribed spheres give a cheap upper bound on the separation achievable along any axis in the separating axis test (SAT): n·d − (rA + rB), where d joins the sphere centers. That one dot product can rule out a polytope face before the O(N) support search. Box3D extends this to edges by projecting d onto each edge's Gauss map arc, using a branchless closed-form test to drop whole edges before the edge-pair stage. On 32-vertex hulls this culls 86% of face tests and 98% of edge pairs, cutting the Convex Pile narrow-phase time by 62%, and SAT becomes roughly competitive with GJK except on long, skinny shapes.

  • Box2D 3.2

    Box2D easyNovice

    Box2D 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.

  • Enum of Arrays

    TigerBeetle mediumAdept

    Struct-of-Arrays has a dual for tagged unions: an Enum of Arrays, where one tag covers a whole batch of homogeneous payloads instead of each element carrying its own tag. Amortizing the tag saves memory, avoids padding waste between differently sized variants, and replaces per-item unpredictable branches with a single branch per batch, which also opens the loop to SIMD. TigerBeetle applies this by processing homogeneous batches of about 8k accounts or 8k transfers rather than mixed operations, mirroring a control plane/data plane split.

The quest for software engineering knowledge.

Look:
Layout: