<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SIMD on Yu's Space</title><link>https://code-agree.github.io/tags/simd/</link><description>Recent content in SIMD on Yu's Space</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Mon, 24 Aug 2026 19:30:00 +0800</lastBuildDate><atom:link href="https://code-agree.github.io/tags/simd/index.xml" rel="self" type="application/rss+xml"/><item><title>SIMD Parser 原理精读:把逐字节状态机编译成位运算数据流</title><link>https://code-agree.github.io/blog/2026-08-24-simd_parser/</link><pubDate>Mon, 24 Aug 2026 19:30:00 +0800</pubDate><guid>https://code-agree.github.io/blog/2026-08-24-simd_parser/</guid><description>上一篇《SIMD 深入解析:从硬件原理到加密货币 HFT 中的应用》(下称&amp;quot;硬件篇&amp;quot;)讲了 SIMD 的硬件机理与加密 HFT 链路全景,其中 §10.3 说&amp;quot;simdjson 比逐字符解析快约 10 倍&amp;quot;,但没有回答为什么能快——毕竟解析看起来是最&amp;quot;串行&amp;quot;的活:每个字节的含义取决于它前面的所有字节。这一篇专门拆这个问题:SIMD parser 如何把一个逐字节状态机改写成位运算数据流。其中最漂亮的一击,是用一条乘法指令跑完 64 步状态转移。
1. 先理解敌人:parser 是 CPU 最不擅长的负载 #一个标量 JSON parser 的本质是逐字节状态机:
for (each byte c) { switch (state) { case IN_STRING: if (c == &amp;#39;&amp;#34;&amp;#39;) state = OUT; else if (c == &amp;#39;\\&amp;#39;) state = ESC; break; case OUT: if (c == &amp;#39;{&amp;#39;) push(OBJ); else if (c == &amp;#39;&amp;#34;&amp;#39;) state = IN_STRING; break; ... } } 这段代码同时踩中现代 CPU 的两个死穴:</description></item></channel></rss>