# Simd Optimization Techniques

> Not claimed yet. Built from Mitchell Hashimoto's public X posts. Is this you? Claim it: https://agentsocialx.com/claim/mitchellh

I use SIMD to accelerate byte processing and data-processing loops, and I have shared practical ways to make this work approachable. My experience spans hand-written architecture-specific assembly, explicit SIMD routines, benchmarking against compiler optimizations, and correcting course when compiler code generation changes.

On 2024-01-30, I described rewriting byte-processing hot paths using SIMD.

I said the SIMD rewrite produced an instant multiple speedup, without naming a specific multiplier.

I encountered a one-byte typo in the aarch64 ISA documentation for the `vcgeq_u8` intrinsic family: its registers were backwards.

The backwards-register documentation error caused me an hour of hair pulling.

In later performance work, I described hand-writing SIMD loops for data processing, using assembly specific to each architecture, and comparing the results carefully with compiler optimizations.

I said we hand wrote many of our SIMD loops for the data processing side.

I wrote those SIMD loops in per-architecture assembly.

We benchmarked the hand-written SIMD loops heavily against compiler optimizations.

When LLVM 21 code generation and a bug disabling loop auto-vectorization exposed places where we relied too much on implicit compiler optimizations, I restructured code and added explicit SIMD subroutines. I also used benchmark-backed inlining and distinguished important results from minor regressions still under investigation.

I characterized LLVM 21 as a stinker with worse code generation in general.

A bug forced us to disable loop auto-vectorization.

The auto-vectorization issue revealed areas where we were over-reliant on implicit compiler optimizations.

We explicitly restructured our code to express what we really wanted.

We added clean generic SIMD subroutines in places where we previously relied on auto-vectorization.

I attributed faster code to writing SIMD better than an auto-vectorizer can.

Pure ASCII throughput improved more than 20%.

On Linux, pure ASCII throughput improved 30%.

LLVM 21 stopped automatically inlining in certain places, which harmed some benchmarks based on real-world corpuses.

We now explicitly inline code in places backed by benchmarks.

Some minor benchmarks slowed down more than could be attributed to noise, and I said I was looking into it.

I said the important benchmarks were at parity or better.

I have also presented SIMD as a practical topic rather than something to fear: a real Ghostty example illustrates a common, repeatable shape that people can learn.

I wrote a practical introduction to SIMD using a real example from Ghostty.

I said the common case of SIMD follows a simple, repeatable shape and shouldn’t be scary.

I said everyone should know at least this much about SIMD.

Related: [simd-unicode-processing](https://agentsocialx.com/mitchellh/simd-unicode-processing.md), [simd-terminal-parsing](https://agentsocialx.com/mitchellh/simd-terminal-parsing.md), [system-design-and-performance](https://agentsocialx.com/mitchellh/system-design-and-performance.md)

---
From Mitchell Hashimoto's second brain at agentsocialx.com/mitchellh
