
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>https://www.bluepuni.com/</id>
 <title>Caturra's Blog</title>
  <subtitle>Caturra的个人博客</subtitle>
  <updated>2025-12-25T00:00:00+08:00</updated>
  <author>
    <name>Caturra</name>
    <uri>https://www.bluepuni.com/</uri>
  </author>
<link rel="self" type="application/atom+xml" href="https://www.bluepuni.com/feed.xml"/>
<link rel="alternate" type="text/html" hreflang="zh-CN"
    href="https://www.bluepuni.com/"/>
  <generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator>
  <rights> © 2026 Caturra </rights>
  <icon>/favicon.ico</icon>
  <logo>/images/favicon.png</logo>
  <entry>
   <title>一些 SIMD 字符集查找的算法实现</title>
  <link href="https://www.bluepuni.com/archives/simd-character-set-search-algorithms/" rel="alternate" type="text/html" title="一些 SIMD 字符集查找的算法实现" />
   <published>2025-12-25T00:00:00+08:00</published>
    <updated>2025-12-25T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/simd-character-set-search-algorithms/</id>
    <content src="https://www.bluepuni.com/archives/simd-character-set-search-algorithms/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="Performance" />
    <category term="Algorithm" />
    <summary>
      字符集查找指的是类似 strpbrk 的接口：在目标字符串中扫描，直到匹配指定字符集的任意字符。本文将使用一个压缩的 bitmap 来替代接口的 breakset 参数，提供不同场景的 SIMD 字符集查找算法。
NOTES:
  本文是给 StringZilla 做 PR 时顺便整理的测试集，特定背景使用 AVX2 而非 AVX512。
  即使是标量而非 SIMD，使用 bitmap（而非字符串）也有相当的性能收益，详见 benchmark。
  本文的工作重点是场景/benchmark，算法当中最重要的核心思路不是原创的（我太菜了）。但是目前没有确切的最早来源，个人猜测作者是 Daniel Lemire 或者 Wojciech Muła。
ASCII character
假设 char 的可用范围是 [0, 127]，也就是 ASCII 场景。我们需要的压缩 bitm...
    </summary>
  </entry>
  <entry>
   <title>C++ 的显式 ILP（指令级并行）实践</title>
  <link href="https://www.bluepuni.com/archives/cpp-explicit-ilp-in-practice/" rel="alternate" type="text/html" title="C++ 的显式 ILP（指令级并行）实践" />
   <published>2025-11-19T00:00:00+08:00</published>
    <updated>2025-11-19T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/cpp-explicit-ilp-in-practice/</id>
    <content src="https://www.bluepuni.com/archives/cpp-explicit-ilp-in-practice/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="Performance" />
    <category term="C++" />
    <summary>
      太长不看
template &amp;lt;auto First, auto Last&amp;gt;
constexpr auto constexpr_for = [](auto &amp;amp;&amp;amp;f) {
    [&amp;amp;]&amp;lt;auto I&amp;gt;(this auto &amp;amp;&amp;amp;self) {
        if constexpr (I &amp;lt; Last) {
            f.template operator()&amp;lt;I&amp;gt;();
            self.template operator()&amp;lt;I + 1&amp;gt;();
        }
    }.template operator()&amp;lt;First&amp;gt;();
};
简单结论：
  使用 SIMD intrinsic 编程时，编译器 -O3 并不提供充分的 ILP ...
    </summary>
  </entry>
  <entry>
   <title>x86 的 REP_GOOD、ERMS 和 FSRS 微架构特性</title>
  <link href="https://www.bluepuni.com/archives/x86-rep-good-erms-and-fsrs/" rel="alternate" type="text/html" title="x86 的 REP_GOOD、ERMS 和 FSRS 微架构特性" />
   <published>2025-10-19T00:00:00+08:00</published>
    <updated>2025-10-19T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/x86-rep-good-erms-and-fsrs/</id>
    <content src="https://www.bluepuni.com/archives/x86-rep-good-erms-and-fsrs/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="Architecture" />
    <category term="Performance" />
    <summary>
      上文调研了某个知名库的 memcpy 实现，本文将调研 Linux 内核的 memset 实现。不过本文的实际动机是讨论 x86 的 REP_GOOD、ERMS 和 FSRS 微架构特性。（虽然初衷是为了电子斗蛐蛐……）
caturra@BLUEPUNI:~$ cat /proc/cpuinfo | grep flags
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb
rdtscp lm constant_tsc rep_good 👈 nopl xtopology tsc_reliable nonstop_tsc
cpuid ...
    </summary>
  </entry>
  <entry>
   <title>[阅读笔记] Arm 与 POWER 宽松内存模型入门</title>
  <link href="https://www.bluepuni.com/archives/notes-on-arm-and-power-relaxed-memory-models/" rel="alternate" type="text/html" title="[阅读笔记] Arm 与 POWER 宽松内存模型入门" />
   <published>2025-09-19T00:00:00+08:00</published>
    <updated>2025-09-19T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/notes-on-arm-and-power-relaxed-memory-models/</id>
    <content src="https://www.bluepuni.com/archives/notes-on-arm-and-power-relaxed-memory-models/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="Concurrency" />
    <category term="Architecture" />
    <summary>
      本文对早期的 浅读 perfbook：如果并行编程很难，那我能做点什么？ 进行内容补充，进一步讨论弱序内存模型，提供更加丰富的代码模式以供理解。主要参考一篇极佳的论文 A Tutorial Introduction to the ARM and POWER Relaxed Memory Models，本文也是这篇论文的阅读笔记。
NOTES:
  出于历史原因，论文视 Arm 为 non-MCA 系统。
  本人不懂 POWER，只是论文标题是这样写的……
  页表操作、自修改代码和外部共享域不在讨论范围内。
  论文篇幅非常长，本文仅作自用笔记，注意极大幅度的精简会缺失一定的上下文信息。
基本概念
有三种内存模型的粗略分类：
  SC：任何写操作都会同时对所有其他线程可见；没有局部重排序。
  TSO：引入多副本原子性（Multi-Copy Atomicity）；写缓冲...
    </summary>
  </entry>
  <entry>
   <title>使用 Zig C++ 在安卓手机上测试弱序内存模型</title>
  <link href="https://www.bluepuni.com/archives/testing-weakly-ordered-memory-model-on-android-phones-using-zig-cpp/" rel="alternate" type="text/html" title="使用 Zig C++ 在安卓手机上测试弱序内存模型" />
   <published>2025-09-01T00:00:00+08:00</published>
    <updated>2025-09-01T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/testing-weakly-ordered-memory-model-on-android-phones-using-zig-cpp/</id>
    <content src="https://www.bluepuni.com/archives/testing-weakly-ordered-memory-model-on-android-phones-using-zig-cpp/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="差生文具多" />
    <category term="Concurrency" />
    <summary>
      背景
这完全是一个工具链问题，跟 Arm 内存模型没关系。
正式的 Android C++ 开发 需要引入 Android NDK 工具链，而现在测试弱序内存模型其实只需要一个满足 ABI 兼容的 Linux 二进制文件，并不涉及任何 Android 生态。
那我能不能扔掉这个庞大的 NDK？里面可是塞满了大量的 llvm-prebuilts！二进制体积高达 2 GB！
Android NDK 里面到底有什么东西？为什么体积会像🐖一样大？
说得好！这个比喻非常形象，Android NDK 的体积确实经常让人“虎躯一震”。它动不动就几个GB的大小，让很多开发者又爱又恨。下面我们来“解剖”一下这头“^(*￣(oo)￣)^”，看看它肚子里到底有什么“货”，以及为什么这么“胖”。
-------
Android NDK 里面到底有什么：
- 编译/链接工具链（多平台预置）...
    </summary>
  </entry>
  <entry>
   <title>使用 Intel Pin 进行动态指令执行统计</title>
  <link href="https://www.bluepuni.com/archives/instruction-counting-with-intel-pin/" rel="alternate" type="text/html" title="使用 Intel Pin 进行动态指令执行统计" />
   <published>2025-08-18T00:00:00+08:00</published>
    <updated>2025-08-18T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/instruction-counting-with-intel-pin/</id>
    <content src="https://www.bluepuni.com/archives/instruction-counting-with-intel-pin/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="差生文具多" />
    <category term="Performance" />
    <summary>
      Intel Pin 本体是一个动态二进制插桩框架，但是其内部集成的 Intel XED 库接口非常适合做指令统计，更重要的是……已经有现成的工具包含在官方示例里面了。
本文简单记录一下 Intel Pin 的概念和用法，仅作为备忘录。
NOTES:
  静态分析的话，可以使用 LLVM-MCA。
  动态分析但是面向性能剖析的话，perf 就够了。
  我本来想着这种观测用途首先就得找 eBPF/bcc 工具集，结果往里一看，没有一个工具是关于指令的。然后我又找了 valgrind --tools=lackey，卡🐔没法用。看来我对工具的认知还不够。
  Intel Pin 是闭源的，不要管什么 JIT 原理实现，能用就行；另外这里只做统计不做分析。
基本概念
以下是对 Pin User Guide 的拙劣解释，不保证理解无误。推荐读者亲自看用户指南，或者找有安全背景的人...
    </summary>
  </entry>
  <entry>
   <title>一些 SSO 实现方式（御三家 + fbstring）</title>
  <link href="https://www.bluepuni.com/archives/sso-implementations/" rel="alternate" type="text/html" title="一些 SSO 实现方式（御三家 + fbstring）" />
   <published>2025-08-13T00:00:00+08:00</published>
    <updated>2025-08-13T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/sso-implementations/</id>
    <content src="https://www.bluepuni.com/archives/sso-implementations/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="Performance" />
    <category term="RTFSC" />
    <summary>
      背景
SSO，即 Small String Optimization。字面意思，面向小数据集场景（长度）进行的优化，以避免高额动态内存分配。
知名库——libstdc++/libc++/MSVC.STL/folly 均采用了不同的方式去实现 SSO。既然存在不同方式，那说明 SSO 没有任意场景的最优解。它们的 SSO 缓冲阈值是多少，为引入 SSO 而设计的字符串本身的静态内存布局占用多大，SSO 的引入是否会为基本使用（data()/size()）带来额外的运行时开销，这些都是问题。
本文将快速总结 SSO 的实现方式，了解通用库是怎么选择的。
NOTES:
  关于库版本，均为本文章发布日期的 master 版本。
  为了版面简洁，会有部分精简实现，同时函数会直接内联。
  不讨论 SSO 以外的事情。
libstdc++
结论先行
对于内存占用，lib...
    </summary>
  </entry>
  <entry>
   <title>[翻译] C++ 的 thread_local 访问模型</title>
  <link href="https://www.bluepuni.com/archives/cpp-thread-local-access-models/" rel="alternate" type="text/html" title="[翻译] C++ 的 thread_local 访问模型" />
   <published>2025-08-09T00:00:00+08:00</published>
    <updated>2025-08-09T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/cpp-thread-local-access-models/</id>
    <content src="https://www.bluepuni.com/archives/cpp-thread-local-access-models/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="C++" />
    <category term="Concurrency" />
    <category term="翻译" />
    <summary>
      背景
本文翻译了解析 thread_local 实现的演讲：Евгений Ерохин — Thread Local в C++ как он есть。主要是介绍 TLS 数据结构、四种经典 TLS 访问模型（access model）和更高效的描述符模型。
一些不重要的备注：
  本人不懂俄语，实际使用 Gemini 翻译。
  重要的地方要是表意模糊我会手动修正，不太重要的地方读者就凑合看吧（）
  图和代码显然也是人工边看演讲边插入的，不是幻觉生成。
  标题不知道该怎么字面翻译（文化差异？），就挑选了篇幅占比最长的「访问模型」。
  演讲是 2020 年的，注意文中部分内容的时效性。
  选这篇是因为我觉得内容很不错，作者是现场直接开 godbolt 跟你聊代码的。
  但是汉化版会受限于个人认知水平……如有错误还请指正！
  转录小站那边还有大量演讲稿，更加适合快...
    </summary>
  </entry>
  <entry>
   <title>新增一个中文转录小站</title>
  <link href="https://www.bluepuni.com/archives/uni-transcripts/" rel="alternate" type="text/html" title="新增一个中文转录小站" />
   <published>2025-07-30T00:00:00+08:00</published>
    <updated>2025-07-30T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/uni-transcripts/</id>
    <content src="https://www.bluepuni.com/archives/uni-transcripts/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="杂项" />
    <summary>
      就在网站侧边栏的底部，新增了一个由 Sphinx 驱动的子站点。（就是中间海胆  形状的按钮）。
  题外话：炼金世界观的海胆（bbs.nga.cn）
这个子站点仅用于存放一些演讲的中文转录稿，我以后收藏的视频就不用每次都花一小时以上去陪听了。其实背后的动机就是我的收藏夹已经积压太多了（2019 年的资料还没清完），所以尝试借助 LLM/AI 红利来解决演讲看不完的痛点，而且也能避开看一半发现是标题党的问题。
工具链很简单，软件只用到 whisper 和 deepseek，有 GUI 套壳方案的话就是拖一把鼠标的事情。单个稿件完整生成大概需要十分钟，唯一瓶颈是 deepssek 的吐字效率。
由于（现在的 jekyll）博客有点用腻了，所以尝试了 Linux 内核文档同款的 Sphinx——实际难用！这个就不多说了，毕竟 Sphinx 也没说自己是写博客用的，没有原生 m...
    </summary>
  </entry>
  <entry>
   <title>Linux 内核的 XArray 实现</title>
  <link href="https://www.bluepuni.com/archives/linux-xarray/" rel="alternate" type="text/html" title="Linux 内核的 XArray 实现" />
   <published>2025-07-04T00:00:00+08:00</published>
    <updated>2025-07-04T00:00:00+08:00</updated>
    <id>https://www.bluepuni.com/archives/linux-xarray/</id>
    <content src="https://www.bluepuni.com/archives/linux-xarray/" />
    <author>
      <name>Caturra</name>
    </author>
    <category term="Kernel" />
    <category term="IO" />
    <category term="RTFSC" />
    <summary>
      背景
Linux 内核使用 XArray（eXtensible Array）作为 Linux IO 栈 的页面缓存（page cache）容器实现。
本文会介绍 XArray 的具体实现，以及 XArray 在 page cache 层的应用。
基本介绍
仅从 外部 API 来看，XArray 可视为自动扩容的无限大的数组。
而从作者的表态来看，XArray 目标是作为一个「万能」的数据结构，除了替代明确的 IDR 或者 page cache 场景的基数树，还可以部分替代内核中的链表、红黑树和哈希表，其定位类似于朱棣数组。
NOTES:
  其实是朱迪数组（Judy Array）🙃
  XArray 的场景适用于小数据集（比链表更省结点空间），或者是相对密集的大数据集（比哈希表更有局部性且无冲突）。
  XArray 还满足了内核特定的需求，比如提供 RCU-free ...
    </summary>
  </entry>
</feed>
